@@ -4,7 +4,7 @@ import * as THREE from 'three';
44
55export function injectNgtsAnimations (
66 animationsFactory : ( ) => THREE . AnimationClip [ ] ,
7- { ref, injector } : { ref ?: NgtInjectedRef < THREE . Object3D > | THREE . Object3D ; injector ?: Injector }
7+ { ref, injector } : { ref ?: NgtInjectedRef < THREE . Object3D > | THREE . Object3D ; injector ?: Injector } = { }
88) {
99 injector = assertInjectionContext ( injectNgtsAnimations , injector ) ;
1010 return runInInjectionContext ( injector , ( ) => {
@@ -38,32 +38,28 @@ export function injectNgtsAnimations(
3838
3939 injectBeforeRender ( ( { delta } ) => mixer . update ( delta ) ) ;
4040
41- requestAnimationFrame ( ( ) => {
42- effect (
43- ( ) => {
44- const actual = actualRef . nativeElement ;
45- const animations = animationsFactory ( ) ;
41+ effect ( ( ) => {
42+ const actual = actualRef . nativeElement ;
43+ if ( ! actual ) return ;
44+ const animations = animationsFactory ( ) ;
4645
47- for ( let i = 0 ; i < animations . length ; i ++ ) {
48- const clip = animations [ i ] ;
46+ for ( let i = 0 ; i < animations . length ; i ++ ) {
47+ const clip = animations [ i ] ;
4948
50- names . push ( clip . name ) ;
51- clips . push ( clip ) ;
49+ names . push ( clip . name ) ;
50+ clips . push ( clip ) ;
5251
53- Object . defineProperty ( actions , clip . name , {
54- enumerable : true ,
55- get : ( ) => {
56- return cached [ clip . name ] || ( cached [ clip . name ] = mixer . clipAction ( clip , actual ) ) ;
57- } ,
58- } ) ;
52+ Object . defineProperty ( actions , clip . name , {
53+ enumerable : true ,
54+ get : ( ) => {
55+ return cached [ clip . name ] || ( cached [ clip . name ] = mixer . clipAction ( clip , actual ) ) ;
56+ } ,
57+ } ) ;
5958
60- if ( i === 0 ) {
61- actions [ clip . name ] . play ( ) ;
62- }
63- }
64- } ,
65- { injector }
66- ) ;
59+ if ( i === 0 ) {
60+ actions [ clip . name ] . play ( ) ;
61+ }
62+ }
6763 } ) ;
6864
6965 return { ref : actualRef , actions, mixer, names, clips } ;
0 commit comments