hj-gis-sdk 1.0.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/README.md +824 -0
- package/README_UERPC.md +667 -0
- package/dist/sdk.esm.js +4143 -0
- package/dist/sdk.esm.js.map +1 -0
- package/dist/sdk.js +4148 -0
- package/dist/sdk.js.map +1 -0
- package/dist/sdk.umd.js +2 -0
- package/dist/sdk.umd.js.map +1 -0
- package/dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts +39 -0
- package/dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts +31 -0
- package/dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts +18 -0
- package/dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/animation/index.d.ts +5 -0
- package/dist/types/hj-gis-sdk/addons/animation/index.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/camera.d.ts +59 -0
- package/dist/types/hj-gis-sdk/addons/camera.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/clock.d.ts +40 -0
- package/dist/types/hj-gis-sdk/addons/clock.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/commander/context.d.ts +24 -0
- package/dist/types/hj-gis-sdk/addons/commander/context.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts +43 -0
- package/dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts +22 -0
- package/dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/loader/index.d.ts +6 -0
- package/dist/types/hj-gis-sdk/addons/loader/index.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/loader/loader.d.ts +4 -0
- package/dist/types/hj-gis-sdk/addons/loader/loader.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/node/base.d.ts +63 -0
- package/dist/types/hj-gis-sdk/addons/node/base.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/node/ue-node.d.ts +82 -0
- package/dist/types/hj-gis-sdk/addons/node/ue-node.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/proxy.d.ts +83 -0
- package/dist/types/hj-gis-sdk/addons/proxy.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/base.d.ts +7 -0
- package/dist/types/hj-gis-sdk/addons/tools/base.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/building.d.ts +36 -0
- package/dist/types/hj-gis-sdk/addons/tools/building.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/daytime.d.ts +7 -0
- package/dist/types/hj-gis-sdk/addons/tools/daytime.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/fence.d.ts +61 -0
- package/dist/types/hj-gis-sdk/addons/tools/fence.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/ghost.d.ts +14 -0
- package/dist/types/hj-gis-sdk/addons/tools/ghost.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts +65 -0
- package/dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/index.d.ts +26 -0
- package/dist/types/hj-gis-sdk/addons/tools/index.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/match-view.d.ts +7 -0
- package/dist/types/hj-gis-sdk/addons/tools/match-view.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/measurement.d.ts +13 -0
- package/dist/types/hj-gis-sdk/addons/tools/measurement.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts +26 -0
- package/dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/scatter.d.ts +57 -0
- package/dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/tools/weather.d.ts +31 -0
- package/dist/types/hj-gis-sdk/addons/tools/weather.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/transform.d.ts +91 -0
- package/dist/types/hj-gis-sdk/addons/transform.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/addons/world.d.ts +76 -0
- package/dist/types/hj-gis-sdk/addons/world.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/core/ue-rpc.d.ts +54 -0
- package/dist/types/hj-gis-sdk/core/ue-rpc.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/index.d.ts +27 -0
- package/dist/types/hj-gis-sdk/index.d.ts.map +1 -0
- package/dist/types/hj-gis-sdk/utils.d.ts +16 -0
- package/dist/types/hj-gis-sdk/utils.d.ts.map +1 -0
- package/dist/types/src/animation.d.ts +2 -0
- package/dist/types/src/animation.d.ts.map +1 -0
- package/dist/types/src/building.d.ts +2 -0
- package/dist/types/src/building.d.ts.map +1 -0
- package/dist/types/src/common.d.ts +5 -0
- package/dist/types/src/common.d.ts.map +1 -0
- package/dist/types/src/fence.d.ts +2 -0
- package/dist/types/src/fence.d.ts.map +1 -0
- package/dist/types/src/ghost.d.ts +2 -0
- package/dist/types/src/ghost.d.ts.map +1 -0
- package/dist/types/src/heatmap.d.ts +2 -0
- package/dist/types/src/heatmap.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/keyframe.d.ts +2 -0
- package/dist/types/src/keyframe.d.ts.map +1 -0
- package/dist/types/src/measurement.d.ts +2 -0
- package/dist/types/src/measurement.d.ts.map +1 -0
- package/dist/types/src/scatter.d.ts +2 -0
- package/dist/types/src/scatter.d.ts.map +1 -0
- package/dist/types/src/weather.d.ts +2 -0
- package/dist/types/src/weather.d.ts.map +1 -0
- package/package.json +55 -0
package/dist/sdk.esm.js
ADDED
|
@@ -0,0 +1,4143 @@
|
|
|
1
|
+
import { Logger } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.5';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UERPC wraps RPC-style interactions over Pixel Streaming's DataChannel.
|
|
5
|
+
* It mirrors the Web/script.js behavior: sends {Type:'RPC_CALL', Command, ReqId, ...payload}
|
|
6
|
+
* and expects UE to reply with {Type:'RPC_RESPONSE', ReqId, Status, Data|Message} via EmitJSEvent.
|
|
7
|
+
*/
|
|
8
|
+
class UERPC {
|
|
9
|
+
constructor(stream, responseEventName = 'handle_responses') {
|
|
10
|
+
this.stream = stream;
|
|
11
|
+
this.responseEventName = responseEventName;
|
|
12
|
+
this.pendingRequests = new Map();
|
|
13
|
+
this.timeoutMs = 30000;
|
|
14
|
+
try {
|
|
15
|
+
this.stream.addResponseEventListener(this.responseEventName, this.handleResponse.bind(this));
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
// If the stream is not ready yet, user can call bind later.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getStream() {
|
|
22
|
+
return this.stream;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Bind the response listener explicitly if constructor binding failed or the stream changed.
|
|
26
|
+
*/
|
|
27
|
+
bind(stream, responseEventName = this.responseEventName) {
|
|
28
|
+
this.stream = stream;
|
|
29
|
+
this.responseEventName = responseEventName;
|
|
30
|
+
this.stream.addResponseEventListener(this.responseEventName, this.handleResponse.bind(this));
|
|
31
|
+
}
|
|
32
|
+
emitCommand(playload) {
|
|
33
|
+
this.stream.emitCommand(playload);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generic RPC call. Resolves when UE replies with matching ReqId.
|
|
37
|
+
*/
|
|
38
|
+
call(command, payload = {}, timeoutMs) {
|
|
39
|
+
const reqId = this.generateUUID();
|
|
40
|
+
const message = {
|
|
41
|
+
Type: 'RPC_CALL',
|
|
42
|
+
Command: command,
|
|
43
|
+
ReqId: reqId,
|
|
44
|
+
...payload
|
|
45
|
+
};
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const timer = window.setTimeout(() => {
|
|
48
|
+
if (this.pendingRequests.has(reqId)) {
|
|
49
|
+
this.pendingRequests.delete(reqId);
|
|
50
|
+
reject(new Error(`UE RPC Timeout: ${command}`));
|
|
51
|
+
}
|
|
52
|
+
}, timeoutMs || this.timeoutMs);
|
|
53
|
+
this.pendingRequests.set(reqId, { resolve, reject, timer });
|
|
54
|
+
try {
|
|
55
|
+
this.stream.emitUIInteraction(message);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
window.clearTimeout(timer);
|
|
59
|
+
this.pendingRequests.delete(reqId);
|
|
60
|
+
reject(e);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handle UE responses. Accepts stringified or object payloads.
|
|
66
|
+
*/
|
|
67
|
+
handleResponse(raw) {
|
|
68
|
+
let json = raw;
|
|
69
|
+
try {
|
|
70
|
+
if (typeof raw === 'string') {
|
|
71
|
+
json = JSON.parse(raw);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!json || json.Type !== 'RPC_RESPONSE')
|
|
78
|
+
return;
|
|
79
|
+
const reqId = json.ReqId;
|
|
80
|
+
if (!reqId)
|
|
81
|
+
return;
|
|
82
|
+
const pending = this.pendingRequests.get(reqId);
|
|
83
|
+
if (!pending)
|
|
84
|
+
return;
|
|
85
|
+
window.clearTimeout(pending.timer);
|
|
86
|
+
this.pendingRequests.delete(reqId);
|
|
87
|
+
const status = json.Status;
|
|
88
|
+
if (status === 'success') {
|
|
89
|
+
pending.resolve(json.Data);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const msg = json.Message || 'Unknown UE Error';
|
|
93
|
+
pending.reject(new Error(msg));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
callModule(moduleName, actionName, params = {}, timeoutMs = 30000) {
|
|
97
|
+
const reqId = this.generateUUID();
|
|
98
|
+
const message = {
|
|
99
|
+
Type: 'RPC_CALL',
|
|
100
|
+
ReqId: reqId,
|
|
101
|
+
ModuleName: moduleName,
|
|
102
|
+
ActionName: actionName,
|
|
103
|
+
Params: params
|
|
104
|
+
};
|
|
105
|
+
Logger.Info(JSON.stringify(message));
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const timer = window.setTimeout(() => {
|
|
108
|
+
if (this.pendingRequests.has(reqId)) {
|
|
109
|
+
this.pendingRequests.delete(reqId);
|
|
110
|
+
reject(new Error(`UE Call Timeout: ${moduleName}/${actionName}`));
|
|
111
|
+
}
|
|
112
|
+
}, timeoutMs || this.timeoutMs);
|
|
113
|
+
this.pendingRequests.set(reqId, { resolve, reject, timer });
|
|
114
|
+
try {
|
|
115
|
+
this.stream.emitUIInteraction(message);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
window.clearTimeout(timer);
|
|
119
|
+
this.pendingRequests.delete(reqId);
|
|
120
|
+
reject(e);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// ---- Convenience helpers for Web-supported commands ----
|
|
125
|
+
// Level management
|
|
126
|
+
loadLevelByName(levelName) {
|
|
127
|
+
return this.call('LoadLevelByName', { LevelName: levelName });
|
|
128
|
+
}
|
|
129
|
+
unLoadMap(levelName) {
|
|
130
|
+
return this.call('UnLoadMap', { LevelName: levelName });
|
|
131
|
+
}
|
|
132
|
+
// Actor management
|
|
133
|
+
spawnStaticMeshActor(params) {
|
|
134
|
+
return this.call('SpawnStaticMeshActor', params);
|
|
135
|
+
}
|
|
136
|
+
// Blueprint management
|
|
137
|
+
spawnLocalBlueprintActor(params) {
|
|
138
|
+
return this.call('SpawnLocalBlueprintActor', params);
|
|
139
|
+
}
|
|
140
|
+
setActorTransformByHandle(handle, transform) {
|
|
141
|
+
return this.call('SetActorTransformByHandle', {
|
|
142
|
+
Handle: handle,
|
|
143
|
+
Transform: transform
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
destroyActorByHandle(handle) {
|
|
147
|
+
return this.call('DestroyActorByHandle', { Handle: handle });
|
|
148
|
+
}
|
|
149
|
+
// Picking
|
|
150
|
+
pickPointByScreen(x, y, maxDistance = 10000000, highlight = false) {
|
|
151
|
+
return this.call('PickPointByScreen', {
|
|
152
|
+
Screen: {
|
|
153
|
+
X: x,
|
|
154
|
+
Y: y
|
|
155
|
+
},
|
|
156
|
+
MaxDistance: maxDistance,
|
|
157
|
+
Highlight: highlight
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// Camera lens and transform
|
|
161
|
+
getCameraTransform() {
|
|
162
|
+
return this.call('GetCameraTransform', {});
|
|
163
|
+
}
|
|
164
|
+
setCameraTransform(transform) {
|
|
165
|
+
return this.call('SetCameraTransform', { Transform: transform });
|
|
166
|
+
}
|
|
167
|
+
setCameraResetTransform(transform) {
|
|
168
|
+
return this.call('SetCameraResetTransform', { Transform: transform });
|
|
169
|
+
}
|
|
170
|
+
resetCameraToSavedTransform() {
|
|
171
|
+
return this.call('ResetCameraToSavedTransform', {});
|
|
172
|
+
}
|
|
173
|
+
generateUUID() {
|
|
174
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
175
|
+
const r = (Math.random() * 16) | 0;
|
|
176
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
177
|
+
return v.toString(16);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// math.gl
|
|
183
|
+
const DEFAULT_CONFIG = {
|
|
184
|
+
EPSILON: 1e-12,
|
|
185
|
+
debug: false,
|
|
186
|
+
precision: 4,
|
|
187
|
+
printTypes: false,
|
|
188
|
+
printDegrees: false,
|
|
189
|
+
printRowMajor: true,
|
|
190
|
+
_cartographicRadians: false
|
|
191
|
+
};
|
|
192
|
+
// Configuration is truly global as of v3.6 to ensure single config even if multiple copies of math.gl
|
|
193
|
+
// Multiple copies of config can be quite tricky to debug...
|
|
194
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
195
|
+
const config = globalThis.mathgl.config;
|
|
196
|
+
/**
|
|
197
|
+
* Formats a value into a string
|
|
198
|
+
* @param value
|
|
199
|
+
* @param param1
|
|
200
|
+
* @returns
|
|
201
|
+
*/
|
|
202
|
+
function formatValue(value, { precision = config.precision } = {}) {
|
|
203
|
+
value = round(value);
|
|
204
|
+
// get rid of trailing zeros
|
|
205
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if value is an "array"
|
|
209
|
+
* Returns `true` if value is either an array or a typed array
|
|
210
|
+
* Note: returns `false` for `ArrayBuffer` and `DataView` instances
|
|
211
|
+
* @note isTypedArray and isNumericArray are often more useful in TypeScript
|
|
212
|
+
*/
|
|
213
|
+
function isArray(value) {
|
|
214
|
+
return Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView));
|
|
215
|
+
}
|
|
216
|
+
function clamp(value, min, max) {
|
|
217
|
+
return map(value, (value) => Math.max(min, Math.min(max, value)));
|
|
218
|
+
}
|
|
219
|
+
/* eslint-disable */
|
|
220
|
+
/**
|
|
221
|
+
* Compares any two math objects, using `equals` method if available.
|
|
222
|
+
* @param a
|
|
223
|
+
* @param b
|
|
224
|
+
* @param epsilon
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
function equals(a, b, epsilon) {
|
|
228
|
+
const oldEpsilon = config.EPSILON;
|
|
229
|
+
if (epsilon) {
|
|
230
|
+
config.EPSILON = epsilon;
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
if (a === b) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
if (isArray(a) && isArray(b)) {
|
|
237
|
+
if (a.length !== b.length) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < a.length; ++i) {
|
|
241
|
+
// eslint-disable-next-line max-depth
|
|
242
|
+
if (!equals(a[i], b[i])) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
if (a && a.equals) {
|
|
249
|
+
return a.equals(b);
|
|
250
|
+
}
|
|
251
|
+
if (b && b.equals) {
|
|
252
|
+
return b.equals(a);
|
|
253
|
+
}
|
|
254
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
255
|
+
return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
config.EPSILON = oldEpsilon;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// HELPERS
|
|
264
|
+
function round(value) {
|
|
265
|
+
return Math.round(value / config.EPSILON) * config.EPSILON;
|
|
266
|
+
}
|
|
267
|
+
// If the array has a clone function, calls it, otherwise returns a copy
|
|
268
|
+
function duplicateArray(array) {
|
|
269
|
+
// @ts-expect-error We check for math.gl class methods
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
271
|
+
return array.clone ? array.clone() : new Array(array.length);
|
|
272
|
+
}
|
|
273
|
+
// If the argument value is an array, applies the func element wise,
|
|
274
|
+
// otherwise applies func to the argument value
|
|
275
|
+
function map(value, func, result) {
|
|
276
|
+
if (isArray(value)) {
|
|
277
|
+
const array = value;
|
|
278
|
+
result = result || duplicateArray(array);
|
|
279
|
+
for (let i = 0; i < result.length && i < array.length; ++i) {
|
|
280
|
+
const val = typeof value === 'number' ? value : value[i];
|
|
281
|
+
result[i] = func(val, i, result);
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
return func(value);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// math.gl
|
|
289
|
+
/** Base class for vectors and matrices */
|
|
290
|
+
class MathArray extends Array {
|
|
291
|
+
// Common methods
|
|
292
|
+
/**
|
|
293
|
+
* Clone the current object
|
|
294
|
+
* @returns a new copy of this object
|
|
295
|
+
*/
|
|
296
|
+
clone() {
|
|
297
|
+
// @ts-expect-error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
|
298
|
+
return new this.constructor().copy(this); // eslint-disable-line
|
|
299
|
+
}
|
|
300
|
+
fromArray(array, offset = 0) {
|
|
301
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
302
|
+
this[i] = array[i + offset];
|
|
303
|
+
}
|
|
304
|
+
return this.check();
|
|
305
|
+
}
|
|
306
|
+
toArray(targetArray = [], offset = 0) {
|
|
307
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
308
|
+
targetArray[offset + i] = this[i];
|
|
309
|
+
}
|
|
310
|
+
return targetArray;
|
|
311
|
+
}
|
|
312
|
+
toObject(targetObject) {
|
|
313
|
+
return targetObject;
|
|
314
|
+
}
|
|
315
|
+
from(arrayOrObject) {
|
|
316
|
+
return Array.isArray(arrayOrObject)
|
|
317
|
+
? this.copy(arrayOrObject)
|
|
318
|
+
: // @ts-ignore
|
|
319
|
+
this.fromObject(arrayOrObject);
|
|
320
|
+
}
|
|
321
|
+
to(arrayOrObject) {
|
|
322
|
+
// @ts-ignore
|
|
323
|
+
if (arrayOrObject === this) {
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
// @ts-expect-error TS2339: Property 'toObject' does not exist on type 'MathArray'.
|
|
327
|
+
return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
|
|
328
|
+
}
|
|
329
|
+
toTarget(target) {
|
|
330
|
+
return target ? this.to(target) : this;
|
|
331
|
+
}
|
|
332
|
+
/** @deprecated */
|
|
333
|
+
toFloat32Array() {
|
|
334
|
+
return new Float32Array(this);
|
|
335
|
+
}
|
|
336
|
+
toString() {
|
|
337
|
+
return this.formatString(config);
|
|
338
|
+
}
|
|
339
|
+
/** Formats string according to options */
|
|
340
|
+
formatString(opts) {
|
|
341
|
+
let string = '';
|
|
342
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
343
|
+
string += (i > 0 ? ', ' : '') + formatValue(this[i], opts);
|
|
344
|
+
}
|
|
345
|
+
return `${opts.printTypes ? this.constructor.name : ''}[${string}]`;
|
|
346
|
+
}
|
|
347
|
+
equals(array) {
|
|
348
|
+
if (!array || this.length !== array.length) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
352
|
+
if (!equals(this[i], array[i])) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
exactEquals(array) {
|
|
359
|
+
if (!array || this.length !== array.length) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
363
|
+
if (this[i] !== array[i]) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
// Modifiers
|
|
370
|
+
/** Negates all values in this object */
|
|
371
|
+
negate() {
|
|
372
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
373
|
+
this[i] = -this[i];
|
|
374
|
+
}
|
|
375
|
+
return this.check();
|
|
376
|
+
}
|
|
377
|
+
lerp(a, b, t) {
|
|
378
|
+
if (t === undefined) {
|
|
379
|
+
return this.lerp(this, a, b);
|
|
380
|
+
}
|
|
381
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
382
|
+
const ai = a[i];
|
|
383
|
+
const endValue = typeof b === 'number' ? b : b[i];
|
|
384
|
+
this[i] = ai + t * (endValue - ai);
|
|
385
|
+
}
|
|
386
|
+
return this.check();
|
|
387
|
+
}
|
|
388
|
+
/** Minimal */
|
|
389
|
+
min(vector) {
|
|
390
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
391
|
+
this[i] = Math.min(vector[i], this[i]);
|
|
392
|
+
}
|
|
393
|
+
return this.check();
|
|
394
|
+
}
|
|
395
|
+
/** Maximal */
|
|
396
|
+
max(vector) {
|
|
397
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
398
|
+
this[i] = Math.max(vector[i], this[i]);
|
|
399
|
+
}
|
|
400
|
+
return this.check();
|
|
401
|
+
}
|
|
402
|
+
clamp(minVector, maxVector) {
|
|
403
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
404
|
+
this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
|
|
405
|
+
}
|
|
406
|
+
return this.check();
|
|
407
|
+
}
|
|
408
|
+
add(...vectors) {
|
|
409
|
+
for (const vector of vectors) {
|
|
410
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
411
|
+
this[i] += vector[i];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return this.check();
|
|
415
|
+
}
|
|
416
|
+
subtract(...vectors) {
|
|
417
|
+
for (const vector of vectors) {
|
|
418
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
419
|
+
this[i] -= vector[i];
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return this.check();
|
|
423
|
+
}
|
|
424
|
+
scale(scale) {
|
|
425
|
+
if (typeof scale === 'number') {
|
|
426
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
427
|
+
this[i] *= scale;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
for (let i = 0; i < this.ELEMENTS && i < scale.length; ++i) {
|
|
432
|
+
this[i] *= scale[i];
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return this.check();
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Multiplies all elements by `scale`
|
|
439
|
+
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
440
|
+
*/
|
|
441
|
+
multiplyByScalar(scalar) {
|
|
442
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
443
|
+
this[i] *= scalar;
|
|
444
|
+
}
|
|
445
|
+
return this.check();
|
|
446
|
+
}
|
|
447
|
+
// Debug checks
|
|
448
|
+
/** Throws an error if array length is incorrect or contains illegal values */
|
|
449
|
+
check() {
|
|
450
|
+
if (config.debug && !this.validate()) {
|
|
451
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
452
|
+
}
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
/** Returns false if the array length is incorrect or contains illegal values */
|
|
456
|
+
validate() {
|
|
457
|
+
let valid = this.length === this.ELEMENTS;
|
|
458
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
459
|
+
valid = valid && Number.isFinite(this[i]);
|
|
460
|
+
}
|
|
461
|
+
return valid;
|
|
462
|
+
}
|
|
463
|
+
// three.js compatibility
|
|
464
|
+
/** @deprecated */
|
|
465
|
+
sub(a) {
|
|
466
|
+
return this.subtract(a);
|
|
467
|
+
}
|
|
468
|
+
/** @deprecated */
|
|
469
|
+
setScalar(a) {
|
|
470
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
471
|
+
this[i] = a;
|
|
472
|
+
}
|
|
473
|
+
return this.check();
|
|
474
|
+
}
|
|
475
|
+
/** @deprecated */
|
|
476
|
+
addScalar(a) {
|
|
477
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
478
|
+
this[i] += a;
|
|
479
|
+
}
|
|
480
|
+
return this.check();
|
|
481
|
+
}
|
|
482
|
+
/** @deprecated */
|
|
483
|
+
subScalar(a) {
|
|
484
|
+
return this.addScalar(-a);
|
|
485
|
+
}
|
|
486
|
+
/** @deprecated */
|
|
487
|
+
multiplyScalar(scalar) {
|
|
488
|
+
// Multiplies all elements
|
|
489
|
+
// `Matrix4.scale` only scales its 3x3 "minor"
|
|
490
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
491
|
+
this[i] *= scalar;
|
|
492
|
+
}
|
|
493
|
+
return this.check();
|
|
494
|
+
}
|
|
495
|
+
/** @deprecated */
|
|
496
|
+
divideScalar(a) {
|
|
497
|
+
return this.multiplyByScalar(1 / a);
|
|
498
|
+
}
|
|
499
|
+
/** @deprecated */
|
|
500
|
+
clampScalar(min, max) {
|
|
501
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
502
|
+
this[i] = Math.min(Math.max(this[i], min), max);
|
|
503
|
+
}
|
|
504
|
+
return this.check();
|
|
505
|
+
}
|
|
506
|
+
/** @deprecated */
|
|
507
|
+
get elements() {
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// math.gl
|
|
513
|
+
function validateVector(v, length) {
|
|
514
|
+
if (v.length !== length) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
// Could be arguments "array" (v.every not availasble)
|
|
518
|
+
for (let i = 0; i < v.length; ++i) {
|
|
519
|
+
if (!Number.isFinite(v[i])) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
function checkNumber(value) {
|
|
526
|
+
if (!Number.isFinite(value)) {
|
|
527
|
+
throw new Error(`Invalid number ${JSON.stringify(value)}`);
|
|
528
|
+
}
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
function checkVector(v, length, callerName = '') {
|
|
532
|
+
if (config.debug && !validateVector(v, length)) {
|
|
533
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
534
|
+
}
|
|
535
|
+
return v;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// math.gl
|
|
539
|
+
// SPDX-License-Identifier: MIT
|
|
540
|
+
// Copyright (c) vis.gl contributors
|
|
541
|
+
function assert(condition, message) {
|
|
542
|
+
if (!condition) {
|
|
543
|
+
throw new Error(`math.gl assertion ${message}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// math.gl
|
|
548
|
+
/** Base class for vectors with at least 2 elements */
|
|
549
|
+
class Vector extends MathArray {
|
|
550
|
+
// ACCESSORS
|
|
551
|
+
get x() {
|
|
552
|
+
return this[0];
|
|
553
|
+
}
|
|
554
|
+
set x(value) {
|
|
555
|
+
this[0] = checkNumber(value);
|
|
556
|
+
}
|
|
557
|
+
get y() {
|
|
558
|
+
return this[1];
|
|
559
|
+
}
|
|
560
|
+
set y(value) {
|
|
561
|
+
this[1] = checkNumber(value);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
565
|
+
*
|
|
566
|
+
* @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
|
|
567
|
+
* Instead we provide `len` and `magnitude`
|
|
568
|
+
*/
|
|
569
|
+
len() {
|
|
570
|
+
return Math.sqrt(this.lengthSquared());
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
574
|
+
*/
|
|
575
|
+
magnitude() {
|
|
576
|
+
return this.len();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
580
|
+
*/
|
|
581
|
+
lengthSquared() {
|
|
582
|
+
let length = 0;
|
|
583
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
584
|
+
length += this[i] * this[i];
|
|
585
|
+
}
|
|
586
|
+
return length;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
590
|
+
*/
|
|
591
|
+
magnitudeSquared() {
|
|
592
|
+
return this.lengthSquared();
|
|
593
|
+
}
|
|
594
|
+
distance(mathArray) {
|
|
595
|
+
return Math.sqrt(this.distanceSquared(mathArray));
|
|
596
|
+
}
|
|
597
|
+
distanceSquared(mathArray) {
|
|
598
|
+
let length = 0;
|
|
599
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
600
|
+
const dist = this[i] - mathArray[i];
|
|
601
|
+
length += dist * dist;
|
|
602
|
+
}
|
|
603
|
+
return checkNumber(length);
|
|
604
|
+
}
|
|
605
|
+
dot(mathArray) {
|
|
606
|
+
let product = 0;
|
|
607
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
608
|
+
product += this[i] * mathArray[i];
|
|
609
|
+
}
|
|
610
|
+
return checkNumber(product);
|
|
611
|
+
}
|
|
612
|
+
// MODIFIERS
|
|
613
|
+
normalize() {
|
|
614
|
+
const length = this.magnitude();
|
|
615
|
+
if (length !== 0) {
|
|
616
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
617
|
+
this[i] /= length;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return this.check();
|
|
621
|
+
}
|
|
622
|
+
multiply(...vectors) {
|
|
623
|
+
for (const vector of vectors) {
|
|
624
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
625
|
+
this[i] *= vector[i];
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return this.check();
|
|
629
|
+
}
|
|
630
|
+
divide(...vectors) {
|
|
631
|
+
for (const vector of vectors) {
|
|
632
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
633
|
+
this[i] /= vector[i];
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return this.check();
|
|
637
|
+
}
|
|
638
|
+
// THREE.js compatibility
|
|
639
|
+
lengthSq() {
|
|
640
|
+
return this.lengthSquared();
|
|
641
|
+
}
|
|
642
|
+
distanceTo(vector) {
|
|
643
|
+
return this.distance(vector);
|
|
644
|
+
}
|
|
645
|
+
distanceToSquared(vector) {
|
|
646
|
+
return this.distanceSquared(vector);
|
|
647
|
+
}
|
|
648
|
+
getComponent(i) {
|
|
649
|
+
assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
|
|
650
|
+
return checkNumber(this[i]);
|
|
651
|
+
}
|
|
652
|
+
setComponent(i, value) {
|
|
653
|
+
assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
|
|
654
|
+
this[i] = value;
|
|
655
|
+
return this.check();
|
|
656
|
+
}
|
|
657
|
+
addVectors(a, b) {
|
|
658
|
+
return this.copy(a).add(b);
|
|
659
|
+
}
|
|
660
|
+
subVectors(a, b) {
|
|
661
|
+
return this.copy(a).subtract(b);
|
|
662
|
+
}
|
|
663
|
+
multiplyVectors(a, b) {
|
|
664
|
+
return this.copy(a).multiply(b);
|
|
665
|
+
}
|
|
666
|
+
addScaledVector(a, b) {
|
|
667
|
+
// @ts-expect-error error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
|
668
|
+
return this.add(new this.constructor(a).multiplyScalar(b));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// @eslint-disable
|
|
673
|
+
// @ts-nocheck
|
|
674
|
+
/**
|
|
675
|
+
* Common utilities
|
|
676
|
+
* @module glMatrix
|
|
677
|
+
*/
|
|
678
|
+
// Configuration Constants
|
|
679
|
+
const EPSILON = 0.000001;
|
|
680
|
+
let ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
681
|
+
|
|
682
|
+
// math.gl
|
|
683
|
+
// vec3 additions
|
|
684
|
+
// Transform as vector, only uses 3x3 minor matrix
|
|
685
|
+
function vec3_transformMat4AsVector(out, a, m) {
|
|
686
|
+
const x = a[0];
|
|
687
|
+
const y = a[1];
|
|
688
|
+
const z = a[2];
|
|
689
|
+
const w = m[3] * x + m[7] * y + m[11] * z || 1.0;
|
|
690
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
|
|
691
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
|
|
692
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
function vec3_transformMat2(out, a, m) {
|
|
696
|
+
const x = a[0];
|
|
697
|
+
const y = a[1];
|
|
698
|
+
out[0] = m[0] * x + m[2] * y;
|
|
699
|
+
out[1] = m[1] * x + m[3] * y;
|
|
700
|
+
out[2] = a[2];
|
|
701
|
+
return out;
|
|
702
|
+
}
|
|
703
|
+
// vec4 additions
|
|
704
|
+
function vec4_transformMat2(out, a, m) {
|
|
705
|
+
const x = a[0];
|
|
706
|
+
const y = a[1];
|
|
707
|
+
out[0] = m[0] * x + m[2] * y;
|
|
708
|
+
out[1] = m[1] * x + m[3] * y;
|
|
709
|
+
out[2] = a[2];
|
|
710
|
+
out[3] = a[3];
|
|
711
|
+
return out;
|
|
712
|
+
}
|
|
713
|
+
function vec4_transformMat3(out, a, m) {
|
|
714
|
+
const x = a[0];
|
|
715
|
+
const y = a[1];
|
|
716
|
+
const z = a[2];
|
|
717
|
+
out[0] = m[0] * x + m[3] * y + m[6] * z;
|
|
718
|
+
out[1] = m[1] * x + m[4] * y + m[7] * z;
|
|
719
|
+
out[2] = m[2] * x + m[5] * y + m[8] * z;
|
|
720
|
+
out[3] = a[3];
|
|
721
|
+
return out;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// @eslint-disable
|
|
725
|
+
/**
|
|
726
|
+
* 3 Dimensional Vector
|
|
727
|
+
* @module vec3
|
|
728
|
+
*/
|
|
729
|
+
/**
|
|
730
|
+
* Creates a new, empty vec3
|
|
731
|
+
*
|
|
732
|
+
* @returns {vec3} a new 3D vector
|
|
733
|
+
*/
|
|
734
|
+
function create$3() {
|
|
735
|
+
const out = new ARRAY_TYPE(3);
|
|
736
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
737
|
+
out[0] = 0;
|
|
738
|
+
out[1] = 0;
|
|
739
|
+
out[2] = 0;
|
|
740
|
+
}
|
|
741
|
+
return out;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Calculates the length of a vec3
|
|
745
|
+
*
|
|
746
|
+
* @param {ReadonlyVec3} a vector to calculate length of
|
|
747
|
+
* @returns {Number} length of a
|
|
748
|
+
*/
|
|
749
|
+
function length$2(a) {
|
|
750
|
+
const x = a[0];
|
|
751
|
+
const y = a[1];
|
|
752
|
+
const z = a[2];
|
|
753
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Creates a new vec3 initialized with the given values
|
|
757
|
+
*
|
|
758
|
+
* @param {Number} x X component
|
|
759
|
+
* @param {Number} y Y component
|
|
760
|
+
* @param {Number} z Z component
|
|
761
|
+
* @returns {vec3} a new 3D vector
|
|
762
|
+
*/
|
|
763
|
+
function fromValues(x, y, z) {
|
|
764
|
+
const out = new ARRAY_TYPE(3);
|
|
765
|
+
out[0] = x;
|
|
766
|
+
out[1] = y;
|
|
767
|
+
out[2] = z;
|
|
768
|
+
return out;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Normalize a vec3
|
|
772
|
+
*
|
|
773
|
+
* @param {vec3} out the receiving vector
|
|
774
|
+
* @param {ReadonlyVec3} a vector to normalize
|
|
775
|
+
* @returns {vec3} out
|
|
776
|
+
*/
|
|
777
|
+
function normalize$2(out, a) {
|
|
778
|
+
const x = a[0];
|
|
779
|
+
const y = a[1];
|
|
780
|
+
const z = a[2];
|
|
781
|
+
let len = x * x + y * y + z * z;
|
|
782
|
+
if (len > 0) {
|
|
783
|
+
// TODO: evaluate use of glm_invsqrt here?
|
|
784
|
+
len = 1 / Math.sqrt(len);
|
|
785
|
+
}
|
|
786
|
+
out[0] = a[0] * len;
|
|
787
|
+
out[1] = a[1] * len;
|
|
788
|
+
out[2] = a[2] * len;
|
|
789
|
+
return out;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Calculates the dot product of two vec3's
|
|
793
|
+
*
|
|
794
|
+
* @param {ReadonlyVec3} a the first operand
|
|
795
|
+
* @param {ReadonlyVec3} b the second operand
|
|
796
|
+
* @returns {Number} dot product of a and b
|
|
797
|
+
*/
|
|
798
|
+
function dot$2(a, b) {
|
|
799
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Computes the cross product of two vec3's
|
|
803
|
+
*
|
|
804
|
+
* @param {vec3} out the receiving vector
|
|
805
|
+
* @param {ReadonlyVec3} a the first operand
|
|
806
|
+
* @param {ReadonlyVec3} b the second operand
|
|
807
|
+
* @returns {vec3} out
|
|
808
|
+
*/
|
|
809
|
+
function cross(out, a, b) {
|
|
810
|
+
const ax = a[0];
|
|
811
|
+
const ay = a[1];
|
|
812
|
+
const az = a[2];
|
|
813
|
+
const bx = b[0];
|
|
814
|
+
const by = b[1];
|
|
815
|
+
const bz = b[2];
|
|
816
|
+
out[0] = ay * bz - az * by;
|
|
817
|
+
out[1] = az * bx - ax * bz;
|
|
818
|
+
out[2] = ax * by - ay * bx;
|
|
819
|
+
return out;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Transforms the vec3 with a mat4.
|
|
823
|
+
* 4th vector component is implicitly '1'
|
|
824
|
+
*
|
|
825
|
+
* @param {vec3} out the receiving vector
|
|
826
|
+
* @param {ReadonlyVec3} a the vector to transform
|
|
827
|
+
* @param {ReadonlyMat4} m matrix to transform with
|
|
828
|
+
* @returns {vec3} out
|
|
829
|
+
*/
|
|
830
|
+
function transformMat4(out, a, m) {
|
|
831
|
+
const x = a[0];
|
|
832
|
+
const y = a[1];
|
|
833
|
+
const z = a[2];
|
|
834
|
+
let w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
835
|
+
w = w || 1.0;
|
|
836
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
|
|
837
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
|
|
838
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
|
|
839
|
+
return out;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Transforms the vec3 with a mat3.
|
|
843
|
+
*
|
|
844
|
+
* @param {vec3} out the receiving vector
|
|
845
|
+
* @param {ReadonlyVec3} a the vector to transform
|
|
846
|
+
* @param {ReadonlyMat3} m the 3x3 matrix to transform with
|
|
847
|
+
* @returns {vec3} out
|
|
848
|
+
*/
|
|
849
|
+
function transformMat3(out, a, m) {
|
|
850
|
+
const x = a[0];
|
|
851
|
+
const y = a[1];
|
|
852
|
+
const z = a[2];
|
|
853
|
+
out[0] = x * m[0] + y * m[3] + z * m[6];
|
|
854
|
+
out[1] = x * m[1] + y * m[4] + z * m[7];
|
|
855
|
+
out[2] = x * m[2] + y * m[5] + z * m[8];
|
|
856
|
+
return out;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Transforms the vec3 with a quat
|
|
860
|
+
* Can also be used for dual quaternions. (Multiply it with the real part)
|
|
861
|
+
*
|
|
862
|
+
* @param {vec3} out the receiving vector
|
|
863
|
+
* @param {ReadonlyVec3} a the vector to transform
|
|
864
|
+
* @param {ReadonlyQuat} q quaternion to transform with
|
|
865
|
+
* @returns {vec3} out
|
|
866
|
+
*/
|
|
867
|
+
function transformQuat$1(out, a, q) {
|
|
868
|
+
// benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
|
|
869
|
+
const qx = q[0];
|
|
870
|
+
const qy = q[1];
|
|
871
|
+
const qz = q[2];
|
|
872
|
+
const qw = q[3];
|
|
873
|
+
const x = a[0];
|
|
874
|
+
const y = a[1];
|
|
875
|
+
const z = a[2];
|
|
876
|
+
// var qvec = [qx, qy, qz];
|
|
877
|
+
// var uv = vec3.cross([], qvec, a);
|
|
878
|
+
let uvx = qy * z - qz * y;
|
|
879
|
+
let uvy = qz * x - qx * z;
|
|
880
|
+
let uvz = qx * y - qy * x;
|
|
881
|
+
// var uuv = vec3.cross([], qvec, uv);
|
|
882
|
+
let uuvx = qy * uvz - qz * uvy;
|
|
883
|
+
let uuvy = qz * uvx - qx * uvz;
|
|
884
|
+
let uuvz = qx * uvy - qy * uvx;
|
|
885
|
+
// vec3.scale(uv, uv, 2 * w);
|
|
886
|
+
const w2 = qw * 2;
|
|
887
|
+
uvx *= w2;
|
|
888
|
+
uvy *= w2;
|
|
889
|
+
uvz *= w2;
|
|
890
|
+
// vec3.scale(uuv, uuv, 2);
|
|
891
|
+
uuvx *= 2;
|
|
892
|
+
uuvy *= 2;
|
|
893
|
+
uuvz *= 2;
|
|
894
|
+
// return vec3.add(out, a, vec3.add(out, uv, uuv));
|
|
895
|
+
out[0] = x + uvx + uuvx;
|
|
896
|
+
out[1] = y + uvy + uuvy;
|
|
897
|
+
out[2] = z + uvz + uuvz;
|
|
898
|
+
return out;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Rotate a 3D vector around the x-axis
|
|
902
|
+
* @param {vec3} out The receiving vec3
|
|
903
|
+
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
904
|
+
* @param {ReadonlyVec3} b The origin of the rotation
|
|
905
|
+
* @param {Number} rad The angle of rotation in radians
|
|
906
|
+
* @returns {vec3} out
|
|
907
|
+
*/
|
|
908
|
+
function rotateX$1(out, a, b, rad) {
|
|
909
|
+
const p = [];
|
|
910
|
+
const r = [];
|
|
911
|
+
// Translate point to the origin
|
|
912
|
+
p[0] = a[0] - b[0];
|
|
913
|
+
p[1] = a[1] - b[1];
|
|
914
|
+
p[2] = a[2] - b[2];
|
|
915
|
+
// perform rotation
|
|
916
|
+
r[0] = p[0];
|
|
917
|
+
r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
|
|
918
|
+
r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
|
|
919
|
+
// translate to correct position
|
|
920
|
+
out[0] = r[0] + b[0];
|
|
921
|
+
out[1] = r[1] + b[1];
|
|
922
|
+
out[2] = r[2] + b[2];
|
|
923
|
+
return out;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Rotate a 3D vector around the y-axis
|
|
927
|
+
* @param {vec3} out The receiving vec3
|
|
928
|
+
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
929
|
+
* @param {ReadonlyVec3} b The origin of the rotation
|
|
930
|
+
* @param {Number} rad The angle of rotation in radians
|
|
931
|
+
* @returns {vec3} out
|
|
932
|
+
*/
|
|
933
|
+
function rotateY$1(out, a, b, rad) {
|
|
934
|
+
const p = [];
|
|
935
|
+
const r = [];
|
|
936
|
+
// Translate point to the origin
|
|
937
|
+
p[0] = a[0] - b[0];
|
|
938
|
+
p[1] = a[1] - b[1];
|
|
939
|
+
p[2] = a[2] - b[2];
|
|
940
|
+
// perform rotation
|
|
941
|
+
r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
|
|
942
|
+
r[1] = p[1];
|
|
943
|
+
r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
|
|
944
|
+
// translate to correct position
|
|
945
|
+
out[0] = r[0] + b[0];
|
|
946
|
+
out[1] = r[1] + b[1];
|
|
947
|
+
out[2] = r[2] + b[2];
|
|
948
|
+
return out;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Rotate a 3D vector around the z-axis
|
|
952
|
+
* @param {vec3} out The receiving vec3
|
|
953
|
+
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
954
|
+
* @param {ReadonlyVec3} b The origin of the rotation
|
|
955
|
+
* @param {Number} rad The angle of rotation in radians
|
|
956
|
+
* @returns {vec3} out
|
|
957
|
+
*/
|
|
958
|
+
function rotateZ$1(out, a, b, rad) {
|
|
959
|
+
const p = [];
|
|
960
|
+
const r = [];
|
|
961
|
+
// Translate point to the origin
|
|
962
|
+
p[0] = a[0] - b[0];
|
|
963
|
+
p[1] = a[1] - b[1];
|
|
964
|
+
p[2] = a[2] - b[2];
|
|
965
|
+
// perform rotation
|
|
966
|
+
r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
|
|
967
|
+
r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
|
|
968
|
+
r[2] = p[2];
|
|
969
|
+
// translate to correct position
|
|
970
|
+
out[0] = r[0] + b[0];
|
|
971
|
+
out[1] = r[1] + b[1];
|
|
972
|
+
out[2] = r[2] + b[2];
|
|
973
|
+
return out;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Get the angle between two 3D vectors
|
|
977
|
+
* @param {ReadonlyVec3} a The first operand
|
|
978
|
+
* @param {ReadonlyVec3} b The second operand
|
|
979
|
+
* @returns {Number} The angle in radians
|
|
980
|
+
*/
|
|
981
|
+
function angle(a, b) {
|
|
982
|
+
const ax = a[0];
|
|
983
|
+
const ay = a[1];
|
|
984
|
+
const az = a[2];
|
|
985
|
+
const bx = b[0];
|
|
986
|
+
const by = b[1];
|
|
987
|
+
const bz = b[2];
|
|
988
|
+
const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz));
|
|
989
|
+
const cosine = mag && dot$2(a, b) / mag;
|
|
990
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Alias for {@link vec3.length}
|
|
994
|
+
* @function
|
|
995
|
+
*/
|
|
996
|
+
const len = length$2;
|
|
997
|
+
/**
|
|
998
|
+
* Perform some operation over an array of vec3s.
|
|
999
|
+
*
|
|
1000
|
+
* @param {Array} a the array of vectors to iterate over
|
|
1001
|
+
* @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
|
|
1002
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
1003
|
+
* @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
|
|
1004
|
+
* @param {Function} fn Function to call for each vector in the array
|
|
1005
|
+
* @param {Object} [arg] additional argument to pass to fn
|
|
1006
|
+
* @returns {Array} a
|
|
1007
|
+
* @function
|
|
1008
|
+
*/
|
|
1009
|
+
((function () {
|
|
1010
|
+
const vec = create$3();
|
|
1011
|
+
return function (a, stride, offset, count, fn, arg) {
|
|
1012
|
+
let i;
|
|
1013
|
+
let l;
|
|
1014
|
+
if (!stride) {
|
|
1015
|
+
stride = 3;
|
|
1016
|
+
}
|
|
1017
|
+
if (!offset) {
|
|
1018
|
+
offset = 0;
|
|
1019
|
+
}
|
|
1020
|
+
if (count) {
|
|
1021
|
+
l = Math.min(count * stride + offset, a.length);
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
l = a.length;
|
|
1025
|
+
}
|
|
1026
|
+
for (i = offset; i < l; i += stride) {
|
|
1027
|
+
vec[0] = a[i];
|
|
1028
|
+
vec[1] = a[i + 1];
|
|
1029
|
+
vec[2] = a[i + 2];
|
|
1030
|
+
fn(vec, vec, arg);
|
|
1031
|
+
a[i] = vec[0];
|
|
1032
|
+
a[i + 1] = vec[1];
|
|
1033
|
+
a[i + 2] = vec[2];
|
|
1034
|
+
}
|
|
1035
|
+
return a;
|
|
1036
|
+
};
|
|
1037
|
+
}))();
|
|
1038
|
+
|
|
1039
|
+
// math.gl
|
|
1040
|
+
const ORIGIN = [0, 0, 0];
|
|
1041
|
+
let ZERO$1;
|
|
1042
|
+
/**
|
|
1043
|
+
* Three-element vector class with common linear algebra operations.
|
|
1044
|
+
* Subclass of Array<number> meaning that it is highly compatible with other libraries
|
|
1045
|
+
*/
|
|
1046
|
+
class Vector3 extends Vector {
|
|
1047
|
+
static get ZERO() {
|
|
1048
|
+
if (!ZERO$1) {
|
|
1049
|
+
ZERO$1 = new Vector3(0, 0, 0);
|
|
1050
|
+
Object.freeze(ZERO$1);
|
|
1051
|
+
}
|
|
1052
|
+
return ZERO$1;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* @class
|
|
1056
|
+
* @param x
|
|
1057
|
+
* @param y
|
|
1058
|
+
* @param z
|
|
1059
|
+
*/
|
|
1060
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
1061
|
+
// PERF NOTE: initialize elements as double precision numbers
|
|
1062
|
+
super(-0, -0, -0);
|
|
1063
|
+
if (arguments.length === 1 && isArray(x)) {
|
|
1064
|
+
this.copy(x);
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
// this.set(x, y, z);
|
|
1068
|
+
if (config.debug) {
|
|
1069
|
+
checkNumber(x);
|
|
1070
|
+
checkNumber(y);
|
|
1071
|
+
checkNumber(z);
|
|
1072
|
+
}
|
|
1073
|
+
// @ts-expect-error TS2412: Property '0' of type 'number | [number, number, number]' is not assignable to numeric index type 'number'
|
|
1074
|
+
this[0] = x;
|
|
1075
|
+
this[1] = y;
|
|
1076
|
+
this[2] = z;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
set(x, y, z) {
|
|
1080
|
+
this[0] = x;
|
|
1081
|
+
this[1] = y;
|
|
1082
|
+
this[2] = z;
|
|
1083
|
+
return this.check();
|
|
1084
|
+
}
|
|
1085
|
+
copy(array) {
|
|
1086
|
+
this[0] = array[0];
|
|
1087
|
+
this[1] = array[1];
|
|
1088
|
+
this[2] = array[2];
|
|
1089
|
+
return this.check();
|
|
1090
|
+
}
|
|
1091
|
+
fromObject(object) {
|
|
1092
|
+
if (config.debug) {
|
|
1093
|
+
checkNumber(object.x);
|
|
1094
|
+
checkNumber(object.y);
|
|
1095
|
+
checkNumber(object.z);
|
|
1096
|
+
}
|
|
1097
|
+
this[0] = object.x;
|
|
1098
|
+
this[1] = object.y;
|
|
1099
|
+
this[2] = object.z;
|
|
1100
|
+
return this.check();
|
|
1101
|
+
}
|
|
1102
|
+
toObject(object) {
|
|
1103
|
+
object.x = this[0];
|
|
1104
|
+
object.y = this[1];
|
|
1105
|
+
object.z = this[2];
|
|
1106
|
+
return object;
|
|
1107
|
+
}
|
|
1108
|
+
// Getters/setters
|
|
1109
|
+
get ELEMENTS() {
|
|
1110
|
+
return 3;
|
|
1111
|
+
}
|
|
1112
|
+
get z() {
|
|
1113
|
+
return this[2];
|
|
1114
|
+
}
|
|
1115
|
+
set z(value) {
|
|
1116
|
+
this[2] = checkNumber(value);
|
|
1117
|
+
}
|
|
1118
|
+
// ACCESSORS
|
|
1119
|
+
angle(vector) {
|
|
1120
|
+
return angle(this, vector);
|
|
1121
|
+
}
|
|
1122
|
+
// MODIFIERS
|
|
1123
|
+
cross(vector) {
|
|
1124
|
+
cross(this, this, vector);
|
|
1125
|
+
return this.check();
|
|
1126
|
+
}
|
|
1127
|
+
rotateX({ radians, origin = ORIGIN }) {
|
|
1128
|
+
rotateX$1(this, this, origin, radians);
|
|
1129
|
+
return this.check();
|
|
1130
|
+
}
|
|
1131
|
+
rotateY({ radians, origin = ORIGIN }) {
|
|
1132
|
+
rotateY$1(this, this, origin, radians);
|
|
1133
|
+
return this.check();
|
|
1134
|
+
}
|
|
1135
|
+
rotateZ({ radians, origin = ORIGIN }) {
|
|
1136
|
+
rotateZ$1(this, this, origin, radians);
|
|
1137
|
+
return this.check();
|
|
1138
|
+
}
|
|
1139
|
+
// Transforms
|
|
1140
|
+
// transforms as point (4th component is implicitly 1)
|
|
1141
|
+
transform(matrix4) {
|
|
1142
|
+
return this.transformAsPoint(matrix4);
|
|
1143
|
+
}
|
|
1144
|
+
// transforms as point (4th component is implicitly 1)
|
|
1145
|
+
transformAsPoint(matrix4) {
|
|
1146
|
+
transformMat4(this, this, matrix4);
|
|
1147
|
+
return this.check();
|
|
1148
|
+
}
|
|
1149
|
+
// transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
|
|
1150
|
+
transformAsVector(matrix4) {
|
|
1151
|
+
vec3_transformMat4AsVector(this, this, matrix4);
|
|
1152
|
+
return this.check();
|
|
1153
|
+
}
|
|
1154
|
+
transformByMatrix3(matrix3) {
|
|
1155
|
+
transformMat3(this, this, matrix3);
|
|
1156
|
+
return this.check();
|
|
1157
|
+
}
|
|
1158
|
+
transformByMatrix2(matrix2) {
|
|
1159
|
+
vec3_transformMat2(this, this, matrix2);
|
|
1160
|
+
return this.check();
|
|
1161
|
+
}
|
|
1162
|
+
transformByQuaternion(quaternion) {
|
|
1163
|
+
transformQuat$1(this, this, quaternion);
|
|
1164
|
+
return this.check();
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// math.gl
|
|
1169
|
+
let ZERO;
|
|
1170
|
+
/**
|
|
1171
|
+
* Four-element vector class with common linear algebra operations.
|
|
1172
|
+
* Subclass of Array<number> meaning that it is highly compatible with other libraries
|
|
1173
|
+
*/
|
|
1174
|
+
class Vector4 extends Vector {
|
|
1175
|
+
static get ZERO() {
|
|
1176
|
+
if (!ZERO) {
|
|
1177
|
+
ZERO = new Vector4(0, 0, 0, 0);
|
|
1178
|
+
Object.freeze(ZERO);
|
|
1179
|
+
}
|
|
1180
|
+
return ZERO;
|
|
1181
|
+
}
|
|
1182
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
1183
|
+
// PERF NOTE: initialize elements as double precision numbers
|
|
1184
|
+
super(-0, -0, -0, -0);
|
|
1185
|
+
if (isArray(x) && arguments.length === 1) {
|
|
1186
|
+
this.copy(x);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
// this.set(x, y, z, w);
|
|
1190
|
+
if (config.debug) {
|
|
1191
|
+
checkNumber(x);
|
|
1192
|
+
checkNumber(y);
|
|
1193
|
+
checkNumber(z);
|
|
1194
|
+
checkNumber(w);
|
|
1195
|
+
}
|
|
1196
|
+
this[0] = x;
|
|
1197
|
+
this[1] = y;
|
|
1198
|
+
this[2] = z;
|
|
1199
|
+
this[3] = w;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
set(x, y, z, w) {
|
|
1203
|
+
this[0] = x;
|
|
1204
|
+
this[1] = y;
|
|
1205
|
+
this[2] = z;
|
|
1206
|
+
this[3] = w;
|
|
1207
|
+
return this.check();
|
|
1208
|
+
}
|
|
1209
|
+
copy(array) {
|
|
1210
|
+
this[0] = array[0];
|
|
1211
|
+
this[1] = array[1];
|
|
1212
|
+
this[2] = array[2];
|
|
1213
|
+
this[3] = array[3];
|
|
1214
|
+
return this.check();
|
|
1215
|
+
}
|
|
1216
|
+
fromObject(object) {
|
|
1217
|
+
if (config.debug) {
|
|
1218
|
+
checkNumber(object.x);
|
|
1219
|
+
checkNumber(object.y);
|
|
1220
|
+
checkNumber(object.z);
|
|
1221
|
+
checkNumber(object.w);
|
|
1222
|
+
}
|
|
1223
|
+
this[0] = object.x;
|
|
1224
|
+
this[1] = object.y;
|
|
1225
|
+
this[2] = object.z;
|
|
1226
|
+
this[3] = object.w;
|
|
1227
|
+
return this;
|
|
1228
|
+
}
|
|
1229
|
+
toObject(object) {
|
|
1230
|
+
object.x = this[0];
|
|
1231
|
+
object.y = this[1];
|
|
1232
|
+
object.z = this[2];
|
|
1233
|
+
object.w = this[3];
|
|
1234
|
+
return object;
|
|
1235
|
+
}
|
|
1236
|
+
// Getters/setters
|
|
1237
|
+
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
1238
|
+
get ELEMENTS() {
|
|
1239
|
+
return 4;
|
|
1240
|
+
}
|
|
1241
|
+
get z() {
|
|
1242
|
+
return this[2];
|
|
1243
|
+
}
|
|
1244
|
+
set z(value) {
|
|
1245
|
+
this[2] = checkNumber(value);
|
|
1246
|
+
}
|
|
1247
|
+
get w() {
|
|
1248
|
+
return this[3];
|
|
1249
|
+
}
|
|
1250
|
+
set w(value) {
|
|
1251
|
+
this[3] = checkNumber(value);
|
|
1252
|
+
}
|
|
1253
|
+
transform(matrix4) {
|
|
1254
|
+
transformMat4(this, this, matrix4);
|
|
1255
|
+
return this.check();
|
|
1256
|
+
}
|
|
1257
|
+
transformByMatrix3(matrix3) {
|
|
1258
|
+
vec4_transformMat3(this, this, matrix3);
|
|
1259
|
+
return this.check();
|
|
1260
|
+
}
|
|
1261
|
+
transformByMatrix2(matrix2) {
|
|
1262
|
+
vec4_transformMat2(this, this, matrix2);
|
|
1263
|
+
return this.check();
|
|
1264
|
+
}
|
|
1265
|
+
transformByQuaternion(quaternion) {
|
|
1266
|
+
transformQuat$1(this, this, quaternion);
|
|
1267
|
+
return this.check();
|
|
1268
|
+
}
|
|
1269
|
+
// three.js compatibility
|
|
1270
|
+
applyMatrix4(m) {
|
|
1271
|
+
m.transform(this, this);
|
|
1272
|
+
return this;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* 3x3 Matrix
|
|
1278
|
+
* @module mat3
|
|
1279
|
+
*/
|
|
1280
|
+
/**
|
|
1281
|
+
* Creates a new identity mat3
|
|
1282
|
+
*
|
|
1283
|
+
* @returns {mat3} a new 3x3 matrix
|
|
1284
|
+
*/
|
|
1285
|
+
function create$2() {
|
|
1286
|
+
const out = new ARRAY_TYPE(9);
|
|
1287
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1288
|
+
out[1] = 0;
|
|
1289
|
+
out[2] = 0;
|
|
1290
|
+
out[3] = 0;
|
|
1291
|
+
out[5] = 0;
|
|
1292
|
+
out[6] = 0;
|
|
1293
|
+
out[7] = 0;
|
|
1294
|
+
}
|
|
1295
|
+
out[0] = 1;
|
|
1296
|
+
out[4] = 1;
|
|
1297
|
+
out[8] = 1;
|
|
1298
|
+
return out;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// @eslint-disable
|
|
1302
|
+
/**
|
|
1303
|
+
* 4 Dimensional Vector
|
|
1304
|
+
* @module vec4
|
|
1305
|
+
*/
|
|
1306
|
+
/**
|
|
1307
|
+
* Creates a new, empty vec4
|
|
1308
|
+
*
|
|
1309
|
+
* @returns {vec4} a new 4D vector
|
|
1310
|
+
*/
|
|
1311
|
+
function create$1() {
|
|
1312
|
+
const out = new ARRAY_TYPE(4);
|
|
1313
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1314
|
+
out[0] = 0;
|
|
1315
|
+
out[1] = 0;
|
|
1316
|
+
out[2] = 0;
|
|
1317
|
+
out[3] = 0;
|
|
1318
|
+
}
|
|
1319
|
+
return out;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Adds two vec4's
|
|
1323
|
+
*
|
|
1324
|
+
* @param {vec4} out the receiving vector
|
|
1325
|
+
* @param {ReadonlyVec4} a the first operand
|
|
1326
|
+
* @param {ReadonlyVec4} b the second operand
|
|
1327
|
+
* @returns {vec4} out
|
|
1328
|
+
*/
|
|
1329
|
+
function add$1(out, a, b) {
|
|
1330
|
+
out[0] = a[0] + b[0];
|
|
1331
|
+
out[1] = a[1] + b[1];
|
|
1332
|
+
out[2] = a[2] + b[2];
|
|
1333
|
+
out[3] = a[3] + b[3];
|
|
1334
|
+
return out;
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Scales a vec4 by a scalar number
|
|
1338
|
+
*
|
|
1339
|
+
* @param {vec4} out the receiving vector
|
|
1340
|
+
* @param {ReadonlyVec4} a the vector to scale
|
|
1341
|
+
* @param {Number} b amount to scale the vector by
|
|
1342
|
+
* @returns {vec4} out
|
|
1343
|
+
*/
|
|
1344
|
+
function scale$1(out, a, b) {
|
|
1345
|
+
out[0] = a[0] * b;
|
|
1346
|
+
out[1] = a[1] * b;
|
|
1347
|
+
out[2] = a[2] * b;
|
|
1348
|
+
out[3] = a[3] * b;
|
|
1349
|
+
return out;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Calculates the length of a vec4
|
|
1353
|
+
*
|
|
1354
|
+
* @param {ReadonlyVec4} a vector to calculate length of
|
|
1355
|
+
* @returns {Number} length of a
|
|
1356
|
+
*/
|
|
1357
|
+
function length$1(a) {
|
|
1358
|
+
const x = a[0];
|
|
1359
|
+
const y = a[1];
|
|
1360
|
+
const z = a[2];
|
|
1361
|
+
const w = a[3];
|
|
1362
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Calculates the squared length of a vec4
|
|
1366
|
+
*
|
|
1367
|
+
* @param {ReadonlyVec4} a vector to calculate squared length of
|
|
1368
|
+
* @returns {Number} squared length of a
|
|
1369
|
+
*/
|
|
1370
|
+
function squaredLength$1(a) {
|
|
1371
|
+
const x = a[0];
|
|
1372
|
+
const y = a[1];
|
|
1373
|
+
const z = a[2];
|
|
1374
|
+
const w = a[3];
|
|
1375
|
+
return x * x + y * y + z * z + w * w;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Normalize a vec4
|
|
1379
|
+
*
|
|
1380
|
+
* @param {vec4} out the receiving vector
|
|
1381
|
+
* @param {ReadonlyVec4} a vector to normalize
|
|
1382
|
+
* @returns {vec4} out
|
|
1383
|
+
*/
|
|
1384
|
+
function normalize$1(out, a) {
|
|
1385
|
+
const x = a[0];
|
|
1386
|
+
const y = a[1];
|
|
1387
|
+
const z = a[2];
|
|
1388
|
+
const w = a[3];
|
|
1389
|
+
let len = x * x + y * y + z * z + w * w;
|
|
1390
|
+
if (len > 0) {
|
|
1391
|
+
len = 1 / Math.sqrt(len);
|
|
1392
|
+
}
|
|
1393
|
+
out[0] = x * len;
|
|
1394
|
+
out[1] = y * len;
|
|
1395
|
+
out[2] = z * len;
|
|
1396
|
+
out[3] = w * len;
|
|
1397
|
+
return out;
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Calculates the dot product of two vec4's
|
|
1401
|
+
*
|
|
1402
|
+
* @param {ReadonlyVec4} a the first operand
|
|
1403
|
+
* @param {ReadonlyVec4} b the second operand
|
|
1404
|
+
* @returns {Number} dot product of a and b
|
|
1405
|
+
*/
|
|
1406
|
+
function dot$1(a, b) {
|
|
1407
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Performs a linear interpolation between two vec4's
|
|
1411
|
+
*
|
|
1412
|
+
* @param {vec4} out the receiving vector
|
|
1413
|
+
* @param {ReadonlyVec4} a the first operand
|
|
1414
|
+
* @param {ReadonlyVec4} b the second operand
|
|
1415
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
1416
|
+
* @returns {vec4} out
|
|
1417
|
+
*/
|
|
1418
|
+
function lerp$1(out, a, b, t) {
|
|
1419
|
+
const ax = a[0];
|
|
1420
|
+
const ay = a[1];
|
|
1421
|
+
const az = a[2];
|
|
1422
|
+
const aw = a[3];
|
|
1423
|
+
out[0] = ax + t * (b[0] - ax);
|
|
1424
|
+
out[1] = ay + t * (b[1] - ay);
|
|
1425
|
+
out[2] = az + t * (b[2] - az);
|
|
1426
|
+
out[3] = aw + t * (b[3] - aw);
|
|
1427
|
+
return out;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Transforms the vec4 with a quat
|
|
1431
|
+
*
|
|
1432
|
+
* @param {vec4} out the receiving vector
|
|
1433
|
+
* @param {ReadonlyVec4} a the vector to transform
|
|
1434
|
+
* @param {ReadonlyQuat} q quaternion to transform with
|
|
1435
|
+
* @returns {vec4} out
|
|
1436
|
+
*/
|
|
1437
|
+
function transformQuat(out, a, q) {
|
|
1438
|
+
const x = a[0];
|
|
1439
|
+
const y = a[1];
|
|
1440
|
+
const z = a[2];
|
|
1441
|
+
const qx = q[0];
|
|
1442
|
+
const qy = q[1];
|
|
1443
|
+
const qz = q[2];
|
|
1444
|
+
const qw = q[3];
|
|
1445
|
+
// calculate quat * vec
|
|
1446
|
+
const ix = qw * x + qy * z - qz * y;
|
|
1447
|
+
const iy = qw * y + qz * x - qx * z;
|
|
1448
|
+
const iz = qw * z + qx * y - qy * x;
|
|
1449
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
1450
|
+
// calculate result * inverse quat
|
|
1451
|
+
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
1452
|
+
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
1453
|
+
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
1454
|
+
out[3] = a[3];
|
|
1455
|
+
return out;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Perform some operation over an array of vec4s.
|
|
1459
|
+
*
|
|
1460
|
+
* @param {Array} a the array of vectors to iterate over
|
|
1461
|
+
* @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
|
|
1462
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
1463
|
+
* @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
|
|
1464
|
+
* @param {Function} fn Function to call for each vector in the array
|
|
1465
|
+
* @param {Object} [arg] additional argument to pass to fn
|
|
1466
|
+
* @returns {Array} a
|
|
1467
|
+
* @function
|
|
1468
|
+
*/
|
|
1469
|
+
((function () {
|
|
1470
|
+
const vec = create$1();
|
|
1471
|
+
return function (a, stride, offset, count, fn, arg) {
|
|
1472
|
+
let i;
|
|
1473
|
+
let l;
|
|
1474
|
+
if (!stride) {
|
|
1475
|
+
stride = 4;
|
|
1476
|
+
}
|
|
1477
|
+
if (!offset) {
|
|
1478
|
+
offset = 0;
|
|
1479
|
+
}
|
|
1480
|
+
if (count) {
|
|
1481
|
+
l = Math.min(count * stride + offset, a.length);
|
|
1482
|
+
}
|
|
1483
|
+
else {
|
|
1484
|
+
l = a.length;
|
|
1485
|
+
}
|
|
1486
|
+
for (i = offset; i < l; i += stride) {
|
|
1487
|
+
vec[0] = a[i];
|
|
1488
|
+
vec[1] = a[i + 1];
|
|
1489
|
+
vec[2] = a[i + 2];
|
|
1490
|
+
vec[3] = a[i + 3];
|
|
1491
|
+
fn(vec, vec, arg);
|
|
1492
|
+
a[i] = vec[0];
|
|
1493
|
+
a[i + 1] = vec[1];
|
|
1494
|
+
a[i + 2] = vec[2];
|
|
1495
|
+
a[i + 3] = vec[3];
|
|
1496
|
+
}
|
|
1497
|
+
return a;
|
|
1498
|
+
};
|
|
1499
|
+
}))();
|
|
1500
|
+
|
|
1501
|
+
// @eslint-disable
|
|
1502
|
+
// const glMatrix: {EPSILON = 0.000001};
|
|
1503
|
+
/**
|
|
1504
|
+
* Quaternion in the format XYZW
|
|
1505
|
+
* @module quat
|
|
1506
|
+
*/
|
|
1507
|
+
/**
|
|
1508
|
+
* Creates a new identity quat
|
|
1509
|
+
*
|
|
1510
|
+
* @returns {quat} a new quaternion
|
|
1511
|
+
*/
|
|
1512
|
+
function create() {
|
|
1513
|
+
const out = new ARRAY_TYPE(4);
|
|
1514
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1515
|
+
out[0] = 0;
|
|
1516
|
+
out[1] = 0;
|
|
1517
|
+
out[2] = 0;
|
|
1518
|
+
}
|
|
1519
|
+
out[3] = 1;
|
|
1520
|
+
return out;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Set a quat to the identity quaternion
|
|
1524
|
+
*
|
|
1525
|
+
* @param {quat} out the receiving quaternion
|
|
1526
|
+
* @returns {quat} out
|
|
1527
|
+
*/
|
|
1528
|
+
function identity(out) {
|
|
1529
|
+
out[0] = 0;
|
|
1530
|
+
out[1] = 0;
|
|
1531
|
+
out[2] = 0;
|
|
1532
|
+
out[3] = 1;
|
|
1533
|
+
return out;
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Sets a quat from the given angle and rotation axis,
|
|
1537
|
+
* then returns it.
|
|
1538
|
+
*
|
|
1539
|
+
* @param {quat} out the receiving quaternion
|
|
1540
|
+
* @param {ReadonlyVec3} axis the axis around which to rotate
|
|
1541
|
+
* @param {Number} rad the angle in radians
|
|
1542
|
+
* @returns {quat} out
|
|
1543
|
+
**/
|
|
1544
|
+
function setAxisAngle(out, axis, rad) {
|
|
1545
|
+
rad = rad * 0.5;
|
|
1546
|
+
const s = Math.sin(rad);
|
|
1547
|
+
out[0] = s * axis[0];
|
|
1548
|
+
out[1] = s * axis[1];
|
|
1549
|
+
out[2] = s * axis[2];
|
|
1550
|
+
out[3] = Math.cos(rad);
|
|
1551
|
+
return out;
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Multiplies two quat's
|
|
1555
|
+
*
|
|
1556
|
+
* @param {quat} out the receiving quaternion
|
|
1557
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1558
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1559
|
+
* @returns {quat} out
|
|
1560
|
+
*/
|
|
1561
|
+
function multiply(out, a, b) {
|
|
1562
|
+
const ax = a[0];
|
|
1563
|
+
const ay = a[1];
|
|
1564
|
+
const az = a[2];
|
|
1565
|
+
const aw = a[3];
|
|
1566
|
+
const bx = b[0];
|
|
1567
|
+
const by = b[1];
|
|
1568
|
+
const bz = b[2];
|
|
1569
|
+
const bw = b[3];
|
|
1570
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
1571
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
1572
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
1573
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
1574
|
+
return out;
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Rotates a quaternion by the given angle about the X axis
|
|
1578
|
+
*
|
|
1579
|
+
* @param {quat} out quat receiving operation result
|
|
1580
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
1581
|
+
* @param {number} rad angle (in radians) to rotate
|
|
1582
|
+
* @returns {quat} out
|
|
1583
|
+
*/
|
|
1584
|
+
function rotateX(out, a, rad) {
|
|
1585
|
+
rad *= 0.5;
|
|
1586
|
+
const ax = a[0];
|
|
1587
|
+
const ay = a[1];
|
|
1588
|
+
const az = a[2];
|
|
1589
|
+
const aw = a[3];
|
|
1590
|
+
const bx = Math.sin(rad);
|
|
1591
|
+
const bw = Math.cos(rad);
|
|
1592
|
+
out[0] = ax * bw + aw * bx;
|
|
1593
|
+
out[1] = ay * bw + az * bx;
|
|
1594
|
+
out[2] = az * bw - ay * bx;
|
|
1595
|
+
out[3] = aw * bw - ax * bx;
|
|
1596
|
+
return out;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Rotates a quaternion by the given angle about the Y axis
|
|
1600
|
+
*
|
|
1601
|
+
* @param {quat} out quat receiving operation result
|
|
1602
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
1603
|
+
* @param {number} rad angle (in radians) to rotate
|
|
1604
|
+
* @returns {quat} out
|
|
1605
|
+
*/
|
|
1606
|
+
function rotateY(out, a, rad) {
|
|
1607
|
+
rad *= 0.5;
|
|
1608
|
+
const ax = a[0];
|
|
1609
|
+
const ay = a[1];
|
|
1610
|
+
const az = a[2];
|
|
1611
|
+
const aw = a[3];
|
|
1612
|
+
const by = Math.sin(rad);
|
|
1613
|
+
const bw = Math.cos(rad);
|
|
1614
|
+
out[0] = ax * bw - az * by;
|
|
1615
|
+
out[1] = ay * bw + aw * by;
|
|
1616
|
+
out[2] = az * bw + ax * by;
|
|
1617
|
+
out[3] = aw * bw - ay * by;
|
|
1618
|
+
return out;
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Rotates a quaternion by the given angle about the Z axis
|
|
1622
|
+
*
|
|
1623
|
+
* @param {quat} out quat receiving operation result
|
|
1624
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
1625
|
+
* @param {number} rad angle (in radians) to rotate
|
|
1626
|
+
* @returns {quat} out
|
|
1627
|
+
*/
|
|
1628
|
+
function rotateZ(out, a, rad) {
|
|
1629
|
+
rad *= 0.5;
|
|
1630
|
+
const ax = a[0];
|
|
1631
|
+
const ay = a[1];
|
|
1632
|
+
const az = a[2];
|
|
1633
|
+
const aw = a[3];
|
|
1634
|
+
const bz = Math.sin(rad);
|
|
1635
|
+
const bw = Math.cos(rad);
|
|
1636
|
+
out[0] = ax * bw + ay * bz;
|
|
1637
|
+
out[1] = ay * bw - ax * bz;
|
|
1638
|
+
out[2] = az * bw + aw * bz;
|
|
1639
|
+
out[3] = aw * bw - az * bz;
|
|
1640
|
+
return out;
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Calculates the W component of a quat from the X, Y, and Z components.
|
|
1644
|
+
* Assumes that quaternion is 1 unit in length.
|
|
1645
|
+
* Any existing W component will be ignored.
|
|
1646
|
+
*
|
|
1647
|
+
* @param {quat} out the receiving quaternion
|
|
1648
|
+
* @param {ReadonlyQuat} a quat to calculate W component of
|
|
1649
|
+
* @returns {quat} out
|
|
1650
|
+
*/
|
|
1651
|
+
function calculateW(out, a) {
|
|
1652
|
+
const x = a[0];
|
|
1653
|
+
const y = a[1];
|
|
1654
|
+
const z = a[2];
|
|
1655
|
+
out[0] = x;
|
|
1656
|
+
out[1] = y;
|
|
1657
|
+
out[2] = z;
|
|
1658
|
+
out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
|
|
1659
|
+
return out;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Performs a spherical linear interpolation between two quat
|
|
1663
|
+
*
|
|
1664
|
+
* @param {quat} out the receiving quaternion
|
|
1665
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1666
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1667
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
1668
|
+
* @returns {quat} out
|
|
1669
|
+
*/
|
|
1670
|
+
function slerp(out, a, b, t) {
|
|
1671
|
+
// benchmarks:
|
|
1672
|
+
// http://jsperf.com/quaternion-slerp-implementations
|
|
1673
|
+
const ax = a[0];
|
|
1674
|
+
const ay = a[1];
|
|
1675
|
+
const az = a[2];
|
|
1676
|
+
const aw = a[3];
|
|
1677
|
+
let bx = b[0];
|
|
1678
|
+
let by = b[1];
|
|
1679
|
+
let bz = b[2];
|
|
1680
|
+
let bw = b[3];
|
|
1681
|
+
let cosom;
|
|
1682
|
+
let omega;
|
|
1683
|
+
let scale0;
|
|
1684
|
+
let scale1;
|
|
1685
|
+
let sinom;
|
|
1686
|
+
// calc cosine
|
|
1687
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
1688
|
+
// adjust signs (if necessary)
|
|
1689
|
+
if (cosom < 0.0) {
|
|
1690
|
+
cosom = -cosom;
|
|
1691
|
+
bx = -bx;
|
|
1692
|
+
by = -by;
|
|
1693
|
+
bz = -bz;
|
|
1694
|
+
bw = -bw;
|
|
1695
|
+
}
|
|
1696
|
+
// calculate coefficients
|
|
1697
|
+
if (1.0 - cosom > EPSILON) {
|
|
1698
|
+
// standard case (slerp)
|
|
1699
|
+
omega = Math.acos(cosom);
|
|
1700
|
+
sinom = Math.sin(omega);
|
|
1701
|
+
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
1702
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
// "from" and "to" quaternions are very close
|
|
1706
|
+
// ... so we can do a linear interpolation
|
|
1707
|
+
scale0 = 1.0 - t;
|
|
1708
|
+
scale1 = t;
|
|
1709
|
+
}
|
|
1710
|
+
// calculate final values
|
|
1711
|
+
out[0] = scale0 * ax + scale1 * bx;
|
|
1712
|
+
out[1] = scale0 * ay + scale1 * by;
|
|
1713
|
+
out[2] = scale0 * az + scale1 * bz;
|
|
1714
|
+
out[3] = scale0 * aw + scale1 * bw;
|
|
1715
|
+
return out;
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Generates a random unit quaternion
|
|
1719
|
+
*
|
|
1720
|
+
* @param {quat} out the receiving quaternion
|
|
1721
|
+
* @returns {quat} out
|
|
1722
|
+
*/
|
|
1723
|
+
// export function random(out) {
|
|
1724
|
+
// // Implementation of http://planning.cs.uiuc.edu/node198.html
|
|
1725
|
+
// // TODO: Calling random 3 times is probably not the fastest solution
|
|
1726
|
+
// let u1 = glMatrix.RANDOM();
|
|
1727
|
+
// let u2 = glMatrix.RANDOM();
|
|
1728
|
+
// let u3 = glMatrix.RANDOM();
|
|
1729
|
+
// let sqrt1MinusU1 = Math.sqrt(1 - u1);
|
|
1730
|
+
// let sqrtU1 = Math.sqrt(u1);
|
|
1731
|
+
// out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
|
|
1732
|
+
// out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
|
|
1733
|
+
// out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
|
|
1734
|
+
// out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
|
|
1735
|
+
// return out;
|
|
1736
|
+
// }
|
|
1737
|
+
/**
|
|
1738
|
+
* Calculates the inverse of a quat
|
|
1739
|
+
*
|
|
1740
|
+
* @param {quat} out the receiving quaternion
|
|
1741
|
+
* @param {ReadonlyQuat} a quat to calculate inverse of
|
|
1742
|
+
* @returns {quat} out
|
|
1743
|
+
*/
|
|
1744
|
+
function invert(out, a) {
|
|
1745
|
+
const a0 = a[0];
|
|
1746
|
+
const a1 = a[1];
|
|
1747
|
+
const a2 = a[2];
|
|
1748
|
+
const a3 = a[3];
|
|
1749
|
+
const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
1750
|
+
const invDot = dot ? 1.0 / dot : 0;
|
|
1751
|
+
// TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
|
|
1752
|
+
out[0] = -a0 * invDot;
|
|
1753
|
+
out[1] = -a1 * invDot;
|
|
1754
|
+
out[2] = -a2 * invDot;
|
|
1755
|
+
out[3] = a3 * invDot;
|
|
1756
|
+
return out;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Calculates the conjugate of a quat
|
|
1760
|
+
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
|
|
1761
|
+
*
|
|
1762
|
+
* @param {quat} out the receiving quaternion
|
|
1763
|
+
* @param {ReadonlyQuat} a quat to calculate conjugate of
|
|
1764
|
+
* @returns {quat} out
|
|
1765
|
+
*/
|
|
1766
|
+
function conjugate(out, a) {
|
|
1767
|
+
out[0] = -a[0];
|
|
1768
|
+
out[1] = -a[1];
|
|
1769
|
+
out[2] = -a[2];
|
|
1770
|
+
out[3] = a[3];
|
|
1771
|
+
return out;
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
1775
|
+
*
|
|
1776
|
+
* NOTE: The resultant quaternion is not normalized, so you should be sure
|
|
1777
|
+
* to renormalize the quaternion yourself where necessary.
|
|
1778
|
+
*
|
|
1779
|
+
* @param {quat} out the receiving quaternion
|
|
1780
|
+
* @param {ReadonlyMat3} m rotation matrix
|
|
1781
|
+
* @returns {quat} out
|
|
1782
|
+
* @function
|
|
1783
|
+
*/
|
|
1784
|
+
function fromMat3(out, m) {
|
|
1785
|
+
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
|
1786
|
+
// article "Quaternion Calculus and Fast Animation".
|
|
1787
|
+
const fTrace = m[0] + m[4] + m[8];
|
|
1788
|
+
let fRoot;
|
|
1789
|
+
if (fTrace > 0.0) {
|
|
1790
|
+
// |w| > 1/2, may as well choose w > 1/2
|
|
1791
|
+
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
|
1792
|
+
out[3] = 0.5 * fRoot;
|
|
1793
|
+
fRoot = 0.5 / fRoot; // 1/(4w)
|
|
1794
|
+
out[0] = (m[5] - m[7]) * fRoot;
|
|
1795
|
+
out[1] = (m[6] - m[2]) * fRoot;
|
|
1796
|
+
out[2] = (m[1] - m[3]) * fRoot;
|
|
1797
|
+
}
|
|
1798
|
+
else {
|
|
1799
|
+
// |w| <= 1/2
|
|
1800
|
+
let i = 0;
|
|
1801
|
+
if (m[4] > m[0])
|
|
1802
|
+
i = 1;
|
|
1803
|
+
if (m[8] > m[i * 3 + i])
|
|
1804
|
+
i = 2;
|
|
1805
|
+
const j = (i + 1) % 3;
|
|
1806
|
+
const k = (i + 2) % 3;
|
|
1807
|
+
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
|
|
1808
|
+
out[i] = 0.5 * fRoot;
|
|
1809
|
+
fRoot = 0.5 / fRoot;
|
|
1810
|
+
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
1811
|
+
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
1812
|
+
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
1813
|
+
}
|
|
1814
|
+
return out;
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Adds two quat's
|
|
1818
|
+
*
|
|
1819
|
+
* @param {quat} out the receiving quaternion
|
|
1820
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1821
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1822
|
+
* @returns {quat} out
|
|
1823
|
+
* @function
|
|
1824
|
+
*/
|
|
1825
|
+
const add = add$1;
|
|
1826
|
+
/**
|
|
1827
|
+
* Scales a quat by a scalar number
|
|
1828
|
+
*
|
|
1829
|
+
* @param {quat} out the receiving vector
|
|
1830
|
+
* @param {ReadonlyQuat} a the vector to scale
|
|
1831
|
+
* @param {Number} b amount to scale the vector by
|
|
1832
|
+
* @returns {quat} out
|
|
1833
|
+
* @function
|
|
1834
|
+
*/
|
|
1835
|
+
const scale = scale$1;
|
|
1836
|
+
/**
|
|
1837
|
+
* Calculates the dot product of two quat's
|
|
1838
|
+
*
|
|
1839
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1840
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1841
|
+
* @returns {Number} dot product of a and b
|
|
1842
|
+
* @function
|
|
1843
|
+
*/
|
|
1844
|
+
const dot = dot$1;
|
|
1845
|
+
/**
|
|
1846
|
+
* Performs a linear interpolation between two quat's
|
|
1847
|
+
*
|
|
1848
|
+
* @param {quat} out the receiving quaternion
|
|
1849
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1850
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1851
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
1852
|
+
* @returns {quat} out
|
|
1853
|
+
* @function
|
|
1854
|
+
*/
|
|
1855
|
+
const lerp = lerp$1;
|
|
1856
|
+
/**
|
|
1857
|
+
* Calculates the length of a quat
|
|
1858
|
+
*
|
|
1859
|
+
* @param {ReadonlyQuat} a vector to calculate length of
|
|
1860
|
+
* @returns {Number} length of a
|
|
1861
|
+
*/
|
|
1862
|
+
const length = length$1;
|
|
1863
|
+
/**
|
|
1864
|
+
* Calculates the squared length of a quat
|
|
1865
|
+
*
|
|
1866
|
+
* @param {ReadonlyQuat} a vector to calculate squared length of
|
|
1867
|
+
* @returns {Number} squared length of a
|
|
1868
|
+
* @function
|
|
1869
|
+
*/
|
|
1870
|
+
const squaredLength = squaredLength$1;
|
|
1871
|
+
/**
|
|
1872
|
+
* Normalize a quat
|
|
1873
|
+
*
|
|
1874
|
+
* @param {quat} out the receiving quaternion
|
|
1875
|
+
* @param {ReadonlyQuat} a quaternion to normalize
|
|
1876
|
+
* @returns {quat} out
|
|
1877
|
+
* @function
|
|
1878
|
+
*/
|
|
1879
|
+
const normalize = normalize$1;
|
|
1880
|
+
/**
|
|
1881
|
+
* Sets a quaternion to represent the shortest rotation from one
|
|
1882
|
+
* vector to another.
|
|
1883
|
+
*
|
|
1884
|
+
* Both vectors are assumed to be unit length.
|
|
1885
|
+
*
|
|
1886
|
+
* @param {quat} out the receiving quaternion.
|
|
1887
|
+
* @param {ReadonlyVec3} a the initial vector
|
|
1888
|
+
* @param {ReadonlyVec3} b the destination vector
|
|
1889
|
+
* @returns {quat} out
|
|
1890
|
+
*/
|
|
1891
|
+
const rotationTo = (function () {
|
|
1892
|
+
const tmpvec3 = create$3();
|
|
1893
|
+
const xUnitVec3 = fromValues(1, 0, 0);
|
|
1894
|
+
const yUnitVec3 = fromValues(0, 1, 0);
|
|
1895
|
+
return function (out, a, b) {
|
|
1896
|
+
const dot = dot$2(a, b);
|
|
1897
|
+
if (dot < -0.999999) {
|
|
1898
|
+
cross(tmpvec3, xUnitVec3, a);
|
|
1899
|
+
if (len(tmpvec3) < 0.000001)
|
|
1900
|
+
cross(tmpvec3, yUnitVec3, a);
|
|
1901
|
+
normalize$2(tmpvec3, tmpvec3);
|
|
1902
|
+
setAxisAngle(out, tmpvec3, Math.PI);
|
|
1903
|
+
return out;
|
|
1904
|
+
}
|
|
1905
|
+
else if (dot > 0.999999) {
|
|
1906
|
+
out[0] = 0;
|
|
1907
|
+
out[1] = 0;
|
|
1908
|
+
out[2] = 0;
|
|
1909
|
+
out[3] = 1;
|
|
1910
|
+
return out;
|
|
1911
|
+
}
|
|
1912
|
+
cross(tmpvec3, a, b);
|
|
1913
|
+
out[0] = tmpvec3[0];
|
|
1914
|
+
out[1] = tmpvec3[1];
|
|
1915
|
+
out[2] = tmpvec3[2];
|
|
1916
|
+
out[3] = 1 + dot;
|
|
1917
|
+
return normalize(out, out);
|
|
1918
|
+
};
|
|
1919
|
+
})();
|
|
1920
|
+
/**
|
|
1921
|
+
* Performs a spherical linear interpolation with two control points
|
|
1922
|
+
*
|
|
1923
|
+
* @param {quat} out the receiving quaternion
|
|
1924
|
+
* @param {ReadonlyQuat} a the first operand
|
|
1925
|
+
* @param {ReadonlyQuat} b the second operand
|
|
1926
|
+
* @param {ReadonlyQuat} c the third operand
|
|
1927
|
+
* @param {ReadonlyQuat} d the fourth operand
|
|
1928
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
1929
|
+
* @returns {quat} out
|
|
1930
|
+
*/
|
|
1931
|
+
((function () {
|
|
1932
|
+
const temp1 = create();
|
|
1933
|
+
const temp2 = create();
|
|
1934
|
+
return function (out, a, b, c, d, t) {
|
|
1935
|
+
slerp(temp1, a, d, t);
|
|
1936
|
+
slerp(temp2, b, c, t);
|
|
1937
|
+
slerp(out, temp1, temp2, 2 * t * (1 - t));
|
|
1938
|
+
return out;
|
|
1939
|
+
};
|
|
1940
|
+
}))();
|
|
1941
|
+
/**
|
|
1942
|
+
* Sets the specified quaternion with values corresponding to the given
|
|
1943
|
+
* axes. Each axis is a vec3 and is expected to be unit length and
|
|
1944
|
+
* perpendicular to all other specified axes.
|
|
1945
|
+
*
|
|
1946
|
+
* @param {ReadonlyVec3} view the vector representing the viewing direction
|
|
1947
|
+
* @param {ReadonlyVec3} right the vector representing the local "right" direction
|
|
1948
|
+
* @param {ReadonlyVec3} up the vector representing the local "up" direction
|
|
1949
|
+
* @returns {quat} out
|
|
1950
|
+
*/
|
|
1951
|
+
((function () {
|
|
1952
|
+
const matr = create$2();
|
|
1953
|
+
return function (out, view, right, up) {
|
|
1954
|
+
matr[0] = right[0];
|
|
1955
|
+
matr[3] = right[1];
|
|
1956
|
+
matr[6] = right[2];
|
|
1957
|
+
matr[1] = up[0];
|
|
1958
|
+
matr[4] = up[1];
|
|
1959
|
+
matr[7] = up[2];
|
|
1960
|
+
matr[2] = -view[0];
|
|
1961
|
+
matr[5] = -view[1];
|
|
1962
|
+
matr[8] = -view[2];
|
|
1963
|
+
return normalize(out, fromMat3(out, matr));
|
|
1964
|
+
};
|
|
1965
|
+
}))();
|
|
1966
|
+
|
|
1967
|
+
// math.gl
|
|
1968
|
+
const IDENTITY_QUATERNION = [0, 0, 0, 1];
|
|
1969
|
+
class Quaternion extends MathArray {
|
|
1970
|
+
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
1971
|
+
// PERF NOTE: initialize elements as double precision numbers
|
|
1972
|
+
super(-0, -0, -0, -0);
|
|
1973
|
+
// eslint-disable-next-line prefer-rest-params
|
|
1974
|
+
if (Array.isArray(x) && arguments.length === 1) {
|
|
1975
|
+
this.copy(x);
|
|
1976
|
+
}
|
|
1977
|
+
else {
|
|
1978
|
+
this.set(x, y, z, w);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
copy(array) {
|
|
1982
|
+
this[0] = array[0];
|
|
1983
|
+
this[1] = array[1];
|
|
1984
|
+
this[2] = array[2];
|
|
1985
|
+
this[3] = array[3];
|
|
1986
|
+
return this.check();
|
|
1987
|
+
}
|
|
1988
|
+
set(x, y, z, w) {
|
|
1989
|
+
this[0] = x;
|
|
1990
|
+
this[1] = y;
|
|
1991
|
+
this[2] = z;
|
|
1992
|
+
this[3] = w;
|
|
1993
|
+
return this.check();
|
|
1994
|
+
}
|
|
1995
|
+
fromObject(object) {
|
|
1996
|
+
this[0] = object.x;
|
|
1997
|
+
this[1] = object.y;
|
|
1998
|
+
this[2] = object.z;
|
|
1999
|
+
this[3] = object.w;
|
|
2000
|
+
return this.check();
|
|
2001
|
+
}
|
|
2002
|
+
/**
|
|
2003
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
2004
|
+
* NOTE: The resultant quaternion is not normalized, so you should
|
|
2005
|
+
* be sure to renormalize the quaternion yourself where necessary.
|
|
2006
|
+
* @param m
|
|
2007
|
+
* @returns
|
|
2008
|
+
*/
|
|
2009
|
+
fromMatrix3(m) {
|
|
2010
|
+
fromMat3(this, m);
|
|
2011
|
+
return this.check();
|
|
2012
|
+
}
|
|
2013
|
+
fromAxisRotation(axis, rad) {
|
|
2014
|
+
setAxisAngle(this, axis, rad);
|
|
2015
|
+
return this.check();
|
|
2016
|
+
}
|
|
2017
|
+
/** Set a quat to the identity quaternion */
|
|
2018
|
+
identity() {
|
|
2019
|
+
identity(this);
|
|
2020
|
+
return this.check();
|
|
2021
|
+
}
|
|
2022
|
+
// Set the components of a quat to the given values
|
|
2023
|
+
// set(i, j, k, l) {
|
|
2024
|
+
// quat_set(this, i, j, k, l);
|
|
2025
|
+
// return this.check();
|
|
2026
|
+
// }
|
|
2027
|
+
// Sets a quat from the given angle and rotation axis, then returns it.
|
|
2028
|
+
setAxisAngle(axis, rad) {
|
|
2029
|
+
return this.fromAxisRotation(axis, rad);
|
|
2030
|
+
}
|
|
2031
|
+
// Getters/setters
|
|
2032
|
+
get ELEMENTS() {
|
|
2033
|
+
return 4;
|
|
2034
|
+
}
|
|
2035
|
+
get x() {
|
|
2036
|
+
return this[0];
|
|
2037
|
+
}
|
|
2038
|
+
set x(value) {
|
|
2039
|
+
this[0] = checkNumber(value);
|
|
2040
|
+
}
|
|
2041
|
+
get y() {
|
|
2042
|
+
return this[1];
|
|
2043
|
+
}
|
|
2044
|
+
set y(value) {
|
|
2045
|
+
this[1] = checkNumber(value);
|
|
2046
|
+
}
|
|
2047
|
+
get z() {
|
|
2048
|
+
return this[2];
|
|
2049
|
+
}
|
|
2050
|
+
set z(value) {
|
|
2051
|
+
this[2] = checkNumber(value);
|
|
2052
|
+
}
|
|
2053
|
+
get w() {
|
|
2054
|
+
return this[3];
|
|
2055
|
+
}
|
|
2056
|
+
set w(value) {
|
|
2057
|
+
this[3] = checkNumber(value);
|
|
2058
|
+
}
|
|
2059
|
+
// Calculates the length of a quat
|
|
2060
|
+
len() {
|
|
2061
|
+
return length(this);
|
|
2062
|
+
}
|
|
2063
|
+
// Calculates the squared length of a quat
|
|
2064
|
+
lengthSquared() {
|
|
2065
|
+
return squaredLength(this);
|
|
2066
|
+
}
|
|
2067
|
+
// Calculates the dot product of two quat's
|
|
2068
|
+
// @return {Number}
|
|
2069
|
+
dot(a) {
|
|
2070
|
+
return dot(this, a);
|
|
2071
|
+
}
|
|
2072
|
+
// Gets the rotation axis and angle for a given quaternion.
|
|
2073
|
+
// If a quaternion is created with setAxisAngle, this method will
|
|
2074
|
+
// return the same values as providied in the original parameter
|
|
2075
|
+
// list OR functionally equivalent values.
|
|
2076
|
+
// Example: The quaternion formed by axis [0, 0, 1] and angle -90
|
|
2077
|
+
// is the same as the quaternion formed by [0, 0, 1] and 270.
|
|
2078
|
+
// This method favors the latter.
|
|
2079
|
+
// @return {{[x,y,z], Number}}
|
|
2080
|
+
// getAxisAngle() {
|
|
2081
|
+
// const axis = [];
|
|
2082
|
+
// // const angle = quat_getAxisAngle(axis, this);
|
|
2083
|
+
// return {axis, angle};
|
|
2084
|
+
// }
|
|
2085
|
+
// MODIFIERS
|
|
2086
|
+
// Sets a quaternion to represent the shortest rotation from one vector
|
|
2087
|
+
// to another. Both vectors are assumed to be unit length.
|
|
2088
|
+
rotationTo(vectorA, vectorB) {
|
|
2089
|
+
rotationTo(this, vectorA, vectorB);
|
|
2090
|
+
return this.check();
|
|
2091
|
+
}
|
|
2092
|
+
// Sets the specified quaternion with values corresponding to the given axes.
|
|
2093
|
+
// Each axis is a vec3 and is expected to be unit length and perpendicular
|
|
2094
|
+
// to all other specified axes.
|
|
2095
|
+
// setAxes() {
|
|
2096
|
+
// Number
|
|
2097
|
+
// }
|
|
2098
|
+
// Performs a spherical linear interpolation with two control points
|
|
2099
|
+
// sqlerp() {
|
|
2100
|
+
// Number;
|
|
2101
|
+
// }
|
|
2102
|
+
// Adds two quat's
|
|
2103
|
+
add(a) {
|
|
2104
|
+
add(this, this, a);
|
|
2105
|
+
return this.check();
|
|
2106
|
+
}
|
|
2107
|
+
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
2108
|
+
// Any existing W component will be ignored.
|
|
2109
|
+
calculateW() {
|
|
2110
|
+
calculateW(this, this);
|
|
2111
|
+
return this.check();
|
|
2112
|
+
}
|
|
2113
|
+
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
2114
|
+
// this function is faster than quat_invert and produces the same result.
|
|
2115
|
+
conjugate() {
|
|
2116
|
+
conjugate(this, this);
|
|
2117
|
+
return this.check();
|
|
2118
|
+
}
|
|
2119
|
+
// Calculates the inverse of a quat
|
|
2120
|
+
invert() {
|
|
2121
|
+
invert(this, this);
|
|
2122
|
+
return this.check();
|
|
2123
|
+
}
|
|
2124
|
+
// Performs a linear interpolation between two quat's
|
|
2125
|
+
lerp(a, b, t) {
|
|
2126
|
+
if (t === undefined) {
|
|
2127
|
+
return this.lerp(this, a, b);
|
|
2128
|
+
}
|
|
2129
|
+
lerp(this, a, b, t);
|
|
2130
|
+
return this.check();
|
|
2131
|
+
}
|
|
2132
|
+
// Multiplies two quat's
|
|
2133
|
+
multiplyRight(a) {
|
|
2134
|
+
multiply(this, this, a);
|
|
2135
|
+
return this.check();
|
|
2136
|
+
}
|
|
2137
|
+
multiplyLeft(a) {
|
|
2138
|
+
multiply(this, a, this);
|
|
2139
|
+
return this.check();
|
|
2140
|
+
}
|
|
2141
|
+
// Normalize a quat
|
|
2142
|
+
normalize() {
|
|
2143
|
+
// Handle 0 case
|
|
2144
|
+
const length = this.len();
|
|
2145
|
+
const l = length > 0 ? 1 / length : 0;
|
|
2146
|
+
this[0] = this[0] * l;
|
|
2147
|
+
this[1] = this[1] * l;
|
|
2148
|
+
this[2] = this[2] * l;
|
|
2149
|
+
this[3] = this[3] * l;
|
|
2150
|
+
// Set to [0, 0, 0, 1] if length is 0
|
|
2151
|
+
if (length === 0) {
|
|
2152
|
+
this[3] = 1;
|
|
2153
|
+
}
|
|
2154
|
+
return this.check();
|
|
2155
|
+
}
|
|
2156
|
+
// Rotates a quaternion by the given angle about the X axis
|
|
2157
|
+
rotateX(rad) {
|
|
2158
|
+
rotateX(this, this, rad);
|
|
2159
|
+
return this.check();
|
|
2160
|
+
}
|
|
2161
|
+
// Rotates a quaternion by the given angle about the Y axis
|
|
2162
|
+
rotateY(rad) {
|
|
2163
|
+
rotateY(this, this, rad);
|
|
2164
|
+
return this.check();
|
|
2165
|
+
}
|
|
2166
|
+
// Rotates a quaternion by the given angle about the Z axis
|
|
2167
|
+
rotateZ(rad) {
|
|
2168
|
+
rotateZ(this, this, rad);
|
|
2169
|
+
return this.check();
|
|
2170
|
+
}
|
|
2171
|
+
// Scales a quat by a scalar number
|
|
2172
|
+
scale(b) {
|
|
2173
|
+
scale(this, this, b);
|
|
2174
|
+
return this.check();
|
|
2175
|
+
}
|
|
2176
|
+
// Performs a spherical linear interpolation between two quat
|
|
2177
|
+
slerp(arg0, arg1, arg2) {
|
|
2178
|
+
let start;
|
|
2179
|
+
let target;
|
|
2180
|
+
let ratio;
|
|
2181
|
+
// eslint-disable-next-line prefer-rest-params
|
|
2182
|
+
switch (arguments.length) {
|
|
2183
|
+
case 1: // Deprecated signature ({start, target, ratio})
|
|
2184
|
+
// eslint-disable-next-line prefer-rest-params
|
|
2185
|
+
({
|
|
2186
|
+
start = IDENTITY_QUATERNION,
|
|
2187
|
+
target,
|
|
2188
|
+
ratio
|
|
2189
|
+
} = arg0);
|
|
2190
|
+
break;
|
|
2191
|
+
case 2: // THREE.js compatibility signature (target, ration)
|
|
2192
|
+
start = this; // eslint-disable-line
|
|
2193
|
+
target = arg0;
|
|
2194
|
+
ratio = arg1;
|
|
2195
|
+
break;
|
|
2196
|
+
default:
|
|
2197
|
+
// Default signature: (start, target, ratio)
|
|
2198
|
+
start = arg0;
|
|
2199
|
+
target = arg1;
|
|
2200
|
+
ratio = arg2;
|
|
2201
|
+
}
|
|
2202
|
+
slerp(this, start, target, ratio);
|
|
2203
|
+
return this.check();
|
|
2204
|
+
}
|
|
2205
|
+
transformVector4(vector, result = new Vector4()) {
|
|
2206
|
+
transformQuat(result, vector, this);
|
|
2207
|
+
return checkVector(result, 4);
|
|
2208
|
+
}
|
|
2209
|
+
// THREE.js Math API compatibility
|
|
2210
|
+
lengthSq() {
|
|
2211
|
+
return this.lengthSquared();
|
|
2212
|
+
}
|
|
2213
|
+
setFromAxisAngle(axis, rad) {
|
|
2214
|
+
return this.setAxisAngle(axis, rad);
|
|
2215
|
+
}
|
|
2216
|
+
premultiply(a) {
|
|
2217
|
+
return this.multiplyLeft(a);
|
|
2218
|
+
}
|
|
2219
|
+
multiply(a) {
|
|
2220
|
+
return this.multiplyRight(a);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
// math.gl
|
|
2225
|
+
// Internal constants
|
|
2226
|
+
const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
|
|
2227
|
+
const ALMOST_ONE = 0.99999;
|
|
2228
|
+
// eslint-disable-next-line no-shadow
|
|
2229
|
+
var RotationOrder;
|
|
2230
|
+
(function (RotationOrder) {
|
|
2231
|
+
RotationOrder[RotationOrder["ZYX"] = 0] = "ZYX";
|
|
2232
|
+
RotationOrder[RotationOrder["YXZ"] = 1] = "YXZ";
|
|
2233
|
+
RotationOrder[RotationOrder["XZY"] = 2] = "XZY";
|
|
2234
|
+
RotationOrder[RotationOrder["ZXY"] = 3] = "ZXY";
|
|
2235
|
+
RotationOrder[RotationOrder["YZX"] = 4] = "YZX";
|
|
2236
|
+
RotationOrder[RotationOrder["XYZ"] = 5] = "XYZ";
|
|
2237
|
+
})(RotationOrder || (RotationOrder = {}));
|
|
2238
|
+
class Euler extends MathArray {
|
|
2239
|
+
// Constants
|
|
2240
|
+
static get ZYX() {
|
|
2241
|
+
return RotationOrder.ZYX;
|
|
2242
|
+
}
|
|
2243
|
+
static get YXZ() {
|
|
2244
|
+
return RotationOrder.YXZ;
|
|
2245
|
+
}
|
|
2246
|
+
static get XZY() {
|
|
2247
|
+
return RotationOrder.XZY;
|
|
2248
|
+
}
|
|
2249
|
+
static get ZXY() {
|
|
2250
|
+
return RotationOrder.ZXY;
|
|
2251
|
+
}
|
|
2252
|
+
static get YZX() {
|
|
2253
|
+
return RotationOrder.YZX;
|
|
2254
|
+
}
|
|
2255
|
+
static get XYZ() {
|
|
2256
|
+
return RotationOrder.XYZ;
|
|
2257
|
+
}
|
|
2258
|
+
static get RollPitchYaw() {
|
|
2259
|
+
return RotationOrder.ZYX;
|
|
2260
|
+
}
|
|
2261
|
+
static get DefaultOrder() {
|
|
2262
|
+
return RotationOrder.ZYX;
|
|
2263
|
+
}
|
|
2264
|
+
static get RotationOrders() {
|
|
2265
|
+
return RotationOrder;
|
|
2266
|
+
}
|
|
2267
|
+
static rotationOrder(order) {
|
|
2268
|
+
return RotationOrder[order];
|
|
2269
|
+
}
|
|
2270
|
+
get ELEMENTS() {
|
|
2271
|
+
return 4;
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* @class
|
|
2275
|
+
* @param {Number | Number[]} x
|
|
2276
|
+
* @param {Number=} [y]
|
|
2277
|
+
* @param {Number=} [z]
|
|
2278
|
+
* @param {Number=} [order]
|
|
2279
|
+
*/
|
|
2280
|
+
constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
|
|
2281
|
+
// PERF NOTE: initialize elements as double precision numbers
|
|
2282
|
+
super(-0, -0, -0, -0);
|
|
2283
|
+
// eslint-disable-next-line prefer-rest-params
|
|
2284
|
+
if (arguments.length > 0 && Array.isArray(arguments[0])) {
|
|
2285
|
+
// @ts-expect-error
|
|
2286
|
+
// eslint-disable-next-line prefer-rest-params
|
|
2287
|
+
this.fromVector3(...arguments);
|
|
2288
|
+
}
|
|
2289
|
+
else {
|
|
2290
|
+
this.set(x, y, z, order);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
fromQuaternion(quaternion) {
|
|
2294
|
+
const [x, y, z, w] = quaternion;
|
|
2295
|
+
const ysqr = y * y;
|
|
2296
|
+
const t0 = -2 * (ysqr + z * z) + 1;
|
|
2297
|
+
const t1 = +2 * (x * y + w * z);
|
|
2298
|
+
let t2 = -2 * (x * z - w * y);
|
|
2299
|
+
const t3 = +2 * (y * z + w * x);
|
|
2300
|
+
const t4 = -2 * (x * x + ysqr) + 1;
|
|
2301
|
+
t2 = t2 > 1 ? 1 : t2;
|
|
2302
|
+
t2 = t2 < -1 ? -1 : t2;
|
|
2303
|
+
const roll = Math.atan2(t3, t4);
|
|
2304
|
+
const pitch = Math.asin(t2);
|
|
2305
|
+
const yaw = Math.atan2(t1, t0);
|
|
2306
|
+
return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
2307
|
+
}
|
|
2308
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2309
|
+
fromObject(object) {
|
|
2310
|
+
throw new Error('not implemented');
|
|
2311
|
+
// return this.set(object.x, object.y, object.z, object.order);
|
|
2312
|
+
}
|
|
2313
|
+
// fromQuaternion(q, order) {
|
|
2314
|
+
// this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2315
|
+
// return this.check();
|
|
2316
|
+
// }
|
|
2317
|
+
// If copied array does contain fourth element, preserves currently set order
|
|
2318
|
+
copy(array) {
|
|
2319
|
+
this[0] = array[0];
|
|
2320
|
+
this[1] = array[1];
|
|
2321
|
+
this[2] = array[2];
|
|
2322
|
+
// @ts-expect-error
|
|
2323
|
+
this[3] = Number.isFinite(array[3]) || this.order;
|
|
2324
|
+
return this.check();
|
|
2325
|
+
}
|
|
2326
|
+
// Sets the three angles, and optionally sets the rotation order
|
|
2327
|
+
// If order is not specified, preserves currently set order
|
|
2328
|
+
set(x = 0, y = 0, z = 0, order) {
|
|
2329
|
+
this[0] = x;
|
|
2330
|
+
this[1] = y;
|
|
2331
|
+
this[2] = z;
|
|
2332
|
+
this[3] = Number.isFinite(order) ? order : this[3];
|
|
2333
|
+
return this.check();
|
|
2334
|
+
}
|
|
2335
|
+
validate() {
|
|
2336
|
+
return (validateOrder(this[3]) &&
|
|
2337
|
+
Number.isFinite(this[0]) &&
|
|
2338
|
+
Number.isFinite(this[1]) &&
|
|
2339
|
+
Number.isFinite(this[2]));
|
|
2340
|
+
}
|
|
2341
|
+
// Does not copy the orientation element
|
|
2342
|
+
toArray(array = [], offset = 0) {
|
|
2343
|
+
array[offset] = this[0];
|
|
2344
|
+
array[offset + 1] = this[1];
|
|
2345
|
+
array[offset + 2] = this[2];
|
|
2346
|
+
return array;
|
|
2347
|
+
}
|
|
2348
|
+
// Copies the orientation element
|
|
2349
|
+
toArray4(array = [], offset = 0) {
|
|
2350
|
+
array[offset] = this[0];
|
|
2351
|
+
array[offset + 1] = this[1];
|
|
2352
|
+
array[offset + 2] = this[2];
|
|
2353
|
+
array[offset + 3] = this[3];
|
|
2354
|
+
return array;
|
|
2355
|
+
}
|
|
2356
|
+
toVector3(result = [-0, -0, -0]) {
|
|
2357
|
+
result[0] = this[0];
|
|
2358
|
+
result[1] = this[1];
|
|
2359
|
+
result[2] = this[2];
|
|
2360
|
+
return result;
|
|
2361
|
+
}
|
|
2362
|
+
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
2363
|
+
// x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
|
|
2364
|
+
get x() {
|
|
2365
|
+
return this[0];
|
|
2366
|
+
}
|
|
2367
|
+
set x(value) {
|
|
2368
|
+
this[0] = checkNumber(value);
|
|
2369
|
+
}
|
|
2370
|
+
get y() {
|
|
2371
|
+
return this[1];
|
|
2372
|
+
}
|
|
2373
|
+
set y(value) {
|
|
2374
|
+
this[1] = checkNumber(value);
|
|
2375
|
+
}
|
|
2376
|
+
get z() {
|
|
2377
|
+
return this[2];
|
|
2378
|
+
}
|
|
2379
|
+
set z(value) {
|
|
2380
|
+
this[2] = checkNumber(value);
|
|
2381
|
+
}
|
|
2382
|
+
// alpha, beta, gamma angle notation
|
|
2383
|
+
get alpha() {
|
|
2384
|
+
return this[0];
|
|
2385
|
+
}
|
|
2386
|
+
set alpha(value) {
|
|
2387
|
+
this[0] = checkNumber(value);
|
|
2388
|
+
}
|
|
2389
|
+
get beta() {
|
|
2390
|
+
return this[1];
|
|
2391
|
+
}
|
|
2392
|
+
set beta(value) {
|
|
2393
|
+
this[1] = checkNumber(value);
|
|
2394
|
+
}
|
|
2395
|
+
get gamma() {
|
|
2396
|
+
return this[2];
|
|
2397
|
+
}
|
|
2398
|
+
set gamma(value) {
|
|
2399
|
+
this[2] = checkNumber(value);
|
|
2400
|
+
}
|
|
2401
|
+
// phi, theta, psi angle notation
|
|
2402
|
+
get phi() {
|
|
2403
|
+
return this[0];
|
|
2404
|
+
}
|
|
2405
|
+
set phi(value) {
|
|
2406
|
+
this[0] = checkNumber(value);
|
|
2407
|
+
}
|
|
2408
|
+
get theta() {
|
|
2409
|
+
return this[1];
|
|
2410
|
+
}
|
|
2411
|
+
set theta(value) {
|
|
2412
|
+
this[1] = checkNumber(value);
|
|
2413
|
+
}
|
|
2414
|
+
get psi() {
|
|
2415
|
+
return this[2];
|
|
2416
|
+
}
|
|
2417
|
+
set psi(value) {
|
|
2418
|
+
this[2] = checkNumber(value);
|
|
2419
|
+
}
|
|
2420
|
+
// roll, pitch, yaw angle notation
|
|
2421
|
+
get roll() {
|
|
2422
|
+
return this[0];
|
|
2423
|
+
}
|
|
2424
|
+
set roll(value) {
|
|
2425
|
+
this[0] = checkNumber(value);
|
|
2426
|
+
}
|
|
2427
|
+
get pitch() {
|
|
2428
|
+
return this[1];
|
|
2429
|
+
}
|
|
2430
|
+
set pitch(value) {
|
|
2431
|
+
this[1] = checkNumber(value);
|
|
2432
|
+
}
|
|
2433
|
+
get yaw() {
|
|
2434
|
+
return this[2];
|
|
2435
|
+
}
|
|
2436
|
+
set yaw(value) {
|
|
2437
|
+
this[2] = checkNumber(value);
|
|
2438
|
+
}
|
|
2439
|
+
// rotation order, in all three angle notations
|
|
2440
|
+
get order() {
|
|
2441
|
+
return this[3];
|
|
2442
|
+
}
|
|
2443
|
+
set order(value) {
|
|
2444
|
+
this[3] = checkOrder(value);
|
|
2445
|
+
}
|
|
2446
|
+
// Constructors
|
|
2447
|
+
fromVector3(v, order) {
|
|
2448
|
+
return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
|
|
2449
|
+
}
|
|
2450
|
+
// TODO - with and without 4th element
|
|
2451
|
+
fromArray(array, offset = 0) {
|
|
2452
|
+
this[0] = array[0 + offset];
|
|
2453
|
+
this[1] = array[1 + offset];
|
|
2454
|
+
this[2] = array[2 + offset];
|
|
2455
|
+
if (array[3] !== undefined) {
|
|
2456
|
+
this[3] = array[3];
|
|
2457
|
+
}
|
|
2458
|
+
return this.check();
|
|
2459
|
+
}
|
|
2460
|
+
// Common ZYX rotation order
|
|
2461
|
+
fromRollPitchYaw(roll, pitch, yaw) {
|
|
2462
|
+
return this.set(roll, pitch, yaw, RotationOrder.ZYX);
|
|
2463
|
+
}
|
|
2464
|
+
fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
2465
|
+
this._fromRotationMatrix(m, order);
|
|
2466
|
+
return this.check();
|
|
2467
|
+
}
|
|
2468
|
+
// ACCESSORS
|
|
2469
|
+
getRotationMatrix(m) {
|
|
2470
|
+
return this._getRotationMatrix(m);
|
|
2471
|
+
}
|
|
2472
|
+
// TODO - move to Quaternion
|
|
2473
|
+
getQuaternion() {
|
|
2474
|
+
const q = new Quaternion();
|
|
2475
|
+
switch (this[3]) {
|
|
2476
|
+
case RotationOrder.XYZ:
|
|
2477
|
+
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
2478
|
+
case RotationOrder.YXZ:
|
|
2479
|
+
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
|
|
2480
|
+
case RotationOrder.ZXY:
|
|
2481
|
+
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
|
|
2482
|
+
case RotationOrder.ZYX:
|
|
2483
|
+
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
|
|
2484
|
+
case RotationOrder.YZX:
|
|
2485
|
+
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
|
|
2486
|
+
case RotationOrder.XZY:
|
|
2487
|
+
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
|
|
2488
|
+
default:
|
|
2489
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
// INTERNAL METHODS
|
|
2493
|
+
// Conversion from Euler to rotation matrix and from matrix to Euler
|
|
2494
|
+
// Adapted from three.js under MIT license
|
|
2495
|
+
// // WARNING: this discards revolution information -bhouston
|
|
2496
|
+
// reorder(newOrder) {
|
|
2497
|
+
// const q = new Quaternion().setFromEuler(this);
|
|
2498
|
+
// return this.setFromQuaternion(q, newOrder);
|
|
2499
|
+
/* eslint-disable complexity, max-statements, one-var */
|
|
2500
|
+
_fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
2501
|
+
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
2502
|
+
const m11 = m[0], m12 = m[4], m13 = m[8];
|
|
2503
|
+
const m21 = m[1], m22 = m[5], m23 = m[9];
|
|
2504
|
+
const m31 = m[2], m32 = m[6], m33 = m[10];
|
|
2505
|
+
order = order || this[3];
|
|
2506
|
+
switch (order) {
|
|
2507
|
+
case Euler.XYZ:
|
|
2508
|
+
this[1] = Math.asin(clamp(m13, -1, 1));
|
|
2509
|
+
if (Math.abs(m13) < ALMOST_ONE) {
|
|
2510
|
+
this[0] = Math.atan2(-m23, m33);
|
|
2511
|
+
this[2] = Math.atan2(-m12, m11);
|
|
2512
|
+
}
|
|
2513
|
+
else {
|
|
2514
|
+
this[0] = Math.atan2(m32, m22);
|
|
2515
|
+
this[2] = 0;
|
|
2516
|
+
}
|
|
2517
|
+
break;
|
|
2518
|
+
case Euler.YXZ:
|
|
2519
|
+
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
2520
|
+
if (Math.abs(m23) < ALMOST_ONE) {
|
|
2521
|
+
this[1] = Math.atan2(m13, m33);
|
|
2522
|
+
this[2] = Math.atan2(m21, m22);
|
|
2523
|
+
}
|
|
2524
|
+
else {
|
|
2525
|
+
this[1] = Math.atan2(-m31, m11);
|
|
2526
|
+
this[2] = 0;
|
|
2527
|
+
}
|
|
2528
|
+
break;
|
|
2529
|
+
case Euler.ZXY:
|
|
2530
|
+
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
2531
|
+
if (Math.abs(m32) < ALMOST_ONE) {
|
|
2532
|
+
this[1] = Math.atan2(-m31, m33);
|
|
2533
|
+
this[2] = Math.atan2(-m12, m22);
|
|
2534
|
+
}
|
|
2535
|
+
else {
|
|
2536
|
+
this[1] = 0;
|
|
2537
|
+
this[2] = Math.atan2(m21, m11);
|
|
2538
|
+
}
|
|
2539
|
+
break;
|
|
2540
|
+
case Euler.ZYX:
|
|
2541
|
+
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
2542
|
+
if (Math.abs(m31) < ALMOST_ONE) {
|
|
2543
|
+
this[0] = Math.atan2(m32, m33);
|
|
2544
|
+
this[2] = Math.atan2(m21, m11);
|
|
2545
|
+
}
|
|
2546
|
+
else {
|
|
2547
|
+
this[0] = 0;
|
|
2548
|
+
this[2] = Math.atan2(-m12, m22);
|
|
2549
|
+
}
|
|
2550
|
+
break;
|
|
2551
|
+
case Euler.YZX:
|
|
2552
|
+
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
2553
|
+
if (Math.abs(m21) < ALMOST_ONE) {
|
|
2554
|
+
this[0] = Math.atan2(-m23, m22);
|
|
2555
|
+
this[1] = Math.atan2(-m31, m11);
|
|
2556
|
+
}
|
|
2557
|
+
else {
|
|
2558
|
+
this[0] = 0;
|
|
2559
|
+
this[1] = Math.atan2(m13, m33);
|
|
2560
|
+
}
|
|
2561
|
+
break;
|
|
2562
|
+
case Euler.XZY:
|
|
2563
|
+
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
2564
|
+
if (Math.abs(m12) < ALMOST_ONE) {
|
|
2565
|
+
this[0] = Math.atan2(m32, m22);
|
|
2566
|
+
this[1] = Math.atan2(m13, m11);
|
|
2567
|
+
}
|
|
2568
|
+
else {
|
|
2569
|
+
this[0] = Math.atan2(-m23, m33);
|
|
2570
|
+
this[1] = 0;
|
|
2571
|
+
}
|
|
2572
|
+
break;
|
|
2573
|
+
default:
|
|
2574
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
2575
|
+
}
|
|
2576
|
+
this[3] = order;
|
|
2577
|
+
return this;
|
|
2578
|
+
}
|
|
2579
|
+
_getRotationMatrix(result) {
|
|
2580
|
+
const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2581
|
+
const x = this.x, y = this.y, z = this.z;
|
|
2582
|
+
const a = Math.cos(x);
|
|
2583
|
+
const c = Math.cos(y);
|
|
2584
|
+
const e = Math.cos(z);
|
|
2585
|
+
const b = Math.sin(x);
|
|
2586
|
+
const d = Math.sin(y);
|
|
2587
|
+
const f = Math.sin(z);
|
|
2588
|
+
switch (this[3]) {
|
|
2589
|
+
case Euler.XYZ: {
|
|
2590
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
2591
|
+
te[0] = c * e;
|
|
2592
|
+
te[4] = -c * f;
|
|
2593
|
+
te[8] = d;
|
|
2594
|
+
te[1] = af + be * d;
|
|
2595
|
+
te[5] = ae - bf * d;
|
|
2596
|
+
te[9] = -b * c;
|
|
2597
|
+
te[2] = bf - ae * d;
|
|
2598
|
+
te[6] = be + af * d;
|
|
2599
|
+
te[10] = a * c;
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
case Euler.YXZ: {
|
|
2603
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
2604
|
+
te[0] = ce + df * b;
|
|
2605
|
+
te[4] = de * b - cf;
|
|
2606
|
+
te[8] = a * d;
|
|
2607
|
+
te[1] = a * f;
|
|
2608
|
+
te[5] = a * e;
|
|
2609
|
+
te[9] = -b;
|
|
2610
|
+
te[2] = cf * b - de;
|
|
2611
|
+
te[6] = df + ce * b;
|
|
2612
|
+
te[10] = a * c;
|
|
2613
|
+
break;
|
|
2614
|
+
}
|
|
2615
|
+
case Euler.ZXY: {
|
|
2616
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
2617
|
+
te[0] = ce - df * b;
|
|
2618
|
+
te[4] = -a * f;
|
|
2619
|
+
te[8] = de + cf * b;
|
|
2620
|
+
te[1] = cf + de * b;
|
|
2621
|
+
te[5] = a * e;
|
|
2622
|
+
te[9] = df - ce * b;
|
|
2623
|
+
te[2] = -a * d;
|
|
2624
|
+
te[6] = b;
|
|
2625
|
+
te[10] = a * c;
|
|
2626
|
+
break;
|
|
2627
|
+
}
|
|
2628
|
+
case Euler.ZYX: {
|
|
2629
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
2630
|
+
te[0] = c * e;
|
|
2631
|
+
te[4] = be * d - af;
|
|
2632
|
+
te[8] = ae * d + bf;
|
|
2633
|
+
te[1] = c * f;
|
|
2634
|
+
te[5] = bf * d + ae;
|
|
2635
|
+
te[9] = af * d - be;
|
|
2636
|
+
te[2] = -d;
|
|
2637
|
+
te[6] = b * c;
|
|
2638
|
+
te[10] = a * c;
|
|
2639
|
+
break;
|
|
2640
|
+
}
|
|
2641
|
+
case Euler.YZX: {
|
|
2642
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
2643
|
+
te[0] = c * e;
|
|
2644
|
+
te[4] = bd - ac * f;
|
|
2645
|
+
te[8] = bc * f + ad;
|
|
2646
|
+
te[1] = f;
|
|
2647
|
+
te[5] = a * e;
|
|
2648
|
+
te[9] = -b * e;
|
|
2649
|
+
te[2] = -d * e;
|
|
2650
|
+
te[6] = ad * f + bc;
|
|
2651
|
+
te[10] = ac - bd * f;
|
|
2652
|
+
break;
|
|
2653
|
+
}
|
|
2654
|
+
case Euler.XZY: {
|
|
2655
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
2656
|
+
te[0] = c * e;
|
|
2657
|
+
te[4] = -f;
|
|
2658
|
+
te[8] = d * e;
|
|
2659
|
+
te[1] = ac * f + bd;
|
|
2660
|
+
te[5] = a * e;
|
|
2661
|
+
te[9] = ad * f - bc;
|
|
2662
|
+
te[2] = bc * f - ad;
|
|
2663
|
+
te[6] = b * e;
|
|
2664
|
+
te[10] = bd * f + ac;
|
|
2665
|
+
break;
|
|
2666
|
+
}
|
|
2667
|
+
default:
|
|
2668
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
2669
|
+
}
|
|
2670
|
+
// last column
|
|
2671
|
+
te[3] = 0;
|
|
2672
|
+
te[7] = 0;
|
|
2673
|
+
te[11] = 0;
|
|
2674
|
+
// bottom row
|
|
2675
|
+
te[12] = 0;
|
|
2676
|
+
te[13] = 0;
|
|
2677
|
+
te[14] = 0;
|
|
2678
|
+
te[15] = 1;
|
|
2679
|
+
return te;
|
|
2680
|
+
}
|
|
2681
|
+
toQuaternion() {
|
|
2682
|
+
// Abbreviations for the various angular functions
|
|
2683
|
+
const cy = Math.cos(this.yaw * 0.5);
|
|
2684
|
+
const sy = Math.sin(this.yaw * 0.5);
|
|
2685
|
+
const cr = Math.cos(this.roll * 0.5);
|
|
2686
|
+
const sr = Math.sin(this.roll * 0.5);
|
|
2687
|
+
const cp = Math.cos(this.pitch * 0.5);
|
|
2688
|
+
const sp = Math.sin(this.pitch * 0.5);
|
|
2689
|
+
const w = cy * cr * cp + sy * sr * sp;
|
|
2690
|
+
const x = cy * sr * cp - sy * cr * sp;
|
|
2691
|
+
const y = cy * cr * sp + sy * sr * cp;
|
|
2692
|
+
const z = sy * cr * cp - cy * sr * sp;
|
|
2693
|
+
return new Quaternion(x, y, z, w);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
// HELPER FUNCTIONS
|
|
2697
|
+
function validateOrder(value) {
|
|
2698
|
+
return value >= 0 && value < 6;
|
|
2699
|
+
}
|
|
2700
|
+
function checkOrder(value) {
|
|
2701
|
+
if (value < 0 && value >= 6) {
|
|
2702
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
2703
|
+
}
|
|
2704
|
+
return value;
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
/**
|
|
2708
|
+
* 变换模块,提供变换相关的类和功能
|
|
2709
|
+
* 用于表示对象的位置、旋转和缩放信息
|
|
2710
|
+
*/
|
|
2711
|
+
/**
|
|
2712
|
+
* 变换基类,用于表示对象的位置、旋转和缩放
|
|
2713
|
+
*/
|
|
2714
|
+
class OTransform {
|
|
2715
|
+
/**
|
|
2716
|
+
* 构造函数
|
|
2717
|
+
* @param position 位置向量
|
|
2718
|
+
* @param rotation 旋转欧拉角
|
|
2719
|
+
* @param scale 缩放向量
|
|
2720
|
+
*/
|
|
2721
|
+
constructor(position, rotation, scale) {
|
|
2722
|
+
this.position = position;
|
|
2723
|
+
this.rotation = rotation;
|
|
2724
|
+
this.scale = scale;
|
|
2725
|
+
}
|
|
2726
|
+
/**
|
|
2727
|
+
* 创建默认的变换对象
|
|
2728
|
+
* @param params 可选参数对象
|
|
2729
|
+
* @param params.position 位置向量,默认值为新的Vector3实例
|
|
2730
|
+
* @param params.rotation 旋转欧拉角,默认值为新的Euler实例
|
|
2731
|
+
* @param params.scale 缩放向量,默认值为Vector3(1, 1, 1)
|
|
2732
|
+
* @returns 默认的变换对象
|
|
2733
|
+
*/
|
|
2734
|
+
static default(params) {
|
|
2735
|
+
return new OTransform(params?.position || new Vector3(), params?.rotation || new Euler(), params?.scale || new Vector3(1, 1, 1));
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* 变换类,继承自OTransform,用于表示带有标识符的变换对象
|
|
2740
|
+
*/
|
|
2741
|
+
class Transform extends OTransform {
|
|
2742
|
+
/**
|
|
2743
|
+
* 构造函数
|
|
2744
|
+
|
|
2745
|
+
* @param position 位置向量
|
|
2746
|
+
* @param rotation 旋转欧拉角
|
|
2747
|
+
* @param scale 缩放向量
|
|
2748
|
+
*/
|
|
2749
|
+
constructor(position, rotation, scale) {
|
|
2750
|
+
super(position, rotation, scale);
|
|
2751
|
+
}
|
|
2752
|
+
toRPCJSON() {
|
|
2753
|
+
return {
|
|
2754
|
+
Location: {
|
|
2755
|
+
X: this.position.x,
|
|
2756
|
+
Y: this.position.y,
|
|
2757
|
+
Z: this.position.z
|
|
2758
|
+
},
|
|
2759
|
+
Rotation: {
|
|
2760
|
+
Pitch: this.rotation.pitch,
|
|
2761
|
+
Yaw: this.rotation.yaw,
|
|
2762
|
+
Roll: this.rotation.roll
|
|
2763
|
+
},
|
|
2764
|
+
Scale: {
|
|
2765
|
+
X: this.scale.x,
|
|
2766
|
+
Y: this.scale.y,
|
|
2767
|
+
Z: this.scale.z
|
|
2768
|
+
}
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* 创建默认的变换对象
|
|
2773
|
+
* @param handle 变换对象的唯一标识符
|
|
2774
|
+
* @returns 默认的变换对象
|
|
2775
|
+
*/
|
|
2776
|
+
static default() {
|
|
2777
|
+
return new Transform(new Vector3(), new Euler(), new Vector3(1, 1, 1));
|
|
2778
|
+
}
|
|
2779
|
+
static fromRPCObject(obj) {
|
|
2780
|
+
return new Transform(obj.Location
|
|
2781
|
+
? new Vector3(obj.Location.X, obj.Location.Y, obj.Location.Z)
|
|
2782
|
+
: new Vector3(), obj.Rotation
|
|
2783
|
+
? new Euler(obj.Rotation.Pitch, obj.Rotation.Yaw, obj.Rotation.Roll)
|
|
2784
|
+
: new Euler(), obj.Scale
|
|
2785
|
+
? new Vector3(obj.Scale.X, obj.Scale.Y, obj.Scale.Z)
|
|
2786
|
+
: new Vector3(1, 1, 1));
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
/**
|
|
2791
|
+
* 节点基类模块,提供节点树的基础实现
|
|
2792
|
+
* 用于表示场景中的对象,支持父子关系、变换和数据存储
|
|
2793
|
+
*/
|
|
2794
|
+
/**
|
|
2795
|
+
* 节点基类,用于表示场景中的对象
|
|
2796
|
+
* 支持父子关系、变换、数据存储和节点查找
|
|
2797
|
+
* @template T 节点数据类型
|
|
2798
|
+
*/
|
|
2799
|
+
class Node {
|
|
2800
|
+
/**
|
|
2801
|
+
* 构造函数
|
|
2802
|
+
* @param key 节点唯一标识符
|
|
2803
|
+
* @param data 节点附加数据
|
|
2804
|
+
* @param transform 节点变换信息
|
|
2805
|
+
*/
|
|
2806
|
+
constructor(key, data, transform) {
|
|
2807
|
+
this._children = [];
|
|
2808
|
+
this._key = key;
|
|
2809
|
+
this.isRoot = true;
|
|
2810
|
+
this.data = data;
|
|
2811
|
+
if (transform) {
|
|
2812
|
+
this._transform = new OTransform(new Vector3(), new Euler(), new Vector3(1, 1, 1));
|
|
2813
|
+
}
|
|
2814
|
+
else {
|
|
2815
|
+
this._transform = OTransform.default();
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* 获取节点唯一标识符
|
|
2820
|
+
*/
|
|
2821
|
+
get key() {
|
|
2822
|
+
return this._key;
|
|
2823
|
+
}
|
|
2824
|
+
/**
|
|
2825
|
+
* 获取节点变换信息
|
|
2826
|
+
*/
|
|
2827
|
+
get transform() {
|
|
2828
|
+
return this._transform;
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* 获取子节点列表
|
|
2832
|
+
*/
|
|
2833
|
+
get children() {
|
|
2834
|
+
return this._children;
|
|
2835
|
+
}
|
|
2836
|
+
/**
|
|
2837
|
+
* 添加子节点
|
|
2838
|
+
* @param child 要添加的子节点
|
|
2839
|
+
*/
|
|
2840
|
+
add(child) {
|
|
2841
|
+
// this.children.push(child)
|
|
2842
|
+
child.parent = this;
|
|
2843
|
+
this._children.push(child);
|
|
2844
|
+
child.isRoot = false;
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* 脱离父节点
|
|
2848
|
+
*/
|
|
2849
|
+
detach() {
|
|
2850
|
+
if (this.parent) {
|
|
2851
|
+
this.parent.removeChild(this);
|
|
2852
|
+
}
|
|
2853
|
+
this.isRoot = true;
|
|
2854
|
+
}
|
|
2855
|
+
remove() {
|
|
2856
|
+
if (this.parent) {
|
|
2857
|
+
this.detach();
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* 移除子节点
|
|
2862
|
+
* @param child 要移除的子节点
|
|
2863
|
+
*/
|
|
2864
|
+
removeChild(child) {
|
|
2865
|
+
child.parent = undefined;
|
|
2866
|
+
let index = this._children.findIndex((c) => c !== child);
|
|
2867
|
+
if (index > -1) {
|
|
2868
|
+
this._children.splice(index, 1);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* 根据key查找子节点
|
|
2873
|
+
* @param key 要查找的节点key
|
|
2874
|
+
* @returns 找到的节点或undefined
|
|
2875
|
+
*/
|
|
2876
|
+
findChild(key) {
|
|
2877
|
+
if (this.key === key) {
|
|
2878
|
+
return this;
|
|
2879
|
+
}
|
|
2880
|
+
for (let i = 0; i < this._children.length; i++) {
|
|
2881
|
+
let child = this._children[i];
|
|
2882
|
+
let found = child.findChild(key);
|
|
2883
|
+
if (found) {
|
|
2884
|
+
return found;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* 代理模块,提供深度代理和变动收集功能
|
|
2892
|
+
* 用于跟踪对象的属性变化并在事件循环结束后统一处理
|
|
2893
|
+
*/
|
|
2894
|
+
/**
|
|
2895
|
+
* 收集器类,用于收集对象变动并在事件循环结束后触发回调
|
|
2896
|
+
*/
|
|
2897
|
+
class Collector {
|
|
2898
|
+
/**
|
|
2899
|
+
* 创建收集器实例
|
|
2900
|
+
* @param callback 变动回调函数,在事件循环结束后调用
|
|
2901
|
+
*/
|
|
2902
|
+
constructor(callback) {
|
|
2903
|
+
/**
|
|
2904
|
+
* 收集到的变动列表
|
|
2905
|
+
*/
|
|
2906
|
+
this.changes = [];
|
|
2907
|
+
/**
|
|
2908
|
+
* 标志位,用于确保只有一个 setTimeout 在运行
|
|
2909
|
+
*/
|
|
2910
|
+
this.isTimeoutSet = false;
|
|
2911
|
+
this.callback = callback;
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* 添加变动
|
|
2915
|
+
* @param change 变动对象
|
|
2916
|
+
*/
|
|
2917
|
+
addChange(change) {
|
|
2918
|
+
this.changes.push(change);
|
|
2919
|
+
this.scheduleCallback();
|
|
2920
|
+
}
|
|
2921
|
+
/**
|
|
2922
|
+
* 调度回调函数,确保在事件循环结束后执行
|
|
2923
|
+
*/
|
|
2924
|
+
scheduleCallback() {
|
|
2925
|
+
if (!this.isTimeoutSet) {
|
|
2926
|
+
this.isTimeoutSet = true;
|
|
2927
|
+
// setTimeout(() => {
|
|
2928
|
+
Promise.resolve().then(() => this.triggerCallback());
|
|
2929
|
+
// }, 0);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
/**
|
|
2933
|
+
* 触发回调函数
|
|
2934
|
+
*/
|
|
2935
|
+
triggerCallback() {
|
|
2936
|
+
if (this.changes.length > 0) {
|
|
2937
|
+
this.callback([...this.changes]); // 传递变动的副本
|
|
2938
|
+
this.changes = []; // 清空变动列表
|
|
2939
|
+
}
|
|
2940
|
+
this.isTimeoutSet = false;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
/**
|
|
2944
|
+
* 创建深度代理,递归地为对象及其所有子对象创建 Proxy
|
|
2945
|
+
* @param target 要代理的目标对象
|
|
2946
|
+
* @param handler 自定义处理器
|
|
2947
|
+
* @param collector 变动收集器,用于收集对象变动
|
|
2948
|
+
* @returns 代理后的对象
|
|
2949
|
+
*/
|
|
2950
|
+
function createDeepProxy(target, handler = {}, collector) {
|
|
2951
|
+
// 递归创建 Proxy 的核心函数
|
|
2952
|
+
const proxyHandler = {
|
|
2953
|
+
// 拦截属性读取
|
|
2954
|
+
get(target, prop, receiver) {
|
|
2955
|
+
// 先调用自定义 handler 的 get(如果有)
|
|
2956
|
+
if (handler.get) {
|
|
2957
|
+
handler.get(target, prop, receiver);
|
|
2958
|
+
}
|
|
2959
|
+
// 获取属性值
|
|
2960
|
+
const result = Reflect.get(target, prop, receiver);
|
|
2961
|
+
// 如果读取的属性是对象/数组且不是 null,递归创建 Proxy
|
|
2962
|
+
if (result !== null &&
|
|
2963
|
+
(typeof result === 'object' || Array.isArray(result))) {
|
|
2964
|
+
return createDeepProxy(result, handler, collector);
|
|
2965
|
+
}
|
|
2966
|
+
return result;
|
|
2967
|
+
},
|
|
2968
|
+
// 拦截属性赋值
|
|
2969
|
+
set(target, prop, value, receiver) {
|
|
2970
|
+
// 先调用自定义 handler 的 set(如果有)
|
|
2971
|
+
if (handler.set) {
|
|
2972
|
+
handler.set(target, prop, value, receiver);
|
|
2973
|
+
}
|
|
2974
|
+
// 赋值时,如果新值是对象/数组,也需要代理
|
|
2975
|
+
const newValue = value !== null && (typeof value === 'object' || Array.isArray(value))
|
|
2976
|
+
? createDeepProxy(value, handler, collector)
|
|
2977
|
+
: value;
|
|
2978
|
+
// 如果有收集器,收集变动
|
|
2979
|
+
if (collector) {
|
|
2980
|
+
collector.addChange({
|
|
2981
|
+
target,
|
|
2982
|
+
prop,
|
|
2983
|
+
value: newValue,
|
|
2984
|
+
type: 'set'
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
return Reflect.set(target, prop, newValue, receiver);
|
|
2988
|
+
},
|
|
2989
|
+
// 拦截属性删除
|
|
2990
|
+
deleteProperty(target, prop) {
|
|
2991
|
+
// 先调用自定义 handler 的 deleteProperty(如果有)
|
|
2992
|
+
if (handler.deleteProperty) {
|
|
2993
|
+
handler.deleteProperty(target, prop);
|
|
2994
|
+
}
|
|
2995
|
+
// 如果有收集器,收集变动
|
|
2996
|
+
if (collector) {
|
|
2997
|
+
collector.addChange({
|
|
2998
|
+
target,
|
|
2999
|
+
prop,
|
|
3000
|
+
value: undefined,
|
|
3001
|
+
type: 'delete'
|
|
3002
|
+
});
|
|
3003
|
+
}
|
|
3004
|
+
return Reflect.deleteProperty(target, prop);
|
|
3005
|
+
},
|
|
3006
|
+
// 可选:拦截其他操作(如 has 等)
|
|
3007
|
+
...handler // 合并自定义 handler 的其他拦截器
|
|
3008
|
+
};
|
|
3009
|
+
// 为目标对象创建 Proxy
|
|
3010
|
+
return new Proxy(target, proxyHandler);
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
/**
|
|
3014
|
+
* 资源类型枚举,用于标识不同类型的资源
|
|
3015
|
+
*/
|
|
3016
|
+
var AssetType;
|
|
3017
|
+
(function (AssetType) {
|
|
3018
|
+
/** 其他类型资源 */
|
|
3019
|
+
AssetType["Other"] = "other";
|
|
3020
|
+
/** 地图资源 */
|
|
3021
|
+
AssetType["Map"] = "map";
|
|
3022
|
+
/** 蓝图资源 */
|
|
3023
|
+
AssetType["Blueprint"] = "blueprint";
|
|
3024
|
+
/** 静态网格资源 */
|
|
3025
|
+
AssetType["StaticMesh"] = "static_mesh";
|
|
3026
|
+
/** 骨骼网格资源 */
|
|
3027
|
+
AssetType["SkeletalMesh"] = "skeletal_mesh";
|
|
3028
|
+
})(AssetType || (AssetType = {}));
|
|
3029
|
+
/**
|
|
3030
|
+
* UE RPC 节点类,继承自 Node,用于与 Unreal Engine 通信
|
|
3031
|
+
* 支持变换同步、远程更新和子节点管理
|
|
3032
|
+
*/
|
|
3033
|
+
class UERPCNode extends Node {
|
|
3034
|
+
/**
|
|
3035
|
+
* 构造函数
|
|
3036
|
+
* @param rpc RPC 通信实例
|
|
3037
|
+
* @param key 节点唯一标识符
|
|
3038
|
+
* @param data 节点数据
|
|
3039
|
+
* @param transform 节点变换信息
|
|
3040
|
+
*/
|
|
3041
|
+
constructor(rpc, key, data, transform, tag) {
|
|
3042
|
+
super(key, data);
|
|
3043
|
+
this._rpc = rpc;
|
|
3044
|
+
if (transform) {
|
|
3045
|
+
this._transform = transform;
|
|
3046
|
+
}
|
|
3047
|
+
else {
|
|
3048
|
+
this._transform = Transform.default();
|
|
3049
|
+
}
|
|
3050
|
+
this._remoteUpdateFlag = false;
|
|
3051
|
+
this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
|
|
3052
|
+
this.tag = tag;
|
|
3053
|
+
}
|
|
3054
|
+
/**
|
|
3055
|
+
* 获取变换信息的深度代理,用于跟踪属性变化
|
|
3056
|
+
*/
|
|
3057
|
+
get transform() {
|
|
3058
|
+
return createDeepProxy(this._transform, {}, this._collector);
|
|
3059
|
+
}
|
|
3060
|
+
set transform(transform) {
|
|
3061
|
+
this._transform = transform;
|
|
3062
|
+
this._triggerRemoteUpdate();
|
|
3063
|
+
}
|
|
3064
|
+
/**
|
|
3065
|
+
* 添加子节点
|
|
3066
|
+
* @param child 要添加的子节点
|
|
3067
|
+
* @throws 非根节点添加子节点时抛出错误
|
|
3068
|
+
*/
|
|
3069
|
+
add(child) {
|
|
3070
|
+
// throw new Error("UERPCNode can't add child")
|
|
3071
|
+
if (this.isRoot) {
|
|
3072
|
+
super.add(child);
|
|
3073
|
+
child.world = this.world;
|
|
3074
|
+
}
|
|
3075
|
+
else {
|
|
3076
|
+
throw new Error("UERPCNode can't add child , except root node");
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
__dangerousRawAdd(child) {
|
|
3080
|
+
super.add(child);
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
* 脱离父节点
|
|
3084
|
+
*/
|
|
3085
|
+
async detach() {
|
|
3086
|
+
super.detach();
|
|
3087
|
+
}
|
|
3088
|
+
async remove() {
|
|
3089
|
+
super.remove();
|
|
3090
|
+
await this._rpc.destroyActorByHandle(this.key);
|
|
3091
|
+
}
|
|
3092
|
+
/**
|
|
3093
|
+
* 移除子节点
|
|
3094
|
+
* @param child 要移除的子节点
|
|
3095
|
+
*/
|
|
3096
|
+
async removeChild(child) {
|
|
3097
|
+
super.removeChild(child);
|
|
3098
|
+
await this._rpc.destroyActorByHandle(this.key);
|
|
3099
|
+
}
|
|
3100
|
+
_triggerRemoteUpdate() {
|
|
3101
|
+
if (!this._remoteUpdateFlag) {
|
|
3102
|
+
this._remoteUpdateFlag = true;
|
|
3103
|
+
Promise.resolve().then(() => this._remoteUpdate());
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
/**
|
|
3107
|
+
* 远程更新节点变换到 UE
|
|
3108
|
+
* 向 UE 发送变换数据,更新 Actor 的位置、旋转和缩放
|
|
3109
|
+
*/
|
|
3110
|
+
_remoteUpdate() {
|
|
3111
|
+
this._rpc.setActorTransformByHandle(this.key, this.transform.toRPCJSON());
|
|
3112
|
+
this._remoteUpdateFlag = false;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
class Tool {
|
|
3117
|
+
constructor(rpc) {
|
|
3118
|
+
this._rpc = rpc;
|
|
3119
|
+
}
|
|
3120
|
+
excute(params) {
|
|
3121
|
+
throw new Error('Method not implemented.');
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
const maxView4K = (width, height) => {
|
|
3126
|
+
const maxWidth = 3840;
|
|
3127
|
+
const maxHeight = 2160;
|
|
3128
|
+
// 如果宽或高任一超过4K限制
|
|
3129
|
+
if (width > maxWidth || height > maxHeight) {
|
|
3130
|
+
const ratio = Math.min(maxWidth / width, maxHeight / height);
|
|
3131
|
+
return {
|
|
3132
|
+
width: Math.ceil(width * ratio),
|
|
3133
|
+
height: Math.ceil(height * ratio)
|
|
3134
|
+
};
|
|
3135
|
+
}
|
|
3136
|
+
// 未超过限制,返回原尺寸
|
|
3137
|
+
return { width, height };
|
|
3138
|
+
};
|
|
3139
|
+
class MatchView extends Tool {
|
|
3140
|
+
constructor(rpc) {
|
|
3141
|
+
super(rpc);
|
|
3142
|
+
}
|
|
3143
|
+
excute() {
|
|
3144
|
+
this._rpc.emitCommand({
|
|
3145
|
+
Command: 'MatchView',
|
|
3146
|
+
'Resolution.Width': maxView4K(window.innerWidth, window.innerHeight)
|
|
3147
|
+
.width,
|
|
3148
|
+
'Resolution.Height': maxView4K(window.innerWidth, window.innerHeight)
|
|
3149
|
+
.height
|
|
3150
|
+
});
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
/**
|
|
3155
|
+
* 天气类型枚举,定义了不同的天气状态
|
|
3156
|
+
*/
|
|
3157
|
+
var WeatherType;
|
|
3158
|
+
(function (WeatherType) {
|
|
3159
|
+
/** 晴天 */
|
|
3160
|
+
WeatherType["SUNNY"] = "Sunny";
|
|
3161
|
+
/** 雾天 */
|
|
3162
|
+
WeatherType["Foggy"] = "Foggy";
|
|
3163
|
+
/** 雨天 */
|
|
3164
|
+
WeatherType["RAIN"] = "Rain";
|
|
3165
|
+
/** 雪天 */
|
|
3166
|
+
WeatherType["SNOW"] = "Snow";
|
|
3167
|
+
})(WeatherType || (WeatherType = {}));
|
|
3168
|
+
/**
|
|
3169
|
+
* 天气类,用于管理和控制场景中的天气
|
|
3170
|
+
*/
|
|
3171
|
+
class Weather {
|
|
3172
|
+
/**
|
|
3173
|
+
* 构造函数
|
|
3174
|
+
*/
|
|
3175
|
+
constructor(rpc) {
|
|
3176
|
+
this._rpc = rpc;
|
|
3177
|
+
}
|
|
3178
|
+
/**
|
|
3179
|
+
* 设置天气类型
|
|
3180
|
+
* @param type 天气类型
|
|
3181
|
+
*/
|
|
3182
|
+
async setWeather(type) {
|
|
3183
|
+
return this._rpc.callModule('Enviorment', 'SetWeather', {
|
|
3184
|
+
Preset: type
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
/**
|
|
3190
|
+
* 防抖函数 - 延迟执行函数,直到停止调用一段时间后才执行
|
|
3191
|
+
* @param func 要执行的函数
|
|
3192
|
+
* @param wait 等待时间(毫秒)
|
|
3193
|
+
* @param immediate 是否立即执行
|
|
3194
|
+
* @returns 防抖处理后的函数
|
|
3195
|
+
*/
|
|
3196
|
+
/**
|
|
3197
|
+
* 节流函数 - 限制函数在一定时间内只能执行一次
|
|
3198
|
+
* @param func 要执行的函数
|
|
3199
|
+
* @param limit 时间限制(毫秒)
|
|
3200
|
+
* @returns 节流处理后的函数
|
|
3201
|
+
*/
|
|
3202
|
+
function throttle(func, limit) {
|
|
3203
|
+
let inThrottle = false;
|
|
3204
|
+
return function (...args) {
|
|
3205
|
+
const context = this;
|
|
3206
|
+
if (!inThrottle) {
|
|
3207
|
+
func.apply(context, args);
|
|
3208
|
+
inThrottle = true;
|
|
3209
|
+
setTimeout(() => (inThrottle = false), limit);
|
|
3210
|
+
}
|
|
3211
|
+
};
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
class PickCast extends Tool {
|
|
3215
|
+
constructor(rpc) {
|
|
3216
|
+
super(rpc);
|
|
3217
|
+
}
|
|
3218
|
+
hover(callback, maxDistance = 1000000, highlight = false) {
|
|
3219
|
+
let stream = this._rpc.getStream();
|
|
3220
|
+
let videoElementParent = stream.videoElementParent;
|
|
3221
|
+
const onMousemove = throttle(async (event) => {
|
|
3222
|
+
// console.log(event)
|
|
3223
|
+
const offsetX = event.offsetX;
|
|
3224
|
+
const offsetY = event.offsetY;
|
|
3225
|
+
let response = await this._rpc.pickPointByScreen(offsetX, offsetY, maxDistance, highlight);
|
|
3226
|
+
callback && callback(response);
|
|
3227
|
+
}, 50);
|
|
3228
|
+
videoElementParent.addEventListener('mousemove', onMousemove);
|
|
3229
|
+
return function finish() {
|
|
3230
|
+
videoElementParent.removeEventListener('mousemove', onMousemove);
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
pick(callback, maxDistance = 1000000, highlight = true) {
|
|
3234
|
+
let videoElementParent = this._rpc.getStream().videoElementParent;
|
|
3235
|
+
let rpc = this._rpc;
|
|
3236
|
+
async function onPick(event) {
|
|
3237
|
+
const offsetX = event.offsetX;
|
|
3238
|
+
const offsetY = event.offsetY;
|
|
3239
|
+
let response = await rpc.pickPointByScreen(offsetX, offsetY, maxDistance, highlight);
|
|
3240
|
+
callback && callback(response);
|
|
3241
|
+
}
|
|
3242
|
+
videoElementParent.addEventListener('click', onPick);
|
|
3243
|
+
return function finish() {
|
|
3244
|
+
videoElementParent.removeEventListener('click', onPick);
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
/**
|
|
3250
|
+
* 热力图工具类,用于创建热力图
|
|
3251
|
+
*/
|
|
3252
|
+
class HeatMap extends Tool {
|
|
3253
|
+
constructor(rpc, world) {
|
|
3254
|
+
super(rpc);
|
|
3255
|
+
this._world = world;
|
|
3256
|
+
}
|
|
3257
|
+
async create(params) {
|
|
3258
|
+
let _transform = params.transform || Transform.default();
|
|
3259
|
+
let response = await this._rpc.callModule('HeatMap', 'Create', {
|
|
3260
|
+
url: params.url,
|
|
3261
|
+
X: _transform.position.x,
|
|
3262
|
+
Y: _transform.position.y,
|
|
3263
|
+
Z: _transform.position.z,
|
|
3264
|
+
ScaleX: _transform.scale.x,
|
|
3265
|
+
ScaleY: _transform.scale.y,
|
|
3266
|
+
ScaleZ: _transform.scale.z,
|
|
3267
|
+
Pitch: _transform.rotation.pitch,
|
|
3268
|
+
Yaw: _transform.rotation.yaw,
|
|
3269
|
+
Roll: _transform.rotation.roll,
|
|
3270
|
+
Tag: params.tag,
|
|
3271
|
+
MeshSize: params.meshSize,
|
|
3272
|
+
MeshSegment: params.meshSegment,
|
|
3273
|
+
LerpScale: params.lerpScale,
|
|
3274
|
+
Opacity: params.opacity,
|
|
3275
|
+
HeightScale: params.heightScale,
|
|
3276
|
+
ZeroValueOpacity: params.zeroValueOpacity,
|
|
3277
|
+
InfluenceSize: params.influenceSize,
|
|
3278
|
+
EmissiveStrength: params.emissiveStrength,
|
|
3279
|
+
HeatMapPoints: params.heatMapPoints
|
|
3280
|
+
});
|
|
3281
|
+
let _node = new UERPCNode(this._rpc, response.Handle, {
|
|
3282
|
+
assetType: AssetType.Other
|
|
3283
|
+
}, _transform, params.tag);
|
|
3284
|
+
this._world.root.__dangerousRawAdd(_node);
|
|
3285
|
+
return _node;
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
class Scatter extends Tool {
|
|
3290
|
+
constructor(rpc) {
|
|
3291
|
+
super(rpc);
|
|
3292
|
+
}
|
|
3293
|
+
async create(params) {
|
|
3294
|
+
let response = await this._rpc.callModule('Point', 'Create', {
|
|
3295
|
+
WidgetSpace: params.widgetSpace,
|
|
3296
|
+
PointParams: params.pointParams.map((item) => {
|
|
3297
|
+
return {
|
|
3298
|
+
Id: item.id,
|
|
3299
|
+
Location: item.location,
|
|
3300
|
+
Rotation: item.rotation,
|
|
3301
|
+
Scale: item.scale,
|
|
3302
|
+
Tag: item.tag,
|
|
3303
|
+
TextContent: item.textContent
|
|
3304
|
+
};
|
|
3305
|
+
})
|
|
3306
|
+
});
|
|
3307
|
+
let _params = [];
|
|
3308
|
+
for (let i = 0; i < response.CreatedIDs.length; i++) {
|
|
3309
|
+
let id = response.CreatedIDs[i];
|
|
3310
|
+
let param = params.pointParams[i];
|
|
3311
|
+
_params.push({
|
|
3312
|
+
...param,
|
|
3313
|
+
id
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
return createScatterGroupHandler(this._rpc, _params);
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
class ScatterGroupHandler {
|
|
3320
|
+
get pointsMap() {
|
|
3321
|
+
return this.children.reduce((acc, cur) => {
|
|
3322
|
+
acc[cur.id] = cur;
|
|
3323
|
+
return acc;
|
|
3324
|
+
}, {});
|
|
3325
|
+
}
|
|
3326
|
+
get tagMap() {
|
|
3327
|
+
return this.children.reduce((acc, cur) => {
|
|
3328
|
+
if (!acc[cur.tag]) {
|
|
3329
|
+
acc[cur.tag] = [];
|
|
3330
|
+
}
|
|
3331
|
+
acc[cur.tag].push(cur);
|
|
3332
|
+
return acc;
|
|
3333
|
+
}, {});
|
|
3334
|
+
}
|
|
3335
|
+
constructor(rpc) {
|
|
3336
|
+
this.children = [];
|
|
3337
|
+
this._rpc = rpc;
|
|
3338
|
+
}
|
|
3339
|
+
getById(id) {
|
|
3340
|
+
return this.pointsMap[id];
|
|
3341
|
+
}
|
|
3342
|
+
async removeById(id) {
|
|
3343
|
+
let handle = this.getById(id);
|
|
3344
|
+
if (handle) {
|
|
3345
|
+
this.children = this.children.filter((child) => child.id !== id);
|
|
3346
|
+
handle.group = undefined;
|
|
3347
|
+
await handle.remove();
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
async removeAll() {
|
|
3351
|
+
let childrenIds = this.children.map((child) => child.id);
|
|
3352
|
+
this.children = [];
|
|
3353
|
+
await this._rpc.callModule('Point', 'DeleteByIds', {
|
|
3354
|
+
IDs: childrenIds
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
async removeByTag(tag) {
|
|
3358
|
+
let childrenIds = this.tagMap[tag].map((child) => child.id);
|
|
3359
|
+
this.children = this.children.filter((child) => child.tag !== tag);
|
|
3360
|
+
await this._rpc.callModule('Point', 'DeleteByIds', {
|
|
3361
|
+
IDs: childrenIds
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
class PointHandler {
|
|
3366
|
+
constructor(id, params) {
|
|
3367
|
+
this._id = id;
|
|
3368
|
+
this._rpc = params.rpc;
|
|
3369
|
+
this._transform = params.transform || Transform.default();
|
|
3370
|
+
this._textContent = params.textContent;
|
|
3371
|
+
this._tag = params.tag || '';
|
|
3372
|
+
this._remoteUpdateFlag = false;
|
|
3373
|
+
this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
|
|
3374
|
+
this.group = params.group;
|
|
3375
|
+
}
|
|
3376
|
+
get tag() {
|
|
3377
|
+
return this._tag;
|
|
3378
|
+
}
|
|
3379
|
+
get id() {
|
|
3380
|
+
return this._id;
|
|
3381
|
+
}
|
|
3382
|
+
get transform() {
|
|
3383
|
+
return createDeepProxy(this._transform, {}, this._collector);
|
|
3384
|
+
}
|
|
3385
|
+
get textContent() {
|
|
3386
|
+
return this._textContent;
|
|
3387
|
+
}
|
|
3388
|
+
set textContent(value) {
|
|
3389
|
+
this._textContent = value;
|
|
3390
|
+
this._triggerRemoteUpdate();
|
|
3391
|
+
}
|
|
3392
|
+
_triggerRemoteUpdate() {
|
|
3393
|
+
if (!this._remoteUpdateFlag) {
|
|
3394
|
+
this._remoteUpdateFlag = true;
|
|
3395
|
+
this.remoteUpdate();
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
remoteUpdate() {
|
|
3399
|
+
let transformObj = this.transform.toRPCJSON();
|
|
3400
|
+
this._rpc.callModule('Point', 'Update', {
|
|
3401
|
+
textContent: this.textContent,
|
|
3402
|
+
Location: transformObj.Location,
|
|
3403
|
+
Rotation: transformObj.Rotation,
|
|
3404
|
+
Scale: transformObj.Scale
|
|
3405
|
+
});
|
|
3406
|
+
this._remoteUpdateFlag = false;
|
|
3407
|
+
}
|
|
3408
|
+
async remove() {
|
|
3409
|
+
if (this.group) {
|
|
3410
|
+
// this.group = undefined
|
|
3411
|
+
return this.group.removeById(this.id);
|
|
3412
|
+
}
|
|
3413
|
+
await this._rpc.callModule('Point', 'DeleteByIds', {
|
|
3414
|
+
IDs: [this.id]
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
function createScatterGroupHandler(rpc, params) {
|
|
3419
|
+
let scatterhandler = new ScatterGroupHandler(rpc);
|
|
3420
|
+
let phandler = params.map((param) => createPointHandler(rpc, {
|
|
3421
|
+
...param
|
|
3422
|
+
}, scatterhandler));
|
|
3423
|
+
scatterhandler.children = phandler;
|
|
3424
|
+
return scatterhandler;
|
|
3425
|
+
}
|
|
3426
|
+
function createPointHandler(rpc, param, group) {
|
|
3427
|
+
// return new PointHandlerQuery()
|
|
3428
|
+
let handler = new PointHandler(param.id, {
|
|
3429
|
+
rpc,
|
|
3430
|
+
transform: Transform.fromRPCObject({}),
|
|
3431
|
+
textContent: param.textContent,
|
|
3432
|
+
tag: param.tag,
|
|
3433
|
+
group: group
|
|
3434
|
+
});
|
|
3435
|
+
return handler;
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
/**
|
|
3439
|
+
* 围栏工具类,用于创建和删除电子围栏
|
|
3440
|
+
*/
|
|
3441
|
+
class Fence extends Tool {
|
|
3442
|
+
constructor(rpc) {
|
|
3443
|
+
super(rpc);
|
|
3444
|
+
}
|
|
3445
|
+
async create(params) {
|
|
3446
|
+
let response = this._rpc.callModule('Box', 'Create', {
|
|
3447
|
+
VectorArray: params.vectorArray,
|
|
3448
|
+
Height: params.height,
|
|
3449
|
+
MaterialEnum: params.materialEnum,
|
|
3450
|
+
Color: params.color
|
|
3451
|
+
});
|
|
3452
|
+
const { FenceID } = await response;
|
|
3453
|
+
let handler = new FenceHandler(this._rpc, FenceID, FenceStatus.Created);
|
|
3454
|
+
return handler;
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
var FenceStatus;
|
|
3458
|
+
(function (FenceStatus) {
|
|
3459
|
+
FenceStatus["UnCreated"] = "UnCreated";
|
|
3460
|
+
/** 围栏已创建 */
|
|
3461
|
+
FenceStatus["Created"] = "Created";
|
|
3462
|
+
/** 围栏已删除 */
|
|
3463
|
+
FenceStatus["Removed"] = "Removed";
|
|
3464
|
+
})(FenceStatus || (FenceStatus = {}));
|
|
3465
|
+
class FenceHandler {
|
|
3466
|
+
get id() {
|
|
3467
|
+
return this._id;
|
|
3468
|
+
}
|
|
3469
|
+
constructor(rpc, id, status) {
|
|
3470
|
+
this._id = id;
|
|
3471
|
+
this._rpc = rpc;
|
|
3472
|
+
this._status = status || FenceStatus.UnCreated;
|
|
3473
|
+
}
|
|
3474
|
+
get status() {
|
|
3475
|
+
return this._status;
|
|
3476
|
+
}
|
|
3477
|
+
async remove() {
|
|
3478
|
+
return this._rpc.callModule('Box', 'Delete', {
|
|
3479
|
+
FenceID: this.id
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3484
|
+
class Building extends Tool {
|
|
3485
|
+
constructor(rpc) {
|
|
3486
|
+
super(rpc);
|
|
3487
|
+
}
|
|
3488
|
+
async expand(id, params) {
|
|
3489
|
+
await this._rpc.callModule('Building', 'Expand', {
|
|
3490
|
+
BuildingId: id,
|
|
3491
|
+
Spacing: params.spacing,
|
|
3492
|
+
Duration: params.duration || 2000
|
|
3493
|
+
});
|
|
3494
|
+
let handler = new BuildingHandler(id, this._rpc);
|
|
3495
|
+
return handler;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
var Status$1;
|
|
3499
|
+
(function (Status) {
|
|
3500
|
+
Status["Expanded"] = "Expanded";
|
|
3501
|
+
Status["ExpandFloor"] = "ExpandFloor";
|
|
3502
|
+
Status["Collapsed"] = "Collapsed";
|
|
3503
|
+
})(Status$1 || (Status$1 = {}));
|
|
3504
|
+
class BuildingHandler {
|
|
3505
|
+
constructor(id, rpc, status) {
|
|
3506
|
+
this._id = id;
|
|
3507
|
+
this._rpc = rpc;
|
|
3508
|
+
this._status = status || Status$1.Collapsed;
|
|
3509
|
+
}
|
|
3510
|
+
get status() {
|
|
3511
|
+
return this._status;
|
|
3512
|
+
}
|
|
3513
|
+
get id() {
|
|
3514
|
+
return this._id;
|
|
3515
|
+
}
|
|
3516
|
+
async expand(params) {
|
|
3517
|
+
await this._rpc.callModule('Building', 'ExpandFloor', {
|
|
3518
|
+
BuildingId: this._id,
|
|
3519
|
+
Spacing: params.spacing,
|
|
3520
|
+
Duration: params.duration || 2
|
|
3521
|
+
});
|
|
3522
|
+
}
|
|
3523
|
+
async expandFloor(params) {
|
|
3524
|
+
let _params = {
|
|
3525
|
+
BuildingId: this._id,
|
|
3526
|
+
Distance: params.distance,
|
|
3527
|
+
ExpandHeight: params.expandHeight,
|
|
3528
|
+
Duration: params.duration || 2
|
|
3529
|
+
};
|
|
3530
|
+
if (params.direction) {
|
|
3531
|
+
_params.Direction = {
|
|
3532
|
+
X: params.direction.X,
|
|
3533
|
+
Y: params.direction.Y,
|
|
3534
|
+
Z: params.direction.Z
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
return this._rpc.callModule('Building', 'ExpandFloor', _params);
|
|
3538
|
+
}
|
|
3539
|
+
async collapse(duration = 2) {
|
|
3540
|
+
return this._rpc.callModule('Building', 'Collapse', {
|
|
3541
|
+
BuildingId: this._id,
|
|
3542
|
+
duration: duration || 2
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
var MeasurementType;
|
|
3548
|
+
(function (MeasurementType) {
|
|
3549
|
+
MeasurementType["Path"] = "Path";
|
|
3550
|
+
MeasurementType["Height"] = "Height";
|
|
3551
|
+
MeasurementType["Area"] = "Area";
|
|
3552
|
+
})(MeasurementType || (MeasurementType = {}));
|
|
3553
|
+
class Measurement extends Tool {
|
|
3554
|
+
constructor(rpc) {
|
|
3555
|
+
super(rpc);
|
|
3556
|
+
}
|
|
3557
|
+
draw(type) {
|
|
3558
|
+
return this._rpc.callModule('Measurement', 'SetDrawType', {
|
|
3559
|
+
Type: type
|
|
3560
|
+
});
|
|
3561
|
+
}
|
|
3562
|
+
clean() {
|
|
3563
|
+
return this._rpc.callModule('Measurement', 'SetDrawType', {
|
|
3564
|
+
Type: 'Null'
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
class Daytime extends Tool {
|
|
3570
|
+
constructor(rpc) {
|
|
3571
|
+
super(rpc);
|
|
3572
|
+
}
|
|
3573
|
+
setDaytime(hh, mm) {
|
|
3574
|
+
return this._rpc.callModule('Environment', 'SetDaytime', {
|
|
3575
|
+
value: `${hh}${mm}`
|
|
3576
|
+
});
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
// 虚化
|
|
3581
|
+
class Ghost extends Tool {
|
|
3582
|
+
constructor(rpc) {
|
|
3583
|
+
super(rpc);
|
|
3584
|
+
}
|
|
3585
|
+
async ghost(node) {
|
|
3586
|
+
await this._rpc.callModule('Visual', 'Ghost', {
|
|
3587
|
+
Ghost: true,
|
|
3588
|
+
handle: node.key
|
|
3589
|
+
});
|
|
3590
|
+
return new GhostHandle(node, this._rpc);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
class GhostHandle {
|
|
3594
|
+
constructor(node, rpc) {
|
|
3595
|
+
this._node = node;
|
|
3596
|
+
this._rpc = rpc;
|
|
3597
|
+
}
|
|
3598
|
+
async restore() {
|
|
3599
|
+
await this._rpc.callModule('Visual', 'Ghost', {
|
|
3600
|
+
handle: this._node.key,
|
|
3601
|
+
Ghost: false
|
|
3602
|
+
});
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3606
|
+
var Tools = {
|
|
3607
|
+
Tool,
|
|
3608
|
+
MatchViewTool: MatchView,
|
|
3609
|
+
WeatherTool: Weather,
|
|
3610
|
+
PickCastTool: PickCast,
|
|
3611
|
+
HeatMapTool: HeatMap,
|
|
3612
|
+
ScatterTool: Scatter,
|
|
3613
|
+
FenceTool: Fence,
|
|
3614
|
+
BuildingTool: Building,
|
|
3615
|
+
MeasurementTool: Measurement,
|
|
3616
|
+
DaytimeTool: Daytime,
|
|
3617
|
+
GhostTool: Ghost
|
|
3618
|
+
};
|
|
3619
|
+
|
|
3620
|
+
/**
|
|
3621
|
+
* 世界模块,提供世界场景的核心类
|
|
3622
|
+
* 用于管理场景中的所有对象、天气和RPC通信
|
|
3623
|
+
*/
|
|
3624
|
+
/**
|
|
3625
|
+
* 世界类,整个场景的根容器
|
|
3626
|
+
* 管理场景中的所有对象、天气系统和RPC通信
|
|
3627
|
+
*/
|
|
3628
|
+
class World {
|
|
3629
|
+
/**
|
|
3630
|
+
* 构造函数
|
|
3631
|
+
* @param pixelStream PixelStream实例,用于与远程渲染引擎通信
|
|
3632
|
+
*/
|
|
3633
|
+
constructor(pixelStream) {
|
|
3634
|
+
this._rpc = new UERPC(pixelStream);
|
|
3635
|
+
this.root = new UERPCNode(this._rpc);
|
|
3636
|
+
this.root.world = this;
|
|
3637
|
+
this.tools = {
|
|
3638
|
+
ghost: new Tools.GhostTool(this._rpc),
|
|
3639
|
+
weather: new Tools.WeatherTool(this._rpc),
|
|
3640
|
+
matchView: new Tools.MatchViewTool(this._rpc),
|
|
3641
|
+
pickCast: new Tools.PickCastTool(this._rpc),
|
|
3642
|
+
scatter: new Tools.ScatterTool(this._rpc),
|
|
3643
|
+
heatMap: new Tools.HeatMapTool(this._rpc, this),
|
|
3644
|
+
fence: new Tools.FenceTool(this._rpc),
|
|
3645
|
+
building: new Tools.BuildingTool(this._rpc),
|
|
3646
|
+
measurement: new Tools.MeasurementTool(this._rpc),
|
|
3647
|
+
daytime: new Tools.DaytimeTool(this._rpc)
|
|
3648
|
+
};
|
|
3649
|
+
}
|
|
3650
|
+
/**
|
|
3651
|
+
* 获取RPC通信实例
|
|
3652
|
+
*/
|
|
3653
|
+
get rpc() {
|
|
3654
|
+
return this._rpc;
|
|
3655
|
+
}
|
|
3656
|
+
/**
|
|
3657
|
+
* 加载关卡
|
|
3658
|
+
* @param params 加载关卡的参数
|
|
3659
|
+
* @returns 加载成功后返回关卡节点
|
|
3660
|
+
*/
|
|
3661
|
+
async loadLevelByName(assetPath) {
|
|
3662
|
+
let response = await this._rpc.loadLevelByName(assetPath);
|
|
3663
|
+
// let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
3664
|
+
// AssetPath: assetPath,
|
|
3665
|
+
// Transform: Transform.default().toRPCJSON()
|
|
3666
|
+
// })
|
|
3667
|
+
let handle = response.Handle || 'map';
|
|
3668
|
+
let node = new UERPCNode(this._rpc, handle, { assetType: AssetType.Map });
|
|
3669
|
+
node.data = { assetType: AssetType.Map };
|
|
3670
|
+
this.root.add(node);
|
|
3671
|
+
return node;
|
|
3672
|
+
}
|
|
3673
|
+
/**
|
|
3674
|
+
* 生成含有骨骼动画的Mesh
|
|
3675
|
+
*/
|
|
3676
|
+
async spawnSkeletalMesh(params) {
|
|
3677
|
+
let _transform = params.transform || Transform.default();
|
|
3678
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
3679
|
+
Type: 'SkeletalMesh',
|
|
3680
|
+
AssetPath: params.assetPath,
|
|
3681
|
+
Transform: _transform.toRPCJSON(),
|
|
3682
|
+
Tag: params.tag
|
|
3683
|
+
});
|
|
3684
|
+
let handle = response.Handle;
|
|
3685
|
+
let node = new UERPCNode(this._rpc, handle, {
|
|
3686
|
+
assetType: AssetType.SkeletalMesh
|
|
3687
|
+
}, _transform);
|
|
3688
|
+
this.root.add(node);
|
|
3689
|
+
return node;
|
|
3690
|
+
}
|
|
3691
|
+
/**
|
|
3692
|
+
* 生成静态网格体演员
|
|
3693
|
+
* @param params 生成静态网格体的参数
|
|
3694
|
+
* @returns 生成成功后返回演员节点
|
|
3695
|
+
*/
|
|
3696
|
+
async spawnStaticMeshActor(params) {
|
|
3697
|
+
let _transform = params.transform || Transform.default();
|
|
3698
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
3699
|
+
Type: 'StaticMesh',
|
|
3700
|
+
AssetPath: params.assetPath,
|
|
3701
|
+
Transform: _transform.toRPCJSON(),
|
|
3702
|
+
Tag: params.tag
|
|
3703
|
+
});
|
|
3704
|
+
let handle = response.Handle;
|
|
3705
|
+
let node = new UERPCNode(this._rpc, handle, {
|
|
3706
|
+
assetType: AssetType.StaticMesh
|
|
3707
|
+
}, _transform);
|
|
3708
|
+
this.root.add(node);
|
|
3709
|
+
return node;
|
|
3710
|
+
}
|
|
3711
|
+
/**
|
|
3712
|
+
* 生成本地蓝图演员
|
|
3713
|
+
* @param params 生成本地蓝图的参数
|
|
3714
|
+
* @returns 生成成功后返回演员节点
|
|
3715
|
+
*/
|
|
3716
|
+
async spawnLocalBlueprintActor(params) {
|
|
3717
|
+
let _transform = params.transform || Transform.default();
|
|
3718
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
3719
|
+
Type: 'Blueprint',
|
|
3720
|
+
AssetPath: params.assetPath,
|
|
3721
|
+
Transform: _transform.toRPCJSON(),
|
|
3722
|
+
Tag: params.tag
|
|
3723
|
+
});
|
|
3724
|
+
// let response = await this._rpc.spawnLocalBlueprintActor({
|
|
3725
|
+
// AssetPath: params.assetPath,
|
|
3726
|
+
// Transform: _transform.toRPCJSON(),
|
|
3727
|
+
// Tag: params.tag
|
|
3728
|
+
// })
|
|
3729
|
+
let handle = response.Handle;
|
|
3730
|
+
let node = new UERPCNode(this._rpc, handle, {
|
|
3731
|
+
assetType: AssetType.Blueprint
|
|
3732
|
+
}, _transform);
|
|
3733
|
+
this.root.add(node);
|
|
3734
|
+
return node;
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
/**
|
|
3739
|
+
* 相机基类,继承自UERPCNode
|
|
3740
|
+
* 定义了相机的基本结构,所有具体相机类型的父类
|
|
3741
|
+
*/
|
|
3742
|
+
class Camera extends UERPCNode {
|
|
3743
|
+
/**
|
|
3744
|
+
* 相机基类构造函数
|
|
3745
|
+
* @param rpc UERPC实例,用于与远程服务通信
|
|
3746
|
+
* @param type 相机类型
|
|
3747
|
+
*/
|
|
3748
|
+
constructor(rpc, type) {
|
|
3749
|
+
super(rpc, type);
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
/**
|
|
3753
|
+
* 透视相机类,用于表示3D场景中的透视相机
|
|
3754
|
+
* 实现了透视相机的属性和变换管理
|
|
3755
|
+
*/
|
|
3756
|
+
class PerspectiveCamera extends Camera {
|
|
3757
|
+
/**
|
|
3758
|
+
* 构造函数
|
|
3759
|
+
* @param rpc UERPC实例,用于与远程服务通信
|
|
3760
|
+
*/
|
|
3761
|
+
constructor(rpc) {
|
|
3762
|
+
super(rpc, 'camera');
|
|
3763
|
+
// // 初始化相机默认属性
|
|
3764
|
+
// this._fov = 75
|
|
3765
|
+
// this._focalLength = 50
|
|
3766
|
+
// this._aperture = 35
|
|
3767
|
+
// this._focusDistance = 100
|
|
3768
|
+
// 创建默认变换
|
|
3769
|
+
this._transform = Transform.default();
|
|
3770
|
+
// 初始化变换收集器
|
|
3771
|
+
this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
|
|
3772
|
+
// 初始化远程更新标志
|
|
3773
|
+
this._remoteUpdateFlag = false;
|
|
3774
|
+
}
|
|
3775
|
+
// /**
|
|
3776
|
+
// * 获取焦距值
|
|
3777
|
+
// * @returns {number} 焦距值,单位为毫米
|
|
3778
|
+
// */
|
|
3779
|
+
// get focalLength() {
|
|
3780
|
+
// return this._focalLength
|
|
3781
|
+
// }
|
|
3782
|
+
// /**
|
|
3783
|
+
// * 设置焦距值
|
|
3784
|
+
// * @param focalLength 新的焦距值,单位为毫米
|
|
3785
|
+
// */
|
|
3786
|
+
// set focalLength(focalLength: number) {
|
|
3787
|
+
// this._focalLength = focalLength
|
|
3788
|
+
// this._triggerRemoteUpdate()
|
|
3789
|
+
// }
|
|
3790
|
+
// /**
|
|
3791
|
+
// * 获取光圈值
|
|
3792
|
+
// * @returns {number} 光圈值
|
|
3793
|
+
// */
|
|
3794
|
+
// get aperture() {
|
|
3795
|
+
// return this._aperture
|
|
3796
|
+
// }
|
|
3797
|
+
// /**
|
|
3798
|
+
// * 设置光圈值
|
|
3799
|
+
// * @param aperture 新的光圈值
|
|
3800
|
+
// */
|
|
3801
|
+
// set aperture(aperture: number) {
|
|
3802
|
+
// this._aperture = aperture
|
|
3803
|
+
// this._triggerRemoteUpdate()
|
|
3804
|
+
// }
|
|
3805
|
+
// /**
|
|
3806
|
+
// * 获取视场角
|
|
3807
|
+
// * @returns {number} 视场角,单位为度
|
|
3808
|
+
// */
|
|
3809
|
+
// get fov() {
|
|
3810
|
+
// return this._fov
|
|
3811
|
+
// }
|
|
3812
|
+
// /**
|
|
3813
|
+
// * 设置视场角
|
|
3814
|
+
// * @param fov 新的视场角,单位为度
|
|
3815
|
+
// */
|
|
3816
|
+
// set fov(fov: number) {
|
|
3817
|
+
// this._fov = fov
|
|
3818
|
+
// this._triggerRemoteUpdate()
|
|
3819
|
+
// }
|
|
3820
|
+
// /**
|
|
3821
|
+
// * 获取焦距离
|
|
3822
|
+
// * @returns {number} 焦距离,单位为世界单位
|
|
3823
|
+
// */
|
|
3824
|
+
// get focusDistance() {
|
|
3825
|
+
// return this._focusDistance
|
|
3826
|
+
// }
|
|
3827
|
+
// 同步远程相机参数到本地
|
|
3828
|
+
async forceSyncRemoteToLocal() {
|
|
3829
|
+
let response = await this._rpc.getCameraTransform();
|
|
3830
|
+
console.log(response);
|
|
3831
|
+
if (response.Transform) {
|
|
3832
|
+
let transform = Transform.fromRPCObject(response.Transform);
|
|
3833
|
+
this._transform = transform;
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
// /**
|
|
3837
|
+
// * 设置焦距离
|
|
3838
|
+
// * @param focusDistance 新的焦距离,单位为世界单位
|
|
3839
|
+
// */
|
|
3840
|
+
// set focusDistance(focusDistance: number) {
|
|
3841
|
+
// this._focusDistance = focusDistance
|
|
3842
|
+
// this._triggerRemoteUpdate()
|
|
3843
|
+
// }
|
|
3844
|
+
/**
|
|
3845
|
+
* 获取相机变换的代理对象
|
|
3846
|
+
* 通过深度代理实现对变换属性的监听,当变换属性变化时自动触发远程更新
|
|
3847
|
+
* @returns {Transform} 相机变换的代理对象
|
|
3848
|
+
*/
|
|
3849
|
+
get transform() {
|
|
3850
|
+
return createDeepProxy(this._transform, {}, this._collector);
|
|
3851
|
+
}
|
|
3852
|
+
/**
|
|
3853
|
+
* 触发远程更新
|
|
3854
|
+
* 该方法在相机属性或变换变化时被调用,用于标记相机需要同步到远程
|
|
3855
|
+
*/
|
|
3856
|
+
_triggerRemoteUpdate() {
|
|
3857
|
+
this._remoteUpdateFlag = true;
|
|
3858
|
+
this._remoteUpdate();
|
|
3859
|
+
}
|
|
3860
|
+
/**
|
|
3861
|
+
* 远程更新处理方法
|
|
3862
|
+
* 用于将相机的属性和变换同步到远程服务器
|
|
3863
|
+
* TODO: 实现具体的远程同步逻辑
|
|
3864
|
+
*/
|
|
3865
|
+
_remoteUpdate() {
|
|
3866
|
+
// TODO: 实现相机属性和变换的远程同步逻辑
|
|
3867
|
+
this._rpc.setCameraTransform(this._transform.toRPCJSON());
|
|
3868
|
+
this._remoteUpdateFlag = true;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
class PresetAnimateClip {
|
|
3873
|
+
constructor(animateName) {
|
|
3874
|
+
this.animateName = animateName;
|
|
3875
|
+
}
|
|
3876
|
+
_clipCall() {
|
|
3877
|
+
return new PresetAnimateClipCall(this);
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
class PresetAnimateClipCall {
|
|
3881
|
+
constructor(clip) {
|
|
3882
|
+
this.clip = clip;
|
|
3883
|
+
}
|
|
3884
|
+
_play(action, params) {
|
|
3885
|
+
action.mixer?.rpc.callModule('Animation', 'Play', {
|
|
3886
|
+
...params,
|
|
3887
|
+
Animation: this.clip.animateName
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
_pause(action, params) {
|
|
3891
|
+
action.mixer?.rpc.callModule('Animation', 'Pause', {
|
|
3892
|
+
handle: params.Handle
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
_resume(action, params) {
|
|
3896
|
+
action.mixer?.rpc.callModule('Animation', 'Resume', {
|
|
3897
|
+
handle: params.Handle
|
|
3898
|
+
});
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
class KeyFrameAnimateClip {
|
|
3902
|
+
constructor(params) {
|
|
3903
|
+
this.startTransform = params.startTransform;
|
|
3904
|
+
this.endTransform = params.endTransform;
|
|
3905
|
+
}
|
|
3906
|
+
_clipCall() {
|
|
3907
|
+
return new KeyFrameAnimateClipCall(this);
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
class KeyFrameAnimateClipCall {
|
|
3911
|
+
constructor(clip) {
|
|
3912
|
+
this.clip = clip;
|
|
3913
|
+
}
|
|
3914
|
+
_play(action, params) {
|
|
3915
|
+
action.mixer?.rpc.callModule('Animation', 'MoveBetweenTransforms', {
|
|
3916
|
+
Handle: action.handle,
|
|
3917
|
+
StartTransform: this.clip.startTransform?.toRPCJSON(),
|
|
3918
|
+
EndTransform: this.clip.endTransform?.toRPCJSON(),
|
|
3919
|
+
Duration: action.duration
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
_pause(action, params) {
|
|
3923
|
+
action.mixer?.rpc.callModule('Animation', 'PauseMoveBetweenTransforms', {
|
|
3924
|
+
Handle: action.handle
|
|
3925
|
+
});
|
|
3926
|
+
}
|
|
3927
|
+
_resume(action, params) {
|
|
3928
|
+
action.mixer?.rpc.callModule('Animation', 'ResumeMoveBetweenTransforms', {
|
|
3929
|
+
Handle: action.handle
|
|
3930
|
+
});
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
var Status;
|
|
3935
|
+
(function (Status) {
|
|
3936
|
+
Status["Playing"] = "playing";
|
|
3937
|
+
Status["Paused"] = "paused";
|
|
3938
|
+
Status["Stopped"] = "stopped";
|
|
3939
|
+
})(Status || (Status = {}));
|
|
3940
|
+
var PlaybackType;
|
|
3941
|
+
(function (PlaybackType) {
|
|
3942
|
+
PlaybackType["Loop"] = "loop";
|
|
3943
|
+
PlaybackType["Once"] = "once";
|
|
3944
|
+
})(PlaybackType || (PlaybackType = {}));
|
|
3945
|
+
class AnimationAction {
|
|
3946
|
+
constructor(handle, clip, mixer) {
|
|
3947
|
+
this._status = Status.Stopped;
|
|
3948
|
+
this._handle = handle;
|
|
3949
|
+
this.type = PlaybackType.Once;
|
|
3950
|
+
this.rate = 1;
|
|
3951
|
+
this.clip = clip;
|
|
3952
|
+
this.playDuration = 0;
|
|
3953
|
+
this.mixer = mixer;
|
|
3954
|
+
}
|
|
3955
|
+
get duration() {
|
|
3956
|
+
return this._duration;
|
|
3957
|
+
}
|
|
3958
|
+
set duration(duration) {
|
|
3959
|
+
this._duration = duration;
|
|
3960
|
+
}
|
|
3961
|
+
get handle() {
|
|
3962
|
+
return this._handle;
|
|
3963
|
+
}
|
|
3964
|
+
get status() {
|
|
3965
|
+
return this._status;
|
|
3966
|
+
}
|
|
3967
|
+
async play() {
|
|
3968
|
+
if (this._status == Status.Paused) {
|
|
3969
|
+
let clipCall = this.clip._clipCall();
|
|
3970
|
+
return clipCall._resume(this, {
|
|
3971
|
+
Handle: this._handle
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
let obj = {
|
|
3975
|
+
Handle: this._handle,
|
|
3976
|
+
Rate: this.rate,
|
|
3977
|
+
Loop: this.type == PlaybackType.Loop
|
|
3978
|
+
};
|
|
3979
|
+
let clipCall = this.clip._clipCall();
|
|
3980
|
+
this.playDuration = 0;
|
|
3981
|
+
this._status = Status.Playing;
|
|
3982
|
+
clipCall._play(this, obj);
|
|
3983
|
+
return;
|
|
3984
|
+
}
|
|
3985
|
+
pause() {
|
|
3986
|
+
let obj = {
|
|
3987
|
+
Handle: this._handle,
|
|
3988
|
+
Rate: this.rate,
|
|
3989
|
+
Loop: this.type == PlaybackType.Loop
|
|
3990
|
+
};
|
|
3991
|
+
let clipCall = this.clip._clipCall();
|
|
3992
|
+
this._status = Status.Paused;
|
|
3993
|
+
return clipCall._pause(this, obj);
|
|
3994
|
+
}
|
|
3995
|
+
update(delta) {
|
|
3996
|
+
if (this.status != Status.Playing) {
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
this.playDuration += delta;
|
|
4000
|
+
if (this.type === PlaybackType.Once &&
|
|
4001
|
+
this.duration &&
|
|
4002
|
+
this.playDuration >= this.duration) {
|
|
4003
|
+
this._status = Status.Stopped;
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
|
|
4008
|
+
// 创建一个 Clock , 计算每次的时间差 , 同时保存开始的时间
|
|
4009
|
+
class Clock {
|
|
4010
|
+
constructor() {
|
|
4011
|
+
this.startTime = 0;
|
|
4012
|
+
this.previousTime = 0;
|
|
4013
|
+
this.elapsedTime = 0;
|
|
4014
|
+
this.isRunning = false;
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* 开始计时
|
|
4018
|
+
*/
|
|
4019
|
+
start() {
|
|
4020
|
+
this.startTime = performance.now();
|
|
4021
|
+
this.previousTime = this.startTime;
|
|
4022
|
+
this.elapsedTime = 0;
|
|
4023
|
+
this.isRunning = true;
|
|
4024
|
+
}
|
|
4025
|
+
/**
|
|
4026
|
+
* 停止计时
|
|
4027
|
+
*/
|
|
4028
|
+
stop() {
|
|
4029
|
+
this.getDelta(); // 更新 elapsedTime
|
|
4030
|
+
this.isRunning = false;
|
|
4031
|
+
}
|
|
4032
|
+
/**
|
|
4033
|
+
* 获取自上次调用 getDelta() 以来经过的时间(时间差)
|
|
4034
|
+
* @returns 时间差(毫秒)
|
|
4035
|
+
*/
|
|
4036
|
+
getDelta() {
|
|
4037
|
+
let currentTime = performance.now();
|
|
4038
|
+
let delta = 0;
|
|
4039
|
+
if (this.isRunning) {
|
|
4040
|
+
delta = currentTime - this.previousTime;
|
|
4041
|
+
this.elapsedTime += delta;
|
|
4042
|
+
this.previousTime = currentTime;
|
|
4043
|
+
}
|
|
4044
|
+
return delta;
|
|
4045
|
+
}
|
|
4046
|
+
/**
|
|
4047
|
+
* 获取自开始计时以来经过的总时间
|
|
4048
|
+
* @returns 经过的总时间(毫秒)
|
|
4049
|
+
*/
|
|
4050
|
+
getElapsedTime() {
|
|
4051
|
+
if (this.isRunning) {
|
|
4052
|
+
this.getDelta(); // 更新 elapsedTime
|
|
4053
|
+
}
|
|
4054
|
+
return this.elapsedTime;
|
|
4055
|
+
}
|
|
4056
|
+
/**
|
|
4057
|
+
* 获取开始时间
|
|
4058
|
+
* @returns 开始时间(毫秒)
|
|
4059
|
+
*/
|
|
4060
|
+
getStartTime() {
|
|
4061
|
+
return this.startTime;
|
|
4062
|
+
}
|
|
4063
|
+
/**
|
|
4064
|
+
* 检查是否正在运行
|
|
4065
|
+
* @returns 是否正在运行
|
|
4066
|
+
*/
|
|
4067
|
+
isRunningState() {
|
|
4068
|
+
return this.isRunning;
|
|
4069
|
+
}
|
|
4070
|
+
/**
|
|
4071
|
+
* 重置计时器
|
|
4072
|
+
*/
|
|
4073
|
+
reset() {
|
|
4074
|
+
this.startTime = performance.now();
|
|
4075
|
+
this.previousTime = this.startTime;
|
|
4076
|
+
this.elapsedTime = 0;
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
class AnimationMixer {
|
|
4081
|
+
constructor(rpc) {
|
|
4082
|
+
this._actions = [];
|
|
4083
|
+
this._rpc = rpc;
|
|
4084
|
+
this._duration = 0;
|
|
4085
|
+
this._actions = [];
|
|
4086
|
+
this.init();
|
|
4087
|
+
}
|
|
4088
|
+
get rpc() {
|
|
4089
|
+
return this._rpc;
|
|
4090
|
+
}
|
|
4091
|
+
init() {
|
|
4092
|
+
this._clock = new Clock();
|
|
4093
|
+
this._clock.start();
|
|
4094
|
+
setTimeout(() => {
|
|
4095
|
+
this._duration += this._clock.getDelta();
|
|
4096
|
+
this.updateAction();
|
|
4097
|
+
}, 1000 / 60);
|
|
4098
|
+
}
|
|
4099
|
+
get duration() {
|
|
4100
|
+
return this._duration;
|
|
4101
|
+
}
|
|
4102
|
+
updateAction() {
|
|
4103
|
+
this._actions.forEach((action) => {
|
|
4104
|
+
action.update(this._duration);
|
|
4105
|
+
});
|
|
4106
|
+
}
|
|
4107
|
+
clipAction(clip, node) {
|
|
4108
|
+
return new AnimationAction(node.key, clip, this);
|
|
4109
|
+
}
|
|
4110
|
+
removeAction(action) {
|
|
4111
|
+
// this._actions = this._actions.filter((item) => item !== action)
|
|
4112
|
+
let index = this._actions.findIndex((item) => item === action);
|
|
4113
|
+
if (index > -1) {
|
|
4114
|
+
this._actions.splice(index, 1);
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
|
|
4119
|
+
var Animation = /*#__PURE__*/Object.freeze({
|
|
4120
|
+
__proto__: null,
|
|
4121
|
+
AnimationMixer: AnimationMixer,
|
|
4122
|
+
AnimationAction: AnimationAction,
|
|
4123
|
+
PresetAnimateClip: PresetAnimateClip,
|
|
4124
|
+
KeyFrameAnimateClip: KeyFrameAnimateClip
|
|
4125
|
+
});
|
|
4126
|
+
|
|
4127
|
+
const Core = {
|
|
4128
|
+
UERPC
|
|
4129
|
+
};
|
|
4130
|
+
const Addons = {
|
|
4131
|
+
World,
|
|
4132
|
+
Transform,
|
|
4133
|
+
PerspectiveCamera,
|
|
4134
|
+
UERPCNode,
|
|
4135
|
+
WeatherType,
|
|
4136
|
+
MeasurementType,
|
|
4137
|
+
Animation: {
|
|
4138
|
+
...Animation
|
|
4139
|
+
}
|
|
4140
|
+
};
|
|
4141
|
+
|
|
4142
|
+
export { Addons, Core };
|
|
4143
|
+
//# sourceMappingURL=sdk.esm.js.map
|