@vived/app 2.38.0 → 2.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/lib/Entities/AppDispatcher.d.ts +1 -1
  2. package/lib/Entities/FocusCamera.d.ts +70 -0
  3. package/lib/Entities/FocusCamera.js +272 -0
  4. package/lib/PresentationManagers/FocusCameraPM.d.ts +15 -0
  5. package/lib/PresentationManagers/FocusCameraPM.js +31 -0
  6. package/lib/PresentationManagers/FocusCameraPosRotPM.d.ts +13 -0
  7. package/lib/PresentationManagers/FocusCameraPosRotPM.js +28 -0
  8. package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.d.ts +17 -0
  9. package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +64 -0
  10. package/lib/UseCases/FocusCamera/LerpFocusCamera.d.ts +36 -0
  11. package/lib/UseCases/FocusCamera/LerpFocusCamera.js +71 -0
  12. package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.d.ts +11 -0
  13. package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +36 -0
  14. package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.d.ts +11 -0
  15. package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +36 -0
  16. package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.d.ts +11 -0
  17. package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +26 -0
  18. package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.d.ts +11 -0
  19. package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +33 -0
  20. package/lib/UseCases/FocusCamera/SerializeFocusCamera.d.ts +22 -0
  21. package/lib/UseCases/FocusCamera/SerializeFocusCamera.js +81 -0
  22. package/lib/UseCases/FocusCamera/index.d.ts +7 -0
  23. package/lib/UseCases/FocusCamera/index.js +19 -0
  24. package/package.json +1 -1
  25. package/lib/PresentationManagers/IsRenderingPM.d.ts +0 -9
  26. package/lib/PresentationManagers/IsRenderingPM.js +0 -20
  27. package/lib/UseCases/Handlers/SetZSpaceEnabledBase.d.ts +0 -10
  28. package/lib/UseCases/Handlers/SetZSpaceEnabledBase.js +0 -32
@@ -53,6 +53,6 @@ export declare abstract class AppDispatcher {
53
53
  abstract showAlert: (data: ShowAlertDTO) => void;
54
54
  abstract showConfirm: (data: ShowConfirmDTO) => void;
55
55
  abstract showMarkDownEditor: (data: ShowMarkDownEditorDTO) => void;
56
- abstract showSelectModel(callback: (modelId: string) => void): void;
56
+ abstract showSelectModel(callback: (modelId: string, dataId: string) => void): void;
57
57
  }
58
58
  export declare function makeAppDispatcher(): AppDispatcher;
@@ -0,0 +1,70 @@
1
+ import { Vector3 } from "../ValueObjects";
2
+ export declare type OnFocusCameraChange = () => void;
3
+ export interface FocusCameraLerper {
4
+ cancelLerp: () => void;
5
+ }
6
+ export interface FocusCameraData {
7
+ defaultAlpha?: number;
8
+ defaultBeta?: number;
9
+ defaultRadius?: number;
10
+ defaultTarget?: {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ };
15
+ nearClip?: number;
16
+ farClip?: number;
17
+ alphaLimit?: {
18
+ min: number;
19
+ max: number;
20
+ };
21
+ betaLimit?: {
22
+ min: number;
23
+ max: number;
24
+ };
25
+ radiusLimit?: {
26
+ min: number;
27
+ max: number;
28
+ };
29
+ targetLimit?: {
30
+ min: {
31
+ x: number;
32
+ y: number;
33
+ z: number;
34
+ };
35
+ max: {
36
+ x: number;
37
+ y: number;
38
+ z: number;
39
+ };
40
+ };
41
+ }
42
+ export interface FocusCamera {
43
+ alpha: number;
44
+ beta: number;
45
+ radius: number;
46
+ target: Vector3;
47
+ direction: Vector3;
48
+ cameraPosition: Vector3;
49
+ nearClip: number;
50
+ farClip: number;
51
+ defaultAlpha: number;
52
+ defaultBeta: number;
53
+ defaultRadius: number;
54
+ defaultTarget: Vector3;
55
+ setAlphaLimits: (min: number, max: number) => void;
56
+ clearAlphaLimits: () => void;
57
+ setBetaLimits: (min: number, max: number) => void;
58
+ clearBetaLimits: () => void;
59
+ setRadiusLimits: (min: number, max: number) => void;
60
+ clearRadiusLimits: () => void;
61
+ setTargetLimits: (min: Vector3, max: Vector3) => void;
62
+ clearTargetLimits: () => void;
63
+ registerLerp: (lerper: FocusCameraLerper) => void;
64
+ lerpCompleted: () => void;
65
+ cancelLerp: () => void;
66
+ applyData: (data: FocusCameraData) => void;
67
+ addObserver: (observer: OnFocusCameraChange) => void;
68
+ removeObserver: (observer: OnFocusCameraChange) => void;
69
+ }
70
+ export declare function makeFocusCamera(): FocusCamera;
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeFocusCamera = void 0;
4
+ const _1 = require(".");
5
+ const ValueObjects_1 = require("../ValueObjects");
6
+ function makeFocusCamera() {
7
+ return new FocusCameraImp();
8
+ }
9
+ exports.makeFocusCamera = makeFocusCamera;
10
+ class FocusCameraImp {
11
+ constructor() {
12
+ this.farClip = 100;
13
+ this.nearClip = 0.01;
14
+ this.defaultAlpha = 0;
15
+ this.defaultBeta = 30;
16
+ this.defaultRadius = 8;
17
+ this.defaultTarget = ValueObjects_1.Vector3.Zero();
18
+ this.limitRadius = false;
19
+ this.minRadius = 0;
20
+ this.maxRadius = 0;
21
+ this.limitAlpha = false;
22
+ this.minAlpha = 0;
23
+ this.maxAlpha = 0;
24
+ this.limitBeta = false;
25
+ this.minBeta = 0;
26
+ this.maxBeta = 0;
27
+ this.limitTarget = false;
28
+ this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
29
+ this.minTargetPosition = ValueObjects_1.Vector3.Zero();
30
+ this.observers = new _1.ObserverList();
31
+ this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
32
+ this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
33
+ this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
34
+ this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.Zero(), this.observers.notify);
35
+ this.setRadiusLimits = (min, max) => {
36
+ let minToUse = min;
37
+ let maxToUse = max;
38
+ if (min < 0) {
39
+ console.warn("[Orbit Camera Entity] Mininum Radius must be greater >= 0, forcing to 0");
40
+ minToUse = 0;
41
+ }
42
+ if (max < minToUse) {
43
+ console.warn(`[Orbit Camera] Max radius must be >= min radius. Forcing to ${minToUse}`);
44
+ maxToUse = minToUse;
45
+ }
46
+ this.maxRadius = maxToUse;
47
+ this.minRadius = minToUse;
48
+ this.limitRadius = true;
49
+ this.radius = this.radius;
50
+ };
51
+ this.clearRadiusLimits = () => {
52
+ this.maxRadius = 0;
53
+ this.minRadius = 0;
54
+ this.limitRadius = false;
55
+ };
56
+ this.setAlphaLimits = (min, max) => {
57
+ let minToUse = min;
58
+ let maxToUse = max;
59
+ if (min < -180) {
60
+ minToUse = -180;
61
+ console.warn("[Orbit Camera] Min alpha must be >= -180. Forcing to -180");
62
+ }
63
+ if (max > 180) {
64
+ maxToUse = 180;
65
+ console.warn("[Orbit Camera] Max alpha must be <= 180. Forcing to 180");
66
+ }
67
+ if (minToUse > maxToUse) {
68
+ const absMin = Math.abs(minToUse);
69
+ const absMax = Math.abs(maxToUse);
70
+ const closestToZero = absMin < absMax ? minToUse : maxToUse;
71
+ minToUse = closestToZero;
72
+ maxToUse = closestToZero;
73
+ console.warn(`[Orbit Camera] Max alpha must be <= Min Alpha. Forcing to ${closestToZero}`);
74
+ }
75
+ this.maxAlpha = maxToUse;
76
+ this.minAlpha = minToUse;
77
+ this.limitAlpha = true;
78
+ this.alpha = this.alpha;
79
+ };
80
+ this.clearAlphaLimits = () => {
81
+ this.maxAlpha = 0;
82
+ this.minAlpha = 0;
83
+ this.limitAlpha = false;
84
+ };
85
+ this.setBetaLimits = (min, max) => {
86
+ let minToUse = min;
87
+ let maxToUse = max;
88
+ if (min < -180) {
89
+ minToUse = -180;
90
+ console.warn("[Orbit Camera] Min beta must be >= -180. Forcing to -180");
91
+ }
92
+ if (max > 180) {
93
+ maxToUse = 180;
94
+ console.warn("[Orbit Camera] Max beta must be <= 180. Forcing to 180");
95
+ }
96
+ if (minToUse > maxToUse) {
97
+ const absMin = Math.abs(minToUse);
98
+ const absMax = Math.abs(maxToUse);
99
+ const closestToZero = absMin < absMax ? minToUse : maxToUse;
100
+ minToUse = closestToZero;
101
+ maxToUse = closestToZero;
102
+ console.warn(`[Orbit Camera] Max beta must be <= Min beta. Forcing to ${closestToZero}`);
103
+ }
104
+ this.maxBeta = maxToUse;
105
+ this.minBeta = minToUse;
106
+ this.limitBeta = true;
107
+ this.beta = this.beta;
108
+ };
109
+ this.clearBetaLimits = () => {
110
+ this.maxBeta = 0;
111
+ this.minBeta = 0;
112
+ this.limitBeta = false;
113
+ };
114
+ this.setTargetLimits = (min, max) => {
115
+ const minArray = min.array;
116
+ const maxArray = max.array;
117
+ for (let i = 0; i < 3; i++) {
118
+ if (minArray[i] > maxArray[i]) {
119
+ console.warn("[Orbit Camera] Target limit min's components must all be <= the max. Limits not set");
120
+ return;
121
+ }
122
+ }
123
+ this.maxTargetPosition = max;
124
+ this.minTargetPosition = min;
125
+ this.limitTarget = true;
126
+ this.target = this.target;
127
+ };
128
+ this.clearTargetLimits = () => {
129
+ this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
130
+ this.minTargetPosition = ValueObjects_1.Vector3.Zero();
131
+ this.limitTarget = false;
132
+ };
133
+ this.registerLerp = (lerper) => {
134
+ if (this.currentLerp) {
135
+ this.currentLerp.cancelLerp();
136
+ }
137
+ this.currentLerp = lerper;
138
+ };
139
+ this.lerpCompleted = () => {
140
+ this.currentLerp = undefined;
141
+ };
142
+ this.cancelLerp = () => {
143
+ var _a;
144
+ (_a = this.currentLerp) === null || _a === void 0 ? void 0 : _a.cancelLerp();
145
+ this.currentLerp = undefined;
146
+ };
147
+ this.applyData = (data) => {
148
+ if (data.defaultAlpha !== undefined) {
149
+ this.defaultAlpha = data.defaultAlpha;
150
+ }
151
+ if (data.defaultBeta !== undefined) {
152
+ this.defaultBeta = data.defaultBeta;
153
+ }
154
+ if (data.defaultRadius !== undefined) {
155
+ this.defaultRadius = data.defaultRadius;
156
+ }
157
+ if (data.defaultTarget !== undefined) {
158
+ const { x, y, z } = data.defaultTarget;
159
+ this.defaultTarget = new ValueObjects_1.Vector3(x, y, z);
160
+ }
161
+ if (data.nearClip !== undefined) {
162
+ this.nearClip = data.nearClip;
163
+ }
164
+ if (data.farClip !== undefined) {
165
+ this.farClip = data.farClip;
166
+ }
167
+ if (data.alphaLimit !== undefined) {
168
+ this.setAlphaLimits(data.alphaLimit.min, data.alphaLimit.max);
169
+ }
170
+ if (data.betaLimit !== undefined) {
171
+ this.setBetaLimits(data.betaLimit.min, data.betaLimit.max);
172
+ }
173
+ if (data.radiusLimit !== undefined) {
174
+ this.setRadiusLimits(data.radiusLimit.min, data.radiusLimit.max);
175
+ }
176
+ if (data.targetLimit !== undefined) {
177
+ const { max, min } = data.targetLimit;
178
+ this.setTargetLimits(new ValueObjects_1.Vector3(min.x, min.y, min.z), new ValueObjects_1.Vector3(max.x, max.y, max.z));
179
+ }
180
+ };
181
+ this.addObserver = (observer) => {
182
+ this.observers.add(observer);
183
+ };
184
+ this.removeObserver = (observer) => {
185
+ this.observers.remove(observer);
186
+ };
187
+ }
188
+ get alpha() {
189
+ return this.memoizedAlpha.val;
190
+ }
191
+ set alpha(val) {
192
+ let valToUse = val;
193
+ if (this.limitAlpha) {
194
+ valToUse = Math.min(valToUse, this.maxAlpha);
195
+ valToUse = Math.max(valToUse, this.minAlpha);
196
+ }
197
+ else {
198
+ valToUse = this.clampAngle(val);
199
+ }
200
+ this.memoizedAlpha.val = valToUse;
201
+ }
202
+ get beta() {
203
+ return this.memoizedBeta.val;
204
+ }
205
+ set beta(val) {
206
+ let valToUse = val;
207
+ if (this.limitBeta) {
208
+ valToUse = Math.min(valToUse, this.maxBeta);
209
+ valToUse = Math.max(valToUse, this.minBeta);
210
+ }
211
+ else {
212
+ valToUse = this.clampAngle(val);
213
+ }
214
+ this.memoizedBeta.val = valToUse;
215
+ }
216
+ get radius() {
217
+ return this.memoizedRadius.val;
218
+ }
219
+ set radius(val) {
220
+ let clampedVal = Math.max(val, 0);
221
+ if (this.limitRadius) {
222
+ clampedVal = Math.min(clampedVal, this.maxRadius);
223
+ clampedVal = Math.max(clampedVal, this.minRadius);
224
+ }
225
+ this.memoizedRadius.val = clampedVal;
226
+ }
227
+ get target() {
228
+ return this.memoizedTarget.val;
229
+ }
230
+ set target(val) {
231
+ const targetVals = val.array;
232
+ if (this.limitTarget) {
233
+ const maxVals = this.maxTargetPosition.array;
234
+ const minVals = this.minTargetPosition.array;
235
+ for (let i = 0; i < 3; i++) {
236
+ let v = targetVals[i];
237
+ v = Math.min(v, maxVals[i]);
238
+ v = Math.max(v, minVals[i]);
239
+ targetVals[i] = v;
240
+ }
241
+ }
242
+ this.memoizedTarget.val = ValueObjects_1.Vector3.FromArray(targetVals);
243
+ }
244
+ get direction() {
245
+ const yLength = -Math.sin(this.degToRad(this.beta));
246
+ const horizontalLenght = Math.cos(this.degToRad(this.beta));
247
+ const alphaRadians = this.degToRad(this.alpha);
248
+ const xLength = horizontalLenght * Math.sin(alphaRadians);
249
+ const zLength = horizontalLenght * Math.cos(alphaRadians);
250
+ return new ValueObjects_1.Vector3(xLength, yLength, zLength);
251
+ }
252
+ get cameraPosition() {
253
+ const localOffset = ValueObjects_1.Vector3.NewVectorOfLength(this.direction, -this.radius);
254
+ return ValueObjects_1.Vector3.Add(this.target, localOffset);
255
+ }
256
+ degToRad(degrees) {
257
+ return (degrees * Math.PI) / 180;
258
+ }
259
+ clampAngle(angle) {
260
+ const isNegative = angle < 0 ? true : false;
261
+ const absAngle = Math.abs(angle);
262
+ const revolutions = Math.floor(absAngle / 360);
263
+ let angleWithoutRevolutions = absAngle - revolutions * 360;
264
+ if (angleWithoutRevolutions > 180) {
265
+ angleWithoutRevolutions = angleWithoutRevolutions - 360;
266
+ }
267
+ if (isNegative) {
268
+ angleWithoutRevolutions *= -1;
269
+ }
270
+ return angleWithoutRevolutions;
271
+ }
272
+ }
@@ -0,0 +1,15 @@
1
+ import { FocusCamera } from "../Entities";
2
+ import { Vector3 } from "../ValueObjects";
3
+ export interface FocusCameraVM {
4
+ alphaEuler: Vector3;
5
+ betaEuler: Vector3;
6
+ cameraLocalPosition: Vector3;
7
+ target: Vector3;
8
+ }
9
+ export declare class FocusCameraPM {
10
+ private orbitCam;
11
+ private view;
12
+ dispose(): void;
13
+ private doUpdateView;
14
+ constructor(orbitCamera: FocusCamera, view: (vm: FocusCameraVM) => void);
15
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FocusCameraPM = void 0;
4
+ const Utilities_1 = require("../Utilities");
5
+ const ValueObjects_1 = require("../ValueObjects");
6
+ class FocusCameraPM {
7
+ constructor(orbitCamera, view) {
8
+ this.doUpdateView = () => {
9
+ const { alpha, beta, radius, target } = this.orbitCam;
10
+ const alphaRadians = Utilities_1.degreesToRadians(alpha);
11
+ const alphaEuler = new ValueObjects_1.Vector3(0, alphaRadians, 0);
12
+ const betaRadians = Utilities_1.degreesToRadians(beta);
13
+ const betaEuler = new ValueObjects_1.Vector3(betaRadians, 0, 0);
14
+ const cameraLocalPosition = new ValueObjects_1.Vector3(0, 0, -radius);
15
+ this.view({
16
+ alphaEuler,
17
+ betaEuler,
18
+ cameraLocalPosition,
19
+ target,
20
+ });
21
+ };
22
+ this.orbitCam = orbitCamera;
23
+ this.view = view;
24
+ this.doUpdateView();
25
+ this.orbitCam.addObserver(this.doUpdateView);
26
+ }
27
+ dispose() {
28
+ this.orbitCam.removeObserver(this.doUpdateView);
29
+ }
30
+ }
31
+ exports.FocusCameraPM = FocusCameraPM;
@@ -0,0 +1,13 @@
1
+ import { FocusCamera } from "../Entities";
2
+ import { Vector3 } from "../ValueObjects";
3
+ export interface FocusCameraPosRotVM {
4
+ position: Vector3;
5
+ rotation: Vector3;
6
+ }
7
+ export declare class FocusCameraPosRotPM {
8
+ private focusCam;
9
+ private view;
10
+ dispose(): void;
11
+ private doUpdateView;
12
+ constructor(orbitCamera: FocusCamera, view: (vm: FocusCameraPosRotVM) => void);
13
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FocusCameraPosRotPM = void 0;
4
+ const Utilities_1 = require("../Utilities");
5
+ const ValueObjects_1 = require("../ValueObjects");
6
+ class FocusCameraPosRotPM {
7
+ constructor(orbitCamera, view) {
8
+ this.doUpdateView = () => {
9
+ const { alpha, beta } = this.focusCam;
10
+ const alphaRadians = Utilities_1.degreesToRadians(alpha);
11
+ const betaRadians = Utilities_1.degreesToRadians(beta);
12
+ const position = this.focusCam.cameraPosition;
13
+ const rotation = new ValueObjects_1.Vector3(betaRadians, alphaRadians, 0);
14
+ this.view({
15
+ position,
16
+ rotation,
17
+ });
18
+ };
19
+ this.focusCam = orbitCamera;
20
+ this.view = view;
21
+ this.doUpdateView();
22
+ this.focusCam.addObserver(this.doUpdateView);
23
+ }
24
+ dispose() {
25
+ this.focusCam.removeObserver(this.doUpdateView);
26
+ }
27
+ }
28
+ exports.FocusCameraPosRotPM = FocusCameraPosRotPM;
@@ -0,0 +1,17 @@
1
+ import { FocusCamera } from "../../Entities";
2
+ import { Vector3 } from "../../ValueObjects";
3
+ export declare class BumpDollyFocusCamera {
4
+ private focusCamera;
5
+ bumpDurationMS: number;
6
+ bumpLerp: (percent: number) => number;
7
+ bumpAmount: number;
8
+ private interval?;
9
+ private chrono;
10
+ private delta;
11
+ private initialRadius;
12
+ private finalRadius;
13
+ private pickPoint?;
14
+ private onTick;
15
+ bump(direction: "IN" | "OUT", target?: Vector3): void;
16
+ constructor(focusCamera: FocusCamera);
17
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BumpDollyFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class BumpDollyFocusCamera {
6
+ constructor(focusCamera) {
7
+ this.focusCamera = focusCamera;
8
+ this.bumpDurationMS = 500;
9
+ this.bumpLerp = (p) => {
10
+ return p;
11
+ }; // Linear
12
+ this.bumpAmount = 0.1;
13
+ this.chrono = 0;
14
+ this.delta = 10;
15
+ this.initialRadius = 0;
16
+ this.finalRadius = 0;
17
+ this.onTick = () => {
18
+ this.chrono = this.chrono + this.delta;
19
+ let nomralizedTime = this.chrono / this.bumpDurationMS;
20
+ if (nomralizedTime > 1) {
21
+ nomralizedTime = 1;
22
+ }
23
+ const percent = this.bumpLerp(nomralizedTime);
24
+ const range = this.finalRadius - this.initialRadius;
25
+ const currentRadius = this.focusCamera.radius;
26
+ this.focusCamera.radius = this.initialRadius + range * percent;
27
+ if (this.pickPoint !== undefined) {
28
+ const percentChange = this.focusCamera.radius / currentRadius;
29
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
30
+ const newLength = pickToTarget.magnitued * percentChange;
31
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
32
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
33
+ this.focusCamera.target = newTargetPos;
34
+ }
35
+ if (nomralizedTime >= 1 && this.interval) {
36
+ this.focusCamera.radius = this.finalRadius;
37
+ clearInterval(this.interval);
38
+ this.interval = undefined;
39
+ this.pickPoint = undefined;
40
+ }
41
+ };
42
+ }
43
+ bump(direction, target) {
44
+ let delta = this.bumpAmount;
45
+ if (direction === "IN") {
46
+ delta *= -1;
47
+ }
48
+ this.initialRadius = this.focusCamera.radius;
49
+ if (this.interval) {
50
+ clearInterval(this.interval);
51
+ this.interval = undefined;
52
+ this.finalRadius = this.finalRadius + delta;
53
+ }
54
+ else {
55
+ this.finalRadius = this.initialRadius + delta;
56
+ }
57
+ this.chrono = 0;
58
+ this.pickPoint = target;
59
+ this.interval = setInterval(() => {
60
+ this.onTick();
61
+ }, 10);
62
+ }
63
+ }
64
+ exports.BumpDollyFocusCamera = BumpDollyFocusCamera;
@@ -0,0 +1,36 @@
1
+ import { FocusCamera } from "../../Entities";
2
+ export interface LerpFocusCameraParameters {
3
+ duration: number;
4
+ finalRadius?: number;
5
+ finalBeta?: number;
6
+ finalAlpha?: number;
7
+ finalTarget?: {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ };
12
+ onComplete?: () => void;
13
+ onAbort?: () => void;
14
+ }
15
+ export declare class LerpFocusCamera {
16
+ get isLerping(): boolean;
17
+ private _isLerping;
18
+ private focusCamera;
19
+ private easeFn;
20
+ private lerpDuration;
21
+ private lerpRadius;
22
+ private lerpBeta;
23
+ private lerpAlpha;
24
+ private lerpX;
25
+ private lerpY;
26
+ private lerpZ;
27
+ private onComplete?;
28
+ private onAbort?;
29
+ private interval;
30
+ private chrono;
31
+ private delta;
32
+ cancelLerp: () => void;
33
+ private onTick;
34
+ constructor(focusCamera: FocusCamera, easeFn: (normalizedTime: number) => number, parameters: LerpFocusCameraParameters);
35
+ private makeLerpNumber;
36
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LerpFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class LerpFocusCamera {
6
+ constructor(focusCamera, easeFn, parameters) {
7
+ var _a, _b, _c;
8
+ this._isLerping = false;
9
+ this.chrono = 0;
10
+ this.delta = 10;
11
+ this.cancelLerp = () => {
12
+ if (!this._isLerping)
13
+ return;
14
+ clearInterval(this.interval);
15
+ if (this.onAbort) {
16
+ this.onAbort();
17
+ }
18
+ this._isLerping = false;
19
+ };
20
+ this.onTick = () => {
21
+ this.chrono = this.chrono + this.delta / 1000;
22
+ let nomralizedTime = this.chrono / this.lerpDuration;
23
+ if (nomralizedTime > 1) {
24
+ nomralizedTime = 1;
25
+ }
26
+ const percent = this.easeFn(nomralizedTime);
27
+ this.focusCamera.radius = this.lerpRadius(percent);
28
+ this.focusCamera.beta = this.lerpBeta(percent);
29
+ this.focusCamera.alpha = this.lerpAlpha(percent);
30
+ const x = this.lerpX(percent);
31
+ const y = this.lerpY(percent);
32
+ const z = this.lerpZ(percent);
33
+ this.focusCamera.target = new ValueObjects_1.Vector3(x, y, z);
34
+ if (nomralizedTime >= 1) {
35
+ clearInterval(this.interval);
36
+ if (this.onComplete) {
37
+ this.onComplete();
38
+ }
39
+ this._isLerping = false;
40
+ this.focusCamera.lerpCompleted();
41
+ }
42
+ };
43
+ this.focusCamera = focusCamera;
44
+ this.easeFn = easeFn;
45
+ this.lerpDuration = parameters.duration;
46
+ this.onComplete = parameters.onComplete;
47
+ this.onAbort = parameters.onAbort;
48
+ this.lerpRadius = this.makeLerpNumber(this.focusCamera.radius, parameters.finalRadius);
49
+ this.lerpBeta = this.makeLerpNumber(this.focusCamera.beta, parameters.finalBeta);
50
+ this.lerpAlpha = this.makeLerpNumber(this.focusCamera.alpha, parameters.finalAlpha);
51
+ this.lerpX = this.makeLerpNumber(this.focusCamera.target.x, (_a = parameters.finalTarget) === null || _a === void 0 ? void 0 : _a.x);
52
+ this.lerpY = this.makeLerpNumber(this.focusCamera.target.y, (_b = parameters.finalTarget) === null || _b === void 0 ? void 0 : _b.y);
53
+ this.lerpZ = this.makeLerpNumber(this.focusCamera.target.z, (_c = parameters.finalTarget) === null || _c === void 0 ? void 0 : _c.z);
54
+ this.interval = setInterval(() => {
55
+ this.onTick();
56
+ }, this.delta);
57
+ this.focusCamera.registerLerp(this);
58
+ this._isLerping = true;
59
+ }
60
+ get isLerping() {
61
+ return this._isLerping;
62
+ }
63
+ makeLerpNumber(initial, final) {
64
+ const actualFinal = final !== null && final !== void 0 ? final : initial;
65
+ return function Lerp(percent) {
66
+ const range = actualFinal - initial;
67
+ return initial + range * percent;
68
+ };
69
+ }
70
+ }
71
+ exports.LerpFocusCamera = LerpFocusCamera;
@@ -0,0 +1,11 @@
1
+ import { FocusCamera } from "../../Entities";
2
+ import { Vector3 } from "../../ValueObjects";
3
+ export declare class PinchDollyFocusCamera {
4
+ private focusCamera;
5
+ sensitivity: number;
6
+ private previousDistanceBetweenTouches;
7
+ private pickPoint?;
8
+ doDolly: (distanceBetweenTouches: number) => void;
9
+ initializeDolly: (distanceBetweenTouches: number, pickPoint?: Vector3 | undefined) => void;
10
+ constructor(focusCamera: FocusCamera);
11
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PinchDollyFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class PinchDollyFocusCamera {
6
+ constructor(focusCamera) {
7
+ this.focusCamera = focusCamera;
8
+ this.sensitivity = 0.05;
9
+ this.previousDistanceBetweenTouches = 0;
10
+ this.doDolly = (distanceBetweenTouches) => {
11
+ const pinchDelta = distanceBetweenTouches - this.previousDistanceBetweenTouches;
12
+ const deltaRadius = pinchDelta * this.sensitivity;
13
+ const currentRadius = this.focusCamera.radius;
14
+ this.focusCamera.radius = currentRadius - deltaRadius;
15
+ if (this.pickPoint !== undefined) {
16
+ const percentChange = this.focusCamera.radius / currentRadius;
17
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
18
+ const newLength = pickToTarget.magnitued * percentChange;
19
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
20
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
21
+ this.focusCamera.target = newTargetPos;
22
+ }
23
+ this.previousDistanceBetweenTouches = distanceBetweenTouches;
24
+ };
25
+ this.initializeDolly = (distanceBetweenTouches, pickPoint) => {
26
+ this.previousDistanceBetweenTouches = distanceBetweenTouches;
27
+ if (pickPoint) {
28
+ this.pickPoint = pickPoint;
29
+ }
30
+ else {
31
+ this.pickPoint = undefined;
32
+ }
33
+ };
34
+ }
35
+ }
36
+ exports.PinchDollyFocusCamera = PinchDollyFocusCamera;
@@ -0,0 +1,11 @@
1
+ import { FocusCamera } from "../../Entities";
2
+ import { Vector2, Vector3 } from "../../ValueObjects";
3
+ export declare class PixelDollyFocusCamera {
4
+ private focusCamera;
5
+ sensitivity: number;
6
+ private previousPixelPosition;
7
+ private pickPoint?;
8
+ doDolly: (pixelPosition: Vector2) => void;
9
+ initializeDolly: (pixelPosition: Vector2, pickPoint?: Vector3 | undefined) => void;
10
+ constructor(focusCamera: FocusCamera);
11
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelDollyFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class PixelDollyFocusCamera {
6
+ constructor(focusCamera) {
7
+ this.focusCamera = focusCamera;
8
+ this.sensitivity = 0.05;
9
+ this.previousPixelPosition = ValueObjects_1.Vector2.Zero();
10
+ this.doDolly = (pixelPosition) => {
11
+ const pixelDeltaY = pixelPosition.y - this.previousPixelPosition.y;
12
+ const deltaRadius = pixelDeltaY * this.sensitivity;
13
+ const currentRadius = this.focusCamera.radius;
14
+ this.focusCamera.radius = currentRadius - deltaRadius;
15
+ if (this.pickPoint !== undefined) {
16
+ const percentChange = this.focusCamera.radius / currentRadius;
17
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
18
+ const newLength = pickToTarget.magnitued * percentChange;
19
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
20
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
21
+ this.focusCamera.target = newTargetPos;
22
+ }
23
+ this.previousPixelPosition = pixelPosition;
24
+ };
25
+ this.initializeDolly = (pixelPosition, pickPoint) => {
26
+ this.previousPixelPosition = pixelPosition;
27
+ if (pickPoint) {
28
+ this.pickPoint = pickPoint;
29
+ }
30
+ else {
31
+ this.pickPoint = undefined;
32
+ }
33
+ };
34
+ }
35
+ }
36
+ exports.PixelDollyFocusCamera = PixelDollyFocusCamera;
@@ -0,0 +1,11 @@
1
+ import { FocusCamera } from "../../Entities";
2
+ import { Vector2, Vector3 } from "../../ValueObjects";
3
+ export declare class PixelOrbitFocusCamera {
4
+ private focusCamera;
5
+ sensitivity: number;
6
+ private previousPixelPos?;
7
+ private pickPoint?;
8
+ doOrbit: (pixelPosition: Vector2) => void;
9
+ initializeOrbit: (initialPixelPos: Vector2, pickPoint?: Vector3 | undefined) => void;
10
+ constructor(focusCamera: FocusCamera);
11
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelOrbitFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class PixelOrbitFocusCamera {
6
+ constructor(focusCamera) {
7
+ this.focusCamera = focusCamera;
8
+ this.sensitivity = 0.5;
9
+ this.doOrbit = (pixelPosition) => {
10
+ if (!this.previousPixelPos) {
11
+ console.error("[PixelOrbitFocusCamera] You must initialize first!");
12
+ return;
13
+ }
14
+ const pixelChange = ValueObjects_1.Vector2.Subtract(pixelPosition, this.previousPixelPos);
15
+ this.focusCamera.alpha += pixelChange.x * this.sensitivity;
16
+ this.focusCamera.beta += pixelChange.y * this.sensitivity;
17
+ this.previousPixelPos = pixelPosition;
18
+ };
19
+ this.initializeOrbit = (initialPixelPos, pickPoint) => {
20
+ this.previousPixelPos = initialPixelPos;
21
+ this.pickPoint = pickPoint;
22
+ this.focusCamera.cancelLerp();
23
+ };
24
+ }
25
+ }
26
+ exports.PixelOrbitFocusCamera = PixelOrbitFocusCamera;
@@ -0,0 +1,11 @@
1
+ import { Babylon, FocusCamera } from "../../Entities";
2
+ import { ParametricPlane, Vector2 } from "../../ValueObjects";
3
+ export declare class PixelPlanePanFocusCamera {
4
+ private focusCamera;
5
+ private babylon;
6
+ private plane?;
7
+ private previousPixelPos?;
8
+ doPan: (pixelPosition: Vector2) => void;
9
+ initializePan: (initialPixelPos: Vector2, panPlane: ParametricPlane) => void;
10
+ constructor(focusCamera: FocusCamera, babylon: Babylon);
11
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelPlanePanFocusCamera = void 0;
4
+ const ValueObjects_1 = require("../../ValueObjects");
5
+ class PixelPlanePanFocusCamera {
6
+ constructor(focusCamera, babylon) {
7
+ this.focusCamera = focusCamera;
8
+ this.babylon = babylon;
9
+ this.doPan = (pixelPosition) => {
10
+ if (!this.plane || !this.previousPixelPos) {
11
+ console.error("[PixelPlanePan_OrbitCamera] You must initialize first!");
12
+ return;
13
+ }
14
+ const initialRay = this.babylon.sceneRay(this.previousPixelPos);
15
+ const finalRay = this.babylon.sceneRay(pixelPosition);
16
+ const p1 = this.plane.intersectLine(initialRay);
17
+ const p2 = this.plane.intersectLine(finalRay);
18
+ if (!p1 || !p2)
19
+ return;
20
+ const delta = ValueObjects_1.Vector3.Subtract(p2, p1);
21
+ const currentTarget = this.focusCamera.target;
22
+ const newTarget = new ValueObjects_1.Vector3(currentTarget.x - delta.x, currentTarget.y - delta.y, currentTarget.z - delta.z);
23
+ this.focusCamera.target = new ValueObjects_1.Vector3(newTarget.x, newTarget.y, newTarget.z);
24
+ this.previousPixelPos = pixelPosition;
25
+ };
26
+ this.initializePan = (initialPixelPos, panPlane) => {
27
+ this.plane = panPlane;
28
+ this.previousPixelPos = initialPixelPos;
29
+ this.focusCamera.cancelLerp();
30
+ };
31
+ }
32
+ }
33
+ exports.PixelPlanePanFocusCamera = PixelPlanePanFocusCamera;
@@ -0,0 +1,22 @@
1
+ import { FocusCamera, SerializedSystem, StateMachine } from "../../Entities";
2
+ export declare class SerializeFocusCamera implements SerializedSystem {
3
+ name: string;
4
+ seriliziationVersion: number;
5
+ private focusCamera;
6
+ private stateMachine;
7
+ getSystemState(): object;
8
+ applySystemState(serializedState: object, version: number, transitionTime: number): void;
9
+ applyDefaultState(transitionDuration: number): void;
10
+ private applyV1Data;
11
+ private applyImmediate;
12
+ private applyLerp;
13
+ constructor(focusCamera: FocusCamera, stateMachine: StateMachine);
14
+ }
15
+ export interface FocusCameraDataV1 {
16
+ alpha: number;
17
+ beta: number;
18
+ radius: number;
19
+ target_x: number;
20
+ target_y: number;
21
+ target_z: number;
22
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializeFocusCamera = void 0;
4
+ const _1 = require(".");
5
+ const ValueObjects_1 = require("../../ValueObjects");
6
+ class SerializeFocusCamera {
7
+ constructor(focusCamera, stateMachine) {
8
+ this.name = "focusCamera";
9
+ this.seriliziationVersion = 1;
10
+ this.focusCamera = focusCamera;
11
+ this.stateMachine = stateMachine;
12
+ stateMachine.registerSerializedSystem(this);
13
+ }
14
+ getSystemState() {
15
+ const data = {
16
+ alpha: this.focusCamera.alpha,
17
+ beta: this.focusCamera.beta,
18
+ radius: this.focusCamera.radius,
19
+ target_x: this.focusCamera.target.x,
20
+ target_y: this.focusCamera.target.y,
21
+ target_z: this.focusCamera.target.z,
22
+ };
23
+ return data;
24
+ }
25
+ applySystemState(serializedState, version, transitionTime) {
26
+ try {
27
+ if (version === 1) {
28
+ const castState = serializedState;
29
+ this.applyV1Data(castState, transitionTime);
30
+ }
31
+ else {
32
+ console.warn(`[SerializeFocusCamera] Unsupported version number ${version}. Defaulting`);
33
+ this.applyDefaultState(transitionTime);
34
+ }
35
+ }
36
+ catch (e) {
37
+ console.warn(`[SerializeFocusCamera] Caught when deserializing ${e}. Defaulting`);
38
+ this.applyDefaultState(transitionTime);
39
+ }
40
+ }
41
+ applyDefaultState(transitionDuration) {
42
+ const alpha = this.focusCamera.defaultAlpha;
43
+ const beta = this.focusCamera.defaultBeta;
44
+ const radius = this.focusCamera.defaultRadius;
45
+ const target = this.focusCamera.defaultTarget;
46
+ if (transitionDuration === 0) {
47
+ this.applyImmediate(alpha, beta, radius, target);
48
+ }
49
+ else {
50
+ this.applyLerp(alpha, beta, radius, target, transitionDuration);
51
+ }
52
+ }
53
+ applyV1Data(data, transitionTime) {
54
+ const { alpha, beta, radius, target_x, target_y, target_z } = data;
55
+ const target = new ValueObjects_1.Vector3(target_x, target_y, target_z);
56
+ if (transitionTime === 0) {
57
+ this.applyImmediate(alpha, beta, radius, target);
58
+ }
59
+ else {
60
+ this.applyLerp(alpha, beta, radius, target, transitionTime);
61
+ }
62
+ }
63
+ applyImmediate(alpha, beta, radius, target) {
64
+ this.focusCamera.cancelLerp();
65
+ this.focusCamera.alpha = alpha;
66
+ this.focusCamera.beta = beta;
67
+ this.focusCamera.radius = radius;
68
+ this.focusCamera.target = target;
69
+ }
70
+ applyLerp(alpha, beta, radius, target, transitionTime) {
71
+ const lerpParams = {
72
+ duration: transitionTime,
73
+ finalRadius: radius,
74
+ finalBeta: beta,
75
+ finalAlpha: alpha,
76
+ finalTarget: target,
77
+ };
78
+ new _1.LerpFocusCamera(this.focusCamera, this.stateMachine.transitionEaseFunction, lerpParams);
79
+ }
80
+ }
81
+ exports.SerializeFocusCamera = SerializeFocusCamera;
@@ -0,0 +1,7 @@
1
+ export * from "./PixelPlanePanFocusCamera";
2
+ export * from "./LerpFocusCamera";
3
+ export * from "./SerializeFocusCamera";
4
+ export * from "./PixelDollyFocusCamera";
5
+ export * from "./BumpDollyFocusCamera";
6
+ export * from "./PinchDollyFocusCamera";
7
+ export * from "./PixelOrbitFocusCamera";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./PixelPlanePanFocusCamera"), exports);
14
+ __exportStar(require("./LerpFocusCamera"), exports);
15
+ __exportStar(require("./SerializeFocusCamera"), exports);
16
+ __exportStar(require("./PixelDollyFocusCamera"), exports);
17
+ __exportStar(require("./BumpDollyFocusCamera"), exports);
18
+ __exportStar(require("./PinchDollyFocusCamera"), exports);
19
+ __exportStar(require("./PixelOrbitFocusCamera"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.38.0",
3
+ "version": "2.39.0",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,9 +0,0 @@
1
- import { BaseApp } from "../Entities";
2
- import { PresentionManager } from "./PresentationManager";
3
- export declare class IsRenderingPM extends PresentionManager {
4
- private baseApp;
5
- private updateView;
6
- private lastSetState?;
7
- doUpdateView: () => void;
8
- constructor(baseApp: BaseApp, updateView: (isAuthoring: boolean) => void);
9
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsRenderingPM = void 0;
4
- const PresentationManager_1 = require("./PresentationManager");
5
- class IsRenderingPM extends PresentationManager_1.PresentionManager {
6
- constructor(baseApp, updateView) {
7
- super(baseApp);
8
- this.baseApp = baseApp;
9
- this.updateView = updateView;
10
- this.doUpdateView = () => {
11
- const isRendering = this.baseApp.isRendering;
12
- if (isRendering === this.lastSetState)
13
- return;
14
- this.updateView(isRendering);
15
- this.lastSetState = isRendering;
16
- };
17
- this.doUpdateView();
18
- }
19
- }
20
- exports.IsRenderingPM = IsRenderingPM;
@@ -1,10 +0,0 @@
1
- import { AppHandler, RequestHandler } from "../../Entities";
2
- export declare type SetZSpaceEnabledAction = (isEnabled: boolean) => void;
3
- export declare class SetZSpaceEnabledBase extends RequestHandler {
4
- readonly requestType = "SET_ZSPACE_ENABLED";
5
- readonly payloadVersion = 1;
6
- action: SetZSpaceEnabledAction;
7
- handleRequest: (version: number, payload: unknown) => void;
8
- private castPayloadV1;
9
- constructor(handler: AppHandler);
10
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetZSpaceEnabledBase = void 0;
4
- const Entities_1 = require("../../Entities");
5
- class SetZSpaceEnabledBase extends Entities_1.RequestHandler {
6
- constructor(handler) {
7
- super();
8
- this.requestType = "SET_ZSPACE_ENABLED";
9
- this.payloadVersion = 1;
10
- this.action = () => {
11
- throw new Entities_1.ActionNotImplemented(this.requestType);
12
- };
13
- this.handleRequest = (version, payload) => {
14
- if (version === this.payloadVersion) {
15
- const { isEnabled } = this.castPayloadV1(payload);
16
- this.action(isEnabled);
17
- }
18
- else {
19
- throw new Entities_1.UnsupportedRequestVerion(this.requestType, version);
20
- }
21
- };
22
- handler.registerRequestHandler(this);
23
- }
24
- castPayloadV1(payload) {
25
- const castPayload = payload;
26
- if (castPayload.isEnabled === undefined) {
27
- throw new Entities_1.UnableToParsePayload(this.requestType, 1, JSON.stringify(payload));
28
- }
29
- return castPayload;
30
- }
31
- }
32
- exports.SetZSpaceEnabledBase = SetZSpaceEnabledBase;