Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FBX] Loading embedded FBX textures the new way #1830

Closed
loebl opened this issue Mar 7, 2018 · 3 comments
Closed

[FBX] Loading embedded FBX textures the new way #1830

loebl opened this issue Mar 7, 2018 · 3 comments

Comments

@loebl
Copy link

loebl commented Mar 7, 2018

Hello,

I noticed that the loading procedure for embedded textures from FBX changed in the last few weeks.
The old method would give a filename like "*1" which could be used to index into the embedded texture array.

Now I get the relative path to the original image file. As far as I know I would need to search the texture array and compare the paths. It gets a bit complicated as the textures store the absolute paths to the original file.

Just to be on the right track: Is it the new way, to get the tex path from the material, search the embedded textures, strip the folders/path prefixes and compare the file names to find out if the texture is embedded?

@Ceydric2002
Copy link

Hi,
I've experienced the same pb, but you can load any embedded texture using "GetEmbeddedTexture" method from the aiScene class.
So basically you get the texture name as before, you will get a complete path name, then you try to get any embedded texture with this read fileName using GetEmbeddedTexture. If it returns an aiTexture pointer, then it's an embedded texture and you can process it as you need.
Hope this helps
Cheers

@loebl
Copy link
Author

loebl commented Mar 14, 2018

Alright:
So where I previously wrote (example)

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
}

I would now write

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
}

I made a quick test and it seems to work. Personally I think that the call to GetEmbeddedTexture should accept an aiString. But I guess this can still change until the next release.

Thanks for the help!

@loebl loebl closed this as completed Mar 14, 2018
@lucasjinreal
Copy link

@loebl Hi, can u share how to read from memory? I wrote from memory but got whole black texture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants