Skip to content

KTX2Loader: Add setTranscoderUrls() for custom transcoder URLs #31446

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

saqsun
Copy link

@saqsun saqsun commented Jul 19, 2025

What

Adds a new method setTranscoderUrls() to KTX2Loader:

ktx2Loader.setTranscoderUrls({
  jsUrl: 'path/to/basis_transcoder.js',
  wasmUrl: 'path/to/basis_transcoder.wasm',
});

This method allows to provide explicit URLs for the transcoder JS and WASM files, instead of relying on fixed filenames and directory paths.

Why

The existing setTranscoderPath() method assumes that basis_transcoder.js and .wasm are located in the same directory and have fixed names. This is not always suitable for:

  • Projects using bundlers like Vite, Webpack, or Rollup
  • Single-file deployments (e.g., HTML5 playable ads)
  • CDN-hosted or dynamically resolved asset setups

setTranscoderUrls() provides more control and flexibility while remaining fully backward-compatible.

Implementation Notes

  • If setTranscoderUrls() is used, it overrides setTranscoderPath().
  • If neither method is called, the default path-based behavior is preserved.
  • No external dependencies added.
  • The new method includes full JSDoc for in-editor discoverability.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 20, 2025

@donmccurdy Looking good to you?

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jul 27, 2025

Thanks @saqsun!

I agree that being able to specify one or more file paths, not folder paths, would be better for bundlers. It might be ideal if only a single .js path were required, and that file had a dynamic import for the .wasm...

https://web.dev/articles/bundling-non-js-resources#universal_pattern_for_browsers_and_bundlers

... but I suspect that is more complex and require us customizing the transcoder build, which we probably don't want to do.

So assuming we want to go with the approach in this PR instead, all that I would change would be the naming. Elsewhere (as in LoadingManager) we use all-uppercase URL in methods like .setURLModifier and .resolveURL, and the method is still accepting paths and not full URLs, so I'm not sure "URL" is a good way to differentiate... perhaps one of these?

// (a)
.setTranscoderPath('path/to/script.js', 'path/to/binary.wasm')

// (b)
.setTranscoderPath({js: 'path/to/script.js', wasm: 'path/to/binary.wasm'})

Note that THREE.DRACOLoader might benefit from the same changes, but that doesn't need to be included in this PR.

@saqsun
Copy link
Author

saqsun commented Jul 29, 2025

@donmccurdy Thanks for the feedback! 🙌

I've updated the API to use the object-based signature as suggested:

.setTranscoderPath({ js: 'path/to/script.js', wasm: 'path/to/binary.wasm' });

I agree this version is clearer, more extensible, and aligns well with modern API conventions, similar to PixiJS v8’s setBasisTranscoderPath.

Also, I totally see what you meant about the ideal setup where only a single .js path is needed and it dynamically imports the .wasm. That universal bundling pattern from web.dev is really clean, and it's nicely implemented in gltfpack. Agree it would require customizing the transcoder build, which is probably out of scope here, but definitely worth considering for future improvements.

Note: This is a breaking change, previous usages will need to be updated.

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.

3 participants