Beispiel #1
0
    def testBound(self):
        fileName = "{}/testUSDBounds.scc".format(self.temporaryDirectory())
        self._writeScene(fileName)

        # root
        stage = pxr.Usd.Stage.Open(fileName)
        root = stage.GetPseudoRoot()
        prim = root.GetPrimAtPath("/t/s")

        extent = prim.GetAttribute("extent")
        self.assertEqual(
            extent.Get(24.0),
            pxr.Vt.Vec3fArray(2,
                              [pxr.Gf.Vec3f(0, 0, 0),
                               pxr.Gf.Vec3f(1, 1, 1)]))
        self.assertEqual(
            extent.Get(48.0),
            pxr.Vt.Vec3fArray(2,
                              [pxr.Gf.Vec3f(1, 1, 1),
                               pxr.Gf.Vec3f(2, 2, 2)]))

        # round trip
        exportPath = "{}/testUSDExportBounds.scc".format(
            self.temporaryDirectory())
        stage.Export(exportPath)

        scene = IECoreScene.SharedSceneInterfaces.get(exportPath)
        location = scene.scene(["t", "s"])

        self.assertEqual(location.readBound(1),
                         imath.Box3d(imath.V3d(0), imath.V3d(1)))
        self.assertEqual(location.readBound(2),
                         imath.Box3d(imath.V3d(1), imath.V3d(2)))
Beispiel #2
0
	def testAnimatedTransform( self ) :

		sphere = maya.cmds.polySphere( name="pSphere1" )

		maya.cmds.setKeyframe( "pSphere1", attribute="tx", t="0sec", v=1 )
		maya.cmds.setKeyframe( "pSphere1", attribute="ty", t="0sec", v=2 )
		maya.cmds.setKeyframe( "pSphere1", attribute="tz", t="0sec", v=3 )

		maya.cmds.setKeyframe( "pSphere1", attribute="tx", t="1sec", v=4 )
		maya.cmds.setKeyframe( "pSphere1", attribute="ty", t="1sec", v=5 )
		maya.cmds.setKeyframe( "pSphere1", attribute="tz", t="1sec", v=6 )

		scene = IECoreMaya.LiveScene()
		transformChild = scene.child( "pSphere1" )

		# test it returns the correct transform in local space
		maya.cmds.currentTime( "0sec" )
		transform0 = transformChild.readTransform( 0 ).value
		maya.cmds.currentTime( "0.5sec" )
		transform0_5 = transformChild.readTransform( 0.5 ).value
		maya.cmds.currentTime( "1sec" )
		transform1 = transformChild.readTransform( 1 ).value

		self.assertEqual( transform0.translate, imath.V3d( 1, 2, 3 ) )

		self.assertAlmostEqual( transform0_5.translate.x, 2.5, 5 )
		self.assertAlmostEqual( transform0_5.translate.y, 3.5, 5 )
		self.assertAlmostEqual( transform0_5.translate.z, 4.5, 5 )

		self.assertEqual( transform1.translate, imath.V3d( 4, 5, 6 ) )
	def testTransform(self):
		"""Test TransformationMatrixd transform"""
		a = IECore.TransformationMatrixd()
		a.scale = imath.V3d( 2, 2, 2 )
		self.assertEqual( a.transform, imath.M44d().scale( imath.V3d( 2, 2, 2 ) ) )
		a.rotate = imath.Eulerd( 0.2, 0.2, 0.2 )
		self.assertTrue( a.transform.equalWithAbsError( imath.M44d().scale( imath.V3d( 2, 2, 2 ) ) * imath.Eulerd( 0.2, 0.2, 0.2 ).toMatrix44(), 0.01 ) )
Beispiel #4
0
	def testTransform( self ):
		fileName = "{}/testUSDTranform.scc".format( self.temporaryDirectory() )
		m = IECoreScene.SceneCache( fileName, IECore.IndexedIO.OpenMode.Write )
		t = m.createChild( "t" )
		transformA = imath.V3d( 1, 0, 0 )
		transformB = imath.V3d( 2, 0, 0 )
		t.writeTransform( IECore.M44dData( imath.M44d().translate( transformA ) ), 1.0 )
		t.writeTransform( IECore.M44dData( imath.M44d().translate( transformB ) ), 2.0 )
		del m, t

		# root
		stage = pxr.Usd.Stage.Open( fileName )
		root = stage.GetPseudoRoot()
		prim = root.GetPrimAtPath( "/{}/t".format( IECoreUSD.SceneCacheDataAlgo.internalRootName() ) )

		transform = prim.GetAttribute( "xformOp:transform" )
		self.assertEqual( transform.Get( 24.0 ), pxr.Gf.Matrix4d(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 ) )
		self.assertEqual( transform.Get( 48.0 ), pxr.Gf.Matrix4d(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 0.0, 1.0 ) )

		# round trip
		exportPath = "{}/testUSDExportTransform.scc".format( self.temporaryDirectory() )
		stage.Export( exportPath )

		scene = IECoreScene.SharedSceneInterfaces.get( exportPath )
		t = scene.child( "t" )
		self.assertEqual( t.readTransformAsMatrix( 1 ).translation(), transformA )
		self.assertEqual( t.readTransformAsMatrix( 2 ).translation(), transformB )
Beispiel #5
0
    def makeRandomBound(self):
        b1 = imath.V3d(random.random(), random.random(), random.random())
        b2 = imath.V3d(random.random(), random.random(), random.random())
        bound = imath.Box3d(b1)
        bound.extendBy(b2)

        return bound
    def testVectorLinearInterpolation(self):

        self.assertEqual(
            IECore.linearObjectInterpolation(IECore.IntVectorData([1]),
                                             IECore.IntVectorData([2]), 0.5),
            None)
        self.assertEqual(
            IECore.linearObjectInterpolation(IECore.FloatVectorData([1]),
                                             IECore.FloatVectorData([2]), 0.5),
            IECore.FloatVectorData([1.5]))
        self.assertEqual(
            IECore.linearObjectInterpolation(IECore.DoubleVectorData([1]),
                                             IECore.DoubleVectorData([2]),
                                             0.5),
            IECore.DoubleVectorData([1.5]))
        self.assertEqual(
            IECore.linearObjectInterpolation(
                IECore.V2fVectorData([imath.V2f(1)]),
                IECore.V2fVectorData([imath.V2f(2)]), 0.5),
            IECore.V2fVectorData([imath.V2f(1.5)]))
        self.assertEqual(
            IECore.linearObjectInterpolation(
                IECore.V3fVectorData([imath.V3f(1)]),
                IECore.V3fVectorData([imath.V3f(2)]), 0.5),
            IECore.V3fVectorData([imath.V3f(1.5)]))
        self.assertEqual(
            IECore.linearObjectInterpolation(
                IECore.V2dVectorData([imath.V2d(1)]),
                IECore.V2dVectorData([imath.V2d(2)]), 0.5),
            IECore.V2dVectorData([imath.V2d(1.5)]))
        self.assertEqual(
            IECore.linearObjectInterpolation(
                IECore.V3dVectorData([imath.V3d(1)]),
                IECore.V3dVectorData([imath.V3d(2)]), 0.5),
            IECore.V3dVectorData([imath.V3d(1.5)]))
Beispiel #7
0
	def testConcave( self ) :

		verticesPerFace = IECore.IntVectorData()
		verticesPerFace.append( 4 )

		vertexIds = IECore.IntVectorData()
		vertexIds.append( 0 )
		vertexIds.append( 1 )
		vertexIds.append( 2 )
		vertexIds.append( 3 )

		P = IECore.V3dVectorData()
		P.append( imath.V3d( -1, 0, -1 ) )
		P.append( imath.V3d( -1, 0,  1 ) )
		P.append( imath.V3d(  1, 0,  1 ) )
		P.append( imath.V3d(  -0.9, 0, -0.9 ) )

		m = IECoreScene.MeshPrimitive( verticesPerFace, vertexIds )
		m["P"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, P )

		def testTriangulate():
			IECoreScene.MeshAlgo.triangulate( m, throwExceptions = True )

		# Concave faces not supported by default
		self.assertRaises( RuntimeError, testTriangulate )

		result = IECoreScene.MeshAlgo.triangulate( m )
Beispiel #8
0
    def testConcave(self):
        """ Test TriangulateOp with a concave polygon"""

        verticesPerFace = IECore.IntVectorData()
        verticesPerFace.append(4)

        vertexIds = IECore.IntVectorData()
        vertexIds.append(0)
        vertexIds.append(1)
        vertexIds.append(2)
        vertexIds.append(3)

        P = IECore.V3dVectorData()
        P.append(imath.V3d(-1, 0, -1))
        P.append(imath.V3d(-1, 0, 1))
        P.append(imath.V3d(1, 0, 1))
        P.append(imath.V3d(-0.9, 0, -0.9))

        m = IECoreScene.MeshPrimitive(verticesPerFace, vertexIds)
        m["P"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, P)

        op = IECoreScene.TriangulateOp()

        op["input"] = m

        # Concave faces not supported by default
        self.assertRaises(RuntimeError, op)

        op.parameters()["throwExceptions"] = False
        result = op()
    def testPerFrameWrite(self):
        fileName = "{}/testPerFrameWrite.scc".format(self.temporaryDirectory())
        frames = list(range(1, 25))
        for i in frames:
            stage = pxr.Usd.Stage.CreateInMemory()
            sphere = pxr.UsdGeom.Sphere.Define(stage, "/Sphere")
            attr = sphere.GetRadiusAttr()
            attr.Set(10, 1)
            attr.Set(100, 24)
            args = {
                "perFrameWrite": "1",
                "currentFrame": str(i),
                "firstFrame": str(frames[0]),
                "lastFrame": str(frames[-1]),
            }

            stage.Export(fileName, args=args)

        scene = IECoreScene.SharedSceneInterfaces.get(fileName)
        sphere = scene.child("Sphere")

        self.assertTrue(sphere)
        self.assertTrue(
            isinstance(sphere.readObject(0), IECoreScene.SpherePrimitive))

        self.assertEqual(sphere.readBound(0),
                         imath.Box3d(imath.V3d(-10), imath.V3d(10)))
        self.assertNotEqual(sphere.readBound(0.5), sphere.readBound(0))
        self.assertEqual(sphere.readBound(1),
                         imath.Box3d(imath.V3d(-100), imath.V3d(100)))
Beispiel #10
0
    def testWriteAnimation(self):

        script = Gaffer.ScriptNode()
        script["sphere"] = GafferScene.Sphere()
        script["group"] = GafferScene.Group()
        script["group"]["in"][0].setInput(script["sphere"]["out"])
        script["xExpression"] = Gaffer.Expression()
        script["xExpression"].setExpression(
            'parent["group"]["transform"]["translate"]["x"] = context.getFrame()'
        )
        script["zExpression"] = Gaffer.Expression()
        script["zExpression"].setExpression(
            'parent["group"]["transform"]["translate"]["z"] = context.getFrame() * 2'
        )
        script["writer"] = GafferScene.SceneWriter()
        script["writer"]["in"].setInput(script["group"]["out"])
        script["writer"]["fileName"].setValue(self.temporaryDirectory() +
                                              "/test.scc")

        with Gaffer.Context():
            script["writer"].executeSequence([1, 1.5, 2])

        sc = IECoreScene.SceneCache(self.temporaryDirectory() + "/test.scc",
                                    IECore.IndexedIO.OpenMode.Read)
        t = sc.child("group")

        self.assertEqual(t.readTransformAsMatrix(0),
                         imath.M44d().translate(imath.V3d(1, 0, 2)))
        self.assertEqual(t.readTransformAsMatrix(1 / 24.0),
                         imath.M44d().translate(imath.V3d(1, 0, 2)))
        self.assertEqual(t.readTransformAsMatrix(1.5 / 24.0),
                         imath.M44d().translate(imath.V3d(1.5, 0, 3)))
        self.assertEqual(t.readTransformAsMatrix(2 / 24.0),
                         imath.M44d().translate(imath.V3d(2, 0, 4)))
Beispiel #11
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
Beispiel #12
0
    def _get_bounds(self):
        #TODO: ugly code needs refactor
        if self.state.scenes:
            bounds = None
            for scene in self.state.scenes:
                if not scene.loaded:
                    continue
                if bounds is None or scene.bounds().max() > bounds.max():
                    bounds = scene.bounds()
                    min = bounds.min()
                    max = bounds.max()
                    if scene.properties.get("translate"):
                        max = max * imath.V3d(*scene.translate)
                        min = min * imath.V3d(*scene.translate)
                    if scene.properties.get("scale"):
                        max = max * imath.V3d(*scene.scale)
                        min = min * imath.V3d(*scene.scale)
                    bounds = imath.Box3d(min, max)

            if bounds is None:
                return self.__bounds_default
            self.__bounds = bounds
            return self.__bounds
        else:
            return self.__bounds_default
Beispiel #13
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 )
Beispiel #14
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
Beispiel #15
0
def mesh_out(name="cask_test_mesh.abc", force=False):
    filename = os.path.join(TEMPDIR, name)
    if not force and (os.path.exists(filename) and cask.is_valid(filename)):
        return filename

    oarch = alembic.Abc.OArchive(filename)
    meshyObj = alembic.AbcGeom.OPolyMesh(oarch.getTop(), 'meshy')
    mesh = meshyObj.getSchema()

    uvsamp = alembic.AbcGeom.OV2fGeomParamSample(meshData.uvs,
                                                 kFacevaryingScope)
    nsamp = alembic.AbcGeom.ON3fGeomParamSample(meshData.normals,
                                                kFacevaryingScope)
    mesh_samp = alembic.AbcGeom.OPolyMeshSchemaSample(meshData.verts,
                                                      meshData.indices,
                                                      meshData.counts, uvsamp,
                                                      nsamp)

    cbox = imath.Box3d()
    cbox.extendBy(imath.V3d(1.0, -1.0, 0.0))
    cbox.extendBy(imath.V3d(-1.0, 1.0, 3.0))

    for i in range(10):
        mesh.getChildBoundsProperty().setValue(cbox)
        mesh.set(mesh_samp)

    del oarch
    return filename
Beispiel #16
0
    def testChildNamesHash(self):

        s = IECoreScene.SceneCache("/tmp/test.scc",
                                   IECore.IndexedIO.OpenMode.Write)
        sphereGroup = s.createChild("sphereGroup")
        sphereGroup.writeTransform(
            IECore.M44dData(imath.M44d().translate(imath.V3d(1, 0, 0))), 0.0)
        sphereGroup.writeTransform(
            IECore.M44dData(imath.M44d().translate(imath.V3d(2, 0, 0))), 1.0)
        sphere = sphereGroup.createChild("sphere")
        sphere.writeObject(IECoreScene.SpherePrimitive(), 0)

        del s, sphereGroup, sphere

        s = GafferScene.SceneReader()
        s["fileName"].setValue("/tmp/test.scc")
        s["refreshCount"].setValue(
            self.uniqueInt("/tmp/test.scc")
        )  # account for our changing of file contents between tests

        t = GafferScene.SceneTimeWarp()
        t["in"].setInput(s["out"])
        t["offset"].setValue(1)

        self.assertSceneHashesEqual(s["out"],
                                    t["out"],
                                    childPlugNames=["childNames"])
Beispiel #17
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 testConstructors(self):
		"""Test TransformationMatrixd constructors"""
		a = IECore.TransformationMatrixd()
		self.assertEqual( a.transform, imath.M44d() )
		a = IECore.TransformationMatrixd( imath.V3d( 2, 2, 2 ), imath.Eulerd(), imath.V3d( 1, 0, 0 ) )
		self.assertTrue( a.transform.equalWithAbsError( imath.M44d().scale( imath.V3d(2,2,2) ) * imath.M44d().translate( imath.V3d(1,0,0) ), 0.01 ) )
		b = IECore.TransformationMatrixd( a )
		self.assertEqual( a.transform, b.transform )
Beispiel #19
0
 def testConstructors(self):
     """Test TransformationMatrixdData constructors"""
     a = IECore.TransformationMatrixdData()
     self.assertEqual(a.value, IECore.TransformationMatrixd())
     a = IECore.TransformationMatrixdData(
         IECore.TransformationMatrixd(imath.V3d(2, 2, 2), imath.Eulerd(),
                                      imath.V3d(1, 0, 0)))
     self.assertEqual(a.value.scale, imath.V3d(2, 2, 2))
Beispiel #20
0
	def testBound( self ) :

		root = IECoreScene.SceneInterface.create( os.path.dirname( __file__ ) + "/data/cube.usda", IECore.IndexedIO.OpenMode.Read )
		cube = root.child( "pCube1" )

		bound = cube.readBound( 0.0 )

		self.assertEqual( bound, imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )
	def testCopy(self):
		"""Test TransformationMatrixdData copy"""
		a = IECore.TransformationMatrixdData( IECore.TransformationMatrixd( imath.V3d( 2, 2, 2 ), imath.Eulerd(), imath.V3d( 1, 0, 0 ) ) )
		self.assertEqual( a.value.scale, imath.V3d( 2, 2, 2 ) )
		b = a.copy()
		a.value = IECore.TransformationMatrixd()
		self.assertEqual( b.value.scale, imath.V3d( 2, 2, 2 ) )
		self.assertEqual( a.value.scale, imath.V3d( 1, 1, 1 ) )
Beispiel #22
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")
	def testComparison(self):
		"""Test TransformationMatrixdData comparison"""
		a = IECore.TransformationMatrixdData()
		b = IECore.TransformationMatrixdData()
		self.assertEqual( a, b )
		b.value = IECore.TransformationMatrixd( imath.V3d( 0.00001, 0, 0 ), imath.Eulerd(), imath.V3d(0,0,0) )
		self.assertNotEqual( a, b )
		a.value = IECore.TransformationMatrixd( imath.V3d( 0.00001, 0, 0 ), imath.Eulerd(), imath.V3d(0,0,0) )
		self.assertEqual( a, b )
Beispiel #24
0
 def testComparison(self):
     """Test TransformationMatrixd comparison"""
     a = IECore.TransformationMatrixd()
     b = IECore.TransformationMatrixd()
     self.assertEqual(a, b)
     b.scalePivot = imath.V3d(0.00001, 0, 0)
     self.assertNotEqual(a, b)
     a.scalePivot = imath.V3d(0.00001, 0, 0)
     self.assertEqual(a, b)
	def testReadBound( self ) :

		scene = self.buildScene()
		hou.node( "/obj/sub1" ).parmTuple( "t" ).set( [ 1, 1, 1 ] )
		hou.node( "/obj/sub1/torus1" ).parmTuple( "t" ).set( [ 2, 2, 2 ] )
		hou.node( "/obj/sub1/torus2" ).parmTuple( "t" ).set( [ -1, 0, 2 ] )
		hou.node( "/obj/box1" ).parmTuple( "t" ).set( [ -1, -1, -1 ] )
		# to make the bounds nice round numbers
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "cols" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "cols" ).set( 100 )

		self.assertEqual( scene.child( "box2" ).readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		sub1 = scene.child( "sub1" )
		box1 = sub1.child( "box1" )
		self.assertEqual( box1.readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		torus1 = sub1.child( "torus1" )
		torus2 = torus1.child( "torus2" )
		self.assertEqual( torus2.readBound( 0 ), imath.Box3d( imath.V3d( -1.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 1.5 ) ) )
		self.assertEqual( torus1.readBound( 0 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( sub1.readBound( 0 ), imath.Box3d( imath.V3d( -1.5 ), imath.V3d( 3.5, 2.5, 5.5 ) ) )
		self.assertEqual( scene.readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 4.5, 3.5, 6.5 ) ) )
Beispiel #26
0
    def testIO(self):
        """Test TransformationMatrixdData IO"""
        a = IECore.TransformationMatrixdData(
            IECore.TransformationMatrixd(imath.V3d(2, 3, 4), imath.Eulerd(),
                                         imath.V3d(1, 2, 3)))
        w = IECore.ObjectWriter(a, self.testFile)
        w.write()

        r = IECore.ObjectReader(self.testFile)
        b = r.read()
        self.assertEqual(a, b)
Beispiel #27
0
    def testBound(self):

        a = IECoreScene.SceneInterface.create(
            os.path.dirname(__file__) + "/data/cube.abc",
            IECore.IndexedIO.OpenMode.Read)
        self.assertEqual(a.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-2), imath.V3d(2)))

        cs = a.child("group1").child("pCube1")
        self.assertEqual(cs.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-1), imath.V3d(1)))
    def testCanReadBounds(self):
        bound = self.sceneInterface.readBound(0.0)

        expectedBound = imath.Box3d(
            imath.V3d([
                -33.809524536132812, -12.380952835083008, -26.190475463867188
            ]),
            imath.V3d(
                [19.047618865966797, 93.333335876464844, 27.142856597900391]))

        self.assertEqual(bound, expectedBound)
Beispiel #29
0
    def test_child_bounds(self):
        filename_1 = os.path.join(TEMPDIR, "cask_child_bounds_1.abc")
        filename_2 = os.path.join(TEMPDIR, "cask_child_bounds_2.abc")
        filename_3 = os.path.join(TEMPDIR, "cask_child_bounds_3.abc")

        # create initial archive with initial value
        bounds = imath.Box3d(
            imath.V3d(1, 1, 1), imath.V3d(1, 1, 1)
        )
        a = cask.Archive()
        x = a.top.children["foo"] = cask.Xform()
        p = x.properties[".xform/.childBnds"] = cask.Property()
        p.set_value(bounds)
        self.assertEqual(p.values[0], bounds)
        a.write_to_file(filename_1)
        a.close()

        # verify export / value
        b = cask.Archive(filename_1)
        p = b.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")
        
        # set a new child bounds value and export
        bounds = imath.Box3d(
            imath.V3d(-5, -5, -5), imath.V3d(5, 5, 5)
        )
        p.values[0] = bounds
        self.assertEqual(p.values[0], bounds)
        b.write_to_file(filename_2)
        b.close()

        # verify the updated value in the export
        c = cask.Archive(filename_2)
        p = c.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")

        # reinitialize the property and export
        p = c.top.children["foo"].properties[".xform/.childBnds"] = cask.Property()
        p.set_value(bounds)
        c.write_to_file(filename_3)
        c.close()

        # re-verify the updated value in the export
        d = cask.Archive(filename_3)
        p = d.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")
Beispiel #30
0
    def testStructureConvertion(self):
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.V3fData(imath.V3f(1, 2, 3)),
                                targetType=int(IECore.TypeId.FloatVectorData)),
            IECore.FloatVectorData([1, 2, 3]))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.V3fData(imath.V3f(1, 2, 3)),
                                targetType=int(IECore.TypeId.Color3fData)),
            IECore.Color3fData(imath.Color3f(1, 2, 3)))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.V3fVectorData(
                [imath.V3f(1), imath.V3f(2),
                 imath.V3f(3)]),
                                targetType=int(IECore.TypeId.FloatVectorData)),
            IECore.FloatVectorData([1, 1, 1, 2, 2, 2, 3, 3, 3]))

        self.assertEqual(
            IECore.DataCastOp()(object=IECore.FloatVectorData([1, 2, 3]),
                                targetType=int(IECore.TypeId.V3fData)),
            IECore.V3fData(imath.V3f(1, 2, 3)))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.Color3fData(
                imath.Color3f(1, 2, 3)),
                                targetType=int(IECore.TypeId.V3fData)),
            IECore.V3fData(imath.V3f(1, 2, 3)))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.FloatVectorData(
                [1, 1, 1, 2, 2, 2, 3, 3, 3]),
                                targetType=int(IECore.TypeId.V3fVectorData)),
            IECore.V3fVectorData([imath.V3f(1),
                                  imath.V3f(2),
                                  imath.V3f(3)]))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.V3fVectorData(
                [imath.V3f(1), imath.V3f(2),
                 imath.V3f(3)]),
                                targetType=int(
                                    IECore.TypeId.Color3fVectorData)),
            IECore.Color3fVectorData(
                [imath.Color3f(1),
                 imath.Color3f(2),
                 imath.Color3f(3)]))
        self.assertEqual(
            IECore.DataCastOp()(object=IECore.V3dVectorData(
                [imath.V3d(1), imath.V3d(2),
                 imath.V3d(3)]),
                                targetType=int(
                                    IECore.TypeId.Color3fVectorData)),
            IECore.Color3fVectorData(
                [imath.Color3f(1),
                 imath.Color3f(2),
                 imath.Color3f(3)]))