Previous Thread  Next Thread

chat icon Applying modifier in Python, creating a new mesh.

damix

Posted: Tue Jul 24, 2012 3:41 pm
Joined: 07 Dec 2011
Posts: 21
Hi everybody.

Let's say I have a bpy.types.Object containing a bpy.types.Mesh data field; how can I apply one of the modifiers associated with the object, in order to obtain a NEW bpy.types.Mesh, possibly contained within a NEW bpy.types.Object, thus leaving the original scene unchaged?

I'm interested in applying the EdgeSplit modifier right before exporting vertex data to my custom format; the reason why I want to do this is to have Blender automatically and transparently duplicate the vertices shared by two faces with very different orientations.
Reply with quote


CoDEmanX

Posted: Thu Jul 26, 2012 10:49 am
Joined: 05 Apr 2009
Posts: 680
there is an operator to apply a single modifier, but i tend to use to_mesh(), which applies all modifiers and stores the result in a new mesh

Code:
MeshObject.to_mesh(scene=bpy.context.scene, apply_modifiers=True, settings='PREVIEW')


you can change the show_viewport (settings='PREVIEW') or show_render (settings='RENDER') properties of modifiers before calling to_mesh to control which to apply (False = won't be applied).

this is an example how i use this:
http://code.google.com/p/blender-cod/source/browse/blender_26/export_xmodel.py#185
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group