FreeFrags Posted November 14, 2014 Share Posted November 14, 2014 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); Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 14, 2014 Author Share Posted November 14, 2014 Ideally i would like to add vertices to the existing batch i already have loaded, but knowing how to use the function i pointed out is something i would like to know too Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 14, 2014 Author Share Posted November 14, 2014 O my im sorry guys i made a stupid mistake in my code which made it look like it didnt update :S so we can close this topic Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 14, 2014 Author Share Posted November 14, 2014 Yet still i would like to get the vertices i have loaded and add vertices. anyone ever tried that? what would be the best way Quote Link to comment Share on other sites More sharing options...
Stephen Andrews Posted November 14, 2014 Share Posted November 14, 2014 I too would like more detail on how to do this, as I want to do some experimentation with meshes generated problematically from scratch. Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 14, 2014 Share Posted November 14, 2014 Did you read this ? http://pixelcodr.com/tutos/trees/trees.html Cheers Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 14, 2014 Author Share Posted November 14, 2014 @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 Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 14, 2014 Share Posted November 14, 2014 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. Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 14, 2014 Author Share Posted November 14, 2014 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 14, 2014 Share Posted November 14, 2014 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. Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 17, 2014 Author Share Posted November 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 17, 2014 Share Posted November 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 17, 2014 Author Share Posted November 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted November 17, 2014 Author Share Posted November 17, 2014 I think ill need to take a good look at "ParticleSystem", at first glance it looks like it does something similar. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.