def test_TopologySublayerAuthoring(self): resultLayer = Sdf.Layer.CreateNew('sublayerTopology.usd') UsdUtils.StitchClips(resultLayer, self.layerFileNames[:7], self.clipPath) self.assertEqual(list(resultLayer.subLayerPaths), ['./sublayerTopology.topology.usd']) resultLayer = Sdf.Layer.CreateNew('foo.usd') topLayer = Sdf.Layer.CreateNew('foo.topology.usd') UsdUtils.StitchClipsTemplate(resultLayer, topLayer, self.clipPath, 'asset.#.usd', 101, 120, 1) self.assertEqual(list(resultLayer.subLayerPaths), ['./foo.topology.usd'])
if results.templateMetadata: def _checkMissingTemplateArg(argName, argValue): if not argValue: raise Tf.ErrorException('Error: %s must be specified ' 'when --templateMetadata is' % argName) _checkMissingTemplateArg('templatePath', results.templatePath) _checkMissingTemplateArg('endTimeCode', results.endTimeCode) _checkMissingTemplateArg('startTimeCode', results.startTimeCode) _checkMissingTemplateArg('stride', results.stride) UsdUtils.StitchClipsTopology(topologyLayer, results.usdFiles) UsdUtils.StitchClipsTemplate(outLayer, topologyLayer, results.clipPath, results.templatePath, results.startTimeCode, results.endTimeCode, results.stride) else: UsdUtils.StitchClips(outLayer, results.usdFiles, results.clipPath, results.startTimeCode, results.endTimeCode) if not results.noComment: outLayer.comment = 'Generated with ' + ' '.join(sys.argv) outLayer.Save() except Tf.ErrorException as e: # if something in the authoring fails, remove the output file if outLayerGenerated and os.path.isfile(results.out): os.remove(results.out) if topologyLayerGenerated and os.path.isfile(topologyLayerName): os.remove(topologyLayerName)
def test_CustomSetName(self): """ Test authoring with a custom set name 'bob' """ # template case resultLayer = Sdf.Layer.CreateNew('customSetName.usd') topLayer = Sdf.Layer.CreateNew('customSetName.topology.usd') UsdUtils.StitchClipsTemplate(resultLayer, topLayer, self.clipPath, 'asset.#.usd', 101, 120, 1, 0.3, 'bob') self.assertEqual(list(resultLayer.subLayerPaths), ['./customSetName.topology.usd']) self.assertEqual(resultLayer.endTimeCode, 120) self.assertEqual(resultLayer.startTimeCode, 101) prim = resultLayer.GetPrimAtPath('/World/fx/Particles_Splash') self.assertTrue('clips' in prim.GetMetaDataInfoKeys()) expectedValues = { 'templateStartTime': 101.0, 'templateStride': 1.0, 'templateActiveOffset': 0.3, 'primPath': '/World/fx/Particles_Splash', 'templateAssetPath': 'asset.#.usd', 'templateEndTime': 120.0 } # Ensure that our custom set name applied actualValues = prim.GetInfo('clips')['bob'] self.assertTrue(actualValues is not None) # Ensure all of our values were written out for k in [ 'templateStartTime', 'templateStride', 'templateEndTime', 'primPath', 'templateAssetPath' ]: self.assertEqual(expectedValues[k], actualValues[k]) # non template case resultLayer = Sdf.Layer.CreateNew('customSetNameNonTemplate.usd') UsdUtils.StitchClips(resultLayer, self.layerFileNames[:7], self.clipPath, clipSet='bob') self.assertEqual(resultLayer.startTimeCode, 101) self.assertEqual(resultLayer.endTimeCode, 107) self.assertEqual(list(resultLayer.subLayerPaths), ['./customSetNameNonTemplate.topology.usd']) prim = resultLayer.GetPrimAtPath('/World/fx/Particles_Splash') expectedValues = { 'active': Vt.Vec2dArray([(101.0, 0.0), (102.0, 1.0), (103.0, 2.0), (104.0, 3.0), (105.0, 4.0), (106.0, 5.0), (107.0, 6.0)]), 'times': Vt.Vec2dArray([(101.0, 101.0), (102.0, 102.0), (103.0, 103.0), (104.0, 104.0), (105.0, 105.0), (106.0, 106.0), (107.0, 107.0)]), 'manifestAssetPath': Sdf.AssetPath('./customSetNameNonTemplate.topology.usd'), 'assetPaths': Sdf.AssetPathArray([ Sdf.AssetPath('./src/Particles_Splash.101.usd'), Sdf.AssetPath('./src/Particles_Splash.102.usd'), Sdf.AssetPath('./src/Particles_Splash.103.usd'), Sdf.AssetPath('./src/Particles_Splash.104.usd'), Sdf.AssetPath('./src/Particles_Splash.105.usd'), Sdf.AssetPath('./src/Particles_Splash.106.usd'), Sdf.AssetPath('./src/Particles_Splash.107.usd') ]), 'primPath': '/World/fx/Particles_Splash' } # Ensure that our custom set name applied actualValues = prim.GetInfo('clips')['bob'] self.assertTrue(actualValues is not None) # Ensure all of our values were written out for k in [ 'active', 'times', 'manifestAssetPath', 'primPath', 'assetPaths' ]: self.assertEqual(expectedValues[k], actualValues[k])
if results.templateMetadata: def _checkMissingTemplateArg(argName, argValue): if not argValue: raise Tf.ErrorException('Error: %s must be specified ' 'when --templateMetadata is' % argName) _checkMissingTemplateArg('templatePath', results.templatePath) _checkMissingTemplateArg('endTimeCode', results.endTimeCode) _checkMissingTemplateArg('startTimeCode', results.startTimeCode) _checkMissingTemplateArg('stride', results.stride) UsdUtils.StitchClipsTopology(topologyLayer, results.usdFiles) UsdUtils.StitchClipsTemplate( outLayer, topologyLayer, results.clipPath, results.templatePath, results.startTimeCode, results.endTimeCode, results.stride, results.activeOffset, results.interpolateMissingClipValues, results.clipSet) else: if results.templatePath: raise Tf.ErrorException('Error: templatePath cannot be specified ' 'without --templateMetadata') if results.activeOffset: raise Tf.ErrorException('Error: activeOffset cannot be specified ' 'without --templateMetadata') if results.stride: raise Tf.ErrorException('Error: stride cannot be specified ' 'without --templateMetadata') UsdUtils.StitchClips(outLayer, results.usdFiles, results.clipPath, results.startTimeCode, results.endTimeCode,
def coalesceFiles(outFile, srcFilePat, frameRange, stride): logging.info("coalesceFiles " + srcFilePat + ", frame range = " + str(min(frameRange)) + " - " + str(max(frameRange))) perFrameFiles = glob(srcFilePat) templatePath = srcFilePat.replace('%', '#').replace('*', '#') templatePath = './' + os.path.basename(templatePath) # create a list of tuples with frame number / file pairs fileList = [(extractNum(f), f) for f in perFrameFiles] # throw away any files that are outside of the frame range ff = min(frameRange) lf = max(frameRange) fileList = [f for f in fileList if f[0] >= ff and f[0] <= lf] if not fileList: logging.info("No files found to coalesce.") return fileList.sort() startFrame = fileList[0][0] endFrame = fileList[-1][0] sortedFiles = [e[1] for e in fileList] # try opening all files openedFiles = [Sdf.Layer.FindOrOpen(fname) for fname in sortedFiles] # 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([sortedFiles[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 # Open the layer that corresponds to outFile, if # it exists. Otherwise, create a new layer for it. if Sdf.Layer.Find(outFile): outLayer = Sdf.Layer.FindOrOpen(outFile) else: outLayer = Sdf.Layer.CreateNew(outFile) # Find out where the extension begins in the outFile string. Note that this # search for '.usd' will also find usda (or even usdb and usdc) extensions. extension = outFile.rfind('.usd') assert extension != -1, 'unable to find extension on file %s' % outFile # generate an aggregate topology from the input files topologyLayerName = outFile.replace(outFile[extension:], '.topology.usda') # Open the layer that corresponds to topologyLayerName layer, if # it exists. Otherwise, create a new layer for it. if Sdf.Layer.Find(topologyLayerName): topologyLayer = Sdf.Layer.FindOrOpen(topologyLayerName) else: topologyLayer = Sdf.Layer.CreateNew(topologyLayerName) UsdUtils.StitchClipsTopology(topologyLayer, sortedFiles) if len(topologyLayer.rootPrims) == 0: print("No geometry found when coalescing USD files.") return # Find the names of all the prim with authored attributes in the primsWithAttributes = set() for p in topologyLayer.rootPrims: walkPrim(p, primsWithAttributes) modelPath = None if len(primsWithAttributes) > 0: modelPath = getCommonPrefix(list(primsWithAttributes)) elif len(topologyLayer.rootPrims) > 0: modelPath = str(topologyLayer.rootPrims[0].path) else: return logging.info("Highest populated prim = " + modelPath) clipPath = Sdf.Path(modelPath) clipPrim = topologyLayer.GetPrimAtPath(clipPath) if not clipPrim: raise Exception("Can't find prim to create clip for") logging.info("model clip root = " + str(clipPath)) # If the thing we are coalescing is a root prim, if can be the default prim. p = str(clipPath) if p[0] == '/' and p[1:].find('/') < 0: outLayer.defaultPrim = p # Stitch the output usda as an fx template UsdUtils.StitchClipsTemplate(outLayer, topologyLayer, clipPath, templatePath, startFrame, endFrame, stride) outLayer.Save()