1
1
import { ElementRef , Injector , afterNextRender , computed , isSignal , signal , untracked } from '@angular/core' ;
2
- import { injectBeforeRender , is } from 'angular-three' ;
2
+ import { injectBeforeRender , resolveRef } from 'angular-three' ;
3
3
import { assertInjector } from 'ngxtension/assert-injector' ;
4
4
import { injectAutoEffect } from 'ngxtension/auto-effect' ;
5
5
import { AnimationAction , AnimationClip , AnimationMixer , Object3D } from 'three' ;
@@ -15,6 +15,9 @@ export type NgtsAnimation<TAnimation extends AnimationClip = AnimationClip> =
15
15
| TAnimation [ ]
16
16
| { animations : TAnimation [ ] } ;
17
17
18
+ /**
19
+ * Use afterNextRender
20
+ */
18
21
export function injectAnimations < TAnimation extends AnimationClip > (
19
22
animations : ( ) => NgtsAnimation < TAnimation > | undefined | null ,
20
23
object : ElementRef < Object3D > | Object3D | ( ( ) => ElementRef < Object3D > | Object3D | undefined | null ) ,
@@ -32,26 +35,18 @@ export function injectAnimations<TAnimation extends AnimationClip>(
32
35
const names = [ ] as NgtsAnimationApi < TAnimation > [ 'names' ] ;
33
36
34
37
const actualObject = computed ( ( ) => {
35
- if ( is . ref ( object ) ) {
36
- return object . nativeElement ;
37
- }
38
-
39
38
if ( isSignal ( object ) || typeof object === 'function' ) {
40
- const value = object ( ) ;
41
- if ( is . ref ( value ) ) {
42
- return value . nativeElement ;
43
- }
44
- return value ;
39
+ return resolveRef ( object ( ) ) ;
45
40
}
46
41
47
- return object ;
42
+ return resolveRef ( object ) ;
48
43
} ) ;
49
44
50
45
const ready = signal ( false ) ;
51
46
52
47
afterNextRender ( ( ) => {
53
48
autoEffect ( ( ) => {
54
- const obj = actualObject ( ) ;
49
+ const obj = actualObject ( ) as Object3D | undefined ;
55
50
if ( ! obj ) return ;
56
51
Object . assign ( mixer , { _root : obj } ) ;
57
52
0 commit comments