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

FBXLoader: Check null textures before assignment #22114

Merged
merged 2 commits into from
Jul 22, 2021
Merged

FBXLoader: Check null textures before assignment #22114

merged 2 commits into from
Jul 22, 2021

Conversation

camnewnham
Copy link
Contributor

Description

We've found that a variety of FBX exporters from CAD software fail to correctly create/assign textures. As a result, scope.getTexture returns null/undefined, but the code fails when attempting to assign an encoding or other property immediately after.

As such, the preferred behaviour would be to load what is possible from the model (sans textures if they are not able to load) rather than throw and exception.

@looeee
Copy link
Collaborator

looeee commented Jul 12, 2021

This looks good, thanks! 👍

@camnewnham
Copy link
Contributor Author

I've updated this some more to not assign the material.map field if the texture (material.map.image) is missing. This is because exporters (GLTFExporter in my tests) check for material.map and assume that means an image is assigned. Would it be appropriate to console.warn here to notify the user/developer that the textures are missing?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 13, 2021

I suggest you undo a1999fe. The previous commit a221988 already looked fine.

@camnewnham
Copy link
Contributor Author

I suggest you undo a1999fe. The previous commit a221988 already looked fine.

Without this, the imported material has map defined but map.image undefined - this causes issues with GLTFExporter (and perhaps others) which checks for map !== undefined and then uses map.image.

Would you prefer I reversed this commit and changed GLTFExporter to check for this instead?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 13, 2021

No, it's better to fix this in FBXLoader.

Thanks for the additional explanation. Wouldn't it be better if getTexture() does not return an incomplete texture? In this way, the check for an undefined image has to be implemented only once.

Besides, if (bumpMap?.image) { does not look like valid JS syntax.

@mrdoob
Copy link
Owner

mrdoob commented Jul 13, 2021

It is valid actually:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

Maybe we can start adopting it?
https://caniuse.com/mdn-javascript_operators_optional_chaining

@mrdoob
Copy link
Owner

mrdoob commented Jul 13, 2021

But yes, adding the logic to getTexture() seems cleaner indeed.

@mrdoob mrdoob added this to the r131 milestone Jul 13, 2021
@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 13, 2021

Interesting! Support looks sufficiently good.

FBXLoader: Check null textures before assignment

Use !==

FBXLoader: don't assign maps if images are missing
@camnewnham
Copy link
Contributor Author

Thanks for the feedback. I've updated this to return undefined from getTexture() when the image is undefined.

Clean up code style.
@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 14, 2021

Cleaned up the code style a bit...

@mrdoob mrdoob merged commit 30c07bc into mrdoob:dev Jul 22, 2021
@mrdoob
Copy link
Owner

mrdoob commented Jul 22, 2021

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants