Skip to content

Ray.intersectsSphere(sphere) is incorrect for empty Spheres #31187

@jmeurice

Description

@jmeurice

Description

The intersectsSphere(sphere) of Ray is not correct for empty Spheres:

intersectsSphere( sphere ) {
    return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
}

Spheres use radius=-1 to indicate "empty", which is not correctly considered when squaring it here.

This breaks raycasting when testing objects with empty geometries (in some conditions, like when the ray passes close to the origin/Sphere's center)

Reproduction steps

  1. Raycast an empty object (with uninitialized BufferGeometry), for example Line

Code

scene = new THREE.Scene();
scene.add(new THREE.Line()) // Empty geometry in Line
    
const raycaster = new THREE.Raycaster() // Default ray traverses the origin -> distance to empty Sphere-center will be 0 < (-1*-1)
raycaster.intersectObject(scene) // Throws an error (intersectsSphere() doesn't exclude properly)

Live example

Screenshots

No response

Version

r176

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions