@vived/app 2.9.1 → 2.10.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.
- package/lib/Entities/FocusCamera.d.ts +70 -0
- package/lib/Entities/FocusCamera.js +243 -0
- package/lib/Entities/MouseInput.js +5 -1
- package/lib/Entities/OrbitCamera.d.ts +59 -0
- package/lib/Entities/OrbitCamera.js +173 -4
- package/lib/Entities/index.d.ts +1 -1
- package/lib/Entities/index.js +1 -1
- package/lib/Interface/Controllers/makeAppHandler.d.ts +1 -1
- package/lib/Interface/Controllers/makeAppHandler.js +12 -10
- package/lib/PresentationManagers/FocusCameraPM.d.ts +14 -0
- package/lib/PresentationManagers/FocusCameraPM.js +31 -0
- package/lib/PresentationManagers/index.d.ts +1 -1
- package/lib/PresentationManagers/index.js +1 -1
- package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.d.ts +16 -0
- package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +63 -0
- package/lib/UseCases/FocusCamera/LerpFocusCamera.d.ts +36 -0
- package/lib/UseCases/FocusCamera/LerpFocusCamera.js +71 -0
- package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.d.ts +10 -0
- package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +35 -0
- package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.d.ts +10 -0
- package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +36 -0
- package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.d.ts +10 -0
- package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +24 -0
- package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.d.ts +10 -0
- package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +32 -0
- package/lib/UseCases/FocusCamera/SerializeFocusCamera.d.ts +22 -0
- package/lib/UseCases/FocusCamera/SerializeFocusCamera.js +81 -0
- package/lib/UseCases/FocusCamera/index.d.ts +7 -0
- package/lib/UseCases/FocusCamera/index.js +19 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.d.ts +9 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.d.ts +10 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.d.ts +22 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.js +81 -0
- package/lib/UseCases/OrbitCamera/index.d.ts +4 -0
- package/lib/UseCases/OrbitCamera/index.js +16 -0
- package/lib/UseCases/index.d.ts +1 -2
- package/lib/UseCases/index.js +1 -2
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Vector3 } from ".";
|
|
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,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeFocusCamera = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeFocusCamera() {
|
|
6
|
+
return new FocusCameraImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeFocusCamera = makeFocusCamera;
|
|
9
|
+
class FocusCameraImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.farClip = 100;
|
|
12
|
+
this.nearClip = 0.01;
|
|
13
|
+
this.defaultAlpha = 0;
|
|
14
|
+
this.defaultBeta = 30;
|
|
15
|
+
this.defaultRadius = 8;
|
|
16
|
+
this.defaultTarget = _1.Vector3.Zero();
|
|
17
|
+
this.limitRadius = false;
|
|
18
|
+
this.minRadius = 0;
|
|
19
|
+
this.maxRadius = 0;
|
|
20
|
+
this.limitAlpha = false;
|
|
21
|
+
this.minAlpha = 0;
|
|
22
|
+
this.maxAlpha = 0;
|
|
23
|
+
this.limitBeta = false;
|
|
24
|
+
this.minBeta = 0;
|
|
25
|
+
this.maxBeta = 0;
|
|
26
|
+
this.limitTarget = false;
|
|
27
|
+
this.maxTargetPosition = _1.Vector3.Zero();
|
|
28
|
+
this.minTargetPosition = _1.Vector3.Zero();
|
|
29
|
+
this.observers = new _1.ObserverList();
|
|
30
|
+
this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
|
|
31
|
+
this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
|
|
32
|
+
this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
|
|
33
|
+
this.memoizedTarget = new _1.MemoizedVector3(_1.Vector3.Zero(), this.observers.notify);
|
|
34
|
+
this.setRadiusLimits = (min, max) => {
|
|
35
|
+
if (min < 0) {
|
|
36
|
+
throw new Error("[Orbit Camera] Mininum Radius must be greater >= 0");
|
|
37
|
+
}
|
|
38
|
+
if (max < min) {
|
|
39
|
+
throw new Error("[Orbit Camera] Max radius must be >= min radius");
|
|
40
|
+
}
|
|
41
|
+
this.maxRadius = max;
|
|
42
|
+
this.minRadius = min;
|
|
43
|
+
this.limitRadius = true;
|
|
44
|
+
this.radius = this.radius;
|
|
45
|
+
};
|
|
46
|
+
this.clearRadiusLimits = () => {
|
|
47
|
+
this.maxRadius = 0;
|
|
48
|
+
this.minRadius = 0;
|
|
49
|
+
this.limitRadius = false;
|
|
50
|
+
};
|
|
51
|
+
this.setAlphaLimits = (min, max) => {
|
|
52
|
+
if (min > max) {
|
|
53
|
+
throw new Error("[Orbit Camera] Max alpha must be >= min alpha");
|
|
54
|
+
}
|
|
55
|
+
if (min < -180) {
|
|
56
|
+
throw new Error("[Orbit Camera] Min alpha must be >= -180");
|
|
57
|
+
}
|
|
58
|
+
if (max > 180) {
|
|
59
|
+
throw new Error("[Orbit Camera] Max alpha must be <= 180");
|
|
60
|
+
}
|
|
61
|
+
this.maxAlpha = max;
|
|
62
|
+
this.minAlpha = min;
|
|
63
|
+
this.limitAlpha = true;
|
|
64
|
+
this.alpha = this.alpha;
|
|
65
|
+
};
|
|
66
|
+
this.clearAlphaLimits = () => {
|
|
67
|
+
this.maxAlpha = 0;
|
|
68
|
+
this.minAlpha = 0;
|
|
69
|
+
this.limitAlpha = false;
|
|
70
|
+
};
|
|
71
|
+
this.setBetaLimits = (min, max) => {
|
|
72
|
+
if (min > max) {
|
|
73
|
+
throw new Error("[Orbit Camera] Max beta must be >= min beta");
|
|
74
|
+
}
|
|
75
|
+
if (min < -180) {
|
|
76
|
+
throw new Error("[Orbit Camera] Min beta must be >= -180");
|
|
77
|
+
}
|
|
78
|
+
if (max > 180) {
|
|
79
|
+
throw new Error("[Orbit Camera] Max beta must be <= 180");
|
|
80
|
+
}
|
|
81
|
+
this.maxBeta = max;
|
|
82
|
+
this.minBeta = min;
|
|
83
|
+
this.limitBeta = true;
|
|
84
|
+
this.beta = this.beta;
|
|
85
|
+
};
|
|
86
|
+
this.clearBetaLimits = () => {
|
|
87
|
+
this.maxBeta = 0;
|
|
88
|
+
this.minBeta = 0;
|
|
89
|
+
this.limitBeta = false;
|
|
90
|
+
};
|
|
91
|
+
this.setTargetLimits = (min, max) => {
|
|
92
|
+
const minArray = min.asArray();
|
|
93
|
+
const maxArray = max.asArray();
|
|
94
|
+
for (let i = 0; i < 3; i++) {
|
|
95
|
+
if (minArray[i] > maxArray[i]) {
|
|
96
|
+
throw new Error("[Orbit Camera] Min target must be less than the max target");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.maxTargetPosition = max;
|
|
100
|
+
this.minTargetPosition = min;
|
|
101
|
+
this.limitTarget = true;
|
|
102
|
+
this.target = this.target;
|
|
103
|
+
};
|
|
104
|
+
this.clearTargetLimits = () => {
|
|
105
|
+
this.maxTargetPosition = _1.Vector3.Zero();
|
|
106
|
+
this.minTargetPosition = _1.Vector3.Zero();
|
|
107
|
+
this.limitTarget = false;
|
|
108
|
+
};
|
|
109
|
+
this.registerLerp = (lerper) => {
|
|
110
|
+
if (this.currentLerp) {
|
|
111
|
+
this.currentLerp.cancelLerp();
|
|
112
|
+
}
|
|
113
|
+
this.currentLerp = lerper;
|
|
114
|
+
};
|
|
115
|
+
this.lerpCompleted = () => {
|
|
116
|
+
this.currentLerp = undefined;
|
|
117
|
+
};
|
|
118
|
+
this.cancelLerp = () => {
|
|
119
|
+
var _a;
|
|
120
|
+
(_a = this.currentLerp) === null || _a === void 0 ? void 0 : _a.cancelLerp();
|
|
121
|
+
this.currentLerp = undefined;
|
|
122
|
+
};
|
|
123
|
+
this.applyData = (data) => {
|
|
124
|
+
if (data.defaultAlpha !== undefined) {
|
|
125
|
+
this.defaultAlpha = data.defaultAlpha;
|
|
126
|
+
}
|
|
127
|
+
if (data.defaultBeta !== undefined) {
|
|
128
|
+
this.defaultBeta = data.defaultBeta;
|
|
129
|
+
}
|
|
130
|
+
if (data.defaultRadius !== undefined) {
|
|
131
|
+
this.defaultRadius = data.defaultRadius;
|
|
132
|
+
}
|
|
133
|
+
if (data.defaultTarget !== undefined) {
|
|
134
|
+
const { x, y, z } = data.defaultTarget;
|
|
135
|
+
this.defaultTarget = new _1.Vector3(x, y, z);
|
|
136
|
+
}
|
|
137
|
+
if (data.nearClip !== undefined) {
|
|
138
|
+
this.nearClip = data.nearClip;
|
|
139
|
+
}
|
|
140
|
+
if (data.farClip !== undefined) {
|
|
141
|
+
this.farClip = data.farClip;
|
|
142
|
+
}
|
|
143
|
+
if (data.alphaLimit !== undefined) {
|
|
144
|
+
this.setAlphaLimits(data.alphaLimit.min, data.alphaLimit.max);
|
|
145
|
+
}
|
|
146
|
+
if (data.betaLimit !== undefined) {
|
|
147
|
+
this.setBetaLimits(data.betaLimit.min, data.betaLimit.max);
|
|
148
|
+
}
|
|
149
|
+
if (data.radiusLimit !== undefined) {
|
|
150
|
+
this.setRadiusLimits(data.radiusLimit.min, data.radiusLimit.max);
|
|
151
|
+
}
|
|
152
|
+
if (data.targetLimit !== undefined) {
|
|
153
|
+
const { max, min } = data.targetLimit;
|
|
154
|
+
this.setTargetLimits(new _1.Vector3(min.x, min.y, min.z), new _1.Vector3(max.x, max.y, max.z));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
this.addObserver = (observer) => {
|
|
158
|
+
this.observers.add(observer);
|
|
159
|
+
};
|
|
160
|
+
this.removeObserver = (observer) => {
|
|
161
|
+
this.observers.remove(observer);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
get alpha() {
|
|
165
|
+
return this.memoizedAlpha.val;
|
|
166
|
+
}
|
|
167
|
+
set alpha(val) {
|
|
168
|
+
let clampedVal = this.clampAngle(val);
|
|
169
|
+
if (this.limitAlpha) {
|
|
170
|
+
clampedVal = Math.min(clampedVal, this.maxAlpha);
|
|
171
|
+
clampedVal = Math.max(clampedVal, this.minAlpha);
|
|
172
|
+
}
|
|
173
|
+
this.memoizedAlpha.val = clampedVal;
|
|
174
|
+
}
|
|
175
|
+
get beta() {
|
|
176
|
+
return this.memoizedBeta.val;
|
|
177
|
+
}
|
|
178
|
+
set beta(val) {
|
|
179
|
+
let clampedVal = this.clampAngle(val);
|
|
180
|
+
if (this.limitBeta) {
|
|
181
|
+
clampedVal = Math.min(clampedVal, this.maxBeta);
|
|
182
|
+
clampedVal = Math.max(clampedVal, this.minBeta);
|
|
183
|
+
}
|
|
184
|
+
this.memoizedBeta.val = clampedVal;
|
|
185
|
+
}
|
|
186
|
+
get radius() {
|
|
187
|
+
return this.memoizedRadius.val;
|
|
188
|
+
}
|
|
189
|
+
set radius(val) {
|
|
190
|
+
let clampedVal = Math.max(val, 0);
|
|
191
|
+
if (this.limitRadius) {
|
|
192
|
+
clampedVal = Math.min(clampedVal, this.maxRadius);
|
|
193
|
+
clampedVal = Math.max(clampedVal, this.minRadius);
|
|
194
|
+
}
|
|
195
|
+
this.memoizedRadius.val = clampedVal;
|
|
196
|
+
}
|
|
197
|
+
get target() {
|
|
198
|
+
return this.memoizedTarget.getVector();
|
|
199
|
+
}
|
|
200
|
+
set target(val) {
|
|
201
|
+
const targetVals = val.asArray();
|
|
202
|
+
if (this.limitTarget) {
|
|
203
|
+
const maxVals = this.maxTargetPosition.asArray();
|
|
204
|
+
const minVals = this.minTargetPosition.asArray();
|
|
205
|
+
for (let i = 0; i < 3; i++) {
|
|
206
|
+
let v = targetVals[i];
|
|
207
|
+
v = Math.min(v, maxVals[i]);
|
|
208
|
+
v = Math.max(v, minVals[i]);
|
|
209
|
+
targetVals[i] = v;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
this.memoizedTarget.setVector(new _1.Vector3(targetVals[0], targetVals[1], targetVals[2]));
|
|
213
|
+
}
|
|
214
|
+
get direction() {
|
|
215
|
+
const yLength = -Math.sin(this.degToRad(this.beta));
|
|
216
|
+
const horizontalLenght = Math.cos(this.degToRad(this.beta));
|
|
217
|
+
const alphaRadians = this.degToRad(this.alpha);
|
|
218
|
+
const xLength = -horizontalLenght * Math.sin(alphaRadians);
|
|
219
|
+
const zLength = horizontalLenght * Math.cos(alphaRadians);
|
|
220
|
+
return new _1.Vector3(xLength, yLength, zLength);
|
|
221
|
+
}
|
|
222
|
+
get cameraPosition() {
|
|
223
|
+
const localOffset = this.direction.copy();
|
|
224
|
+
localOffset.setLength(-this.radius);
|
|
225
|
+
return this.target.add(localOffset);
|
|
226
|
+
}
|
|
227
|
+
degToRad(degrees) {
|
|
228
|
+
return (degrees * Math.PI) / 180;
|
|
229
|
+
}
|
|
230
|
+
clampAngle(angle) {
|
|
231
|
+
const isNegative = angle < 0 ? true : false;
|
|
232
|
+
const absAngle = Math.abs(angle);
|
|
233
|
+
const revolutions = Math.floor(absAngle / 360);
|
|
234
|
+
let angleWithoutRevolutions = absAngle - revolutions * 360;
|
|
235
|
+
if (angleWithoutRevolutions > 180) {
|
|
236
|
+
angleWithoutRevolutions = angleWithoutRevolutions - 360;
|
|
237
|
+
}
|
|
238
|
+
if (isNegative) {
|
|
239
|
+
angleWithoutRevolutions *= -1;
|
|
240
|
+
}
|
|
241
|
+
return angleWithoutRevolutions;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -10,6 +10,7 @@ class MouseInputImp {
|
|
|
10
10
|
constructor() {
|
|
11
11
|
this.controllers = [];
|
|
12
12
|
this.maxClickMovement = 5; // pixels
|
|
13
|
+
this.isPressed = false;
|
|
13
14
|
this._eventElement = undefined;
|
|
14
15
|
this.setEventElement = (eventElement) => {
|
|
15
16
|
if (this._eventElement)
|
|
@@ -47,6 +48,7 @@ class MouseInputImp {
|
|
|
47
48
|
c.onDown(e);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
51
|
+
this.isPressed = true;
|
|
50
52
|
this.pressEvent = e;
|
|
51
53
|
};
|
|
52
54
|
this.onMouseUp = (e) => {
|
|
@@ -56,6 +58,7 @@ class MouseInputImp {
|
|
|
56
58
|
c.onUp(e);
|
|
57
59
|
}
|
|
58
60
|
});
|
|
61
|
+
this.isPressed = false;
|
|
59
62
|
if (!this.pressEvent)
|
|
60
63
|
return;
|
|
61
64
|
const deltaX = this.pressEvent.screenX - e.screenX;
|
|
@@ -88,7 +91,7 @@ class MouseInputImp {
|
|
|
88
91
|
};
|
|
89
92
|
this.onMouseOut = (e) => {
|
|
90
93
|
e.preventDefault();
|
|
91
|
-
if (!this.
|
|
94
|
+
if (!this.isPressed)
|
|
92
95
|
return;
|
|
93
96
|
this.controllers.forEach((c) => {
|
|
94
97
|
if (c.onUp) {
|
|
@@ -96,6 +99,7 @@ class MouseInputImp {
|
|
|
96
99
|
}
|
|
97
100
|
});
|
|
98
101
|
this.pressEvent = undefined;
|
|
102
|
+
this.isPressed = false;
|
|
99
103
|
};
|
|
100
104
|
this.onWheel = (e) => {
|
|
101
105
|
e.preventDefault();
|
|
@@ -3,14 +3,73 @@ export declare type OnOrbitCameraChange = () => void;
|
|
|
3
3
|
export interface CameraLerper {
|
|
4
4
|
cancelLerp: () => void;
|
|
5
5
|
}
|
|
6
|
+
export interface CameraData {
|
|
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
|
+
dollyRollSensitivity?: number;
|
|
42
|
+
dollyPixelSensitivity?: number;
|
|
43
|
+
orbitPixelSensitivity?: number;
|
|
44
|
+
dollyPinchSensitivity?: number;
|
|
45
|
+
}
|
|
6
46
|
export interface OrbitCamera {
|
|
7
47
|
alpha: number;
|
|
8
48
|
beta: number;
|
|
9
49
|
radius: number;
|
|
10
50
|
target: Vector3;
|
|
51
|
+
nearClip: number;
|
|
52
|
+
farClip: number;
|
|
53
|
+
defaultAlpha: number;
|
|
54
|
+
defaultBeta: number;
|
|
55
|
+
defaultRadius: number;
|
|
56
|
+
defaultTarget: Vector3;
|
|
57
|
+
dollyRollSensitivity: number;
|
|
58
|
+
dollyPixelSensitivity: number;
|
|
59
|
+
dollyPinchSensitivity: number;
|
|
60
|
+
orbitPixelSensitivity: number;
|
|
61
|
+
setAlphaLimits: (min: number, max: number) => void;
|
|
62
|
+
clearAlphaLimits: () => void;
|
|
63
|
+
setBetaLimits: (min: number, max: number) => void;
|
|
64
|
+
clearBetaLimits: () => void;
|
|
65
|
+
setRadiusLimits: (min: number, max: number) => void;
|
|
66
|
+
clearRadiusLimits: () => void;
|
|
67
|
+
setTargetLimits: (min: Vector3, max: Vector3) => void;
|
|
68
|
+
clearTargetLimits: () => void;
|
|
11
69
|
registerLerp: (lerper: CameraLerper) => void;
|
|
12
70
|
lerpCompleted: () => void;
|
|
13
71
|
cancelLerp: () => void;
|
|
72
|
+
applyData: (data: CameraData) => void;
|
|
14
73
|
addObserver: (observer: OnOrbitCameraChange) => void;
|
|
15
74
|
removeObserver: (observer: OnOrbitCameraChange) => void;
|
|
16
75
|
}
|
|
@@ -8,11 +8,108 @@ function makeOrbitCamera() {
|
|
|
8
8
|
exports.makeOrbitCamera = makeOrbitCamera;
|
|
9
9
|
class OrbitCameraImp {
|
|
10
10
|
constructor() {
|
|
11
|
+
this.farClip = 100;
|
|
12
|
+
this.nearClip = 0.01;
|
|
13
|
+
this.defaultAlpha = 0;
|
|
14
|
+
this.defaultBeta = 30;
|
|
15
|
+
this.defaultRadius = 8;
|
|
16
|
+
this.defaultTarget = _1.Vector3.Zero();
|
|
17
|
+
this.orbitPixelSensitivity = 0.5;
|
|
18
|
+
this.dollyPixelSensitivity = 0.01;
|
|
19
|
+
this.dollyRollSensitivity = 0.001;
|
|
20
|
+
this.dollyPinchSensitivity = 0.005;
|
|
21
|
+
this.limitRadius = false;
|
|
22
|
+
this.minRadius = 0;
|
|
23
|
+
this.maxRadius = 0;
|
|
24
|
+
this.limitAlpha = false;
|
|
25
|
+
this.minAlpha = 0;
|
|
26
|
+
this.maxAlpha = 0;
|
|
27
|
+
this.limitBeta = false;
|
|
28
|
+
this.minBeta = 0;
|
|
29
|
+
this.maxBeta = 0;
|
|
30
|
+
this.limitTarget = false;
|
|
31
|
+
this.maxTargetPosition = _1.Vector3.Zero();
|
|
32
|
+
this.minTargetPosition = _1.Vector3.Zero();
|
|
11
33
|
this.observers = new _1.ObserverList();
|
|
12
34
|
this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
|
|
13
35
|
this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
|
|
14
36
|
this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
|
|
15
37
|
this.memoizedTarget = new _1.MemoizedVector3(_1.Vector3.Zero(), this.observers.notify);
|
|
38
|
+
this.setRadiusLimits = (min, max) => {
|
|
39
|
+
if (min < 0) {
|
|
40
|
+
throw new Error("[Orbit Camera] Mininum Radius must be greater >= 0");
|
|
41
|
+
}
|
|
42
|
+
if (max < min) {
|
|
43
|
+
throw new Error("[Orbit Camera] Max radius must be >= min radius");
|
|
44
|
+
}
|
|
45
|
+
this.maxRadius = max;
|
|
46
|
+
this.minRadius = min;
|
|
47
|
+
this.limitRadius = true;
|
|
48
|
+
this.radius = this.radius;
|
|
49
|
+
};
|
|
50
|
+
this.clearRadiusLimits = () => {
|
|
51
|
+
this.maxRadius = 0;
|
|
52
|
+
this.minRadius = 0;
|
|
53
|
+
this.limitRadius = false;
|
|
54
|
+
};
|
|
55
|
+
this.setAlphaLimits = (min, max) => {
|
|
56
|
+
if (min > max) {
|
|
57
|
+
throw new Error("[Orbit Camera] Max alpha must be >= min alpha");
|
|
58
|
+
}
|
|
59
|
+
if (min < -180) {
|
|
60
|
+
throw new Error("[Orbit Camera] Min alpha must be >= -180");
|
|
61
|
+
}
|
|
62
|
+
if (max > 180) {
|
|
63
|
+
throw new Error("[Orbit Camera] Max alpha must be <= 180");
|
|
64
|
+
}
|
|
65
|
+
this.maxAlpha = max;
|
|
66
|
+
this.minAlpha = min;
|
|
67
|
+
this.limitAlpha = true;
|
|
68
|
+
this.alpha = this.alpha;
|
|
69
|
+
};
|
|
70
|
+
this.clearAlphaLimits = () => {
|
|
71
|
+
this.maxAlpha = 0;
|
|
72
|
+
this.minAlpha = 0;
|
|
73
|
+
this.limitAlpha = false;
|
|
74
|
+
};
|
|
75
|
+
this.setBetaLimits = (min, max) => {
|
|
76
|
+
if (min > max) {
|
|
77
|
+
throw new Error("[Orbit Camera] Max beta must be >= min beta");
|
|
78
|
+
}
|
|
79
|
+
if (min < -180) {
|
|
80
|
+
throw new Error("[Orbit Camera] Min beta must be >= -180");
|
|
81
|
+
}
|
|
82
|
+
if (max > 180) {
|
|
83
|
+
throw new Error("[Orbit Camera] Max beta must be <= 180");
|
|
84
|
+
}
|
|
85
|
+
this.maxBeta = max;
|
|
86
|
+
this.minBeta = min;
|
|
87
|
+
this.limitBeta = true;
|
|
88
|
+
this.beta = this.beta;
|
|
89
|
+
};
|
|
90
|
+
this.clearBetaLimits = () => {
|
|
91
|
+
this.maxBeta = 0;
|
|
92
|
+
this.minBeta = 0;
|
|
93
|
+
this.limitBeta = false;
|
|
94
|
+
};
|
|
95
|
+
this.setTargetLimits = (min, max) => {
|
|
96
|
+
const minArray = min.asArray();
|
|
97
|
+
const maxArray = max.asArray();
|
|
98
|
+
for (let i = 0; i < 3; i++) {
|
|
99
|
+
if (minArray[i] > maxArray[i]) {
|
|
100
|
+
throw new Error("[Orbit Camera] Min target must be less than the max target");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.maxTargetPosition = max;
|
|
104
|
+
this.minTargetPosition = min;
|
|
105
|
+
this.limitTarget = true;
|
|
106
|
+
this.target = this.target;
|
|
107
|
+
};
|
|
108
|
+
this.clearTargetLimits = () => {
|
|
109
|
+
this.maxTargetPosition = _1.Vector3.Zero();
|
|
110
|
+
this.minTargetPosition = _1.Vector3.Zero();
|
|
111
|
+
this.limitTarget = false;
|
|
112
|
+
};
|
|
16
113
|
this.registerLerp = (lerper) => {
|
|
17
114
|
if (this.currentLerp) {
|
|
18
115
|
this.currentLerp.cancelLerp();
|
|
@@ -27,6 +124,52 @@ class OrbitCameraImp {
|
|
|
27
124
|
(_a = this.currentLerp) === null || _a === void 0 ? void 0 : _a.cancelLerp();
|
|
28
125
|
this.currentLerp = undefined;
|
|
29
126
|
};
|
|
127
|
+
this.applyData = (data) => {
|
|
128
|
+
if (data.defaultAlpha !== undefined) {
|
|
129
|
+
this.defaultAlpha = data.defaultAlpha;
|
|
130
|
+
}
|
|
131
|
+
if (data.defaultBeta !== undefined) {
|
|
132
|
+
this.defaultBeta = data.defaultBeta;
|
|
133
|
+
}
|
|
134
|
+
if (data.defaultRadius !== undefined) {
|
|
135
|
+
this.defaultRadius = data.defaultRadius;
|
|
136
|
+
}
|
|
137
|
+
if (data.defaultTarget !== undefined) {
|
|
138
|
+
const { x, y, z } = data.defaultTarget;
|
|
139
|
+
this.defaultTarget = new _1.Vector3(x, y, z);
|
|
140
|
+
}
|
|
141
|
+
if (data.nearClip !== undefined) {
|
|
142
|
+
this.nearClip = data.nearClip;
|
|
143
|
+
}
|
|
144
|
+
if (data.farClip !== undefined) {
|
|
145
|
+
this.farClip = data.farClip;
|
|
146
|
+
}
|
|
147
|
+
if (data.alphaLimit !== undefined) {
|
|
148
|
+
this.setAlphaLimits(data.alphaLimit.min, data.alphaLimit.max);
|
|
149
|
+
}
|
|
150
|
+
if (data.betaLimit !== undefined) {
|
|
151
|
+
this.setBetaLimits(data.betaLimit.min, data.betaLimit.max);
|
|
152
|
+
}
|
|
153
|
+
if (data.radiusLimit !== undefined) {
|
|
154
|
+
this.setRadiusLimits(data.radiusLimit.min, data.radiusLimit.max);
|
|
155
|
+
}
|
|
156
|
+
if (data.targetLimit !== undefined) {
|
|
157
|
+
const { max, min } = data.targetLimit;
|
|
158
|
+
this.setTargetLimits(new _1.Vector3(min.x, min.y, min.z), new _1.Vector3(max.x, max.y, max.z));
|
|
159
|
+
}
|
|
160
|
+
if (data.dollyRollSensitivity !== undefined) {
|
|
161
|
+
this.dollyRollSensitivity = data.dollyRollSensitivity;
|
|
162
|
+
}
|
|
163
|
+
if (data.dollyPixelSensitivity !== undefined) {
|
|
164
|
+
this.dollyPixelSensitivity = data.dollyPixelSensitivity;
|
|
165
|
+
}
|
|
166
|
+
if (data.dollyPinchSensitivity !== undefined) {
|
|
167
|
+
this.dollyPinchSensitivity = data.dollyPinchSensitivity;
|
|
168
|
+
}
|
|
169
|
+
if (data.orbitPixelSensitivity !== undefined) {
|
|
170
|
+
this.orbitPixelSensitivity = data.orbitPixelSensitivity;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
30
173
|
this.addObserver = (observer) => {
|
|
31
174
|
this.observers.add(observer);
|
|
32
175
|
};
|
|
@@ -38,25 +181,51 @@ class OrbitCameraImp {
|
|
|
38
181
|
return this.memoizedAlpha.val;
|
|
39
182
|
}
|
|
40
183
|
set alpha(val) {
|
|
41
|
-
|
|
184
|
+
let clampedVal = this.clampAngle(val);
|
|
185
|
+
if (this.limitAlpha) {
|
|
186
|
+
clampedVal = Math.min(clampedVal, this.maxAlpha);
|
|
187
|
+
clampedVal = Math.max(clampedVal, this.minAlpha);
|
|
188
|
+
}
|
|
189
|
+
this.memoizedAlpha.val = clampedVal;
|
|
42
190
|
}
|
|
43
191
|
get beta() {
|
|
44
192
|
return this.memoizedBeta.val;
|
|
45
193
|
}
|
|
46
194
|
set beta(val) {
|
|
47
|
-
|
|
195
|
+
let clampedVal = this.clampAngle(val);
|
|
196
|
+
if (this.limitBeta) {
|
|
197
|
+
clampedVal = Math.min(clampedVal, this.maxBeta);
|
|
198
|
+
clampedVal = Math.max(clampedVal, this.minBeta);
|
|
199
|
+
}
|
|
200
|
+
this.memoizedBeta.val = clampedVal;
|
|
48
201
|
}
|
|
49
202
|
get radius() {
|
|
50
203
|
return this.memoizedRadius.val;
|
|
51
204
|
}
|
|
52
205
|
set radius(val) {
|
|
53
|
-
|
|
206
|
+
let clampedVal = Math.max(val, 0);
|
|
207
|
+
if (this.limitRadius) {
|
|
208
|
+
clampedVal = Math.min(clampedVal, this.maxRadius);
|
|
209
|
+
clampedVal = Math.max(clampedVal, this.minRadius);
|
|
210
|
+
}
|
|
211
|
+
this.memoizedRadius.val = clampedVal;
|
|
54
212
|
}
|
|
55
213
|
get target() {
|
|
56
214
|
return this.memoizedTarget.getVector();
|
|
57
215
|
}
|
|
58
216
|
set target(val) {
|
|
59
|
-
|
|
217
|
+
const targetVals = val.asArray();
|
|
218
|
+
if (this.limitTarget) {
|
|
219
|
+
const maxVals = this.maxTargetPosition.asArray();
|
|
220
|
+
const minVals = this.minTargetPosition.asArray();
|
|
221
|
+
for (let i = 0; i < 3; i++) {
|
|
222
|
+
let v = targetVals[i];
|
|
223
|
+
v = Math.min(v, maxVals[i]);
|
|
224
|
+
v = Math.max(v, minVals[i]);
|
|
225
|
+
targetVals[i] = v;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this.memoizedTarget.setVector(new _1.Vector3(targetVals[0], targetVals[1], targetVals[2]));
|
|
60
229
|
}
|
|
61
230
|
clampAngle(angle) {
|
|
62
231
|
const isNegative = angle < 0 ? true : false;
|
package/lib/Entities/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export * from "./MemoizedString";
|
|
|
10
10
|
export * from "./MemoizedVector2";
|
|
11
11
|
export * from "./MemoizedVector3";
|
|
12
12
|
export * from "./ObserverList";
|
|
13
|
-
export * from "./
|
|
13
|
+
export * from "./FocusCamera";
|
|
14
14
|
export * from "./ParametricLine";
|
|
15
15
|
export * from "./ParametricPlane";
|
|
16
16
|
export * from "./StateMachine";
|
package/lib/Entities/index.js
CHANGED
|
@@ -22,7 +22,7 @@ __exportStar(require("./MemoizedString"), exports);
|
|
|
22
22
|
__exportStar(require("./MemoizedVector2"), exports);
|
|
23
23
|
__exportStar(require("./MemoizedVector3"), exports);
|
|
24
24
|
__exportStar(require("./ObserverList"), exports);
|
|
25
|
-
__exportStar(require("./
|
|
25
|
+
__exportStar(require("./FocusCamera"), exports);
|
|
26
26
|
__exportStar(require("./ParametricLine"), exports);
|
|
27
27
|
__exportStar(require("./ParametricPlane"), exports);
|
|
28
28
|
__exportStar(require("./StateMachine"), exports);
|
|
@@ -9,4 +9,4 @@ export interface AppHandlerFunctions {
|
|
|
9
9
|
setState: (finalState: string, duration?: number) => void;
|
|
10
10
|
setDevicePreview: (x: number, y: number) => void;
|
|
11
11
|
}
|
|
12
|
-
export declare function makeAppHandler(functions: AppHandlerFunctions): Handler;
|
|
12
|
+
export declare function makeAppHandler(functions: AppHandlerFunctions, verbose?: boolean): Handler;
|