コード例 #1
0
    def test_operation_priority(self):
        v = libFormula.parse("a+3*(6+(3*b))", a=4, b=7)
        self.assertEqual(v, 85)

        # usage of '-'
        v = libFormula.parse("-2^1.0*-1.0+3.3")
        self.assertEqual(v, 5.3)

        # usage of '-'
        v = libFormula.parse("-2*(1.0-(3^(3*-1.0)))")
        self.assertAlmostEqual(v, -1.925925925925926)
コード例 #2
0
    def test_operation_priority(self):
        v = libFormula.parse("a+3*(6+(3*b))", a=4, b=7)
        self.assertEqual(v, 85)

        # usage of '-'
        v = libFormula.parse("-2^1.0*-1.0+3.3")
        self.assertEqual(v, 5.3)

        # usage of '-'
        v = libFormula.parse("-2*(1.0-(3^(3*-1.0)))")
        self.assertAlmostEqual(v, -1.925925925925926)
コード例 #3
0
ファイル: rigIK.py プロジェクト: SqueezeStudioAnimation/omtk
    def setup_softik(self, ik_handle_to_constraint, stretch_chains):
        """
        Setup the softik system a ik system
        :param ik_handle_to_constraint: A list of ik handles to constraint on the soft-ik network.
        :param stretch_chains: A list of chains to connect the stretch to.
        :return: Nothing
        """
        nomenclature_rig = self.get_nomenclature_rig()

        oAttHolder = self.ctrl_ik
        fnAddAttr = functools.partial(libAttr.addAttr, hasMinValue=True, hasMaxValue=True)
        attInRatio = fnAddAttr(oAttHolder, longName='softIkRatio', niceName='SoftIK', defaultValue=0, minValue=0,
                               maxValue=50, k=True)
        attInStretch = fnAddAttr(oAttHolder, longName='stretch', niceName='Stretch', defaultValue=0, minValue=0,
                                 maxValue=1.0, k=True)
        # Adjust the ratio in percentage so animators understand that 0.03 is 3%
        attInRatio = libRigging.create_utility_node('multiplyDivide', input1X=attInRatio, input2X=0.01).outputX

        # Create and configure SoftIK solver
        soft_ik_network_name = nomenclature_rig.resolve('softik')
        soft_ik_network = SoftIkNode()
        soft_ik_network.build(name=soft_ik_network_name)
        soft_ik_network.setParent(self.grp_rig)

        pymel.connectAttr(attInRatio, soft_ik_network.inRatio)
        pymel.connectAttr(attInStretch, soft_ik_network.inStretch)
        pymel.connectAttr(self._ikChainGrp.worldMatrix, soft_ik_network.inMatrixS)
        pymel.connectAttr(self._ik_handle_target.worldMatrix, soft_ik_network.inMatrixE)
        attr_distance = libFormula.parse('distance*globalScale',
                                         distance=self.chain_length,
                                         globalScale=self.grp_rig.globalScale)
        pymel.connectAttr(attr_distance, soft_ik_network.inChainLength)

        attOutRatio = soft_ik_network.outRatio
        attOutRatioInv = libRigging.create_utility_node('reverse', inputX=soft_ik_network.outRatio).outputX
        # TODO: Improve softik ratio when using multiple ik handle. Not the same ratio will be used depending of the angle
        for handle in ik_handle_to_constraint:
            pointConstraint = pymel.pointConstraint(self._ik_handle_target, self._ikChainGrp, handle)
            pointConstraint.rename(pointConstraint.stripNamespace().replace('pointConstraint', 'softIkConstraint'))
            weight_inn, weight_out = pointConstraint.getWeightAliasList()[-2:]  # Ensure to get the latest target added
            pymel.connectAttr(attOutRatio, weight_inn)
            pymel.connectAttr(attOutRatioInv, weight_out)

        # Connect stretch
        for stretch_chain in stretch_chains:
            for i in range(1, self.iCtrlIndex + 1):
                obj = stretch_chain[i]
                util_get_t = libRigging.create_utility_node(
                    'multiplyDivide',
                    input1X=soft_ik_network.outStretch,
                    input1Y=soft_ik_network.outStretch,
                    input1Z=soft_ik_network.outStretch,
                    input2=obj.t.get()
                )
                pymel.connectAttr(util_get_t.outputX, obj.tx, force=True)
                pymel.connectAttr(util_get_t.outputY, obj.ty, force=True)
                pymel.connectAttr(util_get_t.outputZ, obj.tz, force=True)

        return soft_ik_network
コード例 #4
0
 def test_add_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(1, 2, 3)
     result = libFormula.parse('a+b+c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 6)
コード例 #5
0
 def test_div(self):
     v = libFormula.parse('6/2')
     self.assertEqual(v, 3)
コード例 #6
0
 def test_mul(self):
     v = libFormula.parse('2*3')
     self.assertEqual(v, 6)
コード例 #7
0
 def test_sub(self):
     v = libFormula.parse('5-3')
     self.assertEqual(v, 2)
コード例 #8
0
 def test_add(self):
     v = libFormula.parse('2+3')
     self.assertEqual(v, 5)
コード例 #9
0
 def test_sub(self):
     v = libFormula.parse('5-3')
     self.assertEqual(v, 2)
コード例 #10
0
 def test_mul_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(2, 3, 4)
     result = libFormula.parse('a*b*c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 24)
コード例 #11
0
 def test_sub_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(8, 2, 1)
     result = libFormula.parse('a-b-c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 5)
コード例 #12
0
 def test_add_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(1, 2, 3)
     result = libFormula.parse('a+b+c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 6)
コード例 #13
0
 def test_div(self):
     v = libFormula.parse('6/2')
     self.assertEqual(v, 3)
コード例 #14
0
 def test_mul(self):
     v = libFormula.parse('2*3')
     self.assertEqual(v, 6)
コード例 #15
0
 def test_sub_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(8, 2, 1)
     result = libFormula.parse('a-b-c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 5)
コード例 #16
0
    def setup_softik(self, ik_handle_to_constraint, stretch_chain):
        """
        Setup the softik system a ik system
        :param ik_handle_to_constraint: The ik handle to constraint on the soft ik network (Can be more than one)
        :param stretch_chain: The chain on which the stretch will be connected
        :return: Nothing
        """
        nomenclature_rig = self.get_nomenclature_rig()

        oAttHolder = self.ctrl_ik
        fnAddAttr = functools.partial(libAttr.addAttr,
                                      hasMinValue=True,
                                      hasMaxValue=True)
        attInRatio = fnAddAttr(oAttHolder,
                               longName='softIkRatio',
                               niceName='SoftIK',
                               defaultValue=0,
                               minValue=0,
                               maxValue=50,
                               k=True)
        attInStretch = fnAddAttr(oAttHolder,
                                 longName='stretch',
                                 niceName='Stretch',
                                 defaultValue=0,
                                 minValue=0,
                                 maxValue=1.0,
                                 k=True)
        # Adjust the ratio in percentage so animators understand that 0.03 is 3%
        attInRatio = libRigging.create_utility_node('multiplyDivide',
                                                    input1X=attInRatio,
                                                    input2X=0.01).outputX

        # Create and configure SoftIK solver
        soft_ik_network_name = nomenclature_rig.resolve('softik')
        soft_ik_network = SoftIkNode()
        soft_ik_network.build(name=soft_ik_network_name)
        soft_ik_network.setParent(self.grp_rig)

        pymel.connectAttr(attInRatio, soft_ik_network.inRatio)
        pymel.connectAttr(attInStretch, soft_ik_network.inStretch)
        pymel.connectAttr(self._ikChainGrp.worldMatrix,
                          soft_ik_network.inMatrixS)
        pymel.connectAttr(self._ik_handle_target.worldMatrix,
                          soft_ik_network.inMatrixE)
        attr_distance = libFormula.parse('distance*globalScale',
                                         distance=self.chain_length,
                                         globalScale=self.grp_rig.globalScale)
        pymel.connectAttr(attr_distance, soft_ik_network.inChainLength)

        attOutRatio = soft_ik_network.outRatio
        attOutRatioInv = libRigging.create_utility_node(
            'reverse', inputX=soft_ik_network.outRatio).outputX
        #TODO: Improve softik ratio when using multiple ik handle. Not the same ratio will be used depending of the angle
        for handle in ik_handle_to_constraint:
            pointConstraint = pymel.pointConstraint(self._ik_handle_target,
                                                    self._ikChainGrp, handle)
            pointConstraint.rename(pointConstraint.name().replace(
                'pointConstraint', 'softIkConstraint'))
            weight_inn, weight_out = pointConstraint.getWeightAliasList()[
                -2:]  #Ensure to get the latest target added
            pymel.connectAttr(attOutRatio, weight_inn)
            pymel.connectAttr(attOutRatioInv, weight_out)

        # Connect stretch
        for i in range(1, self.iCtrlIndex + 1):
            obj = stretch_chain[i]
            util_get_t = libRigging.create_utility_node(
                'multiplyDivide',
                input1X=soft_ik_network.outStretch,
                input1Y=soft_ik_network.outStretch,
                input1Z=soft_ik_network.outStretch,
                input2=obj.t.get())
            pymel.connectAttr(util_get_t.outputX, obj.tx, force=True)
            pymel.connectAttr(util_get_t.outputY, obj.ty, force=True)
            pymel.connectAttr(util_get_t.outputZ, obj.tz, force=True)

        return soft_ik_network
コード例 #17
0
 def test_mul_pymel(self):
     a, b, c, _, _, _, _, _, _ = self._create_pymel_attrs(2, 3, 4)
     result = libFormula.parse('a*b*c', a=a, b=b, c=c)
     self.assertEqual(result.get(), 24)
コード例 #18
0
 def test_add(self):
     v = libFormula.parse('2+3')
     self.assertEqual(v, 5)