I have a question, I don't understand the meaning of 128 in ground.optimize(128). Is 128 the ground to be divided into 128*128 grids, why do it?

I have a question, I don’t understand the meaning of 128 in ground.optimize(128). Is 128 the ground to be divided into 128*128 grids, why do it?

1 Like

Hey,

The documentation says that it is the chunksCount.

Do you need some more explanation?

Yes, the mesh is divided when BABYLON.Mesh.CreateGroundFromHeightMap is defined, which is divided again I don’t understand very well

Hello! The division in CreateGroundForHeightMap is different from the division in optimize. In the first one, the divisions parameter is used in creation, to control how many triangles will the final heightmap have (Babylon.js/groundBuilder.ts at 19e98d3a4c15b434740694b14f90c34b6b4294e3 · BabylonJS/Babylon.js · GitHub). The second one is utilized during picking, rendering, etc, to divide the created mesh into multiple submeshes (Babylon.js/mesh.ts at 19e98d3a4c15b434740694b14f90c34b6b4294e3 · BabylonJS/Babylon.js · GitHub), which will then be used in these operations.

Edit: I tried making a drawing to help visualize the difference :rofl:

3 Likes

Thank you very much for your answer, I understand the meaning of the parameters, but now there is still a question, set the chunkSize parameter to create the internal octree, but if the chunkSize=100, the grid will be directly divided into 100 parts, which is the same as I The structure of the understood octree is not the same. When chunkSize=100, how is the grid organized according to the structure of the octree?

ChunkSize doesn’t divide by a grid, it divides by indices. For a concrete example, let’s say we had a plane mesh with 8 triangles. Dividing it by a 3x3 grid would lead to something like the right image. While what subdivide does is dividing the indices of the mesh in 3 submeshes, which in this example could mean that triangles 1-3 go to submesh 1, triangles 4-6 go to submesh 2 and triangles 7-8 go to submesh 3:

Also, it’s important to note that the chunkSize parameter controls the number of submeshes, not the division level of the octree. For the division level, there’s another parameter named octreeBlockSize: Babylon.js/groundMesh.ts at fcdad0b06c122db089a23d871d42b9a449f73309 · BabylonJS/Babylon.js · GitHub. The wording on the documentation is a bit misleading, so I’ll fix that.

3 Likes

Created a PR to fix the docstring Improve optimize docstring. by carolhmj · Pull Request #12950 · BabylonJS/Babylon.js (github.com)

3 Likes

Thanks again for your answer, that is, if there are 10,000 triangular faces and chunksize=100, then 100 sub-grids can be divided, and then these 100 sub-grids can be managed in the form of octrees, am I right?

You’re right! :slight_smile:

Thank you very much for your patient answer! :smile:

3 Likes

It’s my pleasure :smiley: