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

KTX2Loader: Support loading uncompressed DataTexture and Data3DTexture #24129

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

donmccurdy
Copy link
Collaborator

Adds support for loading KTX 2.0 textures in uncompressed formats. With #24102, THREE.KTX2Exporter (new) can export DataTexture and Data3DTexture instances to these formats.

✅ Included:

  • Outputs: THREE.DataTexture or THREE.Data3DTexture
  • Types: UnsignedByteType, HalfFloatType, or FloatType
  • Formats: RGBAFormat, RGFormat, or RedFormat
  • Encodings: LinearEncoding or sRGBEncoding

⚠️ Not included:

  • GPU compression formats (ETC2, ASTC, etc.)
  • Supercompression (BasisLZ, ZSTD, ZLIB)

❌ Breaking change:

  • loader.load( 'path/to/texture.ktx2', onLoad ) no longer returns a CompressedTexture instance synchronously, because we cannot know in advance whether the return type will be CompressedTexture, DataTexture, or Data3DTexture. A callback or the async pattern, const texture = await loader.loadAsync( 'path/to/texture.ktx2' ), should be used instead.

See #24102 for more details.

@mrdoob mrdoob added this to the r141 milestone May 26, 2022
@mrdoob
Copy link
Owner

mrdoob commented May 26, 2022

Seems like webgl_loader_gltf_compressed is failing? 🤔

@mrdoob mrdoob modified the milestones: r141, r142 May 26, 2022
@donmccurdy
Copy link
Collaborator Author

donmccurdy commented May 26, 2022

I'm seeing alternating failures in CI for:

  • webgl_loader_gltf_compressed
  • webgl_loader_texture_ktx2

But both look OK locally... a bit confused what might have broken here. Do these examples break locally for anyone else?

@Mugen87
Copy link
Collaborator

Mugen87 commented May 27, 2022

Do these examples break locally for anyone else?

I've downloaded your branch and tested both examples on my iMac (macOS, Chrome 102.0.5005.61). They break with the following error:

Uncaught SyntaxError: The requested module '../libs/ktx-parse.module.js' does not provide an export named 'VK_FORMAT_R16G16B16A16_SFLOAT'

@donmccurdy donmccurdy force-pushed the feat-ktx2loader-datatexture branch from 9433289 to 469afc1 Compare May 31, 2022 21:42
@donmccurdy
Copy link
Collaborator Author

Ah thanks! This depended on the ktx-parse.module.js update from #24102, I guess I had the file symlinked. Should be fixed now. 👍

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 1, 2022

Both examples work now 🎉 .

@mrdoob mrdoob merged commit cd583bc into mrdoob:dev Jun 1, 2022
@mrdoob
Copy link
Owner

mrdoob commented Jun 1, 2022

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Jun 13, 2022

Is this expected? 🤔

Screen Shot 2022-06-13 at 4 41 28 PM

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 13, 2022

I could imagine that the js version of KTX2Loader does not work with the new import from ../libs/ktx-parse.module.js.

There is no js version of KTX2Exporter. Should we do the same KTX2Loader?

@LeviPesin
Copy link
Contributor

LeviPesin commented Jun 13, 2022

I think maybe it is already time to remove examples/js (and consequently other builds than three.module.js)?
(As we now do not convert new files in examples/jsm)

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 13, 2022

We have stated in #20568 (comment) that examples/js will be kept until all major browsers support import maps. I don't think there is a reason to start a discussion about this topic again.

@donmccurdy donmccurdy deleted the feat-ktx2loader-datatexture branch June 14, 2022 01:20
@donmccurdy
Copy link
Collaborator Author

Originally KTX2Loader was added without an examples/js version, we added it in #22485 to unblock aframevr/aframe#4919 for A-Frame. That support didn't end up making it into A-Frame yet, so maybe not a problem to revert it.

At some point I would like to get KTX2Loader working with much smaller/lighter wasm dependencies, and we will need the ktx-parse dependency for that (with or without this DataTexture / Data3DTexture support). I guess the alternative to support examples/js would be to inline ktx-parse.module.js separately into KTX2Loader and KTX2Exporter, not ideal but possible.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 14, 2022

Is there a UMD version of ktx-parse? If so, you could change the import in examples/jsm/loaders/KTX2Loader.js to something like:

import * as ktxParse from '../libs/ktx-parse.module.js';

Assuming ktxParse is the namespace from the UMD version. This approach is used by other loaders, too.

I'm also fine with inlining ktx-parse or completely removing examples/js/loaders/KTX2Loader.js.

@donmccurdy
Copy link
Collaborator Author

I don't include a UMD module with the ktx-parse npm package, but it shouldn't be a problem to generate one for the three.js package. Probably easier than generating an inline-friendly version of the library.

@donmccurdy
Copy link
Collaborator Author

donmccurdy commented Jun 21, 2022

abernier pushed a commit to abernier/three.js that referenced this pull request Sep 16, 2022
snagy pushed a commit to snagy/three.js-1 that referenced this pull request Sep 21, 2022
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