11import { ElementRef , Injector , afterNextRender , computed , isSignal , signal , untracked } from '@angular/core' ;
2- import { injectBeforeRender , is } from 'angular-three' ;
2+ import { injectBeforeRender , resolveRef } from 'angular-three' ;
33import { assertInjector } from 'ngxtension/assert-injector' ;
44import { injectAutoEffect } from 'ngxtension/auto-effect' ;
55import { AnimationAction , AnimationClip , AnimationMixer , Object3D } from 'three' ;
@@ -15,6 +15,9 @@ export type NgtsAnimation<TAnimation extends AnimationClip = AnimationClip> =
1515 | TAnimation [ ]
1616 | { animations : TAnimation [ ] } ;
1717
18+ /**
19+ * Use afterNextRender
20+ */
1821export function injectAnimations < TAnimation extends AnimationClip > (
1922 animations : ( ) => NgtsAnimation < TAnimation > | undefined | null ,
2023 object : ElementRef < Object3D > | Object3D | ( ( ) => ElementRef < Object3D > | Object3D | undefined | null ) ,
@@ -32,26 +35,18 @@ export function injectAnimations<TAnimation extends AnimationClip>(
3235 const names = [ ] as NgtsAnimationApi < TAnimation > [ 'names' ] ;
3336
3437 const actualObject = computed ( ( ) => {
35- if ( is . ref ( object ) ) {
36- return object . nativeElement ;
37- }
38-
3938 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 ( ) ) ;
4540 }
4641
47- return object ;
42+ return resolveRef ( object ) ;
4843 } ) ;
4944
5045 const ready = signal ( false ) ;
5146
5247 afterNextRender ( ( ) => {
5348 autoEffect ( ( ) => {
54- const obj = actualObject ( ) ;
49+ const obj = actualObject ( ) as Object3D | undefined ;
5550 if ( ! obj ) return ;
5651 Object . assign ( mixer , { _root : obj } ) ;
5752
0 commit comments