Skip to content

Commit 082c47d

Browse files
committed
docs: fix animation for skydiving demo; add link to demo site in docs
1 parent 2a39b78 commit 082c47d

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

apps/astro-docs/astro.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export default defineConfig({
178178
{ label: 'How it works', slug: 'postprocessing/how-it-works' },
179179
],
180180
},
181+
{
182+
label: 'Demo',
183+
link: 'https://demo.angularthree.org',
184+
},
181185
],
182186
}),
183187
tailwind({ applyBaseStyles: false }),

apps/kitchen-sink/src/app/soba/skydiving/skydiver.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { ChangeDetectionStrategy, Component, computed, CUSTOM_ELEMENTS_SCHEMA, effect, Signal } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
effect,
6+
ElementRef,
7+
Signal,
8+
viewChild,
9+
} from '@angular/core';
210
import { injectBeforeRender, NgtArgs } from 'angular-three';
311
import { injectGLTF, injectTexture } from 'angular-three-soba/loaders';
412
import { injectAnimations } from 'angular-three-soba/misc';
5-
import { BufferGeometry, DoubleSide, Mesh, MeshStandardMaterial, ShaderMaterial, SkinnedMesh } from 'three';
13+
import { Bone, BufferGeometry, DoubleSide, Mesh, MeshStandardMaterial, ShaderMaterial, SkinnedMesh } from 'three';
614
import { GLTF } from 'three-stdlib';
715

816
type SkydiverGLTF = GLTF & {
@@ -20,7 +28,7 @@ type SkydiverGLTF = GLTF & {
2028
<ngt-group [dispose]="null">
2129
@if (gltf(); as gltf) {
2230
<ngt-group>
23-
<ngt-primitive *args="[gltf.nodes.mixamorigHips]" />
31+
<ngt-primitive #bone *args="[gltf.nodes.mixamorigHips]" />
2432
<ngt-skinned-mesh [geometry]="gltf.nodes.skydiver_2.geometry" [skeleton]="gltf.nodes.skydiver_2.skeleton">
2533
@if (textures(); as textures) {
2634
<ngt-mesh-standard-material
@@ -48,16 +56,10 @@ type SkydiverGLTF = GLTF & {
4856
imports: [NgtArgs],
4957
})
5058
export class Skydiver {
51-
protected readonly DoubleSide = DoubleSide;
59+
protected DoubleSide = DoubleSide;
5260

53-
gltf = injectGLTF(() => './skydiver.glb') as Signal<SkydiverGLTF | null>;
54-
private model = computed(() => {
55-
const gltf = this.gltf();
56-
if (!gltf) return null;
57-
return gltf.scene;
58-
});
59-
60-
textures = injectTexture(
61+
protected gltf = injectGLTF(() => './skydiver.glb') as Signal<SkydiverGLTF | null>;
62+
protected textures = injectTexture(
6163
() => ({
6264
baseColor: './texture/skydiver_BaseColor.webp',
6365
roughness: './texture/skydiver_Roughness.webp',
@@ -74,9 +76,10 @@ export class Skydiver {
7476
},
7577
);
7678

77-
animations = injectAnimations(this.gltf, this.model);
79+
private boneRef = viewChild<ElementRef<Bone>>('bone');
80+
private animations = injectAnimations(this.gltf, this.boneRef);
7881

79-
onBeforeCompile: MeshStandardMaterial['onBeforeCompile'] = (shader) => {
82+
protected onBeforeCompile: MeshStandardMaterial['onBeforeCompile'] = (shader) => {
8083
const gltf = this.gltf();
8184

8285
Object.assign(shader.uniforms, {
@@ -102,11 +105,12 @@ export class Skydiver {
102105
};
103106

104107
constructor() {
105-
effect(() => {
108+
effect((onCleanup) => {
106109
const ready = this.animations.ready();
107110
if (!ready) return;
108111
const { actions } = this.animations;
109112
actions['animation_0']?.reset().play();
113+
onCleanup(() => actions['animation_0']?.stop());
110114
});
111115

112116
injectBeforeRender(({ clock }) => {

apps/kitchen-sink/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<title>kitchen-sink</title>
5+
<title>Angular Three Demo</title>
66
<base href="/" />
77
<meta name="viewport" content="width=device-width, initial-scale=1" />
88
<link rel="icon" type="image/x-icon" href="favicon.ico" />

0 commit comments

Comments
 (0)