@vived/app 2.5.0 → 2.6.3
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 +31 -0
- package/lib/Entities/Babylon.js +99 -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/MouseInput.d.ts +15 -0
- package/lib/Entities/MouseInput.js +112 -0
- package/lib/Entities/MouseSceneInput.d.ts +15 -0
- package/lib/Entities/MouseSceneInput.js +109 -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/TouchInput.d.ts +20 -0
- package/lib/Entities/TouchInput.js +111 -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 +21 -0
- package/lib/Entities/index.js +33 -0
- package/lib/Interface/Controllers/makeAppHandler.d.ts +1 -1
- package/lib/Interface/Controllers/makeAppHandler.js +21 -10
- 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/package.json +4 -2
- package/CHANGELOG.md +0 -51
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMouseSceneInput = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeMouseSceneInput() {
|
|
6
|
+
return new MouseSceneInputImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeMouseSceneInput = makeMouseSceneInput;
|
|
9
|
+
class MouseSceneInputImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.controllers = [];
|
|
12
|
+
this.maxClickMovement = 5; // pixels
|
|
13
|
+
this._eventElement = undefined;
|
|
14
|
+
this.setEventElement = (eventElement) => {
|
|
15
|
+
if (this._eventElement)
|
|
16
|
+
this.clearInputElement();
|
|
17
|
+
eventElement.addEventListener("mousedown", this.onMouseDown);
|
|
18
|
+
eventElement.addEventListener("mouseup", this.onMouseUp);
|
|
19
|
+
eventElement.addEventListener("mousemove", this.onMouseMove);
|
|
20
|
+
eventElement.addEventListener("mouseout", this.onMouseOut);
|
|
21
|
+
eventElement.addEventListener("wheel", this.onWheel);
|
|
22
|
+
this._eventElement = eventElement;
|
|
23
|
+
};
|
|
24
|
+
this.clearInputElement = () => {
|
|
25
|
+
if (!this._eventElement)
|
|
26
|
+
return;
|
|
27
|
+
this._eventElement.removeEventListener("mousedown", this.onMouseDown);
|
|
28
|
+
this._eventElement.removeEventListener("mouseup", this.onMouseUp);
|
|
29
|
+
this._eventElement.removeEventListener("mousemove", this.onMouseMove);
|
|
30
|
+
this._eventElement.removeEventListener("mouseout", this.onMouseOut);
|
|
31
|
+
this._eventElement.removeEventListener("wheel", this.onWheel);
|
|
32
|
+
this._eventElement = undefined;
|
|
33
|
+
};
|
|
34
|
+
this.registerController = (controller) => {
|
|
35
|
+
this.controllers.push(controller);
|
|
36
|
+
};
|
|
37
|
+
this.removeController = (controller) => {
|
|
38
|
+
const index = this.controllers.indexOf(controller);
|
|
39
|
+
if (index >= 0) {
|
|
40
|
+
this.controllers.splice(index, 1);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.onMouseDown = (e) => {
|
|
44
|
+
const mousePos = new _1.Vector2(e.offsetX, e.offsetY);
|
|
45
|
+
this.controllers.forEach((c) => {
|
|
46
|
+
if (c.onDown) {
|
|
47
|
+
c.onDown(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
this.pressEvent = e;
|
|
51
|
+
};
|
|
52
|
+
this.onMouseUp = (e) => {
|
|
53
|
+
this.controllers.forEach((c) => {
|
|
54
|
+
if (c.onUp) {
|
|
55
|
+
c.onUp(e);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (!this.pressEvent)
|
|
59
|
+
return;
|
|
60
|
+
const deltaX = this.pressEvent.screenX - e.screenX;
|
|
61
|
+
const deltaY = this.pressEvent.screenY - e.screenY;
|
|
62
|
+
const delta = new _1.Vector2(deltaX, deltaY);
|
|
63
|
+
if (delta.magnitued < this.maxClickMovement) {
|
|
64
|
+
this.controllers.forEach((c) => {
|
|
65
|
+
if (c.onClick) {
|
|
66
|
+
c.onClick(e);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
this.pressEvent = undefined;
|
|
71
|
+
};
|
|
72
|
+
this.onMouseMove = (e) => {
|
|
73
|
+
this.controllers.forEach((c) => {
|
|
74
|
+
if (c.onMove) {
|
|
75
|
+
c.onMove(e);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!this.pressEvent)
|
|
79
|
+
return;
|
|
80
|
+
const deltaX = this.pressEvent.screenX - e.screenX;
|
|
81
|
+
const deltaY = this.pressEvent.screenY - e.screenY;
|
|
82
|
+
const delta = new _1.Vector2(deltaX, deltaY);
|
|
83
|
+
if (delta.magnitued > this.maxClickMovement) {
|
|
84
|
+
this.pressEvent = undefined;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
this.onMouseOut = (e) => {
|
|
88
|
+
if (!this.pressEvent)
|
|
89
|
+
return;
|
|
90
|
+
const mousePos = new _1.Vector2(e.offsetX, e.offsetY);
|
|
91
|
+
this.controllers.forEach((c) => {
|
|
92
|
+
if (c.onUp) {
|
|
93
|
+
c.onUp(e);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
this.pressEvent = undefined;
|
|
97
|
+
};
|
|
98
|
+
this.onWheel = (e) => {
|
|
99
|
+
this.controllers.forEach((c) => {
|
|
100
|
+
if (c.onWheel) {
|
|
101
|
+
c.onWheel(e);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
get eventElement() {
|
|
107
|
+
return this._eventElement;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ParametricLine } from "./ParametricLine";
|
|
2
|
+
import { Vector3 } from "./Vector3";
|
|
3
|
+
export interface PlaneParameters {
|
|
4
|
+
a: number;
|
|
5
|
+
b: number;
|
|
6
|
+
c: number;
|
|
7
|
+
d: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class ParametricPlane {
|
|
10
|
+
static FromPointNormal(point: Vector3, normal: Vector3): ParametricPlane;
|
|
11
|
+
static FromThreePoints(A: Vector3, B: Vector3, C: Vector3): ParametricPlane;
|
|
12
|
+
static XY(): ParametricPlane;
|
|
13
|
+
static ZX(): ParametricPlane;
|
|
14
|
+
static YZ(): ParametricPlane;
|
|
15
|
+
private point;
|
|
16
|
+
private normal;
|
|
17
|
+
getParameters(): PlaneParameters;
|
|
18
|
+
intersectLine(line: ParametricLine): Vector3 | undefined;
|
|
19
|
+
constructor(point: Vector3, normal: Vector3);
|
|
20
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParametricPlane = void 0;
|
|
4
|
+
const Vector3_1 = require("./Vector3");
|
|
5
|
+
class ParametricPlane {
|
|
6
|
+
constructor(point, normal) {
|
|
7
|
+
this.point = point.copy();
|
|
8
|
+
this.normal = normal.copy();
|
|
9
|
+
}
|
|
10
|
+
static FromPointNormal(point, normal) {
|
|
11
|
+
return new ParametricPlane(point, normal);
|
|
12
|
+
}
|
|
13
|
+
static FromThreePoints(A, B, C) {
|
|
14
|
+
const point = A;
|
|
15
|
+
const AB = B.subtract(A);
|
|
16
|
+
const AC = C.subtract(A);
|
|
17
|
+
const normal = AB.cross(AC);
|
|
18
|
+
return new ParametricPlane(point, normal);
|
|
19
|
+
}
|
|
20
|
+
static XY() {
|
|
21
|
+
const p = Vector3_1.Vector3.Zero();
|
|
22
|
+
const n = new Vector3_1.Vector3(0, 0, 1);
|
|
23
|
+
return new ParametricPlane(p, n);
|
|
24
|
+
}
|
|
25
|
+
static ZX() {
|
|
26
|
+
const p = Vector3_1.Vector3.Zero();
|
|
27
|
+
const n = new Vector3_1.Vector3(0, 1, 0);
|
|
28
|
+
return new ParametricPlane(p, n);
|
|
29
|
+
}
|
|
30
|
+
static YZ() {
|
|
31
|
+
const p = Vector3_1.Vector3.Zero();
|
|
32
|
+
const n = new Vector3_1.Vector3(1, 0, 0);
|
|
33
|
+
return new ParametricPlane(p, n);
|
|
34
|
+
}
|
|
35
|
+
getParameters() {
|
|
36
|
+
const a = this.normal.x;
|
|
37
|
+
const b = this.normal.y;
|
|
38
|
+
const c = this.normal.z;
|
|
39
|
+
let d = this.point.dot(this.normal);
|
|
40
|
+
if (d !== 0) {
|
|
41
|
+
d *= -1;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
a,
|
|
45
|
+
b,
|
|
46
|
+
c,
|
|
47
|
+
d,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
intersectLine(line) {
|
|
51
|
+
const { x0, y0, z0, a, b, c } = line.getParameters();
|
|
52
|
+
const { a: A, b: B, c: C, d: D } = this.getParameters();
|
|
53
|
+
const tNumerator = -(A * x0 + B * y0 + C * z0 + D);
|
|
54
|
+
const tDenominator = A * a + B * b + C * c;
|
|
55
|
+
if (tDenominator === 0) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const t = tNumerator / tDenominator;
|
|
59
|
+
const intersect = line.getPointAtDistance(t);
|
|
60
|
+
return intersect;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ParametricPlane = ParametricPlane;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SerializedStates {
|
|
2
|
+
version: number;
|
|
3
|
+
systems: SystemState[];
|
|
4
|
+
}
|
|
5
|
+
export interface SystemState {
|
|
6
|
+
name: string;
|
|
7
|
+
seriliziationVersion: number;
|
|
8
|
+
state: object;
|
|
9
|
+
}
|
|
10
|
+
export interface SerializedSystem {
|
|
11
|
+
name: string;
|
|
12
|
+
seriliziationVersion: number;
|
|
13
|
+
getSystemState(): object;
|
|
14
|
+
applySystemState(state: object, version: number, transitionDuration: number): void;
|
|
15
|
+
applyDefaultState(transitionDuration: number): void;
|
|
16
|
+
}
|
|
17
|
+
export interface StateMachine {
|
|
18
|
+
transitionEaseFunction: (normalizedTime: number) => number;
|
|
19
|
+
getSerializedStates(): SerializedStates;
|
|
20
|
+
setSerializedStates(state: SerializedStates, transitionTime: number): void;
|
|
21
|
+
applySerializedStatesString: (state: string, duration?: number) => void;
|
|
22
|
+
setDefaultState(transitionTime: number): void;
|
|
23
|
+
registerSerializedSystem(serializedSystem: SerializedSystem): void;
|
|
24
|
+
}
|
|
25
|
+
export declare function makeStateMachine(): StateMachine;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeStateMachine = void 0;
|
|
4
|
+
function makeStateMachine() {
|
|
5
|
+
return new StateMachineImp();
|
|
6
|
+
}
|
|
7
|
+
exports.makeStateMachine = makeStateMachine;
|
|
8
|
+
class StateMachineImp {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.serializedSystems = new Map();
|
|
11
|
+
this.serilizationVersion = 2;
|
|
12
|
+
this.transitionEaseFunction = (normalizedTime) => {
|
|
13
|
+
return normalizedTime; // default to a linear function
|
|
14
|
+
};
|
|
15
|
+
this.applySerializedStatesString = (state, duration = 0) => {
|
|
16
|
+
if (state === "") {
|
|
17
|
+
this.setDefaultState(duration);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
try {
|
|
21
|
+
const stateObj = JSON.parse(state);
|
|
22
|
+
this.setSerializedStates(stateObj, duration);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
this.setDefaultState(duration);
|
|
26
|
+
console.warn("[StateMachine] Failed to deserialize state string: " + e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.registerSerializedSystem = (serializedSystem) => {
|
|
31
|
+
if (this.serializedSystems.has(serializedSystem.name)) {
|
|
32
|
+
throw new Error(`[StateMachine] Duplicate stateable systems encountered: ${serializedSystem.name}`);
|
|
33
|
+
}
|
|
34
|
+
this.serializedSystems.set(serializedSystem.name, serializedSystem);
|
|
35
|
+
};
|
|
36
|
+
this.getSerializedStates = () => {
|
|
37
|
+
const systems = Array.from(this.serializedSystems.values());
|
|
38
|
+
const serializedStates = systems.map((system) => {
|
|
39
|
+
const state = system.getSystemState();
|
|
40
|
+
return {
|
|
41
|
+
seriliziationVersion: system.seriliziationVersion,
|
|
42
|
+
name: system.name,
|
|
43
|
+
state,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
version: this.serilizationVersion,
|
|
48
|
+
systems: serializedStates,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
this.setSerializedStates = (state, duration) => {
|
|
52
|
+
if (state.version === 2) {
|
|
53
|
+
const appliedToSystems = [];
|
|
54
|
+
state.systems.forEach((systemState) => {
|
|
55
|
+
const seriliazableSystem = this.serializedSystems.get(systemState.name);
|
|
56
|
+
if (seriliazableSystem) {
|
|
57
|
+
seriliazableSystem.applySystemState(systemState.state, systemState.seriliziationVersion, duration);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.warn("Unable to find seriarializedSystem " + systemState.name);
|
|
61
|
+
}
|
|
62
|
+
appliedToSystems.push(systemState.name);
|
|
63
|
+
});
|
|
64
|
+
this.serializedSystems.forEach((system) => {
|
|
65
|
+
if (!appliedToSystems.includes(system.name)) {
|
|
66
|
+
system.applyDefaultState(duration);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Here is where we will add support for future versions
|
|
71
|
+
else {
|
|
72
|
+
throw new Error(`[StateMachine] Unsupported sereialized state encountered: ${state.version}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this.setDefaultState = (duration) => {
|
|
76
|
+
this.serializedSystems.forEach((system) => {
|
|
77
|
+
system.applyDefaultState(duration);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Vector2 } from ".";
|
|
2
|
+
export interface TouchController {
|
|
3
|
+
onTouchStart?: (e: TouchEvent) => void;
|
|
4
|
+
onTouchMove?: (e: TouchEvent) => void;
|
|
5
|
+
onTouchEnd?: (e: TouchEvent) => void;
|
|
6
|
+
onTouchCancel?: (e: TouchEvent) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface TouchInput {
|
|
9
|
+
eventElement: HTMLElement | undefined;
|
|
10
|
+
eventElementBounds?: DOMRect;
|
|
11
|
+
setEventElement: (eventElement: HTMLElement) => void;
|
|
12
|
+
clearInputElement: () => void;
|
|
13
|
+
updateInputElementBounds: () => void;
|
|
14
|
+
getTouchOffsetPosition: (touch: Touch) => Vector2;
|
|
15
|
+
getDistatnceBetweenTouches: (touch1: Touch, touch2: Touch) => number;
|
|
16
|
+
getTouchsCenter: (touches: TouchList) => Vector2;
|
|
17
|
+
registerController: (controller: TouchController) => void;
|
|
18
|
+
removeController: (controller: TouchController) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function makeTouchInput(): TouchInput;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTouchInput = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeTouchInput() {
|
|
6
|
+
return new TouchInputImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeTouchInput = makeTouchInput;
|
|
9
|
+
class TouchInputImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.controllers = [];
|
|
12
|
+
this._eventElement = undefined;
|
|
13
|
+
this.updateInputElementBounds = () => {
|
|
14
|
+
if (!this._eventElement)
|
|
15
|
+
return;
|
|
16
|
+
this.eventElementBounds = this._eventElement.getBoundingClientRect(); // Expensive so we cache
|
|
17
|
+
};
|
|
18
|
+
this.getTouchOffsetPosition = (touch) => {
|
|
19
|
+
if (!this.eventElementBounds) {
|
|
20
|
+
console.warn("No target bounds");
|
|
21
|
+
return _1.Vector2.Zero();
|
|
22
|
+
}
|
|
23
|
+
const x = touch.clientX - this.eventElementBounds.x;
|
|
24
|
+
const y = touch.clientY - this.eventElementBounds.y;
|
|
25
|
+
return new _1.Vector2(x, y);
|
|
26
|
+
};
|
|
27
|
+
this.getDistatnceBetweenTouches = (touch1, touch2) => {
|
|
28
|
+
const t1 = this.getTouchOffsetPosition(touch1);
|
|
29
|
+
const t2 = this.getTouchOffsetPosition(touch2);
|
|
30
|
+
const delta = t2.subtract(t1);
|
|
31
|
+
return delta.magnitued;
|
|
32
|
+
};
|
|
33
|
+
this.getTouchsCenter = (touches) => {
|
|
34
|
+
const touchCount = touches.length;
|
|
35
|
+
if (touchCount === 0)
|
|
36
|
+
return _1.Vector2.Zero();
|
|
37
|
+
let sumX = 0;
|
|
38
|
+
let sumY = 0;
|
|
39
|
+
for (let i = 0; i < touchCount; i++) {
|
|
40
|
+
const touch = touches[i];
|
|
41
|
+
const touchPos = this.getTouchOffsetPosition(touch);
|
|
42
|
+
sumX += touchPos.x;
|
|
43
|
+
sumY += touchPos.y;
|
|
44
|
+
}
|
|
45
|
+
return new _1.Vector2(sumX / touches.length, sumY / touches.length);
|
|
46
|
+
};
|
|
47
|
+
this.setEventElement = (eventElement) => {
|
|
48
|
+
if (this._eventElement)
|
|
49
|
+
this.clearInputElement();
|
|
50
|
+
eventElement.addEventListener("touchstart", this.onTouchStart, false);
|
|
51
|
+
eventElement.addEventListener("touchmove", this.onTouchMove, false);
|
|
52
|
+
eventElement.addEventListener("touchend", this.onTouchEnd, false);
|
|
53
|
+
eventElement.addEventListener("touchcancel", this.onTouchCancel, false);
|
|
54
|
+
this.eventElementBounds = eventElement.getBoundingClientRect();
|
|
55
|
+
this._eventElement = eventElement;
|
|
56
|
+
};
|
|
57
|
+
this.onTouchStart = (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
this.controllers.forEach((c) => {
|
|
60
|
+
if (c.onTouchStart) {
|
|
61
|
+
c.onTouchStart(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
this.onTouchMove = (e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
this.controllers.forEach((c) => {
|
|
68
|
+
if (c.onTouchMove) {
|
|
69
|
+
c.onTouchMove(e);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
this.onTouchEnd = (e) => {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
this.controllers.forEach((c) => {
|
|
76
|
+
if (c.onTouchEnd) {
|
|
77
|
+
c.onTouchEnd(e);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
this.onTouchCancel = (e) => {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
this.controllers.forEach((c) => {
|
|
84
|
+
if (c.onTouchCancel) {
|
|
85
|
+
c.onTouchCancel(e);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
this.clearInputElement = () => {
|
|
90
|
+
if (!this._eventElement)
|
|
91
|
+
return;
|
|
92
|
+
this._eventElement.removeEventListener("touchstart", this.onTouchStart);
|
|
93
|
+
this._eventElement.removeEventListener("touchmove", this.onTouchMove);
|
|
94
|
+
this._eventElement.removeEventListener("touchend", this.onTouchEnd);
|
|
95
|
+
this._eventElement.removeEventListener("touchcancel", this.onTouchCancel);
|
|
96
|
+
this._eventElement = undefined;
|
|
97
|
+
};
|
|
98
|
+
this.registerController = (controller) => {
|
|
99
|
+
this.controllers.push(controller);
|
|
100
|
+
};
|
|
101
|
+
this.removeController = (controller) => {
|
|
102
|
+
const index = this.controllers.indexOf(controller);
|
|
103
|
+
if (index >= 0) {
|
|
104
|
+
this.controllers.splice(index, 1);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
get eventElement() {
|
|
109
|
+
return this._eventElement;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare type OnUndoRedoChange = () => void;
|
|
2
|
+
export interface UndoRedoer {
|
|
3
|
+
undoAction: (action: UndoRedoAction) => void;
|
|
4
|
+
redoAction: (action: UndoRedoAction) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare type DoUndoRedoAction = (action: UndoRedoAction) => void;
|
|
7
|
+
export interface UndoRedo {
|
|
8
|
+
hasUndo: boolean;
|
|
9
|
+
hasRedo: boolean;
|
|
10
|
+
submitAction: (action: UndoRedoAction) => void;
|
|
11
|
+
doUndo: () => void;
|
|
12
|
+
doRedo: () => void;
|
|
13
|
+
clearStack: () => void;
|
|
14
|
+
registerUndoRedoer: (undoRedoer: UndoRedoer) => void;
|
|
15
|
+
addObserver: (observer: OnUndoRedoChange) => void;
|
|
16
|
+
removeObserver: (observer: OnUndoRedoChange) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function makeUndoRedo(): UndoRedo;
|
|
19
|
+
export declare type UndoRedoAction = {
|
|
20
|
+
type: string;
|
|
21
|
+
payload: object;
|
|
22
|
+
};
|