Skip to content

Commit ce60420

Browse files
committed
fix(soba): clean up cube camera
1 parent 1125c86 commit ce60420

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

Diff for: libs/soba/cameras/src/cube-camera/cube-camera.ts

+6-25
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ import {
33
CUSTOM_ELEMENTS_SCHEMA,
44
Component,
55
ContentChild,
6-
DestroyRef,
76
Directive,
8-
EmbeddedViewRef,
97
Input,
108
TemplateRef,
11-
ViewChild,
12-
ViewContainerRef,
139
computed,
1410
effect,
15-
inject,
1611
runInInjectionContext,
1712
untracked,
1813
type Injector,
19-
type OnInit,
2014
type Signal,
2115
} from '@angular/core';
2216
import {
@@ -64,8 +58,7 @@ export function injectNgtsCubeCamera(
6458

6559
const store = injectNgtStore();
6660

67-
const _gl = store.select('gl');
68-
const _scene = store.select('scene');
61+
const [_gl, _scene] = [store.select('gl'), store.select('scene')];
6962

7063
const _fbo = computed(() => {
7164
const renderTarget = new THREE.WebGLCubeRenderTarget(resolution());
@@ -133,23 +126,20 @@ export class NgtsCubeCameraContent {
133126
<ngt-group ngtCompound>
134127
<ngt-primitive *args="[cubeCamera.camera()]" />
135128
<ngt-group [ref]="cameraRef">
136-
<ng-container #anchor />
129+
<ng-container *ngTemplateOutlet="cameraContent; context: { texture }" />
137130
</ngt-group>
138131
</ngt-group>
139132
`,
140133
imports: [NgtArgs, NgTemplateOutlet],
141134
schemas: [CUSTOM_ELEMENTS_SCHEMA],
142135
})
143-
export class NgtsCubeCamera implements OnInit {
136+
export class NgtsCubeCamera {
144137
private inputs = signalStore<NgtsCubeCameraComponentState>({ frames: Infinity });
145138

146139
@Input() cameraRef = injectNgtRef<Group>();
147140

148141
@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']> }>;
153143

154144
/** Resolution of the FBO, 256 */
155145
@Input({ alias: 'resolution' }) set _resolution(resolution: number) {
@@ -177,27 +167,18 @@ export class NgtsCubeCamera implements OnInit {
177167
}
178168

179169
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);
182171

183172
constructor() {
184173
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 });
192174
}
193175

194176
private beforeRender() {
195177
let count = 0;
196178
injectBeforeRender(() => {
197179
const camera = this.cameraRef.nativeElement;
198180
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')];
201182
if (frames === Infinity || count < frames) {
202183
camera.visible = false;
203184
update();

0 commit comments

Comments
 (0)