def build(self, stretch=True, squash=False, *args, **kwargs): # TODO: Use self.chain_jnt self._joints = [input for input in self.input if libPymel.isinstance_of_transform(input, pymel.nodetypes.Joint)] self._curves = [input for input in self.input if libPymel.isinstance_of_shape(input, pymel.nodetypes.CurveShape)] if len(self._joints) < 2: raise Exception("Can't build SplineIK. Expected at least two joints, got {0}".format(self._joints)) if len(self._curves) < 1: raise Exception("Can't build SplineIK. Expected at least one nurbsCurve, got {0}".format(self._curves)) super(SplineIK, self).build(*args, **kwargs) nomenclature_rig = self.get_nomenclature_rig() # todo: handle multiple curves? curve = next(iter(self._curves), None) curve_shape = next((shape for shape in curve.getShapes() if isinstance(shape, pymel.nodetypes.NurbsCurve)), None) # Create ik solver handle_name = nomenclature_rig.resolve('ikHandle') eff_name = nomenclature_rig.resolve('ikEffector') self.ikHandle, self.ikEffector = pymel.ikHandle( solver="ikSplineSolver", curve=curve, startJoint=self._joints[0], endEffector=self._joints[-1], createCurve=False, name=handle_name, parentCurve=False, snapCurve=False) self.ikHandle.setParent(self.grp_rig) self.ikEffector.rename(eff_name) # Create stretch # Todo: use shape instead of transform as curve input? if stretch: stretch_attr = libRigging.create_strech_attr_from_curve(curve_shape) for jnt in self._joints: pymel.connectAttr(stretch_attr, jnt.sx, force=True) # Create squash if squash: num_joints = len(self._joints) squash_attrs = libRigging.create_squash_atts(stretch_attr, num_joints) # Todo: Find correct axis orient for jnt, squash in zip(self._joints, squash_attrs): pymel.connectAttr(squash, jnt.sy, force=True) pymel.connectAttr(squash, jnt.sz, force=True)
def build(self, *args, **kwargs): self._post_setattr_inputs() # update hack if len(self._joints) < 2: raise Exception("Can't build SplineIK. Expected at least two joints, got {0}".format(self._joints)) if len(self._curves) < 1: raise Exception("Can't build SplineIK. Expected at least one nurbsCurve, got {0}".format(self._curves)) super(SplineIK, self).build(*args, **kwargs) # todo: handle multiple curves? curve = self._curves[0] curveShape = next((shape for shape in curve.getShapes() if isinstance(shape, pymel.nodetypes.NurbsCurve)), None) # create splineik effector # todo: search for additional options name_kEffector = self._pNameMapRig.Serialize('ikEffector') self.ikHandle, self.ikEffector = pymel.ikHandle( solver="ikSplineSolver", curve=curve, startJoint=self._joints[0], endEffector=self._joints[-1], createCurve=False, name=name_kEffector, parentCurve=False, snapCurve=False) self.ikHandle.setParent(self.grp_rig) # Create stretch # Todo: use shape instead of transform as curve input? curveLength = libRigging.CreateUtilityNode('curveInfo', inputCurve=curveShape.worldSpace).arcLength self.stretch_att = libRigging.CreateUtilityNode('multiplyDivide', operation=2, input1X=curveLength, input2X=curveLength.get()).outputX # Create squash num_joints = len(self._joints) squash_atts = libRigging.create_squash_atts(self.stretch_att, num_joints) # Connect stretch/squash # Todo: Find correct axis orient for jnt, squash in zip(self._joints, squash_atts): pymel.connectAttr(self.stretch_att, jnt.sx) pymel.connectAttr(squash, jnt.sy) pymel.connectAttr(squash, jnt.sz)
def build(self, stretch=True, squash=False, *args, **kwargs): # TODO: Use self.chain_jnt self._joints = [ input for input in self.input if libPymel.isinstance_of_transform(input, pymel.nodetypes.Joint) ] self._curves = [ input for input in self.input if libPymel.isinstance_of_shape(input, pymel.nodetypes.CurveShape) ] if len(self._joints) < 2: raise Exception( "Can't build SplineIK. Expected at least two joints, got {0}". format(self._joints)) if len(self._curves) < 1: raise Exception( "Can't build SplineIK. Expected at least one nurbsCurve, got {0}" .format(self._curves)) super(SplineIK, self).build(*args, **kwargs) nomenclature_rig = self.get_nomenclature_rig() # todo: handle multiple curves? curve = next(iter(self._curves), None) curve_shape = next((shape for shape in curve.getShapes() if isinstance(shape, pymel.nodetypes.NurbsCurve)), None) # Create ik solver handle_name = nomenclature_rig.resolve('ikHandle') eff_name = nomenclature_rig.resolve('ikEffector') self.ikHandle, self.ikEffector = pymel.ikHandle( solver="ikSplineSolver", curve=curve, startJoint=self._joints[0], endEffector=self._joints[-1], createCurve=False, name=handle_name, parentCurve=False, snapCurve=False) self.ikHandle.setParent(self.grp_rig) self.ikEffector.rename(eff_name) # Create stretch # Todo: use shape instead of transform as curve input? if stretch: stretch_attr = libRigging.create_strech_attr_from_curve( curve_shape) for jnt in self._joints: pymel.connectAttr(stretch_attr, jnt.sx, force=True) # Create squash if squash: num_joints = len(self._joints) squash_attrs = libRigging.create_squash_atts( stretch_attr, num_joints) # Todo: Find correct axis orient for jnt, squash in zip(self._joints, squash_attrs): pymel.connectAttr(squash, jnt.sy, force=True) pymel.connectAttr(squash, jnt.sz, force=True)