How to pass UVs to NGE from code?

Hello!

I’m trying to figure out if it is possible to pass UVs from code into a NGE object. I have been reading the docs and doing several tries with vectors and arrays, but I can’t figure out how to do this.

Playground:

I get the block in line 37, and in line 38 I would like to set some UVs to it.

This is the NGE object, I have setup the UVs node as user defined:

Thanks for the help!

Hello !

Since the UVs block already generates some decent UVs for your boxes, best would be to edit some Vector3 for translation, etc :

// UVs
nodeGeo.getBlockByName('t_UV').value = new BABYLON.Vector3(4, 3, 0);// Trunk Texture
//nodeGeo.getBlockByName('t_UV').value = new BABYLON.Vector3(5, 1, 0);// Coal Texture
nodeGeo.getBlockByName('r_UV').value = new BABYLON.Vector3(0, 0, Math.PI/2);
nodeGeo.getBlockByName('s_UV').value = new BABYLON.Vector3(1, 1, 1);

  • The 2nd transform applies a scaling of 0.2 because you have 5 tiles on your texture
  • The 1st transform allows to move along the texture, for example (3,2) would offset of 3 blocs X and 2 blocks Y, etc… So that it’s very simple to choose your texture :

Also, please note that I replace your box trunk (which had size → height) by this :


Result is the save except the UV is now OK on both cube faces :slight_smile:

3 Likes

Oooh, I didn’t think of using vectors to move the UVs, nice idea. Thank you for the help Tricotou!

1 Like