Proper way to bake deformed mesh after adjusting joints.
-
Howdy,
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
-
Hello @BretBays,
Thank you for reaching out to us. Your posting does not contain an explicit question; there is no question mark in it. There is an implied question of us implementing what you describe, but the MAXON SDK group cannot do that, implement feature descriptions provided by users. I would recommend having a look at our support guidelines regarding asking good technical questions and the scope of support.
About your Question
If you want to CTSO, just CTSO the object or join it, we have examples for both cases in the modeling commands section of the Python examples. The problem with your function is also that it makes quite a few assumptions which do not always hold true, it for example assumes that the deform cache of something is always found directly on an object in the object manager (which is only true for editable polygon objects). What the script is calling 'direct copy' might also lead to results the user does not consider to be a copy.
CSTO is the way to go to 'duplicate that deformed shape to a simple mesh with no deformer'. If the output is then not a singular object, you can join the output or a subset of it.
Cheers,
Ferdinand