예제 #1
0
	def testQueryBound( self ) :

		renderer = GafferScene.Private.IECoreScenePreview.Renderer.create(
			"OpenGL",
			GafferScene.Private.IECoreScenePreview.Renderer.RenderType.Interactive
		)

		cube = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -1 ), imath.V3f( 9 ) ) )

		o = renderer.object(
			"/cube",
			cube,
			renderer.attributes( IECore.CompoundObject() )
		)
		o.transform(
			imath.M44f().translate( imath.V3f( 1 ) )
		)

		self.assertEqual(
			renderer.command( "gl:queryBound", {} ),
			imath.Box3f(
				cube.bound().min() + imath.V3f( 1 ),
				cube.bound().max() + imath.V3f( 1 )
			)
		)

		del o
예제 #2
0
    def testShape(self):

        node = GafferOSL.OSLLight()
        self.assertEqual(node["out"].object("/light"),
                         IECoreScene.DiskPrimitive(0.01))

        node["radius"].setValue(2)
        self.assertEqual(node["out"].object("/light"),
                         IECoreScene.DiskPrimitive(2))

        node["shape"].setValue(node.Shape.Sphere)
        self.assertEqual(node["out"].object("/light"),
                         IECoreScene.SpherePrimitive(2))

        node["shape"].setValue(node.Shape.Geometry)
        node["geometryType"].setValue("teapot")
        node["geometryBound"].setValue(
            imath.Box3f(imath.V3f(-0.5), imath.V3f(0.5)))
        node["geometryParameters"].addChild(
            Gaffer.NameValuePlug("color", imath.Color3f(1, 0, 0)))

        self.assertEqual(
            node["out"].object("/light"),
            GafferScene.Private.IECoreScenePreview.Geometry(
                "teapot", imath.Box3f(imath.V3f(-0.5), imath.V3f(0.5)), {
                    "color": imath.Color3f(1, 0, 0),
                }))
예제 #3
0
    def testSpaces(self):

        sphere = maya.cmds.polySphere(subdivisionsX=10,
                                      subdivisionsY=5,
                                      constructionHistory=False)
        maya.cmds.move(1, 2, 3, sphere)
        sphere = maya.cmds.listRelatives(sphere, shapes=True)[0]

        combiner = maya.cmds.createNode("ieGeometryCombiner")
        maya.cmds.connectAttr(sphere + ".worldMesh",
                              combiner + ".inputGeometry",
                              nextAvailable=True)

        self.assertEqual(maya.cmds.getAttr(combiner + ".conversionSpace"),
                         IECoreMaya.FromMayaShapeConverter.Space.World.real)

        combined = IECoreMaya.FromMayaPlugConverter.create(
            combiner + ".outputGroup").convert()
        self.assertTrue(
            IECore.BoxAlgo.contains(
                imath.Box3f(
                    imath.V3f(-1.0001) + imath.V3f(1, 2, 3),
                    imath.V3f(1.0001) + imath.V3f(1, 2, 3)), combined.bound()))

        maya.cmds.setAttr(combiner + ".conversionSpace",
                          IECoreMaya.FromMayaShapeConverter.Space.Object.real)

        combined = IECoreMaya.FromMayaPlugConverter.create(
            combiner + ".outputGroup").convert()
        self.assertTrue(
            IECore.BoxAlgo.contains(
                imath.Box3f(imath.V3f(-1.0001), imath.V3f(1.0001)),
                combined.bound()))
예제 #4
0
	def writeAnimatedSCC( self ) :

		scene = IECoreScene.SceneCache( self.__testFile, IECore.IndexedIO.OpenMode.Write )

		time = 0
		sc1 = scene.createChild( str( 1 ) )
		mesh = IECoreScene.MeshPrimitive.createBox(imath.Box3f(imath.V3f(0),imath.V3f(1)))
		mesh["Cd"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ imath.V3f( 1, 0, 0 ) ] * 6 ) )
		sc1.writeObject( mesh, time )
		sc1.writeTransform( IECore.M44dData(), time )

		sc2 = sc1.createChild( str( 2 ) )
		mesh = IECoreScene.MeshPrimitive.createBox(imath.Box3f(imath.V3f(0),imath.V3f(1)))
		mesh["Cd"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ imath.V3f( 0, 1, 0 ) ] * 6 ) )
		sc2.writeObject( mesh, time )
		sc2.writeTransform( IECore.M44dData(), time )

		sc3 = sc2.createChild( str( 3 ) )
		mesh = IECoreScene.MeshPrimitive.createBox(imath.Box3f(imath.V3f(0),imath.V3f(1)))
		mesh["Cd"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ imath.V3f( 0, 0, 1 ) ] * 6 ) )
		sc3.writeObject( mesh, time )
		sc3.writeTransform( IECore.M44dData(), time )

		for frame in [ 0.5, 1, 1.5, 2, 5, 10 ] :

			matrix = imath.M44d().translate( imath.V3d( 1, frame, 0 ) )
			sc1.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 )

			mesh["Cd"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ imath.V3f( frame, 1, 0 ) ] * 6 ) )
			sc2.writeObject( mesh, float( frame ) / 24 )
			matrix = imath.M44d().translate( imath.V3d( 2, frame, 0 ) )
			sc2.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 )

			matrix = imath.M44d().translate( imath.V3d( 3, frame, 0 ) )
			sc3.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 )
예제 #5
0
    def testObjectSpaceCulling(self):

        p = self.RecursiveProcedural()

        def renderWithCulling(box):
            r = IECoreGL.Renderer()
            r.setOption("gl:mode", IECore.StringData("deferred"))
            r.worldBegin()
            r.sphere(1.5, 0, 1, 360, {})
            r.procedural(p)
            r.attributeBegin()
            if True:
                r.setAttribute("gl:cullingSpace", IECore.StringData("object"))
                r.setAttribute("gl:cullingBox", IECore.Box3fData(box))
                # everything in this block is culled
                r.sphere(1.5, 0, 1, 360, {})
                r.procedural(p)
            r.attributeEnd()
            r.worldEnd()
            return self.__countChildrenRecursive(r.scene().root())

        noCullingCounter = renderWithCulling(imath.Box3f())

        # verify that only half of the things are renderer when the giving culling box is defined.
        self.assertEqual(
            renderWithCulling(
                imath.Box3f(imath.V3f(2, -1, -1), imath.V3f(3, 1, 1))) * 2,
            noCullingCounter)
예제 #6
0
	def testSpaces( self ) :

		arc = maya.cmds.circle( ch = False, sweep=180 )[0]
		maya.cmds.move( 1, 2, 3, arc )
		arc = maya.cmds.listRelatives( arc, shapes=True )[0]

		converter = IECoreMaya.FromMayaShapeConverter.create( str( arc ), IECoreScene.CurvesPrimitive.staticTypeId() )

		self.assertEqual( converter["space"].getNumericValue(), IECoreMaya.FromMayaCurveConverter.Space.Object )
		c = converter.convert()
		self.assertTrue(
			IECore.BoxAlgo.contains(
				imath.Box3f( imath.V3f( -1.1, -1.01, -0.01 ), imath.V3f( 0.01, 1.01, 0.01 ) ),
				c.bound()
			)
		)

		converter["space"].setNumericValue( IECoreMaya.FromMayaCurveConverter.Space.World )
		c = converter.convert()
		self.assertTrue(
			IECore.BoxAlgo.contains(
				imath.Box3f( imath.V3f( -0.1, 0.99, 2.99 ), imath.V3f( 1.01, 3.01, 3.01 ) ),
				c.bound()
			)
		)
예제 #7
0
    def testTimeContext(self):

        s = Gaffer.ScriptNode()

        s["cube"] = GafferScene.Cube()

        s["e"] = Gaffer.Expression()
        s["e"].setExpression(
            'parent["cube"]["dimensions"] = imath.V3f( context["frame"] )')

        s["n"] = GafferScene.SceneTimeWarp()
        s["n"]["in"].setInput(s["cube"]["out"])
        s["n"]["speed"].setValue(0)
        s["n"]["offset"].setValue(3)
        self.assertEqual(s["n"]["out"].bound("/cube"),
                         imath.Box3f(imath.V3f(-1.5), imath.V3f(1.5)))

        s["e2"] = Gaffer.Expression()
        s["e2"].setExpression(
            inspect.cleandoc("""
			assert( context.get( "scene:path", None ) is None )
			parent["n"]["offset"] = 5
			"""))

        self.assertEqual(s["n"]["out"].bound("/cube"),
                         imath.Box3f(imath.V3f(-2.5), imath.V3f(2.5)))
예제 #8
0
	def testTranformation( self ) :

		m = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) )
		IECoreScene.MeshNormalsOp()( input = m, copyInput = False )
		m["vel"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0.5 ) ] * 8, IECore.GeometricData.Interpretation.Vector ) )
		m["notVel"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0.5 ) ] * 8 ) )

		mt = IECoreScene.TransformOp()( input=m, primVarsToModify = IECore.StringVectorData( m.keys() ), matrix = IECore.M44fData( imath.M44f().translate( imath.V3f( 1 ) ) ) )

		self.assertEqual( mt.bound(), imath.Box3f( imath.V3f( 0 ), imath.V3f( 2 ) ) )
		self.assertEqual( mt["P"].data, IECore.V3fVectorData( [ x + imath.V3f( 1 ) for x in m["P"].data ], IECore.GeometricData.Interpretation.Point ) )
		self.assertEqual( mt["N"].data, m["N"].data )
		self.assertEqual( mt["vel"].data, m["vel"].data )
		self.assertEqual( mt["notVel"].data, m["notVel"].data )

		ms = IECoreScene.TransformOp()( input=m, primVarsToModify = IECore.StringVectorData( m.keys() ), matrix = IECore.M44fData( imath.M44f().scale( imath.V3f( 1, 2, 3 ) ) ) )

		self.assertEqual( ms.bound(), imath.Box3f( imath.V3f( -1, -2, -3 ), imath.V3f( 1, 2, 3 ) ) )
		self.assertEqual( ms["P"].data, IECore.V3fVectorData( [ x * imath.V3f( 1, 2, 3 ) for x in m["P"].data ], IECore.GeometricData.Interpretation.Point ) )
		self.assertNotEqual( ms["N"].data, m["N"].data )
		self.assertNotEqual( ms["N"].data, IECore.V3fVectorData( [ x * imath.V3f( 1, 2, 3 ) for x in m["N"].data ], IECore.GeometricData.Interpretation.Normal ) )
		self.assertEqual( ms["vel"].data, IECore.V3fVectorData( [ x * imath.V3f( 1, 2, 3 ) for x in m["vel"].data ], IECore.GeometricData.Interpretation.Vector ) )
		self.assertEqual( ms["notVel"].data, m["notVel"].data )

		self.assertEqual( ms["P"].data.getInterpretation(), IECore.GeometricData.Interpretation.Point )
		self.assertEqual( ms["N"].data.getInterpretation(), IECore.GeometricData.Interpretation.Normal )
		self.assertEqual( ms["vel"].data.getInterpretation(), IECore.GeometricData.Interpretation.Vector )
		self.assertEqual( ms["notVel"].data.getInterpretation(), IECore.GeometricData.Interpretation.None )
예제 #9
0
	def test( self ) :

		p = GafferScene.Plane()
		options = GafferScene.CustomOptions()
		options["in"].setInput( p["out"] )

		# check that the scene hierarchy is passed through

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

		self.assertEqual( options["out"].object( "/plane" ), IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.5 ), imath.V2f( 0.5 ) ) ) )
		self.assertEqual( options["out"].transform( "/plane" ), imath.M44f() )
		self.assertEqual( options["out"].bound( "/plane" ), imath.Box3f( imath.V3f( -0.5, -0.5, 0 ), imath.V3f( 0.5, 0.5, 0 ) ) )
		self.assertEqual( options["out"].childNames( "/plane" ), IECore.InternedStringVectorData() )

		# check that we can make options

		options["options"].addChild( Gaffer.NameValuePlug( "test", IECore.IntData( 10 ) ) )
		options["options"].addChild( Gaffer.NameValuePlug( "test2", IECore.StringData( "10" ) ) )

		g = options["out"]["globals"].getValue()
		self.assertEqual( len( g ), 2 )
		self.assertEqual( g["option:test"], IECore.IntData( 10 ) )
		self.assertEqual( g["option:test2"], IECore.StringData( "10" ) )
예제 #10
0
	def test( self ) :

		v = GafferArnold.ArnoldVDB()

		# Just an empty procedural at this point.
		self.assertEqual( v["out"].childNames( "/" ), IECore.InternedStringVectorData( [ "volume" ] ) )
		self.assertSceneValid( v["out"] )
		self.assertEqual( v["out"].bound( "/volume" ), imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ) )
		self.assertTrue( isinstance( v["out"].object( "/volume" ), IECoreScene.ExternalProcedural ) )

		# If we enter a valid vdb filename, then we should get something
		# with the right bounds, and the right parameters in the procedural.
		v["fileName"].setValue( os.path.join( os.path.dirname( __file__ ), "volumes", "sphere.vdb" ) )
		self.assertEqual( v["out"].bound( "/volume" ), imath.Box3f( imath.V3f( -1.1, 1.1, -1.1 ), imath.V3f( 1.1, 2.9, 1.1 ) ) )

		procedural = v["out"].object( "/volume" )
		self.assertTrue( isinstance( procedural, IECoreScene.ExternalProcedural ) )
		self.assertEqual( procedural.getBound(), v["out"].bound( "/volume" ) )
		self.assertEqual( procedural.getFileName(), "volume" )
		self.assertEqual( procedural.parameters()["filename" ].value, v["fileName"].getValue() )
		self.assertEqual( procedural.parameters()["grids" ], IECore.StringVectorData( [ v["grids"].getValue() ] ) )

		# Invalid grid names should create errors.
		v["grids"].setValue( "notAGrid" )
		with six.assertRaisesRegex( self, Gaffer.ProcessException, "has no grid named \"notAGrid\"" ) as caught :
			v["out"].bound( "/volume" )

		# As should invalid file names.
		v["grids"].setValue( "density" )
		v["fileName"].setValue( "notAFile.vdb" )
		with six.assertRaisesRegex( self, Gaffer.ProcessException, "No such file or directory" ) :
			v["out"].bound( "/volume" )
예제 #11
0
	def testTimeSetting( self ):
		fileName = "{}/testUSDTimeSettings.scc".format( self.temporaryDirectory() )

		for sampleType in ( "transform", "attribute", "object" ):
			m = IECoreScene.SceneCache( fileName, IECore.IndexedIO.OpenMode.Write )
			t = m.createChild( "t" )
			if sampleType == "transform":
				t.writeTransform( IECore.M44dData(imath.M44d().translate(imath.V3d( 1, 0, 0 ))), 1.0 )
				t.writeTransform( IECore.M44dData(imath.M44d().translate(imath.V3d( 2, 0, 0 ))), 2.0 )
			elif sampleType == "attribute":
				t.writeAttribute( IECoreScene.SceneInterface.visibilityName, IECore.BoolData( True ), 1.0 )
				t.writeAttribute( IECoreScene.SceneInterface.visibilityName, IECore.BoolData( False ), 2.0 )
			else:
				boxA = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( 0 ), imath.V3f( 1 ) ) )
				t.writeObject( boxA, 1.0 )

				boxB = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( 1 ), imath.V3f( 2 ) ) )
				t.writeObject( boxB, 2.0 )

			del m, t

			# root
			stage = pxr.Usd.Stage.Open( fileName )
			root = stage.GetPseudoRoot()

			metadata = root.GetAllMetadata()

			self.assertEqual( metadata["startTimeCode"], 24.0 )
			self.assertEqual( metadata["endTimeCode"], 48.0 )

			self.assertEqual( metadata["timeCodesPerSecond"], 24.0 )
    def testConversion(self):

        g = IECoreScene.Group()
        g.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().scale(imath.V3f(2))))

        c1 = IECoreScene.Group()
        c1.addChild(
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(-1), imath.V3f(1))))
        c1.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(2, 0, 0))))
        g.addChild(c1)

        c2 = IECoreScene.Group()
        c2.addChild(
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(-1), imath.V3f(1))))
        c2.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(-2, 0, 0))))
        g.addChild(c2)

        p = maya.cmds.createNode("transform")

        IECoreMaya.ToMayaGroupConverter(g).convert(p)

        mg = maya.cmds.listRelatives(p, fullPath=True)

        self.assertEqual(len(mg), 1)
        self.assertEqual(maya.cmds.nodeType(mg[0]), "transform")
        self.assertEqual(maya.cmds.getAttr(mg[0] + ".translate"), [(0, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mg[0] + ".rotate"), [(0, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mg[0] + ".scale"), [(2, 2, 2)])

        mgg = maya.cmds.listRelatives(mg[0], fullPath=True)

        self.assertEqual(len(mgg), 2)

        self.assertEqual(maya.cmds.nodeType(mgg[0]), "transform")
        self.assertEqual(maya.cmds.getAttr(mgg[0] + ".translate"), [(2, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mgg[0] + ".rotate"), [(0, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mgg[0] + ".scale"), [(1, 1, 1)])

        self.assertEqual(maya.cmds.nodeType(mgg[1]), "transform")
        self.assertEqual(maya.cmds.getAttr(mgg[1] + ".translate"),
                         [(-2, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mgg[1] + ".rotate"), [(0, 0, 0)])
        self.assertEqual(maya.cmds.getAttr(mgg[1] + ".scale"), [(1, 1, 1)])

        m1 = maya.cmds.listRelatives(mgg[0], fullPath=True)
        self.assertEqual(len(m1), 1)
        self.assertEqual(maya.cmds.nodeType(m1[0]), "mesh")
        self.assertEqual(maya.cmds.polyEvaluate(m1[0], face=True), 6)

        m2 = maya.cmds.listRelatives(mgg[1], fullPath=True)
        self.assertEqual(len(m2), 1)
        self.assertEqual(maya.cmds.nodeType(m2[0]), "mesh")
        self.assertEqual(maya.cmds.polyEvaluate(m2[0], face=True), 6)
예제 #13
0
    def testBound(self):

        g = GafferImageUI.ImageGadget()
        self.assertEqual(g.bound(), imath.Box3f())

        c = GafferImage.Constant()
        c["format"].setValue(GafferImage.Format(200, 100))

        g.setImage(c["out"])
        self.assertEqual(g.bound(),
                         imath.Box3f(imath.V3f(0), imath.V3f(200, 100, 0)))

        c["format"].setValue(GafferImage.Format(200, 100, 2))
        self.assertEqual(g.bound(),
                         imath.Box3f(imath.V3f(0), imath.V3f(400, 100, 0)))

        c2 = GafferImage.Constant()
        g.setImage(c2["out"])

        f = GafferImage.FormatPlug.getDefaultFormat(
            g.getContext()).getDisplayWindow()
        self.assertEqual(
            g.bound(),
            imath.Box3f(imath.V3f(f.min().x,
                                  f.min().y, 0),
                        imath.V3f(f.max().x,
                                  f.max().y, 0)))

        GafferImage.FormatPlug.setDefaultFormat(
            g.getContext(),
            GafferImage.Format(
                imath.Box2i(imath.V2i(10, 20), imath.V2i(30, 40))))
        self.assertEqual(
            g.bound(), imath.Box3f(imath.V3f(10, 20, 0), imath.V3f(30, 40, 0)))
예제 #14
0
    def setUp(self):

        scene = IECoreScene.SceneCache(FnSceneShapeTest.__testFile,
                                       IECore.IndexedIO.OpenMode.Write)
        sc = scene.createChild(str(1))
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        mesh["Cd"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.V3fVectorData([imath.V3f(1, 0, 0)] * 6))
        sc.writeObject(mesh, 0.0)
        matrix = imath.M44d().translate(imath.V3d(1, 0, 0))
        sc.writeTransform(IECore.M44dData(matrix), 0.0)

        sc = sc.createChild("child")
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        mesh["Cd"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.V3fVectorData([imath.V3f(0, 1, 0)] * 6))
        sc.writeObject(mesh, 0.0)
        matrix = imath.M44d().translate(imath.V3d(2, 0, 0))
        sc.writeTransform(IECore.M44dData(matrix), 0.0)

        sc = sc.createChild(str(3))
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        mesh["Cd"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.V3fVectorData([imath.V3f(0, 0, 1)] * 6))
        sc.writeObject(mesh, 0.0)
        matrix = imath.M44d().translate(imath.V3d(3, 0, 0))
        sc.writeTransform(IECore.M44dData(matrix), 0.0)

        return scene
예제 #15
0
	def _writeScene( self, fileName, transformRootChildren=False, writeInvalidUSDName=False, writeCs=False ):
		m = IECoreScene.SceneCache( fileName, IECore.IndexedIO.OpenMode.Write )
		t = m.createChild( "t" )
		s = t.createChild( "s" )
		if writeInvalidUSDName:
			invalidUSDName = m.createChild( "r-invalid" )

		if transformRootChildren:
			t.writeTransform( IECore.M44dData(imath.M44d().translate(imath.V3d( 2, 0, 0 ))), 2.0 )
		
		boxA = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( 0 ), imath.V3f( 1 ) ) )
		if writeCs:
			boxA["Cs"] = IECoreScene.PrimitiveVariable(
				IECoreScene.PrimitiveVariable.Interpolation.Vertex,
				IECore.Color3fVectorData(
				[ imath.Color3f( p.x *.5, p.y * 0.5, p.z * 0.5 ) for p in boxA["P"].data ]
				)
			)
		s.writeObject( boxA, 1.0 )


		boxB = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( 1 ), imath.V3f( 2 ) ) )
		if writeCs:
			boxB["Cs"] = IECoreScene.PrimitiveVariable(
				IECoreScene.PrimitiveVariable.Interpolation.Vertex,
				IECore.Color3fVectorData(
				[ imath.Color3f( p.z * .5, p.y * .5, p.x * .5 ) for p in boxA["P"].data ]
				)
			)
		s.writeObject( boxB, 2.0 )
		# need to delete all the SceneCache references to finalise the file
		del m, t, s,
		if writeInvalidUSDName:
			del invalidUSDName
예제 #16
0
    def writeSCC(self, file, rotation=imath.V3d(0, 0, 0), time=0):

        scene = IECoreScene.SceneCache(file, IECore.IndexedIO.OpenMode.Write)
        sc = scene.createChild(str(1))
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        sc.writeObject(mesh, time)
        matrix = imath.M44d().translate(imath.V3d(1, 0, 0))
        matrix = matrix.rotate(rotation)
        sc.writeTransform(IECore.M44dData(matrix), time)

        sc = sc.createChild(str(2))
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        sc.writeObject(mesh, time)
        matrix = imath.M44d().translate(imath.V3d(2, 0, 0))
        matrix = matrix.rotate(rotation)
        sc.writeTransform(IECore.M44dData(matrix), time)

        sc = sc.createChild(str(3))
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        sc.writeObject(mesh, time)
        matrix = imath.M44d().translate(imath.V3d(3, 0, 0))
        matrix = matrix.rotate(rotation)
        sc.writeTransform(IECore.M44dData(matrix), time)

        return scene
예제 #17
0
    def testDirection(self):

        first = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        second = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)

        c["c1"] = first
        c["c2"] = second

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -4, 0), imath.V3f(1, 4, 0)))
        self.assertEqual(first.getTransform(),
                         imath.M44f().translate(imath.V3f(0, -2, 0)))
        self.assertEqual(second.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 2, 0)))

        c.setDirection(GafferUI.LinearContainer.Direction.Decreasing)

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -4, 0), imath.V3f(1, 4, 0)))
        self.assertEqual(first.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 2, 0)))
        self.assertEqual(second.getTransform(),
                         imath.M44f().translate(imath.V3f(0, -2, 0)))
예제 #18
0
	def testChildBoundsWhenNoChildren( self ) :

		plane = GafferScene.Plane()
		sphere = GafferScene.Sphere()

		self.assertEqual( plane["out"].childBounds( "/plane" ), imath.Box3f() )
		self.assertEqual( sphere["out"].childBounds( "/sphere" ), imath.Box3f() )
예제 #19
0
    def testSceneCacheRoundtrip(self):

        scene = IECoreScene.SceneCache(
            self.temporaryDirectory() + "/fromPython.scc",
            IECore.IndexedIO.OpenMode.Write)
        sc = scene.createChild("a")
        sc.writeObject(
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(0), imath.V3f(1))), 0)
        matrix = imath.M44d().translate(imath.V3d(1, 0, 0)).rotate(
            imath.V3d(0, 0, IECore.degreesToRadians(-30)))
        sc.writeTransform(IECore.M44dData(matrix), 0)
        sc = sc.createChild("b")
        sc.writeObject(
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(0), imath.V3f(1))), 0)
        sc.writeTransform(IECore.M44dData(matrix), 0)
        sc = sc.createChild("c")
        sc.writeObject(
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(0), imath.V3f(1))), 0)
        sc.writeTransform(IECore.M44dData(matrix), 0)

        del scene, sc

        def testCacheFile(f):
            sc = IECoreScene.SceneCache(f, IECore.IndexedIO.OpenMode.Read)
            a = sc.child("a")
            self.assertTrue(a.hasObject())
            self.assertIsInstance(a.readObject(0), IECoreScene.MeshPrimitive)
            self.assertTrue(
                a.readTransformAsMatrix(0).equalWithAbsError(matrix, 1e-6))
            b = a.child("b")
            self.assertTrue(b.hasObject())
            self.assertIsInstance(b.readObject(0), IECoreScene.MeshPrimitive)
            self.assertTrue(
                b.readTransformAsMatrix(0).equalWithAbsError(matrix, 1e-6))
            c = b.child("c")
            self.assertTrue(c.hasObject())
            self.assertIsInstance(c.readObject(0), IECoreScene.MeshPrimitive)
            self.assertTrue(
                c.readTransformAsMatrix(0).equalWithAbsError(matrix, 1e-6))

        testCacheFile(self.temporaryDirectory() + "/fromPython.scc")

        reader = GafferScene.SceneReader()
        reader["fileName"].setValue(self.temporaryDirectory() +
                                    "/fromPython.scc")

        script = Gaffer.ScriptNode()
        writer = GafferScene.SceneWriter()
        script["writer"] = writer
        writer["in"].setInput(reader["out"])
        writer["fileName"].setValue(self.temporaryDirectory() + "/test.scc")
        writer.execute()
        os.remove(self.temporaryDirectory() + "/fromPython.scc")

        testCacheFile(self.temporaryDirectory() + "/test.scc")
예제 #20
0
    def testEquality(self):
        """Test Box3f comparison for equality"""

        b1 = imath.Box3f(imath.V3f(1.0, 2.0, 3.0))
        b2 = imath.Box3f(imath.V3f(1.0, 2.0, 3.0))
        self.assert_(b1 == b2)

        b2 = imath.Box3f(imath.V3f(3.0, 2.0, 1.0))
        self.assert_(b1 != b2)
예제 #21
0
	def test( self ) :

		s = GafferUI.SpacerGadget( imath.Box3f( imath.V3f( -1 ), imath.V3f( 3 ) ) )
		self.assertEqual( s.bound(), imath.Box3f( imath.V3f( -1 ), imath.V3f( 3 ) ) )

		t = GafferUI.TextGadget( "t" )
		self.assertFalse( s.acceptsChild( t ) )

		self.assertRaises( RuntimeError, s.addChild, t )
예제 #22
0
	def testTransformAffectsParentBound( self ) :

		l = GafferSceneTest.TestLight()

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

		# No transform

		self.assertEqual(
			l["out"].bound( "/" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			l["out"].bound( "/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		self.assertEqual(
			g["out"].bound( "/" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		# Transform

		l["transform"]["translate"].setValue( imath.V3f( 1 ) )

		self.assertEqual(
			l["out"].bound( "/" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			l["out"].bound( "/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		self.assertEqual(
			g["out"].bound( "/" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
예제 #23
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 ) ) )
예제 #24
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 ) ) )
예제 #25
0
    def test(self):

        p = GafferScene.Plane()
        outputs = GafferScene.Outputs()
        outputs["in"].setInput(p["out"])

        # check that the scene hierarchy is passed through

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

        self.assertEqual(
            outputs["out"].object("/plane"),
            IECoreScene.MeshPrimitive.createPlane(
                imath.Box2f(imath.V2f(-0.5), imath.V2f(0.5))))
        self.assertEqual(outputs["out"].transform("/plane"), imath.M44f())
        self.assertEqual(
            outputs["out"].bound("/plane"),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))
        self.assertEqual(outputs["out"].childNames("/plane"),
                         IECore.InternedStringVectorData())

        # check that we have some outputs

        output = outputs.addOutput(
            "beauty", IECoreScene.Output("beauty.exr", "exr", "rgba"))
        output["parameters"].addChild(
            Gaffer.NameValuePlug("test", IECore.FloatData(10)))

        outputs.addOutput(
            "diffuse",
            IECoreScene.Output("diffuse.exr", "exr", "color aov_diffuse"))

        g = outputs["out"]["globals"].getValue()
        self.assertEqual(len(g), 2)
        self.assertEqual(
            g["output:beauty"],
            IECoreScene.Output("beauty.exr", "exr", "rgba", {"test": 10.0}))
        self.assertEqual(
            g["output:diffuse"],
            IECoreScene.Output("diffuse.exr", "exr", "color aov_diffuse"))

        # check that we can turn 'em off as well
        output["active"].setValue(False)

        g = outputs["out"]["globals"].getValue()
        self.assertEqual(len(g), 1)
        self.assertEqual(
            g["output:diffuse"],
            IECoreScene.Output("diffuse.exr", "exr", "color aov_diffuse"))
예제 #26
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 ) ) )
예제 #27
0
    def __frame(self, nodes, extend=False):

        graphGadget = self.graphGadget()

        # get the bounds of the nodes
        bound = imath.Box3f()
        for node in nodes:
            nodeGadget = graphGadget.nodeGadget(node)
            if nodeGadget:
                bound.extendBy(nodeGadget.transformedBound(graphGadget))

        # if there were no nodes then use the bound of the whole
        # graph.
        if bound.isEmpty():
            bound = graphGadget.bound()

        # if there's still nothing then an arbitrary area in the centre of the world
        if bound.isEmpty():
            bound = imath.Box3f(imath.V3f(-10, -10, 0), imath.V3f(10, 10, 0))

        # pad it a little bit so
        # it sits nicer in the frame
        bound.setMin(bound.min() - imath.V3f(1, 1, 0))
        bound.setMax(bound.max() + imath.V3f(1, 1, 0))

        if extend:
            # we're extending the existing framing, which we assume the
            # user was happy with other than it not showing the nodes in question.
            # so we just take the union of the existing frame and the one for the nodes.
            cb = self.__currentFrame()
            bound.extendBy(
                imath.Box3f(imath.V3f(cb.min().x,
                                      cb.min().y, 0),
                            imath.V3f(cb.max().x,
                                      cb.max().y, 0)))
        else:
            # we're reframing from scratch, so the frame for the nodes is all we need.
            # we do however want to make sure that we don't zoom in too far if the node
            # bounds are small, as having a single node filling the screen is of little use -
            # it's better to see some context around it.
            boundSize = bound.size()
            widgetSize = imath.V3f(self._qtWidget().width(),
                                   self._qtWidget().height(), 0)

            pixelsPerUnit = min(widgetSize.x / boundSize.x,
                                widgetSize.y / boundSize.y)
            adjustedPixelsPerUnit = min(pixelsPerUnit, 10)

            newBoundSize = widgetSize / adjustedPixelsPerUnit
            boundCenter = bound.center()
            bound.setMin(boundCenter - newBoundSize / 2.0)
            bound.setMax(boundCenter + newBoundSize / 2.0)

        self.__gadgetWidget.getViewportGadget().frame(bound)
예제 #28
0
    def testThreading(self):

        sphere = IECoreScene.SpherePrimitive()
        instanceInput = GafferSceneTest.CompoundObjectSource()
        instanceInput["in"].setValue(
            IECore.CompoundObject({
                "bound":
                IECore.Box3fData(imath.Box3f(imath.V3f(-2), imath.V3f(2))),
                "children": {
                    "sphere": {
                        "object":
                        sphere,
                        "bound":
                        IECore.Box3fData(sphere.bound()),
                        "transform":
                        IECore.M44fData(imath.M44f().scale(imath.V3f(2))),
                    },
                }
            }))

        seeds = IECoreScene.PointsPrimitive(
            IECore.V3fVectorData([
                imath.V3f(1, 0, 0),
                imath.V3f(1, 1, 0),
                imath.V3f(0, 1, 0),
                imath.V3f(0, 0, 0)
            ]))
        seedsInput = GafferSceneTest.CompoundObjectSource()
        seedsInput["in"].setValue(
            IECore.CompoundObject(
                {
                    "bound":
                    IECore.Box3fData(
                        imath.Box3f(imath.V3f(1, 0, 0), imath.V3f(2, 1, 0))),
                    "children": {
                        "seeds": {
                            "bound":
                            IECore.Box3fData(seeds.bound()),
                            "transform":
                            IECore.M44fData(imath.M44f().translate(
                                imath.V3f(1, 0, 0))),
                            "object":
                            seeds,
                        },
                    },
                }, ))

        instancer = GafferScene.Instancer()
        instancer["in"].setInput(seedsInput["out"])
        instancer["instances"].setInput(instanceInput["out"])
        instancer["parent"].setValue("/seeds")
        instancer["name"].setValue("instances")

        GafferSceneTest.traverseScene(instancer["out"])
예제 #29
0
	def test( 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,
							},
						},
					},
				},
			} ),
		)

		self.assertSceneValid( input["out"] )

		transform = GafferScene.Transform()
		transform["in"].setInput( input["out"] )

		# by default transform should do nothing

		self.assertSceneValid( transform["out"] )
		self.assertScenesEqual( transform["out"], input["out"] )

		# even when setting a transform it should do nothing, as
		# it requires a filter before operating (applying the same transform
		# at every location is really not very useful).

		transform["transform"]["translate"].setValue( imath.V3f( 1, 2, 3 ) )

		self.assertSceneValid( transform["out"] )
		self.assertScenesEqual( transform["out"], input["out"] )

		# applying a filter should cause things to happen

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

		self.assertSceneValid( transform["out"] )

		self.assertEqual( transform["out"].transform( "/group/sphere" ), imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) )
		self.assertEqual( transform["out"].transform( "/group" ), imath.M44f() )

		self.assertEqual( transform["out"].bound( "/group/sphere" ), imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) )
		self.assertEqual( transform["out"].bound( "/group" ), imath.Box3f( imath.V3f( 0, 1, 2 ), imath.V3f( 2, 3, 4 ) ) )
		self.assertEqual( transform["out"].bound( "/" ), imath.Box3f( imath.V3f( 0, 1, 2 ), imath.V3f( 2, 3, 4 ) ) )
예제 #30
0
	def testPlugs( self ) :

		c = GafferScene.Cube()
		m = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ) )
		self.assertEqual( c["out"].object( "/cube" ), m )
		h = c["out"].objectHash( "/cube" )

		c["dimensions"].setValue( imath.V3f( 2.5, 5, 6 ) )
		m = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -1.25, -2.5, -3 ), imath.V3f( 1.25, 2.5, 3 ) ) )
		self.assertEqual( c["out"].object( "/cube" ), m )
		self.assertNotEqual( c["out"].objectHash( "/cube" ), h )