简体   繁体   中英

Assimp doens't return texture data

Im using assimp to load 3D models. My models have embedded textures ("I guess"). But I have two problems:

  1. I can't find a way to actually get the texture file path ...
  2. The pcData doensn't seems to be anything.

I can't not even print the width or height of the texture.

printing the texturefile I get that usual format *0 *1 and so On.

But when I try to print the scene->mTextures[atoi(texturefile.C_Str())]->mFileName I get nothing...same thing with texture pcData.

here's the code:

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) {
    }
}

When working with the lastest master the following code shall work for you:

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
}

In older versions you have to look for a special token:

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
}

Hope that helps to understand the concept.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM