Ejemplo n.º 1
0
    def test_XInclude(self):
        """
        Verify documents referenced via XInclude statements are read
        properly.
        """
        stage = UsdMtlx._TestFile('include/Include.mtlx')
        stage.GetRootLayer().Export('Include.usda')

        stage = UsdMtlx._TestFile('include/Include.usdz[Include.mtlx]')
        stage.GetRootLayer().Export('Include_From_Usdz.usda')
Ejemplo n.º 2
0
 def test_DuplicateName(self):
     """
     Verify that a MaterialX file with duplicate element names fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?xml version="1.0" ?>
                <materialx version="1.35">
                    <typedef name="type1">
                    <typedef name="type1">
                </materialx>
             ''')
Ejemplo n.º 3
0
 def test_Cycle(self):
     """
     Verify that a MaterialX file with an inherits cycle fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?xml version="1.0" ?>
                <materialx version="1.35">
                    <nodedef name="n1" type="float" node="test" inherit="n2">
                    <nodedef name="n2" type="float" node="test" inherit="n1">
                </materialx>
             ''')
 def test_DuplicateName(self):
     """
     Verify that a MaterialX file with duplicate element names fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString(
             '''<?xml version="1.0" ?>
                <materialx version="1.35">
                    <typedef name="type1">
                    <typedef name="type1">
                </materialx>
             ''')
 def test_Cycle(self):
     """
     Verify that a MaterialX file with an inherits cycle fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString(
             '''<?xml version="1.0" ?>
                <materialx version="1.35">
                    <nodedef name="n1" type="float" node="test" inherit="n2">
                    <nodedef name="n2" type="float" node="test" inherit="n1">
                </materialx>
             ''')
Ejemplo n.º 6
0
    def test_MultiBindInputs(self):
        """
        Test MaterialX conversion with mutliple bind inputs.
        """

        stage = UsdMtlx._TestFile('MultiBindInputs.mtlx')

        # Get the node graph and make sure there are exactly 3 inputs
        nodeGraph = UsdShade.NodeGraph.Get(
            stage, Sdf.Path('/MaterialX/Materials/layered/ND_layerShader'))
        inputs = nodeGraph.GetInputs()
        self.assertEqual(len(inputs), 3)

        # Make sure each input is connected as expected
        inputToSource = {
            'weight_1':
            '/MaterialX/Materials/layered/NodeGraphs/layered_layer1_gradient',
            'weight_2':
            '/MaterialX/Materials/layered/NodeGraphs/layered_layer2_gradient',
            'weight_3':
            '/MaterialX/Materials/layered/NodeGraphs/layered_layer3_gradient'
        }
        for inputName, source in inputToSource.iteritems():
            input = nodeGraph.GetInput(inputName)
            self.assertEqual(input.HasConnectedSource(), True)
            self.assertEqual(input.GetConnectedSource()[0].GetPath(), source)
Ejemplo n.º 7
0
    def test_Looks(self):
        """
        Test general MaterialX look conversions.
        """

        stage = UsdMtlx._TestFile('Looks.mtlx')
        stage.GetRootLayer().Export('Looks.usda')
Ejemplo n.º 8
0
    def test_NodeGraphs(self):
        """
        Test general MaterialX node graph conversions.
        """

        stage = UsdMtlx._TestFile('NodeGraphs.mtlx', nodeGraphs=True)
        stage.GetRootLayer().Export('NodeGraphs.usda')
Ejemplo n.º 9
0
    def test_NodeGraphs(self):
        """
        Test general MaterialX node graph conversions.
        """

        stage = UsdMtlx._TestFile('NodeGraphs.mtlx', nodeGraphs=True)
        with open('NodeGraphs.usda', 'w') as f:
            print >> f, stage.GetRootLayer().ExportToString()
Ejemplo n.º 10
0
    def test_Looks(self):
        """
        Test general MaterialX look conversions.
        """

        stage = UsdMtlx._TestFile('Looks.mtlx')
        with open('Looks.usda', 'w') as f:
            print >> f, stage.GetRootLayer().ExportToString()
    def test_Looks(self):
        """
        Test general MaterialX look conversions.
        """

        stage = UsdMtlx._TestFile('Looks.mtlx')
        with open('Looks.usda', 'w') as f:
            print >>f, stage.GetRootLayer().ExportToString()
    def test_NodeGraphs(self):
        """
        Test general MaterialX node graph conversions.
        """

        stage = UsdMtlx._TestFile('NodeGraphs.mtlx', nodeGraphs=True)
        with open('NodeGraphs.usda', 'w') as f:
            print >>f, stage.GetRootLayer().ExportToString()
Ejemplo n.º 13
0
    def test_EmbedInUSDZ(self):
        """
        Verify that a MaterialX file can be read from within a .usdz file.
        """

        stage = UsdMtlx._TestFile(
            'usd_preview_surface_gold.usdz[usd_preview_surface_gold.mtlx]')
        stage.GetRootLayer().Export('usd_preview_surface_gold.usda')
Ejemplo n.º 14
0
 def test_EmptyMaterialXDocument(self):
     """
     Verify that a file with an empty a materialx element is okay.
     """
     stage = UsdMtlx._TestString('''<?xml version="1.0" ?>
            <materialx version="1.35">
            </materialx>
         ''')
     self.assertEqual(stage.GetRootLayer().ExportToString(), _EmptyLayer())
 def test_EmptyMaterialXDocument(self):
     """
     Verify that a file with an empty a materialx element is okay.
     """
     stage = UsdMtlx._TestString(
         '''<?xml version="1.0" ?>
            <materialx version="1.35">
            </materialx>
         ''')
     self.assertEqual(stage.GetRootLayer().ExportToString(),
                      _EmptyLayer())
Ejemplo n.º 16
0
    def test_StdlibShaderRefs(self):
        """
        Test that we can use a shader nodedef from the MaterialX stdlib.
        """

        stage = UsdMtlx._TestFile('usd_preview_surface_gold.mtlx')
        # check stage contents
        mprim = stage.GetPrimAtPath("/MaterialX/Materials/USD_Gold")
        self.assertTrue(mprim)
        material = UsdShade.Material(mprim)
        self.assertTrue(material)
        input = material.GetInput("specularColor")
        self.assertTrue(input)
        self.assertEqual(input.GetFullName(),"inputs:specularColor")
Ejemplo n.º 17
0
    def test_MultiOutputNodes(self):
        """
        Test MaterialX nodes with multiple outputs
        """

        stage = UsdMtlx._TestFile('MultiOutputNode.mtlx')
        testInfo = [('/MaterialX/Materials/test_m/test_ng/specular',
                     'artistic_ior', 'extinction'),
                    ('/MaterialX/Materials/test_m/test_ng/ior', 'artistic_ior',
                     'ior')]

        for path, connNodeName, connectionName in testInfo:
            node = UsdShade.Shader.Get(stage, path)
            conn = node.GetInput('in').GetConnectedSource()
            self.assertEqual(conn[0].GetPrim().GetPath().name, connNodeName)
            self.assertEqual(conn[1], connectionName)
 def test_EmptyFile(self):
     """
     Verify that an empty MaterialX document fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('')
Ejemplo n.º 19
0
 def test_BadMagic(self):
     """
     Verify that a MaterialX file with a bad XML header fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?not_xml version="1.0" ?>''')
Ejemplo n.º 20
0
 def test_EmptyXMLDocument(self):
     """
     Verify that a MaterialX file with only an XML header fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?xml version="1.0" ?>''')
Ejemplo n.º 21
0
 def test_MissingFile(self):
     """
     Verify that a missing MaterialX file fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestFile('non-existent-file.xml')
Ejemplo n.º 22
0
 def test_EmptyFile(self):
     """
     Verify that an empty MaterialX document fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('')
 def test_MissingFile(self):
     """
     Verify that a missing MaterialX file fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestFile('non-existent-file.xml')
 def test_BadMagic(self):
     """
     Verify that a MaterialX file with a bad XML header fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?not_xml version="1.0" ?>''')
 def test_EmptyXMLDocument(self):
     """
     Verify that a MaterialX file with only an XML header fails.
     """
     with self.assertRaises(Tf.ErrorException) as e:
         UsdMtlx._TestString('''<?xml version="1.0" ?>''')