def test_StitchTopologyOnly(self): # Generate a fresh topology topologyLayer = Sdf.Layer.CreateNew('topologyLayer.usd') UsdUtils.StitchClipsTopology(topologyLayer, self.layerFileNames[:7]) self.assertTrue(topologyLayer) self.assertTrue(topologyLayer.GetPrimAtPath(self.clipPath)) # Aggregate into an existing topology newClipPath = Sdf.Path('/World/fx/points') UsdUtils.StitchClipsTopology(topologyLayer, self.layerFileNames[8:10]) self.assertTrue(topologyLayer) self.assertTrue(topologyLayer.GetPrimAtPath(newClipPath))
if results.stride: results.stride = float(results.stride) 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):
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()