Change Data In Render asset

I’m working on a simple terrain editor using editor api, can we change mesh data like vertex positions in render asset or are there any similar methods ?

Chat GPT suggest me this is that possible ?


const meshInstance = entity.render.meshInstances[0];
const vertexBuffer = meshInstance.mesh.vertexBuffer;

// Lock the vertex buffer to make changes
const iterator = new pc.VertexIterator(vertexBuffer);

for (let i = 0; i < vertexBuffer.numVertices; i++) {
    iterator.element.position.set(newX, newY, newZ); // Set new position here
    iterator.next();
}

// Unlock the buffer to apply changes
iterator.end();

// Update the bounding box if needed
meshInstance.mesh.updateBounds();

Hi, I have prepared a solution, it is in the process of development, but you can already do something with it.

1 Like

You can also do this following the example.

https://playcanvas.vercel.app/#/graphics/mesh-generation

1 Like

Wow Thank you so much, I checked it and it’s awesome !