How to access and edit the coordinates of all UV (UV0, UV1...) data from a given mesh?

I saw in older posts (2017~2020) that you do it from entity.model , but in my case, this was undefined so I can’t access meshInstances.

I think now we need to access from entity.render._meshInstances

Thanks to some old examples from this forum I’m able to modify the vertices themselves, but not the UVs. A quick example bellow:

instance2Meshes = (instance) => (instance.render._meshInstances)
mesh = instance2Meshes(pc.app.root.findByName('Monkey'))[0]
n = mesh.mesh.vertexBuffer.storage.length || mesh.mesh.vertexBuffer.storage.byteLength / 4

buffer = mesh._mesh.vertexBuffer;
iterator = new pc.VertexIterator(buffer)
posSem = iterator.element[pc.SEMANTIC_POSITION];
original = [...new Float32Array(buffer.storage)]

goUp = new Float32Array([...new Array(n)].map((e,i) => i%11 == 1 ? posSem.array[i] + 1 : original[i]))
mesh.mesh.vertexBuffer.setData(goUp)

Thanks

Hi @dadiaar,

You can use the newer Mesh API, only thing you need is a reference to the original mesh. You can get it from a mesh instance like this:

const mesh = this.entity.render.meshInstances[0].mesh;

https://developer.playcanvas.com/api/pc.Mesh.html

1 Like

have a look at this example:
https://playcanvas.github.io/#/graphics/mesh-deformation

it uses mesh.getPositions function. You can access UVs the same way:
https://developer.playcanvas.com/api/pc.Mesh.html#getUvs

2 Likes

Thanks, I’ll check and give a feedback