Jump to content

bounding box calculation


ua4192
 Share

Recommended Posts

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);

 

Link to comment
Share on other sites

I forgot to mention that I am combining transformation matrix in this way:

MESH --> TRANSMAT

     SUBMESH_LEVEL1 --> TRANSMAT_LEVEL1

          SUBMESH_LEVEL2 --> TRANSMAT_LEVEL2

          ...

                             SUBMESH_LEVELN --> TRANSMAT_LEVELN

 

Link to comment
Share on other sites

Here you have an example of the first BOX in  the scene: here you will see the box definition of the box I want to render(3002.19177246,484.777023315,-292.95451355,12.0001220703,38.2382965088,62.6923980713) and the concat transmatrix array from the first parent until the child from level 0 to level 5

0.996908,0.00435,0.078459,-0.004363,0.99999,0.0,-0.078458,-3.42E-4,0.996917,17923.436,-12778.56,979.951 

-1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000

--1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000

---1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000

----1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000

-----1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000

BJS - [14:57:11]: -- > Processing line: 1/70; length=13  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: -- > COMMON UUID LEVEL bettwen  and 7118d126db404b019d963024ede55be6,182d1297ca7a2c3fe576d5e924591ee0,ba8e63361e1bedef876ac2cc75f9df3b,8e52b463d1bea114367ada11b08077ca,409126d2e817165466aaa4028759e358,5b9818aedd109139224231cd6c3582ca,17291597f1824e85b2dc29a50407fedf ------ > 0; --- > uuid_array_length=7  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: -- > COMMON PN LEVEL bettwen  and MPPX-MC40-S46-LH-R,MPPE-MC40-S46-A36-LH,MPNS-MC40-S46-A36-11000-LH,M36CA2101000,M36CA2101004,M361A200300000,M361A120320000 ------ > 0; --- > uuid_array_length=7  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: ---- > mymesh.parent.id=scene_id; mymesh.parent.name=scene_name; level=0TransMat=0.996908,0.00435,0.078459,-0.004363,0.99999,0.0,-0.078458,-3.42E-4,0.996917,17923.436,-12778.56,979.951  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: ---- > mymesh.parent.id=7118d126db404b019d963024ede55be6; mymesh.parent.name=MPPX-MC40-S46-LH-R_A.14; level=1TransMat=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:57:11]: ---- > mymesh.parent.id=182d1297ca7a2c3fe576d5e924591ee0; mymesh.parent.name=MPPE-MC40-S46-A36-LH_A.8; level=2TransMat=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:57:11]: ---- > mymesh.parent.id=ba8e63361e1bedef876ac2cc75f9df3b; mymesh.parent.name=MPNS-MC40-S46-A36-11000-LH_A.3; level=3TransMat=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:57:11]: ---- > mymesh.parent.id=8e52b463d1bea114367ada11b08077ca; mymesh.parent.name=M36CA2101000_A.17; level=4TransMat=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:57:11]: ---- > POSITIONING MESH M361A200300000_C26  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: ---- > MAKING BOUNDINGBOX for CATPart M361A120320000_A11; BOX_INFO=3002.19177246,484.777023315,-292.95451355,12.0001220703,38.2382965088,62.6923980713; 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:57:11]: ---- > 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  babylon.2.5.max.js:5410:13
BJS - [14:57:11]: ---- > SCENE_BB after = 1000000,1000000,1000000,-1000000,-1000000,-1000000  babylon.2.5.max.js:5410:13

Link to comment
Share on other sites

Well, making a real PG has some benefits : this forces the user to reproduce the problem by isolating it from all the context of his whole application code. This forces the user to simplify things to make the issue visible and understandable to others...

and, most of all, this often leads the user to discover that the issue wasn't where he initially thought but somewhere else in his code, because of its complexity or length (it appends to me all the time).

So please try to reproduce the issue in a PG

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...