static bool _ProvidesForType( const PlugPluginPtr& plug, const std::vector<TfToken>& scope, const std::string& typeName, std::string* mayaPluginName) { JsObject metadata = plug->GetMetadata(); JsObject mayaTranslatorMetadata; if (!_ReadNestedDict(metadata, scope, &mayaTranslatorMetadata)) { return false; } JsValue any; if (!TfMapLookup(mayaTranslatorMetadata, _tokens->providesTranslator, &any)) { return false; } std::vector<std::string> usdTypes; if (!_GetData(any, &usdTypes)) { return false; } bool provides = std::find( usdTypes.begin(), usdTypes.end(), typeName) != usdTypes.end(); if (provides) { if (TfMapLookup(mayaTranslatorMetadata, _tokens->mayaPlugin, &any)) { return _GetData(any, mayaPluginName); } } return provides; }
/* virtual */ VtValue HdxLight::Get(TfToken const &token) const { VtValue val; TfMapLookup(_params, token, &val); return val; }
bool UsdMayaGLSoftSelectHelper::GetWeight( const MDagPath& dagPath, float* weight) const { return TfMapLookup(_dagPathsToWeight, dagPath, weight); }
static bool _GetMayaDictValue(const UsdAttribute& attr, const TfToken& key, T* outVal) { VtValue data = attr.GetCustomDataByKey(_tokens->Maya); if (!data.IsEmpty()) { if (data.IsHolding<VtDictionary>()) { VtValue val; if (TfMapLookup(data.UncheckedGet<VtDictionary>(), key, &val)) { if (val.IsHolding<T>()) { *outVal = val.UncheckedGet<T>(); return true; } else { TF_WARN("Unexpected type for %s[%s] on <%s>.", _tokens->Maya.GetText(), key.GetText(), attr.GetPath().GetText()); } } } else { TF_WARN("Expected to get %s on <%s> to be a dictionary.", _tokens->Maya.GetText(), attr.GetPath().GetText()); } } return false; }
int GlfBindingMap::GetAttributeIndex(TfToken const & name) { int attribIndex = -1; if (!TfMapLookup(_attribBindings, name, &attribIndex)) { return -1; } return attribIndex; }
int GlfBindingMap::GetSamplerUnit(TfToken const & name) { int samplerUnit = -1; if (!TfMapLookup(_samplerBindings, name, &samplerUnit)) { // XXX error check < MAX_TEXTURE_IMAGE_UNITS samplerUnit = _samplerBindings.size(); _samplerBindings[name] = samplerUnit; } TF_VERIFY(samplerUnit >= 0); return samplerUnit; }
bool _DoFindUsdType( const TfToken& usdTypeName, std::string* opName, const _UsdTypeRegistry& registry) { // unfortunately, usdTypeName is diff from the tfTypeName which we use to // register. do the conversion here mostly in case we want to walk up the // type hierarchy TfType tfType = PlugRegistry::FindDerivedTypeByName<UsdSchemaBase>(usdTypeName); std::string typeNameStr = tfType.GetTypeName(); return TfMapLookup(registry, typeNameStr, opName); }
/*virtual*/ VtValue UsdMayaGLBatchRenderer::TaskDelegate::Get( SdfPath const& id, TfToken const &key) { _ValueCache *vcache = TfMapLookupPtr(_valueCacheMap, id); VtValue ret; if( vcache && TfMapLookup(*vcache, key, &ret) ) return ret; TF_CODING_ERROR("%s:%s doesn't exist in the value cache\n", id.GetText(), key.GetText()); return VtValue(); }
/* static */ bool PxrUsdKatanaUsdInPluginRegistry::_DoFindKind( const TfToken& kind, std::string* opName, const _KindRegistry& reg) { // can cache this if it becomes an issue. for (TfToken currKind = kind; not currKind.IsEmpty(); currKind = KindRegistry::GetBaseKind(currKind)) { if (TfMapLookup(reg, currKind, opName)) { return true; } } return false; }
PXR_NAMESPACE_OPEN_SCOPE // --------------------------------------------------------------------------- // Delegate implementation. /* virtual */ VtValue HdStreamTaskController::_Delegate::Get(SdfPath const& id, TfToken const& key) { _ValueCache *vcache = TfMapLookupPtr(_valueCacheMap, id); VtValue ret; if (vcache && TfMapLookup(*vcache, key, &ret)) { return ret; } TF_CODING_ERROR("%s:%s doesn't exist in the value cache\n", id.GetText(), key.GetText()); return VtValue(); }
static bool _HasShadingModePlugin( const PlugPluginPtr& plug, const std::vector<TfToken>& scope, std::string* mayaPluginName) { JsObject metadata = plug->GetMetadata(); JsObject mayaTranslatorMetadata; if (!_ReadNestedDict(metadata, scope, &mayaTranslatorMetadata)) { return false; } JsValue any; if (TfMapLookup(mayaTranslatorMetadata, _tokens->mayaPlugin, &any)) { return _GetData(any, mayaPluginName); } return false; }
PXRUSDMAYA_DEFINE_CHASER_FACTORY(alembic, ctx) { std::map<std::string, std::string> myArgs; TfMapLookup(ctx.GetJobArgs().allChaserArgs, "alembic", &myArgs); // The attrprefix and primvarprefix arguments provide the // prefixes for attributes/primvars to export from Maya and an optional // replacement prefix for the output USD attribute name. // // The format of the argument is: // mayaPrefix1[=usdPrefix1],mayaPrefix2[=usdPrefix2],... // usdPrefix can contain namespaces (i.e. can have colons) for attrprefix // but not for primvarprefix (since primvar names can't have namespaces). // If [=usdPrefix] is omitted, then these defaults are used: // - for attrprefix, "userProperties:" // - for primvarprefix, "" (empty) // // Example attrprefix: // ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace: // ABC_attrName -> userProperties:attrName // ABC2_attrName -> customPrefix_attrName // ABC3_attrName -> attrName // ABC4_attrName -> customNamespace:attrName // // Example primvarprefix: // ABC_,ABC2_=customPrefix_,ABC3_= // ABC_attrName -> attrName // ABC2_attrName -> customPrefix_attrName // ABC3_attrName -> attrName std::map<std::string, std::string> attrPrefixes; _ParseMapArgument(myArgs, "attrprefix", _tokens->userProperties.GetString(), &attrPrefixes); std::map<std::string, std::string> primvarPrefixes; _ParseMapArgument(myArgs, "primvarprefix", std::string(), &primvarPrefixes); return new AlembicChaser( ctx.GetStage(), ctx.GetDagToUsdMap(), attrPrefixes, primvarPrefixes); }
/* static */ bool PxrUsdKatanaUsdInPluginRegistry::_DoFindKind( const TfToken& kind, std::string* opName, const _KindRegistry& reg) { // can cache this if it becomes an issue. TfToken currKind = kind; while (!currKind.IsEmpty()) { if (TfMapLookup(reg, currKind, opName)) { return true; } if (KindRegistry::HasKind(currKind)) { currKind = KindRegistry::GetBaseKind(currKind); } else { FnLogWarn(TfStringPrintf("Unknown kind: '%s'", currKind.GetText())); return false; } } return false; }
static bool _ReadNestedDict( const JsObject& data, const std::vector<TfToken>& keys, JsObject* dict) { JsObject currDict = data; TF_FOR_ALL(iter, keys) { const TfToken& currKey = *iter; JsValue any; if (!TfMapLookup(currDict, currKey, &any)) { return false; } if (!any.IsObject()) { TF_CODING_ERROR("bad plugInfo data."); return false; } currDict = any.GetJsObject(); } *dict = currDict; return true; }
TfToken usdWriteJob::writeVariants(const UsdPrim &usdRootPrim) { // Init parameters for filtering and setting the active variant std::string defaultModelingVariant; // Get the usdVariantRootPrimPath (optionally filter by renderLayer prefix) MayaPrimWriterPtr firstPrimWriterPtr = *mMayaPrimWriterList.begin(); std::string firstPrimWriterPathStr( firstPrimWriterPtr->getDagPath().fullPathName().asChar() ); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), '|', '/'); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), ':', '_'); // replace namespace ":" with "_" SdfPath usdVariantRootPrimPath(firstPrimWriterPathStr); usdVariantRootPrimPath = usdVariantRootPrimPath.GetPrefixes()[0]; // Create a new usdVariantRootPrim and reference the Base Model UsdRootPrim // This is done for reasons as described above under mArgs.usdModelRootOverridePath UsdPrim usdVariantRootPrim = mStage->DefinePrim(usdVariantRootPrimPath); TfToken defaultPrim = usdVariantRootPrim.GetName(); usdVariantRootPrim.GetReferences().AppendInternalReference(usdRootPrim.GetPath()); usdVariantRootPrim.SetActive(true); usdRootPrim.SetActive(false); // Loop over all the renderLayers for (unsigned int ir=0; ir < mRenderLayerObjs.length(); ++ir) { SdfPathTable<bool> tableOfActivePaths; MFnRenderLayer renderLayerFn( mRenderLayerObjs[ir] ); MString renderLayerName = renderLayerFn.name(); std::string variantName(renderLayerName.asChar()); // Determine default variant. Currently unsupported //MPlug renderLayerDisplayOrderPlug = renderLayerFn.findPlug("displayOrder", true); //int renderLayerDisplayOrder = renderLayerDisplayOrderPlug.asShort(); // The Maya default RenderLayer is also the default modeling variant if (mRenderLayerObjs[ir] == MFnRenderLayer::defaultRenderLayer()) { defaultModelingVariant=variantName; } // Make the renderlayer being looped the current one MGlobal::executeCommand(MString("editRenderLayerGlobals -currentRenderLayer ")+ renderLayerName, false, false); // == ModelingVariants == // Identify prims to activate // Put prims and parent prims in a SdfPathTable // Then use that membership to determine if a prim should be Active. // It has to be done this way since SetActive(false) disables access to all child prims. MObjectArray renderLayerMemberObjs; renderLayerFn.listMembers(renderLayerMemberObjs); std::vector< SdfPath > activePaths; for (unsigned int im=0; im < renderLayerMemberObjs.length(); ++im) { MFnDagNode dagFn(renderLayerMemberObjs[im]); MDagPath dagPath; dagFn.getPath(dagPath); dagPath.extendToShape(); SdfPath usdPrimPath; if (!TfMapLookup(mDagPathToUsdPathMap, dagPath, &usdPrimPath)) { continue; } usdPrimPath = usdPrimPath.ReplacePrefix(usdPrimPath.GetPrefixes()[0], usdVariantRootPrimPath); // Convert base to variant usdPrimPath tableOfActivePaths[usdPrimPath] = true; activePaths.push_back(usdPrimPath); //UsdPrim usdPrim = mStage->GetPrimAtPath(usdPrimPath); //usdPrim.SetActive(true); } if (!tableOfActivePaths.empty()) { { // == BEG: Scope for Variant EditContext // Create the variantSet and variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSets().AppendVariantSet("modelingVariant"); modelingVariantSet.AppendVariant(variantName); modelingVariantSet.SetVariantSelection(variantName); // Set the Edit Context UsdEditTarget editTarget = modelingVariantSet.GetVariantEditTarget(); UsdEditContext editContext(mStage, editTarget); // == Activate/Deactivate UsdPrims UsdPrimRange it = UsdPrimRange::AllPrims(mStage->GetPseudoRoot()); std::vector<UsdPrim> primsToDeactivate; for ( ; it; ++it) { UsdPrim usdPrim = *it; // For all xformable usdPrims... if (usdPrim && usdPrim.IsA<UsdGeomXformable>()) { bool isActive=false; for (size_t j=0;j<activePaths.size();j++) { //primPathD.HasPrefix(primPathA); SdfPath activePath=activePaths[j]; if (usdPrim.GetPath().HasPrefix(activePath) || activePath.HasPrefix(usdPrim.GetPath())) { isActive=true; break; } } if (isActive==false) { primsToDeactivate.push_back(usdPrim); it.PruneChildren(); } } } // Now deactivate the prims (done outside of the UsdPrimRange // so not to modify the iterator while in the loop) for ( UsdPrim const& prim : primsToDeactivate ) { prim.SetActive(false); } } // == END: Scope for Variant EditContext } } // END: RenderLayer iterations // Set the default modeling variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSet("modelingVariant"); if (modelingVariantSet.IsValid()) { modelingVariantSet.SetVariantSelection(defaultModelingVariant); } return defaultPrim; }
HdTaskSharedPtr UsdMayaGLBatchRenderer::TaskDelegate::GetRenderTask( size_t hash, RenderParams const &renderParams, SdfPathVector const &roots) { // select bucket SdfPath renderTaskId; if( !TfMapLookup(_renderTaskIdMap, hash, &renderTaskId) ) { // create new render task if not exists renderTaskId = _rootId.AppendChild( TfToken(TfStringPrintf("renderTask%zx", hash))); _InsertRenderTask(renderTaskId); _renderTaskIdMap[hash] = renderTaskId; } // // XXX: The Maya-Hydra plugin needs refactoring such that the plugin is // creating a different collection name for each collection it is trying to // manage. (i.e. Each collection within a frame that has different content // should have a different collection name) // // With Hydra, changing the contents of a collection can be // an expensive operation as it causes draw batches to be rebuilt. // // The Maya-Hydra Plugin is currently reusing the same collection // name for all collections within a frame. // (This stems from a time when collection name had a significant meaning // rather than id'ing a collection). // // The plugin should also track deltas to the contents of a collection // and set Hydra's dirty state when prims get added and removed from // the collection. // // Another possible change that can be made to this code is HdxRenderTask // now takes an array of collections, so it is possible to support different // reprs using the same task. Therefore, this code should be modified to // only add one task that is provided with the active set of collections. // // However, a further improvement to the code could be made using // UsdDelegate's fallback repr feature instead of using multiple // collections as it would avoid modifying the collection as a Maya shape // object display state changes. This would result in a much cheaper state // transition within Hydra itself. // TfToken colName = renderParams.geometryCol; HdRprimCollection rprims(colName, renderParams.drawRepr); rprims.SetRootPaths(roots); rprims.SetRenderTags(renderParams.renderTags); GetRenderIndex().GetChangeTracker().MarkCollectionDirty(colName); // update value cache _SetValue(renderTaskId, HdTokens->collection, rprims); // invalidate GetRenderIndex().GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyCollection); // update render params in the value cache HdxRenderTaskParams taskParams = _GetValue<HdxRenderTaskParams>(renderTaskId, HdTokens->params); // update params taskParams.overrideColor = renderParams.overrideColor; taskParams.wireframeColor = renderParams.wireframeColor; taskParams.enableLighting = renderParams.enableLighting; taskParams.enableIdRender = false; taskParams.alphaThreshold = 0.1; taskParams.tessLevel = 32.0; const float tinyThreshold = 0.9f; taskParams.drawingRange = GfVec2f(tinyThreshold, -1.0f); taskParams.depthBiasUseDefault = true; taskParams.depthFunc = HdCmpFuncLess; taskParams.cullStyle = renderParams.cullStyle; taskParams.geomStyle = HdGeomStylePolygons; taskParams.enableHardwareShading = true; // note that taskParams.rprims and taskParams.viewport are not updated // in this function, and needed to be preserved. // store into cache _SetValue(renderTaskId, HdTokens->params, taskParams); // invalidate GetRenderIndex().GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyParams); return GetRenderIndex().GetTask(renderTaskId); }