【问题标题】:Assimp doens't return texture dataAssimp 不返回纹理数据
【发布时间】:2019-07-16 22:03:53
【问题描述】:

我正在使用 assimp 加载 3D 模型。 我的模型嵌入了纹理(“我猜”)。但是我有两个问题:

  1. 我找不到实际获取纹理文件路径的方法...
  2. pcData 似乎什么都没有。

我什至不能打印纹理的宽度或高度。

打印texturefile 我得到了通常的格式*0 *1 等等。

但是当我尝试打印 scene->mTextures[atoi(texturefile.C_Str())]->mFileName 时,我什么也得不到……纹理 pcData 也是如此。

代码如下:

uint32_t textureCount = scene->mMaterials[i]->GetTextureCount(aiTextureType_DIFFUSE);

for (uint32_t c = 0; c < textureCount ; c++) {
    scene->mMaterials[i]->GetTexture(aiTextureType_DIFFUSE, c, &texturefile);
    std::cout << "\n textureFile : " << texturefile.C_Str() << std::endl;
    std::cout <<"\nTextura : "<< scene->mTextures[atoi(texturefile.C_Str())]<<std::endl;
    aiTexture *texture = scene->mTextures[atoi(texturefile.C_Str())];

    int w = texture->mWidth;
    int h = texture->mHeight;

    if (texture == NULL) {
        std::cout << "\n TextureNull\n";
    }
    else {
        std::cout << "\n textureNotNull\n";
    }

    uint32_t *data = reinterpret_cast<uint32_t* >(texture->pcData);
    createTextureImage(data, w, h, materials[i].texturesImages[c]);

    //createTextureImageView(materials[i].texturesImagesViews[c], materials[i].texturesImages[c]);
    //createTextureSampler(materials[i].texturesSamplers[c]);

    //  void createTextureImage(uint32_t* pixels,int texWidth,int texHeight,VkImage textureImage) {
    }
}

【问题讨论】:

    标签: c++ assimp


    【解决方案1】:

    当使用最新的大师时,以下代码应该适合你:

    aiMaterial material = scene->mMaterials[index];
    aiString texture_file;
    material->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), texture_file);
    if(auto texture = scene->GetEmbeddedTexture(texture_file.C_Str())) {
       //returned pointer is not null, read texture from memory
    } else {
       //regular file, check if it exists and read it
    }
    

    在旧版本中,您必须寻找特殊令牌:

    aiMaterial material = scene->mMaterials[index];
    aiString texture_file;
    material->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), texture_file);
    if('*' == texture_file.data[0]) {
      //embedded texture, get index from string and access scene->mTextures
    } else {
      //regular file, check if it exists and read it
    }
    

    希望这有助于理解这个概念。

    【讨论】:

      猜你喜欢
      • 2013-04-14
      • 1970-01-01
      • 2019-03-25
      • 2017-09-27
      • 1970-01-01
      • 2012-01-13
      • 2013-05-01
      • 2013-12-27
      • 2022-12-21
      相关资源
      最近更新 更多