@vived/app 2.4.0 → 2.7.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/Core/BaseApp/Boundary.d.ts +8 -2
- package/lib/Core/BaseApp/Entity.d.ts +2 -0
- package/lib/Core/BaseApp/UseCase.d.ts +29 -19
- package/lib/Core/BaseApp/UseCase.js +211 -135
- package/lib/Entities/Babylon.d.ts +17 -0
- package/lib/Entities/Babylon.js +81 -0
- package/lib/Entities/BaseApp.d.ts +7 -0
- package/lib/Entities/BaseApp.js +27 -0
- package/lib/Entities/Color.d.ts +20 -0
- package/lib/Entities/Color.js +59 -0
- package/lib/Entities/DevicePreview.d.ts +11 -0
- package/lib/Entities/DevicePreview.js +44 -0
- package/lib/Entities/KeyboardInput.d.ts +14 -0
- package/lib/Entities/KeyboardInput.js +76 -0
- package/lib/Entities/LineSegment2D.d.ts +11 -0
- package/lib/Entities/LineSegment2D.js +70 -0
- package/lib/Entities/MemoizedBoolean.d.ts +7 -0
- package/lib/Entities/MemoizedBoolean.js +19 -0
- package/lib/Entities/MemoizedNumber.d.ts +7 -0
- package/lib/Entities/MemoizedNumber.js +19 -0
- package/lib/Entities/MemoizedString.d.ts +7 -0
- package/lib/Entities/MemoizedString.js +19 -0
- package/lib/Entities/MemoizedVector2.d.ts +12 -0
- package/lib/Entities/MemoizedVector2.js +37 -0
- package/lib/Entities/MemoizedVector3.d.ts +14 -0
- package/lib/Entities/MemoizedVector3.js +46 -0
- package/lib/Entities/ObserverList.d.ts +6 -0
- package/lib/Entities/ObserverList.js +23 -0
- package/lib/Entities/OrbitCamera.d.ts +17 -0
- package/lib/Entities/OrbitCamera.js +74 -0
- package/lib/Entities/ParametricLine.d.ts +29 -0
- package/lib/Entities/ParametricLine.js +79 -0
- package/lib/Entities/ParametricPlane.d.ts +20 -0
- package/lib/Entities/ParametricPlane.js +63 -0
- package/lib/Entities/StateMachine.d.ts +25 -0
- package/lib/Entities/StateMachine.js +81 -0
- package/lib/Entities/UndoRedo.d.ts +22 -0
- package/lib/Entities/UndoRedo.js +61 -0
- package/lib/Entities/Vector2.d.ts +21 -0
- package/lib/Entities/Vector2.js +83 -0
- package/lib/Entities/Vector3.d.ts +19 -0
- package/lib/Entities/Vector3.js +75 -0
- package/lib/Entities/index.d.ts +19 -0
- package/lib/Entities/index.js +31 -0
- package/lib/Interface/Controllers/setState.d.ts +1 -1
- package/lib/Interface/Controllers/setState.js +14 -3
- package/lib/PresentationManagers/DevicePreviewPM.d.ts +13 -0
- package/lib/PresentationManagers/DevicePreviewPM.js +25 -0
- package/lib/PresentationManagers/HasRedoPM.d.ts +9 -0
- package/lib/PresentationManagers/HasRedoPM.js +22 -0
- package/lib/PresentationManagers/HasUndoPM.d.ts +9 -0
- package/lib/PresentationManagers/HasUndoPM.js +22 -0
- package/lib/PresentationManagers/IsAuthoringPM.d.ts +9 -0
- package/lib/PresentationManagers/IsAuthoringPM.js +22 -0
- package/lib/PresentationManagers/OrbitCameraPM.d.ts +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.js +31 -0
- package/lib/PresentationManagers/ShowBabylonInspectorPM.d.ts +9 -0
- package/lib/PresentationManagers/ShowBabylonInspectorPM.js +22 -0
- package/lib/PresentationManagers/index.d.ts +6 -0
- package/lib/PresentationManagers/index.js +18 -0
- package/lib/UseCases/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/SerializeCamera.d.ts +21 -0
- package/lib/UseCases/SerializeCamera.js +59 -0
- package/lib/UseCases/SerializeOrbitCamera.d.ts +21 -0
- package/lib/UseCases/SerializeOrbitCamera.js +59 -0
- package/lib/UseCases/SerializedCamDemo.d.ts +0 -0
- package/lib/UseCases/SerializedCamDemo.js +1 -0
- package/lib/UseCases/index.d.ts +3 -0
- package/lib/UseCases/index.js +15 -0
- package/lib/UseCases/setDevicePreview.d.ts +2 -0
- package/lib/UseCases/setDevicePreview.js +14 -0
- package/lib/Utilities/degreesToRadians.d.ts +1 -0
- package/lib/Utilities/degreesToRadians.js +7 -0
- package/lib/Utilities/index.d.ts +1 -0
- package/lib/Utilities/index.js +13 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +8 -2
- package/package.json +1 -2
- package/CHANGELOG.md +0 -51
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Vector2 } from ".";
|
|
2
|
+
export declare type OnDevicePreviewChange = () => void;
|
|
3
|
+
export interface DevicePreview {
|
|
4
|
+
useDevicePreview: boolean;
|
|
5
|
+
previewSize: Vector2;
|
|
6
|
+
setDevicePreview(x: number, y: number): void;
|
|
7
|
+
clearDevicePreview(): void;
|
|
8
|
+
addObserver(observer: OnDevicePreviewChange): void;
|
|
9
|
+
removeObserver(observer: OnDevicePreviewChange): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function makeDevicePreview(): DevicePreview;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeDevicePreview = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeDevicePreview() {
|
|
6
|
+
return new DevicePreviewImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeDevicePreview = makeDevicePreview;
|
|
9
|
+
class DevicePreviewImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.observers = new _1.ObserverList();
|
|
12
|
+
this._usePreview = false;
|
|
13
|
+
this._previewSize = _1.Vector2.Zero();
|
|
14
|
+
this.setDevicePreview = (x, y) => {
|
|
15
|
+
if (this._usePreview &&
|
|
16
|
+
this._previewSize.x === x &&
|
|
17
|
+
this._previewSize.y === y)
|
|
18
|
+
return;
|
|
19
|
+
this._usePreview = true;
|
|
20
|
+
this._previewSize.x = x;
|
|
21
|
+
this._previewSize.y = y;
|
|
22
|
+
this.observers.notify();
|
|
23
|
+
};
|
|
24
|
+
this.clearDevicePreview = () => {
|
|
25
|
+
if (!this._usePreview)
|
|
26
|
+
return;
|
|
27
|
+
this._previewSize = _1.Vector2.Zero();
|
|
28
|
+
this._usePreview = false;
|
|
29
|
+
this.observers.notify();
|
|
30
|
+
};
|
|
31
|
+
this.addObserver = (observer) => {
|
|
32
|
+
this.observers.add(observer);
|
|
33
|
+
};
|
|
34
|
+
this.removeObserver = (observer) => {
|
|
35
|
+
this.observers.remove(observer);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
get useDevicePreview() {
|
|
39
|
+
return this._usePreview;
|
|
40
|
+
}
|
|
41
|
+
get previewSize() {
|
|
42
|
+
return this._previewSize.copy();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare type OnKeyDown = (key: string) => void;
|
|
2
|
+
export declare type OnKeyUp = (key: string) => void;
|
|
3
|
+
export interface KeyboardInput {
|
|
4
|
+
eventElement: HTMLElement | undefined;
|
|
5
|
+
setEventElement: (eventElement: HTMLElement) => void;
|
|
6
|
+
removeEventElement: (eventElement: HTMLElement) => void;
|
|
7
|
+
clearInputElement: () => void;
|
|
8
|
+
isKeyPressed: (key: string) => boolean;
|
|
9
|
+
addKeyDownObserver: (observer: OnKeyDown) => void;
|
|
10
|
+
removeKeyDownObserver: (observer: OnKeyDown) => void;
|
|
11
|
+
addKeyUpObserver: (observer: OnKeyUp) => void;
|
|
12
|
+
removeKeyUpObserver: (observer: OnKeyUp) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function makeKeyboardInput(): KeyboardInput;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeKeyboardInput = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeKeyboardInput() {
|
|
6
|
+
return new KeyboardInputImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeKeyboardInput = makeKeyboardInput;
|
|
9
|
+
class KeyboardInputImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._eventElement = undefined;
|
|
12
|
+
this.setEventElement = (element) => {
|
|
13
|
+
if (this._eventElement) {
|
|
14
|
+
this._eventElement.onkeydown = null;
|
|
15
|
+
this._eventElement.onkeyup = null;
|
|
16
|
+
}
|
|
17
|
+
element.onkeydown = (e) => {
|
|
18
|
+
this.submitKeyDown(e.code);
|
|
19
|
+
};
|
|
20
|
+
element.onkeyup = (e) => {
|
|
21
|
+
this.submitKeyUp(e.code);
|
|
22
|
+
};
|
|
23
|
+
this._eventElement = element;
|
|
24
|
+
};
|
|
25
|
+
this.removeEventElement = (eventElement) => {
|
|
26
|
+
if (this._eventElement !== eventElement)
|
|
27
|
+
return;
|
|
28
|
+
this._eventElement.onkeydown = null;
|
|
29
|
+
this._eventElement.onkeyup = null;
|
|
30
|
+
this._eventElement = undefined;
|
|
31
|
+
};
|
|
32
|
+
this.clearInputElement = () => {
|
|
33
|
+
if (!this._eventElement)
|
|
34
|
+
return;
|
|
35
|
+
this._eventElement.onkeydown = null;
|
|
36
|
+
this._eventElement.onkeyup = null;
|
|
37
|
+
this._eventElement = undefined;
|
|
38
|
+
};
|
|
39
|
+
this.downObservers = new _1.ObserverList();
|
|
40
|
+
this.upObservers = new _1.ObserverList();
|
|
41
|
+
this.pressedKeys = [];
|
|
42
|
+
this.submitKeyDown = (key) => {
|
|
43
|
+
if (this.pressedKeys.includes(key))
|
|
44
|
+
return;
|
|
45
|
+
this.pressedKeys.push(key);
|
|
46
|
+
this.downObservers.notify(key);
|
|
47
|
+
};
|
|
48
|
+
this.submitKeyUp = (key) => {
|
|
49
|
+
if (!this.pressedKeys.includes(key))
|
|
50
|
+
return;
|
|
51
|
+
const index = this.pressedKeys.indexOf(key);
|
|
52
|
+
if (index >= 0) {
|
|
53
|
+
this.pressedKeys.splice(index, 1);
|
|
54
|
+
}
|
|
55
|
+
this.upObservers.notify(key);
|
|
56
|
+
};
|
|
57
|
+
this.isKeyPressed = (key) => {
|
|
58
|
+
return this.pressedKeys.includes(key);
|
|
59
|
+
};
|
|
60
|
+
this.addKeyDownObserver = (observer) => {
|
|
61
|
+
this.downObservers.add(observer);
|
|
62
|
+
};
|
|
63
|
+
this.removeKeyDownObserver = (observer) => {
|
|
64
|
+
this.downObservers.remove(observer);
|
|
65
|
+
};
|
|
66
|
+
this.addKeyUpObserver = (observer) => {
|
|
67
|
+
this.upObservers.add(observer);
|
|
68
|
+
};
|
|
69
|
+
this.removeKeyUpObserver = (observer) => {
|
|
70
|
+
this.upObservers.remove(observer);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
get eventElement() {
|
|
74
|
+
return this._eventElement;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Vector2 } from "./Vector2";
|
|
2
|
+
export declare class LineSegment2D {
|
|
3
|
+
start: Vector2;
|
|
4
|
+
end: Vector2;
|
|
5
|
+
get length(): number;
|
|
6
|
+
get direction(): Vector2;
|
|
7
|
+
getPositionAtPercent(percent: number): Vector2;
|
|
8
|
+
closestPointOnLine(point: Vector2): Vector2;
|
|
9
|
+
intersect(otherLine: LineSegment2D, tolerance?: number): Vector2 | undefined;
|
|
10
|
+
constructor(start: Vector2, end: Vector2);
|
|
11
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineSegment2D = void 0;
|
|
4
|
+
const Vector2_1 = require("./Vector2");
|
|
5
|
+
class LineSegment2D {
|
|
6
|
+
constructor(start, end) {
|
|
7
|
+
this.start = start;
|
|
8
|
+
this.end = end;
|
|
9
|
+
}
|
|
10
|
+
get length() {
|
|
11
|
+
return this.end.subtract(this.start).magnitued;
|
|
12
|
+
}
|
|
13
|
+
get direction() {
|
|
14
|
+
return this.end.subtract(this.start).unit;
|
|
15
|
+
}
|
|
16
|
+
getPositionAtPercent(percent) {
|
|
17
|
+
const dir = this.direction;
|
|
18
|
+
const length = percent * this.length;
|
|
19
|
+
dir.setLength(length);
|
|
20
|
+
return this.start.add(dir);
|
|
21
|
+
}
|
|
22
|
+
closestPointOnLine(point) {
|
|
23
|
+
// see https://monkeyproofsolutions.nl/wordpress/how-to-calculate-the-shortest-distance-between-a-point-and-a-line/
|
|
24
|
+
const direction = this.end.subtract(this.start);
|
|
25
|
+
const tNumerator = direction.dot(point.subtract(this.start));
|
|
26
|
+
const tDenominator = direction.dot(direction);
|
|
27
|
+
const t = tNumerator / tDenominator;
|
|
28
|
+
if (t < 0) {
|
|
29
|
+
return this.start.copy();
|
|
30
|
+
}
|
|
31
|
+
else if (t > 1) {
|
|
32
|
+
return this.end.copy();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const length = t * direction.magnitued;
|
|
36
|
+
direction.setLength(length);
|
|
37
|
+
return this.start.add(direction);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
intersect(otherLine, tolerance = 0) {
|
|
41
|
+
// See https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
|
|
42
|
+
const x1 = this.start.x;
|
|
43
|
+
const y1 = this.start.y;
|
|
44
|
+
const x2 = this.end.x;
|
|
45
|
+
const y2 = this.end.y;
|
|
46
|
+
const x3 = otherLine.start.x;
|
|
47
|
+
const y3 = otherLine.start.y;
|
|
48
|
+
const x4 = otherLine.end.x;
|
|
49
|
+
const y4 = otherLine.end.y;
|
|
50
|
+
const denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
|
51
|
+
if (denominator === 0) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const tNumerator = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
|
|
55
|
+
const t = tNumerator / denominator;
|
|
56
|
+
const tTolearnce = tolerance / this.length;
|
|
57
|
+
if (t < -tTolearnce || t > 1 + tTolearnce) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const uNumerator = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
|
61
|
+
const u = uNumerator / denominator;
|
|
62
|
+
const uTolearnce = tolerance / otherLine.length;
|
|
63
|
+
if (u < -uTolearnce || u > 1 + uTolearnce)
|
|
64
|
+
return undefined;
|
|
65
|
+
const px = x1 + t * (x2 - x1);
|
|
66
|
+
const py = y1 + t * (y2 - y1);
|
|
67
|
+
return new Vector2_1.Vector2(px, py);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.LineSegment2D = LineSegment2D;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
19
|
+
exports.MemoizedBoolean = MemoizedBoolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
19
|
+
exports.MemoizedNumber = MemoizedNumber;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoizedString = void 0;
|
|
4
|
+
class MemoizedString {
|
|
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
|
+
}
|
|
19
|
+
exports.MemoizedString = MemoizedString;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Vector2 } from "./Vector2";
|
|
2
|
+
export declare class MemoizedVector2 {
|
|
3
|
+
private _val;
|
|
4
|
+
get x(): number;
|
|
5
|
+
set x(x: number);
|
|
6
|
+
get y(): number;
|
|
7
|
+
set y(y: number);
|
|
8
|
+
getVector(): Vector2;
|
|
9
|
+
setVector(vec: Vector2): void;
|
|
10
|
+
private onChangeCallback;
|
|
11
|
+
constructor(initialValue: Vector2, onChangeCallback: () => void);
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoizedVector2 = void 0;
|
|
4
|
+
class MemoizedVector2 {
|
|
5
|
+
constructor(initialValue, onChangeCallback) {
|
|
6
|
+
this._val = initialValue.copy();
|
|
7
|
+
this.onChangeCallback = onChangeCallback;
|
|
8
|
+
}
|
|
9
|
+
get x() {
|
|
10
|
+
return this._val.x;
|
|
11
|
+
}
|
|
12
|
+
set x(x) {
|
|
13
|
+
if (this._val.x === x)
|
|
14
|
+
return;
|
|
15
|
+
this._val.x = x;
|
|
16
|
+
this.onChangeCallback();
|
|
17
|
+
}
|
|
18
|
+
get y() {
|
|
19
|
+
return this._val.y;
|
|
20
|
+
}
|
|
21
|
+
set y(y) {
|
|
22
|
+
if (this._val.y === y)
|
|
23
|
+
return;
|
|
24
|
+
this._val.y = y;
|
|
25
|
+
this.onChangeCallback();
|
|
26
|
+
}
|
|
27
|
+
getVector() {
|
|
28
|
+
return this._val.copy();
|
|
29
|
+
}
|
|
30
|
+
setVector(vec) {
|
|
31
|
+
if (vec.x === this._val.x && vec.y === this._val.y)
|
|
32
|
+
return;
|
|
33
|
+
this._val = vec.copy();
|
|
34
|
+
this.onChangeCallback();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.MemoizedVector2 = MemoizedVector2;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector3 } from "./Vector3";
|
|
2
|
+
export declare class MemoizedVector3 {
|
|
3
|
+
private _val;
|
|
4
|
+
get x(): number;
|
|
5
|
+
set x(x: number);
|
|
6
|
+
get y(): number;
|
|
7
|
+
set y(y: number);
|
|
8
|
+
get z(): number;
|
|
9
|
+
set z(z: number);
|
|
10
|
+
getVector(): Vector3;
|
|
11
|
+
setVector(vec: Vector3): void;
|
|
12
|
+
private onChangeCallback;
|
|
13
|
+
constructor(initialValue: Vector3, onChangeCallback: () => void);
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoizedVector3 = void 0;
|
|
4
|
+
class MemoizedVector3 {
|
|
5
|
+
constructor(initialValue, onChangeCallback) {
|
|
6
|
+
this._val = initialValue.copy();
|
|
7
|
+
this.onChangeCallback = onChangeCallback;
|
|
8
|
+
}
|
|
9
|
+
get x() {
|
|
10
|
+
return this._val.x;
|
|
11
|
+
}
|
|
12
|
+
set x(x) {
|
|
13
|
+
if (this._val.x === x)
|
|
14
|
+
return;
|
|
15
|
+
this._val.x = x;
|
|
16
|
+
this.onChangeCallback();
|
|
17
|
+
}
|
|
18
|
+
get y() {
|
|
19
|
+
return this._val.y;
|
|
20
|
+
}
|
|
21
|
+
set y(y) {
|
|
22
|
+
if (this._val.y === y)
|
|
23
|
+
return;
|
|
24
|
+
this._val.y = y;
|
|
25
|
+
this.onChangeCallback();
|
|
26
|
+
}
|
|
27
|
+
get z() {
|
|
28
|
+
return this._val.z;
|
|
29
|
+
}
|
|
30
|
+
set z(z) {
|
|
31
|
+
if (this._val.z === z)
|
|
32
|
+
return;
|
|
33
|
+
this._val.z = z;
|
|
34
|
+
this.onChangeCallback();
|
|
35
|
+
}
|
|
36
|
+
getVector() {
|
|
37
|
+
return this._val.copy();
|
|
38
|
+
}
|
|
39
|
+
setVector(vec) {
|
|
40
|
+
if (vec.x === this._val.x && vec.y === this._val.y && vec.z === this._val.z)
|
|
41
|
+
return;
|
|
42
|
+
this._val = vec.copy();
|
|
43
|
+
this.onChangeCallback();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MemoizedVector3 = MemoizedVector3;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObserverList = void 0;
|
|
4
|
+
class ObserverList {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.observers = [];
|
|
7
|
+
this.notify = (msg) => {
|
|
8
|
+
this.observers.forEach((obs) => {
|
|
9
|
+
obs(msg);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
this.add = (obs) => {
|
|
13
|
+
this.observers.push(obs);
|
|
14
|
+
};
|
|
15
|
+
this.remove = (obs) => {
|
|
16
|
+
const index = this.observers.indexOf(obs);
|
|
17
|
+
if (index >= 0) {
|
|
18
|
+
this.observers.splice(index, 1);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ObserverList = ObserverList;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Vector3 } from ".";
|
|
2
|
+
export declare type OnOrbitCameraChange = () => void;
|
|
3
|
+
export interface CameraLerper {
|
|
4
|
+
cancelLerp: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface OrbitCamera {
|
|
7
|
+
alpha: number;
|
|
8
|
+
beta: number;
|
|
9
|
+
radius: number;
|
|
10
|
+
target: Vector3;
|
|
11
|
+
registerLerp: (lerper: CameraLerper) => void;
|
|
12
|
+
lerpCompleted: () => void;
|
|
13
|
+
cancelLerp: () => void;
|
|
14
|
+
addObserver: (observer: OnOrbitCameraChange) => void;
|
|
15
|
+
removeObserver: (observer: OnOrbitCameraChange) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function makeOrbitCamera(): OrbitCamera;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeOrbitCamera = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeOrbitCamera() {
|
|
6
|
+
return new OrbitCameraImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeOrbitCamera = makeOrbitCamera;
|
|
9
|
+
class OrbitCameraImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.observers = new _1.ObserverList();
|
|
12
|
+
this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
|
|
13
|
+
this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
|
|
14
|
+
this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
|
|
15
|
+
this.memoizedTarget = new _1.MemoizedVector3(_1.Vector3.Zero(), this.observers.notify);
|
|
16
|
+
this.registerLerp = (lerper) => {
|
|
17
|
+
if (this.currentLerp) {
|
|
18
|
+
this.currentLerp.cancelLerp();
|
|
19
|
+
}
|
|
20
|
+
this.currentLerp = lerper;
|
|
21
|
+
};
|
|
22
|
+
this.lerpCompleted = () => {
|
|
23
|
+
this.currentLerp = undefined;
|
|
24
|
+
};
|
|
25
|
+
this.cancelLerp = () => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = this.currentLerp) === null || _a === void 0 ? void 0 : _a.cancelLerp();
|
|
28
|
+
this.currentLerp = undefined;
|
|
29
|
+
};
|
|
30
|
+
this.addObserver = (observer) => {
|
|
31
|
+
this.observers.add(observer);
|
|
32
|
+
};
|
|
33
|
+
this.removeObserver = (observer) => {
|
|
34
|
+
this.observers.remove(observer);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
get alpha() {
|
|
38
|
+
return this.memoizedAlpha.val;
|
|
39
|
+
}
|
|
40
|
+
set alpha(val) {
|
|
41
|
+
this.memoizedAlpha.val = this.clampAngle(val);
|
|
42
|
+
}
|
|
43
|
+
get beta() {
|
|
44
|
+
return this.memoizedBeta.val;
|
|
45
|
+
}
|
|
46
|
+
set beta(val) {
|
|
47
|
+
this.memoizedBeta.val = this.clampAngle(val);
|
|
48
|
+
}
|
|
49
|
+
get radius() {
|
|
50
|
+
return this.memoizedRadius.val;
|
|
51
|
+
}
|
|
52
|
+
set radius(val) {
|
|
53
|
+
this.memoizedRadius.val = val < 0 ? 0 : val;
|
|
54
|
+
}
|
|
55
|
+
get target() {
|
|
56
|
+
return this.memoizedTarget.getVector();
|
|
57
|
+
}
|
|
58
|
+
set target(val) {
|
|
59
|
+
this.memoizedTarget.setVector(val);
|
|
60
|
+
}
|
|
61
|
+
clampAngle(angle) {
|
|
62
|
+
const isNegative = angle < 0 ? true : false;
|
|
63
|
+
const absAngle = Math.abs(angle);
|
|
64
|
+
const revolutions = Math.floor(absAngle / 360);
|
|
65
|
+
let angleWithoutRevolutions = absAngle - revolutions * 360;
|
|
66
|
+
if (angleWithoutRevolutions > 180) {
|
|
67
|
+
angleWithoutRevolutions = angleWithoutRevolutions - 360;
|
|
68
|
+
}
|
|
69
|
+
if (isNegative) {
|
|
70
|
+
angleWithoutRevolutions *= -1;
|
|
71
|
+
}
|
|
72
|
+
return angleWithoutRevolutions;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Vector3 } from "./Vector3";
|
|
2
|
+
export interface LineParameters {
|
|
3
|
+
x0: number;
|
|
4
|
+
y0: number;
|
|
5
|
+
z0: number;
|
|
6
|
+
a: number;
|
|
7
|
+
b: number;
|
|
8
|
+
c: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class ParametricLine {
|
|
11
|
+
private x0;
|
|
12
|
+
private y0;
|
|
13
|
+
private z0;
|
|
14
|
+
private a;
|
|
15
|
+
private b;
|
|
16
|
+
private c;
|
|
17
|
+
static FromTwoPoint(p1: Vector3, p2: Vector3): ParametricLine;
|
|
18
|
+
static FromPointDirection(point: Vector3, direction: Vector3): ParametricLine;
|
|
19
|
+
static Forward(): ParametricLine;
|
|
20
|
+
static Backward(): ParametricLine;
|
|
21
|
+
static Up(): ParametricLine;
|
|
22
|
+
static Down(): ParametricLine;
|
|
23
|
+
static Left(): ParametricLine;
|
|
24
|
+
static Right(): ParametricLine;
|
|
25
|
+
getPointAtDistance(distance: number): Vector3;
|
|
26
|
+
getParameters(): LineParameters;
|
|
27
|
+
copy(): ParametricLine;
|
|
28
|
+
constructor(parameters: LineParameters);
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParametricLine = void 0;
|
|
4
|
+
const Vector3_1 = require("./Vector3");
|
|
5
|
+
class ParametricLine {
|
|
6
|
+
constructor(parameters) {
|
|
7
|
+
this.x0 = parameters.x0;
|
|
8
|
+
this.y0 = parameters.y0;
|
|
9
|
+
this.z0 = parameters.z0;
|
|
10
|
+
this.a = parameters.a;
|
|
11
|
+
this.b = parameters.b;
|
|
12
|
+
this.c = parameters.c;
|
|
13
|
+
}
|
|
14
|
+
static FromTwoPoint(p1, p2) {
|
|
15
|
+
const dir = p2.subtract(p1).unit;
|
|
16
|
+
return this.FromPointDirection(p1, dir);
|
|
17
|
+
}
|
|
18
|
+
static FromPointDirection(point, direction) {
|
|
19
|
+
return new ParametricLine({
|
|
20
|
+
x0: point.x,
|
|
21
|
+
y0: point.y,
|
|
22
|
+
z0: point.z,
|
|
23
|
+
a: direction.x,
|
|
24
|
+
b: direction.y,
|
|
25
|
+
c: direction.z,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
static Forward() {
|
|
29
|
+
const p = Vector3_1.Vector3.Zero();
|
|
30
|
+
const d = new Vector3_1.Vector3(0, 0, 1);
|
|
31
|
+
return this.FromPointDirection(p, d);
|
|
32
|
+
}
|
|
33
|
+
static Backward() {
|
|
34
|
+
const p = Vector3_1.Vector3.Zero();
|
|
35
|
+
const d = new Vector3_1.Vector3(0, 0, -1);
|
|
36
|
+
return this.FromPointDirection(p, d);
|
|
37
|
+
}
|
|
38
|
+
static Up() {
|
|
39
|
+
const p = Vector3_1.Vector3.Zero();
|
|
40
|
+
const d = new Vector3_1.Vector3(0, 1, 0);
|
|
41
|
+
return this.FromPointDirection(p, d);
|
|
42
|
+
}
|
|
43
|
+
static Down() {
|
|
44
|
+
const p = Vector3_1.Vector3.Zero();
|
|
45
|
+
const d = new Vector3_1.Vector3(0, -1, 0);
|
|
46
|
+
return this.FromPointDirection(p, d);
|
|
47
|
+
}
|
|
48
|
+
static Left() {
|
|
49
|
+
const p = Vector3_1.Vector3.Zero();
|
|
50
|
+
const d = new Vector3_1.Vector3(-1, 0, 0);
|
|
51
|
+
return this.FromPointDirection(p, d);
|
|
52
|
+
}
|
|
53
|
+
static Right() {
|
|
54
|
+
const p = Vector3_1.Vector3.Zero();
|
|
55
|
+
const d = new Vector3_1.Vector3(1, 0, 0);
|
|
56
|
+
return this.FromPointDirection(p, d);
|
|
57
|
+
}
|
|
58
|
+
getPointAtDistance(distance) {
|
|
59
|
+
const x = this.x0 + this.a * distance;
|
|
60
|
+
const y = this.y0 + this.b * distance;
|
|
61
|
+
const z = this.z0 + this.c * distance;
|
|
62
|
+
return new Vector3_1.Vector3(x, y, z);
|
|
63
|
+
}
|
|
64
|
+
getParameters() {
|
|
65
|
+
return {
|
|
66
|
+
x0: this.x0,
|
|
67
|
+
y0: this.y0,
|
|
68
|
+
z0: this.z0,
|
|
69
|
+
a: this.a,
|
|
70
|
+
b: this.b,
|
|
71
|
+
c: this.c,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
copy() {
|
|
75
|
+
const parameters = this.getParameters();
|
|
76
|
+
return new ParametricLine(parameters);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ParametricLine = ParametricLine;
|