import { MeshCompat, Object3DCompat } from "./Object3DCompat.js";
import { Vector3Compat } from "../math/index.js";
export class RaycasterCompat {
    ray = {
        origin: new Vector3Compat(),
        direction: new Vector3Compat(0, 0, -1)
    };
    near = 0;
    far = Infinity;
    set(origin, direction) {
        this.ray.origin.copy(origin);
        this.ray.direction.copy(direction).normalize();
    }
    intersectObject(object, recursive = true) {
        const objects = [];
        recursive ? object.traverse((entry) => objects.push(entry)) : objects.push(object);
        return objects
            .filter((entry) => entry instanceof MeshCompat && entry.visible)
            .map((entry) => {
            const toObject = entry.position.clone().sub(this.ray.origin);
            const distance = Math.max(this.near, Math.min(this.far, toObject.length()));
            return { object: entry, distance, point: entry.position.clone() };
        })
            .filter((entry) => entry.distance >= this.near && entry.distance <= this.far)
            .sort((a, b) => a.distance - b.distance);
    }
}
//# sourceMappingURL=RaycasterCompat.js.map