mirror of
https://github.com/troisjs/trois.git
synced 2024-11-23 20:02:32 +08:00
add intersectRecursive for raycasting #55
This commit is contained in:
parent
4d30f03130
commit
9e828b01b2
@ -20,6 +20,7 @@ export default defineComponent({
|
||||
onPointerLeave: { type: Function as PropType<PointerIntersectCallbackType>, default: emptyCallBack },
|
||||
onClick: { type: Function as PropType<PointerIntersectCallbackType>, 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,
|
||||
|
@ -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[] = []
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user