Skip to content

gltfpack: Fix corner cases in texture coordinate processing#1066

Merged
zeux merged 2 commits into
masterfrom
gltf-fix
Jul 13, 2026
Merged

gltfpack: Fix corner cases in texture coordinate processing#1066
zeux merged 2 commits into
masterfrom
gltf-fix

Conversation

@zeux

@zeux zeux commented Jul 13, 2026

Copy link
Copy Markdown
Owner

When UV quantization was enabled (by default) and the input had two
identical meshes with two different materials that required different UV
bounds, we could mistakenly reuse the encoded mesh data through accessor
deduplication; the first mesh that was serialized used the quantization
settings.

Also, if the input file had KHR_texture_transform objects, the quantization
transform was not combined correctly with the existing transform: to
preserve the offset, it needs to be transformed according to offset/scale.
This could be masked by the quantization offset being 0.

@zeux zeux changed the title gltfpack: Fix several corner cases in texture coordinate processing gltfpack: Fix corner cases in texture coordinate processing Jul 13, 2026
zeux added 2 commits July 13, 2026 12:50
When UV quantization was enabled (by default) and the input had two
identical meshes with two different materials that required different UV
bounds, we could mistakenly reuse the encoded mesh data through accessor
deduplication; the first mesh that was serialized used the quantization
settings.

This was fairly rare, as it required one of the materials to also be
used on a different mesh so that the combined UV range is different. To
fix this, we only deduplicate accessors if the UV quantization settings
are compatible.
Because UVs are stored in a quantized form by default, we need to first
apply the dequantization transform and only then apply the original
texture transform. Our logic was the opposite, and only worked if
quantization offset was 0 or if texture transform was offset-only.

Note that this relies on the original transform being TRS; if the
original transform was TSR, then applying a second non-uniform scale
like so: TSR * TS would introduce skew and the resulting matrix will not
be decomposable.

Currently, three.js is using incorrect order (TSR), but Babylon.js and
PlayCanvas correctly implement glTF specification using TRS.
@zeux
zeux merged commit e759e60 into master Jul 13, 2026
13 checks passed
@zeux
zeux deleted the gltf-fix branch July 13, 2026 19:56
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.

1 participant