Example #1
0
	def test( self ) :

		locatorTransform = maya.cmds.spaceLocator()[0]

		c = IECoreMaya.FromMayaDagNodeConverter.create( str( locatorTransform ), IECore.TypeId.TransformationMatrixdData )

		self.assertEqual( IECoreMaya.TypeId.FromMayaTransformConverter, IECoreMaya.FromMayaTransformConverter.staticTypeId() )
		self.assertEqual( c.typeId(), IECoreMaya.FromMayaTransformConverter.staticTypeId() )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d() )

		maya.cmds.xform( locatorTransform, translation=( 1, 2, 3 ) )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d().translate( imath.V3d( 1, 2, 3 ) ) )

		group = maya.cmds.group( locatorTransform )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d().translate( imath.V3d( 1, 2, 3 ) ) )

		maya.cmds.xform( group, translation=( 1, 0, 10 ) )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d().translate( imath.V3d( 2, 2, 13 ) ) )

		c["space"].setValue( "Local" )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d().translate( imath.V3d( 1, 2, 3 ) ) )

		# test custom space
		customSpace = imath.M44f()
		customSpace.setScale( imath.V3f( 0.5, 0.5, 0.5 ) )
		c["space"].setValue( "Custom" )
		c["customSpace"].setValue( IECore.M44fData( customSpace ) )
		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		expectedResult = imath.M44d( 2, 0, 0, 0,   0, 2, 0, 0,   0, 0, 2, 0,   4, 4, 26, 1 )
		self.assertEqual( t.value.transform, expectedResult )
		# sanity check: if we apply the custom space to the result we should get the world space result
		self.assertEqual( t.value.transform * imath.M44d().scale( imath.V3d( 0.5, 0.5, 0.5 ) ), imath.M44d().translate( imath.V3d( 2, 2, 13 ) ) )

		locatorShape = maya.cmds.listRelatives( locatorTransform, children=True )[0]

		c = IECoreMaya.FromMayaTransformConverter( str( locatorShape ) )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d().translate( imath.V3d( 2, 2, 13 ) ) )

		c["space"].setValue( "Local" )

		t = c.convert()
		self.assert_( t.isInstanceOf( IECore.TransformationMatrixdData.staticTypeId() ) )
		self.assertEqual( t.value.transform, imath.M44d() )
Example #2
0
    def testStaticHashes(self):

        s = IECoreScene.SceneCache("/tmp/test.scc",
                                   IECore.IndexedIO.OpenMode.Write)

        movingGroup = s.createChild("movingGroup")
        movingGroup.writeTransform(
            IECore.M44dData(imath.M44d().translate(imath.V3d(1, 0, 0))), 0.0)
        movingGroup.writeTransform(
            IECore.M44dData(imath.M44d().translate(imath.V3d(2, 0, 0))), 1.0)

        deformingSphere = movingGroup.createChild("deformingSphere")
        deformingSphere.writeObject(IECoreScene.SpherePrimitive(), 0)
        deformingSphere.writeObject(IECoreScene.SpherePrimitive(2), 1)

        staticGroup = s.createChild("staticGroup")
        staticGroup.writeTransform(
            IECore.M44dData(imath.M44d().translate(imath.V3d(1, 0, 0))), 0.0)

        staticSphere = staticGroup.createChild("staticSphere")
        staticSphere.writeObject(IECoreScene.SpherePrimitive(), 0)

        del s, movingGroup, deformingSphere, staticGroup, staticSphere

        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.assertPathHashesNotEqual(s["out"],
                                      "/movingGroup",
                                      t["out"],
                                      "/movingGroup",
                                      childPlugNames=["transform", "bound"])

        self.assertPathHashesNotEqual(s["out"],
                                      "/movingGroup/deformingSphere",
                                      t["out"],
                                      "/movingGroup/deformingSphere",
                                      childPlugNames=["bound", "object"])

        self.assertPathHashesEqual(s["out"],
                                   "/movingGroup",
                                   t["out"],
                                   "/movingGroup",
                                   childPlugNames=["attributes", "object"])

        self.assertPathHashesEqual(s["out"],
                                   "/movingGroup/deformingSphere",
                                   t["out"],
                                   "/movingGroup/deformingSphere",
                                   childPlugNames=["attributes"])

        self.assertPathHashesEqual(
            s["out"],
            "/staticGroup",
            t["out"],
            "/staticGroup",
            childPlugNames=["object", "transform", "attributes", "bound"])

        self.assertPathHashesEqual(
            s["out"],
            "/staticGroup/staticSphere",
            t["out"],
            "/staticGroup/staticSphere",
            childPlugNames=["object", "transform", "attributes", "bound"])
Example #3
0
    def testPrimVarTypes(self):

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

        object = root.child("root").child("sphere").readObject(0.0)

        expected = {
            'test_Bool_Scalar_constant':
            IECore.BoolData(0),
            'test_Double2_Array_constant':
            IECore.V2dVectorData([
                imath.V2d(1.1, 1.2),
                imath.V2d(2.1, 2.2),
                imath.V2d(3.1, 3.2)
            ]),
            'test_Double2_Scalar_constant':
            IECore.V2dData(imath.V2d(0.1, 0.2)),
            'test_Double3_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_Double3_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_Double_Array_constant':
            IECore.DoubleVectorData([1.2, 1.3, 1.4]),
            'test_Double_Scalar_constant':
            IECore.DoubleData(1.1),
            'test_Float2_Array_constant':
            IECore.V2fVectorData([
                imath.V2f(1.1, 1.2),
                imath.V2f(2.1, 2.2),
                imath.V2f(3.1, 3.2)
            ]),
            'test_Float2_Scalar_constant':
            IECore.V2fData(imath.V2f(0.1, 0.2)),
            'test_Float3_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_Float3_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_Float_Array_constant':
            IECore.FloatVectorData([0.7, 0.8, 0.9]),
            'test_Float_Scalar_constant':
            IECore.FloatData(0.6),
            'test_Half_Array_constant':
            IECore.HalfVectorData([0.0999756, 0.199951, 0.300049]),
            'test_Half_Scalar_constant':
            IECore.HalfData(0.5),
            'test_Int2_Array_constant':
            IECore.V2iVectorData(
                [imath.V2i(3, 4),
                 imath.V2i(5, 6),
                 imath.V2i(7, 8)]),
            'test_Int2_Scalar_constant':
            IECore.V2iData(imath.V2i(1, 2)),
            'test_Int3_Array_constant':
            IECore.V3iVectorData(
                [imath.V3i(3, 4, 5),
                 imath.V3i(5, 6, 7),
                 imath.V3i(7, 8, 9)]),
            'test_Int3_Scalar_constant':
            IECore.V3iData(imath.V3i(1, 2, 3)),
            'test_Int64_Array_constant':
            IECore.Int64VectorData([
                9223372036854775805, 9223372036854775806, 9223372036854775807
            ]),
            'test_Int64_Scalar_constant':
            IECore.Int64Data(-9223372036854775808),
            'test_Int_Array_constant':
            IECore.IntVectorData([0, -1, -2]),
            'test_Int_Scalar_constant':
            IECore.IntData(-1),
            'test_String_Array_constant':
            IECore.StringVectorData(["is", "a", "test"]),
            'test_String_Scalar_constant':
            IECore.StringData('this'),
            'test_Token_Array_constant':
            IECore.InternedStringVectorData([
                IECore.InternedString("t-is"),
                IECore.InternedString("t-a"),
                IECore.InternedString("t-test")
            ]),
            'test_Token_Scalar_constant':
            IECore.InternedStringData(IECore.InternedString("t-this")),
            'test_UChar_Array_constant':
            IECore.UCharVectorData([0, 1, 2]),
            'test_UChar_Scalar_constant':
            IECore.UCharData(0),
            'test_UInt64_Array_constant':
            IECore.UInt64VectorData([
                18446744073709551613, 18446744073709551614,
                18446744073709551615
            ]),
            'test_UInt64_Scalar_constant':
            IECore.UInt64Data(18446744073709551615),
            'test_UInt_Array_constant':
            IECore.UIntVectorData([4294967293, 4294967294, 4294967295]),
            'test_UInt_Scalar_constant':
            IECore.UIntData(4294967295),
            #'test_color3d_Array_constant' : IECore.Color3dVectorData([IECore.Color3d(1.1, 1.2, 1.3), IECore.Color3d(2.1, 2.2, 2.3), IECore.Color3d(3.1, 3.2, 3.3)]),
            #'test_color3d_Scalar_constant' : IECore.Color3dData(IECore.Color3d(0.1, 0.2, 0.3)),
            'test_color3f_Array_constant':
            IECore.Color3fVectorData([
                imath.Color3f(1.1, 1.2, 1.3),
                imath.Color3f(2.1, 2.2, 2.3),
                imath.Color3f(3.1, 3.2, 3.3)
            ]),
            'test_color3f_Scalar_constant':
            IECore.Color3fData(imath.Color3f(0.1, 0.2, 0.3)),
            #'test_color4d_Array_constant' : IECore.Color4dVectorData([IECore.Color4d(1.1, 1.2, 1.3, 1.4), IECore.Color4d(2.1, 2.2, 2.3, 2.4), IECore.Color4d(3.1, 3.2, 3.3, 3.4)]),
            #'test_color4d_Scalar_constant' : IECore.Color4dData(IECore.Color4d(0.1, 0.2, 0.3, 0.4)),
            'test_color4f_Array_constant':
            IECore.Color4fVectorData([
                imath.Color4f(1.1, 1.2, 1.3, 1.4),
                imath.Color4f(2.1, 2.2, 2.3, 2.4),
                imath.Color4f(3.1, 3.2, 3.3, 3.4)
            ]),
            'test_color4f_Scalar_constant':
            IECore.Color4fData(imath.Color4f(0.1, 0.2, 0.3, 0.4)),
            'test_matrix3d_Array_constant':
            IECore.M33dVectorData([
                imath.M33d(0, 0, 0, 0, 1, 0, 0, 0, 0),
                imath.M33d(0, 0, 0, 0, 0, 0, 0, 0, 2),
                imath.M33d(0, 0, 4, 0, 0, 0, 0, 0, 0)
            ]),
            'test_matrix3d_Scalar_constant':
            IECore.M33dData(imath.M33d(0, 0, 0, 0, 0, 0, 0, 0, 0)),
            'test_matrix4d_Array_constant':
            IECore.M44dVectorData([
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0),
                imath.M44d(1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0)
            ]),
            'test_matrix4d_Scalar_constant':
            IECore.M44dData(
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
            'test_normal3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_normal3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_normal3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_normal3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_point3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_point3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_point3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_point3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_quatd_Array_constant':
            IECore.QuatdVectorData([
                imath.Quatd(1, 0, 0, 0),
                imath.Quatd(0, 1, 0, 0),
                imath.Quatd(0, 0, 1, 0)
            ]),
            'test_quatd_Scalar_constant':
            IECore.QuatdData(imath.Quatd(0, 0, 0, 1)),
            'test_quatf_Array_constant':
            IECore.QuatfVectorData([
                imath.Quatf(1, 0, 0, 0),
                imath.Quatf(0, 1, 0, 0),
                imath.Quatf(0, 0, 1, 0)
            ]),
            'test_quatf_Scalar_constant':
            IECore.QuatfData(imath.Quatf(0, 0, 0, 1)),
            'test_vector3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_vector3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_vector3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_vector3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
        }

        for primVarName, primVarExpectedValue in expected.items():
            self.assertTrue(primVarName in object.keys())
            p = object[primVarName]
            self.assertEqual(p.data, primVarExpectedValue)
Example #4
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.failUnless(a.hasObject())
            self.failUnless(
                isinstance(a.readObject(0), IECoreScene.MeshPrimitive))
            self.failUnless(
                a.readTransformAsMatrix(0).equalWithAbsError(matrix, 1e-6))
            b = a.child("b")
            self.failUnless(b.hasObject())
            self.failUnless(
                isinstance(b.readObject(0), IECoreScene.MeshPrimitive))
            self.failUnless(
                b.readTransformAsMatrix(0).equalWithAbsError(matrix, 1e-6))
            c = b.child("c")
            self.failUnless(c.hasObject())
            self.failUnless(
                isinstance(c.readObject(0), IECoreScene.MeshPrimitive))
            self.failUnless(
                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")
Example #5
0
    def test_pod_extent(self):
        filename = os.path.join(TEMPDIR, "cask_pod_extent.abc")

        extent = 5
        v = imath.UnsignedCharArray(extent)
        for i in range(0, extent):
            v[i] = i

        a = cask.Archive()

        # create test properties
        foo = a.top.children["foo"] = cask.Xform()
        bar = foo.properties["bar"] = cask.Property()
        baz = foo.properties["baz"] = cask.Property()
        qux = foo.properties["qux"] = cask.Property()
        quux = foo.properties["quux"] = cask.Property()
        garply = foo.properties["garply"] = cask.Property()
        waldo = foo.properties["waldo"] = cask.Property()
        fred = foo.properties["fred"] = cask.Property()
        color = foo.properties["color"] = cask.Property()
        color.metadata["interpretation"] = "rgb"
        
        # set test values
        v = imath.UnsignedCharArray(5)
        for i in range(0, 5):
            v[i] = i
        bar.set_value(v)
        baz.set_value(["a", "b", "c"])
        qux.set_value(imath.Box3d())
        quux.set_value(imath.M33d())
        garply.set_value(imath.M44d())
        waldo.set_value(1)
        fred.set_value([1, 2, 3, 4])
        color.set_value(imath.Color3f(1, 2, 3))
       
        # export
        a.write_to_file(filename)
        a.close()

        # reimport the test file
        a = cask.Archive(filename)

        # recover the test properties
        foo = a.top.children["foo"]
        bar = foo.properties["bar"]
        baz = foo.properties["baz"]
        qux = foo.properties["qux"]
        quux = foo.properties["quux"]
        garply = foo.properties["garply"]
        waldo = foo.properties["waldo"]
        fred = foo.properties["fred"]
        color = foo.properties["color"]
        
        # assert pod, extent values
        self.assertEqual(bar.extent(), 5)
        self.assertEqual(bar.pod(), alembic.Util.POD.kUint8POD)
        self.assertEqual(bar.values[0], v)
        self.assertEqual(baz.extent(), 1)
        self.assertEqual(baz.pod(), alembic.Util.POD.kStringPOD)
        self.assertEqual(list(baz.values[0]), ["a", "b", "c"])
        self.assertEqual(qux.extent(), 6)
        self.assertEqual(qux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(qux.values[0], imath.Box3d())
        self.assertEqual(quux.extent(), 9)
        self.assertEqual(quux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(quux.values[0], imath.M33d())
        self.assertEqual(garply.extent(), 16)
        self.assertEqual(garply.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(garply.values[0], imath.M44d())
        self.assertEqual(waldo.extent(), 1)
        self.assertEqual(waldo.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(waldo.values[0], 1)
        self.assertEqual(fred.extent(), 1)
        self.assertEqual(fred.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(list(fred.values[0]), [1, 2, 3, 4])
        self.assertEqual(color.extent(), 3)
        self.assertEqual(color.pod(), alembic.Util.POD.kFloat32POD)
        self.assertEqual(color.metadata["interpretation"], "rgb")
        self.assertEqual(color.values[0], imath.Color3f(1, 2, 3))
Example #6
0
def buildTestAttributes():
    attributes_map = {
        "0": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(0.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "1": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(1.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "2": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(2.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "3": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(3.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "frameOffset": IECore.FloatData(0),
    }

    return {"atoms:agents": IECore.BlindDataHolder(attributes_map)}
Example #7
0
	def testCameras( self ):

		fileName = self.getOutputPath("cameras.usda", cleanUp = False )

		testCameras = []
		for projection in [ "orthographic", "perspective" ]:
			for horizontalAperture in [0.3, 1, 20, 50, 100]:
				for verticalAperture in [0.3, 1, 20, 50, 100]:
					for horizontalApertureOffset in [0, -0.4, 2.1]:
						for verticalApertureOffset in [0, -0.4, 2.1]:
							for focalLength in [1, 10, 60.5]:
								index = len( testCameras )
								c = IECoreScene.Camera()
								c.setProjection( projection )
								c.setAperture( imath.V2f( horizontalAperture, verticalAperture ) )
								c.setApertureOffset( imath.V2f( horizontalApertureOffset, verticalApertureOffset ) )
								c.setFocalLength( focalLength )
								testCameras.append( ( index, imath.M44d(), c ) )

		for near in [ 0.01, 0.1, 1.7 ]:
			for far in [ 10, 100.9, 10000000 ]:
				index = len( testCameras )
				c = IECoreScene.Camera()
				c.setClippingPlanes( imath.V2f( near, far ) )
				testCameras.append( ( index, imath.M44d( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, index, 1 ), c ) )

		for scale in [ 0.01, 0.1, 0.001 ]:
			index = len( testCameras )
			c = IECoreScene.Camera()
			c.setProjection( "perspective" )
			c.setAperture( imath.V2f( 36, 24 ) )
			c.setFocalLength( 35 )
			c.setFocalLengthWorldScale( scale )
			testCameras.append( ( index, imath.M44d(), c ) )

		sceneWrite = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
		root = sceneWrite.createChild( "root" )

		for i, matrix, camObj in testCameras:
			cam = root.createChild( "cam%i" %i  )
			cam.writeTransform( IECore.M44dData( matrix ), 0.0 )
			cam.writeObject( camObj, 0.0 )
			del cam

		del root
		del sceneWrite

		usdFile = pxr.Usd.Stage.Open( fileName )

		for i, matrix, cortexCam in testCameras:
			cG = pxr.UsdGeom.Camera.Get( usdFile, "/root/cam%i" % i )
			c = cG.GetCamera()
			usdMatrix = cG.MakeMatrixXform().GetOpTransform( 1.0 )
			for i in range( 16 ):
				self.assertAlmostEqual( usdMatrix[i/4][i%4], matrix[i/4][i%4] )

			self.assertEqual( c.projection.name.lower(), cortexCam.getProjection() )

			if cortexCam.getProjection() == "orthographic":
				self.assertAlmostEqual( c.horizontalAperture * 0.1, cortexCam.getAperture()[0], places = 6 )
				self.assertAlmostEqual( c.verticalAperture * 0.1, cortexCam.getAperture()[1], places = 6 )
				self.assertAlmostEqual( c.horizontalApertureOffset * 0.1, cortexCam.getApertureOffset()[0], places = 6 )
				self.assertAlmostEqual( c.verticalApertureOffset * 0.1, cortexCam.getApertureOffset()[1], places = 6 )
			else:
				scale = 0.1 / cortexCam.getFocalLengthWorldScale()
				self.assertAlmostEqual( c.horizontalAperture * scale, cortexCam.getAperture()[0], places = 5 )
				self.assertAlmostEqual( c.verticalAperture * scale, cortexCam.getAperture()[1], places = 5 )
				self.assertAlmostEqual( c.horizontalApertureOffset * scale, cortexCam.getApertureOffset()[0], places = 5 )
				self.assertAlmostEqual( c.verticalApertureOffset * scale, cortexCam.getApertureOffset()[1], places = 5 )
				self.assertAlmostEqual( c.focalLength * scale, cortexCam.getFocalLength(), places = 5 )


			self.assertEqual( c.clippingRange.min, cortexCam.getClippingPlanes()[0] )
			self.assertEqual( c.clippingRange.max, cortexCam.getClippingPlanes()[1] )
			self.assertEqual( c.fStop, cortexCam.getFStop() )
			self.assertEqual( c.focusDistance, cortexCam.getFocusDistance() )
			self.assertEqual( cG.GetShutterOpenAttr().Get(), cortexCam.getShutter()[0] )
			self.assertEqual( cG.GetShutterCloseAttr().Get(), cortexCam.getShutter()[1] )

			for usdFit, cortexFit in [
					(pxr.CameraUtil.MatchHorizontally, IECoreScene.Camera.FilmFit.Horizontal),
					(pxr.CameraUtil.MatchVertically, IECoreScene.Camera.FilmFit.Vertical),
					(pxr.CameraUtil.Fit, IECoreScene.Camera.FilmFit.Fit),
					(pxr.CameraUtil.Crop, IECoreScene.Camera.FilmFit.Fill)
				]:

				for aspect in [ 0.3, 1, 2.5 ]:
					usdWindow = pxr.CameraUtil.ConformedWindow( c.frustum.GetWindow(), usdFit, aspect )
					cortexWindow = cortexCam.frustum( cortexFit, aspect )
					for i in range( 2 ):
						self.assertAlmostEqual( usdWindow.min[i], cortexWindow.min()[i], delta = max( 1, math.fabs( cortexWindow.min()[i] ) ) * 0.000002 )
						self.assertAlmostEqual( usdWindow.max[i], cortexWindow.max()[i], delta = max( 1, math.fabs( cortexWindow.max()[i] ) ) * 0.000002 )

		del usdFile