@@ -4,7 +4,7 @@ import * as THREE from 'three';
4
4
5
5
export function injectNgtsAnimations (
6
6
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 } = { }
8
8
) {
9
9
injector = assertInjectionContext ( injectNgtsAnimations , injector ) ;
10
10
return runInInjectionContext ( injector , ( ) => {
@@ -38,32 +38,28 @@ export function injectNgtsAnimations(
38
38
39
39
injectBeforeRender ( ( { delta } ) => mixer . update ( delta ) ) ;
40
40
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 ( ) ;
46
45
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 ] ;
49
48
50
- names . push ( clip . name ) ;
51
- clips . push ( clip ) ;
49
+ names . push ( clip . name ) ;
50
+ clips . push ( clip ) ;
52
51
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
+ } ) ;
59
58
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
+ }
67
63
} ) ;
68
64
69
65
return { ref : actualRef , actions, mixer, names, clips } ;
0 commit comments