Skip to content

Commit

Permalink
updated raycaster to be more maintainable
Browse files Browse the repository at this point in the history
  • Loading branch information
lewibs authored Oct 13, 2023
1 parent b0ead42 commit 2bb68e7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/SimpleRaycaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ export class SimpleRaycaster extends BaseRaycaster implements Disposable {
): THREE.Intersection | null {
const camera = this.components.camera.get();
this._raycaster.setFromCamera(this.mouse.position, camera);
const result = this._raycaster.intersectObjects(items);
const filtered = this.filterClippingPlanes(result);
return filtered.length > 0 ? filtered[0] : null;
return this.intersect(items)
}

castRayFromVector(
Expand All @@ -59,6 +57,12 @@ export class SimpleRaycaster extends BaseRaycaster implements Disposable {
items = this.components.meshes
) {
this._raycaster.set(origin, direction);
return this.intersect(items);
}

private intersect(
items: THREE.Mesh[] = this.components.meshes
) {
const result = this._raycaster.intersectObjects(items);
const filtered = this.filterClippingPlanes(result);
return filtered.length > 0 ? filtered[0] : null;
Expand Down

0 comments on commit 2bb68e7

Please sign in to comment.