[英]Assimp doens't return texture data
我正在使用assimp加载3D模型。 我的模型具有嵌入式纹理(“我猜”)。 但是我有两个问题:
我什至无法打印纹理的宽度或高度。
打印texturefile
我得到了通常的格式*0 *1
,依此texturefile
。
但是,当我尝试打印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) {
}
}
使用最新的母版时,以下代码将为您工作:
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
}
希望能帮助您理解这个概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.