Assimp 不返回纹理数据

Assimp doens't return texture data

本文关键字:数据 纹理 返回 Assimp      更新时间:2023-10-16

im使用Assimp加载3D模型。我的模型具有嵌入式纹理("我猜"(。但是我有两个问题:

  1. 我找不到真正获取纹理文件路径的方法...
  2. pcdata doens似乎没有任何东西。

我什至无法打印纹理的宽度或高度。

打印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 TextureNulln";
    }
    else {
        std::cout << "n textureNotNulln";
    }
    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) {
    }
}

与Lastest Master一起工作时,以下代码应适用于您:

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
}

希望有助于理解概念。