Example #1
0
    def test_abs(self):
        v = Nodex(-15.0)
        v = Math.abs(v)
        self.assertEqual(v.value(), 15)

        v = Nodex([-23, -100, -45])
        v = Math.abs(v)
        self.assertTrue(v.value().isEquivalent(pymel.core.datatypes.Vector(23, 100, 45)))

        v = Nodex([12.5, -9999, -9.9])
        v = Math.abs(v)
        print v.value()
        self.assertTrue(v.value().isEquivalent(pymel.core.datatypes.Vector(12.5, 9999, 9.9), tol=0.01))
Example #2
0
    def test_scene1(self):
        mc.file(new=True, force=True)
        sphere1 = pymel.core.polySphere()[0]
        sphere1.setTranslation((10, 0, 0))
        sphere2 = pymel.core.polySphere()[0]

        print sphere1.getTranslation()

        from nodex.core import Nodex, Math

        # free position
        target = Nodex('pSphere1.translate')

        # limited position (5.0 units from origin)
        targetMax = target.normal() * 5.0

        # add a condition (so we use the limited targetMax position if the target is further away than 5.0 units)
        distanceFromOrigin = target.length()
        conditionOutput = Math.greaterThan(distanceFromOrigin,
                                           5.0,
                                           ifTrue=targetMax,
                                           ifFalse=target)

        conditionOutput.connect('pSphere2.translate')

        print sphere2.getTranslation()
Example #3
0
    def test_abs(self):
        v = Nodex(-15.0)
        v = Math.abs(v)
        self.assertEqual(v.value(), 15)

        v = Nodex([-23, -100, -45])
        v = Math.abs(v)
        self.assertTrue(v.value().isEquivalent(
            pymel.core.datatypes.Vector(23, 100, 45)))

        v = Nodex([12.5, -9999, -9.9])
        v = Math.abs(v)
        print v.value()
        self.assertTrue(v.value().isEquivalent(pymel.core.datatypes.Vector(
            12.5, 9999, 9.9),
                                               tol=0.01))
Example #4
0
    def test_scene1(self):
        mc.file(new=True, force=True)
        sphere1 = pymel.core.polySphere()[0]
        sphere1.setTranslation((10, 0, 0))
        sphere2 = pymel.core.polySphere()[0]

        print sphere1.getTranslation()

        from nodex.core import Nodex, Math

        # free position
        target = Nodex('pSphere1.translate')

        # limited position (5.0 units from origin)
        targetMax = target.normal() * 5.0

        # add a condition (so we use the limited targetMax position if the target is further away than 5.0 units)
        distanceFromOrigin = target.length()
        conditionOutput = Math.greaterThan(distanceFromOrigin, 5.0, ifTrue=targetMax, ifFalse=target)

        conditionOutput.connect('pSphere2.translate')

        print sphere2.getTranslation()
Example #5
0
    def test_comparisons(self):
        """
            Test if the comparisons have the correct outputs.
        """
        n = (Nodex(3) == Nodex(2))
        self.assertEqual(n.value(), 0.0)

        n = (Nodex(2) == Nodex(2))
        self.assertEqual(n.value(), 1.0)

        # ==
        mc.xform("pSphere1", t=(3, 3, 0), absolute=True, objectSpace=True)
        n = (Nodex("pSphere1.tx") == Nodex("pSphere1.ty"))
        self.assertEqual(n.value(), 1)
        mc.xform("pSphere1", t=(3, 4, 0), absolute=True, objectSpace=True)
        self.assertEqual(n.value(), 0)

        # !=
        x_not_y = (Nodex("pSphere1.tx") != Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_not_y.value(), 0)
        mc.xform("pSphere1", t=(0, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_not_y.value(), 1)

        # >
        x_bigger_y = (Nodex("pSphere1.tx") > Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(0.5, 0.1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 1)
        mc.xform("pSphere1", t=(0.1, 0.5, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 0)
        mc.xform("pSphere1", t=(0, 5, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 0)
        mc.xform("pSphere1", t=(-49, -50, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 1)

        # <
        x_smaller_y = (Nodex("pSphere1.tx") < Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(-5, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)
        mc.xform("pSphere1", t=(1.1, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 0)
        mc.xform("pSphere1", t=(0, 0.1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)
        mc.xform("pSphere1", t=(-50, -49, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)

        # Graph: Check if x, y, z are all the same value
        xy = (Nodex("pSphere1.tx") == Nodex("pSphere1.ty"))
        yz = (Nodex("pSphere1.ty") == Nodex("pSphere1.tz"))
        xz = (Nodex("pSphere1.tx") == Nodex("pSphere1.tz"))
        sum = Math.sum(xy, yz, xz)  # sum in a single node
        cond_all = (sum == 3)

        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 1)
        mc.xform("pSphere1", t=(1, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(0, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(0, 0, 1), absolute=True, objectSpace=True)

        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(15, 15, 15), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 1)
        mc.xform("pSphere1", t=(0.001, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)

        # Reset the sphere
        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)
Example #6
0
    def test_comparisons(self):
        """
            Test if the comparisons have the correct outputs.
        """
        n = (Nodex(3) == Nodex(2))
        self.assertEqual(n.value(), 0.0)

        n = (Nodex(2) == Nodex(2))
        self.assertEqual(n.value(), 1.0)

        # ==
        mc.xform("pSphere1", t=(3, 3, 0), absolute=True, objectSpace=True)
        n = (Nodex("pSphere1.tx") == Nodex("pSphere1.ty"))
        self.assertEqual(n.value(), 1)
        mc.xform("pSphere1", t=(3, 4, 0), absolute=True, objectSpace=True)
        self.assertEqual(n.value(), 0)

        # !=
        x_not_y = (Nodex("pSphere1.tx") != Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_not_y.value(), 0)
        mc.xform("pSphere1", t=(0, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_not_y.value(), 1)

        # >
        x_bigger_y = (Nodex("pSphere1.tx") > Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(0.5, 0.1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 1)
        mc.xform("pSphere1", t=(0.1, 0.5, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 0)
        mc.xform("pSphere1", t=(0, 5, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 0)
        mc.xform("pSphere1", t=(-49, -50, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_bigger_y.value(), 1)

        # <
        x_smaller_y = (Nodex("pSphere1.tx") < Nodex("pSphere1.ty"))
        mc.xform("pSphere1", t=(-5, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)
        mc.xform("pSphere1", t=(1.1, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 0)
        mc.xform("pSphere1", t=(0, 0.1, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)
        mc.xform("pSphere1", t=(-50, -49, 0), absolute=True, objectSpace=True)
        self.assertEqual(x_smaller_y.value(), 1)

        # Graph: Check if x, y, z are all the same value
        xy = (Nodex("pSphere1.tx") == Nodex("pSphere1.ty"))
        yz = (Nodex("pSphere1.ty") == Nodex("pSphere1.tz"))
        xz = (Nodex("pSphere1.tx") == Nodex("pSphere1.tz"))
        sum = Math.sum(xy, yz, xz) # sum in a single node
        cond_all = (sum == 3)

        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 1)
        mc.xform("pSphere1", t=(1, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(0, 1, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(0, 0, 1), absolute=True, objectSpace=True)

        self.assertEqual(cond_all.value(), 0)
        mc.xform("pSphere1", t=(15, 15, 15), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 1)
        mc.xform("pSphere1", t=(0.001, 0, 0), absolute=True, objectSpace=True)
        self.assertEqual(cond_all.value(), 0)

        # Reset the sphere
        mc.xform("pSphere1", t=(0, 0, 0), absolute=True, objectSpace=True)