Reputation: 415
Im using assimp to load 3D models. My models have embedded textures ("I guess"). But I have two problems:
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) {
}
}
Upvotes: 1
Views: 2081
Reputation: 2843
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.
Upvotes: 4