Babylon Editor - export texture scaling

Hello! :grinning:

Is there a way for textures on export to keep their transform values, specifically changing scaling V to -1?



Pinging @julien-moreau

1 Like

Hey @sguerrero,

It should. If not, I suggest to use the Editor v4. Are you using the Editor v4 ? It is availble here in beta.3: BabylonJS Editor v4.0.0 beta · BabylonJS/Editor Wiki · GitHub and will be released in few weeks.

Documentation is available here (still WIP): Editor/ at release/4.0.0 · BabylonJS/Editor · GitHub

The Editor v3 projects are not compatible with v4. If you are not in an advanced project using the v3, I highly suggest that you use the v4 as it provides more stability and is more wysiwyg than the v3.

@julien-moreau Thank you for the speedy response!

I am using v4 of the Editor, but it was beta.2. I just downloaded beta.3 to see if that helped, but I still got the same issue on export. I uploaded two images to show how my scene looks in the Editor prior to export, and what is being exported. In the Editor I do scale V on the textures to -1, but it is either not saving that or flipping them back on export.

Ouch! I’m fixing ASAP!!!
Thanks for that feedback, I’m testing right now :slight_smile:

With my first tries, I don’t reproduce :frowning:

When I drag’n’dropped a mesh with its textures in the assets, I got the textures added to the “textures assets” directly. When I dropped the mesh from the assets in my preview I got textures created twice.

What you can try: clear the unused textures using the button “Clear Unused” in the textures assets panel:

Then, select the texture you want to modify.
If it shows UV equal to -1 that means I have a big bug. If they look untouched that means you haven’t modified to right texture.

In any cases, I should not create textures twice, the Editor should reuse them. I’m fixing that ASAP as well :slight_smile:

I haven’t encountered an issue with duplicate textures. What I think is happening is exporting out of the Editor is not saving the texture scaling changes.

When I open an exported glb in either Editor or sandbox the textures V scaling resets back to 1, instead of the -1 I set it to.

Ah !! You are using GLTF :slight_smile:
I’m trying with a GLB right now

@sguerrero I still don’t reproduce :frowning:
Is that possible that you share your scene with me ? Via PM or a public link? That would help me a lot to reproduce and fix that bug. Thanks :slight_smile:

As seen with @sguerrero, the problem appears when the GLTF/GLB serializer is used.

Context: All textures in the Editor have UV scales equal to (1, -1).

Using Babylon.JS Scene Serializer: When the scene is exported using the .babylon serializer, that works well: the UV scales are preserved in the .babylon file and the scene looks well after the serialization in the sandbox.

Using the GLTF/GLB Scene Serializer: When the scene is exported using the GLTF/GLB serializer, all UV scales are reset to (1, 1). @bghgary is that an issue you know ? The only thing that the Editor does is using the .GLBAsync or .GLTFAsync functions: Editor/tools.ts at release/4.0.0 · BabylonJS/Editor · GitHub

@julien-moreau depending on the current texture transform, we bake the texture transform into the output texture. we mainly do this because of restrictions of the texture transforms that can be expressed in glTF

Thanks for that informations @Drigax!
That means if the texture matrix is modified then it is applied on the output texture when exporting to gltf or glb?

It depends. Check our logic when deciding whether to preserve the texture and preserve the texture transform, or bake the texture and reset its matrix:

Where if the rotation center is not centered, we have any uAng or vAng texture rotations, we can’t express this so we have to bake the texture information and export the baked map.

The expection is that one should consider the exported texture as separate from the imported texture that was used in the scene. Meaning, one isn’t guaranteed to be able to roundtrip an exported texture into the same scene using the same texture transformations, as it may have been baked

I appreciate all the assistance so far on the issue. What I am using the Editor for at the moment is to assemble a scene to then export into a repository.

If we connect all the textures to the materials in Maya or Blender before we export, the textures then export from the Editor correctly. If we update textures in the Editor however, they export inverted. It would be nice to be able to edit textures in the Editor without having to re-export a new glb from either Maya or Blender.

Thanks! :grinning:

Hi @Drigax thanks a lot for all these informations :slight_smile:
I understood the limitations and that’s not good news for us! Ahah

Do you think there can be a workaround for @sguerrero? I mean what can we do instead of using UV Scales to invert the texture on V ?

Thanks for your answer :slight_smile:

I’m back :slight_smile:

We shouldn’t be baking the texture unless it’s necessary as @Drigax pointed out. It should only be necessary when the texture is rotated. Is the texture rotated in this case?

@bghgary hello ! :slight_smile:

Looks like it is not rotated.

The problem is if you modify the UV scaling of a texture in your scene, for example (uScale, vScale)=(1,-1) and then serialize your scene using the GLTF serializer, the final gltf file doesn’t take car of these values. That means when you load your previously serialized GLTF, then all textures have their UV scaling equal to (1, 1) and they don’t appear flipped on V visually.

The question of @sguerrero is « are these UV scaling values set on textures supported by the gltf format ? »

If not, what can be the workaround for @sguerrero, as he just want to flip the scale on V for some textures.

glTF has an extension that supports texture transforms: glTF/extensions/2.0/Khronos/KHR_texture_transform at master · KhronosGroup/glTF · GitHub

The serializer is aware of this extension and should be exporting it when the values are not the default. Would it be possible to debug the serializer and make sure it’s working properly?

Not sure, I’d have to take a look at a scene that reproduces this issue. Can you or @sgurrero create a Playground that loads some asset that reproduces this issue when exported? At this point I need to debug this.

Hi @Drigax,

You can find the repro here: Babylon.js Playground
The V scale is set to -1 so the palm tree texture appears on the top of the sphere.

Once you downloaded the file and drag’n’dropped in the sandbox, the palm tree appears on the bottom of the sphere. That means the scale is set to 1 on V.

From camera on top of sphere in playground:

From camera on top of sphere in sandbox:

1 Like