Skip to content

FBXLoader: Use getHandler() for custom texture loaders.#31032

Merged
Mugen87 merged 10 commits into
mrdoob:devfrom
tatsuya-ogawa:fbxloader-with-customtextureloader
May 5, 2025
Merged

FBXLoader: Use getHandler() for custom texture loaders.#31032
Mugen87 merged 10 commits into
mrdoob:devfrom
tatsuya-ogawa:fbxloader-with-customtextureloader

Conversation

@tatsuya-ogawa

@tatsuya-ogawa tatsuya-ogawa commented Apr 30, 2025

Copy link
Copy Markdown
Contributor

#31031

Description
I’d like to submit a PR to three.js because the TextureLoader inside FbxLoader isn’t receiving any credentials—this causes errors when loading textures.
so add manager.addHandler to instantiate TextureLoader.

@donmccurdy

Copy link
Copy Markdown
Collaborator

I had a similar issue recently with KTX2Loader not passing 'path' or 'crossOrigin' options to its internal FileLoader, just haven't made a PR yet. I think probably we want to make sure that any options set on the parent loader are passed down to its internal loaders, rather than introducing a factory pattern? Perhaps don't change the PR yet, though – I'm curious if other maintainers agree.

@Mugen87

Mugen87 commented May 1, 2025

Copy link
Copy Markdown
Collaborator

How about adding FBXLoader.setTextureLoader(). This would match the set*Loader() pattern we are already using in other loaders.

By default, an instance of TextureLoader is used like in the existent code. This could be overwritten by a custom instance via setTextureLoader().

@tatsuya-ogawa

Copy link
Copy Markdown
Contributor Author

@Mugen87
Thanks for the feedback. I've pushed the PR, and by default an instance of TextureLoader is still used. However, we've now added FBXLoader.setTextureLoader() so that we can override it with a custom instance for cases like authenticated texture fetching. Let me know what you think!

@gkjohnson

Copy link
Copy Markdown
Collaborator

I think probably we want to make sure that any options set on the parent loader are passed down to its internal loaders, rather than introducing a factory pattern? Perhaps don't change the PR yet, though – I'm curious if other maintainers agree.

I agree with this. I would prefer not to introduce a new pattern - my expectation would always be that the settings (or intent of the settings) on the parent loader should be passed to any other child loaders. Without knowing more this sounds like a bug. Is there a reason you wouldn't want this behavior?

How about adding FBXLoader.setTextureLoader(). This would match the set*Loader() pattern ...

Where else is set*Loader pattern being used? setKTX2Loader and setDRACOLoader are not comparable imo because they are not loading files - just interpreting buffers. I would expect LoadingManager.addHandler and getHandler to be used here, if anything.

@tatsuya-ogawa

tatsuya-ogawa commented May 2, 2025

Copy link
Copy Markdown
Contributor Author

@gkjohnson Thank you.

I would expect LoadingManager.addHandler and getHandler to be used here,

Like this?
https://github.com/mrdoob/three.js/blob/dev/examples/jsm/loaders/MTLLoader.js#L573

@Mugen87

Mugen87 commented May 2, 2025

Copy link
Copy Markdown
Collaborator

I would expect LoadingManager.addHandler and getHandler to be used here, if anything.

That sounds even better!

@tatsuya-ogawa Do you mind updating the PR with the suggested approach? If you are not familiar with the addHandler() method, it allows to define custom loaders for loading specific file extensions. E.g.:

manager.addHandler( /\.tga$/i, new TGALoader() );

This would mean all TGA textures are now loaded with an instance of TGALoader and not TextureLoader. You can do the same for loading PNGs and JPGs with a custom texture loader.

However, LoadingManager.getHandler() must be used in FBXLoader otherwise the setting would be ignored.

@tatsuya-ogawa tatsuya-ogawa changed the title Add TextureLoaderFactory to customize behavior of loading texutre Use manager.getHandler to instantiate TextureLoader May 2, 2025
@Mugen87 Mugen87 changed the title Use manager.getHandler to instantiate TextureLoader FBXLoader: Use getHandler() for custom texture loaders. May 2, 2025
Mugen87
Mugen87 previously approved these changes May 2, 2025
@Mugen87 Mugen87 added this to the r177 milestone May 2, 2025
@tatsuya-ogawa

Copy link
Copy Markdown
Contributor Author

I'm checking e2e testcase webgl_loader_fbx

Comment thread examples/jsm/loaders/FBXLoader.js Outdated
@Mugen87 Mugen87 dismissed their stale review May 2, 2025 12:59

Bug found.

@tatsuya-ogawa

tatsuya-ogawa commented May 2, 2025

Copy link
Copy Markdown
Contributor Author

@Mugen87

Bug found.

Thank you. fix it.
e400684

Comment thread examples/jsm/loaders/FBXLoader.js Outdated
@gkjohnson

gkjohnson commented May 3, 2025

Copy link
Copy Markdown
Collaborator

I think allowing for getHandler here is a fine change but to be clear I think the issue Don raised should still be addressed - either here or in another PR:

I think probably we want to make sure that any options set on the parent loader are passed down to its internal loaders

The problem raised in the original post doesn't sound like something that should require custom texture loader handlers to fix.

@Mugen87 Mugen87 merged commit e367e2b into mrdoob:dev May 5, 2025
@tatsuya-ogawa

Copy link
Copy Markdown
Contributor Author

@Mugen87 @gkjohnson @donmccurdy
Thank you for your review.

RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* add capable of custom texture loader

* replace factory to setXXXLoader

* Update FBXLoader.js

* fix indent

* use manager.getHandler

* fix loader variable name

* fix url

* use getHandler for all extensions

* Update FBXLoader.js

Clean up.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* add capable of custom texture loader

* replace factory to setXXXLoader

* Update FBXLoader.js

* fix indent

* use manager.getHandler

* fix loader variable name

* fix url

* use getHandler for all extensions

* Update FBXLoader.js

Clean up.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
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