Skip to content

Commit 52fe340

Browse files
committed
fix(core): rename selection apis
1 parent 7fd7825 commit 52fe340

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

apps/examples/src/app/postprocessing/outline/scene.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';
2-
import { NgtArgs, NgtSelect, NgtSelection } from 'angular-three';
2+
import { NgtArgs, NgtSelection, NgtSelectionApi } from 'angular-three';
33
import { NgtpEffectComposer, NgtpOutline, NgtpSMAA } from 'angular-three-postprocessing';
44
import { NgtsOrbitControls } from 'angular-three-soba/controls';
55
import { KernelSize } from 'postprocessing';
66

77
/**
88
* There are multiple ways to use the Outline effect.
99
*
10-
* 1. Via NgtSelection and NgtSelect
10+
* 1. Via NgtSelectionApi and NgtSelect
1111
* This is the recommended way to use the Outline effect.
1212
*
13-
* 1a. We can use NgtSelection as hostDirective (as shown) to enable Selection on the entire scene.
13+
* 1a. We can use NgtSelectionApi as hostDirective (as shown) to enable Selection on the entire scene.
1414
* NgtpOutline will automatically be aware of the NgtSelection context and will use it for the selected objects.
1515
*
16-
* 1b. We can wrap `<ng-container ngtSelection>` around the objects we want to select AS WELL AS the Outline effect.
16+
* 1b. We can wrap `<ng-container selection>` around the objects we want to select AS WELL AS the Outline effect.
17+
* When using this approach, you can use `NgtSelection` in the imports array instead of [NgtSelectionApi, NgtSelect].
1718
*
18-
* ngtSelect can be used on ngt-group or ngt-mesh. ngt-group will select all children, ngt-mesh will only select itself.
19+
* select can be used on ngt-group or ngt-mesh. ngt-group will select all children, ngt-mesh will only select itself.
1920
*
2021
* 2. Via selection input on NgtpOutline
2122
* If we want to control the selection ourselves, we can pass in the selection input an Array of Object3D or ElementRef<Object3D>
@@ -36,7 +37,7 @@ import { KernelSize } from 'postprocessing';
3637
<ngt-point-light [position]="[0, -1, -1]" [decay]="0" color="green" />
3738
<ngt-directional-light [position]="[0, 1, 1]" />
3839
39-
<ngt-group [ngtSelect]="hovered()" (pointerenter)="hovered.set(true)" (pointerleave)="hovered.set(false)">
40+
<ngt-group [select]="hovered()" (pointerenter)="hovered.set(true)" (pointerleave)="hovered.set(false)">
4041
<ngt-mesh>
4142
<ngt-box-geometry />
4243
<ngt-mesh-standard-material color="hotpink" />
@@ -59,8 +60,8 @@ import { KernelSize } from 'postprocessing';
5960
schemas: [CUSTOM_ELEMENTS_SCHEMA],
6061
changeDetection: ChangeDetectionStrategy.OnPush,
6162
host: { class: 'postprocessing-sample' },
62-
hostDirectives: [NgtSelection],
63-
imports: [NgtsOrbitControls, NgtSelect, NgtpEffectComposer, NgtpOutline, NgtArgs, NgtpSMAA],
63+
hostDirectives: [NgtSelectionApi],
64+
imports: [NgtsOrbitControls, NgtSelection, NgtpEffectComposer, NgtpOutline, NgtArgs, NgtpSMAA],
6465
})
6566
export class SceneGraph {
6667
protected KernelSize = KernelSize;

libs/core/src/lib/directives/selection.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { booleanAttribute, Directive, effect, ElementRef, inject, input, signal,
22
import { Group, Mesh, Object3D } from 'three';
33
import { getInstanceState } from '../instance';
44

5-
@Directive({ selector: '[ngtSelection]' })
6-
export class NgtSelection {
7-
enabled = input(true, { alias: 'ngtSelection', transform: booleanAttribute });
5+
@Directive({ selector: '[selection]' })
6+
export class NgtSelectionApi {
7+
enabled = input(true, { alias: 'selection', transform: booleanAttribute });
88

99
private source = signal<Array<ElementRef<Object3D> | Object3D>>([]);
1010
selected = this.source.asReadonly();
@@ -15,16 +15,16 @@ export class NgtSelection {
1515
}
1616
}
1717

18-
@Directive({ selector: 'ngt-group[ngtSelect], ngt-mesh[ngtSelect]' })
18+
@Directive({ selector: 'ngt-group[select], ngt-mesh[select]' })
1919
export class NgtSelect {
20-
enabled = input(false, { transform: booleanAttribute, alias: 'ngtSelect' });
20+
enabled = input(false, { transform: booleanAttribute, alias: 'select' });
2121

2222
constructor() {
2323
const elementRef = inject<ElementRef<Group | Mesh>>(ElementRef);
24-
const selection = inject(NgtSelection);
24+
const selectionApi = inject(NgtSelectionApi);
2525

2626
effect((onCleanup) => {
27-
const selectionEnabled = selection.enabled();
27+
const selectionEnabled = selectionApi.enabled();
2828
if (!selectionEnabled) return;
2929

3030
const enabled = this.enabled();
@@ -36,14 +36,14 @@ export class NgtSelect {
3636
const localState = getInstanceState(host);
3737
if (!localState) return;
3838

39-
// ngt-mesh[ngtSelect]
39+
// ngt-mesh[select]
4040
if (host.type === 'Mesh') {
41-
selection.update((prev) => [...prev, host]);
42-
onCleanup(() => selection.update((prev) => prev.filter((el) => el !== host)));
41+
selectionApi.update((prev) => [...prev, host]);
42+
onCleanup(() => selectionApi.update((prev) => prev.filter((el) => el !== host)));
4343
return;
4444
}
4545

46-
const [collection] = [untracked(selection.selected), localState.objects()];
46+
const [collection] = [untracked(selectionApi.selected), localState.objects()];
4747
let changed = false;
4848
const current: Object3D[] = [];
4949
host.traverse((child) => {
@@ -53,10 +53,12 @@ export class NgtSelect {
5353

5454
if (!changed) return;
5555

56-
selection.update((prev) => [...prev, ...current]);
56+
selectionApi.update((prev) => [...prev, ...current]);
5757
onCleanup(() => {
58-
selection.update((prev) => prev.filter((el) => !current.includes(el as Object3D)));
58+
selectionApi.update((prev) => prev.filter((el) => !current.includes(el as Object3D)));
5959
});
6060
});
6161
}
6262
}
63+
64+
export const NgtSelection = [NgtSelectionApi, NgtSelect] as const;

0 commit comments

Comments
 (0)