3.7.2 • Published 4 months ago

angular-three v3.7.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 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

4 months ago

4.0.0-next.96

4 months ago

4.0.0-next.93

4 months ago

4.0.0-next.94

4 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

4 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

5 months ago

4.0.0-next.70

4 months ago

4.0.0-next.59

5 months ago

4.0.0-next.62

5 months ago

4.0.0-next.63

5 months ago

4.0.0-next.60

5 months ago

4.0.0-next.61

5 months ago

4.0.0-next.66

5 months ago

4.0.0-next.67

5 months ago

4.0.0-next.64

5 months ago

4.0.0-next.65

5 months ago

4.0.0-next.68

5 months ago

4.0.0-next.55

5 months ago

4.0.0-next.56

5 months ago

4.0.0-next.53

5 months ago

4.0.0-next.54

5 months ago

4.0.0-next.57

5 months ago

4.0.0-next.58

5 months ago

4.0.0-next.51

5 months ago

4.0.0-next.52

5 months ago

4.0.0-next.50

5 months ago

4.0.0-next.40

5 months ago

4.0.0-next.41

5 months ago

4.0.0-next.44

5 months ago

4.0.0-next.45

5 months ago

4.0.0-next.42

5 months ago

4.0.0-next.43

5 months ago

4.0.0-next.48

5 months ago

4.0.0-next.49

5 months ago

4.0.0-next.46

5 months ago

4.0.0-next.47

5 months ago

4.0.0-next.30

5 months ago

4.0.0-next.33

5 months ago

4.0.0-next.34

5 months ago

4.0.0-next.31

5 months ago

4.0.0-next.32

5 months ago

4.0.0-next.37

5 months ago

4.0.0-next.38

5 months ago

4.0.0-next.35

5 months ago

4.0.0-next.36

5 months ago

4.0.0-next.39

5 months ago

4.0.0-next.22

5 months ago

4.0.0-next.23

5 months ago

4.0.0-next.20

5 months ago

4.0.0-next.21

5 months ago

4.0.0-next.26

5 months ago

4.0.0-next.27

5 months ago

4.0.0-next.24

5 months ago

4.0.0-next.25

5 months ago

4.0.0-next.28

5 months ago

4.0.0-next.29

5 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

6 months ago

4.0.0-next.6

6 months ago

4.0.0-next.5

6 months ago

4.0.0-next.4

6 months ago

4.0.0-next.3

6 months ago

4.0.0-next.2

6 months ago

3.7.1

6 months ago

3.7.2

5 months ago

4.0.0-next.1

6 months ago

3.7.0

6 months ago

3.6.1

6 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

6 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

8 months ago

2.10.1

8 months ago

2.10.2

8 months ago

2.10.7

8 months ago

2.10.5

8 months ago

2.10.6

8 months ago

2.10.3

8 months ago

2.10.4

8 months ago

2.12.0

8 months ago

2.10.0

8 months ago

2.9.0

8 months ago

2.8.1

8 months ago

2.8.0

8 months ago

2.7.0

9 months ago

2.6.1

9 months ago

2.6.0

9 months ago

2.5.2

9 months ago

2.4.0

10 months ago

2.5.0

10 months ago

2.5.1

10 months ago

2.3.0

10 months ago

2.3.2

10 months ago

2.2.1

10 months ago

2.2.0

10 months ago

2.0.0-beta.316

11 months ago

2.1.0

10 months ago

2.0.0

11 months ago

2.0.0-beta.314

11 months ago

2.0.0-beta.315

11 months ago

2.0.0-beta.307

11 months ago

2.0.0-beta.308

11 months ago

2.0.0-beta.309

11 months ago

2.0.0-beta.310

11 months ago

2.0.0-beta.311

11 months ago

2.0.0-beta.312

11 months ago

2.0.0-beta.313

11 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

12 months ago

2.0.0-beta.279

12 months ago

2.0.0-beta.280

12 months ago

2.0.0-beta.281

12 months ago

2.0.0-beta.282

12 months ago

2.0.0-beta.283

12 months ago

2.0.0-beta.274

12 months ago

2.0.0-beta.275

12 months ago

2.0.0-beta.276

12 months ago

2.0.0-beta.277

12 months ago

2.0.0-beta.271

12 months ago

2.0.0-beta.272

12 months ago

2.0.0-beta.273

12 months ago

2.0.0-beta.268

12 months ago

2.0.0-beta.269

12 months ago

2.0.0-beta.270

12 months ago

2.0.0-beta.265

12 months ago

2.0.0-beta.266

12 months ago

2.0.0-beta.267

12 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

1 year ago

2.0.0-beta.244

1 year ago

2.0.0-beta.245

1 year ago

2.0.0-beta.246

1 year ago

2.0.0-beta.247

1 year ago

2.0.0-beta.248

1 year ago

2.0.0-beta.240

1 year ago

2.0.0-beta.249

1 year ago

2.0.0-beta.252

1 year ago

2.0.0-beta.253

1 year ago

2.0.0-beta.254

1 year ago

2.0.0-beta.255

1 year ago

2.0.0-beta.256

1 year ago

2.0.0-beta.257

1 year ago

2.0.0-beta.258

12 months ago

2.0.0-beta.259

12 months ago

2.0.0-beta.250

1 year ago

2.0.0-beta.251

1 year ago

2.0.0-beta.263

12 months ago

2.0.0-beta.264

12 months ago

2.0.0-beta.260

12 months ago

2.0.0-beta.261

12 months ago

2.0.0-beta.262

12 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

2 years 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