@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
|
@@ -6,9 +6,14 @@ export interface BaseAppUC {
|
|
|
6
6
|
setShowBabylonInspector(showInspector: boolean): void;
|
|
7
7
|
addObserver(observer: BaseAppStateObserver): void;
|
|
8
8
|
removeObserver(observer: BaseAppStateObserver): void;
|
|
9
|
+
setVerbose(verbose: boolean): void;
|
|
9
10
|
getSerializedState(): SerializedStates;
|
|
10
|
-
setSerializedState(state: SerializedStates): void;
|
|
11
|
+
setSerializedState(state: SerializedStates, transitionTime: number): void;
|
|
12
|
+
setDefaultState(transitionTime: number): void;
|
|
11
13
|
registerSerializableSystem(serializedSystem: SerializableSystem): void;
|
|
14
|
+
getIsTransitioning(): boolean;
|
|
15
|
+
abortTransition(): void;
|
|
16
|
+
setTransitionEaseFn: (easeFn: (normalizedTime: number) => number) => void;
|
|
12
17
|
setHostHandler(handler: Handler): void;
|
|
13
18
|
hasHostHandler(): boolean;
|
|
14
19
|
dispatchOnStateChange(stateObject: object): void;
|
|
@@ -39,5 +44,6 @@ export interface SerializableSystem {
|
|
|
39
44
|
name: string;
|
|
40
45
|
seriliziationVersion: number;
|
|
41
46
|
getSerializedObject(): object;
|
|
42
|
-
|
|
47
|
+
intializeStateForTransition(serializedState: object | null, version: number): void;
|
|
48
|
+
applyTransition(percent: number): void;
|
|
43
49
|
}
|
|
@@ -5,29 +5,39 @@ export declare class BaseAppUCImp implements BaseAppUC {
|
|
|
5
5
|
private observers;
|
|
6
6
|
private systems;
|
|
7
7
|
private serilizationVersion;
|
|
8
|
+
private currentInterval?;
|
|
9
|
+
private easeFunction;
|
|
8
10
|
constructor();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
setVerbose(verbose: boolean): void;
|
|
12
|
+
abortTransition: () => void;
|
|
13
|
+
setTransitionEaseFn: (easeFn: (normalizedTime: number) => number) => void;
|
|
14
|
+
getIsTransitioning: () => boolean;
|
|
15
|
+
setDevicePreview: (x: number, y: number) => void;
|
|
16
|
+
clearDevicePreview: () => void;
|
|
17
|
+
getUseDevicePreview: () => boolean;
|
|
18
|
+
getDevicePreviewSize: () => {
|
|
13
19
|
x: number;
|
|
14
20
|
y: number;
|
|
15
21
|
};
|
|
16
|
-
setHostHandler(handler: Handler)
|
|
17
|
-
hasHostHandler()
|
|
18
|
-
dispatchOnStateChange(stateObject: object)
|
|
19
|
-
dispatchOnStateComplete()
|
|
20
|
-
dispatchSubmitResults(results: object)
|
|
21
|
-
dispatchGetAppAssetsURL()
|
|
22
|
-
registerSerializableSystem(serializedSystem: SerializableSystem)
|
|
23
|
-
getSerializedState()
|
|
24
|
-
setSerializedState(state: SerializedStates
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
setHostHandler: (handler: Handler) => void;
|
|
23
|
+
hasHostHandler: () => boolean;
|
|
24
|
+
dispatchOnStateChange: (stateObject: object) => void;
|
|
25
|
+
dispatchOnStateComplete: () => void;
|
|
26
|
+
dispatchSubmitResults: (results: object) => void;
|
|
27
|
+
dispatchGetAppAssetsURL: () => string;
|
|
28
|
+
registerSerializableSystem: (serializedSystem: SerializableSystem) => void;
|
|
29
|
+
getSerializedState: () => SerializedStates;
|
|
30
|
+
setSerializedState: (state: SerializedStates, duration: number) => void;
|
|
31
|
+
setDefaultState: (duration: number) => void;
|
|
32
|
+
getShowBabylonInspector: () => boolean;
|
|
33
|
+
setShowBabylonInspector: (showInspector: boolean) => void;
|
|
34
|
+
getIsAuthoring: () => boolean;
|
|
35
|
+
setIsAuthoring: (isAuthoring: boolean) => void;
|
|
36
|
+
addObserver: (observer: BaseAppStateObserver) => void;
|
|
37
|
+
removeObserver: (observer: BaseAppStateObserver) => void;
|
|
38
|
+
private logToConsole;
|
|
39
|
+
private startTransition;
|
|
40
|
+
private applyTransitionToSystems;
|
|
31
41
|
private notify;
|
|
32
42
|
private dispatch;
|
|
33
43
|
}
|
|
@@ -8,157 +8,232 @@ class BaseAppUCImp {
|
|
|
8
8
|
this.observers = [];
|
|
9
9
|
this.systems = new Map();
|
|
10
10
|
this.serilizationVersion = 2;
|
|
11
|
+
this.easeFunction = (normalizedTime) => {
|
|
12
|
+
return normalizedTime; // default to a linear function
|
|
13
|
+
};
|
|
14
|
+
this.abortTransition = () => {
|
|
15
|
+
if (this.currentInterval) {
|
|
16
|
+
clearInterval(this.currentInterval);
|
|
17
|
+
}
|
|
18
|
+
this.appState.isTransitioning = false;
|
|
19
|
+
};
|
|
20
|
+
this.setTransitionEaseFn = (easeFn) => {
|
|
21
|
+
this.easeFunction = easeFn;
|
|
22
|
+
};
|
|
23
|
+
this.getIsTransitioning = () => {
|
|
24
|
+
return this.appState.isTransitioning;
|
|
25
|
+
};
|
|
26
|
+
this.setDevicePreview = (x, y) => {
|
|
27
|
+
if (this.appState.useDevicePreview &&
|
|
28
|
+
x === this.appState.x &&
|
|
29
|
+
y === this.appState.y) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.appState.useDevicePreview = true;
|
|
33
|
+
this.appState.x = x;
|
|
34
|
+
this.appState.y = y;
|
|
35
|
+
this.notify();
|
|
36
|
+
this.logToConsole(`Device Preview set to ${x}, ${y}`);
|
|
37
|
+
};
|
|
38
|
+
this.clearDevicePreview = () => {
|
|
39
|
+
if (!this.appState.useDevicePreview)
|
|
40
|
+
return;
|
|
41
|
+
this.appState.useDevicePreview = false;
|
|
42
|
+
this.appState.x = -1;
|
|
43
|
+
this.appState.y = -1;
|
|
44
|
+
this.notify();
|
|
45
|
+
this.logToConsole(`Device Preview cleared`);
|
|
46
|
+
};
|
|
47
|
+
this.getUseDevicePreview = () => {
|
|
48
|
+
return this.appState.useDevicePreview;
|
|
49
|
+
};
|
|
50
|
+
this.getDevicePreviewSize = () => {
|
|
51
|
+
const { x, y } = this.appState;
|
|
52
|
+
return { x, y };
|
|
53
|
+
};
|
|
54
|
+
this.setHostHandler = (handler) => {
|
|
55
|
+
this.appState.handler = handler;
|
|
56
|
+
this.logToConsole("Handler set");
|
|
57
|
+
};
|
|
58
|
+
this.hasHostHandler = () => {
|
|
59
|
+
if (this.appState.handler) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.dispatchOnStateChange = (stateObject) => {
|
|
67
|
+
const request = {
|
|
68
|
+
type: app_host_boundary_1.ON_STATE_CHANGE,
|
|
69
|
+
version: 1,
|
|
70
|
+
payload: {
|
|
71
|
+
stateObject,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
this.dispatch(request);
|
|
75
|
+
};
|
|
76
|
+
this.dispatchOnStateComplete = () => {
|
|
77
|
+
const request = {
|
|
78
|
+
type: app_host_boundary_1.ON_STATE_COMPLETED,
|
|
79
|
+
version: 1,
|
|
80
|
+
};
|
|
81
|
+
this.dispatch(request);
|
|
82
|
+
};
|
|
83
|
+
this.dispatchSubmitResults = (results) => {
|
|
84
|
+
const request = {
|
|
85
|
+
type: app_host_boundary_1.SUBMIT_RESULTS,
|
|
86
|
+
version: 1,
|
|
87
|
+
payload: {
|
|
88
|
+
results,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
this.dispatch(request);
|
|
92
|
+
};
|
|
93
|
+
this.dispatchGetAppAssetsURL = () => {
|
|
94
|
+
var _a;
|
|
95
|
+
const callback = (url) => {
|
|
96
|
+
this.appState.appAssetsURL = url;
|
|
97
|
+
};
|
|
98
|
+
const request = {
|
|
99
|
+
type: app_host_boundary_1.GET_APP_ASSET_URL,
|
|
100
|
+
version: 1,
|
|
101
|
+
payload: {
|
|
102
|
+
callback,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
this.dispatch(request);
|
|
106
|
+
return (_a = this.appState.appAssetsURL) !== null && _a !== void 0 ? _a : "";
|
|
107
|
+
};
|
|
108
|
+
this.registerSerializableSystem = (serializedSystem) => {
|
|
109
|
+
if (this.systems.has(serializedSystem.name)) {
|
|
110
|
+
throw new Errors_1.DuplicateSystemNameError(serializedSystem.name);
|
|
111
|
+
}
|
|
112
|
+
this.systems.set(serializedSystem.name, serializedSystem);
|
|
113
|
+
};
|
|
114
|
+
this.getSerializedState = () => {
|
|
115
|
+
const systems = Array.from(this.systems.values());
|
|
116
|
+
const serializedStates = systems.map((system) => {
|
|
117
|
+
const state = system.getSerializedObject();
|
|
118
|
+
return {
|
|
119
|
+
seriliziationVersion: system.seriliziationVersion,
|
|
120
|
+
name: system.name,
|
|
121
|
+
state,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
version: this.serilizationVersion,
|
|
126
|
+
systems: serializedStates,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
this.setSerializedState = (state, duration) => {
|
|
130
|
+
if (state.version === 2) {
|
|
131
|
+
state.systems.forEach((systemState) => {
|
|
132
|
+
const seriliazableSystem = this.systems.get(systemState.name);
|
|
133
|
+
if (seriliazableSystem) {
|
|
134
|
+
seriliazableSystem.intializeStateForTransition(systemState.state, systemState.seriliziationVersion);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.warn("Unable to find seriarializedSystem " + systemState.name);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// Here is where we will add support for future versions
|
|
142
|
+
else {
|
|
143
|
+
throw new Errors_1.UnsupportedVersionNumber(state.version);
|
|
144
|
+
}
|
|
145
|
+
this.startTransition(duration);
|
|
146
|
+
this.logToConsole(`State set to ${JSON.stringify(state)} with a ${duration} second duration`);
|
|
147
|
+
};
|
|
148
|
+
this.setDefaultState = (duration) => {
|
|
149
|
+
this.systems.forEach((system) => {
|
|
150
|
+
system.intializeStateForTransition(null, -1);
|
|
151
|
+
});
|
|
152
|
+
this.startTransition(duration);
|
|
153
|
+
this.logToConsole(`State has been set to transition to default over ${duration} seconds`);
|
|
154
|
+
};
|
|
155
|
+
this.getShowBabylonInspector = () => {
|
|
156
|
+
return this.appState.showBabyonInspector;
|
|
157
|
+
};
|
|
158
|
+
this.setShowBabylonInspector = (showInspector) => {
|
|
159
|
+
if (this.appState.showBabyonInspector === showInspector)
|
|
160
|
+
return;
|
|
161
|
+
this.appState.showBabyonInspector = showInspector;
|
|
162
|
+
this.notify();
|
|
163
|
+
this.logToConsole(`Show Babylon Inspector set to ${showInspector}`);
|
|
164
|
+
};
|
|
165
|
+
this.getIsAuthoring = () => {
|
|
166
|
+
return this.appState.isAuthoring;
|
|
167
|
+
};
|
|
168
|
+
this.setIsAuthoring = (isAuthoring) => {
|
|
169
|
+
if (isAuthoring === this.appState.isAuthoring)
|
|
170
|
+
return;
|
|
171
|
+
this.appState.isAuthoring = isAuthoring;
|
|
172
|
+
this.notify();
|
|
173
|
+
this.logToConsole(`Is Authoring set to ${isAuthoring}`);
|
|
174
|
+
};
|
|
175
|
+
this.addObserver = (observer) => {
|
|
176
|
+
this.observers.push(observer);
|
|
177
|
+
};
|
|
178
|
+
this.removeObserver = (observer) => {
|
|
179
|
+
const index = this.observers.indexOf(observer);
|
|
180
|
+
if (index >= 0) {
|
|
181
|
+
this.observers.splice(index, 1);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
11
184
|
this.appState = {
|
|
12
185
|
isAuthoring: false,
|
|
13
186
|
showBabyonInspector: false,
|
|
14
187
|
useDevicePreview: false,
|
|
15
188
|
x: -1,
|
|
16
189
|
y: -1,
|
|
190
|
+
isTransitioning: false,
|
|
191
|
+
verbose: false,
|
|
17
192
|
};
|
|
18
193
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
x === this.appState.x &&
|
|
22
|
-
y === this.appState.y) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
this.appState.useDevicePreview = true;
|
|
26
|
-
this.appState.x = x;
|
|
27
|
-
this.appState.y = y;
|
|
28
|
-
this.notify();
|
|
194
|
+
setVerbose(verbose) {
|
|
195
|
+
this.appState.verbose = verbose;
|
|
29
196
|
}
|
|
30
|
-
|
|
31
|
-
if (!this.appState.
|
|
197
|
+
logToConsole(message) {
|
|
198
|
+
if (!this.appState.verbose)
|
|
32
199
|
return;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { x, y } = this.appState;
|
|
43
|
-
return { x, y };
|
|
44
|
-
}
|
|
45
|
-
setHostHandler(handler) {
|
|
46
|
-
this.appState.handler = handler;
|
|
47
|
-
}
|
|
48
|
-
hasHostHandler() {
|
|
49
|
-
if (this.appState.handler) {
|
|
50
|
-
return true;
|
|
200
|
+
console.log("[Base App UC] " + message);
|
|
201
|
+
}
|
|
202
|
+
startTransition(duration) {
|
|
203
|
+
if (duration === 0) {
|
|
204
|
+
if (this.currentInterval) {
|
|
205
|
+
clearInterval(this.currentInterval);
|
|
206
|
+
this.appState.isTransitioning = false;
|
|
207
|
+
}
|
|
208
|
+
this.applyTransitionToSystems(1);
|
|
51
209
|
}
|
|
52
210
|
else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
dispatchOnStateComplete() {
|
|
67
|
-
const request = {
|
|
68
|
-
type: app_host_boundary_1.ON_STATE_COMPLETED,
|
|
69
|
-
version: 1,
|
|
70
|
-
};
|
|
71
|
-
this.dispatch(request);
|
|
72
|
-
}
|
|
73
|
-
dispatchSubmitResults(results) {
|
|
74
|
-
const request = {
|
|
75
|
-
type: app_host_boundary_1.SUBMIT_RESULTS,
|
|
76
|
-
version: 1,
|
|
77
|
-
payload: {
|
|
78
|
-
results,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
this.dispatch(request);
|
|
82
|
-
}
|
|
83
|
-
dispatchGetAppAssetsURL() {
|
|
84
|
-
var _a;
|
|
85
|
-
const callback = (url) => {
|
|
86
|
-
this.appState.appAssetsURL = url;
|
|
87
|
-
};
|
|
88
|
-
const request = {
|
|
89
|
-
type: app_host_boundary_1.GET_APP_ASSET_URL,
|
|
90
|
-
version: 1,
|
|
91
|
-
payload: {
|
|
92
|
-
callback,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
this.dispatch(request);
|
|
96
|
-
return (_a = this.appState.appAssetsURL) !== null && _a !== void 0 ? _a : "";
|
|
97
|
-
}
|
|
98
|
-
registerSerializableSystem(serializedSystem) {
|
|
99
|
-
if (this.systems.has(serializedSystem.name)) {
|
|
100
|
-
throw new Errors_1.DuplicateSystemNameError(serializedSystem.name);
|
|
101
|
-
}
|
|
102
|
-
this.systems.set(serializedSystem.name, serializedSystem);
|
|
103
|
-
}
|
|
104
|
-
getSerializedState() {
|
|
105
|
-
const systems = Array.from(this.systems.values());
|
|
106
|
-
const serializedStates = systems.map((system) => {
|
|
107
|
-
const state = system.getSerializedObject();
|
|
108
|
-
return {
|
|
109
|
-
seriliziationVersion: system.seriliziationVersion,
|
|
110
|
-
name: system.name,
|
|
111
|
-
state,
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
return {
|
|
115
|
-
version: this.serilizationVersion,
|
|
116
|
-
systems: serializedStates,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
setSerializedState(state) {
|
|
120
|
-
if (state.version === 2) {
|
|
121
|
-
state.systems.forEach((systemState) => {
|
|
122
|
-
const seriliazableSystem = this.systems.get(systemState.name);
|
|
123
|
-
if (seriliazableSystem) {
|
|
124
|
-
seriliazableSystem.applySerailizedObject(systemState.state, systemState.seriliziationVersion);
|
|
211
|
+
if (this.currentInterval) {
|
|
212
|
+
clearInterval(this.currentInterval);
|
|
213
|
+
}
|
|
214
|
+
this.appState.isTransitioning = true;
|
|
215
|
+
const durationInMS = duration * 1000;
|
|
216
|
+
let chrono = 0;
|
|
217
|
+
const transitionDelta = 10;
|
|
218
|
+
this.currentInterval = setInterval(() => {
|
|
219
|
+
chrono = chrono + transitionDelta;
|
|
220
|
+
let normalizedTime = chrono / durationInMS;
|
|
221
|
+
if (normalizedTime > 1) {
|
|
222
|
+
normalizedTime = 1;
|
|
125
223
|
}
|
|
126
|
-
|
|
127
|
-
|
|
224
|
+
const percent = this.easeFunction(normalizedTime);
|
|
225
|
+
this.applyTransitionToSystems(percent);
|
|
226
|
+
if (normalizedTime >= 1 && this.currentInterval) {
|
|
227
|
+
clearInterval(this.currentInterval);
|
|
228
|
+
this.appState.isTransitioning = false;
|
|
128
229
|
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
// Here is where we will add support for future versions
|
|
132
|
-
else {
|
|
133
|
-
throw new Errors_1.UnsupportedVersionNumber(state.version);
|
|
230
|
+
}, transitionDelta);
|
|
134
231
|
}
|
|
135
232
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (this.appState.showBabyonInspector === showInspector)
|
|
141
|
-
return;
|
|
142
|
-
this.appState.showBabyonInspector = showInspector;
|
|
143
|
-
this.notify();
|
|
144
|
-
}
|
|
145
|
-
getIsAuthoring() {
|
|
146
|
-
return this.appState.isAuthoring;
|
|
147
|
-
}
|
|
148
|
-
setIsAuthoring(isAuthoring) {
|
|
149
|
-
if (isAuthoring === this.appState.isAuthoring)
|
|
150
|
-
return;
|
|
151
|
-
this.appState.isAuthoring = isAuthoring;
|
|
152
|
-
this.notify();
|
|
153
|
-
}
|
|
154
|
-
addObserver(observer) {
|
|
155
|
-
this.observers.push(observer);
|
|
156
|
-
}
|
|
157
|
-
removeObserver(observer) {
|
|
158
|
-
const index = this.observers.indexOf(observer);
|
|
159
|
-
if (index >= 0) {
|
|
160
|
-
this.observers.splice(index, 1);
|
|
161
|
-
}
|
|
233
|
+
applyTransitionToSystems(percent) {
|
|
234
|
+
this.systems.forEach((system) => {
|
|
235
|
+
system.applyTransition(percent);
|
|
236
|
+
});
|
|
162
237
|
}
|
|
163
238
|
notify() {
|
|
164
239
|
this.observers.forEach((observer) => observer.onBaseAppChange());
|
|
@@ -169,6 +244,7 @@ class BaseAppUCImp {
|
|
|
169
244
|
}
|
|
170
245
|
const handler = this.appState.handler;
|
|
171
246
|
handler(request);
|
|
247
|
+
this.logToConsole(`Dispatched request: ${JSON.stringify(request)}`);
|
|
172
248
|
}
|
|
173
249
|
}
|
|
174
250
|
exports.BaseAppUCImp = BaseAppUCImp;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ParametricLine, Vector3 } from ".";
|
|
2
|
+
import { Vector2 } from "./Vector2";
|
|
3
|
+
export declare type OnBabylonChange = () => void;
|
|
4
|
+
export interface ScenePick {
|
|
5
|
+
mouseRay: ParametricLine;
|
|
6
|
+
hit: boolean;
|
|
7
|
+
worldPickPoint?: Vector3;
|
|
8
|
+
objectPickMeta?: object;
|
|
9
|
+
}
|
|
10
|
+
export declare type ScenePicker = (pixelPos: Vector2) => ScenePick;
|
|
11
|
+
export declare type SceneRayer = (pixelPos: Vector2) => ParametricLine;
|
|
12
|
+
export interface Babylon {
|
|
13
|
+
engine: unknown;
|
|
14
|
+
scene: unknown;
|
|
15
|
+
workingCanvas?: HTMLCanvasElement;
|
|
16
|
+
showInspector: boolean;
|
|
17
|
+
renderCanvas?: HTMLCanvasElement;
|
|
18
|
+
scenePick: (pixelPos: Vector2) => ScenePick;
|
|
19
|
+
sceneRay: (pixelPos: Vector2) => ParametricLine;
|
|
20
|
+
updateCanvasSize: () => void;
|
|
21
|
+
submitRenderCanvas: (canvas: HTMLCanvasElement) => void;
|
|
22
|
+
clearRenderCanvas: () => void;
|
|
23
|
+
registerResizeEnging: (resizeEngine: () => void) => void;
|
|
24
|
+
registerStartRendering: (startRendering: (canvas: HTMLCanvasElement) => void) => void;
|
|
25
|
+
registerStopRendering: (stopRendering: (canvas: HTMLCanvasElement) => void) => void;
|
|
26
|
+
registerScenePicker: (picker: ScenePicker) => void;
|
|
27
|
+
registerSceneRayer: (rayer: SceneRayer) => void;
|
|
28
|
+
addObserver: (observer: OnBabylonChange) => void;
|
|
29
|
+
removeObserver: (observer: OnBabylonChange) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare function makeBabylon(): Babylon;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBabylon = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const MemoizedBoolean_1 = require("./MemoizedBoolean");
|
|
6
|
+
const MemoizedVector2_1 = require("./MemoizedVector2");
|
|
7
|
+
const ObserverList_1 = require("./ObserverList");
|
|
8
|
+
const Vector2_1 = require("./Vector2");
|
|
9
|
+
function makeBabylon() {
|
|
10
|
+
return new BabylonImp();
|
|
11
|
+
}
|
|
12
|
+
exports.makeBabylon = makeBabylon;
|
|
13
|
+
class BabylonImp {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.scenePick = () => {
|
|
16
|
+
console.warn("orignal scene picker");
|
|
17
|
+
return {
|
|
18
|
+
mouseRay: _1.ParametricLine.Forward(),
|
|
19
|
+
hit: false,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
this.sceneRay = () => {
|
|
23
|
+
console.warn("orignal scene ray");
|
|
24
|
+
return _1.ParametricLine.Forward();
|
|
25
|
+
};
|
|
26
|
+
this.observers = new ObserverList_1.ObserverList();
|
|
27
|
+
this.updateCanvasSize = () => {
|
|
28
|
+
if (!this.workingCanvas)
|
|
29
|
+
return;
|
|
30
|
+
if (!this._renderCanvas)
|
|
31
|
+
return;
|
|
32
|
+
if (this.resizeEngine) {
|
|
33
|
+
this.resizeEngine();
|
|
34
|
+
}
|
|
35
|
+
this.workingCanvas.height = this._renderCanvas.height;
|
|
36
|
+
this.workingCanvas.width = this._renderCanvas.width;
|
|
37
|
+
};
|
|
38
|
+
this.submitRenderCanvas = (canvas) => {
|
|
39
|
+
if (canvas === this._renderCanvas)
|
|
40
|
+
return;
|
|
41
|
+
if (this._renderCanvas && this.stopRendering) {
|
|
42
|
+
this.stopRendering(this._renderCanvas);
|
|
43
|
+
}
|
|
44
|
+
this._renderCanvas = canvas;
|
|
45
|
+
this.updateCanvasSize();
|
|
46
|
+
if (this.startRendering) {
|
|
47
|
+
this.startRendering(canvas);
|
|
48
|
+
}
|
|
49
|
+
this.observers.notify();
|
|
50
|
+
};
|
|
51
|
+
this.clearRenderCanvas = () => {
|
|
52
|
+
if (!this._renderCanvas)
|
|
53
|
+
return;
|
|
54
|
+
if (this.stopRendering) {
|
|
55
|
+
this.stopRendering(this._renderCanvas);
|
|
56
|
+
}
|
|
57
|
+
this._renderCanvas = undefined;
|
|
58
|
+
this.observers.notify();
|
|
59
|
+
};
|
|
60
|
+
this.registerResizeEnging = (resizeEngine) => {
|
|
61
|
+
this.resizeEngine = resizeEngine;
|
|
62
|
+
};
|
|
63
|
+
this.registerStartRendering = (startRendering) => {
|
|
64
|
+
this.startRendering = startRendering;
|
|
65
|
+
};
|
|
66
|
+
this.registerStopRendering = (stopRendering) => {
|
|
67
|
+
this.stopRendering = stopRendering;
|
|
68
|
+
};
|
|
69
|
+
this.addObserver = (observer) => {
|
|
70
|
+
this.observers.add(observer);
|
|
71
|
+
};
|
|
72
|
+
this.removeObserver = (observer) => {
|
|
73
|
+
this.observers.remove(observer);
|
|
74
|
+
};
|
|
75
|
+
this.registerScenePicker = (picker) => {
|
|
76
|
+
this.scenePick = picker;
|
|
77
|
+
};
|
|
78
|
+
this.registerSceneRayer = (rayer) => {
|
|
79
|
+
this.sceneRay = rayer;
|
|
80
|
+
};
|
|
81
|
+
this.memoizedShowInspector = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
|
|
82
|
+
this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(Vector2_1.Vector2.One(), this.observers.notify);
|
|
83
|
+
}
|
|
84
|
+
get showInspector() {
|
|
85
|
+
return this.memoizedShowInspector.val;
|
|
86
|
+
}
|
|
87
|
+
set showInspector(val) {
|
|
88
|
+
this.memoizedShowInspector.val = val;
|
|
89
|
+
}
|
|
90
|
+
get renderCanvas() {
|
|
91
|
+
return this._renderCanvas;
|
|
92
|
+
}
|
|
93
|
+
get canvasSize() {
|
|
94
|
+
return this.memoizedCanvasSize.getVector();
|
|
95
|
+
}
|
|
96
|
+
set canvasSize(val) {
|
|
97
|
+
this.memoizedCanvasSize.setVector(val);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBaseApp = void 0;
|
|
4
|
+
const MemoizedBoolean_1 = require("./MemoizedBoolean");
|
|
5
|
+
const ObserverList_1 = require("./ObserverList");
|
|
6
|
+
function makeBaseApp() {
|
|
7
|
+
return new BaseAppImp();
|
|
8
|
+
}
|
|
9
|
+
exports.makeBaseApp = makeBaseApp;
|
|
10
|
+
class BaseAppImp {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.observers = new ObserverList_1.ObserverList();
|
|
13
|
+
this.memoizedIsAuthoring = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
|
|
14
|
+
this.addObserver = (observer) => {
|
|
15
|
+
this.observers.add(observer);
|
|
16
|
+
};
|
|
17
|
+
this.removeObserver = (observer) => {
|
|
18
|
+
this.observers.remove(observer);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
get isAuthoring() {
|
|
22
|
+
return this.memoizedIsAuthoring.val;
|
|
23
|
+
}
|
|
24
|
+
set isAuthoring(val) {
|
|
25
|
+
this.memoizedIsAuthoring.val = val;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class Color {
|
|
2
|
+
static White(): Color;
|
|
3
|
+
static Black(): Color;
|
|
4
|
+
static Red(): Color;
|
|
5
|
+
static Green(): Color;
|
|
6
|
+
static Blue(): Color;
|
|
7
|
+
static Yellow(): Color;
|
|
8
|
+
static Gray(): Color;
|
|
9
|
+
r: number;
|
|
10
|
+
g: number;
|
|
11
|
+
b: number;
|
|
12
|
+
a: number;
|
|
13
|
+
get rPercent(): number;
|
|
14
|
+
get gPercent(): number;
|
|
15
|
+
get bPercent(): number;
|
|
16
|
+
get aPercent(): number;
|
|
17
|
+
equal: (otherColor: Color) => boolean;
|
|
18
|
+
copy: () => Color;
|
|
19
|
+
constructor(r: number, g: number, b: number, a?: number);
|
|
20
|
+
}
|