static bool _CheckUsdTypeAndResizeArrays( const UsdAttribute& usdAttr, const TfType& expectedType, const GfInterval& timeInterval, std::vector<double>* timeSamples, MTimeArray* timeArray, MDoubleArray* valueArray) { // Validate that the attribute holds values of the expected type. const TfType type = usdAttr.GetTypeName().GetType(); if (type != expectedType) { TF_CODING_ERROR("Unsupported type name for USD attribute '%s': %s", usdAttr.GetName().GetText(), type.GetTypeName().c_str()); return false; } if (!usdAttr.GetTimeSamplesInInterval(timeInterval, timeSamples)) { return false; } size_t numTimeSamples = timeSamples->size(); if (numTimeSamples < 1) { return false; } timeArray->setLength(numTimeSamples); valueArray->setLength(numTimeSamples); return true; }
static bool _GetMetadataUnchecked( const MFnDependencyNode& node, const TfToken& key, VtValue* value) { VtValue fallback = SdfSchema::GetInstance().GetFallback(key); if (fallback.IsEmpty()) { return false; } std::string mayaAttrName = _GetMayaAttrNameForMetadataKey(key); MPlug plug = node.findPlug(mayaAttrName.c_str()); if (plug.isNull()) { return false; } TfType ty = fallback.GetType(); VtValue result = UsdMayaWriteUtil::GetVtValue(plug, ty, TfToken()); if (result.IsEmpty()) { TF_RUNTIME_ERROR( "Cannot convert plug '%s' into metadata '%s' (%s)", plug.name().asChar(), key.GetText(), ty.GetTypeName().c_str()); return false; } *value = result; return true; }
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 UsdPrim::_HasAPI(const TfType& schemaType, bool validateSchemaType) const { if (validateSchemaType) { if (schemaType.IsUnknown()) { TF_CODING_ERROR("Unknown schema type (%s) is invalid for HasAPI query", schemaType.GetTypeName().c_str()); return false; } // Note that this is only hit in python code paths, // C++ clients would hit the static_asserts defined in prim.h auto schemaRegistry = UsdSchemaRegistry::GetInstance(); if (schemaRegistry.IsConcrete(schemaType)) { TF_CODING_ERROR("Provided schema type must be non-concrete"); return false; } if (schemaRegistry.IsTyped(schemaType)) { TF_CODING_ERROR("Provided schema type must be untyped"); return false; } } // Get our composed set of applied schemas static const auto usdSchemaBase = TfType::FindByName("UsdSchemaBase"); auto appliedSchemas = GetAppliedSchemas(); if (appliedSchemas.empty()) { return false; } auto foundMatch = [&appliedSchemas](const std::string& alias) { return std::find(appliedSchemas.begin(), appliedSchemas.end(), alias) != appliedSchemas.end(); }; // See if our schema is directly authored for (const auto& alias : usdSchemaBase.GetAliases(schemaType)) { if (foundMatch(alias)) { return true; } } // If we couldn't find it directly authored in apiSchemas, // consider derived types. For example, if a user queries // prim.HasAPI<UsdModelAPI>() on a prim with // apiSchemas = ["UsdGeomModelAPI"], we should return true std::set<TfType> derivedTypes; schemaType.GetAllDerivedTypes(&derivedTypes); for (const auto& derived : derivedTypes) { for (const auto& alias : usdSchemaBase.GetAliases(derived)) { if (foundMatch(alias)) { return true; } } } return false; }
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); }
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 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); }
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); }