Beispiel #1
0
    def testExportWithKindAttrAndKindFlag(self):
        """
        Tests exporting a Maya file with both USD_kind custom attributes and
        using the usdExport -kind flag; there should be an error if the USD_kind
        is not derived from the kind specified in the -kind flag.
        """
        cmds.file(os.path.abspath('KindTestUsdKindAttr.ma'),
                  open=True,
                  force=True)
        cmds.loadPlugin('pxrUsd')

        usdFilePath = os.path.abspath('KindTestUsdKindAttr.usda')
        with self.assertRaises(RuntimeError):
            cmds.usdExport(mergeTransformAndShape=True,
                           file=usdFilePath,
                           kind='assembly')

        cmds.usdExport(mergeTransformAndShape=True,
                       file=usdFilePath,
                       kind='model')
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        rootPrim = stage.GetPrimAtPath('/KindTest')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim).GetKind(), 'component'))
        rootPrim2 = stage.GetPrimAtPath('/KindTest2')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim2).GetKind(), 'assembly'))
Beispiel #2
0
    def test_Basic(self):
        # Register python module plugins
        Plug.Registry().RegisterPlugins(os.getcwd() + "/**/")

        reg = Kind.Registry()
        self.assertTrue(reg)

        # Test factory default kinds + config file contributions
        expectedDefaultKinds = [
            'group',
            'model',
            'test_model_kind',
            'test_root_kind',
        ]
        actualDefaultKinds = Kind.Registry.GetAllKinds()

        # We cannot expect actual to be equal to expected, because there is no
        # way to prune the site's extension plugins from actual.
        # assertEqual(sorted(expectedDefaultKinds), sorted(actualDefaultKinds))

        for expected in expectedDefaultKinds:
            self.assertTrue(Kind.Registry.HasKind(expected))
            self.assertTrue(expected in actualDefaultKinds)

        # Check the 'test_model_kind' kind from the TestKindModule_plugInfo.json
        self.assertTrue(Kind.Registry.HasKind('test_root_kind'))
        self.assertEqual(Kind.Registry.GetBaseKind('test_root_kind'), '')

        # Check the 'test_model_kind' kind from the TestKindModule_plugInfo.json
        self.assertTrue(Kind.Registry.HasKind('test_model_kind'))
        self.assertEqual(Kind.Registry.GetBaseKind('test_model_kind'), 'model')
Beispiel #3
0
    def testExportWithKindFlag(self):
        """
        Tests exporting a Maya file with no USD_kind custom attributes
        and using the usdExport -kind flag.
        """
        cmds.file(os.path.abspath('KindTest.ma'), open=True, force=True)
        cmds.loadPlugin('pxrUsd')

        usdFilePath = os.path.abspath('KindTest.usda')

        # Check the error mark; this ensures that we actually got a Tf error
        # (that was eventually converted into a Maya error, which Maya raises
        # in Python as a RuntimeError).
        mark = Tf.Error.Mark()
        mark.SetMark()
        with self.assertRaises(RuntimeError):
            cmds.usdExport(mergeTransformAndShape=True,
                           file=usdFilePath,
                           kind='assembly')
        errors = mark.GetErrors()
        self.assertEqual(len(errors), 1)
        self.assertIn(
            "</KindTest> has kind 'assembly', which is derived from 'assembly'",
            str(errors[0]))

        cmds.usdExport(mergeTransformAndShape=True,
                       file=usdFilePath,
                       kind='fakeKind')
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        rootPrim = stage.GetPrimAtPath('/KindTest')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim).GetKind(), 'fakeKind'))
Beispiel #4
0
    def testExportWithAssemblyAndMesh(self):
        """
        Tests exporting a Maya file with a root prim containing an assembly
        and a mesh.
        """
        cmds.file(os.path.abspath('KindTestAssemblyAndMesh.ma'),
                  open=True,
                  force=True)
        cmds.loadPlugin('pxrUsd')

        # Should fail due to the mesh.
        usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda')
        with self.assertRaises(RuntimeError):
            cmds.usdExport(mergeTransformAndShape=True,
                           file=usdFilePath,
                           kind='assembly')

        # Should be 'component' because of the mesh
        usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda')
        cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath)
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        rootPrim = stage.GetPrimAtPath('/KindTest')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim).GetKind(), 'component'))
Beispiel #5
0
    def testExportWithAssemblies(self):
        """
        Tests exporting a Maya file with a root prim containing an assembly.
        """
        cmds.file(os.path.abspath('KindTestAssembly.ma'),
                  open=True,
                  force=True)
        cmds.loadPlugin('pxrUsd')

        usdFilePath = os.path.abspath('KindTestAssembly.usda')
        cmds.usdExport(mergeTransformAndShape=True,
                       file=usdFilePath,
                       kind='assembly')
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        # Default kind without setting kind=assembly should still be assembly.
        usdFilePath = os.path.abspath('KindTestAssembly2.usda')
        cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath)
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        rootPrim = stage.GetPrimAtPath('/KindTest')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim).GetKind(), 'assembly'))
Beispiel #6
0
    def testExportWithKindFlag(self):
        """
        Tests exporting a Maya file with no USD_kind custom attributes
        and using the usdExport -kind flag.
        """
        cmds.file(os.path.abspath('KindTest.ma'), open=True, force=True)
        cmds.loadPlugin('pxrUsd')

        usdFilePath = os.path.abspath('KindTest.usda')
        with self.assertRaises(RuntimeError):
            cmds.usdExport(mergeTransformAndShape=True,
                           file=usdFilePath,
                           kind='assembly')

        cmds.usdExport(mergeTransformAndShape=True,
                       file=usdFilePath,
                       kind='fakeKind')
        stage = Usd.Stage.Open(usdFilePath)
        self.assertTrue(stage)

        rootPrim = stage.GetPrimAtPath('/KindTest')
        self.assertTrue(Kind.Registry().IsA(
            Usd.ModelAPI(rootPrim).GetKind(), 'fakeKind'))