Assimp Load FBX纹理失败,可能的问题:单元0 GLD_TEXTURE_INDEX_2D不载并绑定到采样器类型(float)

发布于 2025-02-02 12:33:42 字数 2525 浏览 4 评论 0原文

我正在使用此代码加载FBX(注意:特定于FBX),无法成功加载的纹理,

for (unsigned int i = 0; i < mat->GetTextureCount(type); i++) {
      aiString str;
      mat->GetTexture(type, i, &str);
      if (auto texture_inside = scene->GetEmbeddedTexture(str.C_Str())) {
        unsigned char *image_data = nullptr;
        int width, height, nrComponents;
        if (texture_inside->mHeight == 0) {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth, &width, &height, &nrComponents, 0);
        } else {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth * texture_inside->mHeight, &width, &height,
              &nrComponents, 0);
        }

        if (image_data) {
          GLenum format;
          if (nrComponents == 1)
            format = GL_RED;
          else if (nrComponents == 3)
            format = GL_RGB;
          else if (nrComponents == 4)
            format = GL_RGBA;

          unsigned int t_id;
          glGenTextures(1, &t_id);
          glBindTexture(GL_TEXTURE_2D, t_id);
          glTexImage2D(GL_TEXTURE_2D, 0, format, texture_inside->mWidth,
                       texture_inside->mHeight, 0, format, GL_UNSIGNED_BYTE,
                       image_data);
          glGenerateMipmap(GL_TEXTURE_2D);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                          GL_LINEAR_MIPMAP_LINEAR);
          glBindTexture(GL_TEXTURE_2D, 0);

          delete image_data;

          AnimTexture texture;
          texture.id = t_id;
          texture.type_name = typeName;
          texture.file_path = str.C_Str();
          textures.push_back(texture);
        }
        LOG(INFO) << "loading texture from embeded: " << str.C_Str();
      }
}

然后我收到这样的错误消息:

UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

我的问题是:

  1. 如何以正确的可行方式加载FBX嵌入式纹理?
  2. 我在这里错过了什么可能导致上述错误?

目前,我只有黑色深色纹理。

I am using this code to load FBX (note: specific for FBX), the textures unable to load successfully

for (unsigned int i = 0; i < mat->GetTextureCount(type); i++) {
      aiString str;
      mat->GetTexture(type, i, &str);
      if (auto texture_inside = scene->GetEmbeddedTexture(str.C_Str())) {
        unsigned char *image_data = nullptr;
        int width, height, nrComponents;
        if (texture_inside->mHeight == 0) {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth, &width, &height, &nrComponents, 0);
        } else {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth * texture_inside->mHeight, &width, &height,
              &nrComponents, 0);
        }

        if (image_data) {
          GLenum format;
          if (nrComponents == 1)
            format = GL_RED;
          else if (nrComponents == 3)
            format = GL_RGB;
          else if (nrComponents == 4)
            format = GL_RGBA;

          unsigned int t_id;
          glGenTextures(1, &t_id);
          glBindTexture(GL_TEXTURE_2D, t_id);
          glTexImage2D(GL_TEXTURE_2D, 0, format, texture_inside->mWidth,
                       texture_inside->mHeight, 0, format, GL_UNSIGNED_BYTE,
                       image_data);
          glGenerateMipmap(GL_TEXTURE_2D);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                          GL_LINEAR_MIPMAP_LINEAR);
          glBindTexture(GL_TEXTURE_2D, 0);

          delete image_data;

          AnimTexture texture;
          texture.id = t_id;
          texture.type_name = typeName;
          texture.file_path = str.C_Str();
          textures.push_back(texture);
        }
        LOG(INFO) << "loading texture from embeded: " << str.C_Str();
      }
}

then I got error message like this:

UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

My question is:

  1. How to load FBX embedded texture in a correct workable way?
  2. what did I miss here caused above errors possibly?

currently I only got wrong black dark texture.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2025-02-09 12:33:42

这是Assimp项目中的一个常见问题。您可以在此处找到一个示例:如何处理嵌入式纹理

This is a common question in the assimp-project. You can find an example how to load embedded textures here: How to deal with embedded textures

In short:

  1. Get the data from the embedded texture
  2. Encode it with a image-converter
  3. Put it into your texture on the GPU
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文