Skip to content

Commit 9d05d0c

Browse files
committed
fix(soba): move makeDefault up for controls
1 parent 2807f68 commit 9d05d0c

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

libs/soba/controls/src/lib/camera-controls.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
input,
88
output,
99
} from '@angular/core';
10-
import { extend, injectBeforeRender, injectStore, NgtArgs, NgtCamera, omit, pick } from 'angular-three';
10+
import { injectBeforeRender, injectStore, NgtArgs, NgtCamera, omit, pick } from 'angular-three';
1111
import CameraControls from 'camera-controls';
1212
import { mergeInputs } from 'ngxtension/inject-inputs';
1313
import {
@@ -91,7 +91,16 @@ export class NgtsCameraControls {
9191
Vector4,
9292
},
9393
});
94-
extend({ CameraControls });
94+
95+
effect((onCleanup) => {
96+
const makeDefault = this.makeDefault();
97+
if (!makeDefault) return;
98+
99+
const controls = this.controls();
100+
const oldControls = this.store.snapshot.controls;
101+
this.store.update({ controls: controls as unknown as EventDispatcher });
102+
onCleanup(() => void this.store.update({ controls: oldControls }));
103+
});
95104

96105
injectBeforeRender(
97106
({ delta }) => {
@@ -145,15 +154,5 @@ export class NgtsCameraControls {
145154
controls.removeEventListener('wake', callback);
146155
});
147156
});
148-
149-
effect((onCleanup) => {
150-
const makeDefault = this.makeDefault();
151-
if (!makeDefault) return;
152-
153-
const controls = this.controls();
154-
const oldControls = this.store.snapshot.controls;
155-
this.store.update({ controls: controls as unknown as EventDispatcher });
156-
onCleanup(() => void this.store.update({ controls: oldControls }));
157-
});
158157
}
159158
}

libs/soba/controls/src/lib/orbit-controls.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ export class NgtsOrbitControls {
7070
{ priority: -1 },
7171
);
7272

73+
effect((onCleanup) => {
74+
const makeDefault = this.makeDefault();
75+
if (!makeDefault) return;
76+
77+
const controls = this.controls();
78+
if (!controls) return;
79+
80+
const oldControls = this.store.get('controls');
81+
this.store.update({ controls });
82+
onCleanup(() => void this.store.update({ controls: oldControls }));
83+
});
84+
7385
effect((onCleanup) => {
7486
const [keyEvents, domElement, controls] = [
7587
this.keyEvents(),
@@ -87,18 +99,6 @@ export class NgtsOrbitControls {
8799
onCleanup(() => void controls.dispose());
88100
});
89101

90-
effect((onCleanup) => {
91-
const makeDefault = this.makeDefault();
92-
if (!makeDefault) return;
93-
94-
const controls = this.controls();
95-
if (!controls) return;
96-
97-
const oldControls = this.store.get('controls');
98-
this.store.update({ controls });
99-
onCleanup(() => void this.store.update({ controls: oldControls }));
100-
});
101-
102102
effect((onCleanup) => {
103103
const controls = this.controls();
104104
if (!controls) return;

libs/soba/staging/src/lib/bounds.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class NgtsBounds {
106106
if (!controls) return;
107107

108108
const callback = () => {
109-
if (controls && this.goal.target && this.animationState !== AnimationState.NONE) {
109+
if (this.goal.target && this.animationState !== AnimationState.NONE) {
110110
const front = new Vector3().setFromMatrixColumn(camera.matrix, 2);
111111
const d0 = this.origin.camPos.distanceTo(controls.target);
112112
const d1 = (this.goal.camPos || this.origin.camPos).distanceTo(this.goal.target);
@@ -131,8 +131,10 @@ export class NgtsBounds {
131131
this.observe(),
132132
this.size(),
133133
this.camera(),
134+
// TODO: (chau) for some reason, if this effect tracks controls changes, the initial bounds doesn't target properly
134135
this.controls(),
135136
];
137+
136138
if (observe || count++ === 0) {
137139
this.refresh();
138140
if (fit) this.reset().fit();

0 commit comments

Comments
 (0)