Skip to content

Commit

Permalink
Shifter: Data Collector: Track joint solvers inputs closes #127
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcampos committed May 20, 2022
1 parent 99829f3 commit 26eb363
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 55 deletions.
23 changes: 23 additions & 0 deletions release/scripts/mgear/shifter/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def addJoint(
vanilla_nodes=False,
leaf_joint=False,
guide_relative=None,
data_contracts=None,
):
"""Add joint as child of the active joint or under driver object.
Expand Down Expand Up @@ -317,6 +318,7 @@ def addJoint(
rot_off=rot_off,
leaf_joint=leaf_joint,
guide_relative=guide_relative,
data_contracts=data_contracts,
)

def _addJoint(
Expand All @@ -329,6 +331,7 @@ def _addJoint(
rot_off=None,
leaf_joint=False,
guide_relative=None,
data_contracts=None,
):
"""Add joint as child of the active joint or under driver object.
Expand Down Expand Up @@ -514,6 +517,10 @@ def _addJoint(
at = attribute.addAttribute(jnt, "guide_relative", "string")
at.set(guide_relative)

if data_contracts:
at = attribute.addAttribute(jnt, "data_contracts", "string")
at.set(data_contracts)

return jnt

# old method to allow the joint creation using Maya default nodes
Expand Down Expand Up @@ -1943,13 +1950,29 @@ def collect_build_data(self):
self.build_data["Controls"] = []
self.build_data["Ik"] = []
self.build_data["Twist"] = []
self.build_data["Squash"] = []

# joints
for j in self.jointList:
jnt_dict = {}
jnt_dict["Name"] = j.name()
jnt_dict.update(self.gather_transform_info(j))
self.build_data["Joints"].append(jnt_dict)
if j.hasAttr("data_contracts"):
for dc in j.data_contracts.get().split(","):
# check if the Data contract indentifier type is a valid
# data contract
if dc not in self.build_data.keys():
pm.displayWarning(
"{} is not a valid Data Contract Key".format(dc)
)
continue
# populate component active data contracts list
if dc not in self.build_data["DataContracts"]:
self.build_data["DataContracts"].append(dc)
# add joint Name to the corresponding data contract list
self.build_data[dc].append(j.name())

# controls
for c in self.controlers:
ctl_dict = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ def addObjects(self):
"obj": driver,
"name": jdn_upperarm,
"guide_relative": self.guide.guide_locators[0],
"data_contracts": "Ik",
}
)
current_parent = "root"
Expand All @@ -577,6 +578,7 @@ def addObjects(self):
"name": jdn_lowerarm,
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[1],
"data_contracts": "Ik",
}
)
twist_name = jdn_lowerarm_twist
Expand All @@ -591,6 +593,7 @@ def addObjects(self):
twist_name, twist_idx
),
"newActiveJnt": current_parent,
"data_contracts": "Twist,Squash",
}
)
twist_idx += increment
Expand All @@ -605,6 +608,7 @@ def addObjects(self):
"name": jdn_hand,
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[2],
"data_contracts": "Ik",
}
)

Expand Down Expand Up @@ -1163,12 +1167,3 @@ def connect_shoulder_01(self):
"""Custom connection to be use with shoulder 01 component"""
self.connect_standard()
pm.parent(self.rollRef[0], self.ikHandleUpvRef, self.parent_comp.ctl)

def collect_build_data(self):
component.Main.collect_build_data(self)
self.build_data["DataContracts"] = ["Ik"]
self.build_data["Ik"] = [
self.jointList[0].name(),
self.jointList[self.settings["div0"] + 1].name(),
self.jointList[-1].name(),
]
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def addObjects(self):
"obj": driver,
"name": jdn_thigh,
"guide_relative": self.guide.guide_locators[0],
"data_contracts": "Ik",
}
)
current_parent = "root"
Expand All @@ -465,6 +466,7 @@ def addObjects(self):
"name": jdn_calf,
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[1],
"data_contracts": "Ik",
}
)
twist_name = jdn_calf_twist
Expand All @@ -479,6 +481,7 @@ def addObjects(self):
twist_name, twist_idx
),
"newActiveJnt": current_parent,
"data_contracts": "Twist,Squash",
}
)
twist_idx += increment
Expand All @@ -500,6 +503,7 @@ def addObjects(self):
"name": jdn_foot,
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[2],
"data_contracts": "Ik",
}
)

Expand Down Expand Up @@ -888,12 +892,3 @@ def connect_standard(self):
[self.ctrn_loc],
False,
)

def collect_build_data(self):
component.Main.collect_build_data(self)
self.build_data["DataContracts"] = ["Ik"]
self.build_data["Ik"] = [
self.jointList[0].name(),
self.jointList[self.settings["div0"] + 1].name(),
self.jointList[-1].name(),
]
Original file line number Diff line number Diff line change
Expand Up @@ -554,32 +554,56 @@ def addObjects(self):

# setting the joints
if i == 0:
self.jnt_pos.append([driver, "upperarm"])
self.jnt_pos.append(
{
"obj": driver,
"name": "upperarm",
"guide_relative": self.guide.guide_locators[0],
"data_contracts": "Ik",
}
)
current_parent = "root"
twist_name = "upperarm_twist_"
twist_idx = 1
increment = 1
elif i == self.settings["div0"] + 1:
self.jnt_pos.append([driver, "lowerarm", current_parent])
self.jnt_pos.append(
{
"obj": driver,
"name": "lowerarm",
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[1],
"data_contracts": "Ik",
}
)
twist_name = "lowerarm_twist_"
current_parent = "elbow"
twist_idx = self.settings["div1"]
increment = -1
else:
self.jnt_pos.append(
[
driver,
twist_name + str(twist_idx).zfill(2),
current_parent,
]
{
"obj": driver,
"name": twist_name + str(twist_idx).zfill(2),
"newActiveJnt": current_parent,
"data_contracts": "Twist,Squash",
}
)
twist_idx += increment

if self.settings["use_blade"]:
eff_loc = self.eff_jnt_off
else:
eff_loc = self.eff_loc
self.jnt_pos.append([eff_loc, "hand", current_parent])
self.jnt_pos.append(
{
"obj": eff_loc,
"name": "hand",
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[2],
"data_contracts": "Ik",
}
)

# match IK FK references
self.match_fk0_off = self.add_match_ref(
Expand Down Expand Up @@ -1140,12 +1164,3 @@ def connect_shoulder_01(self):
"""Custom connection to be use with shoulder 01 component"""
self.connect_standard()
pm.parent(self.rollRef[0], self.ikHandleUpvRef, self.parent_comp.ctl)

def collect_build_data(self):
component.Main.collect_build_data(self)
self.build_data["DataContracts"] = ["ik"]
self.build_data["ik"] = [
self.jointList[0].name(),
self.jointList[self.settings["div0"] + 1].name(),
self.jointList[-1].name(),
]
Original file line number Diff line number Diff line change
Expand Up @@ -451,24 +451,40 @@ def addObjects(self):

# setting the joints
if i == 0:
self.jnt_pos.append([driver, "thigh"])
self.jnt_pos.append(
{
"obj": driver,
"name": "thigh",
"guide_relative": self.guide.guide_locators[0],
"data_contracts": "Ik",
}
)
current_parent = "root"
twist_name = "thigh_twist_"
twist_idx = 1
increment = 1
elif i == self.settings["div0"] + 1:
self.jnt_pos.append([driver, "calf", current_parent])
self.jnt_pos.append(
{
"obj": driver,
"name": "calf",
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[1],
"data_contracts": "Ik",
}
)
twist_name = "calf_twist_"
current_parent = "knee"
twist_idx = self.settings["div1"]
increment = -1
else:
self.jnt_pos.append(
[
driver,
twist_name + str(twist_idx).zfill(2),
current_parent,
]
{
"obj": driver,
"name": twist_name + str(twist_idx).zfill(2),
"newActiveJnt": current_parent,
"data_contracts": "Twist,Squash",
}
)
twist_idx += increment

Expand All @@ -483,7 +499,15 @@ def addObjects(self):
)
if self.up_axis == "z":
self.end_jnt_off.rz.set(-90)
self.jnt_pos.append([self.end_jnt_off, "foot", current_parent])
self.jnt_pos.append(
{
"obj": self.end_jnt_off,
"name": "foot",
"newActiveJnt": current_parent,
"guide_relative": self.guide.guide_locators[2],
"data_contracts": "Ik",
}
)

# match IK FK references
self.match_fk0_off = self.add_match_ref(
Expand Down Expand Up @@ -870,12 +894,3 @@ def connect_standard(self):
[self.ctrn_loc],
False,
)

def collect_build_data(self):
component.Main.collect_build_data(self)
self.build_data["DataContracts"] = ["ik"]
self.build_data["ik"] = [
self.jointList[0].name(),
self.jointList[self.settings["div0"] + 1].name(),
self.jointList[-1].name(),
]
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def addObjects(self):
jdn_neck, i + 1
),
"guide_relative": guide_relative,
"data_contracts": "Twist,Squash",
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def addObjects(self):
"obj": scl_ref,
"name": string.replaceSharpWithPadding(jdn_spine, i + 1),
"guide_relative": guide_relative,
"data_contracts": "Twist,Squash",
}
)

Expand Down Expand Up @@ -439,6 +440,7 @@ def addObjects(self):
"obj": self.cnx1,
"name": string.replaceSharpWithPadding(jdn_spine, i + 2),
"guide_relative": self.guide.guide_locators[-1],
"data_contracts": "Twist,Squash",
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def addObjects(self):
self.hip_lvl = primitive.addTransform(
self.ik0_ctl, self.getName("hip_lvl"), t
)
self.jnt_pos.append([self.hip_lvl, "pelvis"])
self.jnt_pos.append(
{
"obj": self.hip_lvl,
"name": "pelvis",
"guide_relative": self.guide.guide_locators[0],
}
)

t = transform.setMatrixPosition(t, self.guide.apos[-1])
if self.settings["autoBend"]:
Expand Down Expand Up @@ -381,8 +387,20 @@ def addObjects(self):
self.scl_transforms.append(scl_ref)

# Deformers (Shadow)
# self.jnt_pos.append([scl_ref, i])
self.jnt_pos.append([scl_ref, "spine_" + str(i + 1).zfill(2)])
if i == 0:
guide_relative = self.guide.guide_locators[1]
elif i == self.settings["division"] - 1:
guide_relative = self.guide.guide_locators[-2]
else:
guide_relative = None
self.jnt_pos.append(
{
"obj": scl_ref,
"name": "spine_" + str(i + 1).zfill(2),
"guide_relative": guide_relative,
"data_contracts": "Twist,Squash",
}
)

# Twist references (This objects will replace the spinlookup
# slerp solver behavior)
Expand Down

0 comments on commit 26eb363

Please sign in to comment.