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); }
bool UsdPrim::_IsA(const TfType& schemaType) const { // Check Schema TfType if (schemaType.IsUnknown()) { TF_CODING_ERROR("Unknown schema type (%s) is invalid for IsA query", schemaType.GetTypeName().c_str()); return false; } // Get Prim TfType const std::string &typeName = GetTypeName().GetString(); return !typeName.empty() && PlugRegistry::FindDerivedTypeByName<UsdSchemaBase>(typeName). IsA(schemaType); }
GlfTextureFactoryBase* GlfTextureRegistry::_GetTextureFactory(const TfToken &filename) { // Lookup the plug-in type name based on the file extension. TfToken fileExtension(TfStringGetSuffix(filename)); TfType pluginType = _typeMap->Find(fileExtension); if (!pluginType) { // Unknown type. Try the wildcard. pluginType = _typeMap->Find(TfToken("*")); if (!pluginType) { TF_DEBUG(GLF_DEBUG_TEXTURE_PLUGINS).Msg( "[PluginLoad] Unknown texture type '%s'\n", fileExtension.GetText()); return nullptr; } } PlugRegistry& plugReg = PlugRegistry::GetInstance(); PlugPluginPtr plugin = plugReg.GetPluginForType(pluginType); if (!plugin || !plugin->Load()) { TF_CODING_ERROR("[PluginLoad] PlugPlugin could not be loaded for " "TfType '%s'\n", pluginType.GetTypeName().c_str()); return nullptr; } TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg( "[PluginLoad] Loaded plugin '%s' for texture type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); if (GlfTextureFactoryBase* factory = pluginType.GetFactory<GlfTextureFactoryBase>()) { return factory; } TF_CODING_ERROR("[PluginLoad] Cannot manufacture type '%s' " "for texture type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); return nullptr; }
bool SdfPropertySpec::SetDefaultValue(const VtValue &defaultValue) { if (defaultValue.IsEmpty()) { ClearDefaultValue(); return true; } if (defaultValue.IsHolding<SdfValueBlock>()) { return SetField(SdfFieldKeys->Default, defaultValue); } TfType valueType = GetValueType(); if (valueType.IsUnknown()) { TF_CODING_ERROR("Can't set value on attribute <%s> with " "unknown type \"%s\"", GetPath().GetText(), GetTypeName().GetAsToken().GetText()); return false; } if (ARCH_UNLIKELY(valueType.GetTypeid() == typeid(void))) { // valueType may be provided by a plugin that has not been loaded. // In that case, we cannot get the type info, which is required to cast. // So we load the plugin in that case. if (PlugPluginPtr p = PlugRegistry::GetInstance().GetPluginForType(valueType)) { p->Load(); } } VtValue value = VtValue::CastToTypeid(defaultValue, valueType.GetTypeid()); if (value.IsEmpty()) { TF_CODING_ERROR("Can't set value on <%s> to %s: " "expected a value of type \"%s\"", GetPath().GetText(), TfStringify(defaultValue).c_str(), valueType.GetTypeName().c_str()); return false; } return SetField(SdfFieldKeys->Default, value); }
UsdMayaAdaptor::SchemaAdaptor UsdMayaAdaptor::GetSchemaOrInheritedSchema(const TfType& ty) const { if (!*this) { return SchemaAdaptor(); } if (ty.IsA<UsdAPISchemaBase>()) { // No "promotion" for API schemas. return GetSchema(ty); } else if (ty.IsA<UsdSchemaBase>()) { // Can "promote" typed schemas based on inheritance. const TfType objectType = GetUsdType(); if (objectType.IsA(ty)) { return GetSchema(objectType); } } return SchemaAdaptor(); }
void UsdMayaAdaptor::UnapplySchema(const TfType& ty, MDGModifier& modifier) { const SdfPrimSpecHandle primDef = UsdSchemaRegistry::GetInstance() .GetPrimDefinition(ty); if (!primDef) { TF_CODING_ERROR("Can't find schema definition for type '%s'", ty.GetTypeName().c_str()); return; } UnapplySchemaByName(primDef->GetNameToken(), modifier); }
bool UsdSchemaRegistry::IsAppliedAPISchema(const TfType& apiSchemaType) { // Return false if apiSchemaType is not an API schema. if (!apiSchemaType.IsA(*_apiSchemaBaseType)) { return false; } for (const auto& alias : _schemaBaseType->GetAliases(apiSchemaType)) { if (_appliedAPISchemaNames.find(TfToken(alias)) != _appliedAPISchemaNames.end()) { return true; } } return false; }
void Hf_PluginEntry::SetFactory(TfType &type, _PluginFactoryFn &func) { type.SetFactory(std::unique_ptr<_Factory>(new _Factory(func))); }