Serialize and deserialize texture userData in glTF sampler. #32055
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Hello,
The
userDatain three.jsTextureis not serialized into glTF. This PR adds support for that.It also changes GLTFLoader so that userData from the
Sampleris copied to texture.userData, instead ofImage(as introduced in #28226)Some background -
in glTF, textures are broken up into Texture, Sampler, TextureInfo and Image, all of which support storing extras. See - donmccurdy/glTF-Transform#645 (comment)
For three.js, its ideal that any file that is imported and exported across three.js, gltf-transform etc, retain as many properties as possible without changing or transferring them across primitives.
Based on how three.js objects are structured, and the above explanation by donmccurdy, it makes sense to map three.js
Sourceto glTFImage, and three.jsTextureto glTFSamplerorTexture. Since the threejs API does not prevent changing/sharing the Source instance attached to a Texture(which is the case in glTF I think), I think it makes sense to map it toSamplerinstead ofTexture.Ofc, with this, the extras on source and texture def will never be read from glTF in three and lost when exported with GLTFExporter. This can be handled by reading them into something like
texture.userData.imageExtrasandtexture.userData.textureExtrasand used when exporting.This contribution is funded by Threepipe