Changing few vertex position in a mesh

Recommended Posts

I'm trying to create a forest with planes. All with a unique texture. Since I want it to be optimize, I have created a sort of "clusterer" to append some textures together and draw the planes into one mesh (with some serverside work to append the textures). It works fine!

The problem that I have is that I need to animate the scale of the planes dynamically. I am using mesh.setVerticesData() to update the vertex positions, but it has some performance issues. Is there a way to update only 16 vertices positions out of 64k without refreshing ALL of the mesh?

I'm not sure if I'm clear enough... that's what I have so far to update the positions.

updateMesh(index, vertexPositions) {
    let positions = this.mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
    let dataLength = vertexPositions.length;
    let startIndex = index * dataLength;

    for(let i = 0; i < dataLength; i++) {
        positions[startIndex+i] = vertexPositions[i];

    this.mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);


Share this post

Link to post
Share on other sites

You could just update the 16 wanted vertices and still pass the whole modified buffer (verticesData).. The bottleneck isn't usually in the size of the buffer to be passed to the GPU but rather in the user logic. Have you profiled your code to check where the time was spent and what was responsible for this time consumption ?

BJS provides a feature that could fit your need, called the Solid Particle System (SPS), with many optimizations already set :

and the ability to update only some parts of the system (mesh) and to use a single texture too.


Share this post

Link to post
Share on other sites

I must say, the performance issue is a fps drop of 15 frames. I will profiled my code and get you back.

As for the particle system, I have thought of it, but all my tree are user generated for the shape, decorations, colors, etc. They all have unique textures. Might it work?!? Haven't seen anything like this into the documentation. Sure it would save me a lot of time to manage and optimize the scale animation, but at the same time I feel I'll have an issue with the textures.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.