Skip to content

Commit 2f034b7

Browse files
committed
fix(soba/cameras): clean up cameras
1 parent e748675 commit 2f034b7

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

libs/soba/cameras/src/lib/orthographic-camera.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
contentChild,
1010
effect,
1111
input,
12-
untracked,
1312
viewChild,
1413
} from '@angular/core';
1514
import { NgtThreeElements, extend, injectBeforeRender, injectStore, omit, pick } from 'angular-three';
@@ -86,13 +85,15 @@ export class NgtsOrthographicCamera {
8685

8786
private store = injectStore();
8887

89-
private camera = this.store.camera;
90-
private size = this.store.size;
88+
private _left = pick(this.options, 'left');
89+
private _right = pick(this.options, 'right');
90+
private _top = pick(this.options, 'top');
91+
private _bottom = pick(this.options, 'bottom');
9192

92-
protected left = computed(() => this.options().left ?? this.size().width / -2);
93-
protected right = computed(() => this.options().right ?? this.size().width / 2);
94-
protected top = computed(() => this.options().top ?? this.size().height / 2);
95-
protected bottom = computed(() => this.options().bottom ?? this.size().height / -2);
93+
protected left = computed(() => this._left() ?? this.store.size.width() / -2);
94+
protected right = computed(() => this._right() ?? this.store.size.width() / 2);
95+
protected top = computed(() => this._top() ?? this.store.size.height() / 2);
96+
protected bottom = computed(() => this._bottom() ?? this.store.size.height() / -2);
9697

9798
private manual = pick(this.options, 'manual');
9899
private makeDefault = pick(this.options, 'makeDefault');
@@ -120,7 +121,7 @@ export class NgtsOrthographicCamera {
120121
const makeDefault = this.makeDefault();
121122
if (!makeDefault) return;
122123

123-
const oldCam = untracked(this.camera);
124+
const oldCam = this.store.snapshot.camera;
124125
this.store.update({ camera: this.cameraRef().nativeElement });
125126
onCleanup(() => this.store.update(() => ({ camera: oldCam })));
126127
});

libs/soba/cameras/src/lib/perspective-camera.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
contentChild,
99
effect,
1010
input,
11-
untracked,
1211
viewChild,
1312
} from '@angular/core';
1413
import { NgtThreeElements, extend, injectBeforeRender, injectStore, omit, pick } from 'angular-three';
@@ -68,9 +67,6 @@ export class NgtsPerspectiveCamera {
6867

6968
private store = injectStore();
7069

71-
private camera = this.store.camera;
72-
private size = this.store.size;
73-
7470
private manual = pick(this.options, 'manual');
7571
private makeDefault = pick(this.options, 'makeDefault');
7672
private resolution = pick(this.options, 'resolution');
@@ -87,16 +83,20 @@ export class NgtsPerspectiveCamera {
8783
effect(() => {
8884
const manual = this.manual();
8985
if (manual) return;
90-
const [camera, size] = [this.cameraRef().nativeElement, this.size()];
91-
camera.aspect = size.width / size.height;
86+
const [camera, width, height] = [
87+
this.cameraRef().nativeElement,
88+
this.store.size.width(),
89+
this.store.size.height(),
90+
];
91+
camera.aspect = width / height;
9292
camera.updateProjectionMatrix();
9393
});
9494

9595
effect((onCleanup) => {
9696
const makeDefault = this.makeDefault();
9797
if (!makeDefault) return;
9898

99-
const oldCam = untracked(this.camera);
99+
const oldCam = this.store.snapshot.camera;
100100
this.store.update({ camera: this.cameraRef().nativeElement });
101101
onCleanup(() => this.store.update(() => ({ camera: oldCam })));
102102
});

0 commit comments

Comments
 (0)