@@ -8,11 +8,11 @@ import {
88} from '@angular/core' ;
99import { injectBeforeRender , NgtArgs } from 'angular-three' ;
1010import { injectGLTF , injectTexture } from 'angular-three-soba/loaders' ;
11- import { injectAnimations } from 'angular-three-soba/misc' ;
11+ import { injectAnimations , NgtsAnimationClips } from 'angular-three-soba/misc' ;
1212import {
13- Bone ,
1413 BufferGeometry ,
1514 DoubleSide ,
15+ Group ,
1616 Mesh ,
1717 MeshStandardMaterial ,
1818 ShaderMaterial ,
@@ -27,35 +27,36 @@ type SkydiverGLTF = GLTF & {
2727 mixamorigHips : Mesh ;
2828 } ;
2929 materials : { } ;
30+ animations : NgtsAnimationClips < 'animation_0' > ;
3031} ;
3132
3233@Component ( {
3334 selector : 'app-skydiver' ,
3435 template : `
3536 <ngt-group [dispose]="null">
3637 @if (gltf(); as gltf) {
37- <ngt-group>
38+ <ngt-group #group >
3839 <ngt-primitive #bone *args="[gltf.nodes.mixamorigHips]" />
3940 <ngt-skinned-mesh
4041 [geometry]="gltf.nodes.skydiver_2.geometry"
4142 [skeleton]="gltf.nodes.skydiver_2.skeleton"
4243 >
43- @if (textures(); as textures) {
44- <ngt-mesh-standard-material
45- [parameters]="{
46- uniforms: { uTime: { value: 0 }, uClothes: { value: textures.clothes } },
47- onBeforeCompile,
48- toneMapped: false,
49- envMapIntensity: 0.8,
50- metalnessMap: textures.metallic,
51- normalMap: textures.normal,
52- roughnessMap: textures.roughness,
53- map: textures.baseColor,
54- normalScale: [-0.2, 0.2],
55- side: DoubleSide,
56- } "
57- />
58- }
44+ @let metallic = textures()?.metallic;
45+ @let normal = textures()?.normal;
46+ @let roughness = textures()?.roughness;
47+ @let baseColor = textures()?.baseColor;
48+
49+ <ngt-mesh-standard-material
50+ [toneMapped]="false"
51+ [envMapIntensity]="0.8"
52+ [metalnessMap]="metallic"
53+ [normalMap]="normal"
54+ [roughnessMap]="roughness"
55+ [map]="baseColor"
56+ [normalScale]="[-0.2, 0.2]"
57+ [side]="DoubleSide "
58+ [parameters]="{ onBeforeCompile }"
59+ />
5960 </ngt-skinned-mesh>
6061 </ngt-group>
6162 }
@@ -87,14 +88,15 @@ export class Skydiver {
8788 } ,
8889 ) ;
8990
90- private boneRef = viewChild < ElementRef < Bone > > ( 'bone ' ) ;
91- private animations = injectAnimations ( this . gltf , this . boneRef ) ;
91+ private groupRef = viewChild < ElementRef < Group > > ( 'group ' ) ;
92+ private animations = injectAnimations ( this . gltf , this . groupRef ) ;
9293
9394 protected onBeforeCompile : MeshStandardMaterial [ 'onBeforeCompile' ] = ( shader ) => {
9495 const gltf = this . gltf ( ) ;
96+ if ( ! gltf ) return ;
9597
9698 Object . assign ( shader . uniforms , {
97- ...( gltf ? .nodes [ 'skydiver_2' ] . material ? .uniforms || { } ) ,
99+ ...gltf . nodes [ 'skydiver_2' ] . material . uniforms ,
98100 } ) ;
99101
100102 shader . vertexShader = /* language=glsl glsl */ `
@@ -116,17 +118,30 @@ export class Skydiver {
116118 } ;
117119
118120 constructor ( ) {
121+ effect ( ( ) => {
122+ const gltf = this . gltf ( ) ;
123+ if ( ! gltf ) return ;
124+
125+ const textures = this . textures ( ) ;
126+ if ( ! textures ) return ;
127+
128+ gltf . nodes [ 'skydiver_2' ] . material . uniforms = {
129+ uTime : { value : 0 } ,
130+ uClothes : { value : textures . clothes } ,
131+ } ;
132+ } ) ;
133+
119134 effect ( ( onCleanup ) => {
120135 if ( ! this . animations . isReady ) return ;
121136 const { actions } = this . animations ;
122- actions [ 'animation_0' ] ? .reset ( ) . play ( ) ;
123- onCleanup ( ( ) => actions [ 'animation_0' ] ? .stop ( ) ) ;
137+ actions [ 'animation_0' ] . reset ( ) . play ( ) ;
138+ onCleanup ( ( ) => actions [ 'animation_0' ] . stop ( ) ) ;
124139 } ) ;
125140
126141 injectBeforeRender ( ( { clock } ) => {
127142 const skydiver = this . gltf ( ) ?. nodes [ 'skydiver_2' ] ;
128143 if ( skydiver ?. material . uniforms ?. [ 'uTime' ] ) {
129- skydiver . material . uniforms [ 'uTime' ] . value = clock . getElapsedTime ( ) ;
144+ skydiver . material . uniforms [ 'uTime' ] . value = clock . elapsedTime ;
130145 }
131146 } ) ;
132147 }
0 commit comments