55 computed ,
66 effect ,
77 runInInjectionContext ,
8+ signal ,
9+ untracked ,
810 type Injector ,
911} from '@angular/core' ;
1012import {
@@ -59,7 +61,7 @@ export function injectNgtsTrail(
5961) {
6062 injector = assertInjector ( injectNgtsTrail , injector ) ;
6163 return runInInjectionContext ( injector , ( ) => {
62- const points = injectNgtRef < Float32Array > ( ) ;
64+ const _points = signal < Float32Array > ( new Float32Array ( ) ) ;
6365 let frameCount = 0 ;
6466
6567 const prevPosition = new THREE . Vector3 ( ) ;
@@ -77,20 +79,17 @@ export function injectNgtsTrail(
7779 effect ( ( ) => {
7880 const [ target , length ] = [ _target ( ) , _length ( ) ] ;
7981 if ( target ) {
80- points . nativeElement = Float32Array . from ( { length : length * 10 * 3 } , ( _ , i ) =>
81- target . position . getComponent ( i % 3 ) ,
82- ) ;
82+ untracked ( ( ) => {
83+ _points . set (
84+ Float32Array . from ( { length : length * 10 * 3 } , ( _ , i ) => target . position . getComponent ( i % 3 ) ) ,
85+ ) ;
86+ } ) ;
8387 }
8488 } ) ;
8589
8690 injectBeforeRender ( ( ) => {
87- const [ target , _points , { local, decay, stride, interval } ] = [
88- _target ( ) ,
89- points . nativeElement ,
90- _settings ( ) ,
91- ] ;
92- if ( ! target ) return ;
93- if ( ! _points ) return ;
91+ const [ target , points , { local, decay, stride, interval } ] = [ _target ( ) , _points ( ) , _settings ( ) ] ;
92+ if ( ! target || ! points ) return ;
9493
9594 if ( frameCount === 0 ) {
9695 let newPosition : THREE . Vector3 ;
@@ -105,8 +104,8 @@ export function injectNgtsTrail(
105104 for ( let i = 0 ; i < steps ; i ++ ) {
106105 if ( newPosition . distanceTo ( prevPosition ) < stride ) continue ;
107106
108- shiftLeft ( _points , 3 ) ;
109- _points . set ( newPosition . toArray ( ) , _points . length - 3 ) ;
107+ shiftLeft ( points , 3 ) ;
108+ points . set ( newPosition . toArray ( ) , points . length - 3 ) ;
110109 }
111110 prevPosition . copy ( newPosition ) ;
112111 }
@@ -115,7 +114,7 @@ export function injectNgtsTrail(
115114 frameCount = frameCount % interval ;
116115 } ) ;
117116
118- return points ;
117+ return _points . asReadonly ( ) ;
119118 } ) ;
120119}
121120
@@ -247,8 +246,7 @@ export class NgtsTrail {
247246
248247 private beforeRender ( ) {
249248 injectBeforeRender ( ( ) => {
250- const [ points , attenuation ] = [ this . points . nativeElement , this . attenuation ( ) ] ;
251- if ( ! points ) return ;
249+ const [ points , attenuation ] = [ this . points ( ) , this . attenuation ( ) ] ;
252250 this . geometry . setPoints ( points , attenuation ) ;
253251 } ) ;
254252 }
0 commit comments