[Bf-python] Get geometry displacement after applying modifier

Nikolaos Kyriazis n.kyriazis at engys.com
Thu Jul 13 11:01:52 CEST 2023


Hello,

I am struggling the past two weeks with the following problem. I have tried different approaches but none of them worked so far, therefore I would like your help/advice.

I have created a geometry in Blender, for instance a BezierCurve, and I have connected it with a Lattice modifier and a vertex group. So, once I move one point or a family of points of the lattice, the geometry shape changes as well. Is there a way to get the displacement vector, i.e. how much each geometry point (neither the lattice points nor the BezierCurce control points) has moved?


i.                     The only way I have found so far is exporting the new geometry to stl format and comparing the old and the new (after applying bpy.ops.transform.translate()) stl files. The problem is that the stl files are not consistent.


ii.                   I have tried using the python API to subtract the vertices of bpy.data.objects["BezierCurve"].data.vertices before and after applying bpy.ops.transform.translate(), but the list of the vectors with the vertice coordinates is identical before and after applying the lattice modifier. I also tried getting the coordinates of the geometry shape from the mesh, once in the beginning and once after the lattice translation, but the results was the same:
    bm = bmesh.new()
    bm.from_mesh(bpy.data.objects["BezierCurve"].data)
    vertices = bm.verts
    original_positions = [list(vertex.co) for vertex in vertices]
Surprisingly enough, when I tried to plot the range of each coordinate, i.e the min, max values of the x,y,z coordinates of the vertices, they are not the same as the ones noticed when I do a visual inspection of the geometry, i.e with ParaView.


iii.                 Finally, I tried getting the necessary functions from the blender source code in c, c++ but I don't think this is the correct way. To begin with, I couldn't find another executable apart from ./blender to run and test some isolated functionalities. Secondly, it wasn't so easy to grab and extract the relevant functions BKE_lattice_deform_coords_with_mesh, deformVerts to a c++ file outside blender and perform the necessary operations.

I feel like the best way to proceed is (ii) but I cannot get why the vertices location is not updated although the exported stl looks different. I tried doing:
    bpy.ops.object.modifier_apply(modifier=bpy.data.objects["BezierCurve"].name)
    bpy.data.objects["BezierCurve"].data.update()
after applying applying bpy.ops.transform.translate().

Any advice or idea is more than welcome.
Thanks and kind regards,
Nikos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20230713/048fc793/attachment.htm>


More information about the Bf-python mailing list