Skip to content

Commit 728db58

Browse files
committed
docs: clean up more demos
1 parent 1104e27 commit 728db58

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

apps/demo/src/app/animation-keyframes/animation-keyframes.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, inject } from '@angular/core';
22
import { injectBeforeRender, injectNgtLoader, NgtArgs, NgtCanvas, NgtPush, NgtStore } from 'angular-three';
3-
import { map, tap } from 'rxjs';
3+
import { map } from 'rxjs';
44
import * as THREE from 'three';
55
import { DRACOLoader, GLTFLoader, RoomEnvironment } from 'three-stdlib';
66
import Stats from 'three/examples/jsm/libs/stats.module.js';
@@ -12,7 +12,7 @@ import { DemoOrbitControls } from '../ui-orbit-controls/orbit-controls.component
1212
<ngt-color *args="['#bfe3dd']" attach="background" />
1313
<ngt-value [rawValue]="texture" attach="environment" />
1414
15-
<ngt-primitive *args="[model$ | ngtPush : null]" [position]="[1, 1, 0]" [scale]="0.01" />
15+
<ngt-primitive *args="[model$ | ngtPush]" [position]="[1, 1, 0]" [scale]="0.01" />
1616
1717
<demo-orbit-controls [target]="[0, 0.5, 0]" [enablePan]="false" />
1818
`,
@@ -37,12 +37,12 @@ export class Scene {
3737
(loader as GLTFLoader).setDRACOLoader(dracoLoader);
3838
}
3939
).pipe(
40-
tap((model) => {
40+
map((model) => {
4141
const scene = model.scene;
4242
this.mixer = new THREE.AnimationMixer(scene);
4343
this.mixer.clipAction(model.animations[0]).play();
44-
}),
45-
map((model) => model.scene)
44+
return scene;
45+
})
4646
);
4747

4848
constructor() {

apps/demo/src/app/animation-skinning-ik/animation-skinning-ik.component.ts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { NgIf } from '@angular/common';
22
import { Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, inject, OnDestroy, ViewChild } from '@angular/core';
3-
import { extend, injectBeforeRender, injectNgtLoader, NgtArgs, NgtCanvas, NgtPush, NgtStore } from 'angular-three';
3+
import {
4+
extend,
5+
injectBeforeRender,
6+
injectNgtLoader,
7+
NgtArgs,
8+
NgtCanvas,
9+
NgtPush,
10+
NgtRenderState,
11+
NgtStore,
12+
} from 'angular-three';
413
import { map } from 'rxjs';
514
import * as THREE from 'three';
615
import { CCDIKHelper, CCDIKSolver, DRACOLoader, GLTFLoader, IKS, OrbitControls, TransformControls } from 'three-stdlib';
@@ -94,30 +103,7 @@ export class Scene implements OnDestroy {
94103
this.gui.add(this.config, 'turnHead').name('turn head');
95104
this.gui.add(this.config, 'ikSolver').name('IK Auto update');
96105

97-
injectBeforeRender(({ gl, scene }) => {
98-
const head = this.ooi['head'];
99-
const sphere = this.ooi.sphere;
100-
101-
if (sphere && this.cubeCamera) {
102-
sphere.visible = false;
103-
sphere.getWorldPosition(this.cubeCamera.nativeElement.position);
104-
this.cubeCamera.nativeElement.update(gl, scene);
105-
sphere.visible = true;
106-
}
107-
108-
if (sphere && this.config.followSphere) {
109-
sphere.getWorldPosition(v0);
110-
this.orbitControls?.target.lerp(v0, 0.1);
111-
}
112-
113-
if (head && sphere && this.config.turnHead) {
114-
sphere.getWorldPosition(v0);
115-
head.lookAt(v0);
116-
head.rotation.set(head.rotation.x, head.rotation.y + Math.PI, head.rotation.z);
117-
}
118-
119-
if (this.config.ikSolver && this.solver) this.solver.update();
120-
});
106+
injectBeforeRender(this.onBeforeRender.bind(this));
121107
}
122108

123109
onAfterModelAttach() {
@@ -144,6 +130,31 @@ export class Scene implements OnDestroy {
144130
this.gui.open();
145131
}
146132

133+
private onBeforeRender({ gl, scene }: NgtRenderState) {
134+
const head = this.ooi['head'];
135+
const sphere = this.ooi.sphere;
136+
137+
if (sphere && this.cubeCamera) {
138+
sphere.visible = false;
139+
sphere.getWorldPosition(this.cubeCamera.nativeElement.position);
140+
this.cubeCamera.nativeElement.update(gl, scene);
141+
sphere.visible = true;
142+
}
143+
144+
if (sphere && this.config.followSphere) {
145+
sphere.getWorldPosition(v0);
146+
this.orbitControls?.target.lerp(v0, 0.1);
147+
}
148+
149+
if (head && sphere && this.config.turnHead) {
150+
sphere.getWorldPosition(v0);
151+
head.lookAt(v0);
152+
head.rotation.set(head.rotation.x, head.rotation.y + Math.PI, head.rotation.z);
153+
}
154+
155+
if (this.config.ikSolver && this.solver) this.solver.update();
156+
}
157+
147158
ngOnDestroy() {
148159
this.gui.domElement.remove();
149160
}

apps/demo/src/app/camera/camera.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class Scene implements AfterViewInit, OnInit {
181181
</a>
182182
- cameras
183183
<br />
184-
<b class="text-green-300">O</b> orthographic <b class="text-green-300">P</b> perspective
184+
<b class="text-green-400">O</b> orthographic <b class="text-green-400">P</b> perspective
185185
</div>
186186
`,
187187
imports: [NgtCanvas],

apps/documentation/docs/getting-started/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { NgtCanvas } from 'angular-three';
5151
@Component({
5252
selector: 'my-app',
5353
standalone: true,
54-
template: `<ngt-canvas [scene]="Scene" />`,
54+
template: `<ngt-canvas [sceneGraph]="Scene" />`,
5555
imports: [NgtCanvas],
5656
})
5757
export class AppComponent {

0 commit comments

Comments
 (0)