[SOLVED] Secondary UVs and UV morph targets

Hello Deltakosh, hello Wingnut and the whole Babylon Team!
It’s us again, Mainequin. Thank you for your tireless work, it has been a pleasure using Babylon JS so far.

We currently have a usecase, where we need to display furniture with a lot of different possible materials. We do this by unwrapping a table for example, baking it’s lightmap and then defining a texture scale. This texture scale defines a relation between object surface and uv layout, such that 1x1m surface is 1x1 units in uv space.
Then we map a diffuse texture like wood onto the object and define how often this texture repeats on this 1x1m. This gives us incredibly high texture resolution with low bandwith requirements and we can reuse the material textures on different models.
The problem with this method is, that the rotation of the wood texture on the object is defined by the lightmap-layout.

So our first question is:
Do we currently have the option in babylon JS to use a secondary UV-map? Such that we have a UV_lightmap for lightmap.jpg and a UV_material for wood_diffuse.jpg? It would give us a lot more control over the end result and simplify our workflow greatly.

Recently we played around with morph targets and we saw the potential of parametric meshes. We really want to define maybe three parameters for said table like width, length and leg thickness for example, which works almost flawlessly. Except: With our setup the texture will stretch accordingly, since the UV remains unchanged while morphing.

So our second question is:
If we can use a secondary UV, would it be possible to allow morphing of UV-coordinates? We don’t know of any software that can export this kind of morphing, but we can simply build a script that will add the desired UVs in the respective morph-target in the JSON structure.
We would gladly sacrifice another attribute per morph of the 16-attribute limit to do this.

As always thank you very much for your time and dedication
Kind regards
The Mainequin Team

Hey welcome back folks :slight_smile:

Absolutely:), just set texture.coordinatesIndex = 1 (instead of 0)
(for instance the espilit demo uses that tech for the lightmaps: Babylon.js - Espilit demo)

To your second question: So far we do not morph UV (only position, normal and tangent), but I see no problem to add UV for you. I will only need a scene in the playground with a mesh and a morph target already setup so I can use them to test

Hey Deltakosh,
as always thank you for your lightning fast reply.

We used the time to put a Playground together: https://playground.babylonjs.com/#H6YPT8#7
The scene consists of a cube and a shadow plane. Both have morph targets, but since only the cube has a secondary uv map we would need uv-morphing only on this one. Both morph targets of the cube have a new “uvs” attribute, with the relative uv coordinate changes. I hope I pasted them each in the right morph target (~;
We think there should be a way to define which uv set is used for morphing, but we could happily live with a static rule like “when uv morphing is on uv channel 0 will always be used for morphing”.

As always thank you very much for your time,
it is a pleasure for us.
Kind regards
The Mainequin team

Do you mind creating an issue for me in the repo? I will work on that asap (and yeah first version will probably just morph uv0 ;))

We have created a Ticket “Feature Request - UV morphing” with the number #6480.
We’ll change the playground as soon as we can such that the morphed UV will be the first index.

Thank you very much!

I have been notified, that my Team already swapped the UV layouts. :^D
We have modified the Playground accordingly and updated the link in the ticket. The new Link is https://playground.babylonjs.com/#H6YPT8#8

I’ll make it work :slight_smile:

We found it hard to debug wheter our UV-Morphtargets are working correctly or not, since the cube still is pretty complex for editing things by hand.

Therefore we made a simpler example for testing purposes.
At the moment the UVs scale to zero somehow when reaching 1. However the desired effect looks like this:

We checked the UVs in this example by setting up a blender scene, that links the UV-Interpolation directly to the morph target influence, so in case the morphing uses an absolute UV-coordinates for the interpolation this should be correct.
We assumed absolute coordinates, since it is the same for the position attribute.

Thank you and your team very much for getting on it so quickly!

Actually I’m stupid. There was a remaining bug :slight_smile:

This will be all fine with next nightly (in a couple of minutes)

Sorry about the inconvenience

There were no inconveniences. We are very happy that this was possible at all!
We updated the mesh accordingly in our original playground.

We are baffled by the pace you and your team work on these topics and the speed at which you reply.
Thank you very much for your time and dedication,
The Mainequin Team


This is because we value our community above everything else :slight_smile:

1 Like