@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,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Color = void 0;
|
|
4
|
+
class Color {
|
|
5
|
+
constructor(r, g, b, a = 255) {
|
|
6
|
+
this.equal = (otherColor) => {
|
|
7
|
+
if (otherColor.r === this.r &&
|
|
8
|
+
otherColor.g === this.g &&
|
|
9
|
+
otherColor.b === this.b &&
|
|
10
|
+
otherColor.a === this.a) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
this.copy = () => {
|
|
18
|
+
return new Color(this.r, this.g, this.b, this.a);
|
|
19
|
+
};
|
|
20
|
+
this.r = r;
|
|
21
|
+
this.g = g;
|
|
22
|
+
this.b = b;
|
|
23
|
+
this.a = a;
|
|
24
|
+
}
|
|
25
|
+
static White() {
|
|
26
|
+
return new Color(255, 255, 255, 255);
|
|
27
|
+
}
|
|
28
|
+
static Black() {
|
|
29
|
+
return new Color(0, 0, 0, 255);
|
|
30
|
+
}
|
|
31
|
+
static Red() {
|
|
32
|
+
return new Color(255, 0, 0, 255);
|
|
33
|
+
}
|
|
34
|
+
static Green() {
|
|
35
|
+
return new Color(0, 255, 0, 255);
|
|
36
|
+
}
|
|
37
|
+
static Blue() {
|
|
38
|
+
return new Color(0, 0, 255, 255);
|
|
39
|
+
}
|
|
40
|
+
static Yellow() {
|
|
41
|
+
return new Color(255, 0, 255, 255);
|
|
42
|
+
}
|
|
43
|
+
static Gray() {
|
|
44
|
+
return new Color(192, 192, 192, 255);
|
|
45
|
+
}
|
|
46
|
+
get rPercent() {
|
|
47
|
+
return this.r / 255;
|
|
48
|
+
}
|
|
49
|
+
get gPercent() {
|
|
50
|
+
return this.g / 255;
|
|
51
|
+
}
|
|
52
|
+
get bPercent() {
|
|
53
|
+
return this.b / 255;
|
|
54
|
+
}
|
|
55
|
+
get aPercent() {
|
|
56
|
+
return this.a / 255;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Color = Color;
|
|
@@ -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,15 @@
|
|
|
1
|
+
export interface MouseController {
|
|
2
|
+
onClick?: (e: MouseEvent) => void;
|
|
3
|
+
onDown?: (e: MouseEvent) => void;
|
|
4
|
+
onUp?: (e: MouseEvent) => void;
|
|
5
|
+
onMove?: (e: MouseEvent) => void;
|
|
6
|
+
onWheel?: (e: WheelEvent) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface MouseInput {
|
|
9
|
+
eventElement: HTMLElement | undefined;
|
|
10
|
+
setEventElement: (eventElement: HTMLElement) => void;
|
|
11
|
+
clearInputElement: () => void;
|
|
12
|
+
registerController: (controller: MouseController) => void;
|
|
13
|
+
removeController: (controller: MouseController) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function makeMouseInput(): MouseInput;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMouseInput = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeMouseInput() {
|
|
6
|
+
return new MouseInputImp();
|
|
7
|
+
}
|
|
8
|
+
exports.makeMouseInput = makeMouseInput;
|
|
9
|
+
class MouseInputImp {
|
|
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, false);
|
|
18
|
+
eventElement.addEventListener("mouseup", this.onMouseUp, false);
|
|
19
|
+
eventElement.addEventListener("mousemove", this.onMouseMove, false);
|
|
20
|
+
eventElement.addEventListener("mouseout", this.onMouseOut, false);
|
|
21
|
+
eventElement.addEventListener("wheel", this.onWheel, false);
|
|
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
|
+
e.preventDefault();
|
|
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
|
+
e.preventDefault();
|
|
54
|
+
this.controllers.forEach((c) => {
|
|
55
|
+
if (c.onUp) {
|
|
56
|
+
c.onUp(e);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (!this.pressEvent)
|
|
60
|
+
return;
|
|
61
|
+
const deltaX = this.pressEvent.screenX - e.screenX;
|
|
62
|
+
const deltaY = this.pressEvent.screenY - e.screenY;
|
|
63
|
+
const delta = new _1.Vector2(deltaX, deltaY);
|
|
64
|
+
if (delta.magnitued < this.maxClickMovement) {
|
|
65
|
+
this.controllers.forEach((c) => {
|
|
66
|
+
if (c.onClick) {
|
|
67
|
+
c.onClick(e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
this.pressEvent = undefined;
|
|
72
|
+
};
|
|
73
|
+
this.onMouseMove = (e) => {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
this.controllers.forEach((c) => {
|
|
76
|
+
if (c.onMove) {
|
|
77
|
+
c.onMove(e);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!this.pressEvent)
|
|
81
|
+
return;
|
|
82
|
+
const deltaX = this.pressEvent.screenX - e.screenX;
|
|
83
|
+
const deltaY = this.pressEvent.screenY - e.screenY;
|
|
84
|
+
const delta = new _1.Vector2(deltaX, deltaY);
|
|
85
|
+
if (delta.magnitued > this.maxClickMovement) {
|
|
86
|
+
this.pressEvent = undefined;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
this.onMouseOut = (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
if (!this.pressEvent)
|
|
92
|
+
return;
|
|
93
|
+
this.controllers.forEach((c) => {
|
|
94
|
+
if (c.onUp) {
|
|
95
|
+
c.onUp(e);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.pressEvent = undefined;
|
|
99
|
+
};
|
|
100
|
+
this.onWheel = (e) => {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
this.controllers.forEach((c) => {
|
|
103
|
+
if (c.onWheel) {
|
|
104
|
+
c.onWheel(e);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
get eventElement() {
|
|
110
|
+
return this._eventElement;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface MouseController {
|
|
2
|
+
onClick?: (e: MouseEvent) => void;
|
|
3
|
+
onDown?: (e: MouseEvent) => void;
|
|
4
|
+
onUp?: (e: MouseEvent) => void;
|
|
5
|
+
onMove?: (e: MouseEvent) => void;
|
|
6
|
+
onWheel?: (e: WheelEvent) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface MouseSceneInput {
|
|
9
|
+
eventElement: HTMLElement | undefined;
|
|
10
|
+
setEventElement: (eventElement: HTMLElement) => void;
|
|
11
|
+
clearInputElement: () => void;
|
|
12
|
+
registerController: (controller: MouseController) => void;
|
|
13
|
+
removeController: (controller: MouseController) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function makeMouseSceneInput(): MouseSceneInput;
|