コード例 #1
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()
コード例 #2
0
ファイル: tests.py プロジェクト: BigRoy/nodex
    def test_vector_normal(self):

        v1 = Nodex((100, 0, 0))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(pymel.core.datatypes.Vector(1, 0, 0)))

        v1 = Nodex((100, 0, 100))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(pymel.core.datatypes.Vector(0.707, 0, 0.707), tol=1e-3))

        v1 = Nodex((0, -100, 0))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(pymel.core.datatypes.Vector(0, -1, 0)))

        v1 = Nodex((100, -100, -100))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(pymel.core.datatypes.Vector(0.577, -0.577, -0.577), tol=1e-3))
コード例 #3
0
    def test_vector_length(self):

        v1 = Nodex((100, 0, 0))
        length = v1.length()
        self.assertAlmostEqual(length.value(), 100.0, places=5)

        v1 = Nodex(
            (0.707, 0, 0.707))  # this is rough approximation of a unit vector
        length = v1.length()
        self.assertAlmostEqual(length.value(), 1.0, places=2)

        # Check distance in two ways and check if is equal
        v1 = Nodex((100, 0, 0))
        v2 = Nodex((24, 25, 10))
        diff = v1 - v2
        distance = diff.length()
        distance_direct = v1.distanceTo(v2)
        self.assertAlmostEqual(distance.value(),
                               distance_direct.value(),
                               places=5)

        # Set some random vectors, normalize and check whether length == 1.0
        v = Nodex((2154.0, 2315.98, -918))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        v = Nodex((500, 0.7, 50))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        v = Nodex((-4, 9, -7))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        # squared length
        v = Nodex((-4, 9, -7))
        lengthSquared = v.length() ^ 2
        lengthSquaredMethod = v.squareLength()
        self.assertAlmostEqual(lengthSquared.value(),
                               lengthSquaredMethod.value(),
                               places=5)
コード例 #4
0
    def test_vector_normal(self):

        v1 = Nodex((100, 0, 0))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(
            pymel.core.datatypes.Vector(1, 0, 0)))

        v1 = Nodex((100, 0, 100))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(
            pymel.core.datatypes.Vector(0.707, 0, 0.707), tol=1e-3))

        v1 = Nodex((0, -100, 0))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(
            pymel.core.datatypes.Vector(0, -1, 0)))

        v1 = Nodex((100, -100, -100))
        normal = v1.normal()
        self.assertTrue(normal.value().isEquivalent(
            pymel.core.datatypes.Vector(0.577, -0.577, -0.577), tol=1e-3))
コード例 #5
0
ファイル: tests.py プロジェクト: BigRoy/nodex
    def test_vector_length(self):

        v1 = Nodex((100, 0, 0))
        length = v1.length()
        self.assertAlmostEqual(length.value(), 100.0, places=5)

        v1 = Nodex((0.707, 0, 0.707)) # this is rough approximation of a unit vector
        length = v1.length()
        self.assertAlmostEqual(length.value(), 1.0, places=2)

        # Check distance in two ways and check if is equal
        v1 = Nodex((100, 0, 0))
        v2 = Nodex((24, 25, 10))
        diff = v1 - v2
        distance = diff.length()
        distance_direct = v1.distanceTo(v2)
        self.assertAlmostEqual(distance.value(), distance_direct.value(), places=5)

        # Set some random vectors, normalize and check whether length == 1.0
        v = Nodex((2154.0, 2315.98, -918))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        v = Nodex((500, 0.7, 50))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        v = Nodex((-4, 9, -7))
        normal_length = v.normal().length()
        self.assertAlmostEqual(normal_length.value(), 1.0, places=5)

        # squared length
        v = Nodex((-4, 9, -7))
        lengthSquared = v.length() ^ 2
        lengthSquaredMethod = v.squareLength()
        self.assertAlmostEqual(lengthSquared.value(), lengthSquaredMethod.value(), places=5)
コード例 #6
0
ファイル: tests.py プロジェクト: BigRoy/nodex
    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()