@@ -3,20 +3,14 @@ import {
3
3
CUSTOM_ELEMENTS_SCHEMA ,
4
4
Component ,
5
5
ContentChild ,
6
- DestroyRef ,
7
6
Directive ,
8
- EmbeddedViewRef ,
9
7
Input ,
10
8
TemplateRef ,
11
- ViewChild ,
12
- ViewContainerRef ,
13
9
computed ,
14
10
effect ,
15
- inject ,
16
11
runInInjectionContext ,
17
12
untracked ,
18
13
type Injector ,
19
- type OnInit ,
20
14
type Signal ,
21
15
} from '@angular/core' ;
22
16
import {
@@ -64,8 +58,7 @@ export function injectNgtsCubeCamera(
64
58
65
59
const store = injectNgtStore ( ) ;
66
60
67
- const _gl = store . select ( 'gl' ) ;
68
- const _scene = store . select ( 'scene' ) ;
61
+ const [ _gl , _scene ] = [ store . select ( 'gl' ) , store . select ( 'scene' ) ] ;
69
62
70
63
const _fbo = computed ( ( ) => {
71
64
const renderTarget = new THREE . WebGLCubeRenderTarget ( resolution ( ) ) ;
@@ -133,23 +126,20 @@ export class NgtsCubeCameraContent {
133
126
<ngt-group ngtCompound>
134
127
<ngt-primitive *args="[cubeCamera.camera()]" />
135
128
<ngt-group [ref]="cameraRef">
136
- <ng-container #anchor />
129
+ <ng-container *ngTemplateOutlet="cameraContent; context: { texture }" />
137
130
</ngt-group>
138
131
</ngt-group>
139
132
` ,
140
133
imports : [ NgtArgs , NgTemplateOutlet ] ,
141
134
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
142
135
} )
143
- export class NgtsCubeCamera implements OnInit {
136
+ export class NgtsCubeCamera {
144
137
private inputs = signalStore < NgtsCubeCameraComponentState > ( { frames : Infinity } ) ;
145
138
146
139
@Input ( ) cameraRef = injectNgtRef < Group > ( ) ;
147
140
148
141
@ContentChild ( NgtsCubeCameraContent , { static : true , read : TemplateRef } )
149
- private cameraContent ! : TemplateRef < { texture : Signal < THREE . WebGLRenderTarget [ 'texture' ] > } > ;
150
-
151
- @ViewChild ( 'anchor' , { static : true , read : ViewContainerRef } )
152
- private anchor ! : ViewContainerRef ;
142
+ cameraContent ! : TemplateRef < { texture : Signal < THREE . WebGLRenderTarget [ 'texture' ] > } > ;
153
143
154
144
/** Resolution of the FBO, 256 */
155
145
@Input ( { alias : 'resolution' } ) set _resolution ( resolution : number ) {
@@ -177,27 +167,18 @@ export class NgtsCubeCamera implements OnInit {
177
167
}
178
168
179
169
cubeCamera = injectNgtsCubeCamera ( this . inputs . state ) ;
180
- private texture = computed ( ( ) => this . cubeCamera . fbo ( ) . texture ) ;
181
- private contentRef ?: EmbeddedViewRef < unknown > ;
170
+ texture = computed ( ( ) => this . cubeCamera . fbo ( ) . texture ) ;
182
171
183
172
constructor ( ) {
184
173
this . beforeRender ( ) ;
185
- inject ( DestroyRef ) . onDestroy ( ( ) => {
186
- this . contentRef ?. destroy ( ) ;
187
- } ) ;
188
- }
189
-
190
- ngOnInit ( ) {
191
- this . contentRef = this . anchor . createEmbeddedView ( this . cameraContent , { texture : this . texture } ) ;
192
174
}
193
175
194
176
private beforeRender ( ) {
195
177
let count = 0 ;
196
178
injectBeforeRender ( ( ) => {
197
179
const camera = this . cameraRef . nativeElement ;
198
180
if ( ! camera ) return ;
199
- const update = this . cubeCamera . update ( ) ;
200
- const frames = this . inputs . get ( 'frames' ) ;
181
+ const [ update , frames ] = [ this . cubeCamera . update ( ) , this . inputs . get ( 'frames' ) ] ;
201
182
if ( frames === Infinity || count < frames ) {
202
183
camera . visible = false ;
203
184
update ( ) ;
0 commit comments