diff --git a/src/core/Raycaster.ts b/src/core/Raycaster.ts index f9d9efb..89a987d 100644 --- a/src/core/Raycaster.ts +++ b/src/core/Raycaster.ts @@ -20,6 +20,7 @@ export default defineComponent({ onPointerLeave: { type: Function as PropType, default: emptyCallBack }, onClick: { type: Function as PropType, default: emptyCallBack }, intersectMode: { type: String, default: 'move' }, + intersectRecursive: { type: Boolean, default: false }, }, setup(): RaycasterSetupInterface { const renderer = inject(RendererInjectionKey) @@ -39,6 +40,7 @@ export default defineComponent({ camera: renderer.camera, domElement: renderer.canvas, intersectObjects: this.getIntersectObjects(), + intersectRecursive: this.intersectRecursive, onIntersectEnter: this.onPointerEnter, onIntersectOver: this.onPointerOver, onIntersectMove: this.onPointerMove, diff --git a/src/core/usePointer.ts b/src/core/usePointer.ts index f4d1de5..1938cdf 100644 --- a/src/core/usePointer.ts +++ b/src/core/usePointer.ts @@ -22,6 +22,7 @@ export type IntersectObject = Mesh | InstancedMesh export interface PointerPublicConfigInterface { intersectMode?: 'frame' + intersectRecursive?: boolean touch?: boolean resetOnEnd?: boolean resetPosition?: Vector2 @@ -59,6 +60,7 @@ export default function usePointer(options: PointerConfigInterface): PointerInte camera, domElement, intersectObjects, + intersectRecursive = false, touch = true, resetOnEnd = false, resetPosition = new Vector2(0, 0), @@ -119,7 +121,7 @@ export default function usePointer(options: PointerConfigInterface): PointerInte function intersect() { if (intersectObjects.length) { - const intersects = raycaster.intersect(positionN, intersectObjects) + const intersects = raycaster.intersect(positionN, intersectObjects, intersectRecursive) const offObjects: IntersectObject[] = [...intersectObjects] const iMeshes: InstancedMesh[] = [] diff --git a/src/core/useRaycaster.ts b/src/core/useRaycaster.ts index d28e862..2ebf662 100644 --- a/src/core/useRaycaster.ts +++ b/src/core/useRaycaster.ts @@ -4,7 +4,7 @@ import { IntersectObject } from './usePointer' export interface RaycasterInterface { position: Vector3 updatePosition(coords: Vector2): void - intersect(coords: Vector2, objects: IntersectObject[]): Intersection[], + intersect(coords: Vector2, objects: IntersectObject[], recursive: boolean): Intersection[], } export interface RaycasterConfigInterface { @@ -28,9 +28,9 @@ export default function useRaycaster(options: RaycasterConfigInterface): Raycast raycaster.ray.intersectPlane(plane, position) } - const intersect = (coords: Vector2, objects: IntersectObject[]) => { + const intersect = (coords: Vector2, objects: IntersectObject[], recursive = false) => { raycaster.setFromCamera(coords, camera) - return raycaster.intersectObjects(objects) + return raycaster.intersectObjects(objects, recursive) } return {