-
-
Notifications
You must be signed in to change notification settings - Fork 36k
GLTFExporter: export from compressed texture data #23321
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
Conversation
|
Also related And would make progress on / fix in the sense of supporting import for |
|
@hybridherbst is this PR something you're still interested in? I'm thinking that a utility in examples/jsm/TextureUtils might be the way to go. Ideally it'd take a WebGLRenderer as an optional argument so we aren't making so many GL contexts, take a THREE.CompressedTexture, and return a THREE.Texture. Then we could decide later whether to integrate it with GLTFExporter or ask users to preprocess. |
|
Definitely, yes! I also recently saw that there's a similar implementation in USDZExporter, so maybe all of those can be pulled in one place. |
9e885a5 to
45322ce
Compare
|
@donmccurdy I rebased on latest dev and got a couple questions so this PR can be completed:
|
Yes, I think so.
If
I think a helper located in jsm/utils/TextureUtils.js would operate only on a single texture, without any concept of an export session. Something like: const texture = TextureUtils.decompress( compressedTexture, renderer );If it's the user's responsibility to call this before exporting a scene with compressed textures, they'd choose what renderer(s) to provide. If we enable it by default in GLTFExporter (preference: not right now) then we'd limit how many are created.
Let's start a new thread for this somewhere? We've never implemented KHR_mesh_quantization in GLTFExporter, which would be required here. |
|
I'm interested in this too! The |
81891e9 to
dc59c08
Compare
|
Finally got around to continue here;
Little Coffeemat looks pretty good now! Original Compressed Version (etc1s+draco) | Re-Exported Version |
a569d79 to
74223fa
Compare
614fe8b to
a96ca87
Compare
|
I rebased this on latest dev now and simplified the code, some things that this PR did have already been added in the meantime. @donmccurdy I also accomodated most of your feedback above. I did not find a good alternative for the I also tested that it still works for the compressed coffeemat (which is still included in this PR as part of the sample change, but could be removed before merging). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hybridherbst!
plus I think that caching has some broken edgecases - the same image with different flipY settings would result in the same cache hit (and one of them wrong data), but I think that's outside the scope of this PR.
Agreed, we can think about this later.
added coffemat.etc1s.glb and etc1s+draco, etc1s+meshopt to test compressed formats only use one temp render context, clean up renderer after writing file, make metalnessMap and roughnessMap readable refactor: move to TextureUtils class and use that in GLTFExporter, respect sRGB vs. Linear, cache some generated objects cleanup simplify modifiedMap access fix formatting for TextureUtils dispose of temporary renderer remove duplicate switch entries
36b1639 to
3f1307e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple suggestions but nothing blocking, thanks @hybridherbst!
examples/misc_exporter_gltf.html
Outdated
| window.addEventListener( 'resize', onWindowResize ); | ||
|
|
||
| // --------------------------------------------------------------------- | ||
| // Exporting compressed textures and meshes (KTX2 / Draco) (TODO: Meshopt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Draco compression won't leave any trace in the resulting three.js objects, and Meshopt requires only KHR_mesh_quantization (which is tested for export above). So it might just be KTX2 that is a concern here, perhaps we could use the existing coffeemat.glb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe when I originally started the PR Draco compression did indeed not work for roundtrips since it could still end up as int8 or so, which wasn't supported in the exporter. May not be the case anymore!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple suggestions but nothing blocking, thanks @hybridherbst!
|
Thanks! I'm honestly not really sure why the existing coffeemat.glb doesn't export right now — would it be possible you take a look at that? |
|
@hybridherbst not sure why it's only hitting the issue for one version of the model, but this patch should fix it: 4e87041 |
|
Excellent, that works – I removed the additional model again and now the existing coffeemat.glb is used. |
|
@hybridherbst I implemented your |
* USDZExporter: export from compressed texture data #23321 * add screenshot, update files.json * Update USDZExporter.js Clean up. * remove usdz compressed example * Update USDZExporter.js --------- Co-authored-by: Michael Herzog <[email protected]>
…b#27382) * USDZExporter: export from compressed texture data mrdoob#23321 * add screenshot, update files.json * Update USDZExporter.js Clean up. * remove usdz compressed example * Update USDZExporter.js --------- Co-authored-by: Michael Herzog <[email protected]>


Description
Currently, GLTFExporter can only export RGBATextures and basic meshes. For example, loading a GLTF mesh that has KTX2 textures and/or Draco compression will prevent exporting the scene. A similar issue happens when auto-converting to USDZ for AR viewing, where the compressed textures are also breaking conversion.
This draft PR attempts to mitigate that by blitting any textures that are not RGBA into new textures that can then be exported.
It's very much draft because I'd like to learn: both
I understand that there's efforts for a new texture type to potentially keep the CPU data for the loaded texture in memory so it might be possible to just "pass it through" for export, however I think that's not always desired (e.g. I might want to export a file without KTX2 and Draco compression even if my scene contains some models that do). Also, I don't think keeping the data around on the CPU just because someone might export it later makes sense; with blitting any type of 2D texture, no matter the source, could be exported.
Current Status
I added a
etc1scompressed version ofcoffeemat.glb,coffeemat.etc1s.glb, that does not use meshopt compression, to only deal with textures for now.I added this coffemat to the

misc_exporter_gltfsample scene, together with a button to export it:Without this PR, clicking that button will simply abort exporting because the
CompressedTexturecan't be read. With this PR, the export works without warning, and a glb file is produced that contains textures.The textures look correct when inspected with https://gltf.report, with the exception of the

baseColortexture, that seems to be in a wrong color space:Exporting the fully compressed coffeemat (meshopt + etc1s) results in an invalid model with gltf.report outputting numerous errors about wrong attribute formats (displaying a black model with correct vertices but broken UVs), so I think this is out of scope for this PR.
I attempted adding mesh export support for the meshopt coffeemat by adding
Int8export support, which leads to a black mesh instead of nothing, but fails at properly exporting various attributes; my understanding is that some of them would need to be converted back to non-meshopt formats (e.g.byte normalizedback tofloatfor vertex positions)TODO / Feedback needed
Creating the full renderer feels wrong, is there a better way to blit any texture into a new, readable one?
The place feels wrong, making a texture readable by blitting it would also be beneficial for other exporters
The baseColor texture ends up having the wrong color space - it does actually already look wrong on the HTML page, so not sure if there's another issue hidden here
The Int8/Byte support needs to be stripped out again and potentially moved into a different PR
Feedback very welcome 🙏
CC @elalish as I think you might be interested in better USDZ autoconversion as well
Related Issues
#20474