GlfImageSharedPtr
GlfImageRegistry::_ConstructImage(std::string const & filename)
{
    static GlfImageSharedPtr NULL_IMAGE;

    // Lookup the plug-in type name based on the filename.
    TfToken fileExtension(ArGetResolver().GetExtension(filename));

    TfType const & pluginType = _typeMap->Find(fileExtension);

    if (!pluginType) {
        // Unknown prim type.
        TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg(
                "[PluginLoad] Unknown image type '%s'\n",
                fileExtension.GetText());
        return NULL_IMAGE;
    }

    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 NULL_IMAGE;
    }

    GlfImageFactoryBase* factory = pluginType.GetFactory<GlfImageFactoryBase>();
    if (!factory) {
        TF_CODING_ERROR("[PluginLoad] Cannot manufacture type '%s' "
                "for image type '%s'\n",
                pluginType.GetTypeName().c_str(),
                fileExtension.GetText());

        return NULL_IMAGE;
    }

    GlfImageSharedPtr instance = factory->New();
    if (!instance) {
        TF_CODING_ERROR("[PluginLoad] Cannot construct instance of type '%s' "
                "for image type '%s'\n",
                pluginType.GetTypeName().c_str(),
                fileExtension.GetText());
        return NULL_IMAGE;
    }

    TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg(
    	        "[PluginLoad] Loaded plugin '%s' for image type '%s'\n",
                pluginType.GetTypeName().c_str(),
                fileExtension.GetText());

    return instance;
}
Exemple #2
0
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;
}
static SdfLayerRefPtr
_GetGeneratedSchema(const PlugPluginPtr &plugin)
{
    // Look for generatedSchema in Resources.
    const string fname = TfStringCatPaths(plugin->GetResourcePath(),
                                          "generatedSchema.usda");
    return SdfLayer::OpenAsAnonymous(fname);
}
Exemple #4
0
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;
}
Exemple #5
0
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;
}