A shape's Perfect-fit Bounding Box?

Hi,

I was wondering how to get the bounding box for a model that fits that model perfectly. It seems like everytime I do BoundingBox bbox = new BoundingBox(theModel.getBounds()), I get the same bounding box no matter what, which has lower point (-1,-1,-1) and upper point (1,1,1). The bounding box always seems to be this size no matter how big or small the actual model is. Is there a way to get the bounding box that fits the model perfectly?

The reason I ask this question is because I want to load some models into my scengraph, and I want to compute that model’s width, length, and height. I thought I could get it from the model’s boundingbox, but as I mentioned previously, the bounding box never scales according to its model.

Thanks,
DAT

Hm strange … I did checks against BBoxes myself and they seemed to be correct…

But I never constructed a new one from a models getBounds().
Maybe try to check wether the models getBounds() already delivers a BoundingBox, cast, and examine that? (thats the way I worked with it.)

Ah, and I dunno wether the model has to be live for the bounds getting calculated correctly!!

When you call getBounds() you always get a BoundingSphere if the bounds is autocomputed.

Is the properties of this sphere also the same each time?

Sure thats true?

I think I got an BoundingBox already, not a BoundingSphere. IIRC I used it with models loaded from 3DS with Starfires loader.

So Herkules, how did you get your 3ds models’ bounding box? If I can do it without a boundingsphere in between or getBounds(), that’s fine. I just want to know how to get the bounding box for the sakes of computing the dimensions of my model.

Also, I load up my model as follows:


class ModelWrapper extends BranchGroup {
....

ModelLoader loader = new ModelLoader();
Scene scene = null;
try { scene = loader.load(filename);
        }
...

}

The ModelWrapper branchgroup is the child of a transformgroup, and that transformgroup is the child of another branchgroup.

Which group should I be computing my bounding box off of? Or perhaps I compute it based off of scene?

Thanks.

"When you call getBounds() you always get a BoundingSphere if the bounds is autocomputed.

Is the properties of this sphere also the same each time? "

Well, as I mentioned in the post above this one, there maybe be a problem of me calling getBounds() on the wrong object.

I’m using Portfolio Loader to load dxf files, and I provided the code snippet for my code loader in the previous post.

What should I be calling getBounds on?

Hm, if in doubt, get the bounds from everything you can get hold of. Check for bounds type (instanceof BoundingBox?).

If the bounds are wrong, maybe the loader is fooling you? getAutoComputeBounds() is true?

Sorry that I cannot help better - just can say the NORMALLY the results of getBounds() makes sense.

So should autoComputeBounds be true or false? Ifodalai said earlier that “When you call getBounds() you always get a BoundingSphere if the bounds is autocomputed”, but I’m not sure if that’s what I want.

getBounds() always should deliver a bounds. Not necessarily a BoundingSphere, can be BoundingBox.
autocomputebounds lets Java3D compute the bounds by aggregating them up the scenegraph whenever a change in a subgraph occurs.

So e.g. if the loader assembles the model from smallerparts that have bounds, Java3D will automatically compute the bounds for the higherlevel nodes.

Sometimes this is desirable, sometimes not. A loader might be a candidate to set the bounds itself and let autocompute off. But if it doesn’t…

[quote]Sure thats true?

I think I got an BoundingBox already, not a BoundingSphere. IIRC I used it with models loaded from 3DS with Starfires loader.
[/quote]
Yes I am sure. I believe they do that because it is faster to check for intersections with spheres than boxes or polytypes, when doing viewFrustumCulling.

It could be the loader disabled autocomputing and then has sat the bounds to a box.

Yes ok - this makes sense and does not contradict the facts I observed.

So autocomputed bounds always are BoundingSpheres.

The more I think the loader is fooling DAT64X.

[quote]Is there a way to get the bounding box that fits the model perfectly?
[/quote]
Yes, some time ago a guy wrote a routine to do just that.

I think his name was Fabrizio Nunnari (http://digilander.libero.it/fnunnari), but I cant search the Java3D archives that feature seems not to work.

I remember a complete source solution to your problem was posted some years ago on the mailing list.