Poor performance when updating vertex and index buffers of mesh

I’ve created a series of meshes that change over time by updating their vertices but I’m getting a low frame rate. Is there anyway to improve the performance of this?

mesh.setPositions(positions);
mesh.setUvs(0, uvs);
mesh.setIndices(indices);
mesh.setNormals(pc.calculateNormals(positions, indices));

mesh.update();

The arguments I pass to these methods are typed arrays.

I’ve tried calling mesh.clear(true, true, 10000, 10000) after creating the mesh so that the buffers are created with BUFFER_DYNAMIC but it doesn’t improve it. I’ve also tried using mesh.update(pc.PRIMITIVE_TRIANGLES, false) so it doesn’t calculate the mesh’s bounding box.

This example simulates and updates 100k points every frame, and runs really well.

Do you see what is taking the time if you profile the application in Chrome profiler?

This example simulates and updates 100k points every frame, and runs really well.

Can you provide a link to that example?

Do you see what is taking the time if you profile the application in Chrome profiler?

Calculating the normals and writing to the vertex buffer seems to be taking up the most time. I’m guessing that copying from one BufferArray to another is taking time:

class VertexIterator {
  ...
  writeData(semantic, data, numVertices) {
    ...
    element.array.set(data);
    ...
  }
}

How did I forgot! :slight_smile:
https://playcanvas.github.io/#/graphics/point-cloud-simulation

1 Like

This is just a memcopy effectively, in the best case anyways … step into the function and see which branch is being taken.