gwenael Posted December 23, 2013 Share Posted December 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 24, 2013 Share Posted December 24, 2013 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) Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 24, 2013 Author Share Posted December 24, 2013 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 25, 2013 Share Posted December 25, 2013 If we speak about collisions, things are computed only once because there is a test to check if there is only one submesh gwenael 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 26, 2013 Author Share Posted December 26, 2013 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); }}; GameMonetize 1 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.