There is a very nasty bug in merging bounding spheres with oriented bounding boxes :frowning:

this simple test case:

public void testMergeSphereOBB() {
        BoundingSphere sphere = new BoundingSphere( 1, new Vector3f() );
        OrientedBoundingBox obb = new OrientedBoundingBox();
        obb.setCenter( new Vector3f( 1, 1, 0 ) );
        obb.setExtent( new Vector3f( 1, 1, 1 ) );

        BoundingSphere merged = (BoundingSphere) sphere.merge( obb );
        BoundingSphere merged2 = (BoundingSphere) merged.merge( obb );
        System.out.println( merged );
        System.out.println( merged2 );
        assertEquals( "center", merged.getCenter(), merged2.getCenter() );
        assertEquals( "radius", merged.getRadius(), merged2.getRadius(), FastMath.FLT_EPSILON );

should print the same bounding sphere twice - but is does not! If merge is called more often (about 30 times) the resulting radius is NaN! This results in scenes with many small nodes to be entirely culled :-o
It prints:

com.jme.scene.BoundingSphere [Radius: 2.345208 Center: com.jme.math.Vector3f [X=0.5, Y=0.5, Z=0.0]]
com.jme.scene.BoundingSphere [Radius: 4.0620193 Center: com.jme.math.Vector3f [X=0.5, Y=0.5, Z=0.0]]

junit.framework.AssertionFailedError: radius expected:<2.345208> but was:<4.0620193>

The calcWelzl stuff seems to be the problem... anybody having insight into that strange algorithm? Or do I really have to read through that ugly thing :(?

Problem solved: mergeOBB was approximating the old sphere by a box which caused it to be enlarged by factor sqrt(2). Fixed by merging two spheres (old + obb).