Skip to main content

BoundingSphere is emty

2 replies [Last post]
josch
Offline
Joined: 2005-08-18
Points: 0

I am having a problem with getting the BoundingSphere of an loaded 3d object.
During application start i immediatly load a file into java3d and place the view that i can see the geometry.
For that task i need the BoundingSphere of that object to compute the view position.

=====CUT=======

scene = loader.load(filename);
BranchGroup sceneGroup = scene.getSceneGroup();
sceneGroup.compile();
BoundingSphere sceneBounds = (BoundingSphere)sceneGroup.getBounds();
Transform3D transform3d = new Transform3D();
Transform3D transform3d1 = new Transform3D();
Point3d point3d = new Point3d();
sceneBounds.getCenter(point3d);
double d = point3d.distance(new Point3d());
Vector3d vector3d = new Vector3d(point3d);
transform3d.set(vector3d);
double d1 = (10D * d) / Math.tan(view.getFieldOfView() / 2D);
vector3d.x = 0.0D;
vector3d.y = 0.0D;
vector3d.z = d1;
transform3d1.set(vector3d);
transform3d.mul(transform3d1);
viewPlatformTransformGroup.setTransform(transform3d);

========CUT=======

The problem is that during application start and directly after loading the file java3d doesn't seem to be ready computing the boundingsphere.
If i put a "Thread.sleep(x)" in front of the "sceneBounds = (BoundingSphere)sceneRoot.getBounds()"
it works, but this can't be the solution.
If i use the application in applet form even this Thread.sleep workaround doesn't help.

Any idea?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nitro
Offline
Joined: 2004-09-12
Points: 0

Where do you add the sceneGroup to the sceneRoot?

josch
Offline
Joined: 2005-08-18
Points: 0

That was a posting mistake, i corrected my org. post.