I think I asked this before but life got in the way, and then it was closed. I wanted to ask the best way to do something.
I am working on a script that requires me to essentially do the equivalent to like a Current State to Object on a mesh. Basically, I move a joint, which deforms the mesh with a deformer or two, and I try to duplicate that deformed shape to a simple mesh with no deformers, but in that deformed shape.
I have tried using SendModelingCommand, but because of the deformers, it creates a group that I then have to traverse and find and I worry there's differences depending on the deformers used and such.
The other wrinkle of this, is that I am cycling through this and procedurally with python adding a joint to a weight tag, weighting it, and then moving the joint, and then trying to get the deformed version. So I think part of getting everything refreshed and updated is a part of it as well. What all is needed to ensure proper updating of the deform cache to be able to extract it? I have the following code from Niklas R from many moons ago. If I just run this function, it will get me the deformed geo properly, but when I use this in my script where I add joints and move joints, it doesn't update properly or something.
use_cache = True direct_copy = True def CSTO(obj): op = obj if use_cache and op.GetDeformCache(): op = op.GetDeformCache() if direct_copy: points = op.GetAllPoints() polygons = op.GetAllPolygons() dest = c4d.PolygonObject(len(points), len(polygons)) dest.SetAllPoints(points) for i, p in enumerate(polygons): dest.SetPolygon(i, p) else: dest = op.GetClone(c4d.COPYFLAGS_0) doc.InsertObject(dest) dest.Message(c4d.MSG_UPDATE) return dest