@vived/app 3.2.1 → 3.3.1

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 (73) hide show
  1. package/lib/AppObjectComponents/Dispatcher/Entities/AppDispatcher.d.ts +16 -0
  2. package/lib/AppObjectComponents/Dispatcher/Entities/AppDispatcher.js +40 -0
  3. package/lib/AppObjectComponents/Dispatcher/Factories/makeBasicDispatcher.d.ts +4 -0
  4. package/lib/AppObjectComponents/Dispatcher/Factories/makeBasicDispatcher.js +12 -0
  5. package/lib/AppObjectComponents/Dispatcher/UC/DispatchStopZSpaceUC.d.ts +10 -0
  6. package/lib/AppObjectComponents/Dispatcher/UC/DispatchStopZSpaceUC.js +44 -0
  7. package/lib/AppObjectComponents/Dispatcher/index.d.ts +3 -0
  8. package/lib/AppObjectComponents/Dispatcher/index.js +15 -0
  9. package/lib/AppObjectComponents/Transform3D/Entities/Transform3D.d.ts +1 -0
  10. package/lib/AppObjectComponents/Transform3D/Entities/Transform3D.js +6 -1
  11. package/lib/Entities/AppDispatcher.d.ts +0 -1
  12. package/lib/Entities/AppDispatcher.js +0 -3
  13. package/lib/Entities/FocusCamera.d.ts +70 -0
  14. package/lib/Entities/FocusCamera.js +272 -0
  15. package/lib/Entities/MemoizedBoolean.d.ts +8 -0
  16. package/lib/Entities/MemoizedBoolean.js +22 -0
  17. package/lib/Entities/MemoizedNumber.d.ts +8 -0
  18. package/lib/Entities/MemoizedNumber.js +22 -0
  19. package/lib/Entities/MemoizedQuaternion.d.ts +9 -0
  20. package/lib/Entities/MemoizedQuaternion.js +23 -0
  21. package/lib/Entities/MemoizedString.d.ts +8 -0
  22. package/lib/Entities/MemoizedString.js +22 -0
  23. package/lib/Entities/MemoizedVector2.d.ts +9 -0
  24. package/lib/Entities/MemoizedVector2.js +23 -0
  25. package/lib/Entities/MemoizedVector3.d.ts +9 -0
  26. package/lib/Entities/MemoizedVector3.js +23 -0
  27. package/lib/Entities/MeshModel.d.ts +68 -0
  28. package/lib/Entities/MeshModel.js +174 -0
  29. package/lib/Entities/ModelObject.d.ts +10 -0
  30. package/lib/Entities/ModelObject.js +42 -0
  31. package/lib/PresentationManagers/FocusCameraPM.d.ts +15 -0
  32. package/lib/PresentationManagers/FocusCameraPM.js +31 -0
  33. package/lib/PresentationManagers/FocusCameraPosRotPM.d.ts +13 -0
  34. package/lib/PresentationManagers/FocusCameraPosRotPM.js +28 -0
  35. package/lib/PresentationManagers/SceneModel/SceneMeshOverlayPM.d.ts +15 -0
  36. package/lib/PresentationManagers/SceneModel/SceneMeshOverlayPM.js +34 -0
  37. package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.d.ts +17 -0
  38. package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +64 -0
  39. package/lib/UseCases/FocusCamera/LerpFocusCamera.d.ts +36 -0
  40. package/lib/UseCases/FocusCamera/LerpFocusCamera.js +71 -0
  41. package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.d.ts +11 -0
  42. package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +36 -0
  43. package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.d.ts +11 -0
  44. package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +36 -0
  45. package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.d.ts +11 -0
  46. package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +26 -0
  47. package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.d.ts +11 -0
  48. package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +33 -0
  49. package/lib/UseCases/FocusCamera/SerializeFocusCamera.d.ts +22 -0
  50. package/lib/UseCases/FocusCamera/SerializeFocusCamera.js +81 -0
  51. package/lib/UseCases/FocusCamera/index.d.ts +7 -0
  52. package/lib/UseCases/FocusCamera/index.js +19 -0
  53. package/lib/UseCases/Handlers/StartZSpaceBase.d.ts +3 -3
  54. package/lib/UseCases/Handlers/StartZSpaceBase.js +7 -4
  55. package/lib/UseCases/SceneModel/SerializeActiveModel.d.ts +18 -0
  56. package/lib/UseCases/SceneModel/SerializeActiveModel.js +74 -0
  57. package/lib/UseCases/SceneModel/SetMeshesEnabledHook.d.ts +7 -0
  58. package/lib/UseCases/SceneModel/SetMeshesEnabledHook.js +22 -0
  59. package/lib/UseCases/SceneModel/SetSceneModelMeshOverlayColor.d.ts +2 -0
  60. package/lib/UseCases/SceneModel/SetSceneModelMeshOverlayColor.js +13 -0
  61. package/lib/UseCases/SceneModel/index.d.ts +3 -0
  62. package/lib/UseCases/SceneModel/index.js +3 -0
  63. package/lib/UseCases/SceneModel/loadNewModel.d.ts +2 -2
  64. package/lib/UseCases/SceneModel/loadNewModel.js +17 -15
  65. package/lib/UseCases/SceneObjects/PeelSceneObject.d.ts +18 -0
  66. package/lib/UseCases/SceneObjects/PeelSceneObject.js +61 -0
  67. package/lib/UseCases/SceneObjects/index.d.ts +1 -0
  68. package/lib/UseCases/SceneObjects/index.js +13 -0
  69. package/package.json +1 -1
  70. package/lib/AppObject/IsEnabledPM.d.ts +0 -11
  71. package/lib/AppObject/IsEnabledPM.js +0 -29
  72. package/lib/AppObjectComponents/Transform3D/UseCases/getStickUC.d.ts +0 -3
  73. package/lib/AppObjectComponents/Transform3D/UseCases/getStickUC.js +0 -8
@@ -0,0 +1,16 @@
1
+ import { AppObject } from "../../../AppObject/AppObject";
2
+ import { AppObjectEntity } from "../../../AppObject/AppObjectEntity";
3
+ import { AppObjectRepo } from "../../../AppObject/AppObjectRepo";
4
+ export declare type Handler = (request: Request) => void;
5
+ export interface Request {
6
+ type: string;
7
+ version: number;
8
+ payload?: unknown;
9
+ }
10
+ export declare abstract class AppDispatcher extends AppObjectEntity {
11
+ static readonly type = "APP_DISPATCHER";
12
+ abstract dispatch: (request: Request) => void;
13
+ abstract formRequestAndDispatch: (type: string, version: number, payload?: object | undefined) => void;
14
+ static get(appObjects: AppObjectRepo): AppDispatcher | undefined;
15
+ }
16
+ export declare function makeAppDispatcher(appObject: AppObject, hostHandler: Handler): AppDispatcher;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeAppDispatcher = exports.AppDispatcher = void 0;
4
+ const AppObjectEntity_1 = require("../../../AppObject/AppObjectEntity");
5
+ class AppDispatcher extends AppObjectEntity_1.AppObjectEntity {
6
+ static get(appObjects) {
7
+ const selectionEntities = appObjects.getAllComponents(AppDispatcher.type);
8
+ if (selectionEntities.length === 0) {
9
+ console.warn("Unable to find a App Dispatcher. Add one on Mount");
10
+ return undefined;
11
+ }
12
+ else if (selectionEntities.length > 1) {
13
+ console.warn("Multiple App Dispatcher have been found. There should only be one. Using the first one");
14
+ }
15
+ return selectionEntities[0];
16
+ }
17
+ }
18
+ exports.AppDispatcher = AppDispatcher;
19
+ AppDispatcher.type = "APP_DISPATCHER";
20
+ function makeAppDispatcher(appObject, hostHandler) {
21
+ return new AppDispatcherImp(appObject, hostHandler);
22
+ }
23
+ exports.makeAppDispatcher = makeAppDispatcher;
24
+ class AppDispatcherImp extends AppDispatcher {
25
+ constructor(appObject, hostHandler) {
26
+ super(appObject, AppDispatcher.type);
27
+ this.hostHandler = hostHandler;
28
+ this.dispatch = (request) => {
29
+ this.hostHandler(request);
30
+ };
31
+ this.formRequestAndDispatch = (type, version, payload) => {
32
+ const request = {
33
+ type,
34
+ version,
35
+ payload
36
+ };
37
+ this.hostHandler(request);
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,4 @@
1
+ import { AppObjectRepo } from "../../../AppObject/AppObjectRepo";
2
+ import { Handler } from "../Entities/AppDispatcher";
3
+ export declare const APP_DISPATCHER_ID = "AppDispatcher";
4
+ export declare function makeBasicDispatcher(appObjects: AppObjectRepo, hostHandler: Handler): void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBasicDispatcher = exports.APP_DISPATCHER_ID = void 0;
4
+ const AppDispatcher_1 = require("../Entities/AppDispatcher");
5
+ const DispatchStopZSpaceUC_1 = require("../UC/DispatchStopZSpaceUC");
6
+ exports.APP_DISPATCHER_ID = "AppDispatcher";
7
+ function makeBasicDispatcher(appObjects, hostHandler) {
8
+ const dispatcherAO = appObjects.getOrCreate(exports.APP_DISPATCHER_ID);
9
+ AppDispatcher_1.makeAppDispatcher(dispatcherAO, hostHandler);
10
+ DispatchStopZSpaceUC_1.makeDispatchStopZSpaceUC(dispatcherAO);
11
+ }
12
+ exports.makeBasicDispatcher = makeBasicDispatcher;
@@ -0,0 +1,10 @@
1
+ import { AppObject } from "../../../AppObject/AppObject";
2
+ import { AppObjectRepo } from "../../../AppObject/AppObjectRepo";
3
+ import { AppObjectUC } from "../../../AppObject/AppObjectUC";
4
+ export declare abstract class DispatchStopZSpaceUC extends AppObjectUC {
5
+ static readonly type = "DispatchStopZSpaceUC";
6
+ readonly requestType = "STOP_ZSPACE";
7
+ abstract doDispatch(): void;
8
+ static get(appObjects: AppObjectRepo): DispatchStopZSpaceUC | undefined;
9
+ }
10
+ export declare function makeDispatchStopZSpaceUC(appObject: AppObject): DispatchStopZSpaceUC;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeDispatchStopZSpaceUC = exports.DispatchStopZSpaceUC = void 0;
4
+ const AppObjectUC_1 = require("../../../AppObject/AppObjectUC");
5
+ const AppDispatcher_1 = require("../Entities/AppDispatcher");
6
+ class DispatchStopZSpaceUC extends AppObjectUC_1.AppObjectUC {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.requestType = "STOP_ZSPACE";
10
+ }
11
+ static get(appObjects) {
12
+ const selectionEntities = appObjects.getAllComponents(DispatchStopZSpaceUC.type);
13
+ if (selectionEntities.length === 0) {
14
+ console.warn("Unable to find a DispatchStopZSpaceUC. Add one on Mount");
15
+ return undefined;
16
+ }
17
+ else if (selectionEntities.length > 1) {
18
+ console.warn("Multiple DispatchStopZSpaceUC have been found. There should only be one. Using the first one");
19
+ }
20
+ return selectionEntities[0];
21
+ }
22
+ }
23
+ exports.DispatchStopZSpaceUC = DispatchStopZSpaceUC;
24
+ DispatchStopZSpaceUC.type = "DispatchStopZSpaceUC";
25
+ function makeDispatchStopZSpaceUC(appObject) {
26
+ return new DispatchStateChangeUCImp(appObject);
27
+ }
28
+ exports.makeDispatchStopZSpaceUC = makeDispatchStopZSpaceUC;
29
+ class DispatchStateChangeUCImp extends DispatchStopZSpaceUC {
30
+ constructor(appObject) {
31
+ super(appObject, DispatchStopZSpaceUC.type);
32
+ this.requestVersion = 1;
33
+ this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
34
+ if (!this.appDispatcher) {
35
+ console.warn("DispatchStopZSpaceUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
36
+ this.dispose();
37
+ }
38
+ }
39
+ doDispatch() {
40
+ if (!this.appDispatcher)
41
+ return;
42
+ this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion);
43
+ }
44
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./Entities/AppDispatcher";
2
+ export * from "./Factories/makeBasicDispatcher";
3
+ export * from "./UC/DispatchStopZSpaceUC";
@@ -0,0 +1,15 @@
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("./Entities/AppDispatcher"), exports);
14
+ __exportStar(require("./Factories/makeBasicDispatcher"), exports);
15
+ __exportStar(require("./UC/DispatchStopZSpaceUC"), exports);
@@ -37,6 +37,7 @@ export declare class Transform3D extends AppObjectEntity {
37
37
  private lerpQuat?;
38
38
  private lerpScale?;
39
39
  private onLerpCompletedCallback?;
40
+ private previousTime;
40
41
  lerp: (duration: number, ease: EaseFn, desiredPosition?: Vector3 | undefined, desiredRotation?: Quaternion | undefined, desiredScale?: Vector3 | undefined, onCompletedCallback?: (() => void) | undefined) => void;
41
42
  private tickLerp;
42
43
  cancelLerp: () => void;
@@ -27,6 +27,7 @@ class Transform3D extends AppObject_1.AppObjectEntity {
27
27
  this.lerpDuration = 1;
28
28
  this.lerpEase = (p) => p;
29
29
  this.tickInterval = 10;
30
+ this.previousTime = 0;
30
31
  this.lerp = (duration, ease, desiredPosition, desiredRotation, desiredScale, onCompletedCallback) => {
31
32
  this.cancelLerp();
32
33
  this.chrono = 0;
@@ -55,12 +56,16 @@ class Transform3D extends AppObject_1.AppObjectEntity {
55
56
  this.lerpScale = undefined;
56
57
  }
57
58
  this.onLerpCompletedCallback = onCompletedCallback;
59
+ this.previousTime = Date.now();
58
60
  this.interval = setInterval(() => {
59
61
  this.tickLerp();
60
62
  }, this.tickInterval);
61
63
  };
62
64
  this.tickLerp = () => {
63
- this.chrono = this.chrono + this.tickInterval;
65
+ const currentTime = Date.now();
66
+ const timeDiff = currentTime - this.previousTime;
67
+ this.previousTime = currentTime;
68
+ this.chrono = this.chrono + timeDiff;
64
69
  let nomralizedTime = this.chrono / this.lerpDuration;
65
70
  if (nomralizedTime > 1) {
66
71
  nomralizedTime = 1;
@@ -58,7 +58,6 @@ export declare abstract class AppDispatcher {
58
58
  abstract getAssetsForOwner: (ownerID: string) => Promise<AssetMetaDTO[]>;
59
59
  abstract isAssetFetched: (data: IsAssetFetchedDTO) => void;
60
60
  abstract submitNewActivityAsset: (file: File) => Promise<string>;
61
- abstract stopZSpace: () => void;
62
61
  abstract showAlert: (data: ShowAlertDTO) => void;
63
62
  abstract showConfirm: (data: ShowConfirmDTO) => void;
64
63
  abstract showMarkDownEditor: (data: ShowMarkDownEditorDTO) => void;
@@ -268,9 +268,6 @@ class AppDistpatcherImp extends AppDispatcher {
268
268
  this.goToNextState = () => {
269
269
  this.formRequestAndDispatch("GO_TO_NEXT_STATE", 1);
270
270
  };
271
- this.stopZSpace = () => {
272
- this.formRequestAndDispatch("STOP_ZSPACE", 1);
273
- };
274
271
  this.hasNextState = () => {
275
272
  return new Promise((resolve, reject) => {
276
273
  const callback = (hasNextState) => {
@@ -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,8 @@
1
+ export declare class MemoizedBoolean {
2
+ private _val;
3
+ get val(): boolean;
4
+ set val(b: boolean);
5
+ setValQuietly(val: boolean): void;
6
+ private onChangeCallback;
7
+ constructor(initialValue: boolean, onChangeCallback: () => void);
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoizedBoolean = void 0;
4
+ class MemoizedBoolean {
5
+ constructor(initialValue, onChangeCallback) {
6
+ this._val = initialValue;
7
+ this.onChangeCallback = onChangeCallback;
8
+ }
9
+ get val() {
10
+ return this._val;
11
+ }
12
+ set val(b) {
13
+ if (this._val === b)
14
+ return;
15
+ this._val = b;
16
+ this.onChangeCallback();
17
+ }
18
+ setValQuietly(val) {
19
+ this._val = val;
20
+ }
21
+ }
22
+ exports.MemoizedBoolean = MemoizedBoolean;
@@ -0,0 +1,8 @@
1
+ export declare class MemoizedNumber {
2
+ private _val;
3
+ get val(): number;
4
+ set val(b: number);
5
+ setValQuietly(val: number): void;
6
+ private onChangeCallback;
7
+ constructor(initialValue: number, onChangeCallback: () => void);
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoizedNumber = void 0;
4
+ class MemoizedNumber {
5
+ constructor(initialValue, onChangeCallback) {
6
+ this._val = initialValue;
7
+ this.onChangeCallback = onChangeCallback;
8
+ }
9
+ get val() {
10
+ return this._val;
11
+ }
12
+ set val(b) {
13
+ if (this._val === b)
14
+ return;
15
+ this._val = b;
16
+ this.onChangeCallback();
17
+ }
18
+ setValQuietly(val) {
19
+ this._val = val;
20
+ }
21
+ }
22
+ exports.MemoizedNumber = MemoizedNumber;
@@ -0,0 +1,9 @@
1
+ import { Quaternion } from "../ValueObjects";
2
+ export declare class MemoizedQuaternion {
3
+ private _val;
4
+ get val(): Quaternion;
5
+ set val(v: Quaternion);
6
+ setValQuietly(val: Quaternion): void;
7
+ private onChangeCallback;
8
+ constructor(initialValue: Quaternion, onChangeCallback: () => void);
9
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoizedQuaternion = void 0;
4
+ const ValueObjects_1 = require("../ValueObjects");
5
+ class MemoizedQuaternion {
6
+ constructor(initialValue, onChangeCallback) {
7
+ this._val = initialValue;
8
+ this.onChangeCallback = onChangeCallback;
9
+ }
10
+ get val() {
11
+ return this._val;
12
+ }
13
+ set val(v) {
14
+ if (ValueObjects_1.Quaternion.Equal(v, this._val))
15
+ return;
16
+ this._val = v;
17
+ this.onChangeCallback();
18
+ }
19
+ setValQuietly(val) {
20
+ this._val = val;
21
+ }
22
+ }
23
+ exports.MemoizedQuaternion = MemoizedQuaternion;
@@ -0,0 +1,8 @@
1
+ export declare class MemoizedString {
2
+ private _val;
3
+ get val(): string;
4
+ set val(b: string);
5
+ setValQuietly(val: string): void;
6
+ private onChangeCallback;
7
+ constructor(initialValue: string, onChangeCallback: () => void);
8
+ }