Changing faceUV after Instantiating

Hey everyone happy new year!

I was wondering, is there a way to change the faceUV of a mesh, specifically a box styled mesh, after it has been created?
Heres what i tried to do:
https://www.babylonjs-playground.com/#20OAV9#443

However that doesnt seem to work, is there a way to do this, or will i need to create a new box all together?

Any ideas?

Actually, I had never heard of a faceUV property before. Looks like this is just an option of the MeshBuilder object. UV’s are usually 2 values per vertex, not 4.

MeshBuilder must eventually create a UV vertex buffer. Once created you will need to update the vertex buffer directly. Add an initial value for FaceUV’s, and also add the MeshBuilder option updateable, setting it to true.

Then get the vertexBuffer:

let buffer = box2.getVertexData(BABYLON.VertexBuffer.UVKind);

change buffer, then

box.updateVerticesData(BABYLON.VertexBuffer.UVKind, buffer);

Or you could just skip it during creation, like you did, then do something like:

let buffer = new float32Array({1,2,   1,2   1,2});
box.setVerticesData(BABYLON.VertexBuffer.UVKind, buffer);
2 Likes

This seems like it will work however, im still having trouble getting it working. Heres what i have:

https://www.babylonjs-playground.com/#20OAV9#444

I get an error when trying to use the box2.updateVerticesData(BABYLON.VertexBuffer.UVKind, buffer);
it says:

“Argument of type ‘VertexBuffer’ is not assignable to parameter of type ‘FloatArray’.
Type ‘VertexBuffer’ is missing the following properties from type ‘Float32Array’: BYTES_PER_ELEMENT, buffer, byteLength, copyWithin, and 23 more.ts(2345)”

Any ideas?

faceUV is a parameter to allow the user to select what area to crop from an image and to apply it to the wanted side of some meshes supporting this feature (boxes, cylinders, etc).

As it modifies the internal geometry at construction time, it can’t be changed afterwards.

The real way to change the UVs after a mesh is built is to set it as “updatable” at construction time and then to update its VerticeData about UVs like JCPalmer described in the former post.

yeah thats what i tried in my response to him :slight_smile:

to build on that resposne, i forgot to add updatable to the options, now its in:

https://www.babylonjs-playground.com/#20OAV9#445

When i just use the a float32Array it works but does not produce the intended result:
https://www.babylonjs-playground.com/#20OAV9#446

This is a neat pattern, however i do not think im going in the right direction.

https://www.babylonjs-playground.com/#20OAV9#447

I have never tried understand what the UV data actually was. I just exported it. As I said before it is a set of 2 numbers per vertex.

Maybe do a set where you get the UVs where you set them using faceUV, and write them to console to reverse engineer the values need to set directly.

1 Like

https://doc.babylonjs.com/how_to/updating_vertices

this seems to be what i should read :slight_smile:

1 Like

Got it!

https://www.babylonjs-playground.com/#20OAV9#448

Thanks for the help everyone!

another source for how i figured this all out:

https://www.babylonjs-playground.com/#1ALQPZ#29

Cant sleep on the playground search it is invaluable!

1 Like