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' ;
2
10
import { injectBeforeRender , NgtArgs } from 'angular-three' ;
3
11
import { injectGLTF , injectTexture } from 'angular-three-soba/loaders' ;
4
12
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' ;
6
14
import { GLTF } from 'three-stdlib' ;
7
15
8
16
type SkydiverGLTF = GLTF & {
@@ -20,7 +28,7 @@ type SkydiverGLTF = GLTF & {
20
28
<ngt-group [dispose]="null">
21
29
@if (gltf(); as gltf) {
22
30
<ngt-group>
23
- <ngt-primitive *args="[gltf.nodes.mixamorigHips]" />
31
+ <ngt-primitive #bone *args="[gltf.nodes.mixamorigHips]" />
24
32
<ngt-skinned-mesh [geometry]="gltf.nodes.skydiver_2.geometry" [skeleton]="gltf.nodes.skydiver_2.skeleton">
25
33
@if (textures(); as textures) {
26
34
<ngt-mesh-standard-material
@@ -48,16 +56,10 @@ type SkydiverGLTF = GLTF & {
48
56
imports : [ NgtArgs ] ,
49
57
} )
50
58
export class Skydiver {
51
- protected readonly DoubleSide = DoubleSide ;
59
+ protected DoubleSide = DoubleSide ;
52
60
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 (
61
63
( ) => ( {
62
64
baseColor : './texture/skydiver_BaseColor.webp' ,
63
65
roughness : './texture/skydiver_Roughness.webp' ,
@@ -74,9 +76,10 @@ export class Skydiver {
74
76
} ,
75
77
) ;
76
78
77
- animations = injectAnimations ( this . gltf , this . model ) ;
79
+ private boneRef = viewChild < ElementRef < Bone > > ( 'bone' ) ;
80
+ private animations = injectAnimations ( this . gltf , this . boneRef ) ;
78
81
79
- onBeforeCompile : MeshStandardMaterial [ 'onBeforeCompile' ] = ( shader ) => {
82
+ protected onBeforeCompile : MeshStandardMaterial [ 'onBeforeCompile' ] = ( shader ) => {
80
83
const gltf = this . gltf ( ) ;
81
84
82
85
Object . assign ( shader . uniforms , {
@@ -102,11 +105,12 @@ export class Skydiver {
102
105
} ;
103
106
104
107
constructor ( ) {
105
- effect ( ( ) => {
108
+ effect ( ( onCleanup ) => {
106
109
const ready = this . animations . ready ( ) ;
107
110
if ( ! ready ) return ;
108
111
const { actions } = this . animations ;
109
112
actions [ 'animation_0' ] ?. reset ( ) . play ( ) ;
113
+ onCleanup ( ( ) => actions [ 'animation_0' ] ?. stop ( ) ) ;
110
114
} ) ;
111
115
112
116
injectBeforeRender ( ( { clock } ) => {
0 commit comments