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

GLTFExporter unable to process compressed texture #24321

Closed
stefandouw opened this issue Jul 6, 2022 · 5 comments
Closed

GLTFExporter unable to process compressed texture #24321

stefandouw opened this issue Jul 6, 2022 · 5 comments

Comments

@stefandouw
Copy link

Describe the bug

When trying to export a scene that contains a material that uses a compressed texture format an error will occur and the export will fail. Format number is 36492 which I believe is COMPRESSED_RGBA_BPTC_UNORM_EXT: https://www.khronos.org/registry/webgl/extensions/EXT_texture_compression_bptc/

To Reproduce

Steps to reproduce the behavior:

  1. Convert a .jpg image with the tools provided by khronos: toktx --t2 --genmipmap --bcmp --2d texture.ktx2 texture.jpg
  2. Use the image as a texture with the KTX2Loader
  3. Attempt to export a scene that has the object with the KTX2 texture using the GLTFExporter
  4. Error message appears in the browser console

Screenshots

image

Platform:

  • Device: Desktop
  • OS: Windows 10
  • Browser: Chrome
  • Three.js version: 135
@donmccurdy
Copy link
Collaborator

donmccurdy commented Jul 6, 2022

Related:

As the error message suggests, GLTFExporter cannot export compressed textures. If we were to fix this, I believe the steps would be:

  1. Add a helper function somewhere (examples/jsm/utils/?) that converts a THREE.CompressedTexture to an uncompressed THREE.Texture, using WebGLRenderer.
  2. Either invoke that helper automatically in GLTFExporter, or require users to do so manually

Note that the process is lossy — GLTFExporter cannot reproduce the original compressed KTX2 file in any case, and I don't see a practical way around that. So I'm undecided about whether we should go this direction.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 7, 2022

Looking at the OP's workflow, it might be better to not create the compressed texture first and then using it for export. In general, the compression should be applied during the export or after it with a tool like gltfpack.

Nevertheless, I understand there are situations where compressed assets are loaded and users want to include it in other workflows (not just for rendering). A new helper would be a good start although the docs should highlight the mentioned consequences.

@stefandouw
Copy link
Author

Exporting a scene is only a small part of our application, users typically place various objects in an interactive scene and we provide the option to render the scene in high quality on a server. Therefore we would like to optimize the interactive experience by decreasing the memory footprint. Unfortunately we can't implement compressed textures right now until there is a solution for GLTFExporter.

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jul 7, 2022

If I were building such an application, my advice would be to keep a source-of-truth outside the three.js scene graph and update it directly — treating the three.js scene as a "view" into the source scene, but never fully overwriting that with a serialized three.js scene graph. This is basically what glTF-Transform/View provides. The "source" could be a glTF file, or something custom.

IMG_3557 Large

Nevertheless I think support for converting THREE.CompressedTexture to THREE.Texture makes sense to include, and #23321 is a good start.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 15, 2023

Closing since with the merge of #23321 the original runtime error should be fixed.

@Mugen87 Mugen87 closed this as completed Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants