NGE UV-variation for instances

Hi there!

I have a little question regarding the Node Geometry Editor.

  1. I want to instantiate a mesh multiple times in a linear direction. (works)
  2. I want to give the UVs a random offset per instantiated mesh.

Is this possible somehow?

This is what I’ve got [Babylon.js Node Geometry Editor]

  • When setting the random value to instanceID the UVs of all cubes are offsest randomly, but for each instance the same.

  • When setting the random value to LoopID every vertex UV position of all boxes is uniquely affected.

Both cases make sense. But is there a way to affect each boxes UV with the same random value, so there is no distortion of the initial mapping?

Thank you very much,

best, David

cc @PatrickRyan

@Fenk, there is a slight order of operations issue with your graph. Since you call the instantiate block before the setUV block, the output only has one instance which is the final mesh of 10 blocks. This is why you are seeing only one value when locking random to instance ID. To get this to work correctly with instance ID, you need to wire your setUV block before your instantiate block so it has access to the instance ID to increment the UVs. However, this will generate a new random value per instance, not the same value to offset instanceID times.

There are two solves here and one of them will need a small feature request. The first solve is to set your random value in code before you build your mesh.

Note I have a float named rand multiplying by the instance ID which will give you the same offset for each instance as you can see in the preview window. Once you have loaded the node geometry graph, you can use nodeGeometry.getBlockByName("rand").value = your_random_value which will set the value of that block once. Then when you build the mesh, your random value will be used to offset the UVs per instance.

The other way would be to have a fourth lock that generates the random value only once. There isn’t another way to do this in the current node system. Normally, you would use evaluate context to disable generating random values multiple times, but you can only use those with nodes like setUVs, which defeats the purpose here. I will open a feature request for the new lock, but we have some vacation schedules to work around, so this may not come in for a week or so if we are able to do it. Hope this helps in the interim.

3 Likes

@PatrickRyan thank you so much!!

This is EXACTLY what I needed. With the randomly offset UVs per instace, I can use a tilable wood texture, and give every wood block a unique look.

I really appreciate your help.

Thanks again,

best, David

2 Likes