angular-three 4.0.0-next.47 → 4.0.0-next.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +38 -183
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,32 +1,31 @@
1
1
  # `angular-three`
2
2
 
3
- A custom Renderer for Angular 18+ that uses Three.js to render 3D scenes.
3
+ A custom Renderer for Angular 19+ that uses Three.js to render 3D scenes.
4
4
 
5
- ## Compatibility
5
+ ## Official documentation
6
6
 
7
- Angular Three v2 is still in beta and aims to be compatible with Angular 17+.
7
+ Please visit [angularthree-docs-next](https://angularthree-docs-next.netlify.app)
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- npm install angular-three@beta ngxtension three
13
- # yarn add angular-three@beta ngxtension three
14
- # pnpm add angular-three@beta ngxtension three
12
+ npm install -D angular-three-plugin@next
13
+ npx ng generate angular-three-plugin:init
15
14
  ```
16
15
 
17
- > Make sure to install `@types/three` as well
18
-
19
16
  ## Usage
20
17
 
18
+ - Create a `SceneGraph` component for your 3D scene graph
19
+
21
20
  ```typescript
22
21
  import { extend } from 'angular-three';
23
22
  import { Mesh, BoxGeometry } from 'three';
24
23
 
25
24
  extend({
26
- Mesh, // makes ngt-mesh available
27
- BoxGeometry, // makes ngt-box-geometry available
28
- /* ... */
29
- MyMesh: Mesh, // makes ngt-my-mesh available
25
+ Mesh, // makes ngt-mesh available
26
+ BoxGeometry, // makes ngt-box-geometry available
27
+ /* ... */
28
+ MyMesh: Mesh, // makes ngt-my-mesh available
30
29
  });
31
30
 
32
31
  // alternatively for demo purposes, you can use the following
@@ -34,189 +33,45 @@ extend({
34
33
  // This includes the entire THREE.js namespace
35
34
 
36
35
  @Component({
37
- // This Component is rendered in the Custom Renderer
38
- template: `
39
- <ngt-mesh>
40
- <ngt-box-geometry />
41
- </ngt-mesh>
42
- `,
43
- schemas: [CUSTOM_ELEMENTS_SCHEMA], // required
44
- changeDetection: ChangeDetectionStrategy.OnPush,
36
+ selector: 'app-scene-graph',
37
+ template: `
38
+ <ngt-mesh>
39
+ <ngt-box-geometry />
40
+ </ngt-mesh>
41
+ `,
42
+ schemas: [CUSTOM_ELEMENTS_SCHEMA], // required
43
+ changeDetection: ChangeDetectionStrategy.OnPush,
45
44
  })
46
45
  export class SceneGraph {}
47
-
48
- @Component({
49
- // This Component is rendered normally in Angular.
50
- selector: 'app-my-experience',
51
- template: `
52
- <ngt-canvas [sceneGraph]="SceneGraph" />
53
- `,
54
- imports: [NgtCanvas],
55
- })
56
- export class MyExperience {
57
- SceneGraph = SceneGraph;
58
- }
59
- ```
60
-
61
- > The Component that renders `NgtCanvas` (`MyExperience` in this case) controls the dimensions of the canvas so make sure to style it accordingly.
62
-
63
- ### Inputs
64
-
65
- - `sceneGraph: Type<any>`: **required**. This is the Component that renders your 3D Scene graph. It must be a standalone Component.
66
- - `gl?: NgtGLOptions`: This input allows you to configure the WebGL renderer used by Angular Three. You can provide a THREE.js renderer instance, properties for the default renderer, or a function that returns a renderer based on the canvas element.
67
- - `size?: NgtSize`: Specifies the dimensions of the renderer. If omitted, the component will automatically measure the canvas dimensions.
68
- - `shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<WebGLShadowMap>`: Enables or disables shadows in the scene. You can provide a boolean value to toggle shadows on or off, or use specific strings to control the shadow type. Additionally, you can pass partial WebGLShadowMap options for fine-tuning.
69
- - `legacy?: boolean`: Disables three r139 color management when set to true.
70
- - `linear?: boolean`: Switches off automatic sRGB color space and gamma correction when set to true.
71
- - `flat?: boolean`: Uses THREE.NoToneMapping instead of THREE.ACESFilmicToneMapping when set to true.
72
- - `orthographic?: boolean`: Creates an orthographic camera instead of a perspective camera when set to true.
73
- - `frameloop?: 'always' | 'demand' | 'never'`: Controls the rendering mode. 'always' renders continuously, 'demand' renders only on state changes, and 'never' gives you manual control over rendering.
74
- - `performance?: Partial<Omit<NgtPerformance, 'regress'>>`: Allows you to configure performance options for adaptive performance.
75
- - `dpr?: NgtDpr`: Sets the target pixel ratio. You can provide a single number or a range [min, max].
76
- - `raycaster?: Partial<Raycaster>`: Configures the default raycaster used for interaction.
77
- - `scene?: Scene | Partial<Scene>`: Provides a THREE.js scene instance or properties to create a default scene.
78
- - `camera?: NgtCamera | Partial<NgtObject3DNode<Camera>>`: Provides a THREE.js camera instance or properties to create a default camera. You can also set the manual property to true to take control of the camera projection.
79
- - `events?: (store: NgtSignalStore<NgtState>) => NgtEventManager<HTMLElement>`: Allows you to customize the event manager for handling pointer events.
80
- - `eventSource?: HTMLElement | ElementRef<HTMLElement>`: Specifies the target element where events are subscribed. By default, it's the div wrapping the canvas.
81
- - `eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'`: Sets the event prefix used for canvas pointer events.
82
- - `lookAt?: Vector3 | Parameters<Vector3['set']>`: Defines the default coordinate for the camera to look at.
83
-
84
- ### Outputs
85
-
86
- - `created`: Emitted when the canvas is created.
87
- - `pointerMissed`: Emitted when a pointer event is not captured by any element (aka clicking on the canvas)
88
-
89
- ## Intellisense support
90
-
91
- Since Angular Three is a custom Renderer, the elements are not recognized by the Angular Language Service.
92
-
93
- ### Jetbrains IDE
94
-
95
- The consumers can add `web-types` property to the workspace's `package.json` and set the value to `node_modules/angular-three/web-types.json`.
96
-
97
- ```json
98
- {
99
- "web-types": "node_modules/angular-three/web-types.json"
100
- }
101
- ```
102
-
103
- ### VSCode
104
-
105
- Similarly, there's `node_modules/angular-three/metadata.json` file that can be used to provide intellisense support for VSCode users.
106
-
107
- The consumers can enable it via `html.customData` in their `settings.json` file.
108
-
109
- ```json
110
- {
111
- "html.customData": ["node_modules/angular-three/metadata.json"]
112
- }
113
- ```
114
-
115
- ## Input Bindings
116
-
117
- Input bindings for `ngt-*` elements work the same way as they do in Angular.
118
-
119
- > You can consult THREE.js documentation on what is available on the entities
120
-
121
- ```html
122
- <ngt-mesh [position]="[x, y, z]" [rotation]="[x, y, z]">
123
- <ngt-mesh-basic-material color="hotpink" />
124
- </ngt-mesh>
125
46
  ```
126
47
 
127
- ## Events
128
-
129
- Angular Three Custom Renderer supports the following events on applicable objects (`ngt-mesh`, `ngt-group` etc...)
130
-
131
- ```
132
- 'click',
133
- 'contextmenu',
134
- 'dblclick',
135
- 'pointerup',
136
- 'pointerdown',
137
- 'pointerover',
138
- 'pointerout',
139
- 'pointerenter',
140
- 'pointerleave',
141
- 'pointermove',
142
- 'pointermissed',
143
- 'pointercancel',
144
- 'wheel',
145
- ```
146
-
147
- In addition, there are 2 special events that the consumers can listen to;
148
-
149
- - `attached`: when the element is attached to its parent
150
- - `updated`: when the element properties are updated
151
-
152
- ## Constructor Arguments
153
-
154
- In THREE.js, there are some entities that require the consumers to dispose and recreate them if their parameters change; like the Geometries.
155
-
156
- To handle this, Angular Three exports a `NgtArgs` structural directive that always accepts an Array of values. The consumers can consult THREE.js documentations to know what values are applicable for what entities and their order.
157
-
158
- ```html
159
- <!-- for example, new BoxGeometry(width, height, depth) -->
160
- <ngt-box-geometry *args="[width, height, depth]" />
161
- ```
162
-
163
- `NgtArgs`, as a structural directive, ensures to create a new instance of the entity when the value changes
164
-
165
- ## Parameters
166
-
167
- Beside the normal properties that `ngt-*` elements can accept for Input bindings, the consumers can also pass a `parameters` object to a special property `[parameters]` on the elements. This parameters object will be used to apply the properties on the entity.
168
-
169
- ```html
170
- <!-- instead of <ngt-mesh [position]="[x, y, z]" [scale]="scale" /> -->
171
- <ngt-mesh [parameters]="{ position: [x, y, z], scale }" />
172
- ```
173
-
174
- ## Element Queries
175
-
176
- The consumers can query for the THREE.js entities like they would do in normal HTML Angular Template.
48
+ - Render the `SceneGraph` with `NgtCanvas`
177
49
 
178
50
  ```ts
179
- @Component({
180
- template: `
181
- <ngt-mesh #mesh></ngt-mesh>
182
- `,
183
- })
184
- export class Box {
185
- mesh = viewChild.required<ElementRef<Mesh>>('mesh');
186
- // notice that it is an ElementRef of THREE.Mesh instead of an HTMLElement
187
- }
188
- ```
51
+ import { NgtCanvas } from 'angular-three/dom';
52
+ import { SceneGraph } from './scene-graph';
189
53
 
190
- ## Animation Loop
191
-
192
- In order to participate in the animation loop, use `injectBeforeRender` inject function
193
-
194
- ```ts
195
54
  @Component({
196
- /*...*/
55
+ // This Component is rendered normally in Angular.
56
+ selector: 'app-my-experience',
57
+ template: `
58
+ <ngt-canvas>
59
+ <app-scene-graph *canvasContent />
60
+ </ngt-canvas>
61
+ `,
62
+ imports: [NgtCanvas],
197
63
  })
198
- export class Box {
199
- mesh = viewChild.required<ElementRef<Mesh>>('mesh');
200
-
201
- constructor() {
202
- injectBeforeRender(() => {
203
- // runs every frame
204
- const mesh = this.mesh().nativeElement;
205
- mesh.rotation.x += 0.01;
206
- });
207
- }
208
- }
64
+ export class MyExperience {}
209
65
  ```
210
66
 
211
- ## Store
67
+ > The Component that renders `NgtCanvas` (`MyExperience` in this case) controls the dimensions of the canvas so make sure to style it accordingly.
212
68
 
213
- Angular Three keeps track of its state via an internal store. The consumers can access this store via the `injectStore` inject function
69
+ - Finally, provide the custom renderer in `bootstrapApplication`
214
70
 
215
71
  ```ts
216
- export class Box {
217
- store = injectStore();
218
- viewport = this.store.select('viewport'); // Signal<NgtViewport>
219
- camera = this.store.select('camera'); // Signal<NgtCamera> - the default camera
220
- /* many more properties */
221
- }
72
+ import { provideNgtRenderer } from 'angular-three/dom';
73
+
74
+ bootstrapApplication(AppComponent, {
75
+ providers: [provideNgtRenderer()],
76
+ });
222
77
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angular-three",
3
- "version": "4.0.0-next.47",
3
+ "version": "4.0.0-next.49",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },