Skip to content

Commit 79b5b60

Browse files
committed
fix(core): skip invisible objects before intersectObject
1 parent 729cdc1 commit 79b5b60

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

libs/core/src/lib/events.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ export function createEvents(store: SignalState<NgtState>) {
140140
if (objState.raycaster.camera === undefined) objState.raycaster.camera = null!;
141141
}
142142

143+
// skip invisible objects
144+
let currentObj: THREE.Object3D | null = obj;
145+
while (currentObj) {
146+
if (!currentObj.visible) return [];
147+
currentObj = currentObj.parent;
148+
}
149+
143150
// Intersect object by object
144151
return objState.raycaster.camera ? objState.raycaster.intersectObject(obj, true) : [];
145152
}

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)