I have a loop over a set of polyhedra (PolyObject) where I shrinkwrap a sphere (CellObject) about each and generate a new mesh from the deformed sphere mesh. The ultimate goal is that I’d like to add these as shape keys while avoiding costly ops calls like modifier_apply.
for j in range(0,nF):
MyMesh=bpy.data.meshes.new("MyMesh_"+str(i).zfill(2)+"_"+str(j+1).zfill(2))
PolyObject=bpy.data.objects["Poly_"+str(j+1).zfill(4)]
Vertices=GlobalVertexList[i][j+1] //Vertex and face data that I've previously read in from an external file.
Faces=GlobalFaceList[i][j+1] //
MyMesh.from_pydata(Vertices,[],Faces)
PolyObject.data=MyMesh
CellObject.location=PolyObject.location
MyMod=CellObject.modifiers.new("shrink"+str(j+1).zfill(2), type='SHRINKWRAP')
MyMod.target=PolyObject
MyMod.offset=0.0001
MeshKey=CellObject.to_mesh(bpy.context.scene,True,'PREVIEW')
CellObject.modifiers.remove(MyMod)
Key1=CellObject.shape_key_add()
for k,v in enumerate(MeshKey.vertices):
Key1.data[k].co=v.co
When I run the code above, the resulting mesh from the to_mesh operator (MeshKey) is the exact same as the undeformed sphere mesh. By inserting a bpy.context.scene.update() before the to_mesh call works how I’d like. Unfortunately I’m working with around 8000 spheres with 81 polyhedra each which means doing that many scene updates would take too much time. Trying to update CellObject and PolyObject individually using object.data.update() doesn’t work. Am I asking the right question? What part of the update that happens during bpy.context.scene.update() am I missing?