Skip to content

Commit cd0d275

Browse files
committed
feat: add sceneGraphInputs
1 parent 599f67d commit cd0d275

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

apps/documentation/docs/api/canvas.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The root of a NGT 3D scene is the `NgtCanvas` component
1515
| name | description | type | default |
1616
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------ |
1717
| **sceneGraph** | **(required)** A component that will be rendered as the Root THREE.Scene | `Type<any>` | |
18+
| sceneGraphInputs | An object that will be used as Inputs for the `sceneGraph` component | `Record<string, any>` | `{}` |
1819
| compoundPrefixes | An array of prefixes of HTML tags that NGT will treat as [Compound](../advanced/compound) | `string[]` | `[]` |
1920
| gl | A THREE.js Renderer instance of options that go into the default Renderer. It also accepts a callback that returns a THREE.js Renderer instance | `NgtGLOptions` | - |
2021
| size | Dimensions to fit the THREE.js Renderer to. Will measure `<canvas>` dimentions if omitted | `NgtSize` | - |

libs/angular-three/src/lib/canvas.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
HostBinding,
1010
inject,
1111
Input,
12+
OnChanges,
1213
OnDestroy,
1314
OnInit,
1415
Output,
16+
SimpleChanges,
1517
Type,
1618
ViewChild,
1719
ViewContainerRef,
@@ -22,7 +24,7 @@ import { injectNgtLoader } from './loader';
2224
import { provideNgtRenderer } from './renderer/provider';
2325
import { NgtRxStore } from './stores/rx-store';
2426
import { NgtStore, rootStateMap } from './stores/store';
25-
import type { NgtCanvasInputs, NgtDomEvent, NgtDpr, NgtState } from './types';
27+
import type { NgtAnyRecord, NgtCanvasInputs, NgtDomEvent, NgtDpr, NgtState } from './types';
2628
import { is } from './utils/is';
2729
import { createPointerEvents } from './web/events';
2830

@@ -48,7 +50,7 @@ import { createPointerEvents } from './web/events';
4850
`,
4951
],
5052
})
51-
export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, OnDestroy {
53+
export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, OnDestroy, OnChanges {
5254
private readonly cdr = inject(ChangeDetectorRef);
5355
private readonly envInjector = inject(EnvironmentInjector);
5456
private readonly host = inject(ElementRef) as ElementRef<HTMLElement>;
@@ -74,6 +76,7 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
7476
}
7577

7678
@Input() sceneGraph!: Type<any>;
79+
@Input() sceneGraphInputs: NgtAnyRecord = {};
7780
@Input() compoundPrefixes: string[] = [];
7881

7982
@Input() set linear(linear: boolean) {
@@ -143,6 +146,12 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
143146
private glRef?: ComponentRef<unknown>;
144147
private glEnvInjector?: EnvironmentInjector;
145148

149+
ngOnChanges(changes: SimpleChanges) {
150+
if (changes['sceneGraphInputs'] && this.glRef) {
151+
this.setSceneGraphInputs();
152+
}
153+
}
154+
146155
ngOnInit() {
147156
if (!this.get('eventSource')) {
148157
// set default event source to the host element
@@ -222,6 +231,7 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
222231
environmentInjector: this.glEnvInjector,
223232
});
224233
this.glRef.changeDetectorRef.detach();
234+
this.setSceneGraphInputs();
225235

226236
// here, we override the detectChanges to also call detectChanges on the ComponentRef
227237
this.overrideDetectChanges();
@@ -243,4 +253,11 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
243253
this.glRef?.changeDetectorRef.detectChanges();
244254
};
245255
}
256+
257+
private setSceneGraphInputs() {
258+
for (const key of Object.keys(this.sceneGraphInputs)) {
259+
this.glRef?.setInput(key, this.sceneGraphInputs[key]);
260+
}
261+
this.cdr.detectChanges();
262+
}
246263
}

0 commit comments

Comments
 (0)