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

fix: extracting embedded texture files for materials from glTF file #2441

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

Basewq
Copy link
Contributor

@Basewq Basewq commented Sep 11, 2024

PR Details

Documentation on assimp texture behavior is described here:
https://assimp-docs.readthedocs.io/en/latest/API/API-Documentation.html#_CPPv49aiTexture
(Search struct aiTexture if the link doesn't jump to the correct section)

glTF materials referencing embedded textures may be denoted by * + index of the texture array, and the full file name must be determined by examining the Texture data.

Apparently it is possible to have uncompressed textures in the file (ie. the 'raw' texture is directly embedded).
I have opted to output a log error rather than implement it.

Related Issue

Used the model from #2406 (this pull does not fix the animation issue in that link)

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@@ -160,5 +172,51 @@ public static unsafe MaterialStack ConvertAssimpStackCppToCs(Silk.NET.Assimp.Ass

return ret;
}

internal static unsafe (bool isOk, string errorMessage) TryGetTextureFileName(string materialTextureFileName, Scene* scene, out string fileName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tuple return type for a Try[...] seems a bit awkward to work with;

var (isOk, errorMessage) = TryGetTextureFileName(elTexPath.AsString, scene, out texFileName);
if (!isOk)
{
    logger?.Error(errorMessage);
    continue; // error !
}

vs a try with another out var

if (!TryGetTextureFileName(elTexPath.AsString, scene, out texFileName, out var errorMessage))
{
    logger?.Error(errorMessage);
    continue; // error !
}

Not a big deal, but it's not standard in c#, and not sure it is any easier to read ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can never settle on the right way the TryGet pattern, haha.
I'll change it for returning bool and out the message since it's standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and swapped the logic in the TryGet methods so it doesn't need nested if statements.

@Eideren Eideren changed the title Fix extracting embedded texture files for materials from glTF file fix: extracting embedded texture files for materials from glTF file Sep 12, 2024
@Eideren Eideren merged commit c21272c into stride3d:master Sep 12, 2024
2 checks passed
@Eideren
Copy link
Collaborator

Eideren commented Sep 12, 2024

Thanks !

@Basewq Basewq deleted the assimp_embedded_tex_fix branch September 13, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants