|
1 | 1 | --- |
2 | 2 | id: migrate |
3 | | -title: Migrate to Angular Three (WIP) |
4 | | -sidebar_label: Migrate to Angular Three (WIP) |
| 3 | +title: Migrate to V2 |
| 4 | +sidebar_label: Migrate to V2 |
5 | 5 | --- |
6 | 6 |
|
7 | | -## Packages |
| 7 | +Angular Three v2 is utilizing [Angular Signals](https://angular.io/guide/signals) under the hood so there are some fundamental changes |
| 8 | +as to how things work |
8 | 9 |
|
9 | | -NGT is now distributed via `angular-three` (and auxiliary packages like `angular-three-soba` or `angular-three-cannon`) instead of `@angular-three/*` |
| 10 | +### `NgtStore` |
10 | 11 |
|
11 | | -```shell |
12 | | -npx ng add angular-three |
13 | | -npx ng add angular-three-soba |
14 | | -npx ng add angular-three-cannon |
15 | | -... |
16 | | -``` |
17 | | - |
18 | | -## Canvas |
19 | | - |
20 | | -The Scene Graph now has to be in a separate component instead of inline as Content Child to the `NgtCanvas`. |
21 | | - |
22 | | -```html title="app.component.html" |
23 | | -<!-- before --> |
24 | | -<ngt-canvas> |
25 | | - <ng-template> |
26 | | - <ngt-mesh></ngt-mesh> |
27 | | - </ng-template> |
28 | | -</ngt-canvas> |
29 | | -``` |
30 | | - |
31 | | -```html title="app.component.html" |
32 | | -<!-- after --> |
33 | | -<ngt-canvas [sceneGraph]="Scene" /> |
34 | | -``` |
| 12 | +`NgtStore` utilizes Signal APIs that returns reactive properties as `Signal<Type>` instead of `Observable<Type>`. Check out [Store](../api/store) for more information |
35 | 13 |
|
36 | | -where `Scene` is a reference to the component with our Scene graph. |
| 14 | +```ts |
| 15 | +export class Scene { |
| 16 | + readonly #store = inject(NgtStore); |
37 | 17 |
|
38 | | -```ts title="app.component.ts" |
39 | | -@Component({ |
40 | | - standalone: true, |
41 | | - template: ` <ngt-mesh></ngt-mesh> `, |
42 | | - schemas: [CUSTOM_ELEMENTS_SCHEMA], |
43 | | -}) |
44 | | -export class SceneComponent {} |
| 18 | + // before |
| 19 | + readonly camera$ = this.#store.select('camera'); // Observable<NgtCamera> |
| 20 | + readonly glDom$ = this.#store.select('gl', 'domElement'); // Observable<HTMLElement> |
| 21 | + readonly orbitControlsArgs$ = combineLatest([this.camera$, this.glDom$]); // Observable<[NgtCamera, HTMLElement]> |
45 | 22 |
|
46 | | -@Component({ |
47 | | - standalone: true, |
48 | | - templateUrl: 'app.component.html', |
49 | | - imports: [NgtCanvas], |
50 | | -}) |
51 | | -export class AppComponent { |
52 | | - readonly Scene = SceneComponent; |
| 23 | + // after |
| 24 | + readonly #camera = this.#store.select('camera'); // Signal<NgtCamera> |
| 25 | + readonly #glDom = this.#store.select('gl', 'domElement'); // Signal<HTMLElement> |
| 26 | + readonly orbitControlsArgs = computed(() => [this.#camera(), this.#glDom()]); // Signal<[NgtCamera, HTMLElement]> |
53 | 27 | } |
54 | 28 | ``` |
55 | 29 |
|
56 | | -:::info |
| 30 | +### `NgtPush` |
57 | 31 |
|
58 | | -Check out [First Scene](../getting-started/first-scene) for better explanation |
| 32 | +With Signals, we do not need `NgtPush` pipe anymore so this pipe is removed |
59 | 33 |
|
60 | | -::: |
61 | | - |
62 | | -## Store |
63 | | - |
64 | | -`angular-three` has migrated to [RxAngular](https://www.rx-angular.io/) instead of [NgRx](https://ngrx.io) for our internal states. |
65 | | - |
66 | | -:::info |
67 | | - |
68 | | -Check out [Store](../api/store) for more info |
69 | | - |
70 | | -::: |
| 34 | +```html |
| 35 | +<!-- before --> |
| 36 | +<ngt-primitive *args="[model$ | push]" /> |
| 37 | +<!-- after --> |
| 38 | +<ngt-primitive *args="[model()]" /> |
| 39 | +``` |
0 commit comments