3.7.2 • Published 3 months ago

angular-three v3.7.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

angular-three

A custom Renderer for Angular 18+ that uses Three.js to render 3D scenes.

Compatibility

Angular Three v2 is still in beta and aims to be compatible with Angular 17+.

Installation

npm install angular-three@beta ngxtension three
# yarn add angular-three@beta ngxtension three
# pnpm add angular-three@beta ngxtension three

Make sure to install @types/three as well

Usage

import { extend } from 'angular-three';
import { Mesh, BoxGeometry } from 'three';

extend({
 Mesh, // makes ngt-mesh available
 BoxGeometry, // makes ngt-box-geometry available
 /* ... */
 MyMesh: Mesh, // makes ngt-my-mesh available
});

// alternatively for demo purposes, you can use the following
// extend(THREE);
// This includes the entire THREE.js namespace

@Component({
 // This Component is rendered in the Custom Renderer
 template: `
  <ngt-mesh>
   <ngt-box-geometry />
  </ngt-mesh>
 `,
 schemas: [CUSTOM_ELEMENTS_SCHEMA], // required
 changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SceneGraph {}

@Component({
 // This Component is rendered normally in Angular.
 selector: 'app-my-experience',
 template: `
  <ngt-canvas [sceneGraph]="SceneGraph" />
 `,
 imports: [NgtCanvas],
})
export class MyExperience {
 SceneGraph = SceneGraph;
}

The Component that renders NgtCanvas (MyExperience in this case) controls the dimensions of the canvas so make sure to style it accordingly.

Inputs

  • sceneGraph: Type<any>: required. This is the Component that renders your 3D Scene graph. It must be a standalone Component.
  • 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.
  • size?: NgtSize: Specifies the dimensions of the renderer. If omitted, the component will automatically measure the canvas dimensions.
  • 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.
  • legacy?: boolean: Disables three r139 color management when set to true.
  • linear?: boolean: Switches off automatic sRGB color space and gamma correction when set to true.
  • flat?: boolean: Uses THREE.NoToneMapping instead of THREE.ACESFilmicToneMapping when set to true.
  • orthographic?: boolean: Creates an orthographic camera instead of a perspective camera when set to true.
  • 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.
  • performance?: Partial<Omit<NgtPerformance, 'regress'>>: Allows you to configure performance options for adaptive performance.
  • dpr?: NgtDpr: Sets the target pixel ratio. You can provide a single number or a range min, max.
  • raycaster?: Partial<Raycaster>: Configures the default raycaster used for interaction.
  • scene?: Scene | Partial<Scene>: Provides a THREE.js scene instance or properties to create a default scene.
  • 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.
  • events?: (store: NgtSignalStore<NgtState>) => NgtEventManager<HTMLElement>: Allows you to customize the event manager for handling pointer events.
  • eventSource?: HTMLElement | ElementRef<HTMLElement>: Specifies the target element where events are subscribed. By default, it's the div wrapping the canvas.
  • eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen': Sets the event prefix used for canvas pointer events.
  • lookAt?: Vector3 | Parameters<Vector3['set']>: Defines the default coordinate for the camera to look at.

Outputs

  • created: Emitted when the canvas is created.
  • pointerMissed: Emitted when a pointer event is not captured by any element (aka clicking on the canvas)

Intellisense support

Since Angular Three is a custom Renderer, the elements are not recognized by the Angular Language Service.

Jetbrains IDE

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.

{
 "web-types": "node_modules/angular-three/web-types.json"
}

VSCode

Similarly, there's node_modules/angular-three/metadata.json file that can be used to provide intellisense support for VSCode users.

The consumers can enable it via html.customData in their settings.json file.

{
 "html.customData": ["node_modules/angular-three/metadata.json"]
}

Input Bindings

Input bindings for ngt-* elements work the same way as they do in Angular.

You can consult THREE.js documentation on what is available on the entities

<ngt-mesh [position]="[x, y, z]" [rotation]="[x, y, z]">
 <ngt-mesh-basic-material color="hotpink" />
</ngt-mesh>

Events

Angular Three Custom Renderer supports the following events on applicable objects (ngt-mesh, ngt-group etc...)

'click',
'contextmenu',
'dblclick',
'pointerup',
'pointerdown',
'pointerover',
'pointerout',
'pointerenter',
'pointerleave',
'pointermove',
'pointermissed',
'pointercancel',
'wheel',

In addition, there are 2 special events that the consumers can listen to;

  • attached: when the element is attached to its parent
  • updated: when the element properties are updated

Constructor Arguments

In THREE.js, there are some entities that require the consumers to dispose and recreate them if their parameters change; like the Geometries.

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.

<!-- for example, new BoxGeometry(width, height, depth) -->
<ngt-box-geometry *args="[width, height, depth]" />

NgtArgs, as a structural directive, ensures to create a new instance of the entity when the value changes

Parameters

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.

<!-- instead of <ngt-mesh [position]="[x, y, z]" [scale]="scale" /> -->
<ngt-mesh [parameters]="{ position: [x, y, z], scale }" />

Element Queries

The consumers can query for the THREE.js entities like they would do in normal HTML Angular Template.

@Component({
 template: `
  <ngt-mesh #mesh></ngt-mesh>
 `,
})
export class Box {
 mesh = viewChild.required<ElementRef<Mesh>>('mesh');
 //  notice that it is an ElementRef of THREE.Mesh instead of an HTMLElement
}

Animation Loop

In order to participate in the animation loop, use injectBeforeRender inject function

@Component({
 /*...*/
})
export class Box {
 mesh = viewChild.required<ElementRef<Mesh>>('mesh');

 constructor() {
  injectBeforeRender(() => {
   // runs every frame
   const mesh = this.mesh().nativeElement;
   mesh.rotation.x += 0.01;
  });
 }
}

Store

Angular Three keeps track of its state via an internal store. The consumers can access this store via the injectStore inject function

export class Box {
 store = injectStore();
 viewport = this.store.select('viewport'); // Signal<NgtViewport>
 camera = this.store.select('camera'); // Signal<NgtCamera> - the default camera
 /* many more properties */
}
4.0.0-next.95

3 months ago

4.0.0-next.96

3 months ago

4.0.0-next.93

3 months ago

4.0.0-next.94

3 months ago

4.0.0-next.84

4 months ago

4.0.0-next.85

4 months ago

4.0.0-next.88

4 months ago

4.0.0-next.89

4 months ago

4.0.0-next.86

4 months ago

4.0.0-next.87

4 months ago

4.0.0-next.91

4 months ago

4.0.0-next.92

3 months ago

4.0.0-next.90

4 months ago

4.0.0-next.82

4 months ago

4.0.0-next.83

4 months ago

4.0.0-next.73

4 months ago

4.0.0-next.74

4 months ago

4.0.0-next.71

4 months ago

4.0.0-next.72

4 months ago

4.0.0-next.77

4 months ago

4.0.0-next.78

4 months ago

4.0.0-next.75

4 months ago

4.0.0-next.76

4 months ago

4.0.0-next.79

4 months ago

4.0.0-next.80

4 months ago

4.0.0-next.81

4 months ago

4.0.0-next.69

4 months ago

4.0.0-next.70

4 months ago

4.0.0-next.59

4 months ago

4.0.0-next.62

4 months ago

4.0.0-next.63

4 months ago

4.0.0-next.60

4 months ago

4.0.0-next.61

4 months ago

4.0.0-next.66

4 months ago

4.0.0-next.67

4 months ago

4.0.0-next.64

4 months ago

4.0.0-next.65

4 months ago

4.0.0-next.68

4 months ago

4.0.0-next.55

4 months ago

4.0.0-next.56

4 months ago

4.0.0-next.53

4 months ago

4.0.0-next.54

4 months ago

4.0.0-next.57

4 months ago

4.0.0-next.58

4 months ago

4.0.0-next.51

4 months ago

4.0.0-next.52

4 months ago

4.0.0-next.50

4 months ago

4.0.0-next.40

4 months ago

4.0.0-next.41

4 months ago

4.0.0-next.44

4 months ago

4.0.0-next.45

4 months ago

4.0.0-next.42

4 months ago

4.0.0-next.43

4 months ago

4.0.0-next.48

4 months ago

4.0.0-next.49

4 months ago

4.0.0-next.46

4 months ago

4.0.0-next.47

4 months ago

4.0.0-next.30

4 months ago

4.0.0-next.33

4 months ago

4.0.0-next.34

4 months ago

4.0.0-next.31

4 months ago

4.0.0-next.32

4 months ago

4.0.0-next.37

4 months ago

4.0.0-next.38

4 months ago

4.0.0-next.35

4 months ago

4.0.0-next.36

4 months ago

4.0.0-next.39

4 months ago

4.0.0-next.22

4 months ago

4.0.0-next.23

4 months ago

4.0.0-next.20

4 months ago

4.0.0-next.21

4 months ago

4.0.0-next.26

4 months ago

4.0.0-next.27

4 months ago

4.0.0-next.24

4 months ago

4.0.0-next.25

4 months ago

4.0.0-next.28

4 months ago

4.0.0-next.29

4 months ago

4.0.0-next.19

5 months ago

4.0.0-next.18

5 months ago

4.0.0-next.11

5 months ago

4.0.0-next.12

5 months ago

4.0.0-next.10

5 months ago

4.0.0-next.15

5 months ago

4.0.0-next.16

5 months ago

4.0.0-next.13

5 months ago

4.0.0-next.14

5 months ago

4.0.0-next.17

5 months ago

4.0.0-next.9

5 months ago

4.0.0-next.8

5 months ago

4.0.0-next.7

5 months ago

4.0.0-next.6

5 months ago

4.0.0-next.5

5 months ago

4.0.0-next.4

5 months ago

4.0.0-next.3

5 months ago

4.0.0-next.2

5 months ago

3.7.1

5 months ago

3.7.2

5 months ago

4.0.0-next.1

5 months ago

3.7.0

5 months ago

3.6.1

5 months ago

3.2.2

6 months ago

3.2.1

6 months ago

3.2.4

6 months ago

3.2.3

6 months ago

3.6.0

5 months ago

3.5.0

6 months ago

3.4.0

6 months ago

3.4.1

6 months ago

3.3.0

6 months ago

3.2.0

6 months ago

3.1.0

6 months ago

3.0.0

6 months ago

2.14.0

6 months ago

2.13.0

6 months ago

2.11.0

7 months ago

2.10.1

7 months ago

2.10.2

7 months ago

2.10.7

7 months ago

2.10.5

7 months ago

2.10.6

7 months ago

2.10.3

7 months ago

2.10.4

7 months ago

2.12.0

7 months ago

2.10.0

7 months ago

2.9.0

7 months ago

2.8.1

7 months ago

2.8.0

7 months ago

2.7.0

8 months ago

2.6.1

8 months ago

2.6.0

8 months ago

2.5.2

8 months ago

2.4.0

9 months ago

2.5.0

9 months ago

2.5.1

9 months ago

2.3.0

9 months ago

2.3.2

9 months ago

2.2.1

9 months ago

2.2.0

10 months ago

2.0.0-beta.316

10 months ago

2.1.0

10 months ago

2.0.0

10 months ago

2.0.0-beta.314

10 months ago

2.0.0-beta.315

10 months ago

2.0.0-beta.307

10 months ago

2.0.0-beta.308

10 months ago

2.0.0-beta.309

10 months ago

2.0.0-beta.310

10 months ago

2.0.0-beta.311

10 months ago

2.0.0-beta.312

10 months ago

2.0.0-beta.313

10 months ago

2.0.0-beta.300

11 months ago

2.0.0-beta.301

11 months ago

2.0.0-beta.302

11 months ago

2.0.0-beta.303

11 months ago

2.0.0-beta.304

11 months ago

2.0.0-beta.305

11 months ago

2.0.0-beta.306

11 months ago

2.0.0-beta.296

11 months ago

2.0.0-beta.297

11 months ago

2.0.0-beta.298

11 months ago

2.0.0-beta.299

11 months ago

2.0.0-beta.290

11 months ago

2.0.0-beta.291

11 months ago

2.0.0-beta.292

11 months ago

2.0.0-beta.293

11 months ago

2.0.0-beta.294

11 months ago

2.0.0-beta.295

11 months ago

2.0.0-beta.285

11 months ago

2.0.0-beta.286

11 months ago

2.0.0-beta.287

11 months ago

2.0.0-beta.288

11 months ago

2.0.0-beta.289

11 months ago

2.0.0-beta.284

11 months ago

2.0.0-beta.278

11 months ago

2.0.0-beta.279

11 months ago

2.0.0-beta.280

11 months ago

2.0.0-beta.281

11 months ago

2.0.0-beta.282

11 months ago

2.0.0-beta.283

11 months ago

2.0.0-beta.274

11 months ago

2.0.0-beta.275

11 months ago

2.0.0-beta.276

11 months ago

2.0.0-beta.277

11 months ago

2.0.0-beta.271

11 months ago

2.0.0-beta.272

11 months ago

2.0.0-beta.273

11 months ago

2.0.0-beta.268

11 months ago

2.0.0-beta.269

11 months ago

2.0.0-beta.270

11 months ago

2.0.0-beta.265

11 months ago

2.0.0-beta.266

11 months ago

2.0.0-beta.267

11 months ago

2.0.0-beta.231

1 year ago

2.0.0-beta.232

1 year ago

2.0.0-beta.233

1 year ago

2.0.0-beta.234

1 year ago

2.0.0-beta.235

1 year ago

2.0.0-beta.236

1 year ago

2.0.0-beta.237

1 year ago

2.0.0-beta.238

1 year ago

2.0.0-beta.239

1 year ago

2.0.0-beta.241

1 year ago

2.0.0-beta.242

1 year ago

2.0.0-beta.243

12 months ago

2.0.0-beta.244

12 months ago

2.0.0-beta.245

12 months ago

2.0.0-beta.246

12 months ago

2.0.0-beta.247

12 months ago

2.0.0-beta.248

12 months ago

2.0.0-beta.240

1 year ago

2.0.0-beta.249

12 months ago

2.0.0-beta.252

12 months ago

2.0.0-beta.253

12 months ago

2.0.0-beta.254

12 months ago

2.0.0-beta.255

12 months ago

2.0.0-beta.256

12 months ago

2.0.0-beta.257

12 months ago

2.0.0-beta.258

11 months ago

2.0.0-beta.259

11 months ago

2.0.0-beta.250

12 months ago

2.0.0-beta.251

12 months ago

2.0.0-beta.263

11 months ago

2.0.0-beta.264

11 months ago

2.0.0-beta.260

11 months ago

2.0.0-beta.261

11 months ago

2.0.0-beta.262

11 months ago

2.0.0-beta.227

1 year ago

2.0.0-beta.228

1 year ago

2.0.0-beta.229

1 year ago

2.0.0-beta.230

1 year ago

0.0.0-replace

1 year ago

2.0.0-beta.224

1 year ago

2.0.0-beta.225

1 year ago

2.0.0-beta.226

1 year ago

2.0.0-beta.223

1 year ago

2.0.0-beta.42

1 year ago

1.10.7

2 years ago

2.0.0-beta.9

2 years ago

2.0.0-beta.8

2 years ago

2.0.0-beta.40

2 years ago

2.0.0-beta.41

2 years ago

2.0.0-beta.33

2 years ago

2.0.0-beta.32

2 years ago

2.0.0-beta.31

2 years ago

2.0.0-beta.30

2 years ago

2.0.0-beta.37

2 years ago

2.0.0-beta.36

2 years ago

2.0.0-beta.35

2 years ago

2.0.0-beta.34

2 years ago

2.0.0-beta.39

2 years ago

2.0.0-beta.38

2 years ago

2.0.0-beta.22

2 years ago

2.0.0-beta.21

2 years ago

2.0.0-beta.20

2 years ago

2.0.0-beta.26

2 years ago

2.0.0-beta.25

2 years ago

2.0.0-beta.24

2 years ago

2.0.0-beta.23

2 years ago

2.0.0-beta.29

2 years ago

2.0.0-beta.28

2 years ago

2.0.0-beta.27

2 years ago

2.0.0-beta.11

2 years ago

2.0.0-beta.10

2 years ago

2.0.0-beta.15

2 years ago

2.0.0-beta.14

2 years ago

2.0.0-beta.13

2 years ago

2.0.0-beta.12

2 years ago

2.0.0-beta.19

2 years ago

2.0.0-beta.18

2 years ago

2.0.0-beta.17

2 years ago

2.0.0-beta.16

2 years ago

1.10.5

2 years ago

1.10.4

2 years ago

1.10.6

2 years ago

2.0.0-beta.7

2 years ago

2.0.0-beta.2

2 years ago

2.0.0-beta.1

2 years ago

2.0.0-beta.0

2 years ago

2.0.0-beta.6

2 years ago

2.0.0-beta.5

2 years ago

2.0.0-beta.4

2 years ago

2.0.0-beta.3

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.9.16

2 years ago

1.9.15

2 years ago

1.9.14

2 years ago

1.9.13

2 years ago

1.9.12

2 years ago

1.9.11

2 years ago

1.6.4

2 years ago

1.8.1

2 years ago

1.6.3

2 years ago

1.4.5

2 years ago

1.8.0

2 years ago

1.6.2

2 years ago

1.4.4

2 years ago

1.6.1

2 years ago

1.4.3

2 years ago

1.6.0

2 years ago

1.4.2

2 years ago

1.2.4

2 years ago

1.4.1

2 years ago

1.2.3

2 years ago

1.4.0

2 years ago

1.9.10

2 years ago

1.9.9

2 years ago

1.9.8

2 years ago

1.9.7

2 years ago

1.9.6

2 years ago

1.9.5

2 years ago

1.6.11

2 years ago

1.9.4

2 years ago

1.6.10

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.5.0-beta.0

2 years ago

1.6.9

2 years ago

1.6.8

2 years ago

1.6.7

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.2.0

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.0

2 years ago

1.0.0-beta.1

2 years ago

1.0.0-beta.11

2 years ago

1.0.0-beta.10

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.7

2 years ago

1.0.0-beta.8

2 years ago

1.0.0-beta.9

2 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago