From 3d9a300807e0ac41a7ef56bba20c86213e554118 Mon Sep 17 00:00:00 2001 From: samjay3d <71744685+samjay3d@users.noreply.github.com> Date: Mon, 31 May 2021 09:00:50 -0700 Subject: [PATCH] Code Refactor + Version Added --- .../plugins/DazToC4D/lib/DtC4DWindow.py | 2 +- .../plugins/DazToC4D/lib/MaxonTracking.py | 47 ++++++++++++++++++ .../plugins/DazToC4D/lib/Morphs.py | 48 +------------------ .../scripts/support/DAZ/Daz to Cinema 4D.dsa | 2 +- 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DWindow.py b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DWindow.py index d248bf3..c5305bb 100644 --- a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DWindow.py +++ b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DWindow.py @@ -122,7 +122,7 @@ def buttonBC(self, tooltipText="", presetLook=""): return bc def CreateLayout(self): - self.SetTitle("DazToC4D v1.2.0 Beta") + self.SetTitle("DazToC4D v1.2.1 Beta") self.AddSeparatorH(c4d.BFV_SCALEFIT) # Separator H bc = c4d.BaseContainer() # Create a new container to store the button image diff --git a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/MaxonTracking.py b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/MaxonTracking.py index e50d73f..862b5bb 100644 --- a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/MaxonTracking.py +++ b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/MaxonTracking.py @@ -45,3 +45,50 @@ def add_head_tracking(face_capture): node_master, c4d.GV_DEGREE_, 400, 0 ) degrees_to_rad[c4d.GV_DEGREE_FUNCTION_ID] = c4d.GV_RAD2DEGREE_NODE_FUNCTION + + @staticmethod + def find_facial_morph(face_morph_tag, morph_name): + morph_amount = face_morph_tag.GetMorphCount() + for x in range(morph_amount): + face_morph_tag.SetActiveMorphIndex(x) + morph = face_morph_tag.GetActiveMorph() + face_morph_name = morph.GetName() + if set(face_morph_name.split(" ")) == set(morph_name.split(" ")): + return face_morph_tag.GetMorphID(x) + + @staticmethod + def connect_face_morphs(face_capture): + """Connects to the Move By Maxon Animation""" + doc = c4d.documents.GetActiveDocument() + morph_obj = doc.SearchObject("Daz Morphs Controller") + morph_tag = morph_obj.GetTag(c4d.Tposemorph) + face_morph_tag = face_capture.GetTag(c4d.Tposemorph) + xpresso_tag = morph_obj.GetTag(c4d.Texpresso) + node_master = xpresso_tag.GetNodeMaster() + morph_master_output = Tracking.create_node(node_master, morph_tag, -1000, 100) + facial_node = Tracking.create_node(node_master, face_morph_tag, -1200, 100) + if morph_tag: + morph_amount = morph_tag.GetMorphCount() + for x in range(morph_amount): + morph_tag.SetActiveMorphIndex(x) + morph = morph_tag.GetActiveMorph() + morph_name = morph.GetName() + blend_shape = Tracking.find_facial_morph(face_morph_tag, morph_name) + if blend_shape: + morph_num = morph_tag.GetMorphID(x) + morph_input = morph_master_output.AddPort( + c4d.GV_PORT_INPUT, morph_num + ) + facial_output = facial_node.AddPort(c4d.GV_PORT_OUTPUT, blend_shape) + facial_output.Connect(morph_input) + + return morph_master_output, facial_node + + @staticmethod + def disconnect_face_morphs(face_node, morph_node): + """Remove the Connection to the Move By Maxon Animation""" + face_node.Remove() + morph_node.Remove() + c4d.gui.MessageDialog( + "Face Capture Has been Successfully Removed!", type=c4d.GEMB_OK + ) diff --git a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/Morphs.py b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/Morphs.py index e0acd53..8cc4b4f 100644 --- a/Cinema 4D/appdir_common/plugins/DazToC4D/lib/Morphs.py +++ b/Cinema 4D/appdir_common/plugins/DazToC4D/lib/Morphs.py @@ -16,6 +16,7 @@ def __init__(self): @staticmethod def create_null_for_morphs(body): + """Create a null to hold the Morphs for the Daz Pose Morph""" doc = documents.GetActiveDocument() morph_tag = body.GetTag(c4d.Tposemorph) xpresso_tag = body.GetTag(c4d.Texpresso) @@ -29,54 +30,9 @@ def create_null_for_morphs(body): c4d.EventAdd() return null - @staticmethod - def find_facial_morph(face_morph_tag, morph_name): - morph_amount = face_morph_tag.GetMorphCount() - for x in range(morph_amount): - face_morph_tag.SetActiveMorphIndex(x) - morph = face_morph_tag.GetActiveMorph() - face_morph_name = morph.GetName() - if set(face_morph_name.split(" ")) == set(morph_name.split(" ")): - return face_morph_tag.GetMorphID(x) - - @staticmethod - def connect_face_morphs(face_capture): - doc = documents.GetActiveDocument() - morph_obj = doc.SearchObject("Daz Morphs Controller") - morph_tag = morph_obj.GetTag(c4d.Tposemorph) - face_morph_tag = face_capture.GetTag(c4d.Tposemorph) - print(face_morph_tag) - xpresso_tag = morph_obj.GetTag(c4d.Texpresso) - node_master = xpresso_tag.GetNodeMaster() - morph_master_output = Morphs().create_node(node_master, morph_tag, -1000, 100) - facial_node = Morphs().create_node(node_master, face_morph_tag, -1200, 100) - if morph_tag: - morph_amount = morph_tag.GetMorphCount() - for x in range(morph_amount): - morph_tag.SetActiveMorphIndex(x) - morph = morph_tag.GetActiveMorph() - morph_name = morph.GetName() - blend_shape = Morphs.find_facial_morph(face_morph_tag, morph_name) - if blend_shape: - morph_num = morph_tag.GetMorphID(x) - morph_input = morph_master_output.AddPort( - c4d.GV_PORT_INPUT, morph_num - ) - facial_output = facial_node.AddPort(c4d.GV_PORT_OUTPUT, blend_shape) - facial_output.Connect(morph_input) - - return morph_master_output, facial_node - - @staticmethod - def disconnect_face_morphs(face_node, morph_node): - face_node.Remove() - morph_node.Remove() - c4d.gui.MessageDialog( - "Face Capture Has been Successfully Removed!", type=c4d.GEMB_OK - ) - @staticmethod def move_poses_under_morphs(group, poses): + """Move the Poses (Morphs) to the Morph Group""" for pose in poses: if pose and group: pose.InsertUnder(group) diff --git a/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa b/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa index 055907d..2c20b19 100644 --- a/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa +++ b/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa @@ -2102,7 +2102,7 @@ } /*********************************************************************/ - // Array : Find if Bone Exists on Children Objects + // Array : Find if Morph Exists on Children, Useful for FACS function checkForMorphOnChild( oNode, aControlledMeshes, sMorphName ) { for ( var i = 0; i < oNode.getNumNodeChildren(); i++ ){