omni360 / kuda

Automatically exported from code.google.com/p/kuda
GNU General Public License v2.0
0 stars 0 forks source link

getBoundingBox() function for hemi.model.Model #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I needed to get the bounding box of a model during run-time to assist in 
positioning in 3d space. I could not find this information.  I wrote a function 
for the Class hemi.model.Model below:

hemi.model.Model.prototype.getBoundingBox = function(){

    var boundingBox = new o3d.BoundingBox();

    var shapesLen = this.shapes.length;
    for (var i = 0; i < shapesLen; i++) {
        var shape = this.shapes[i];
        var elementsLen = shape.elements.length;

        for (var j = 0; j < elementsLen; j++) {
            boundingBox = boundingBox.add(shape.elements[j].boundingBox);
        }
    };

    return boundingBox;
};

This works great for me.  However I do not want to commit this because we lack 
Unit Tests that will help us make sure that the code will not break something.

Original issue reported on code.google.com by raj...@gmail.com on 9 May 2011 at 3:20

GoogleCodeExporter commented 9 years ago
The transform of the model contains the bounding box information. You can grab 
it like so:

model.root.boundingBox

with root being the root transform. You can also traverse the transform tree if 
you wanted to get more specific bounding boxes.

Original comment by khang.du...@gmail.com on 9 May 2011 at 4:51

GoogleCodeExporter commented 9 years ago
The model.root.boundingBox object is not accurate and contains extents of 
[-1,-1,-1] rather than the correct values.  I have a unit test that reproduces 
that problem for you to see. I am just waiting for approval from John to commit 
it.

Original comment by raj...@gmail.com on 17 May 2011 at 12:28

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I put the unit tests online.

http://dev/kuda/public/unit_tests/

look at the failures to in test 5 to see what I cam talking about. I will 
commit the unit tests when I get the go-ahead from John P

Original comment by raj...@gmail.com on 17 May 2011 at 2:37

GoogleCodeExporter commented 9 years ago
I added the function getBoundingBox() to the hemi.model.Model class and I 
committed it.  This satisfies what I need.  I will leave this open because of 
the issue of the [-1,-1,-1] extents, but I will lower the Priority

Original comment by raj...@gmail.com on 19 May 2011 at 12:58

GoogleCodeExporter commented 9 years ago
The current getBoundingBox for Model does not return an accurate bounding box. 
It accounts for all of the geometry, but not the transform matrices which can 
alter the rendered geometry radically.

To see the problem, add this line of code to unit1.js at line 75:
hemi.curve.showBoxes([[boundingBox.minExtent, boundingBox.maxExtent]]);

The wireframe of the bounding box does not match the house model. I'm currently 
working on fixing the bounds calculations.

Original comment by erik.kit...@gmail.com on 19 May 2011 at 8:54

GoogleCodeExporter commented 9 years ago
Bounding box calculations fixed. This is the summary of changes:

Updated BoundingBoxes created by add() or mul() to inherit the valid property 
of its parent(s). Fixed bounding box calculations performed by Transforms and 
Shapes. Now force a Model's Transform bounding boxes to be recalculated when 
the Model is done
loading. Updated Model's getBoundingBox function to use correctly calculated 
value.

Original comment by erik.kit...@gmail.com on 20 May 2011 at 4:15

GoogleCodeExporter commented 9 years ago
Excellent Thanks!

Original comment by raj...@gmail.com on 20 May 2011 at 1:03

GoogleCodeExporter commented 9 years ago

Original comment by raj...@gmail.com on 20 May 2011 at 1:04