bool UsdUtilsStitchClipsTemplate(const SdfLayerHandle& resultLayer, const SdfLayerHandle& topologyLayer, const SdfPath& clipPath, const std::string& templatePath, const double startTime, const double endTime, const double stride, const double activeOffset, const TfToken& clipSet) { // XXX: See comment in UsdUtilsStitchClipsTopology above. TF_PY_ALLOW_THREADS_IN_SCOPE(); if (!_LayerIsWritable(resultLayer)) { return false; } else { resultLayer->Clear(); } if (!topologyLayer) { return false; } // set prim level metadata auto prim = SdfCreatePrimInLayer(resultLayer, clipPath); const std::string topologyId = _GetRelativePathIfPossible(topologyLayer->GetIdentifier(), topologyLayer->GetRealPath(), resultLayer->GetRealPath()); // set root layer metadata _StitchClipsTopologySubLayerPath(resultLayer, topologyId); VtDictionary clipSetDict; clipSetDict[UsdClipsAPIInfoKeys->primPath] = clipPath.GetString(); clipSetDict[UsdClipsAPIInfoKeys->templateAssetPath] = templatePath; clipSetDict[UsdClipsAPIInfoKeys->templateStartTime] = startTime; clipSetDict[UsdClipsAPIInfoKeys->templateEndTime] = endTime; clipSetDict[UsdClipsAPIInfoKeys->templateStride] = stride; clipSetDict[UsdClipsAPIInfoKeys->manifestAssetPath] = SdfAssetPath(topologyId); if (activeOffset != std::numeric_limits<double>::max()) { clipSetDict[UsdClipsAPIInfoKeys->templateActiveOffset] = activeOffset; } VtDictionary clips; clips[clipSet] = clipSetDict; prim->SetInfo(UsdTokens->clips, VtValue::Take(clips)); resultLayer->SetStartTimeCode(startTime); resultLayer->SetEndTimeCode(endTime); resultLayer->Save(); return true; }
SdfLayerRefPtr& UsdKatanaCache::_FindOrCreateSessionLayer( FnAttribute::GroupAttribute sessionAttr, std::string rootLocation) { // Grab a reader lock for reading the _sessionKeyCache boost::upgrade_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetSessionCacheLock()); std::string cacheKey = FnAttribute::GroupAttribute("s", sessionAttr, "r", FnAttribute::StringAttribute(rootLocation), true).getHash().str(); // Open the usd stage SdfLayerRefPtr sessionLayer; if (_sessionKeyCache.find(cacheKey) == _sessionKeyCache.end()) { boost::upgrade_to_unique_lock<boost::upgrade_mutex> writerLock(readerLock); sessionLayer = SdfLayer::CreateAnonymous(); _sessionKeyCache[cacheKey] = sessionLayer; std::string rootLocationPlusSlash = rootLocation + "/"; FnAttribute::GroupAttribute variantsAttr = sessionAttr.getChildByName("variants"); for (int64_t i = 0, e = variantsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( variantsAttr.getChildName(i)); FnAttribute::GroupAttribute entryVariantSets = variantsAttr.getChildByIndex(i); if (entryVariantSets.getNumberOfChildren() == 0) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); for (int64_t i = 0, e = entryVariantSets.getNumberOfChildren(); i != e; ++i) { std::string variantSetName = entryVariantSets.getChildName(i); FnAttribute::StringAttribute variantValueAttr = entryVariantSets.getChildByIndex(i); if (!variantValueAttr.isValid()) { continue; } std::string variantSetSelection = variantValueAttr.getValue("", false); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); if (spec) { std::pair<std::string, std::string> sel = varSelPath.GetVariantSelection(); spec->SetVariantSelection(variantSetName, variantSetSelection); } } } FnAttribute::GroupAttribute activationsAttr = sessionAttr.getChildByName("activations"); for (int64_t i = 0, e = activationsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( activationsAttr.getChildName(i)); FnAttribute::IntAttribute stateAttr = activationsAttr.getChildByIndex(i); if (stateAttr.getNumberOfValues() != 1) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); spec->SetActive(stateAttr.getValue()); } } return _sessionKeyCache[cacheKey]; }