Search the Community
Showing results for tags 'bounding box of multiple meshes'.
-
Hi I want to calculate the combined aligned bounding box of all boxes loaded in my scene. Here you can see the logs I am posting in my code: TRANS_MAT=1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000 babylon.2.5.max.js:5410:13 BJS - [14:10:35]: ---- > MESH_BB before transforming = -12.0001220703125,-38.23829650878906,- 62.69239807128906,12.0001220703125,38.23829650878906,62.69239807128906 0.000000+3002.19177246,0.000000+484.777023315,0.000000+-292.95451355 babylon.2.5.max.js:5410:13 BJS - [14:10:35]: ---- > MESH_BB after transforming = 1.7976931348623157e+308,1.7976931348623157e+308,1.7976931348623157e+308,-1.7976931348623157e+308,-1.7976931348623157e+308,-1.7976931348623157e+308; SCENE_BB = 1000000,1000000,1000000,-1000000,-1000000,-1000000 As you can see, after transforming the box ( positioning and rotating), the bounding box I am obtaining is not real. I thought that I was using the TRANS_MAT in a proper way, but it seems it is not the case. Here you can see my code: A small function to get the min(x,y,z) and max(z,y,z) function get_scene_box1(scene_bb1, current_bb1) { // To do: optimize in 2 for loops: //BABYLON.Tools.Log("----------------------------------------array_bb=" + array_bb); for (var b = 0; b < 3 ; b++) { if (current_bb1 < scene_bb1){ scene_bb1 = current_bb1; } } for (var b = 3; b < 6 ; b++) { if (current_bb1 > scene_bb1){ scene_bb1 = current_bb1; } } return scene_bb1; } And the code: BABYLON.Tools.Log("---- > MAKING BOUNDINGBOX for CATPart " + partnumber_array[q] + "_" + version_array[q] + "; BOX_INFO=" + bbox_info + "; TRANS_MAT=" + trans_mat); // We create the Box with unity value: var mymesh = new BABYLON.Mesh.CreateBox( part_number, 1, scene); // We position and scalate the box: mymesh.scaling= new BABYLON.Vector3(bbox_info[3]*2, bbox_info[4]*2, bbox_info[5]*2); // We set the relative trans matrix: // to check for null values and sums mymesh.computeWorldMatrix(true); mymesh.refreshBoundingInfo(); var mesh_bb = []; mesh_bb[0] = mymesh.getBoundingInfo().boundingBox.minimumWorld.x; mesh_bb[1] = mymesh.getBoundingInfo().boundingBox.minimumWorld.y; mesh_bb[2] = mymesh.getBoundingInfo().boundingBox.minimumWorld.z; mesh_bb[3] = mymesh.getBoundingInfo().boundingBox.maximumWorld.x; mesh_bb[4] = mymesh.getBoundingInfo().boundingBox.maximumWorld.y; mesh_bb[5] = mymesh.getBoundingInfo().boundingBox.maximumWorld.z; //BABYLON.Tools.Log("---- > CURRENT_LINE=" + mesh_counter ); BABYLON.Tools.Log("---- > MESH_BB before transforming = " + mesh_bb + " " + trans_mat[9] + "+" + bbox_info[0] + "," + trans_mat[10] + "+" + bbox_info[1] + "," + trans_mat[11] + "+" + bbox_info[2] ); mymesh.position = new BABYLON.Vector3(trans_mat[9]+bbox_info[0],trans_mat[10]+bbox_info[1],trans_mat[11]+bbox_info[2]); axis1 = new BABYLON.Vector3(trans_mat[0],trans_mat[1],trans_mat[2]); axis2 = new BABYLON.Vector3(trans_mat[3],trans_mat[4],trans_mat[5]); axis3 = new BABYLON.Vector3(trans_mat[6],trans_mat[7],trans_mat[8]); var rot = BABYLON.Vector3.RotationFromAxis(axis1, axis2, axis3); mymesh.rotation = rot; mymesh.isVisible = true; var mymesh_parent = array_scene_meshes[uuid_array[q-1]]; var name_parent = mymesh_parent.name; var id_parent = mymesh_parent.id; mymesh.parent = mymesh_parent; // We get the bounding box information for eac hsubmesh in GLTF: mymesh.computeWorldMatrix(true); mymesh.refreshBoundingInfo(); var mesh_bb = []; mesh_bb[0] = mymesh.getBoundingInfo().boundingBox.minimumWorld.x; mesh_bb[1] = mymesh.getBoundingInfo().boundingBox.minimumWorld.y; mesh_bb[2] = mymesh.getBoundingInfo().boundingBox.minimumWorld.z; mesh_bb[3] = mymesh.getBoundingInfo().boundingBox.maximumWorld.x; mesh_bb[4] = mymesh.getBoundingInfo().boundingBox.maximumWorld.y; mesh_bb[5] = mymesh.getBoundingInfo().boundingBox.maximumWorld.z; //BABYLON.Tools.Log("---- > CURRENT_LINE=" + mesh_counter ); BABYLON.Tools.Log("---- > MESH_BB after transforming = " + mesh_bb + "; SCENE_BB = " + box_def1); box_def1 = get_scene_box1(box_def1, mesh_bb); BABYLON.Tools.Log("---- > SCENE_BB after = " + box_def1);