Skip to content

Commit

Permalink
Bug Issues + Basic Support of Move by Maxon
Browse files Browse the repository at this point in the history
- Fixed Morphs becoming zero when applied at pass the maximum.
- Updated The Genesis 8.1 Facs Preset to represent the necessary morphs for Move By Maxon.
- Added an Option Automatic Weight the mesh when subdivision is present.
- Fixed Facs being Deleted on Children objects. where not needed too.
- Can now try out Move By Maxon and disconnect it head rotation is a wip.
  • Loading branch information
samjay3d committed May 31, 2021
1 parent 995bcd6 commit f79ca28
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 104 deletions.
10 changes: 10 additions & 0 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/CustomImports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import Utilities
from . import Morphs
from . import DazRig
from .DtC4DWeights import Weights
from .DtC4DPosing import Poses
from .DtC4DDialogs import guiASKtoSave
from .Definitions import EXPORT_DIR
Expand Down Expand Up @@ -61,6 +62,7 @@ def genesis_import(self, file_path, dtu, sss_value, normal_value, bump_value):
morph = Morphs.Morphs()
var = Utilities.Variables()
jnt_fixes = DazRig.JointFixes()
wgt = Weights()

if os.path.exists(file_path) == False:
gui.MessageDialog(
Expand Down Expand Up @@ -115,6 +117,14 @@ def genesis_import(self, file_path, dtu, sss_value, normal_value, bump_value):
print("Material Conversion Done")
c4d.EventAdd()

wgt.store_subdivision(dtu)
if wgt.check_level():
auto_weight = c4d.gui.QuestionDialog(
"Subdivisions have been detected\nthis is currently not fully supported.\nWould you like to autoweight the mesh?"
)
if auto_weight:
wgt.auto_calculate_weights(var.body)

isPosed = Poses().checkIfPosed()
if isPosed == False:
jnt_fixes.store_joint_orientations(dtu)
Expand Down
58 changes: 25 additions & 33 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .DtC4DPosing import Poses
from .Definitions import RES_DIR
from .Morphs import Morphs
from .MaxonTracking import Tracking

dazReduceSimilar = True

Expand Down Expand Up @@ -871,9 +872,9 @@ def find_face_captures(self):
obj = self.face_link.GetLink()
if obj.GetType() == 1040464:
c4d.MessageDialog(
"Do not connect the Face Capture\nCreate Pose Morphs first.",
type=c4d.GEMB_ICONEXCLAMATION,
)
"Do not connect the Face Capture\nCreate Pose Morphs first.",
type=c4d.GEMB_ICONEXCLAMATION,
)
if obj.GetTag(1040839):
self.face_link.SetLink(obj)

Expand Down Expand Up @@ -919,9 +920,7 @@ def CreateLayout(self):

self.GroupEnd()

self.GroupBegin(
11, c4d.BFH_SCALEFIT, 1, 1, title="Moves By Maxon: "
)
self.GroupBegin(11, c4d.BFH_SCALEFIT, 1, 1, title="Moves By Maxon: ")
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10, 5, 10, 5)

Expand All @@ -933,31 +932,26 @@ def CreateLayout(self):
350,
0,
)
self.GroupBegin(
11, c4d.BFH_SCALEFIT, 8, 1, title="Connect Face Capture: "
)
self.GroupBorder(c4d.BORDER_GROUP_OUT)
self.GroupBegin(11, c4d.BFH_SCALEFIT, 8, 1, title="Connect Face Capture: ")
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10, 5, 12, 5)

self.connect_morphs = self.AddButton(
self.BUTTON_CONNECT_MORPH,
c4d.BFV_TOP,
name="Connect Morphs"
)
self.disconnect_morphs = self.AddButton(
self.BUTTON_DISCONNECT_MORPH,
c4d.BFV_BOTTOM,
name="Disconnect Morphs"
self.BUTTON_CONNECT_MORPH, c4d.BFV_CENTER, name="Connect Morphs"
)
self.add_head_rotation = self.AddButton(
self.BUTTON_CONNECT_HEAD,
c4d.BFV_TOP,
name="Connect Head Rotation"
self.BUTTON_CONNECT_HEAD, c4d.BFV_CENTER, name="Connect Head Rotation"
)

self.GroupEnd()
self.GroupBegin(11, c4d.BFH_SCALEFIT, 8, 1, title="Connect Face Capture: ")
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10, 5, 12, 5)
self.disconnect_morphs = self.AddButton(
self.BUTTON_DISCONNECT_MORPH, c4d.BFV_CENTER, name="Disconnect Morphs"
)
self.disconnect_head_rotation = self.AddButton(
self.BUTTON_DISCONNECT_HEAD,
c4d.BFV_BOTTOM,
name="Disconnect Head Rotation"
self.BUTTON_DISCONNECT_HEAD, c4d.BFV_CENTER, name="Disconnect Head Rotation"
)
self.GroupEnd()
self.GroupEnd()
Expand Down Expand Up @@ -1236,25 +1230,25 @@ def Command(self, id, msg):
self.dazIkmControls = getJointFromConstraint(self.jointPelvis).GetUp()
IKMAXFastAttach.jointPelvis = self.jointPelvis

if id == self.BUTTON_CONNECT_MORPH:
if id == self.BUTTON_CONNECT_MORPH:
face_capture = self.face_link.GetLink()
Morphs.connect_face_morphs(face_capture)
self.morph_node, self.face_morphs = Morphs.connect_face_morphs(face_capture)

if id == self.BUTTON_DISCONNECT_MORPH:
if id == self.BUTTON_DISCONNECT_MORPH:
face_capture = self.face_link.GetLink()
Morphs.connect_face_morphs(face_capture)
Morphs.disconnect_face_morphs(self.face_morphs, self.morph_node)

if id == self.BUTTON_CONNECT_HEAD:
if id == self.BUTTON_CONNECT_HEAD:
face_capture = self.face_link.GetLink()

gui.MessageDialog("Feature is Currently Not Functional", c4d.GEMB_OK)
# Tracking.add_head_tracking(face_capture)

if id == self.IDC_LINKBOX_2:
self.find_face_captures()

# GUIDES
if dzc4d.findIK() == 1:


if id == self.BUTTON_RESET:
caca = ikmaxUtils().removeStuff()
if caca == 1:
Expand Down Expand Up @@ -1584,5 +1578,3 @@ def makeChild(child, parent):
)

return True


22 changes: 22 additions & 0 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtC4DWeights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import c4d


class Weights:
subdivsion_level = 0

def store_subdivision(self, dtu):
self.subdivsion_level = dtu.get_subdivision()

def check_level(self):
if self.subdivsion_level > 0:
return True

def auto_calculate_weights(self, body):
doc = c4d.documents.GetActiveDocument()
weight_tag = body.GetTag(c4d.Tweights)
if weight_tag:
doc.SetActiveTag(weight_tag, c4d.SELECTION_NEW)
c4d.modules.character.CAWeightMgr.Update(doc)
c4d.modules.character.CAWeightMgr.SelectAllJoints(doc)
c4d.modules.character.CAWeightMgr.AutoWeight(doc)
c4d.EventAdd()
10 changes: 10 additions & 0 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtuLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DtuLoader:
joint_orientation_dict = dict()
asset_name = ""
fbx_path = ""
subdivsion_level = ""
materials_list = []

def __init__(self, imported_dir):
Expand Down Expand Up @@ -61,6 +62,15 @@ def get_fbx_path(self):
self.load_fbx_path()
return self.fbx_path

def load_subdivision(self):
dtu_dict = self.get_dtu_dict()
self.subdivision = dtu_dict["Subdivision"]

def get_subdivision(self):
if self.subdivsion_level == "":
self.load_subdivision()
return self.subdivision

def load_bone_head_tail_dict(self):
dtu_dict = self.get_dtu_dict()
self.bone_head_tail_dict = dtu_dict["HeadTailData"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ def erc_multiply(addend, x, var):
erc_multiply = """
global var{1}
var{1} = {2}{1}))
if current > 0:
temp += var{1} * current + {0}
else:
temp *= var{1} + {0}
temp *= var{1} + {0}
""".format(
addend, x, var
)
Expand Down
47 changes: 47 additions & 0 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/MaxonTracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import c4d
from . import Utilities


class Tracking:
@staticmethod
def create_node(node_parent, obj, x, y):
node = node_parent.CreateNode(
node_parent.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, x, y
)
node[c4d.GV_OBJECT_OBJECT_ID] = obj
return node

@staticmethod
def create_xpresso_node(node_parent, type, x, y):
node = node_parent.CreateNode(node_parent.GetRoot(), type, None, x, y)
return node

@staticmethod
def add_head_tracking(face_capture):
"""Need to removed Hardcoding of Neck_Ctrl"""
neck_name = Utilities.get_daz_name() + "_Neck_ctrl"
doc = c4d.documents.GetActiveDocument()
neck_ctrl = doc.SearchObject(neck_name)
if neck_ctrl:
xpresso_tag = c4d.BaseTag(c4d.Texpresso)
# Set Tag priority to Animation
pd = xpresso_tag[c4d.EXPRESSION_PRIORITY]
pd.SetPriorityValue(c4d.PRIORITYVALUE_MODE, 1)
xpresso_tag[c4d.EXPRESSION_PRIORITY] = pd
xpresso_tag[c4d.ID_BASELIST_NAME] = "Movement Tracking"
neck_ctrl.InsertTag(xpresso_tag)
node_master = xpresso_tag.GetNodeMaster()
neck_node = Tracking.create_node(node_master, neck_ctrl, 600, 0)
face_node = Tracking.create_node(node_master, face_capture, 0, 0)
vect_real = Tracking.create_xpresso_node(
node_master, c4d.GV_VECT2REAL_, 100, 0
)
degrees_to_rad = Tracking.create_xpresso_node(
node_master, c4d.GV_DEGREE_, 200, 0
)
degrees_to_rad[c4d.GV_DEGREE_FUNCTION_ID] = c4d.GV_DEGREE2RAD_NODE_FUNCTION
math_node = Tracking.create_xpresso_node(node_master, c4d.GV_MATH_, 300, 0)
rad_to_degrees = Tracking.create_xpresso_node(
node_master, c4d.GV_DEGREE_, 400, 0
)
degrees_to_rad[c4d.GV_DEGREE_FUNCTION_ID] = c4d.GV_RAD2DEGREE_NODE_FUNCTION
19 changes: 12 additions & 7 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/Morphs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ntpath import join
import c4d
from c4d import utils, documents
from c4d import gui

from .CustomIterators import TagIterator
from . import ErcExpressions as erc
Expand Down Expand Up @@ -28,7 +29,6 @@ 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()
Expand All @@ -38,6 +38,7 @@ def find_facial_morph(face_morph_tag, morph_name):
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()
Expand All @@ -59,16 +60,20 @@ def connect_face_morphs(face_capture):
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
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,7 @@
oDtuJson["JointOrientation"] = s_oJointOrientation;
oDtuJson["LimitData"] = s_oLimitsData;
oDtuJson["PoseData"] = s_oPoseData;
oDtuJson["Subdivision"] = s_nSubDivLevel;

aFigureMats = writeMaterials( oNode, sDir );
oDtuJson["Materials"].push( aFigureMats );
Expand Down Expand Up @@ -2099,7 +2100,25 @@
}
return aControlledMeshes
}
/*********************************************************************/

// Array : Find if Bone Exists on Children Objects
function checkForMorphOnChild( oNode, aControlledMeshes, sMorphName )
{
for ( var i = 0; i < oNode.getNumNodeChildren(); i++ ){
oChildNode = oNode.getNodeChild( i );
if( oChildNode.inherits( "DzFigure" ) ){
oObject = oChildNode.getObject();
if( oObject ){
oModifer = oObject.findModifier( sMorphName );
if( oModifer ){
aControlledMeshes.pushIfNotExists( oChildNode.name + ".Shape" );
}
}
}
}
return aControlledMeshes
}

/*********************************************************************/
// Void : Load morph links that are directly controlled by skeleton bones
Expand Down Expand Up @@ -2162,7 +2181,8 @@
aControlledMeshes.pushIfNotExists( oMorphInfo.node.name + ".Shape" );
}
}

// Check for FACs Morphs on Children
aControlledMeshes = checkForMorphOnChild( oNode, aControlledMeshes, oMorphInfo.name )

var oMorphLinkObj = {
"Label": oMorphProperty.getLabel(),
Expand Down
Loading

0 comments on commit f79ca28

Please sign in to comment.