Beispiel #1
0
    def test_Write(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with Tf.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             Tf.NamedTemporaryFile(suffix='.usda') as tempUsdFile:

            # Create a USD file that we'll save out as .abc
            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            stage.OverridePrim('/Prim')
            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect to read back a prim.
            roundTrippedStage = Usd.Stage.Open(tempAbcFile.name)
            prim = roundTrippedStage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            # Verify that timeCodesPerSecond and framesPerSecond values are preserved 
            # when round-tripping.
            self.assertTrue(roundTrippedStage.GetRootLayer().HasTimeCodesPerSecond())
            self.assertEqual(roundTrippedStage.GetTimeCodesPerSecond(), 
                             stage.GetTimeCodesPerSecond())

            self.assertTrue(roundTrippedStage.GetRootLayer().HasFramesPerSecond())
            self.assertEqual(roundTrippedStage.GetFramesPerSecond(), 
                             stage.GetTimeCodesPerSecond())
Beispiel #2
0
    def test_Write(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with Tf.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             Tf.NamedTemporaryFile(suffix='.usda') as tempUsdFile:

            # Create a USD file that we'll save out as .abc
            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            stage.OverridePrim('/Prim')
            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect to read back a prim.
            roundTrippedStage = Usd.Stage.Open(tempAbcFile.name)
            prim = roundTrippedStage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            # Verify that timeCodesPerSecond and framesPerSecond values are preserved
            # when round-tripping.
            self.assertTrue(
                roundTrippedStage.GetRootLayer().HasTimeCodesPerSecond())
            self.assertEqual(roundTrippedStage.GetTimeCodesPerSecond(),
                             stage.GetTimeCodesPerSecond())

            self.assertTrue(
                roundTrippedStage.GetRootLayer().HasFramesPerSecond())
            self.assertEqual(roundTrippedStage.GetFramesPerSecond(),
                             stage.GetTimeCodesPerSecond())
    def test_Write(self):
        with tempfile.NamedTemporaryFile(suffix='.abc') as tempAbcFile:
            tempAbcFile.close()
            testFile = 'testUsdAbcUvReadWrite_OldEncoding.usda'

            planeStPath = '/pPlaneSt'
            planeUvPath = '/pPlaneUv'
            planeStUvPath = '/pPlaneStUv'

            UsdAbc._WriteAlembic(testFile, tempAbcFile.name)

            stage = Usd.Stage.Open(testFile)
            self.assertTrue(stage)
            roundStage = Usd.Stage.Open(tempAbcFile.name)
            self.assertTrue(roundStage)

            planeSt = UsdGeom.Mesh.Get(stage, planeStPath)
            planeUv = UsdGeom.Mesh.Get(stage, planeUvPath)
            planeStUv = UsdGeom.Mesh.Get(stage, planeStUvPath)

            self.assertTrue(planeSt)
            self.assertTrue(planeUv)
            self.assertTrue(planeStUv)

            rplaneSt = UsdGeom.Mesh.Get(roundStage, planeStPath)
            rplaneUv = UsdGeom.Mesh.Get(roundStage, planeUvPath)
            rplaneStUv = UsdGeom.Mesh.Get(roundStage, planeStUvPath)

            self.assertTrue(rplaneSt)
            self.assertTrue(rplaneUv)
            self.assertTrue(rplaneStUv)

            self.assertEqual(planeSt.GetPrimvar('st').GetTypeName(), 'float2[]') 
            self.assertEqual(rplaneSt.GetPrimvar('uv').GetTypeName(), 'float2[]')
            self.assertEqual(planeSt.GetPrimvar('st').Get(), rplaneSt.GetPrimvar('uv').Get(0))
            self.assertEqual(planeSt.GetPrimvar('st').GetIndices(), rplaneSt.GetPrimvar('uv').GetIndices(0))

            self.assertEqual(planeUv.GetPrimvar('uv').GetTypeName(), 'float2[]') 
            self.assertEqual(rplaneUv.GetPrimvar('uv').GetTypeName(), 'float2[]')
            self.assertEqual(planeUv.GetPrimvar('uv').Get(), rplaneUv.GetPrimvar('uv').Get(0))
            self.assertEqual(planeUv.GetPrimvar('uv').GetIndices(), rplaneUv.GetPrimvar('uv').GetIndices(0))

            self.assertEqual(planeStUv.GetPrimvar('st').GetTypeName(), 'float2[]') 
            self.assertEqual(rplaneStUv.GetPrimvar('uv').GetTypeName(), 'float2[]')
            self.assertEqual(planeStUv.GetPrimvar('st').Get(), rplaneStUv.GetPrimvar('uv').Get(0))
            self.assertEqual(planeStUv.GetPrimvar('st').GetIndices(), rplaneStUv.GetPrimvar('uv').GetIndices(0))

            del stage
            del roundStage
    def test_RoundTrip(self):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'

        time = Usd.TimeCode.EarliestTime()

        self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile))

        origStage = Usd.Stage.Open(usdFile)
        stage = Usd.Stage.Open(abcFile)

        prim = stage.GetPrimAtPath('/World/geom/CenterCross/UpLeft')
        creaseIndices = prim.GetAttribute('creaseIndices').Get(time)
        expectedCreaseIndices = [
            0, 1, 3, 2, 0, 4, 5, 7, 6, 4, 1, 5, 0, 4, 2, 6, 3, 7
        ]
        for c, e in zip(creaseIndices, expectedCreaseIndices):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        creaseLengths = prim.GetAttribute('creaseLengths').Get(time)
        expectedCreaseLengths = [5, 5, 2, 2, 2, 2]
        for c, e in zip(creaseLengths, expectedCreaseLengths):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        creaseSharpnesses = prim.GetAttribute('creaseSharpnesses').Get(time)
        expectedCreaseSharpness = [1000, 1000, 1000, 1000, 1000, 1000]
        for c, e in zip(creaseSharpnesses, expectedCreaseSharpness):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        faceVertexCounts = prim.GetAttribute('faceVertexCounts').Get(time)
        expectedFaceVertexCounts = [4, 4, 4, 4, 4, 4]
        for c, e in zip(faceVertexCounts, expectedFaceVertexCounts):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        # The writer will revrse the orientation because alembic only supports
        # left handed winding order.
        faceVertexIndices = prim.GetAttribute('faceVertexIndices').Get(time)
        expectedFaceVertexIndices = [
            2, 6, 4, 0, 4, 5, 1, 0, 6, 7, 5, 4, 1, 5, 7, 3, 2, 3, 7, 6, 0, 1,
            3, 2
        ]
        for c, e in zip(faceVertexIndices, expectedFaceVertexIndices):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        # Check layer/stage metadata transfer
        self.assertEqual(origStage.GetDefaultPrim().GetPath(),
                         stage.GetDefaultPrim().GetPath())
        self.assertEqual(origStage.GetTimeCodesPerSecond(),
                         stage.GetTimeCodesPerSecond())
        self.assertEqual(origStage.GetFramesPerSecond(),
                         stage.GetFramesPerSecond())
        self.assertEqual(origStage.GetStartTimeCode(),
                         stage.GetStartTimeCode())
        self.assertEqual(origStage.GetEndTimeCode(), stage.GetEndTimeCode())
        self.assertEqual(UsdGeom.GetStageUpAxis(origStage),
                         UsdGeom.GetStageUpAxis(stage))
    def test_RoundTrip(self):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'

        time = Usd.TimeCode.EarliestTime()
        
        self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile))

        origStage = Usd.Stage.Open(usdFile)
        stage = Usd.Stage.Open(abcFile)

        prim = stage.GetPrimAtPath('/World/geom/CenterCross/UpLeft')
        creaseIndices = prim.GetAttribute('creaseIndices').Get(time)
        expectedCreaseIndices = [0, 1, 3, 2, 0, 4, 5, 7, 
                                 6, 4, 1, 5, 0, 4, 2, 6, 3, 7]
        for c, e in zip(creaseIndices, expectedCreaseIndices):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        creaseLengths = prim.GetAttribute('creaseLengths').Get(time)
        expectedCreaseLengths = [5, 5, 2, 2, 2, 2]
        for c, e in zip(creaseLengths, expectedCreaseLengths):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        creaseSharpnesses = prim.GetAttribute('creaseSharpnesses').Get(time)
        expectedCreaseSharpness = [1000, 1000, 1000, 1000, 1000, 1000]
        for c, e in zip(creaseSharpnesses, expectedCreaseSharpness):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        faceVertexCounts = prim.GetAttribute('faceVertexCounts').Get(time)
        expectedFaceVertexCounts = [4, 4, 4, 4, 4, 4]
        for c, e in zip(faceVertexCounts, expectedFaceVertexCounts):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        # The writer will revrse the orientation because alembic only supports
        # left handed winding order.
        faceVertexIndices = prim.GetAttribute('faceVertexIndices').Get(time)
        expectedFaceVertexIndices = [2, 6, 4, 0, 4, 5, 1, 0, 6, 7, 5, 
                                     4, 1, 5, 7, 3, 2, 3, 7, 6, 0, 1, 3, 2]
        for c, e in zip(faceVertexIndices, expectedFaceVertexIndices):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        # Check layer/stage metadata transfer
        self.assertEqual(origStage.GetDefaultPrim().GetPath(),
                    stage.GetDefaultPrim().GetPath())
        self.assertEqual(origStage.GetTimeCodesPerSecond(),
                    stage.GetTimeCodesPerSecond())
        self.assertEqual(origStage.GetFramesPerSecond(),
                    stage.GetFramesPerSecond())
        self.assertEqual(origStage.GetStartTimeCode(),
                    stage.GetStartTimeCode())
        self.assertEqual(origStage.GetEndTimeCode(),
                    stage.GetEndTimeCode())
        self.assertEqual(UsdGeom.GetStageUpAxis(origStage),
                    UsdGeom.GetStageUpAxis(stage))
Beispiel #6
0
    def test_Write(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with tempfile.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             tempfile.NamedTemporaryFile(suffix='.usda') as tempUsdFile:
            tempAbcFile.close()
            tempUsdFile.close()

            # Create a USD file that we'll save out as .abc
            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            stage.OverridePrim('/Prim')
            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect to read back a prim.
            roundTrippedStage = Usd.Stage.Open(tempAbcFile.name)
            prim = roundTrippedStage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            # Verify that timeCodesPerSecond and framesPerSecond values are preserved
            # when round-tripping.
            self.assertTrue(
                roundTrippedStage.GetRootLayer().HasTimeCodesPerSecond())
            self.assertEqual(roundTrippedStage.GetTimeCodesPerSecond(),
                             stage.GetTimeCodesPerSecond())

            self.assertTrue(
                roundTrippedStage.GetRootLayer().HasFramesPerSecond())
            self.assertEqual(roundTrippedStage.GetFramesPerSecond(),
                             stage.GetTimeCodesPerSecond())

            # NOTE: tempAbcFile and tempUsdFile will want to delete the
            #       underlying filse on __exit__ from the context manager.
            #       But roundTrippedStage and stage may have the file open.
            #       If so the deletion will  fail on Windows.  Explicitly
            #       release our references to the stages to close the file.
            del stage
            del roundTrippedStage
Beispiel #7
0
    def test_Write(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with tempfile.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             tempfile.NamedTemporaryFile(suffix='.usda') as tempUsdFile:
            tempAbcFile.close()
            tempUsdFile.close()

            # Create a USD file that we'll save out as .abc
            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            stage.OverridePrim('/Prim')
            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect to read back a prim.
            roundTrippedStage = Usd.Stage.Open(tempAbcFile.name)
            prim = roundTrippedStage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            # Verify that timeCodesPerSecond and framesPerSecond values are preserved 
            # when round-tripping.
            self.assertTrue(roundTrippedStage.GetRootLayer().HasTimeCodesPerSecond())
            self.assertEqual(roundTrippedStage.GetTimeCodesPerSecond(), 
                             stage.GetTimeCodesPerSecond())

            self.assertTrue(roundTrippedStage.GetRootLayer().HasFramesPerSecond())
            self.assertEqual(roundTrippedStage.GetFramesPerSecond(), 
                             stage.GetTimeCodesPerSecond())

            # NOTE: tempAbcFile and tempUsdFile will want to delete the
            #       underlying filse on __exit__ from the context manager.
            #       But roundTrippedStage and stage may have the file open.
            #       If so the deletion will  fail on Windows.  Explicitly
            #       release our references to the stages to close the file.
            del stage
            del roundTrippedStage
Beispiel #8
0
    def test_RoundTrip(self):
        baseName = 'testShotFlattened'
        camPath = '/World/main_cam'

        oldUsdFile, abcFile, newUsdFile = (self._RoundTripFileNames(baseName))

        # USD -> ABC
        self.assertTrue(UsdAbc._WriteAlembic(oldUsdFile, abcFile))

        # ABC -> USD
        layer = Sdf.Layer.FindOrOpen(abcFile)
        self.assertTrue(layer)
        self.assertTrue(layer.Export(newUsdFile))
        layer = None

        # Open old and new USD file on stages
        oldStage = Usd.Stage.Open(oldUsdFile)
        self.assertTrue(oldStage)
        newStage = Usd.Stage.Open(newUsdFile)
        self.assertTrue(newStage)

        # Get old and new camera
        oldCam = oldStage.GetPrimAtPath(camPath)
        self.assertTrue(oldCam)
        newCam = newStage.GetPrimAtPath(camPath)
        self.assertTrue(newCam)

        # Iterate through frames
        for frame in range(
            int(oldStage.GetStartTimeCode()),
            int(oldStage.GetEndTimeCode()) + 1):

            # Convert to Gf camera
            oldGfCam = UsdGeom.Camera(oldCam).GetCamera(frame)
            newGfCam = UsdGeom.Camera(newCam).GetCamera(frame)

            # Compare frustums
            self._CompareFrustumCorners(oldGfCam.frustum.ComputeCorners(), 
                                        newGfCam.frustum.ComputeCorners())
Beispiel #9
0
    def test_Types(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with tempfile.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             tempfile.NamedTemporaryFile(suffix='.usda') as tempUsdFile:
            tempAbcFile.close()
            tempUsdFile.close()

            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            prim = stage.OverridePrim('/Prim')

            # Note these test cases come from testSdTypes.py
            usdValuesToTest = [
                ("hello", 'string', 'myString'),
                (True, 'bool', 'myBool'),
                (1, 'uchar', 'myUChar'),
                (1, 'int', 'myInt'),
                (1, 'uint', 'myUInt'),
                (1, 'int64', 'myInt64'),
                (1, 'uint64', 'myUInt64'),
                (1.0, 'half', 'myHalf'),
                (1.0, 'float', 'myFloat'),
                (1.0, 'double', 'myDouble'),
                (Gf.Vec2d(1, 2), 'double2', 'myVec2d'),
                (Gf.Vec2f(1, 2), 'float2', 'myVec2f'),
                (Gf.Vec2h(1, 2), 'half2', 'myVec2h'),
                (Gf.Vec2i(1, 2), 'int2', 'myVec2i'),
                (Gf.Vec3d(1, 2, 3), 'double3', 'myVec3d'),
                (Gf.Vec3f(1, 2, 3), 'float3', 'myVec3f'),
                (Gf.Vec3h(1, 2, 3), 'half3', 'myVec3h'),
                (Gf.Vec3i(1, 2, 3), 'int3', 'myVec3i'),
                (Gf.Vec4d(1, 2, 3, 4), 'double4', 'myVec4d'),
                (Gf.Vec4f(1, 2, 3, 4), 'float4', 'myVec4f'),
                (Gf.Vec4h(1, 2, 3, 4), 'half4', 'myVec4h'),
                (Gf.Vec4i(1, 2, 3, 4), 'int4', 'myVec4i'),
                (Gf.Matrix4d(3), 'matrix4d', 'myMatrix4d'),
                (Gf.Quatf(1.0, [2.0, 3.0, 4.0]), 'quatf', 'myQuatf'),
                (Gf.Quatd(1.0, [2.0, 3.0, 4.0]), 'quatd', 'myQuatd'),
                (Vt.StringArray(), 'string[]', 'myStringArray'),
                (Vt.Vec2dArray(), 'double2[]', 'myVec2dArray'),
                (Vt.Vec2fArray(), 'float2[]', 'myVec2fArray'),
                (Vt.Vec2hArray(), 'half2[]', 'myVec2hArray'),
                (Vt.Vec2iArray(), 'int2[]', 'myVec2iArray'),
            ]

            for value, typeName, attrName in usdValuesToTest:
                prim.CreateAttribute(attrName,
                                     Sdf.ValueTypeNames.Find(typeName))
                prim.GetAttribute(attrName).Set(value)

            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect the same attributes and values
            stage = Usd.Stage.Open(tempAbcFile.name)
            prim = stage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            for value, typeName, attrName in usdValuesToTest:
                attr = prim.GetAttribute(attrName)
                self.assertTrue(attr)
                self.assertEqual(attr.GetTypeName(), typeName)
                self.assertEqual(attr.Get(), value)

            # NOTE: tempAbcFile will want to delete the underlying file
            #       on __exit__ from the context manager.  But stage
            #       may have the file open.  If so the deletion will
            #       fail on Windows.  Explicitly release our reference
            #       to the stage to close the file.
            del stage
Beispiel #10
0
    def test_Types(self):
        # Create a usda and abc temporary files.
        # NOTE: This files will automatically be deleted when the test quits,
        # if you want to keep them around for debugging, pass in delete=False
        with tempfile.NamedTemporaryFile(suffix='.abc') as tempAbcFile, \
             tempfile.NamedTemporaryFile(suffix='.usda') as tempUsdFile:
            tempAbcFile.close()
            tempUsdFile.close()

            stage = Usd.Stage.CreateNew(tempUsdFile.name)
            prim = stage.OverridePrim('/Prim')

            # Note these test cases come from testSdTypes.py
            usdValuesToTest = [
                ("hello", 'string', 'myString'),
                (True,'bool', 'myBool'),
                (1,'uchar', 'myUChar'),
                (1,'int', 'myInt'),
                (1,'uint', 'myUInt'),
                (1,'int64', 'myInt64'), 
                (1,'uint64', 'myUInt64'), 
                (1.0,'half', 'myHalf'), 
                (1.0,'float', 'myFloat'), 
                (1.0,'double', 'myDouble'), 
                (Gf.Vec2d(1,2),'double2', 'myVec2d'),
                (Gf.Vec2f(1,2),'float2', 'myVec2f'), 
                (Gf.Vec2h(1,2),'half2', 'myVec2h'), 
                (Gf.Vec2i(1,2),'int2', 'myVec2i'), 
                (Gf.Vec3d(1,2,3),'double3', 'myVec3d'), 
                (Gf.Vec3f(1,2,3),'float3', 'myVec3f'), 
                (Gf.Vec3h(1,2,3),'half3', 'myVec3h'), 
                (Gf.Vec3i(1,2,3),'int3', 'myVec3i'), 
                (Gf.Vec4d(1,2,3,4),'double4', 'myVec4d'), 
                (Gf.Vec4f(1,2,3,4),'float4', 'myVec4f'), 
                (Gf.Vec4h(1,2,3,4),'half4', 'myVec4h'), 
                (Gf.Vec4i(1,2,3,4),'int4', 'myVec4i'), 
                (Gf.Matrix4d(3),'matrix4d', 'myMatrix4d'), 
                (Gf.Quatf(1.0, [2.0, 3.0, 4.0]), 'quatf', 'myQuatf'),
                (Gf.Quatd(1.0, [2.0, 3.0, 4.0]), 'quatd', 'myQuatd'),
                (Vt.StringArray(),'string[]', 'myStringArray'), 
                (Vt.Vec2dArray(),'double2[]', 'myVec2dArray'), 
                (Vt.Vec2fArray(),'float2[]', 'myVec2fArray'), 
                (Vt.Vec2hArray(),'half2[]', 'myVec2hArray'), 
                (Vt.Vec2iArray(),'int2[]', 'myVec2iArray'), 
            ]

            for value, typeName, attrName in usdValuesToTest:
                prim.CreateAttribute(attrName, Sdf.ValueTypeNames.Find(typeName))
                prim.GetAttribute(attrName).Set(value)

            stage.GetRootLayer().Save()

            # Write out the USD file as .abc
            UsdAbc._WriteAlembic(tempUsdFile.name, tempAbcFile.name)

            # Read it back in and expect the same attributes and values
            stage = Usd.Stage.Open(tempAbcFile.name)
            prim = stage.GetPrimAtPath('/Prim')
            self.assertTrue(prim)

            for value, typeName, attrName in usdValuesToTest:
                attr = prim.GetAttribute(attrName)
                self.assertTrue(attr)
                self.assertEqual(attr.GetTypeName(), typeName)
                self.assertEqual(attr.Get(), value)

            # NOTE: tempAbcFile will want to delete the underlying file
            #       on __exit__ from the context manager.  But stage
            #       may have the file open.  If so the deletion will
            #       fail on Windows.  Explicitly release our reference
            #       to the stage to close the file.
            del stage
    def test_RoundTrip(self):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'
        self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile))

        stage = Usd.Stage.Open(abcFile)
        prim1 = stage.GetPrimAtPath('/cube1')
        self.assertTrue(prim1.IsValid())

        faceset1prim1 = stage.GetPrimAtPath('/cube1/faceset1')
        faceset2prim1 = stage.GetPrimAtPath('/cube1/faceset2')
        self.assertTrue(faceset1prim1.IsValid())
        self.assertTrue(faceset2prim1.IsValid())

        faceset1_1 = UsdGeom.Subset(faceset1prim1)
        faceset2_1 = UsdGeom.Subset(faceset2prim1)

        self.assertEqual(faceset1_1.GetElementTypeAttr().Get(), 'face')
        self.assertEqual(faceset2_1.GetElementTypeAttr().Get(), 'face')

        # Validate the indices for faceset1 (which is animated)
        indices = faceset1_1.GetIndicesAttr()

        timeSamples = indices.GetTimeSamples()
        expectedTimeSamples = [0.0, 1.0]

        self.assertEqual(len(timeSamples), len(expectedTimeSamples))

        for c, e in zip(timeSamples, expectedTimeSamples):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        expectedFaceIndices = {0.0: [0, 3, 5], 1.0: [3]}
        for time, expectedValue in expectedFaceIndices.iteritems():
            faceIndices = indices.Get(time)
            for c, e in zip(faceIndices, expectedValue):
                self.assertEqual(c, e)

        # Validate the indices for faceset2.
        indices = faceset2_1.GetIndicesAttr()

        timeSamples = indices.GetTimeSamples()

        # The reason we expect a timesample here even though original.usda
        # had only a default is that currently (unfortunately) schema properties
        # do not get the metadata that allows defaults to roundtrip back to 
        # defaults, and it would take some (unrelated to FaceSets) work to 
        # change the writer to make them do so.
        self.assertEqual(len(timeSamples), 1)

        expectedFaceIndices = {0.0: [1, 2, 4]}
        for time, expectedValue in expectedFaceIndices.items():
            faceIndices = indices.Get(time)
            for c, e in zip(faceIndices, expectedValue):
                self.assertEqual(c, e)

        # Initialize checks for /cube2
        prim2 = stage.GetPrimAtPath('/cube2')
        self.assertTrue(prim2.IsValid())
        faceset1prim2 = stage.GetPrimAtPath('/cube2/faceset1')
        faceset2prim2 = stage.GetPrimAtPath('/cube2/faceset2')
        faceset3prim2 = stage.GetPrimAtPath('/cube2/faceset3')
        self.assertTrue(faceset1prim2.IsValid())
        self.assertTrue(faceset2prim2.IsValid())
        self.assertTrue(faceset3prim2.IsValid())

        faceset1_2 = UsdGeom.Subset(faceset1prim2)
        faceset2_2 = UsdGeom.Subset(faceset2prim2)
        faceset3_2 = UsdGeom.Subset(faceset3prim2)

        # Initialize checks for /cube3
        prim3 = stage.GetPrimAtPath('/cube3')
        self.assertTrue(prim3.IsValid())
        faceset1prim3 = stage.GetPrimAtPath('/cube3/faceset')
        self.assertTrue(faceset1prim3.IsValid())
        faceset1_3 = UsdGeom.Subset(faceset1prim3)

        # Check the round-tripping of familyTypes.
        imageable1 = UsdGeom.Imageable(prim1)
        imageable2 = UsdGeom.Imageable(prim2)
        imageable3 = UsdGeom.Imageable(prim3)

        # In cube1 we've used "partition" as the familyType. This should be
        # converted to "nonOverlapping" as it more closely matches the Alembic
        # definition of "partition".
        self.assertEqual(faceset1_1.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(faceset2_1.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(UsdGeom.Subset.GetFamilyType(imageable1, "materialBind"),
                         "nonOverlapping")

        # In cube2 we've used "unrestricted". This should come across directly.
        self.assertEqual(faceset1_2.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(faceset2_2.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(UsdGeom.Subset.GetFamilyType(imageable2, "materialBind"),
                         "unrestricted")
        # We've also added another familyName in addition. We should see this
        # being lost in the round-trip and converted to "materialBind".
        self.assertEqual(faceset3_2.GetFamilyNameAttr().Get(), 'materialBind')

        # In cube3, no familyName or familyType has been specified. Upon
        # round-tripping, a default value of "unrestricted" will appear on the
        # the default "materialBind" familyName.
        self.assertEqual(faceset1_3.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(UsdGeom.Subset.GetFamilyType(imageable3, "materialBind"),
                         "unrestricted")
Beispiel #12
0
    def setUpClass(cls):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'

        UsdAbc._WriteAlembic(usdFile, abcFile)
        cls.stage = Usd.Stage.Open(abcFile)
Beispiel #13
0
    def test_RoundTrip(self):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'
        self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile))

        stage = Usd.Stage.Open(abcFile)
        prim1 = stage.GetPrimAtPath('/cube1')
        self.assertTrue(prim1.IsValid())

        faceset1prim1 = stage.GetPrimAtPath('/cube1/faceset1')
        faceset2prim1 = stage.GetPrimAtPath('/cube1/faceset2')
        self.assertTrue(faceset1prim1.IsValid())
        self.assertTrue(faceset2prim1.IsValid())

        faceset1_1 = UsdGeom.Subset(faceset1prim1)
        faceset2_1 = UsdGeom.Subset(faceset2prim1)

        self.assertEqual(faceset1_1.GetElementTypeAttr().Get(), 'face')
        self.assertEqual(faceset2_1.GetElementTypeAttr().Get(), 'face')

        # Validate the indices for faceset1 (which is animated)
        indices = faceset1_1.GetIndicesAttr()

        timeSamples = indices.GetTimeSamples()
        expectedTimeSamples = [0.0, 1.0]

        self.assertEqual(len(timeSamples), len(expectedTimeSamples))

        for c, e in zip(timeSamples, expectedTimeSamples):
            self.assertTrue(Gf.IsClose(c, e, 1e-5))

        expectedFaceIndices = {0.0: [0, 3, 5], 1.0: [3]}
        for time, expectedValue in expectedFaceIndices.items():
            faceIndices = indices.Get(time)
            for c, e in zip(faceIndices, expectedValue):
                self.assertEqual(c, e)

        # Validate the indices for faceset2.
        indices = faceset2_1.GetIndicesAttr()

        timeSamples = indices.GetTimeSamples()

        # The reason we expect a timesample here even though original.usda
        # had only a default is that currently (unfortunately) schema properties
        # do not get the metadata that allows defaults to roundtrip back to
        # defaults, and it would take some (unrelated to FaceSets) work to
        # change the writer to make them do so.
        self.assertEqual(len(timeSamples), 1)

        expectedFaceIndices = {0.0: [1, 2, 4]}
        for time, expectedValue in expectedFaceIndices.items():
            faceIndices = indices.Get(time)
            for c, e in zip(faceIndices, expectedValue):
                self.assertEqual(c, e)

        # Initialize checks for /cube2
        prim2 = stage.GetPrimAtPath('/cube2')
        self.assertTrue(prim2.IsValid())
        faceset1prim2 = stage.GetPrimAtPath('/cube2/faceset1')
        faceset2prim2 = stage.GetPrimAtPath('/cube2/faceset2')
        faceset3prim2 = stage.GetPrimAtPath('/cube2/faceset3')
        self.assertTrue(faceset1prim2.IsValid())
        self.assertTrue(faceset2prim2.IsValid())
        self.assertTrue(faceset3prim2.IsValid())

        faceset1_2 = UsdGeom.Subset(faceset1prim2)
        faceset2_2 = UsdGeom.Subset(faceset2prim2)
        faceset3_2 = UsdGeom.Subset(faceset3prim2)

        # Initialize checks for /cube3
        prim3 = stage.GetPrimAtPath('/cube3')
        self.assertTrue(prim3.IsValid())
        faceset1prim3 = stage.GetPrimAtPath('/cube3/faceset')
        self.assertTrue(faceset1prim3.IsValid())
        faceset1_3 = UsdGeom.Subset(faceset1prim3)

        # Check the round-tripping of familyTypes.
        imageable1 = UsdGeom.Imageable(prim1)
        imageable2 = UsdGeom.Imageable(prim2)
        imageable3 = UsdGeom.Imageable(prim3)

        # In cube1 we've used "partition" as the familyType. This should be
        # converted to "nonOverlapping" as it more closely matches the Alembic
        # definition of "partition".
        self.assertEqual(faceset1_1.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(faceset2_1.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(
            UsdGeom.Subset.GetFamilyType(imageable1, "materialBind"),
            "nonOverlapping")

        # In cube2 we've used "unrestricted". This should come across directly.
        self.assertEqual(faceset1_2.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(faceset2_2.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(
            UsdGeom.Subset.GetFamilyType(imageable2, "materialBind"),
            "unrestricted")
        # We've also added another familyName in addition. We should see this
        # being lost in the round-trip and converted to "materialBind".
        self.assertEqual(faceset3_2.GetFamilyNameAttr().Get(), 'materialBind')

        # In cube3, no familyName or familyType has been specified. Upon
        # round-tripping, a default value of "unrestricted" will appear on the
        # the default "materialBind" familyName.
        self.assertEqual(faceset1_3.GetFamilyNameAttr().Get(), 'materialBind')
        self.assertEqual(
            UsdGeom.Subset.GetFamilyType(imageable3, "materialBind"),
            "unrestricted")
    def setUpClass(cls):
        usdFile = 'original.usda'
        abcFile = 'converted.abc'

        UsdAbc._WriteAlembic(usdFile, abcFile)
        cls.stage = Usd.Stage.Open(abcFile)