Skip to content

Commit 7683d93

Browse files
authored
fix(core): skip invisible objects before intersectObject (#81)
1 parent 6664d5e commit 7683d93

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

libs/core/src/lib/events.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,19 @@ export function createEvents(store: SignalState<NgtState>) {
105105
const duplicates = new Set<string>();
106106
const intersections: NgtIntersection[] = [];
107107
// Allow callers to eliminate event objects
108-
const eventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
108+
const allEventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
109+
110+
// filter out invisible objects
111+
const eventsObjects: THREE.Object3D[] = [];
112+
for (const eventsObject of allEventsObjects) {
113+
let current: THREE.Object3D | null = eventsObject;
114+
while (current) {
115+
if (!current.visible) break;
116+
current = current.parent;
117+
}
118+
119+
if (!current) eventsObjects.push(eventsObject);
120+
}
109121

110122
if (!state.previousRoot) {
111123
// Make sure root-level pointer and ray are set up

libs/soba/src/performances/detailed.stories.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ import { NgtsOrbitControls } from 'angular-three-soba/controls';
55
import { NgtsDetailed } from 'angular-three-soba/performances';
66
import { storyDecorators, storyFunction } from '../setup-canvas';
77

8+
@Component({
9+
template: `
10+
<ngts-detailed [distances]="[0, 50]">
11+
<ngt-group>
12+
<ngt-mesh (pointermove)="onHover()">
13+
<ngt-icosahedron-geometry *args="[10, 3]" />
14+
<ngt-mesh-basic-material color="hotpink" wireframe />
15+
</ngt-mesh>
16+
</ngt-group>
17+
18+
<ngt-mesh>
19+
<ngt-icosahedron-geometry *args="[10, 1]" />
20+
<ngt-mesh-basic-material color="lightblue" wireframe />
21+
</ngt-mesh>
22+
</ngts-detailed>
23+
24+
<ngts-orbit-controls [options]="{ enablePan: false, enableRotate: false, zoomSpeed: 0.5 }" />
25+
`,
26+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
27+
changeDetection: ChangeDetectionStrategy.OnPush,
28+
imports: [NgtsDetailed, NgtArgs, NgtsOrbitControls],
29+
})
30+
class WithEventDetailedStory {
31+
protected onHover() {
32+
console.log('hovered');
33+
}
34+
}
35+
836
@Component({
937
template: `
1038
<ngts-detailed [distances]="[0, 50, 150]">
@@ -41,3 +69,8 @@ export const Default = storyFunction(DefaultDetailedStory, {
4169
camera: { position: [0, 0, 100] },
4270
controls: false,
4371
});
72+
73+
export const WithEvent = storyFunction(WithEventDetailedStory, {
74+
camera: { position: [0, 0, 100] },
75+
controls: false,
76+
});

0 commit comments

Comments
 (0)