Jump to content

Changing few vertex position in a mesh


jpvaillancourt
 Share

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);
}

image.thumb.png.296e09ddab84413fb31274c4b8a156be.png

Link to comment
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 : https://doc.babylonjs.com/how_to/solid_particle_system

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

 

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...