1
- import { DestroyRef , Injector , computed , effect , inject , runInInjectionContext } from '@angular/core' ;
1
+ import { Injector , computed , effect , runInInjectionContext } from '@angular/core' ;
2
2
import { assertInjectionContext , injectBeforeRender , injectNgtRef , type NgtRef } from 'angular-three' ;
3
3
import * as THREE from 'three' ;
4
4
@@ -30,24 +30,11 @@ export function injectNgtsAnimations(
30
30
const clips = [ ] as THREE . AnimationClip [ ] ;
31
31
const names = [ ] as string [ ] ;
32
32
33
- inject ( DestroyRef ) . onDestroy ( ( ) => {
34
- // clear cached
35
- cached = { } ;
36
- // uncache actions
37
- Object . values ( actions ) . forEach ( ( action ) => {
38
- mixer . uncacheAction ( action as unknown as THREE . AnimationClip , object ! ) ;
39
- } ) ;
40
- // stop all actions
41
- mixer . stopAllAction ( ) ;
42
-
43
- object = null ;
44
- } ) ;
45
-
46
33
injectBeforeRender ( ( { delta } ) => mixer . update ( delta ) ) ;
47
34
48
35
const ready = computed ( ( ) => ! ! actualRef . nativeElement && ! ! animationsFactory ( ) . length ) ;
49
36
50
- effect ( ( ) => {
37
+ effect ( ( onCleanup ) => {
51
38
const actual = actualRef . nativeElement ;
52
39
if ( ! actual ) return ;
53
40
object = actual ;
@@ -70,6 +57,19 @@ export function injectNgtsAnimations(
70
57
actions [ clip . name ] . play ( ) ;
71
58
}
72
59
}
60
+
61
+ onCleanup ( ( ) => {
62
+ // clear cached
63
+ cached = { } ;
64
+ // stop all actions
65
+ mixer . stopAllAction ( ) ;
66
+ // uncache actions
67
+ Object . values ( actions ) . forEach ( ( action ) => {
68
+ mixer . uncacheAction ( action as unknown as THREE . AnimationClip , object ! ) ;
69
+ } ) ;
70
+
71
+ object = null ;
72
+ } ) ;
73
73
} ) ;
74
74
75
75
return { ref : actualRef , actions, mixer, names, clips, ready } ;
0 commit comments