Fedor

How to create an updatable custom shaped mesh

Recommended Posts

As far as I understand, updating the positions data on a mesh using updateMeshPositions - or other update* functions - only works when the mesh is set to be updateable. This setting can only be done at creation time. 

All basic shape creation* functions have the updateable option that can be set, but the standard mesh constructor has not. How do I make a custom shaped mesh updatable?

I have thought of a workaround, by creating an updateable cube or something and replacing the vertices data with my custom mesh data. I have not tested this, but I will.

 

And another question: it was my take that the updateMeshPositions is the fastest way to update the vertices positions. setVerticesData works also on non Updateables but seems to be slow. Is updateMeshPositions the fastest way to modify the vertices positions? And if not, what is? 

I am working on a sculpting app, my custom mesh has over 50K positions. Updating vertices is what the app is all about and I need it to be done as smooth and realtime as possible.

Share this post


Link to post
Share on other sites

#1 all shapes provided by BJS have the updatable option what means the underlying mesh vertex buffer can be updated without being destroyed/recreated once the mesh is created if we need to morph it.

#1 bis. Among all these provided shapes only a part of them are called "parametric shapes" ( http://doc.babylonjs.com/tutorials/parametric_shapes )  . Only the parametric shapes provide a way to be updated directly by calling back their constructor with the parameter "instance"

#1 ter. For any other updatable mesh, you can use the function updateMeshPositions(). This function is not faster nor slower than updateVerticesData() because it just calls it !

# 2 If you use another shape from another origin than the provided shapes (imported from blender, created by you from scratch, etc), you could then set the parameter updatable at the VertexData level : https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.mesh.vertexData.ts#L83

# 3 setVerticesData() creates a new vertex buffer on each call, this means that the garbage collector will have to clean up the house. If you need to really update some mesh of your own, it's better to create it with setVerticesData() and then only to update it with updateVerticesData()

 

Share this post


Link to post
Share on other sites

Tnx John and Jerome, this is great additional information to get a more in depth view of how Babylon works!

@JohnK But why is there a second manual that would be a very nice addition to the one on the website? 

@jerome so updateVerticesData would be faster, My guess is it still does a copy of the entire buffer. Wouldn't it be nice to have a function to directly update a single vertice or a given range in the meshes own buffers? @Deltakosh 

 

 

 

Share this post


Link to post
Share on other sites
4 hours ago, Fedor said:

@JohnK But why is there a second manual that would be a very nice addition to the one on the website? 

That is because the guide is a manual I write and maintain as a compliment to the official documentation. This way I can keep the content in a manner and a style I want. You will see this is different than the official documentation. There is a link at the bottom of the official documentation to the guide.

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.