Posted: Sun Dec 23, 2012 10:30 pm
Joined: 20 Sep 2012
Posts: 8
whether I edit the mesh's normal in python console, or even if I manually reverse the order of the vertices in python.
how do I get my changes to the mesh data in python to take effect on the actual blender model/mesh/scene/whatever?
here's a video to illustrate my problem:
bcaptain.net/blender-normals.mpeg
and here's the code I wrote to reverse a quad's vertex order:
| Code: |
sce = bpy.context.scene #sce = bpy.data.scenes.active
ob = sce.objects.active
mesh = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')
# ** show current normal
mesh.polygons[0].normal
# ** flip vertices of a quad
tmp=mesh.polygons[0].vertices[0]
mesh.polygons[0].vertices[0]=mesh.polygons[0].vertices[3]
mesh.polygons[0].vertices[3]=tmp
tmp=mesh.polygons[0].vertices[1]
mesh.polygons[0].vertices[1]=mesh.polygons[0].vertices[2]
mesh.polygons[0].vertices[2]=tmp
mesh.update( calc_edges=True )
# ** show new normal
mesh.polygons[0].normal
|
Posted: Wed Dec 26, 2012 3:52 pm
Joined: 20 Sep 2012
Posts: 8
This seems like a pretty simple thing, somebody must have an answer to this.
Posted: Wed Dec 26, 2012 4:04 pm
Joined: 20 Sep 2012
Posts: 8
After some thinking, I presume that I am not editing the mesh data directly, but instead a copy.
mesh = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')
how to edit the mesh directly.. that is the question!
Posted: Wed Dec 26, 2012 9:06 pm
Joined: 05 Apr 2009
Posts: 691
there can be issues with the "old" api, you should try the bmesh module. It has a special function to update normals:
http://www.blender.org/documentation/blender_python_api_2_65_release/bmesh.types.html#bmesh.types.BMesh.normal_update
but if you really wanna use the old api, switch from edit to object mode, apply changes, then switch back. This may last a while for complex models and eat memory, but otherwise changes are likely ignored (in edit mode)
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Thu Dec 27, 2012 2:29 am
Joined: 20 Sep 2012
Posts: 8
I didn't realize there was an "old" api. I wrote an export script using roughly the same python code and it took a while to wade through what was "old blender" and what was "new blender" because 2.63 is so new. But... I guess I've got some homework to do.