Loading data into a mesh super-fast!

I load landscape meshes dynamically and notice lags while moving around in larger realms in my game.

This is how I load my landscape mesh data:

//let data: { vertices: number[], indices:number[], uvs: number[] }

if (data.vertices.length > 0) 
                mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, data.vertices, false);
                mesh.setIndices(data.indices, null, false);
                mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, data.uvs, false);

Anyone knows about a faster way to load data into a mesh ?

Many thanks :slight_smile:

could you give us some more info? Is this vertex data procedurally generated dynamically or is it pre-computed somewhere? What is the topology of the landscape, could a heightmap texture be used?

There are many ways depending on what your requirements are for the landscape mesh.

For simple terrain you can export a heightmap from something like terragen/zbrush…etc.
For procedural terrain you can make a vertex shader with some noise.
Both are way more efficient that loading a huge mesh vertex by vertex.

It is pre-computed vertices, indices, and uvs for the mesh and the data is not procedurally generated and other objects and data is interacting with the mesh object.

using Float32Array and UInt8Array would prevent extra copies but there is still a roundtrip to the gpu which is quite costly


Thanks, I can use that :slight_smile:

Thanks for sharing your insight of babylon!