【问题标题】:Change .OBJ's memory texture in runtime using Assimp使用 Assimp 在运行时更改 .OBJ 的内存纹理
【发布时间】:2020-03-20 05:57:09
【问题描述】:

在我的程序 (C++/OpenGL/Assimp/Windows10) 中,我加载并显示一个 .OBJ 文件及其对应的 .MTL

一切正常,但我需要:

  1. 从内存加载,而不是从 .MTL 文件中写入的任何内容(例如:map_Kd output.jpg)。
  2. 我需要在运行时更改纹理。

这是我的 LoadOpenGLTexture(),我正在使用 DevIL 加载纹理(将更改为 OpenCV)。

bool Model::LoadGLTextures(const aiScene* scene)
{
    ILboolean success;

    ilInit();

    for (unsigned int m = 0; m < scene->mNumMaterials; ++m)
    {
        int texIndex = 0;
        aiString path;  // filename

        aiReturn texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, 
        &path);
        while (texFound == AI_SUCCESS)
        {
            //fill map with textures, OpenGL image ids set to 0
            textureIdMap[path.data] = 0;
            // more textures?
            texIndex++;
            texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
        }
    }

    int numTextures = textureIdMap.size();

    /* create and fill array with DevIL texture ids */
    ILuint* imageIds = new ILuint[numTextures];
    ilGenImages(numTextures, imageIds);

    /* create and fill array with GL texture ids */
    GLuint* textureIds = new GLuint[numTextures];
    glGenTextures(numTextures, textureIds); /* Texture name generation */

    /* get iterator */
    std::map<std::string, GLuint>::iterator itr = textureIdMap.begin();
    int i = 0;
    for (; itr != textureIdMap.end(); ++i, ++itr)
    {
        //save IL image ID
        std::string filename = (*itr).first;  // get filename
        (*itr).second = textureIds[i];    // save texture id for filename in map

        ilBindImage(imageIds[i]); /* Binding of DevIL image name */
        ilEnable(IL_ORIGIN_SET);
        ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
        success = ilLoadImage((ILstring)filename.c_str());

        if (success) {
            /* Convert image to RGBA */
            ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

            /* Create and load textures to OpenGL */
            glBindTexture(GL_TEXTURE_2D, textureIds[i]);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH), 
            ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());
        }
        else
            printf("Couldn't load Image: %s\n", filename.c_str());
    }
    /* Because we have already copied image data into texture data
    we can release memory used by image. */
    ilDeleteImages(numTextures, imageIds);

    //Cleanup
    delete[] imageIds;
    delete[] textureIds;

    //return success;
    return true;
}

【问题讨论】:

  • 你的问题到底是什么?
  • 问题是,我无法在运行时使用 assimp 更改纹理。
  • 你想定义类似动画纹理的东西吗?
  • 这就像一个预览,每次你在列表视图中选择一个纹理,它都会渲染到对象上。

标签: c++ opengl assimp wavefront


【解决方案1】:

目前 Asset-Importer-Lib 中的纹理定义没有为纹理/材质定义提供这样的动态更新。纹理的每个定义在应用程序运行期间保持稳定,您无法更改它。 我您对这样的功能感兴趣,我们需要以适当的方式更新材料系统,以使其对用户有用。因此,如果您对此功能感兴趣,最好能更好地了解您的需求/用例。

您可以在我们的项目端为其打开功能请求,请参阅:Assimp on Github

【讨论】:

  • 哦,男孩......也许......你知道这个特定问题的任何开源替代品吗?感谢您的宝贵时间。
  • 您可以只更新渲染引擎中的文本数据吗?
  • 我不确定我是否理解,我尝试更新我的纹理,但我的对象没有任何变化。
  • 您必须在 GPU 上更新纹理,而不是在 Assimp 数据结构中。
  • 你的意思是使用我的着色器?
猜你喜欢
  • 2013-08-21
  • 2021-09-18
  • 2021-01-04
  • 2023-03-11
  • 2022-12-14
  • 1970-01-01
  • 1970-01-01
  • 2020-09-01
  • 1970-01-01
相关资源
最近更新 更多