Sandbox: GLB Export destroys KHR_texture_transform?

Not sure if this is a new bug, or if it’s always been there?

  1. Unzip the attachment.
  2. Drag-and-drop all into the BabylonJS Sandbox.
  3. Inspector > Tools > Export to GLB.
  4. Drag-and-drop the GLB into the Sandbox.

Result: texture transforms have been flattened into the textures, reducing resolution significantly.

Expected: KHR_texture_transform should be preserved, along with the original U Scale and V Scale values.

Exported GLB:

Original glTF: (3.1 MB)

As always, thank you for all your hard work on this awesome tool.

It was already there unfortunately. This is the way we deal with KHR_Transform

I will add an issue to fix that

1 Like

Hi I am using this BABYLON.GLTF2Export.GLTFAsync(scene, “object”).then((gltf) => {
for my base I have set texture offset and scale.
output in .gltf is showing like these
“baseColorTexture”: {
“index”: 0,
“texCoord”: 0

how to enable KHR_texture_transform

Adding @Drigax to double check

1 Like

@Atul_Sharma Does your asset have a texture transform already applied?

I used the chair asset uploaded by @echadwick-wayfair as a test, everything looks fine as far as round-tripping goes.

I can see that some of the asset’s texture maps have offset and scale applied:

Exported from the sandbox, I can see that the texture transform values were preserved:

Can you create a PG that reproduces what you’re seeing?

Hi @Drigax thanks for your efforts.

No texture transform is not already applied.

When I use my objects in latest sandbox version 4.2.0 beta it still not add texture transform.
It exports texture with offset and scale
Check this out .
I am setting material baseTexture offset and scale and exporting scene to Gltf.
And in gltf its not adding khr texture transform extension.

Thanks for the example. This is definitely strange. I can see the resulting texture has been changed after export:

Tracing through the export, Our implementation of the exporter for KHR_Texture_Transform is very suspect:

@kcoley appears to have authored this extension, but this implementation seems antithetical to the intent of the extension. I’m not sure why the original chair model appears preserved, however.

I decided to remove the baking from the texture export process entirely, I’m not sure why we would want to bake out a texture with the normal TRS transformations applied.

So far, this appears to work as expected:

I’ll put out a PR containing the change soon.

Let s add @bghgary who might be aware of this ?

Thanks for the ping @sebavan!

The reason why TRS transformations are sometimes applied is because KHR_texture_transform only support rotation at [0, 0]. See glTF/extensions/2.0/Khronos/KHR_texture_transform at master · KhronosGroup/glTF · GitHub

Rotate the UVs by this many radians counter-clockwise around the origin

If the rotation point is not at the origin [0, 0], I don’t think there is a way to preserve the original intent in a glTF and thus we bake the transform into the texture. We should use the same resolution though and it shouldn’t loose much precision.

The code is checking this: Babylon.js/KHR_texture_transform.ts at master · BabylonJS/Babylon.js · GitHub

Perhaps the code is not doing the check properly or not baking the transforms properly.

1 Like

Ah, the original complaint was that we were removing the Texture transform extension, if that’s the case then this isn’t a bug. The textures appear to be baked properly. @Atul_Sharma, since you’re offsetting the texture, we cannot export this texture using KHR_texture_transform as @bghgary explained.

Well, hold on. The PG from @Atul_Sharma doesn’t do any rotations. If you set uRotationOffset and vRotationOffset to 0, then it won’t bake the transforms. This is because uRotationOffset and vRotationOffset default to 0.5, 0.5 in Babylon.js.

But since we are not doing any rotations at all, the uRotationOffset and vRotationOffset shouldn’t even matter. The code should be updated to check if there is even a rotation.


Ah, good catch! I think we can just simplify this bake code to only check for

   babylonTexture.wAng !== 0 
&& (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0))

I’m not sure. If someone uses uAng or vAng, I think that will affect the texture matrix also. Probably should check both of these.

1 Like

thanks @bghgary @Drigax It does the work for me now. I have some more doubts I will add them later.