Skip to content

Commit fb1f73a

Browse files
committed
fix(core): bubble up events from primitive children
1 parent d67e2a7 commit fb1f73a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

libs/core/src/lib/events.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,23 @@ export function createEvents(store: SignalState<NgtState>) {
160160
if (intersections.length) {
161161
const localState = { stopped: false };
162162
for (const hit of intersections) {
163-
const { raycaster, pointer, camera, internal } = getInstanceState(hit.object)?.store?.snapshot || rootState;
163+
let instanceState = getInstanceState(hit.object);
164+
165+
// If the object is not managed by NGT, it might be parented to an element which is.
166+
// Traverse upwards until we find a managed parent and use its state instead.
167+
if (!instanceState) {
168+
hit.object.traverseAncestors((ancestor) => {
169+
const parentInstanceState = getInstanceState(ancestor);
170+
if (parentInstanceState) {
171+
instanceState = parentInstanceState;
172+
return false;
173+
}
174+
return;
175+
});
176+
}
177+
178+
const { raycaster, pointer, camera, internal } = instanceState?.store?.snapshot || rootState;
179+
164180
const unprojectedPoint = new THREE.Vector3(pointer.x, pointer.y, 0).unproject(camera);
165181
const hasPointerCapture = (id: number) => internal.capturedMap.get(id)?.has(hit.eventObject) ?? false;
166182

0 commit comments

Comments
 (0)