Jump to content

How to create an updatable custom shaped mesh


Fedor
 Share

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.

Link to comment
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()

 

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

 

 

 

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

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...