@@ -6,13 +6,96 @@ sidebar_label: First Scene
6
6
7
7
This tutorial will help us setup our first NGT scene and introduce us to some of its core concepts.
8
8
9
+ :::note
10
+
11
+ - We are using Inline Template syntax for this tutorial
12
+ - We will put everything in ` app.component.ts ` for simplicity
13
+
14
+ :::
15
+
16
+ ## Create a root component for our Scene graph
17
+
18
+ Let's start by creating a Component as the root of our Scene graph. We'll put the component in ` app.component.ts ` for now
19
+
20
+ ``` ts title="app.component.ts"
21
+ import { Component , CUSTOM_ELEMENTS_SCHEMA } from ' @angular/core' ;
22
+
23
+ @Component ({
24
+ standalone: true ,
25
+ template: ` ` ,
26
+ schemas: [CUSTOM_ELEMENTS_SCHEMA ],
27
+ })
28
+ export class SceneGraph {}
29
+
30
+ @Component ({
31
+ /* ...*/
32
+ })
33
+ export class AppComponent {}
34
+ ```
35
+
36
+ - The ` template ` is intentionally left empty, we'll fill it out later.
37
+ - The ` selector ` is intentionally left out because we'll not render our ` SceneGraph ` component on the template.
38
+ - ` CUSTOM_ELEMENTS_SCHEMA ` is required because Angular does not support custom schemas so our Custom Elements won't work without it.
39
+
9
40
## Set up the Canvas
10
41
11
- The scene graph in NGT starts with ` <ngt-canvas> ` . Let's start by rendering ` <ngt-canvas> ` on our ` app.component.ts ` .
42
+ The scene graph in NGT starts with ` <ngt-canvas> ` . Let's render ` <ngt-canvas> ` on our ` app.component.ts ` template .
12
43
Make sure to import ` NgtCanvas ` from ` angular-three `
13
44
14
- :::note
45
+ ``` ts title="app.component.ts"
46
+ import { Component , CUSTOM_ELEMENTS_SCHEMA } from ' @angular/core' ;
47
+ // highlight-next-line
48
+ import { NgtCanvas } from ' angular-three' ;
49
+
50
+ @Component ({
51
+ /* ...*/
52
+ })
53
+ export class SceneGraph {}
54
+
55
+ @Component ({
56
+ selector: ' app-root' ,
57
+ standalone: true ,
58
+ // highlight-start
59
+ template: ` <ngt-canvas [sceneGraph]="SceneGraph" /> ` ,
60
+ imports: [NgtCanvas ],
61
+ // highlight-end
62
+ })
63
+ export class AppComponent {
64
+ // highlight-next-line
65
+ readonly SceneGraph = SceneGraph ;
66
+ }
67
+ ```
68
+
69
+ - ` <ngt-canvas> ` has a ** required** input ` [sceneGraph] ` which accepts a Component class. We pass our ` SceneGraph ` component into that input.
70
+
71
+ ` ngt-canvas ` sets up the following:
72
+
73
+ - A ` WebGLRenderer ` , a default ` Scene ` , and a default ` PerspectiveCamera `
74
+ - A render loop that renders our scene evere frame outside of Angular Zone
75
+ - A ` window:resize ` listener that updates our Renderer and Camera when the viewport is resized
76
+
77
+ ` ngt-canvas ` renders the ` SceneGraph ` input in a _ detached_ environment from Angular Change Detection. It also provides the custom Angular Renderer
78
+ to render THREE.js entities instead of DOM elements.
79
+
80
+ Next, we'll set some basic styles in ` styles.css `
81
+
82
+ ``` css title="style.css"
83
+ html ,
84
+ body {
85
+ height : 100% ;
86
+ width : 100% ;
87
+ margin : 0 ;
88
+ }
89
+ ```
90
+
91
+ :::tip
92
+
93
+ ` ngt-canvas ` is designed to fit the parent container so we can control our 3D scene by adjusting the parent's dimensions.
15
94
16
- We are using Inline Template syntax for this tutorial
95
+ ``` html
96
+ <div class =" canvas-container" >
97
+ <ngt-canvas [sceneGraph] =" ..." />
98
+ </div >
99
+ ```
17
100
18
101
:::
0 commit comments