Antonioya
(Antonioya)
May 17, 2015, 11:58pm
1
Hi,
I have got this code to print vertex position:
import bpy
current_obj = bpy.context.active_object
print("="*40) # printing marker
for face in current_obj.data.polygons:
verts_in_face = face.vertices[:]
print("face index", face.index)
print("normal", face.normal)
for vert in verts_in_face:
local_point = current_obj.data.vertices[vert].co
world_point = current_obj.matrix_world * local_point
print("vert", vert, " vert co", world_point)
The code works fine, but, there is a problem. If I add a Subdivision modifier, the vertex is not in the same place in world coordinates.
How can I get the position AFTER subdivision without apply the modifiers?
CoDEmanX
(CoDEmanX)
May 18, 2015, 12:45pm
2
You need to apply the modifier in one or the other way, via operator or to_mesh() - which creates a new mesh datablock.
Antonioya
(Antonioya)
May 18, 2015, 10:44pm
3
Ok, but how can apply the modifier “on the fly”. I mean, only to get the vertex data, but not a “real” apply the modifier?
I want the new vertex data, but I don’t want to remove the modifier from the modifier stack.
CoDEmanX
(CoDEmanX)
May 19, 2015, 7:39am
4
what’s wrong with to_mesh()? I believe it’s faster than its bmesh module equivalent (which would be entirely in-memory).
Antonioya
(Antonioya)
May 19, 2015, 10:11am
5
I have never used to_mesh(), can you tell me where can I find API doc’s?
Antonioya
(Antonioya)
May 19, 2015, 10:21am
6
About, bmesh… is this the best way to get selected vertices?
bm = bmesh.from_edit_mesh(myobject.data)
for v in bm.verts:
if v.select:
mylist.extend([v.index])
CoDEmanX
(CoDEmanX)
May 19, 2015, 2:11pm
7
After the all important missing import bmesh
It says it has to be in edit mode, so I guess that doesn’t work for me.
Any other ideas that are better then having to apply the subdivision modifier to see the actual post modifier vertices in python code?
I see now using to_mesh is not applying it permanently like the GUI action does, as long as you remove it after.
aom = ao.to_mesh(ctx.scene, True, “PREVIEW”)bpy.data.meshes.remove(aom)