Jump to content

SubMeshes, GlobalSubMesh


gwenael
 Share

Recommended Posts

Hi there,

 

I was reading the code for BABYLON.SceneLoader._ImportGeometry and I noticed that the following line calls internally the creation of a global subMesh:

mesh.setVerticesData(parsedGeometry.positions, BABYLON.VertexBuffer.PositionKind, false);

Later in this function, there is the following part:

if (parsedGeometry.subMeshes) {                mesh.subMeshes = [];                for (var subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {                    var parsedSubMesh = parsedGeometry.subMeshes[subIndex];                    var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);                }            }

Thus mesh.subMeshes which previously contained the global suMesh is cleared and filled by subMeshes found in the .babylon file (or .babylonmeshdata file).

 

Is there always a global submesh provided for a mesh in the .babylon file (or .babylonmeshdata file)? If yes, and if that the first one in the array, I have the feeling that during importing geometry, it would be possible not to empty mesh.subMeshes and to start the loop to 1. We'll get this:

if (parsedGeometry.subMeshes) {                for (var subIndex = 1; subIndex < parsedGeometry.subMeshes.length; subIndex++) {                    var parsedSubMesh = parsedGeometry.subMeshes[subIndex];                    var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);                }            }

In the collision code, I got confused too.

 

I understood that first the collision with the bounding sphere and the bounding box of the mesh is checked and then the collision for the subMeshes is checked. The globalSubMesh seems to be the first in the array of subMeshes, so the collision with its bounding sphere and its bounding box is checked too. Its boundingInfo are the same as the mesh, aren't they?

 

From these two examples, I feel like we are computing twice the same thing. I may be wrong so please correct me so I could understand the use of this global submesh. Thank you.

Link to comment
Share on other sites

the global submesh is a the submesh that cover all the mesh. If there are submeshes in the .babylon file we have to remove the globalsubmesh because the file will provide more precise subdivisions

 

From the collisions point of view, after checking bounding box and sphere, we have to check submeshes one by one in order to optimize collisions (not against all the mesh but jsut against a specific submesh)

Link to comment
Share on other sites

Ok, thank you Deltakosh. So things are computed twice (for the mesh and the global submesh) only if no submeshes are provided in the babylon file. Is that right? I will test a new export (FBX to Babylon) because I have the impression that if I don't have submeshes in 3ds max, I have a submesh (corresponding to the global submesh) in the babylon file.

Link to comment
Share on other sites

OK I found the code you're talking about. Thank you.

BABYLON.Mesh.prototype._processCollisionsForSubModels = function (collider, transformMatrix) {    for (var index = 0; index < this.subMeshes.length; index++) {        var subMesh = this.subMeshes[index];        // Bounding test        if (this.subMeshes.length > 1 && !subMesh._checkCollision(collider))            continue;        this._collideForSubMesh(subMesh, transformMatrix, collider);    }};
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...