Adding a Morph Deformer Causes Pose Morph Tag to Stop Working
-
Hello all, I've noticed that my Pose Morph tag stops working after I add a Morph Deformer. It seems that I can't replicate the manual process of adding the Morph Deformer. What might I be doing wrong?
The main function of the code is to copy the selected object, then add a pose morph, and set the target to the selected object. The reason for adding the Morph Deformer is that I can offset issues with priority lag. However, in the code, once I add the Morph Deformer, the Pose Morph stops workingimport c4d def copyObj(obj): _copyObj = obj.GetClone(); doc.AddUndo(c4d.UNDOTYPE_NEW, _copyObj) _copyObj.SetName('{}_copy'.format(obj.GetName())) _copyObj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 2 _copyObj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2 doc.InsertObject(_copyObj); _copyObj.InsertAfter(obj) for tag in _copyObj.GetTags(): if isinstance(tag, c4d.modules.character.CAWeightTag): tag.Remove() for child in _copyObj.GetChildren(): if child.CheckType(c4d.Oskin): child.Remove() return _copyObj def addPoseMorph(target, obj): pmTag = obj.MakeTag(1024237) priorityData = c4d.PriorityData() priorityData.SetPriorityValue(c4d.PRIORITYVALUE_MODE, c4d.CYCLE_INITIAL) pmTag[c4d.ID_CA_POSE_BASE_PRI] = priorityData pmTag[c4d.ID_CA_POSE_POINTS] = 1 baseMorph = pmTag.AddMorph() # id0 targetMorph = pmTag.AddMorph() # id1 pmTag.UpdateMorphs() targetMorph.SetName('target') pmTag.SetActiveMorphIndex(1) pmTag[c4d.ID_CA_POSE_TARGET] = target pmTag[c4d.ID_CA_POSE_MODE] = 1 return pmTag def addMorphDeformer(obj, tag): morph = c4d.BaseObject(1019768) morph.InsertUnder(obj) morph[c4d.ID_CA_MORPH_DEFORMER_OBJECT_TAG] = tag morph[c4d.ID_CA_MORPH_DEFORMER_OBJECT_APPLY_BASEPOSE] = True def create(): sel = doc.GetSelection() if not sel: return doc.StartUndo() for o in sel: doc.AddUndo(c4d.UNDOTYPE_CHANGE, o) o[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 o[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1 cObj = copyObj(o) pmTag = addPoseMorph(o, cObj) addMorphDeformer(cObj, pmTag) doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': create()
-
test file
-
Hello everyone, I seem to have found a solution. You just need to go to the Falloff option in Morph and add a default parameter
data = c4d.FieldList() morph[c4d.FIELDS] = data
This way, the PoseMorph tag becomes effective. I still don't understand why this is necessary, as I can't find any python related content about the Morph deformer:(
-
Hi @kangddan,
Thanks for providing such a good reference for reproducing the issue!
Looks like you're missing the initialization and finalizing phases of creating the morph tag, hence you end up with invalid (or not updated) one. Executing the following functions in the correct order seems to fix your issue. Please have a look at InitMorphs(), UpdateMorphs() and ExitEdit().
Please find the corrected addPoseMorph() function below.
Regarding the falloff option, I assume it implicitly calls UpdateMorphs() function, which updates the morph tag, hence you have it in working state.
Cheers,
IliaPS There's no need to insert object to document first, if you later insert it after another object that's already in document, or in other words the
doc.InsertObject(_copyObj)
call is redundant.The corrected addPoseMorph function code snippet:
def addPoseMorph(target, obj): pmTag = obj.MakeTag(1024237) pmTag[c4d.ID_CA_POSE_POINTS] = 1 pmTag.InitMorphs() priorityData = c4d.PriorityData() priorityData.SetPriorityValue(c4d.PRIORITYVALUE_MODE, c4d.CYCLE_INITIAL) pmTag[c4d.ID_CA_POSE_BASE_PRI] = priorityData baseMorph = pmTag.AddMorph() # id0 targetMorph = pmTag.AddMorph() # id1 targetMorph.SetName('target') pmTag.SetActiveMorphIndex(1) pmTag[c4d.ID_CA_POSE_TARGET] = target pmTag.ExitEdit(doc, False) # switch to "Animate Mode" pmTag.UpdateMorphs() return pmTag
-
This post is deleted! -
Thank u @i_mazlov
I appreciate you pointing me in the right direction. I will try to understand the workings behind the posemorph tag!