def testConstructors(self):
     """Test TransformationMatrixf constructors"""
     a = IECore.TransformationMatrixf()
     self.assertEqual(a.transform, imath.M44f())
     a = IECore.TransformationMatrixf(imath.V3f(2, 2, 2), imath.Eulerf(),
                                      imath.V3f(1, 0, 0))
     self.assert_(
         a.transform.equalWithAbsError(
             imath.M44f().scale(imath.V3f(2, 2, 2)) *
             imath.M44f().translate(imath.V3f(1, 0, 0)), 0.01))
     b = IECore.TransformationMatrixf(a)
     self.assertEqual(a.transform, b.transform)
Ejemplo n.º 2
0
    def testTransform(self):

        sphere = IECoreScene.SpherePrimitive()
        originalRootBound = sphere.bound()
        originalRootBound.setMin(originalRootBound.min() + imath.V3f(1, 0, 0))
        originalRootBound.setMax(originalRootBound.max() + imath.V3f(1, 0, 0))
        input = GafferSceneTest.CompoundObjectSource()
        input["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(originalRootBound),
                "children": {
                    "sphere": {
                        "object":
                        sphere,
                        "bound":
                        IECore.Box3fData(sphere.bound()),
                        "transform":
                        IECore.M44fData(imath.M44f().translate(
                            imath.V3f(1, 0, 0))),
                    }
                }
            }))

        group = GafferScene.Group()
        group["in"][0].setInput(input["out"])
        group["transform"]["translate"].setValue(imath.V3f(0, 1, 0))

        self.assertEqual(group["name"].getValue(), "group")

        groupedRootBound = imath.Box3f(originalRootBound.min(),
                                       originalRootBound.max())
        groupedRootBound.setMin(groupedRootBound.min() + imath.V3f(0, 1, 0))
        groupedRootBound.setMax(groupedRootBound.max() + imath.V3f(0, 1, 0))

        self.assertEqual(group["out"].object("/"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/"), imath.M44f())
        self.assertEqual(group["out"].bound("/"), groupedRootBound)
        self.assertEqual(group["out"].childNames("/"),
                         IECore.InternedStringVectorData(["group"]))

        self.assertEqual(group["out"].object("/group"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/group"),
                         imath.M44f().translate(imath.V3f(0, 1, 0)))
        self.assertEqual(group["out"].bound("/group"), originalRootBound)
        self.assertEqual(group["out"].childNames("/group"),
                         IECore.InternedStringVectorData(["sphere"]))

        self.assertEqual(group["out"].object("/group/sphere"), sphere)
        self.assertEqual(group["out"].transform("/group/sphere"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))
        self.assertEqual(group["out"].bound("/group/sphere"), sphere.bound())
        self.assertEqual(group["out"].childNames("/group/sphere"),
                         IECore.InternedStringVectorData())
Ejemplo n.º 3
0
    def testConstructors(self):
        """Test Eulerf constructors"""

        #
        e = imath.Eulerf()
        self.assertEqual(e.x, 0)
        self.assertEqual(e.y, 0)
        self.assertEqual(e.z, 0)

        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        #
        ecopy = imath.Eulerf(e)
        self.assertEqual(ecopy.x, 0)
        self.assertEqual(ecopy.y, 0)
        self.assertEqual(ecopy.z, 0)

        self.assertEqual(ecopy.order(), imath.Eulerf.Order.XYZ)

        #
        e = imath.Eulerf(imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.V3f(0, 0, 0), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(0, 0, 0)
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(0, 0, 0, imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.M33f())
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.M33f(), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.M44f())
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.M44f(), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)
Ejemplo n.º 4
0
	def decompressed( self ) :

		names = IECore.StringVectorData( [ 'jointA', 'jointB', 'jointC' ] )
		poses = IECore.M44fVectorData( [imath.M44f(),imath.M44f(),imath.M44f()] )
		offsets = IECore.IntVectorData( [0, 3, 6] )
		counts = IECore.IntVectorData( [3, 3, 3] )
		indices = IECore.IntVectorData( [0, 1, 2, 0, 1, 2, 0, 1, 2] )
		weights = IECore.FloatVectorData( [0.5, 0.5, 0.0, 0.2, 0.8, 0.0, 0.0, 1.0, 0.0] )

		ssd = IECoreScene.SmoothSkinningData( names, poses, offsets, counts, indices, weights )

		return ssd
Ejemplo n.º 5
0
        def doTest(depthTest, r, g, b):

            renderer = IECoreGL.Renderer()
            renderer.setOption("gl:mode", IECore.StringData("immediate"))
            renderer.setOption(
                "gl:searchPath:shader",
                IECore.StringData(os.path.dirname(__file__) + "/shaders"))

            renderer.camera(
                "main", {
                    "projection":
                    IECore.StringData("orthographic"),
                    "resolution":
                    IECore.V2iData(imath.V2i(256)),
                    "clippingPlanes":
                    IECore.V2fData(imath.V2f(1, 1000)),
                    "screenWindow":
                    IECore.Box2fData(imath.Box2f(imath.V2f(-1), imath.V2f(1)))
                })
            renderer.display(
                os.path.dirname(__file__) + "/output/depthTest.tif", "tif",
                "rgba", {})

            m = IECoreScene.MeshPrimitive.createPlane(
                imath.Box2f(imath.V2f(-1), imath.V2f(1)))

            with IECoreScene.WorldBlock(renderer):

                renderer.setAttribute("gl:depthTest",
                                      IECore.BoolData(depthTest))

                renderer.concatTransform(imath.M44f().translate(
                    imath.V3f(0, 0, -1)))
                renderer.shader(
                    "surface", "color",
                    {"colorValue": IECore.Color3fData(imath.Color3f(1, 0, 0))})
                m.render(renderer)

                renderer.concatTransform(imath.M44f().translate(
                    imath.V3f(0, 0, -1)))
                renderer.shader(
                    "surface", "color",
                    {"colorValue": IECore.Color3fData(imath.Color3f(0, 1, 0))})
                m.render(renderer)

            i = IECore.Reader.create(
                os.path.dirname(__file__) + "/output/depthTest.tif").read()
            for p in i["R"]:
                self.assertEqual(p, r)
            for p in i["G"]:
                self.assertEqual(p, g)
            for p in i["B"]:
                self.assertEqual(p, b)
    def createSSD(self, offsets, counts, indices, weights):

        names = IECore.StringVectorData(
            ["|joint1", "|joint1|joint2", "|joint1|joint2|joint3"])
        poses = IECore.M44fVectorData([
            imath.M44f(1, -0, 0, -0, -0, 1, -0, 0, 0, -0, 1, -0, -0, 2, -0, 1),
            imath.M44f(1, -0, 0, -0, -0, 1, -0, 0, 0, -0, 1, -0, -0, 0, -0, 1),
            imath.M44f(1, -0, 0, -0, -0, 1, -0, 0, 0, -0, 1, -0, -0, -2, -0, 1)
        ])

        return IECoreScene.SmoothSkinningData(names, poses, offsets, counts,
                                              indices, weights)
Ejemplo n.º 7
0
    def testTwoLevels(self):

        sphere = IECoreScene.SpherePrimitive()
        input = GafferSceneTest.CompoundObjectSource()
        input["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(sphere.bound()),
                "children": {
                    "group": {
                        "bound": IECore.Box3fData(sphere.bound()),
                        "children": {
                            "sphere": {
                                "bound": IECore.Box3fData(sphere.bound()),
                                "object": sphere,
                            },
                        },
                    },
                },
            }), )

        group = GafferScene.Group()
        group["in"][0].setInput(input["out"])
        group["name"].setValue("topLevel")

        self.assertEqual(group["name"].getValue(), "topLevel")

        self.assertEqual(group["out"].object("/"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/"), imath.M44f())
        self.assertEqual(group["out"].bound("/"), sphere.bound())
        self.assertEqual(group["out"].childNames("/"),
                         IECore.InternedStringVectorData(["topLevel"]))

        self.assertEqual(group["out"].object("/topLevel"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/topLevel"), imath.M44f())
        self.assertEqual(group["out"].bound("/topLevel"), sphere.bound())
        self.assertEqual(group["out"].childNames("/topLevel"),
                         IECore.InternedStringVectorData(["group"]))

        self.assertEqual(group["out"].object("/topLevel/group"),
                         IECore.NullObject())
        self.assertEqual(group["out"].transform("/topLevel/group"),
                         imath.M44f())
        self.assertEqual(group["out"].bound("/topLevel/group"), sphere.bound())
        self.assertEqual(group["out"].childNames("/topLevel/group"),
                         IECore.InternedStringVectorData(["sphere"]))

        self.assertEqual(group["out"].object("/topLevel/group/sphere"), sphere)
        self.assertEqual(group["out"].transform("/topLevel/group/sphere"),
                         imath.M44f())
        self.assertEqual(group["out"].bound("/topLevel/group/sphere"),
                         sphere.bound())
        self.assertEqual(group["out"].childNames("/topLevel/group/sphere"),
                         IECore.InternedStringVectorData())
Ejemplo n.º 8
0
	def testAccessors( self ) :

		m = imath.M44f( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 )
		b = IECore.CubicBasisf( m, 10 )
		self.assertEqual( b.matrix, m )
		self.assertEqual( b.step, 10 )

		m2 = imath.M44f( 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 )
		b.matrix = m2
		self.assertEqual( b.matrix, m2 )

		b.step = 1
		self.assertEqual( b.matrix, m2 )
Ejemplo n.º 9
0
	def testCompute( self ) :

		c = GafferScene.Cube()

		self.assertEqual( c["out"].object( "/" ), IECore.NullObject() )
		self.assertEqual( c["out"].transform( "/" ), imath.M44f() )
		self.assertEqual( c["out"].bound( "/" ), imath.Box3f( imath.V3f( -0.5, -0.5, -0.5 ), imath.V3f( 0.5, 0.5, 0.5 ) ) )
		self.assertEqual( c["out"].childNames( "/" ), IECore.InternedStringVectorData( [ "cube" ] ) )

		self.assertEqual( c["out"].object( "/cube" ), IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ) ) )
		self.assertEqual( c["out"].transform( "/cube" ), imath.M44f() )
		self.assertEqual( c["out"].bound( "/cube" ), imath.Box3f( imath.V3f( -0.5, -0.5, -0.5 ), imath.V3f( 0.5, 0.5, 0.5 ) ) )
		self.assertEqual( c["out"].childNames( "/cube" ), IECore.InternedStringVectorData() )
    def compressedAfterIndexed(self):

        names = IECore.StringVectorData(['jointA', 'jointB', 'jointC'])
        poses = IECore.M44fVectorData(
            [imath.M44f(1), imath.M44f(2),
             imath.M44f(3)])
        offsets = IECore.IntVectorData([0, 1, 2, 2, 3])
        counts = IECore.IntVectorData([1, 1, 0, 1, 2])
        indices = IECore.IntVectorData([0, 0, 2, 0, 2])
        weights = IECore.FloatVectorData([0.7, 0.2, 0.8, 0.4, 0.4])

        return IECoreScene.SmoothSkinningData(names, poses, offsets, counts,
                                              indices, weights)
Ejemplo n.º 11
0
	def testParentAndChildInSameEditScope( self ) :

		script = Gaffer.ScriptNode()

		script["cube"] = GafferScene.Cube()
		script["cube"]["transform"]["translate"].setValue( imath.V3f( 0, 1, 0 ) )

		script["group"] = GafferScene.Group()
		script["group"]["in"][0].setInput( script["cube"]["out"] )

		script["editScope"] = Gaffer.EditScope()
		script["editScope"].setup( script["group"]["out"] )
		script["editScope"]["in"].setInput( script["group"]["out"] )

		view = GafferSceneUI.SceneView()
		view["in"].setInput( script["editScope"]["out"] )
		view["editScope"].setInput( script["editScope"]["out"] )

		groupTransformEdit = GafferScene.EditScopeAlgo.acquireTransformEdit( script["editScope"], "/group" )
		groupTransformEdit.rotate["y"].setValue( 90 )

		GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher( [ "/group/cube" ] ) )

		tool = GafferSceneUI.TranslateTool( view )
		tool["active"].setValue( True )

		self.assertTrue(
			tool.handlesTransform().equalWithAbsError(
				groupTransformEdit.matrix() * imath.M44f().translate( imath.V3f( 0, 1, 0 ) ),
				0.00001
			)
		)

		tool.translate( imath.V3f( 1, 0, 0 ) )

		self.assertTrue(
			script["editScope"]["out"].fullTransform( "/group/cube" ).equalWithAbsError(
				imath.M44f().translate( imath.V3f( 1, 1, 0 ) ) * groupTransformEdit.matrix(),
				0.00001
			)
		)

		tool.translate( imath.V3f( 1, 0, 0 ) )

		self.assertTrue(
			script["editScope"]["out"].fullTransform( "/group/cube" ).equalWithAbsError(
				imath.M44f().translate( imath.V3f( 2, 1, 0 ) ) * groupTransformEdit.matrix(),
				0.00001
			)
		)
Ejemplo n.º 12
0
	def testInstances(self):

		r = IECoreGL.Renderer()
		r.instanceBegin( "instanceA", {} )
		r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) )
		r.transformBegin()
		r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) )
		r.sphere( 1, -1, 1, 360, {} )
		r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) )
		r.sphere( 1, -1, 1, 360, {} )
		r.transformEnd()
		r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) )
		r.sphere( 1, -1, 1, 360, {} )
		r.instanceEnd()

		r.instanceBegin( "instanceB", {} )
		r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 10 ) ) )
		r.instance( "instanceA" )
		r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 20 ) ) )
		r.instance( "instanceA" )
		r.instanceEnd()

		r.setOption( "gl:mode", IECore.StringData( "deferred" ) )
		r.worldBegin()
		r.concatTransform( imath.M44f().translate( imath.V3f( 0, 5, 0 ) ) )
		r.instance( "instanceB" )
		r.setTransform( imath.M44f().translate( imath.V3f( 0, 10, 0 ) ) )
		r.instance( "instanceB" )
		r.worldEnd()

		g = r.scene().root()

		self.assertEqual( self.__countChildrenRecursive( g ), 12 )
		self.assertTrue( g.bound().min().equalWithAbsError( imath.V3f( -1, 4, 9 ), 0.001 ) )
		self.assertTrue( g.bound().max().equalWithAbsError( imath.V3f( 4, 11, 31 ), 0.001 ) )
Ejemplo n.º 13
0
	def testCompute( self ) :

		s = GafferScene.Sphere()
		s["type"].setValue( GafferScene.Sphere.Type.Primitive )

		self.assertEqual( s["out"].object( "/" ), IECore.NullObject() )
		self.assertEqual( s["out"].transform( "/" ), imath.M44f() )
		self.assertEqual( s["out"].bound( "/" ), imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) )
		self.assertEqual( s["out"].childNames( "/" ), IECore.InternedStringVectorData( [ "sphere" ] ) )

		self.assertEqual( s["out"].object( "/sphere" ), IECoreScene.SpherePrimitive( 1 ) )
		self.assertEqual( s["out"].transform( "/sphere" ), imath.M44f() )
		self.assertEqual( s["out"].bound( "/sphere" ), imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) )
		self.assertEqual( s["out"].childNames( "/sphere" ), IECore.InternedStringVectorData() )
Ejemplo n.º 14
0
    def testNegativeLocalScale(self):

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()
        script["plane"]["transform"]["scale"]["z"].setValue(-10)

        view = GafferSceneUI.SceneView()
        view["in"].setInput(script["plane"]["out"])
        GafferSceneUI.ContextAlgo.setSelectedPaths(
            view.getContext(), IECore.PathMatcher(["/plane"]))

        tool = GafferSceneUI.RotateTool(view)
        tool["active"].setValue(True)
        tool["orientation"].setValue(tool.Orientation.Local)

        # We want the direction of the handles to reflect the
        # flipped scale, but not its magnitude.

        self.assertTrue(tool.handlesTransform().equalWithAbsError(
            imath.M44f().scale(imath.V3f(1, 1, -1)), 0.000001))

        # And the handles need to move the object in the right
        # direction still.

        with Gaffer.UndoScope(script):
            tool.rotate(imath.Eulerf(0, 45, 0))

        self.assertTrue(script["plane"]["transform"]
                        ["rotate"].getValue().equalWithAbsError(
                            imath.V3f(0, -45, 0), 0.0001))

        script.undo()

        # When orientation is Parent or World, the scale should
        # not be reflected in the handles.

        for orientation in (tool.Orientation.World, tool.Orientation.Parent):

            tool["orientation"].setValue(orientation)
            self.assertEqual(tool.handlesTransform(), imath.M44f())

            with Gaffer.UndoScope(script):
                tool.rotate(imath.Eulerf(0, 45, 0))

            self.assertTrue(script["plane"]["transform"]
                            ["rotate"].getValue().equalWithAbsError(
                                imath.V3f(0, 45, 0), 0.0001))

            script.undo()
Ejemplo n.º 15
0
    def testPrimitiveInterpolation(self):

        m1 = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m2 = IECoreScene.TransformOp()(input=m1,
                                       matrix=IECore.M44fData(
                                           imath.M44f().scale(imath.V3f(2))))

        m3 = IECore.linearObjectInterpolation(m1, m2, 0.5)
        self.assertEqual(
            m3,
            IECoreScene.TransformOp()(input=m1,
                                      matrix=IECore.M44fData(
                                          imath.M44f().scale(imath.V3f(1.5)))))
Ejemplo n.º 16
0
	def testTransformationMotionBlur( self ) :

		transformSequence = appleseed.TransformSequence()
		IECoreAppleseed.TransformAlgo.makeTransformSequence(
			[ 0.25, 0.5, 0.75 ],
			[ imath.M44f().translate( imath.V3f( 0 ) ), imath.M44f().translate( imath.V3f( 1 ) ), imath.M44f().translate( imath.V3f( 2 ) ) ],
			transformSequence
		)

		transforms = transformSequence.transforms()
		self.assertTrue( len( transforms ) == 3 )
		self.assertTrue( transforms[0][0] == 0.25 )
		self.assertTrue( transforms[1][0] == 0.50 )
		self.assertTrue( transforms[2][0] == 0.75 )
    def createSSD(self, weights):

        names = IECore.StringVectorData(['jointA', 'jointB', 'jointC'])
        poses = IECore.M44fVectorData(
            [imath.M44f(1), imath.M44f(2),
             imath.M44f(3)])
        offsets = IECore.IntVectorData([0, 2, 5, 6, 8])
        counts = IECore.IntVectorData([2, 3, 1, 2, 3])
        indices = IECore.IntVectorData([0, 1, 0, 1, 2, 1, 1, 2, 0, 1, 2])

        ssd = IECoreScene.SmoothSkinningData(names, poses, offsets, counts,
                                             indices, weights)

        return ssd
Ejemplo n.º 18
0
    def testTransform(self):

        s = GafferScene.Sphere()
        s["type"].setValue(GafferScene.Sphere.Type.Primitive)
        s["transform"]["translate"].setValue(imath.V3f(1, 0, 0))

        self.assertEqual(s["out"].transform("/"), imath.M44f())
        self.assertEqual(s["out"].transform("/sphere"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))

        self.assertEqual(s["out"].bound("/"),
                         imath.Box3f(imath.V3f(0, -1, -1), imath.V3f(2, 1, 1)))
        self.assertEqual(s["out"].bound("/sphere"),
                         imath.Box3f(imath.V3f(-1), imath.V3f(1)))
    def testSkinClusterInfluencesWereRenamed(self):
        (sc, sc2) = self.buildTestSetup()
        fromConverter = IECoreMaya.FromMayaSkinClusterConverter.create(sc)
        fromConverter.parameters()["influenceName"].setValue(
            IECoreMaya.FromMayaSkinClusterConverter.InfluenceName.Partial)
        ssd = fromConverter.convert()
        self.assertEqual(
            ssd.influenceNames(),
            IECore.StringVectorData(['joint1', 'joint2', 'joint3']))
        ssd.validate()

        maya.cmds.rename('joint2', 'fakeJoint')
        newPose = IECore.M44fVectorData([
            imath.M44f(*maya.cmds.getAttr('skinCluster1.bindPreMatrix[0]')),
            imath.M44f(*maya.cmds.getAttr('skinCluster1.bindPreMatrix[2]')),
            imath.M44f(*maya.cmds.getAttr('skinCluster1.bindPreMatrix[1]'))
        ])

        toConverter = IECoreMaya.ToMayaSkinClusterConverter.create(ssd)
        toConverter.parameters()["ignoreMissingInfluences"].setTypedValue(True)
        toConverter.convert(sc)

        fromConverter = IECoreMaya.FromMayaSkinClusterConverter.create(sc)
        fromConverter.parameters()["influenceName"].setValue(
            IECoreMaya.FromMayaSkinClusterConverter.InfluenceName.Partial)
        ssd2 = fromConverter.convert()
        self.assertEqual(
            ssd2.influenceNames(),
            IECore.StringVectorData(['joint1', 'joint3', 'fakeJoint']))
        self.assertEqual(ssd2.influencePose(), newPose)
        self.assertEqual(
            ssd2.pointIndexOffsets(),
            IECore.IntVectorData(
                [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]))
        self.assertEqual(
            ssd2.pointInfluenceCounts(),
            IECore.IntVectorData(
                [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
        self.assertEqual(
            ssd2.pointInfluenceIndices(),
            IECore.IntVectorData(
                [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]))
        newWeights = IECore.FloatVectorData([
            ssd.pointInfluenceWeights()[x]
            for x in range(0,
                           ssd.pointInfluenceWeights().size())
            if ssd.pointInfluenceIndices()[x] != 1
        ])
        self.assertEqual(ssd2.pointInfluenceWeights(), newWeights)
Ejemplo n.º 20
0
    def testTransform(self):

        c = GafferScene.Cube()
        c["transform"]["translate"].setValue(imath.V3f(1, 0, 0))

        self.assertEqual(c["out"].transform("/"), imath.M44f())
        self.assertEqual(c["out"].transform("/cube"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))

        self.assertEqual(
            c["out"].bound("/"),
            imath.Box3f(imath.V3f(0.5, -0.5, -0.5), imath.V3f(1.5, 0.5, 0.5)))
        self.assertEqual(
            c["out"].bound("/cube"),
            imath.Box3f(imath.V3f(-0.5, -0.5, -0.5), imath.V3f(0.5, 0.5, 0.5)))
Ejemplo n.º 21
0
    def testTransform(self):

        p = GafferScene.Plane()
        p["transform"]["translate"].setValue(imath.V3f(1, 0, 0))

        self.assertEqual(p["out"].transform("/"), imath.M44f())
        self.assertEqual(p["out"].transform("/plane"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))

        self.assertEqual(
            p["out"].bound("/"),
            imath.Box3f(imath.V3f(0.5, -0.5, 0), imath.V3f(1.5, 0.5, 0)))
        self.assertEqual(
            p["out"].bound("/plane"),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))
Ejemplo n.º 22
0
    def testLoadCobWithTransform(self):

        c = IECoreScene.CoordinateSystem(
            "test", IECoreScene.MatrixTransform(imath.M44f()))
        IECore.ObjectWriter(c, "test/IECore/data/coordSys.cob").write()
        c = IECore.ObjectReader("test/IECore/data/coordSys.cob").read()

        self.assertEqual(c.getTransform(),
                         IECoreScene.MatrixTransform(imath.M44f()))

        c = IECoreScene.CoordinateSystem("test", None)
        IECore.ObjectWriter(c, "test/IECore/data/coordSys.cob").write()
        c = IECore.ObjectReader("test/IECore/data/coordSys.cob").read()

        self.assertEqual(c.getTransform(), None)
Ejemplo n.º 23
0
	def testTransformsInImmediateRenderer( self ):
		r = IECoreGL.Renderer()
		r.setOption( "gl:mode", IECore.StringData( "immediate" ) )
		r.transformBegin()
		r.concatTransform( imath.M44f().rotate( imath.V3f( 1, 1, 1 ) ) )
		r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ), "projection" : IECore.StringData( "perspective" ) } )
		r.transformEnd()
		r.worldBegin()
		# confirm that the camera transformation is not affecting the world space matrix
		r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) )
		self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ), 1e-4 ) )
		# confirm that setting the world space transform does not affect the camera matrix (that was already set in openGL )
		r.setTransform( imath.M44f().translate( imath.V3f( 0, 1, 0 ) ) )
		self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().translate( imath.V3f( 0, 1, 0 ) ), 1e-4 ) )
		r.worldEnd()
Ejemplo n.º 24
0
	def testCameraTransform( self ) :

		# camera must be output with an identity transform, because of the hierarchical
		# nature of this class...

		scene = IECoreMaya.LiveScene()
		cameraTransform = scene.child( "persp" )
		maya.cmds.currentTime( "0.0sec" )
		camera = cameraTransform.readObject( 0 )

		# sanity check: camera transform is not identity?
		self.assertNotEqual( cameraTransform.readTransformAsMatrix( 0 ), imath.M44f() )

		# this transform must be identity...
		self.assertEqual( camera.getTransform().transform(), imath.M44f() )
    def testM44fPlugs(self):

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["user"]["i"] = Gaffer.M44fPlug(flags=Gaffer.Plug.Flags.Default
                                              | Gaffer.Plug.Flags.Dynamic)
        s["n"]["user"]["o"] = Gaffer.M44fPlug(flags=Gaffer.Plug.Flags.Default
                                              | Gaffer.Plug.Flags.Dynamic)

        s["e"] = Gaffer.Expression()
        s["e"].setExpression("parent.n.user.o = parent.n.user.i * 2;", "OSL")

        s["n"]["user"]["i"].setValue(imath.M44f(*range(16)))
        self.assertEqual(s["n"]["user"]["o"].getValue(),
                         imath.M44f(*range(0, 32, 2)))
Ejemplo n.º 26
0
    def testPivotExpression(self):

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()

        script["expression"] = Gaffer.Expression()
        script["expression"].setExpression(
            inspect.cleandoc("""
			parent["plane"]["transform"]["pivot"]["x"] = context["x"]
			"""))

        script["variables"] = Gaffer.ContextVariables()
        script["variables"].setup(GafferScene.ScenePlug())
        script["variables"]["in"].setInput(script["plane"]["out"])
        script["variables"]["variables"].addChild(
            Gaffer.NameValuePlug("x", 1.0))

        view = GafferSceneUI.SceneView()
        view["in"].setInput(script["variables"]["out"])
        view.setContext(script.context())

        GafferSceneUI.ContextAlgo.setSelectedPaths(
            view.getContext(), IECore.PathMatcher(["/plane"]))

        tool = GafferSceneUI.TranslateTool(view)
        tool["active"].setValue(True)

        self.assertEqual(tool.selection()[0].path, "/plane")
        self.assertEqual(tool.handlesTransform(),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))
Ejemplo n.º 27
0
    def testRelativeTransform(self):

        plane1 = GafferScene.Plane()
        plane1["transform"]["translate"].setValue(imath.V3f(1, 2, 3))
        plane1["transform"]["rotate"].setValue(imath.V3f(0, 90, 0))
        plane1["name"].setValue("target")

        plane2 = GafferScene.Plane()
        plane2["name"].setValue("constrained")

        group = GafferScene.Group()
        group["in"][0].setInput(plane1["out"])
        group["in"][1].setInput(plane2["out"])

        self.assertSceneValid(group["out"])

        constraint = GafferScene.ParentConstraint()
        constraint["target"].setValue("/group/target")
        constraint["in"].setInput(group["out"])
        constraint["relativeTransform"]["translate"].setValue(
            imath.V3f(1, 0, 0))

        filter = GafferScene.PathFilter()
        filter["paths"].setValue(
            IECore.StringVectorData(["/group/constrained"]))
        constraint["filter"].setInput(filter["out"])

        self.assertSceneValid(constraint["out"])

        self.assertEqual(
            constraint["out"].fullTransform("/group/constrained"),
            imath.M44f().translate(imath.V3f(1, 0, 0)) *
            group["out"].fullTransform("/group/target"))
Ejemplo n.º 28
0
    def testDataTypes(self):

        d = IECore.CompoundData()
        d['a'] = IECore.IntData(1)
        d['c'] = IECore.FloatData(3)
        d['e'] = IECore.HalfData(4)
        d['f'] = IECore.V2iData(imath.V2i(1, 10))
        d['g'] = IECore.V2fData(imath.V2f(2, 31),
                                IECore.GeometricData.Interpretation.Vector)
        d['h'] = IECore.V2dData(imath.V2d(3, 551),
                                IECore.GeometricData.Interpretation.Color)
        d['i'] = IECore.V3fData(imath.V3f(1, 3, 5),
                                IECore.GeometricData.Interpretation.Point)
        d['k'] = IECore.M44fData(imath.M44f(2))
        d['l'] = IECore.HalfVectorData([1, 2, 3, 100, 9, 10, 11])
        d['m'] = IECore.V2fVectorData(
            [imath.V2f(1, 2),
             imath.V2f(3, 4),
             imath.V2f(5, 6)], IECore.GeometricData.Interpretation.Normal)
        d['x'] = IECore.StringData("testttt")
        d['z'] = IECore.StringVectorData(["a", 'b', 'adffs'])

        iface = IECore.IndexedIO.create("test/o.fio", [],
                                        IECore.IndexedIO.OpenMode.Write)
        d.save(iface, "test")

        dd = IECore.Object.load(iface, "test")
        self.assertEqual(d, dd)
Ejemplo n.º 29
0
    def testInvalidRoot(self):

        p = GafferScene.Plane()
        p["sets"].setValue("A")

        g = GafferScene.Group()
        g["in"][0].setInput(p["out"])

        s = GafferScene.SubTree()
        s["in"].setInput(g["out"])

        # An invalid root matches nothing, so should output an empty scene

        for includeRoot in (True, False):

            s["includeRoot"].setValue(includeRoot)

            for root in ("notAThing", "/group/stillNotAThing",
                         "/group/definitely/not/a/thing"):

                s["root"].setValue(root)

                self.assertSceneValid(s["out"])
                self.assertEqual(s["out"].childNames("/"),
                                 IECore.InternedStringVectorData())
                self.assertEqual(s["out"].set("A"), IECore.PathMatcherData())
                self.assertEqual(s["out"].bound("/"), imath.Box3f())
                self.assertEqual(s["out"].attributes("/"),
                                 IECore.CompoundObject())
                self.assertEqual(s["out"].transform("/"), imath.M44f())
Ejemplo n.º 30
0
    def testTransforms(self):
        def add(parent, child, vec):
            child.setTransform(
                IECoreScene.MatrixTransform(imath.M44f().translate(vec)))
            parent.addChild(child)
            if random.random() > 0.75:
                child.addChild(self.mesh())

        group = IECoreScene.Group()
        group.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(5, 0, 0))))
        for i in range(0, 50):
            add(
                group, self.meshGroup(),
                imath.V3f(random.random(), random.random(), random.random()) *
                3)

        null = self.emptySop()
        self.failUnless(
            IECoreHoudini.ToHoudiniGroupConverter(group).convert(null))

        houdiniBound = null.geometry().boundingBox()
        bound = imath.Box3f(imath.V3f(list(houdiniBound.minvec())),
                            imath.V3f(list(houdiniBound.maxvec())))
        self.assertEqual(group.bound(), bound)