Skip to content

Commit b4f6b3f

Browse files
committed
docs: update theatre example
1 parent ac14210 commit b4f6b3f

File tree

3 files changed

+261
-161
lines changed

3 files changed

+261
-161
lines changed

apps/examples/src/app/theatre/basic/basic.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
2-
import { TheatreProject, TheatreSequence, TheatreSheet, TheatreStudio } from 'angular-three-theatre';
2+
import { TheatreProject, TheatreSheet, TheatreStudio } from 'angular-three-theatre';
33
import { NgtCanvas } from 'angular-three/dom';
44
import { SceneGraph } from './scene';
55
import stateJson from './state.json';
66

77
@Component({
88
template: `
9-
<ngt-canvas shadows [camera]="{ position: [5, 5, 5] }">
9+
<ngt-canvas shadows>
1010
<theatre-project *canvasContent studio [config]="{ state }">
1111
<theatre-sheet [sequence]="{ autoplay: true, iterationCount: Infinity }">
1212
<app-scene-graph />
@@ -15,7 +15,7 @@ import stateJson from './state.json';
1515
</ngt-canvas>
1616
`,
1717
changeDetection: ChangeDetectionStrategy.OnPush,
18-
imports: [NgtCanvas, SceneGraph, TheatreProject, TheatreStudio, TheatreSheet, TheatreSequence],
18+
imports: [NgtCanvas, SceneGraph, TheatreProject, TheatreStudio, TheatreSheet],
1919
host: { class: 'basic-theatre' },
2020
})
2121
export default class Basic {
+55-31
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,76 @@
1-
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, Component } from '@angular/core';
2-
import { NgtArgs } from 'angular-three';
3-
import { TheatreSheetObject } from 'angular-three-theatre';
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, signal, viewChild } from '@angular/core';
2+
import { injectBeforeRender, NgtArgs } from 'angular-three';
3+
import { NgtsRoundedBox } from 'angular-three-soba/abstractions';
4+
import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';
5+
import { TheatreSheetObject, TheatreSheetObjectTransform } from 'angular-three-theatre';
46

57
@Component({
68
selector: 'app-scene-graph',
79
template: `
10+
<ngts-perspective-camera #camera [options]="{ makeDefault: true, position: [5, 5, 5], fov: 75, far: 1000 }" />
11+
812
<ngt-ambient-light
913
#ambientLight
1014
*sheetObject="'Ambient Light'"
1115
[sync]="ambientLight"
1216
[syncProps]="['intensity', 'color']"
1317
/>
1418
15-
<ng-template sheetObject="Directional Light">
16-
<theatre-transform>
17-
<ngt-directional-light
18-
#directionalLight
19-
castShadow
20-
[sync]="directionalLight"
21-
[syncProps]="['intensity', 'color']"
19+
<theatre-transform *sheetObject="'Directional Light'">
20+
<ngt-directional-light
21+
#directionalLight
22+
castShadow
23+
[sync]="directionalLight"
24+
[syncProps]="['intensity', 'color']"
25+
/>
26+
</theatre-transform>
27+
28+
<theatre-transform
29+
#boxTransform
30+
*sheetObject="'Box'; select as select; deselect as deselect"
31+
[options]="{ mode: boxTransformMode() }"
32+
>
33+
<ngts-rounded-box [options]="{ castShadow: true }" (click)="select()" (pointermissed)="deselect()">
34+
<ngt-mesh-standard-material
35+
#boxMaterial
36+
transparent
37+
[sync]="boxMaterial"
38+
[syncProps]="['color', 'roughness', 'metalness', 'side', 'opacity']"
2239
/>
23-
</theatre-transform>
24-
</ng-template>
25-
26-
<ng-template sheetObject="Box" let-select="select" let-deselect="deselect">
27-
<theatre-transform>
28-
<ngt-mesh castShadow (click)="select()" (pointermissed)="deselect()">
29-
<ngt-box-geometry />
30-
<ngt-mesh-standard-material
31-
#boxMaterial
32-
transparent
33-
[sync]="boxMaterial"
34-
[syncProps]="['color', 'roughness', 'metalness', 'side', 'opacity']"
35-
/>
36-
</ngt-mesh>
37-
</theatre-transform>
38-
</ng-template>
39-
40-
<ngt-mesh receiveShadow [position.y]="-1" [rotation.x]="-Math.PI / 2">
41-
<ngt-circle-geometry *args="[1.4, 48]" />
40+
</ngts-rounded-box>
41+
</theatre-transform>
42+
43+
<ngt-mesh receiveShadow [position.y]="-1" [rotation.x]="-Math.PI / 2" [scale]="10">
44+
<ngt-circle-geometry />
4245
<ngt-mesh-standard-material />
4346
</ngt-mesh>
4447
`,
4548
schemas: [CUSTOM_ELEMENTS_SCHEMA],
46-
imports: [NgtArgs, TheatreSheetObject],
49+
imports: [NgtArgs, TheatreSheetObject, NgtsRoundedBox, NgtsPerspectiveCamera],
4750
changeDetection: ChangeDetectionStrategy.OnPush,
48-
host: { class: 'experience-basic-theatre' },
51+
host: { class: 'experience-basic-theatre', '(document:keyup)': 'onKeyup($event)' },
4952
})
5053
export class SceneGraph {
5154
protected readonly Math = Math;
55+
56+
private boxTransform = viewChild.required('boxTransform', { read: TheatreSheetObjectTransform });
57+
private modes = ['translate', 'rotate', 'scale'] as const;
58+
protected boxTransformMode = signal<(typeof this.modes)[number]>('translate');
59+
60+
protected onKeyup(event: KeyboardEvent) {
61+
if (event.key === 'Shift' && event.location === KeyboardEvent.DOM_KEY_LOCATION_LEFT) {
62+
// cycle through modes
63+
this.boxTransformMode.set(
64+
this.modes[(this.modes.indexOf(this.boxTransformMode()) + 1) % this.modes.length],
65+
);
66+
}
67+
}
68+
69+
constructor() {
70+
injectBeforeRender(({ camera }) => {
71+
const boxSheetObject = this.boxTransform().sheetObject();
72+
const position = boxSheetObject.value['position'];
73+
camera.lookAt(position.x, position.y, position.z);
74+
});
75+
}
5276
}

0 commit comments

Comments
 (0)