Jump to content

updateVerticesDataDirectly


FreeFrags
 Share

Recommended Posts

Can someone please give an example how to use mesh.updateVerticesDataDirectly 

 

i tried the following but no luck so far

 

where vertices is an array filled x,y,z,x,y,z.......

 mesh.updateVerticesDataDirectly(BABYLON.VertexBuffer.PositionKind, vertices, false);
Link to comment
Share on other sites

@Temechon thank you for your post 

 

That is a very nice page, but it doesnt really show what i would like to do.

 

please see the following simplified piece of code:

var vertexData = new BABYLON.VertexData();vertexData.positions = new Array();vertexData.normals = new Array();vertexData.uvs = new Array();for (var i = 0; i < 9; i++) {  vertexData.positions.push(1);  vertexData.normals.push(1);  vertexData.uvs.push(1);}vertexData.applyToMesh(mbeMesh, true);var h = mbeMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);

somehow h is null here everytime, i would like to get the vertexdata here add new vertices and then call the mesh.updateVerticesDataDirectly some thing like this:

var h = mbeMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);h.push(1,2,3);mesh.updateVerticesDataDirectly(BABYLON.VertexBuffer.PositionKind, h, false);

so obviously im doing somthing wrong here... or maybe there is a better way of doing something like this 

Link to comment
Share on other sites

How do you create mbeMesh ? I think there is a bug in babylon if you use a new mesh (without any geometry).

 

Here is the code for setVerticesData : 

if (!this._geometry) {   var vertexData = new BABYLON.VertexData();   vertexData.set(data, kind);   var scene = this.getScene();   new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene, vertexData, updatable, this);} else {   this._geometry.setVerticesData(kind, data, updatable);}

You can see the new geometry is never affected to this._geometry.

Link to comment
Share on other sites

mbeMesh = new BABYLON.Mesh(name, scene);var vertexData = new BABYLON.VertexData();vertexData.positions = new Array();vertexData.normals = new Array();vertexData.uvs = new Array();for (var i = 0; i < 9; i++) {  vertexData.positions.push(1);  vertexData.normals.push(1);  vertexData.uvs.push(1);}vertexData.applyToMesh(mbeMesh, true);var h = mbeMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);

Im Sorry i missed that line when copy pasting.

 

Babylon has no trouble drawing the mesh, its the getVerticesData which returns null. 

 

I hope i can find sometime this weekend to create a sandbox example for this. 

Link to comment
Share on other sites

udpateVerticesDataDirectly was added in V1.14 for MORPH.Mesh  (in the Babylon Extensions repository).  When vertices / normals are updated they need to be transmitted to the GPU.  The WebGL call that does this requires that the data structure passed is a Float32Array.  This is really setup to be a one time thing in Babylon from a performance standpoint, since up to the intro of updateVerticesDataDirectly, data had to be a [], not Float32Array.  Babylon then had to do a double copy first from [] to Float32Array, & again to the GPU.

 

What made things worse is Float32Arrays are more expensive to create, and they are thrown away every transfer.  Plus, read / update is slightly faster for Float32Arrays.

 

MORPH.Mesh however, needs to continuously update vertices / normals during the deformation process.  Early in dev, I used a public method in Engine and bypassed the existing way.  Deltakosh did not really like this, so I gave my requirements of method which accepted a Float32Array & made not copies along the way.  This is how udpateVerticesDataDirectly came about.

 

You can look in the repository for an example, but the only source is typescript.  In v1.0, I actually got the names of debug & uglified backwards.The Morph.js has readable js.  Fixed in futue release.

Link to comment
Share on other sites

Ok i will take another look, first i will need to update my project to use the latest babylonJS since there were a few modifications made when my pull request was merged.

 

Hopefully i will be able to find it all, my ultimate goal would be that i could update a mesh on the fly, adding and removing vertices when needed. If i manage to get it working and i need to modify anything in the engine you can expect a new pull request :)

Link to comment
Share on other sites

I do not believe adding or removing vertices is possible in BJS.  The positions are the unique coordinates of vertices, with matching normals, but the indices refer to the positions to create the triangles.  I do not set that indices are updateable.  You may be able to set the indices again, but I would look at source before you do.

 

Do not know what you wish to do, but you might want fold the locations on top of others to create the illusion of deletion, or the opposite for creation.

Link to comment
Share on other sites

Id like to be able to "stream vertices" to the gpu, creating a FIFO container with a certain size so the container stays the same size (adding them at one end and removing at the other).

 

In my case it would be enough to only stream vertices and render them as points. The work around you suggest is also possible yes and is not a bad idea at all. ill give that a try before i do anything more complicated.

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