"""Component aim hinge module"""
from mgear.shifter import component
from mgear.core import attribute, transform, primitive, applyop
import pymel.core as pm
##########################################################
COMPONENT
##########################################################
class Component(component.Main):
“”“Shifter component Class”""
# =====================================================
# OBJECTS
# =====================================================
def addObjects(self):
"""Add all the objects needed to create the component."""
self.root_pos = self.guide.tra["root"],
self.twist_aim_pos = self.guide.tra["twist_aim"],
self.swing_aim_pos = self.guide.tra["swing_aim"]
# Create joint driver groups and aim targets
self.twist_jnt_drv = primitive.addTransform(
self.root,
self.getName("twist_jnt_drv"),
self.root_pos
)
self.swing_jnt_drv = primitive.addTransform(
self.root,
self.getName("swing_jnt_drv"),
self.root_pos
)
self.twist_aim = primitive.addTransform(
self.root,
self.getName("twist_aim_grp"),
self.twist_aim_pos
)
self.swing_aim = primitive.addTransform(
self.root,
self.getName("swing_aim_grp"),
self.swing_aim_pos
)
self.jnt_pos.append([self.twist_jnt_drv, "twist", "parent_relative_jnt", False])
self.jnt_pos.append([self.swing_jnt_drv, "swing", None, False])
# =====================================================
# ATTRIBUTES
# =====================================================
def addAttributes(self):
"""Create the anim and setup rig attributes for the component"""
pass
# =====================================================
# OPERATORS
# =====================================================
def addOperators(self):
"""Create operators and set the relations for the component rig
Apply operators, constraints, expressions to the hierarchy.
In order to keep the code clean and easier to debug,
we shouldn't create any new object in this method.
"""
# aim gun ctl at gun target ctl
applyop.aimCns(
self.twist_jnt_drv,
self.twist_aim,
axis="zy",
wupType="object",
wupVector=[0, 1, 0],
wupObject=self.swing_aim,
maintainOffset=False
)
# aim gun joint group at gun control target group
applyop.aimCns(
self.swing_jnt_drv,
self.swing_aim,
axis="xy",
wupType="object",
wupVector=[0, 1, 0],
wupObject=self.twist_aim,
maintainOffset=False
)
# =====================================================
# CONNECTOR
# =====================================================
def setRelation(self):
"""Set the relation between object from guide to rig"""
self.relatives["root"] = self.twist_jnt_drv
self.relatives["twist_aim"] = self.twist_jnt_drv
self.relatives["swing_aim"] = self.swing_jnt_drv
self.controlRelatives = None
self.jointRelatives["root"] = 0
self.jointRelatives["swing_aim"] = 1
def addConnection(self):
"""Add more connection definition to the set"""
self.connections["standard"] = self.connect_standard
def connect_standard(self):
"""standard connection definition for the component"""
self.parent.addChild(self.root)
twist_aim_target = self.rig.findRelative(self.settings["twistAimTarget"])
swing_aim_target = self.rig.findRelative(self.settings["swingAimTarget"])
if pm.objExists(twist_aim_target):
pm.parentConstraint(twist_aim_target, self.twist_aim, mo=True)
if pm.objExists(swing_aim_target):
pm.parentConstraint(swing_aim_target, self.swing_aim, mo=True)