Ejemplo n.º 1
0
    def setUp(self):
        self.layers = [
            Sdf.Layer.CreateAnonymous(),
            Sdf.Layer.FindOrOpen('src/Particles_Splash.101.usd'),
            Sdf.Layer.FindOrOpen('src/Particles_Splash.103.usd'),
            Sdf.Layer.CreateAnonymous(),
            Sdf.Layer.FindOrOpen('src/letters_perFrame.101.usda'),
            Sdf.Layer.FindOrOpen('src/letters_perFrame.102.usda'),
            Sdf.Layer.FindOrOpen('src/letters_perFrame.103.usda')
        ]

        self.rootprims_combined = None
        self.rootprims_a = None
        self.rootprims_b = None

        # stitch layers for basic tests
        UsdUtils.StitchLayers(self.layers[0], self.layers[1])
        UsdUtils.StitchLayers(self.layers[0], self.layers[2])

        self.rootprims_combined = self.layers[0].rootPrims
        self.rootprims_a = self.layers[1].rootPrims
        self.rootprims_b = self.layers[2].rootPrims

        # stitch layers for secondary tests
        UsdUtils.StitchLayers(self.layers[3], self.layers[4])
        UsdUtils.StitchLayers(self.layers[3], self.layers[5])
        UsdUtils.StitchLayers(self.layers[3], self.layers[6])
Ejemplo n.º 2
0
def main():
    """Run the main execution of the current script."""
    # Initialize the stage and layers
    stage = Usd.Stage.CreateInMemory()
    UsdGeom.Xform.Define(stage, "/SomeTransform")
    UsdGeom.Sphere.Define(stage, "/SomeTransform/SomeSphere")
    anonymous1 = Usd.Stage.CreateInMemory()
    anonymous1.DefinePrim("/SomeItemInAnonymous")
    anonymous2 = Usd.Stage.CreateInMemory()
    anonymous2.DefinePrim("/SomethingElseThatIsInAnotherLayer")

    # Add some composition arcs that target the anonymous layers
    prim = stage.GetPrimAtPath("/SomeTransform/SomeSphere")
    prim.GetReferences().AddReference(anonymous1.GetRootLayer().identifier,
                                      primPath="/SomeItemInAnonymous")
    prim.GetReferences().AddReference(
        anonymous2.GetRootLayer().identifier,
        primPath="/SomethingElseThatIsInAnotherLayer",
    )

    # XXX : Here we are using `FlattenLayerStack` to replace the
    # authored, anonymous assetPath arguments with nothing because we
    # are about to merge the anonymous layer(s) into the stage anyway,
    # so the paths will just refer to the current USD stage.
    #
    roots = set((layer.GetRootLayer() for layer in (anonymous1, anonymous2)))
    layer = UsdUtils.FlattenLayerStack(
        stage,
        resolveAssetPathFn=functools.partial(
            _remove_anonymous_asset_paths,
            identifiers=tuple(root.identifier for root in roots),
        ),
    )

    # XXX : Merge each anonymous layer that was listed in `identifiers`
    # into the current stage. That way, the references that were created
    # will not break.
    #
    for root in roots:
        UsdUtils.StitchLayers(layer, root)

    print(layer.ExportToString())
Ejemplo n.º 3
0
    def add_frame_file(self, filepath, i):
        print i, self._counter
        self._files_to_stitch[i] = Sdf.Layer.FindOrOpen(filepath)
        print self._files_to_stitch[i] == None
        for n in self._files_to_stitch.keys():
            j = min(self._counter)
            print "##########", j
            to_stitch = self._files_to_stitch.get(j)
            if to_stitch != None:
                UsdUtils.StitchLayers(self._outLayer, to_stitch)
                self._counter.remove(n)
                del self._files_to_stitch[n]

        print len(self._counter), i, filepath
        print 
        if self._counter == []:
            self._outLayer.Save()
            print "[HA MESSAGE] DONE", self._out_file
            thread.start_new_thread(shutdown_thread, ())

        return True
Ejemplo n.º 4
0
assert results.out != None, "must specify output file"

if os.path.isfile(results.out):
    print("Warning: overwriting pre-existing file")

# fold over the files, left file takes precedence on op. strength
outLayer = Sdf.Layer.CreateNew(results.out)

# open up all of the files into memory before stitching.
# if one is missing, this will allow us to fail without doing
#
# try opening all files
openedFiles = [Sdf.Layer.FindOrOpen(fname) for fname in results.usdFiles]
# grab the index of all, if any, files which failed to open
unopened = [i for i, unopened in enumerate(openedFiles) if unopened == None ]
# grab the filenames of the failed files for error messaging
erroredFiles = ' '.join([results.usdFiles[i] for i in unopened])
# if we failed to open any files, error out
assert len(unopened) == 0, 'unable to open file(s) %s' %erroredFiles
    
# the extra computation and fail more gracefully
try:
    for usdFile in openedFiles:
        UsdUtils.StitchLayers(outLayer, usdFile)
        outLayer.Save()
# if something in the authoring fails, remove the output file
except Exception as e:
    print('Failed to complete stitching, removing output file %s' % results.out)
    print(e)
    os.remove(results.out) 
Ejemplo n.º 5
0
    def test_Variants(self):
        layer1 = Sdf.Layer.FindOrOpen('src/variants_1.usda')
        layer2 = Sdf.Layer.FindOrOpen('src/variants_2.usda')

        # First, stitch to an empty layer -- this should be equivalent
        # to making a copy of the weaker layer.
        l = Sdf.Layer.CreateAnonymous('.usda')
        UsdUtils.StitchLayers(l, layer1)
        self.assertEqual(layer1.ExportToString(), l.ExportToString(),
                         ("Expected:\n%s\nResult:\n%s" %
                          (layer1.ExportToString(), l.ExportToString())))

        l = Sdf.Layer.CreateAnonymous('.usda')
        UsdUtils.StitchLayers(l, layer2)
        self.assertEqual(layer2.ExportToString(), l.ExportToString(),
                         ("Expected:\n%s\nResult:\n%s" %
                          (layer2.ExportToString(), l.ExportToString())))

        # Stitch the two layers together and verify that variants
        # are merged as expected.
        UsdUtils.StitchLayers(layer1, layer2)

        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child.testAttr'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child.testRel'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child_2'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child_2.testAttr'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{a=x}Child_2.testRel'))
        self.assertTrue(layer1.GetObjectAtPath('/Root{b=x}Child'))

        self.assertEqual(
            layer1.GetAttributeAtPath('/Root{a=x}Child.testAttr').GetInfo(
                'timeSamples'), {
                    1.0: 1.0,
                    2.0: 2.0
                })

        self.assertEqual(
            layer1.GetAttributeAtPath('/Root{a=x}Child_2.testAttr').GetInfo(
                'timeSamples'), {2.0: 2.0})

        expectedTargets = Sdf.PathListOp()
        expectedTargets.prependedItems = ['/Root/Test', '/Root/Test2']
        self.assertEqual(
            layer1.GetRelationshipAtPath('/Root{a=x}Child.testRel').GetInfo(
                'targetPaths'), expectedTargets)

        expectedTargets.prependedItems = ['/Root/Test2']
        self.assertEqual(
            layer1.GetRelationshipAtPath('/Root{a=x}Child_2.testRel').GetInfo(
                'targetPaths'), expectedTargets)

        self.assertEqual(dict(layer1.GetPrimAtPath('/Root').variantSelections),
                         {
                             'a': 'x',
                             'b': 'x'
                         })

        expectedNames = Sdf.StringListOp()
        expectedNames.prependedItems = ['a', 'b']
        self.assertEqual(
            layer1.GetPrimAtPath('/Root').GetInfo('variantSetNames'),
            expectedNames)