@vived/app 2.6.0 → 2.6.4
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/UseCase.js +1 -1
- 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 +12 -10
- 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 -58
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUndoRedo = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeUndoRedo() {
|
|
6
|
+
return new UndoRedoImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeUndoRedo = makeUndoRedo;
|
|
9
|
+
class UndoRedoImp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.observers = new _1.ObserverList();
|
|
12
|
+
this.undoRedoers = [];
|
|
13
|
+
this.undoStack = [];
|
|
14
|
+
this.redoStack = [];
|
|
15
|
+
this.doUndo = () => {
|
|
16
|
+
const action = this.undoStack.pop();
|
|
17
|
+
if (!action) {
|
|
18
|
+
console.warn("[UndoRedo] nothing to undo");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.redoStack.push(action);
|
|
22
|
+
this.undoRedoers.forEach(undoers => undoers.undoAction(action));
|
|
23
|
+
this.observers.notify();
|
|
24
|
+
};
|
|
25
|
+
this.doRedo = () => {
|
|
26
|
+
const action = this.redoStack.pop();
|
|
27
|
+
if (!action) {
|
|
28
|
+
console.warn("[UndoRedo] nothing to redo");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.undoStack.push(action);
|
|
32
|
+
this.undoRedoers.forEach(redoers => redoers.redoAction(action));
|
|
33
|
+
this.observers.notify();
|
|
34
|
+
};
|
|
35
|
+
this.submitAction = (action) => {
|
|
36
|
+
this.undoStack.push(action);
|
|
37
|
+
this.redoStack = [];
|
|
38
|
+
this.observers.notify();
|
|
39
|
+
};
|
|
40
|
+
this.clearStack = () => {
|
|
41
|
+
this.redoStack = [];
|
|
42
|
+
this.undoStack = [];
|
|
43
|
+
this.observers.notify();
|
|
44
|
+
};
|
|
45
|
+
this.registerUndoRedoer = (undoredoer) => {
|
|
46
|
+
this.undoRedoers.push(undoredoer);
|
|
47
|
+
};
|
|
48
|
+
this.addObserver = (observer) => {
|
|
49
|
+
this.observers.add(observer);
|
|
50
|
+
};
|
|
51
|
+
this.removeObserver = (observer) => {
|
|
52
|
+
this.observers.remove(observer);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
get hasUndo() {
|
|
56
|
+
return this.undoStack.length > 0;
|
|
57
|
+
}
|
|
58
|
+
get hasRedo() {
|
|
59
|
+
return this.redoStack.length > 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class Vector2 {
|
|
2
|
+
static Zero(): Vector2;
|
|
3
|
+
static One(): Vector2;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
get magnitued(): number;
|
|
7
|
+
get unit(): Vector2;
|
|
8
|
+
get theta(): number;
|
|
9
|
+
setLength: (length: number) => void;
|
|
10
|
+
add: (vector2: Vector2) => Vector2;
|
|
11
|
+
subtract: (vector2: Vector2) => Vector2;
|
|
12
|
+
equal: (a: Vector2) => boolean;
|
|
13
|
+
close: (vec: Vector2) => boolean;
|
|
14
|
+
copy: () => Vector2;
|
|
15
|
+
asArray: () => [number, number];
|
|
16
|
+
rotate: (theta: number) => Vector2;
|
|
17
|
+
dot: (vec: Vector2) => number;
|
|
18
|
+
angleTo: (vec: Vector2) => number;
|
|
19
|
+
cross: (vec: Vector2) => number;
|
|
20
|
+
constructor(x: number, y: number);
|
|
21
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vector2 = void 0;
|
|
4
|
+
class Vector2 {
|
|
5
|
+
constructor(x, y) {
|
|
6
|
+
this.setLength = (length) => {
|
|
7
|
+
const unit = this.unit;
|
|
8
|
+
this.x = length * unit.x;
|
|
9
|
+
this.y = length * unit.y;
|
|
10
|
+
};
|
|
11
|
+
this.add = (vector2) => {
|
|
12
|
+
return new Vector2(this.x + vector2.x, this.y + vector2.y);
|
|
13
|
+
};
|
|
14
|
+
this.subtract = (vector2) => {
|
|
15
|
+
return new Vector2(this.x - vector2.x, this.y - vector2.y);
|
|
16
|
+
};
|
|
17
|
+
this.equal = (a) => {
|
|
18
|
+
if (a.x === this.x && a.y === this.y)
|
|
19
|
+
return true;
|
|
20
|
+
else
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
this.close = (vec) => {
|
|
24
|
+
const diff = this.subtract(vec);
|
|
25
|
+
const diffMag = diff.magnitued;
|
|
26
|
+
if (diffMag < 0.01)
|
|
27
|
+
return true;
|
|
28
|
+
else
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
this.copy = () => {
|
|
32
|
+
return new Vector2(this.x, this.y);
|
|
33
|
+
};
|
|
34
|
+
this.asArray = () => {
|
|
35
|
+
return [this.x, this.y];
|
|
36
|
+
};
|
|
37
|
+
this.rotate = (theta) => {
|
|
38
|
+
const thetaRadians = theta * Math.PI / 180;
|
|
39
|
+
const x = this.x * Math.cos(thetaRadians) - this.y * Math.sin(thetaRadians);
|
|
40
|
+
const y = this.x * Math.sin(thetaRadians) + this.y * Math.cos(thetaRadians);
|
|
41
|
+
return new Vector2(x, y);
|
|
42
|
+
};
|
|
43
|
+
this.dot = (vec) => {
|
|
44
|
+
return this.x * vec.x + this.y * vec.y;
|
|
45
|
+
};
|
|
46
|
+
this.angleTo = (vec) => {
|
|
47
|
+
const dot = this.dot(vec);
|
|
48
|
+
const magnitues = vec.magnitued * this.magnitued;
|
|
49
|
+
const angRadians = Math.acos(dot / magnitues);
|
|
50
|
+
return angRadians * 180 / Math.PI;
|
|
51
|
+
};
|
|
52
|
+
this.cross = (vec) => {
|
|
53
|
+
return (this.x * vec.y) - (this.y * vec.x);
|
|
54
|
+
};
|
|
55
|
+
this.x = x;
|
|
56
|
+
this.y = y;
|
|
57
|
+
}
|
|
58
|
+
static Zero() {
|
|
59
|
+
return new Vector2(0, 0);
|
|
60
|
+
}
|
|
61
|
+
static One() {
|
|
62
|
+
return new Vector2(1, 1);
|
|
63
|
+
}
|
|
64
|
+
get magnitued() {
|
|
65
|
+
const xSqr = this.x * this.x;
|
|
66
|
+
const ySqr = this.y * this.y;
|
|
67
|
+
const magnitude = Math.sqrt(xSqr + ySqr);
|
|
68
|
+
return magnitude;
|
|
69
|
+
}
|
|
70
|
+
get unit() {
|
|
71
|
+
const mag = this.magnitued;
|
|
72
|
+
if (mag === 0) {
|
|
73
|
+
return Vector2.Zero();
|
|
74
|
+
}
|
|
75
|
+
const unitX = this.x / mag;
|
|
76
|
+
const unitY = this.y / mag;
|
|
77
|
+
return new Vector2(unitX, unitY);
|
|
78
|
+
}
|
|
79
|
+
get theta() {
|
|
80
|
+
return (Math.atan2(this.y, this.x) * 180) / Math.PI;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Vector2 = Vector2;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class Vector3 {
|
|
2
|
+
static Zero(): Vector3;
|
|
3
|
+
static One(): Vector3;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
z: number;
|
|
7
|
+
get magnitued(): number;
|
|
8
|
+
get unit(): Vector3;
|
|
9
|
+
setLength: (length: number) => void;
|
|
10
|
+
add: (a: Vector3) => Vector3;
|
|
11
|
+
subtract: (vector2: Vector3) => Vector3;
|
|
12
|
+
copy: () => Vector3;
|
|
13
|
+
equals: (vec: Vector3) => boolean;
|
|
14
|
+
close: (vec: Vector3) => boolean;
|
|
15
|
+
cross: (vec: Vector3) => Vector3;
|
|
16
|
+
dot: (vec: Vector3) => number;
|
|
17
|
+
asArray: () => [number, number, number];
|
|
18
|
+
constructor(x: number, y: number, z: number);
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vector3 = void 0;
|
|
4
|
+
class Vector3 {
|
|
5
|
+
constructor(x, y, z) {
|
|
6
|
+
this.setLength = (length) => {
|
|
7
|
+
const unit = this.unit;
|
|
8
|
+
this.x = length * unit.x;
|
|
9
|
+
this.y = length * unit.y;
|
|
10
|
+
this.z = length * unit.z;
|
|
11
|
+
};
|
|
12
|
+
this.add = (a) => {
|
|
13
|
+
return new Vector3(this.x + a.x, this.y + a.y, this.z + a.z);
|
|
14
|
+
};
|
|
15
|
+
this.subtract = (vector2) => {
|
|
16
|
+
return new Vector3(this.x - vector2.x, this.y - vector2.y, this.z - vector2.z);
|
|
17
|
+
};
|
|
18
|
+
this.copy = () => {
|
|
19
|
+
return new Vector3(this.x, this.y, this.z);
|
|
20
|
+
};
|
|
21
|
+
this.equals = (vec) => {
|
|
22
|
+
if (vec.x === this.x && vec.y === this.y && vec.z === this.z)
|
|
23
|
+
return true;
|
|
24
|
+
else
|
|
25
|
+
return false;
|
|
26
|
+
};
|
|
27
|
+
this.close = (vec) => {
|
|
28
|
+
const diff = this.subtract(vec);
|
|
29
|
+
const diffMag = diff.magnitued;
|
|
30
|
+
if (diffMag < 0.01)
|
|
31
|
+
return true;
|
|
32
|
+
else
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
this.cross = (vec) => {
|
|
36
|
+
const x = this.y * vec.z - this.z * vec.y;
|
|
37
|
+
const y = this.z * vec.x - this.x * vec.z;
|
|
38
|
+
const z = this.x * vec.y - this.y * vec.x;
|
|
39
|
+
return new Vector3(x, y, z);
|
|
40
|
+
};
|
|
41
|
+
this.dot = (vec) => {
|
|
42
|
+
return this.x * vec.x + this.y * vec.y + this.z * vec.z;
|
|
43
|
+
};
|
|
44
|
+
this.asArray = () => {
|
|
45
|
+
return [this.x, this.y, this.z];
|
|
46
|
+
};
|
|
47
|
+
this.x = x;
|
|
48
|
+
this.y = y;
|
|
49
|
+
this.z = z;
|
|
50
|
+
}
|
|
51
|
+
static Zero() {
|
|
52
|
+
return new Vector3(0, 0, 0);
|
|
53
|
+
}
|
|
54
|
+
static One() {
|
|
55
|
+
return new Vector3(1, 1, 1);
|
|
56
|
+
}
|
|
57
|
+
get magnitued() {
|
|
58
|
+
const xSqr = this.x * this.x;
|
|
59
|
+
const ySqr = this.y * this.y;
|
|
60
|
+
const zSqr = this.z * this.z;
|
|
61
|
+
const magnitude = Math.sqrt(xSqr + ySqr + zSqr);
|
|
62
|
+
return magnitude;
|
|
63
|
+
}
|
|
64
|
+
get unit() {
|
|
65
|
+
const mag = this.magnitued;
|
|
66
|
+
if (mag === 0) {
|
|
67
|
+
return Vector3.Zero();
|
|
68
|
+
}
|
|
69
|
+
const unitX = this.x / mag;
|
|
70
|
+
const unitY = this.y / mag;
|
|
71
|
+
const unitZ = this.z / mag;
|
|
72
|
+
return new Vector3(unitX, unitY, unitZ);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.Vector3 = Vector3;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from "./Babylon";
|
|
2
|
+
export * from "./BaseApp";
|
|
3
|
+
export * from "./Color";
|
|
4
|
+
export * from "./DevicePreview";
|
|
5
|
+
export * from "./KeyboardInput";
|
|
6
|
+
export * from "./LineSegment2D";
|
|
7
|
+
export * from "./MemoizedBoolean";
|
|
8
|
+
export * from "./MemoizedNumber";
|
|
9
|
+
export * from "./MemoizedString";
|
|
10
|
+
export * from "./MemoizedVector2";
|
|
11
|
+
export * from "./MemoizedVector3";
|
|
12
|
+
export * from "./ObserverList";
|
|
13
|
+
export * from "./OrbitCamera";
|
|
14
|
+
export * from "./ParametricLine";
|
|
15
|
+
export * from "./ParametricPlane";
|
|
16
|
+
export * from "./StateMachine";
|
|
17
|
+
export * from "./UndoRedo";
|
|
18
|
+
export * from "./Vector2";
|
|
19
|
+
export * from "./Vector3";
|
|
20
|
+
export * from "./MouseInput";
|
|
21
|
+
export * from "./TouchInput";
|
|
@@ -0,0 +1,33 @@
|
|
|
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("./Babylon"), exports);
|
|
14
|
+
__exportStar(require("./BaseApp"), exports);
|
|
15
|
+
__exportStar(require("./Color"), exports);
|
|
16
|
+
__exportStar(require("./DevicePreview"), exports);
|
|
17
|
+
__exportStar(require("./KeyboardInput"), exports);
|
|
18
|
+
__exportStar(require("./LineSegment2D"), exports);
|
|
19
|
+
__exportStar(require("./MemoizedBoolean"), exports);
|
|
20
|
+
__exportStar(require("./MemoizedNumber"), exports);
|
|
21
|
+
__exportStar(require("./MemoizedString"), exports);
|
|
22
|
+
__exportStar(require("./MemoizedVector2"), exports);
|
|
23
|
+
__exportStar(require("./MemoizedVector3"), exports);
|
|
24
|
+
__exportStar(require("./ObserverList"), exports);
|
|
25
|
+
__exportStar(require("./OrbitCamera"), exports);
|
|
26
|
+
__exportStar(require("./ParametricLine"), exports);
|
|
27
|
+
__exportStar(require("./ParametricPlane"), exports);
|
|
28
|
+
__exportStar(require("./StateMachine"), exports);
|
|
29
|
+
__exportStar(require("./UndoRedo"), exports);
|
|
30
|
+
__exportStar(require("./Vector2"), exports);
|
|
31
|
+
__exportStar(require("./Vector3"), exports);
|
|
32
|
+
__exportStar(require("./MouseInput"), exports);
|
|
33
|
+
__exportStar(require("./TouchInput"), 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;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeAppHandler = exports.appPayloadVersions = void 0;
|
|
4
4
|
const app_host_boundary_1 = require("@vived/app-host-boundary");
|
|
5
|
-
const verbose = false;
|
|
6
5
|
exports.appPayloadVersions = {
|
|
7
6
|
disposeApp: 1,
|
|
8
7
|
setDevicePreview: 1,
|
|
@@ -12,10 +11,13 @@ exports.appPayloadVersions = {
|
|
|
12
11
|
stopApp: 1,
|
|
13
12
|
setState: 2,
|
|
14
13
|
};
|
|
15
|
-
function makeAppHandler(functions) {
|
|
14
|
+
function makeAppHandler(functions, verbose = false) {
|
|
16
15
|
const handler = (request) => {
|
|
16
|
+
if (verbose) {
|
|
17
|
+
console.log(request);
|
|
18
|
+
}
|
|
17
19
|
switch (request.type) {
|
|
18
|
-
case
|
|
20
|
+
case 'SHOW_BABYLON_INSPECTOR':
|
|
19
21
|
if (request.version === exports.appPayloadVersions.showBabylonInspector) {
|
|
20
22
|
const payload = request.payload;
|
|
21
23
|
functions.showBabylonInspector(payload.showBabylonInspector);
|
|
@@ -24,7 +26,7 @@ function makeAppHandler(functions) {
|
|
|
24
26
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
25
27
|
}
|
|
26
28
|
break;
|
|
27
|
-
case
|
|
29
|
+
case 'SET_IS_AUTHORING':
|
|
28
30
|
if (request.version === exports.appPayloadVersions.setIsAuthoring) {
|
|
29
31
|
const payload = request.payload;
|
|
30
32
|
functions.setIsAuthoring(payload.isAuthoring);
|
|
@@ -33,7 +35,7 @@ function makeAppHandler(functions) {
|
|
|
33
35
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
34
36
|
}
|
|
35
37
|
break;
|
|
36
|
-
case
|
|
38
|
+
case 'DISPOSE_APP':
|
|
37
39
|
if (request.version === exports.appPayloadVersions.disposeApp) {
|
|
38
40
|
functions.disposeApp();
|
|
39
41
|
}
|
|
@@ -41,7 +43,7 @@ function makeAppHandler(functions) {
|
|
|
41
43
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
42
44
|
}
|
|
43
45
|
break;
|
|
44
|
-
case
|
|
46
|
+
case 'STOP_APP':
|
|
45
47
|
if (request.version === exports.appPayloadVersions.stopApp) {
|
|
46
48
|
functions.stopApp();
|
|
47
49
|
}
|
|
@@ -49,7 +51,7 @@ function makeAppHandler(functions) {
|
|
|
49
51
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
50
52
|
}
|
|
51
53
|
break;
|
|
52
|
-
case
|
|
54
|
+
case 'SET_DEVICE_PREVIEW':
|
|
53
55
|
if (request.version === exports.appPayloadVersions.setDevicePreview) {
|
|
54
56
|
const payload = request.payload;
|
|
55
57
|
functions.setDevicePreview(payload.x, payload.y);
|
|
@@ -58,7 +60,7 @@ function makeAppHandler(functions) {
|
|
|
58
60
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
59
61
|
}
|
|
60
62
|
break;
|
|
61
|
-
case
|
|
63
|
+
case 'START_APP':
|
|
62
64
|
if (request.version === exports.appPayloadVersions.startApp) {
|
|
63
65
|
const payload = request.payload;
|
|
64
66
|
functions.startApp(payload.container);
|
|
@@ -67,7 +69,7 @@ function makeAppHandler(functions) {
|
|
|
67
69
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
68
70
|
}
|
|
69
71
|
break;
|
|
70
|
-
case
|
|
72
|
+
case 'SET_APP_STATE':
|
|
71
73
|
if (request.version === exports.appPayloadVersions.setState) {
|
|
72
74
|
const payload = request.payload;
|
|
73
75
|
functions.setState(payload.finalState, payload.duration);
|
|
@@ -76,7 +78,7 @@ function makeAppHandler(functions) {
|
|
|
76
78
|
throw new app_host_boundary_1.UnsupportedRequestVerion(request.type, request.version);
|
|
77
79
|
}
|
|
78
80
|
break;
|
|
79
|
-
case
|
|
81
|
+
case 'GET_APP_PAYLOAD_VERSION':
|
|
80
82
|
if (request.version === 1) {
|
|
81
83
|
const payload = request.payload;
|
|
82
84
|
payload.callback(exports.appPayloadVersions);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DevicePreview } from "../Entities";
|
|
2
|
+
export interface DevicePreviewVM {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
useDevicePreview: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class DevicePreviewPM {
|
|
8
|
+
devicePreview: DevicePreview;
|
|
9
|
+
updateView: (vm: DevicePreviewVM) => void;
|
|
10
|
+
doUpdateView: () => void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
constructor(devicePreview: DevicePreview, updateView: (vm: DevicePreviewVM) => void);
|
|
13
|
+
}
|