5
5
computed ,
6
6
effect ,
7
7
runInInjectionContext ,
8
+ signal ,
9
+ untracked ,
8
10
type Injector ,
9
11
} from '@angular/core' ;
10
12
import {
@@ -59,7 +61,7 @@ export function injectNgtsTrail(
59
61
) {
60
62
injector = assertInjector ( injectNgtsTrail , injector ) ;
61
63
return runInInjectionContext ( injector , ( ) => {
62
- const points = injectNgtRef < Float32Array > ( ) ;
64
+ const _points = signal < Float32Array > ( new Float32Array ( ) ) ;
63
65
let frameCount = 0 ;
64
66
65
67
const prevPosition = new THREE . Vector3 ( ) ;
@@ -77,20 +79,17 @@ export function injectNgtsTrail(
77
79
effect ( ( ) => {
78
80
const [ target , length ] = [ _target ( ) , _length ( ) ] ;
79
81
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
+ } ) ;
83
87
}
84
88
} ) ;
85
89
86
90
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 ;
94
93
95
94
if ( frameCount === 0 ) {
96
95
let newPosition : THREE . Vector3 ;
@@ -105,8 +104,8 @@ export function injectNgtsTrail(
105
104
for ( let i = 0 ; i < steps ; i ++ ) {
106
105
if ( newPosition . distanceTo ( prevPosition ) < stride ) continue ;
107
106
108
- shiftLeft ( _points , 3 ) ;
109
- _points . set ( newPosition . toArray ( ) , _points . length - 3 ) ;
107
+ shiftLeft ( points , 3 ) ;
108
+ points . set ( newPosition . toArray ( ) , points . length - 3 ) ;
110
109
}
111
110
prevPosition . copy ( newPosition ) ;
112
111
}
@@ -115,7 +114,7 @@ export function injectNgtsTrail(
115
114
frameCount = frameCount % interval ;
116
115
} ) ;
117
116
118
- return points ;
117
+ return _points . asReadonly ( ) ;
119
118
} ) ;
120
119
}
121
120
@@ -247,8 +246,7 @@ export class NgtsTrail {
247
246
248
247
private beforeRender ( ) {
249
248
injectBeforeRender ( ( ) => {
250
- const [ points , attenuation ] = [ this . points . nativeElement , this . attenuation ( ) ] ;
251
- if ( ! points ) return ;
249
+ const [ points , attenuation ] = [ this . points ( ) , this . attenuation ( ) ] ;
252
250
this . geometry . setPoints ( points , attenuation ) ;
253
251
} ) ;
254
252
}
0 commit comments