@vived/app 2.20.1 → 2.21.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 +49 -0
- package/lib/Core/BaseApp/Boundary.js +2 -0
- package/lib/Core/BaseApp/Entity.d.ts +11 -0
- package/lib/Core/BaseApp/Entity.js +2 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.js +10 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/BaseApp/Errors/index.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/index.js +15 -0
- package/lib/Core/BaseApp/UseCase.d.ts +43 -0
- package/lib/Core/BaseApp/UseCase.js +250 -0
- package/lib/Core/BaseAppState/Boundary.d.ts +14 -0
- package/lib/Core/BaseAppState/Boundary.js +2 -0
- package/lib/Core/BaseAppState/Entity.d.ts +5 -0
- package/lib/Core/BaseAppState/Entity.js +2 -0
- package/lib/Core/BaseAppState/UseCase.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase.js +54 -0
- package/lib/Core/BaseAppState/UseCase_Imp.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase_Imp.js +54 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.d.ts +16 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.js +56 -0
- package/lib/Core/DevicePreview/boundary.d.ts +14 -0
- package/lib/Core/DevicePreview/boundary.js +2 -0
- package/lib/Core/DevicePreview/entity.d.ts +5 -0
- package/lib/Core/DevicePreview/entity.js +2 -0
- package/lib/Core/DispatchToHost/Entity.d.ts +4 -0
- package/lib/Core/DispatchToHost/Entity.js +2 -0
- package/lib/Core/DispatchToHost/UseCase.d.ts +12 -0
- package/lib/Core/DispatchToHost/UseCase.js +70 -0
- package/lib/Core/DispatchToHost/boundary.d.ts +9 -0
- package/lib/Core/DispatchToHost/boundary.js +2 -0
- package/lib/Core/Serilization/Boundary.d.ts +20 -0
- package/lib/Core/Serilization/Boundary.js +2 -0
- package/lib/Core/Serilization/Entity.d.ts +3 -0
- package/lib/Core/Serilization/Entity.js +2 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/Serilization/Errors.d.ts +6 -0
- package/lib/Core/Serilization/Errors.js +19 -0
- package/lib/Core/Serilization/UseCase.d.ts +10 -0
- package/lib/Core/Serilization/UseCase.js +52 -0
- package/lib/Core/Serilization/UseCase_Imp.d.ts +10 -0
- package/lib/Core/Serilization/UseCase_Imp.js +51 -0
- package/lib/Core/index.d.ts +3 -0
- package/lib/Core/index.js +19 -0
- package/lib/Entities/Color.d.ts +20 -0
- package/lib/Entities/Color.js +59 -0
- package/lib/Entities/LineSegment2D.d.ts +11 -0
- package/lib/Entities/LineSegment2D.js +70 -0
- package/lib/Entities/MouseSceneInput.d.ts +15 -0
- package/lib/Entities/MouseSceneInput.js +109 -0
- package/lib/Entities/OrbitCamera.d.ts +76 -0
- package/lib/Entities/OrbitCamera.js +243 -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/SceneRoot.d.ts +69 -0
- package/lib/Entities/SceneRoot.js +77 -0
- package/lib/Entities/TransformNode.d.ts +78 -0
- package/lib/Entities/TransformNode.js +217 -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/WorkPlane.d.ts +49 -0
- package/lib/Entities/WorkPlane.js +122 -0
- package/lib/Entities/index.d.ts +3 -0
- package/lib/Entities/index.js +3 -0
- package/lib/Interface/Controllers/appHandler.d.ts +12 -0
- package/lib/Interface/Controllers/appHandler.js +94 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.d.ts +3 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.js +31 -0
- package/lib/Interface/Controllers/dispatchStateChange.d.ts +2 -0
- package/lib/Interface/Controllers/dispatchStateChange.js +10 -0
- package/lib/Interface/Controllers/index.d.ts +9 -0
- package/lib/Interface/Controllers/index.js +21 -0
- package/lib/Interface/Controllers/makeAppHandler.d.ts +12 -0
- package/lib/Interface/Controllers/makeAppHandler.js +96 -0
- package/lib/Interface/Controllers/setDevicePreview.d.ts +2 -0
- package/lib/Interface/Controllers/setDevicePreview.js +14 -0
- package/lib/Interface/Controllers/setIsAuthoring.d.ts +2 -0
- package/lib/Interface/Controllers/setIsAuthoring.js +14 -0
- package/lib/Interface/Controllers/setState.d.ts +2 -0
- package/lib/Interface/Controllers/setState.js +21 -0
- package/lib/Interface/Controllers/showBabylonInspector.d.ts +2 -0
- package/lib/Interface/Controllers/showBabylonInspector.js +9 -0
- package/lib/Interface/Controllers/startApp.d.ts +1 -0
- package/lib/Interface/Controllers/startApp.js +9 -0
- package/lib/Interface/Controllers/stopApp.d.ts +2 -0
- package/lib/Interface/Controllers/stopApp.js +10 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.d.ts +13 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.js +25 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.js +23 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.js +23 -0
- package/lib/Interface/PresentationManagers/index.d.ts +3 -0
- package/lib/Interface/PresentationManagers/index.js +15 -0
- package/lib/Interface/appHandler.d.ts +12 -0
- package/lib/Interface/appHandler.js +94 -0
- package/lib/Interface/index.d.ts +2 -0
- package/lib/Interface/index.js +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.d.ts +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.js +31 -0
- package/lib/PresentationManagers/TransformNodePM.d.ts +14 -0
- package/lib/PresentationManagers/TransformNodePM.js +23 -0
- package/lib/PresentationManagers/index.d.ts +1 -0
- package/lib/PresentationManagers/index.js +1 -0
- package/lib/UseCases/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.d.ts +9 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.d.ts +10 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.d.ts +22 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.js +81 -0
- package/lib/UseCases/OrbitCamera/index.d.ts +4 -0
- package/lib/UseCases/OrbitCamera/index.js +16 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.d.ts +18 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.js +48 -0
- package/lib/UseCases/SceneRoot/index.d.ts +1 -0
- package/lib/UseCases/SceneRoot/index.js +13 -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 +1 -0
- package/lib/UseCases/index.js +1 -0
- package/lib/ValueObjects/Angle.d.ts +18 -0
- package/lib/ValueObjects/Angle.js +26 -2
- package/lib/ValueObjects/Color.d.ts +46 -0
- package/lib/ValueObjects/Color.js +46 -0
- package/lib/ValueObjects/Matrix.d.ts +120 -0
- package/lib/ValueObjects/Matrix.js +423 -0
- package/lib/ValueObjects/Quaternion.d.ts +94 -0
- package/lib/ValueObjects/Quaternion.js +243 -0
- package/lib/ValueObjects/Vector2.d.ts +82 -0
- package/lib/ValueObjects/Vector2.js +82 -0
- package/lib/ValueObjects/Vector3.d.ts +107 -0
- package/lib/ValueObjects/Vector3.js +116 -0
- package/lib/ValueObjects/index.d.ts +2 -0
- package/lib/ValueObjects/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeSceneRoot = void 0;
|
|
4
|
+
const ValueObjects_1 = require("../ValueObjects");
|
|
5
|
+
const ObserverList_1 = require("./ObserverList");
|
|
6
|
+
const TransformNode_1 = require("./TransformNode");
|
|
7
|
+
function makeSceneRoot() {
|
|
8
|
+
return new SceneRootImp();
|
|
9
|
+
}
|
|
10
|
+
exports.makeSceneRoot = makeSceneRoot;
|
|
11
|
+
class SceneRootImp {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.observers = new ObserverList_1.ObserverList();
|
|
14
|
+
this._defaultPosition = ValueObjects_1.Vector3.Zero();
|
|
15
|
+
this._defaultRoation = ValueObjects_1.Quaternion.Identity();
|
|
16
|
+
this._defaultScale = ValueObjects_1.Vector3.One();
|
|
17
|
+
this._minScale = 0.01;
|
|
18
|
+
this._maxScale = 10;
|
|
19
|
+
this._id = "scene_root";
|
|
20
|
+
this.applyDefaultData = (data) => {
|
|
21
|
+
this._defaultPosition = ValueObjects_1.Vector3.FromArray(data.position);
|
|
22
|
+
this._defaultRoation = ValueObjects_1.Quaternion.FromArray(data.rotation);
|
|
23
|
+
this._defaultScale = new ValueObjects_1.Vector3(data.scale, data.scale, data.scale);
|
|
24
|
+
this._maxScale = data.maxScale;
|
|
25
|
+
this._minScale = data.minScale;
|
|
26
|
+
this._id = data.id;
|
|
27
|
+
};
|
|
28
|
+
this.centerOnPoint = (point, durationMS, easeFn, onCompleted) => {
|
|
29
|
+
const finalPosition = ValueObjects_1.Vector3.Subtract(this.transform.worldPosition, point);
|
|
30
|
+
this.transform.lerp(durationMS, easeFn, finalPosition, undefined, undefined, onCompleted);
|
|
31
|
+
};
|
|
32
|
+
this.bumpScaleAboutPoint = (amount, worldPoint) => {
|
|
33
|
+
const localPickOffset = this.transform.worldPointToLocal(worldPoint);
|
|
34
|
+
const currentScale = this.transform.worldScale.x;
|
|
35
|
+
let newScale = currentScale + amount;
|
|
36
|
+
if (newScale < this.minScale) {
|
|
37
|
+
newScale = this.minScale;
|
|
38
|
+
}
|
|
39
|
+
else if (newScale > this.maxScale) {
|
|
40
|
+
newScale = this.maxScale;
|
|
41
|
+
}
|
|
42
|
+
this.transform.worldScale = new ValueObjects_1.Vector3(newScale, newScale, newScale);
|
|
43
|
+
const worldPickOffset = this.transform.localPointToWorld(localPickOffset);
|
|
44
|
+
const bump = ValueObjects_1.Vector3.Subtract(worldPoint, worldPickOffset);
|
|
45
|
+
this.transform.worldPosition = ValueObjects_1.Vector3.Add(bump, this.transform.worldPosition);
|
|
46
|
+
};
|
|
47
|
+
this.lerpToDefault = (durationMS, easeFn, onCompleted) => {
|
|
48
|
+
this.transform.lerp(durationMS, easeFn, this.defaultPosition, this.defaultRoation, this.defaultScale, onCompleted);
|
|
49
|
+
};
|
|
50
|
+
this.addObserver = (observer) => {
|
|
51
|
+
this.observers.add(observer);
|
|
52
|
+
};
|
|
53
|
+
this.removeObserver = (observer) => {
|
|
54
|
+
this.observers.remove(observer);
|
|
55
|
+
};
|
|
56
|
+
this.transform = TransformNode_1.makeTransformNode();
|
|
57
|
+
this.transform.addObserver(this.observers.notify);
|
|
58
|
+
}
|
|
59
|
+
get defaultPosition() {
|
|
60
|
+
return this._defaultPosition;
|
|
61
|
+
}
|
|
62
|
+
get defaultRoation() {
|
|
63
|
+
return this._defaultRoation;
|
|
64
|
+
}
|
|
65
|
+
get defaultScale() {
|
|
66
|
+
return this._defaultScale;
|
|
67
|
+
}
|
|
68
|
+
get minScale() {
|
|
69
|
+
return this._minScale;
|
|
70
|
+
}
|
|
71
|
+
get maxScale() {
|
|
72
|
+
return this._maxScale;
|
|
73
|
+
}
|
|
74
|
+
get id() {
|
|
75
|
+
return this._id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Matrix, Quaternion, Vector3 } from "../ValueObjects";
|
|
2
|
+
export declare type OnTransformNodeChange = () => void;
|
|
3
|
+
export declare type EaseFn = (p: number) => number;
|
|
4
|
+
export interface TransformNode {
|
|
5
|
+
/**
|
|
6
|
+
* Local position of the transform
|
|
7
|
+
*/
|
|
8
|
+
localPosition: Vector3;
|
|
9
|
+
/**
|
|
10
|
+
* The world position of the transform
|
|
11
|
+
*/
|
|
12
|
+
worldPosition: Vector3;
|
|
13
|
+
/**
|
|
14
|
+
* Local roation of the transform
|
|
15
|
+
*/
|
|
16
|
+
localRotation: Quaternion;
|
|
17
|
+
/**
|
|
18
|
+
* World roation of the transform
|
|
19
|
+
*/
|
|
20
|
+
worldRotation: Quaternion;
|
|
21
|
+
/**
|
|
22
|
+
* Local scale of the transform
|
|
23
|
+
*/
|
|
24
|
+
localScale: Vector3;
|
|
25
|
+
/**
|
|
26
|
+
* World scale of the transform
|
|
27
|
+
*/
|
|
28
|
+
worldScale: Vector3;
|
|
29
|
+
/**
|
|
30
|
+
* Local transformation matrix
|
|
31
|
+
*/
|
|
32
|
+
localMatrix: Matrix;
|
|
33
|
+
/**
|
|
34
|
+
* The global transformation matrix
|
|
35
|
+
*/
|
|
36
|
+
worldMatrix: Matrix;
|
|
37
|
+
/**
|
|
38
|
+
* The transform's parent. Optional
|
|
39
|
+
*/
|
|
40
|
+
parent?: TransformNode;
|
|
41
|
+
/**
|
|
42
|
+
* Transforms a point from local to world space coordinates
|
|
43
|
+
* @param point point to transform in local coordinates
|
|
44
|
+
*/
|
|
45
|
+
localPointToWorld: (point: Vector3) => Vector3;
|
|
46
|
+
/**
|
|
47
|
+
* Transforms a point from world to local space coordinates
|
|
48
|
+
* @param point point to transform in world coordinates
|
|
49
|
+
*/
|
|
50
|
+
worldPointToLocal: (point: Vector3) => Vector3;
|
|
51
|
+
/**
|
|
52
|
+
* Transforms a local direction vector to world coordinates.
|
|
53
|
+
* @param direction direction to transform in local coordinates
|
|
54
|
+
*/
|
|
55
|
+
localDirectionToWorld: (direction: Vector3) => Vector3;
|
|
56
|
+
/**
|
|
57
|
+
* Transforms a world direction vector to local coordinates
|
|
58
|
+
* @param direction direction to transform in world coordinates
|
|
59
|
+
*/
|
|
60
|
+
worldDirectionToLocal: (direction: Vector3) => Vector3;
|
|
61
|
+
/**
|
|
62
|
+
* Lerps this transform node
|
|
63
|
+
* @param duration Lerp duration in MS
|
|
64
|
+
* @param ease Lerp ease function
|
|
65
|
+
* @param desiredPosition: Desired position. Optional.
|
|
66
|
+
* @param desiredRotation: Desired rotation. Optional.
|
|
67
|
+
* @param desiredScale: Desired scale. Optional.
|
|
68
|
+
* @param onCompletedCallback: Optional function to call when the lerp has completed
|
|
69
|
+
*/
|
|
70
|
+
lerp: (duration: number, ease: EaseFn, desiredPosition?: Vector3, desiredRotation?: Quaternion, desiredScale?: Vector3, onCompletedCallback?: () => void) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Cancels any currently running lerp
|
|
73
|
+
*/
|
|
74
|
+
cancelLerp: () => void;
|
|
75
|
+
addObserver: (observer: OnTransformNodeChange) => void;
|
|
76
|
+
removeObserver: (observer: OnTransformNodeChange) => void;
|
|
77
|
+
}
|
|
78
|
+
export declare function makeTransformNode(): TransformNode;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTransformNode = void 0;
|
|
4
|
+
const ValueObjects_1 = require("../ValueObjects");
|
|
5
|
+
const ObserverList_1 = require("./ObserverList");
|
|
6
|
+
function makeTransformNode() {
|
|
7
|
+
return new TransformNodeImp();
|
|
8
|
+
}
|
|
9
|
+
exports.makeTransformNode = makeTransformNode;
|
|
10
|
+
class TransformNodeImp {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.observers = new ObserverList_1.ObserverList();
|
|
13
|
+
this._transformationMatrix = ValueObjects_1.Matrix.Identity();
|
|
14
|
+
this.localPointToWorld = (point) => {
|
|
15
|
+
return ValueObjects_1.Vector3.Transform(point, this.worldMatrix);
|
|
16
|
+
};
|
|
17
|
+
this.worldPointToLocal = (point) => {
|
|
18
|
+
const worldInverse = ValueObjects_1.Matrix.Invert(this.worldMatrix);
|
|
19
|
+
return ValueObjects_1.Vector3.Transform(point, worldInverse);
|
|
20
|
+
};
|
|
21
|
+
this.localDirectionToWorld = (point) => {
|
|
22
|
+
const rotationMatrix = ValueObjects_1.Quaternion.ToRotationMatrix(this.worldRotation);
|
|
23
|
+
return ValueObjects_1.Vector3.Transform(point, rotationMatrix).unit;
|
|
24
|
+
};
|
|
25
|
+
this.worldDirectionToLocal = (point) => {
|
|
26
|
+
const worldInverse = ValueObjects_1.Matrix.Invert(this.worldMatrix);
|
|
27
|
+
const rotationMatrix = ValueObjects_1.Quaternion.ToRotationMatrix(worldInverse.rotation);
|
|
28
|
+
return ValueObjects_1.Vector3.Transform(point, rotationMatrix).unit;
|
|
29
|
+
};
|
|
30
|
+
this.chrono = 0;
|
|
31
|
+
this.lerpDuration = 1;
|
|
32
|
+
this.lerpEase = (p) => p;
|
|
33
|
+
this.tickInterval = 10;
|
|
34
|
+
this.lerp = (duration, ease, desiredPosition, desiredRotation, desiredScale, onCompletedCallback) => {
|
|
35
|
+
this.cancelLerp();
|
|
36
|
+
this.chrono = 0;
|
|
37
|
+
this.lerpDuration = duration;
|
|
38
|
+
this.lerpEase = ease;
|
|
39
|
+
if (duration <= 0) {
|
|
40
|
+
this.localMatrix = ValueObjects_1.Matrix.Compose(desiredScale !== null && desiredScale !== void 0 ? desiredScale : this.localScale, desiredRotation !== null && desiredRotation !== void 0 ? desiredRotation : this.localRotation, desiredPosition !== null && desiredPosition !== void 0 ? desiredPosition : this.localPosition);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (desiredPosition) {
|
|
44
|
+
this.lerpPos = [this.localPosition, desiredPosition];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.lerpPos = undefined;
|
|
48
|
+
}
|
|
49
|
+
if (desiredRotation) {
|
|
50
|
+
this.lerpQuat = [this.localRotation, desiredRotation];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.lerpQuat = undefined;
|
|
54
|
+
}
|
|
55
|
+
if (desiredScale) {
|
|
56
|
+
this.lerpScale = [this.localScale, desiredScale];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.lerpScale = undefined;
|
|
60
|
+
}
|
|
61
|
+
this.onLerpCompletedCallback = onCompletedCallback;
|
|
62
|
+
this.interval = setInterval(() => {
|
|
63
|
+
this.tickLerp();
|
|
64
|
+
}, this.tickInterval);
|
|
65
|
+
};
|
|
66
|
+
this.tickLerp = () => {
|
|
67
|
+
this.chrono = this.chrono + this.tickInterval;
|
|
68
|
+
let nomralizedTime = this.chrono / this.lerpDuration;
|
|
69
|
+
if (nomralizedTime > 1) {
|
|
70
|
+
nomralizedTime = 1;
|
|
71
|
+
}
|
|
72
|
+
const percent = this.lerpEase(nomralizedTime);
|
|
73
|
+
let pos = this.localPosition;
|
|
74
|
+
if (this.lerpPos) {
|
|
75
|
+
pos = ValueObjects_1.Vector3.Lerp(this.lerpPos[0], this.lerpPos[1], percent);
|
|
76
|
+
}
|
|
77
|
+
let rotation = this.localRotation;
|
|
78
|
+
if (this.lerpQuat) {
|
|
79
|
+
rotation = ValueObjects_1.Quaternion.Slerp(this.lerpQuat[0], this.lerpQuat[1], percent);
|
|
80
|
+
}
|
|
81
|
+
let scale = this.localScale;
|
|
82
|
+
if (this.lerpScale) {
|
|
83
|
+
scale = ValueObjects_1.Vector3.Lerp(this.lerpScale[0], this.lerpScale[1], percent);
|
|
84
|
+
}
|
|
85
|
+
this._transformationMatrix = ValueObjects_1.Matrix.Compose(scale, rotation, pos);
|
|
86
|
+
this.observers.notify();
|
|
87
|
+
if (nomralizedTime >= 1 && this.interval) {
|
|
88
|
+
if (this.onLerpCompletedCallback) {
|
|
89
|
+
this.onLerpCompletedCallback();
|
|
90
|
+
}
|
|
91
|
+
clearInterval(this.interval);
|
|
92
|
+
this.interval = undefined;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
this.cancelLerp = () => {
|
|
96
|
+
if (this.interval) {
|
|
97
|
+
clearInterval(this.interval);
|
|
98
|
+
this.interval = undefined;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
this.addObserver = (observer) => {
|
|
102
|
+
this.observers.add(observer);
|
|
103
|
+
};
|
|
104
|
+
this.removeObserver = (observer) => {
|
|
105
|
+
this.observers.remove(observer);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
get localMatrix() {
|
|
109
|
+
return this._transformationMatrix;
|
|
110
|
+
}
|
|
111
|
+
set localMatrix(val) {
|
|
112
|
+
if (ValueObjects_1.Matrix.Close(this._transformationMatrix, val))
|
|
113
|
+
return;
|
|
114
|
+
this.cancelLerp();
|
|
115
|
+
this._transformationMatrix = val;
|
|
116
|
+
this.observers.notify();
|
|
117
|
+
}
|
|
118
|
+
get worldMatrix() {
|
|
119
|
+
if (!this._parent) {
|
|
120
|
+
return this._transformationMatrix;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return ValueObjects_1.Matrix.Multiply(this._parent.worldMatrix, this._transformationMatrix);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
get localPosition() {
|
|
127
|
+
return this._transformationMatrix.translation;
|
|
128
|
+
}
|
|
129
|
+
set localPosition(val) {
|
|
130
|
+
const currentPos = this._transformationMatrix.translation;
|
|
131
|
+
if (ValueObjects_1.Vector3.Close(val, currentPos, 0.00001))
|
|
132
|
+
return;
|
|
133
|
+
this.cancelLerp();
|
|
134
|
+
this._transformationMatrix = ValueObjects_1.Matrix.SetMatrixTranslation(this._transformationMatrix, val);
|
|
135
|
+
this.observers.notify();
|
|
136
|
+
}
|
|
137
|
+
get worldPosition() {
|
|
138
|
+
return this.worldMatrix.translation;
|
|
139
|
+
}
|
|
140
|
+
set worldPosition(val) {
|
|
141
|
+
if (!this._parent) {
|
|
142
|
+
this.localPosition = val;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const local = this._parent.worldPointToLocal(val);
|
|
146
|
+
this.localPosition = local;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
get localRotation() {
|
|
150
|
+
return this._transformationMatrix.rotation;
|
|
151
|
+
}
|
|
152
|
+
set localRotation(val) {
|
|
153
|
+
const currentRot = this._transformationMatrix.rotation;
|
|
154
|
+
if (ValueObjects_1.Quaternion.Close(val, currentRot))
|
|
155
|
+
return;
|
|
156
|
+
this.cancelLerp();
|
|
157
|
+
this._transformationMatrix = ValueObjects_1.Matrix.SetMatrixRotation(this._transformationMatrix, val);
|
|
158
|
+
this.observers.notify();
|
|
159
|
+
}
|
|
160
|
+
get worldRotation() {
|
|
161
|
+
return this.worldMatrix.rotation;
|
|
162
|
+
}
|
|
163
|
+
set worldRotation(val) {
|
|
164
|
+
if (!this._parent) {
|
|
165
|
+
this.localRotation = val;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const parentRotation = this._parent.worldRotation;
|
|
169
|
+
const parentRotationInverse = ValueObjects_1.Quaternion.Inverse(parentRotation);
|
|
170
|
+
this.localRotation = ValueObjects_1.Quaternion.Multiply(parentRotationInverse, val);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
get localScale() {
|
|
174
|
+
return this._transformationMatrix.scale;
|
|
175
|
+
}
|
|
176
|
+
set localScale(val) {
|
|
177
|
+
const currentScale = this._transformationMatrix.scale;
|
|
178
|
+
if (ValueObjects_1.Vector3.Close(val, currentScale, 0.00001))
|
|
179
|
+
return;
|
|
180
|
+
this.cancelLerp();
|
|
181
|
+
this._transformationMatrix = ValueObjects_1.Matrix.SetMatrixScale(this._transformationMatrix, val);
|
|
182
|
+
this.observers.notify();
|
|
183
|
+
}
|
|
184
|
+
get worldScale() {
|
|
185
|
+
return this.worldMatrix.scale;
|
|
186
|
+
}
|
|
187
|
+
set worldScale(val) {
|
|
188
|
+
if (!this._parent) {
|
|
189
|
+
this.localScale = val;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const parentScale = this._parent.worldScale;
|
|
193
|
+
const x = val.x / parentScale.x;
|
|
194
|
+
const y = val.y / parentScale.y;
|
|
195
|
+
const z = val.z / parentScale.z;
|
|
196
|
+
this.localScale = new ValueObjects_1.Vector3(x, y, z);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
get parent() {
|
|
200
|
+
return this._parent;
|
|
201
|
+
}
|
|
202
|
+
set parent(val) {
|
|
203
|
+
if (this._parent === val)
|
|
204
|
+
return;
|
|
205
|
+
const wMatrix = this.worldMatrix;
|
|
206
|
+
this._parent = val;
|
|
207
|
+
if (this._parent) {
|
|
208
|
+
const parentMatrix = this._parent.worldMatrix;
|
|
209
|
+
const parentMatrixInverse = ValueObjects_1.Matrix.Invert(parentMatrix);
|
|
210
|
+
this.localMatrix = ValueObjects_1.Matrix.Multiply(parentMatrixInverse, wMatrix);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.localMatrix = wMatrix;
|
|
214
|
+
}
|
|
215
|
+
this.observers.notify();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -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,49 @@
|
|
|
1
|
+
import { ParametricLine, Vector2 } from "../ValueObjects";
|
|
2
|
+
import { TransformNode } from "./TransformNode";
|
|
3
|
+
export declare type OnWorkPlaneChange = () => void;
|
|
4
|
+
export declare enum WorkPlaneUnits {
|
|
5
|
+
INCHES = 0,
|
|
6
|
+
METERS = 1,
|
|
7
|
+
FEET = 2
|
|
8
|
+
}
|
|
9
|
+
export declare enum WorkplaneShape {
|
|
10
|
+
RECTANGE = 0,
|
|
11
|
+
CIRCLE = 1,
|
|
12
|
+
UNKNOWN = 2
|
|
13
|
+
}
|
|
14
|
+
export interface WorkPlane {
|
|
15
|
+
transform: TransformNode;
|
|
16
|
+
id: string;
|
|
17
|
+
units: WorkPlaneUnits;
|
|
18
|
+
/**
|
|
19
|
+
* The conversion rate from world units (meters) to workspace units
|
|
20
|
+
*/
|
|
21
|
+
conversionFactor: number;
|
|
22
|
+
workplaneShape: WorkplaneShape;
|
|
23
|
+
showWorkPlane: boolean;
|
|
24
|
+
workPlaneRadius?: number;
|
|
25
|
+
workPlaneSize?: Vector2;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the radius of the work plane. Call this if your workplane is a circle and it will limits the picks accordingly
|
|
28
|
+
* Note this will not notify observers of a change so this should be set
|
|
29
|
+
* when the app starts.
|
|
30
|
+
* @param radius The radius of the work plane in work plane units
|
|
31
|
+
*/
|
|
32
|
+
setWorkplaneSize: (size: Vector2) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the radius of the work plane. Call this if your workplane is a circle and it will limits the picks accordingly
|
|
35
|
+
* Note this will not notify observers of a change so this should be set
|
|
36
|
+
* when the app starts.
|
|
37
|
+
* @param radius The radius of the work plane in work plane units
|
|
38
|
+
*/
|
|
39
|
+
setWorkplaneRadius: (radius: number) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Tries to intersect a world ray with the work plane. If the work plane size or radius has been set
|
|
42
|
+
* it will limit the intersection appropriately, otherwise it will use an infinate plane.
|
|
43
|
+
* @param ray A ray in world coordinates
|
|
44
|
+
* @param unconstrained Optional. If set to true it will not limit the pick to the workplane size or radius. Instead it will pick on an infinate plane in the X-Z plane of the work plane. Defaults to false.
|
|
45
|
+
* @returns Where that ray intersects the work plane in work plane units. If the ray does not intersect, it returns undefined
|
|
46
|
+
*/
|
|
47
|
+
pickOnWorkplane: (ray: ParametricLine, unconstrained?: boolean) => Vector2 | undefined;
|
|
48
|
+
}
|
|
49
|
+
export declare function makeWorkPlane(): WorkPlane;
|