@polarfront-lab/ionian 1.1.0 → 1.3.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/dist/index.d.ts +7 -5
- package/dist/ionian.iife.js +1 -6
- package/dist/ionian.iife.js.map +1 -1
- package/dist/ionian.js +372 -2189
- package/dist/ionian.js.map +1 -1
- package/package.json +2 -5
package/dist/ionian.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import * as THREE from "three";
|
|
5
|
-
import { Mesh, OrthographicCamera, BufferGeometry, Float32BufferAttribute, NearestFilter, ShaderMaterial, WebGLRenderTarget, FloatType, RGBAFormat, DataTexture, ClampToEdgeWrapping } from "three";
|
|
5
|
+
import { Triangle, Vector3, Vector2, Mesh, OrthographicCamera, BufferGeometry, Float32BufferAttribute, NearestFilter, ShaderMaterial, WebGLRenderTarget, FloatType, RGBAFormat, DataTexture, ClampToEdgeWrapping } from "three";
|
|
6
6
|
import { GLTFLoader, DRACOLoader } from "three-stdlib";
|
|
7
7
|
const linear = (n) => n;
|
|
8
8
|
function mitt(n) {
|
|
@@ -44,2046 +44,291 @@ class DefaultEventEmitter {
|
|
|
44
44
|
this.emitter.all.clear();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
52
|
-
const proxyMarker = Symbol("Comlink.proxy");
|
|
53
|
-
const createEndpoint = Symbol("Comlink.endpoint");
|
|
54
|
-
const releaseProxy = Symbol("Comlink.releaseProxy");
|
|
55
|
-
const finalizer = Symbol("Comlink.finalizer");
|
|
56
|
-
const throwMarker = Symbol("Comlink.thrown");
|
|
57
|
-
const isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
|
|
58
|
-
const proxyTransferHandler = {
|
|
59
|
-
canHandle: (val) => isObject(val) && val[proxyMarker],
|
|
60
|
-
serialize(obj) {
|
|
61
|
-
const { port1, port2 } = new MessageChannel();
|
|
62
|
-
expose(obj, port1);
|
|
63
|
-
return [port2, [port2]];
|
|
64
|
-
},
|
|
65
|
-
deserialize(port) {
|
|
66
|
-
port.start();
|
|
67
|
-
return wrap(port);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const throwTransferHandler = {
|
|
71
|
-
canHandle: (value) => isObject(value) && throwMarker in value,
|
|
72
|
-
serialize({ value }) {
|
|
73
|
-
let serialized;
|
|
74
|
-
if (value instanceof Error) {
|
|
75
|
-
serialized = {
|
|
76
|
-
isError: true,
|
|
77
|
-
value: {
|
|
78
|
-
message: value.message,
|
|
79
|
-
name: value.name,
|
|
80
|
-
stack: value.stack
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
serialized = { isError: false, value };
|
|
85
|
-
}
|
|
86
|
-
return [serialized, []];
|
|
87
|
-
},
|
|
88
|
-
deserialize(serialized) {
|
|
89
|
-
if (serialized.isError) {
|
|
90
|
-
throw Object.assign(new Error(serialized.value.message), serialized.value);
|
|
91
|
-
}
|
|
92
|
-
throw serialized.value;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const transferHandlers = /* @__PURE__ */ new Map([
|
|
96
|
-
["proxy", proxyTransferHandler],
|
|
97
|
-
["throw", throwTransferHandler]
|
|
98
|
-
]);
|
|
99
|
-
function isAllowedOrigin(allowedOrigins, origin) {
|
|
100
|
-
for (const allowedOrigin of allowedOrigins) {
|
|
101
|
-
if (origin === allowedOrigin || allowedOrigin === "*") {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
|
|
111
|
-
ep.addEventListener("message", function callback(ev) {
|
|
112
|
-
if (!ev || !ev.data) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
|
|
116
|
-
console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const { id, type, path } = Object.assign({ path: [] }, ev.data);
|
|
120
|
-
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
|
|
121
|
-
let returnValue;
|
|
122
|
-
try {
|
|
123
|
-
const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
|
|
124
|
-
const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
|
|
125
|
-
switch (type) {
|
|
126
|
-
case "GET":
|
|
127
|
-
{
|
|
128
|
-
returnValue = rawValue;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case "SET":
|
|
132
|
-
{
|
|
133
|
-
parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
|
|
134
|
-
returnValue = true;
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
case "APPLY":
|
|
138
|
-
{
|
|
139
|
-
returnValue = rawValue.apply(parent, argumentList);
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
case "CONSTRUCT":
|
|
143
|
-
{
|
|
144
|
-
const value = new rawValue(...argumentList);
|
|
145
|
-
returnValue = proxy(value);
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
case "ENDPOINT":
|
|
149
|
-
{
|
|
150
|
-
const { port1, port2 } = new MessageChannel();
|
|
151
|
-
expose(obj, port2);
|
|
152
|
-
returnValue = transfer(port1, [port1]);
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
case "RELEASE":
|
|
156
|
-
{
|
|
157
|
-
returnValue = void 0;
|
|
158
|
-
}
|
|
159
|
-
break;
|
|
160
|
-
default:
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
} catch (value) {
|
|
164
|
-
returnValue = { value, [throwMarker]: 0 };
|
|
165
|
-
}
|
|
166
|
-
Promise.resolve(returnValue).catch((value) => {
|
|
167
|
-
return { value, [throwMarker]: 0 };
|
|
168
|
-
}).then((returnValue2) => {
|
|
169
|
-
const [wireValue, transferables] = toWireValue(returnValue2);
|
|
170
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
171
|
-
if (type === "RELEASE") {
|
|
172
|
-
ep.removeEventListener("message", callback);
|
|
173
|
-
closeEndPoint(ep);
|
|
174
|
-
if (finalizer in obj && typeof obj[finalizer] === "function") {
|
|
175
|
-
obj[finalizer]();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}).catch((error) => {
|
|
179
|
-
const [wireValue, transferables] = toWireValue({
|
|
180
|
-
value: new TypeError("Unserializable return value"),
|
|
181
|
-
[throwMarker]: 0
|
|
182
|
-
});
|
|
183
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
if (ep.start) {
|
|
187
|
-
ep.start();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function isMessagePort(endpoint) {
|
|
191
|
-
return endpoint.constructor.name === "MessagePort";
|
|
192
|
-
}
|
|
193
|
-
function closeEndPoint(endpoint) {
|
|
194
|
-
if (isMessagePort(endpoint))
|
|
195
|
-
endpoint.close();
|
|
196
|
-
}
|
|
197
|
-
function wrap(ep, target) {
|
|
198
|
-
const pendingListeners = /* @__PURE__ */ new Map();
|
|
199
|
-
ep.addEventListener("message", function handleMessage(ev) {
|
|
200
|
-
const { data } = ev;
|
|
201
|
-
if (!data || !data.id) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const resolver = pendingListeners.get(data.id);
|
|
205
|
-
if (!resolver) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
resolver(data);
|
|
210
|
-
} finally {
|
|
211
|
-
pendingListeners.delete(data.id);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
return createProxy(ep, pendingListeners, [], target);
|
|
215
|
-
}
|
|
216
|
-
function throwIfProxyReleased(isReleased) {
|
|
217
|
-
if (isReleased) {
|
|
218
|
-
throw new Error("Proxy has been released and is not useable");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function releaseEndpoint(ep) {
|
|
222
|
-
return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
|
|
223
|
-
type: "RELEASE"
|
|
224
|
-
}).then(() => {
|
|
225
|
-
closeEndPoint(ep);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
const proxyCounter = /* @__PURE__ */ new WeakMap();
|
|
229
|
-
const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
|
|
230
|
-
const newCount = (proxyCounter.get(ep) || 0) - 1;
|
|
231
|
-
proxyCounter.set(ep, newCount);
|
|
232
|
-
if (newCount === 0) {
|
|
233
|
-
releaseEndpoint(ep);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
function registerProxy(proxy2, ep) {
|
|
237
|
-
const newCount = (proxyCounter.get(ep) || 0) + 1;
|
|
238
|
-
proxyCounter.set(ep, newCount);
|
|
239
|
-
if (proxyFinalizers) {
|
|
240
|
-
proxyFinalizers.register(proxy2, ep, proxy2);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function unregisterProxy(proxy2) {
|
|
244
|
-
if (proxyFinalizers) {
|
|
245
|
-
proxyFinalizers.unregister(proxy2);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function createProxy(ep, pendingListeners, path = [], target = function() {
|
|
249
|
-
}) {
|
|
250
|
-
let isProxyReleased = false;
|
|
251
|
-
const proxy2 = new Proxy(target, {
|
|
252
|
-
get(_target, prop) {
|
|
253
|
-
throwIfProxyReleased(isProxyReleased);
|
|
254
|
-
if (prop === releaseProxy) {
|
|
255
|
-
return () => {
|
|
256
|
-
unregisterProxy(proxy2);
|
|
257
|
-
releaseEndpoint(ep);
|
|
258
|
-
pendingListeners.clear();
|
|
259
|
-
isProxyReleased = true;
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
if (prop === "then") {
|
|
263
|
-
if (path.length === 0) {
|
|
264
|
-
return { then: () => proxy2 };
|
|
265
|
-
}
|
|
266
|
-
const r = requestResponseMessage(ep, pendingListeners, {
|
|
267
|
-
type: "GET",
|
|
268
|
-
path: path.map((p) => p.toString())
|
|
269
|
-
}).then(fromWireValue);
|
|
270
|
-
return r.then.bind(r);
|
|
271
|
-
}
|
|
272
|
-
return createProxy(ep, pendingListeners, [...path, prop]);
|
|
273
|
-
},
|
|
274
|
-
set(_target, prop, rawValue) {
|
|
275
|
-
throwIfProxyReleased(isProxyReleased);
|
|
276
|
-
const [value, transferables] = toWireValue(rawValue);
|
|
277
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
278
|
-
type: "SET",
|
|
279
|
-
path: [...path, prop].map((p) => p.toString()),
|
|
280
|
-
value
|
|
281
|
-
}, transferables).then(fromWireValue);
|
|
282
|
-
},
|
|
283
|
-
apply(_target, _thisArg, rawArgumentList) {
|
|
284
|
-
throwIfProxyReleased(isProxyReleased);
|
|
285
|
-
const last = path[path.length - 1];
|
|
286
|
-
if (last === createEndpoint) {
|
|
287
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
288
|
-
type: "ENDPOINT"
|
|
289
|
-
}).then(fromWireValue);
|
|
290
|
-
}
|
|
291
|
-
if (last === "bind") {
|
|
292
|
-
return createProxy(ep, pendingListeners, path.slice(0, -1));
|
|
293
|
-
}
|
|
294
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
295
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
296
|
-
type: "APPLY",
|
|
297
|
-
path: path.map((p) => p.toString()),
|
|
298
|
-
argumentList
|
|
299
|
-
}, transferables).then(fromWireValue);
|
|
300
|
-
},
|
|
301
|
-
construct(_target, rawArgumentList) {
|
|
302
|
-
throwIfProxyReleased(isProxyReleased);
|
|
303
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
304
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
305
|
-
type: "CONSTRUCT",
|
|
306
|
-
path: path.map((p) => p.toString()),
|
|
307
|
-
argumentList
|
|
308
|
-
}, transferables).then(fromWireValue);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
registerProxy(proxy2, ep);
|
|
312
|
-
return proxy2;
|
|
313
|
-
}
|
|
314
|
-
function myFlat(arr) {
|
|
315
|
-
return Array.prototype.concat.apply([], arr);
|
|
316
|
-
}
|
|
317
|
-
function processArguments(argumentList) {
|
|
318
|
-
const processed = argumentList.map(toWireValue);
|
|
319
|
-
return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
|
|
320
|
-
}
|
|
321
|
-
const transferCache = /* @__PURE__ */ new WeakMap();
|
|
322
|
-
function transfer(obj, transfers) {
|
|
323
|
-
transferCache.set(obj, transfers);
|
|
324
|
-
return obj;
|
|
47
|
+
function createDataTexture(data, size) {
|
|
48
|
+
const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat, THREE.FloatType);
|
|
49
|
+
texture.needsUpdate = true;
|
|
50
|
+
return texture;
|
|
325
51
|
}
|
|
326
|
-
function
|
|
327
|
-
return
|
|
52
|
+
function createBlankDataTexture(size) {
|
|
53
|
+
return createDataTexture(new Float32Array(4 * size * size), size);
|
|
328
54
|
}
|
|
329
|
-
function
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
];
|
|
55
|
+
function createSpherePoints(size) {
|
|
56
|
+
const data = new Float32Array(size * size * 4);
|
|
57
|
+
for (let i = 0; i < size; i++) {
|
|
58
|
+
for (let j = 0; j < size; j++) {
|
|
59
|
+
const index = i * size + j;
|
|
60
|
+
let theta = Math.random() * Math.PI * 2;
|
|
61
|
+
let phi = Math.acos(Math.random() * 2 - 1);
|
|
62
|
+
let x = Math.sin(phi) * Math.cos(theta);
|
|
63
|
+
let y = Math.sin(phi) * Math.sin(theta);
|
|
64
|
+
let z = Math.cos(phi);
|
|
65
|
+
data[4 * index] = x;
|
|
66
|
+
data[4 * index + 1] = y;
|
|
67
|
+
data[4 * index + 2] = z;
|
|
68
|
+
data[4 * index + 3] = (Math.random() - 0.5) * 0.01;
|
|
341
69
|
}
|
|
342
70
|
}
|
|
343
|
-
return
|
|
344
|
-
{
|
|
345
|
-
type: "RAW",
|
|
346
|
-
value
|
|
347
|
-
},
|
|
348
|
-
transferCache.get(value) || []
|
|
349
|
-
];
|
|
350
|
-
}
|
|
351
|
-
function fromWireValue(value) {
|
|
352
|
-
switch (value.type) {
|
|
353
|
-
case "HANDLER":
|
|
354
|
-
return transferHandlers.get(value.name).deserialize(value.value);
|
|
355
|
-
case "RAW":
|
|
356
|
-
return value.value;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
function requestResponseMessage(ep, pendingListeners, msg, transfers) {
|
|
360
|
-
return new Promise((resolve) => {
|
|
361
|
-
const id = generateUUID();
|
|
362
|
-
pendingListeners.set(id, resolve);
|
|
363
|
-
if (ep.start) {
|
|
364
|
-
ep.start();
|
|
365
|
-
}
|
|
366
|
-
ep.postMessage(Object.assign({ id }, msg), transfers);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
function generateUUID() {
|
|
370
|
-
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
371
|
-
}
|
|
372
|
-
function getDefaultExportFromCjs(x) {
|
|
373
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
71
|
+
return createDataTexture(data, size);
|
|
374
72
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
hasRequiredEvents = 1;
|
|
380
|
-
var R = typeof Reflect === "object" ? Reflect : null;
|
|
381
|
-
var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) {
|
|
382
|
-
return Function.prototype.apply.call(target, receiver, args);
|
|
383
|
-
};
|
|
384
|
-
var ReflectOwnKeys;
|
|
385
|
-
if (R && typeof R.ownKeys === "function") {
|
|
386
|
-
ReflectOwnKeys = R.ownKeys;
|
|
387
|
-
} else if (Object.getOwnPropertySymbols) {
|
|
388
|
-
ReflectOwnKeys = function ReflectOwnKeys2(target) {
|
|
389
|
-
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
|
|
390
|
-
};
|
|
73
|
+
function disposeMesh(mesh) {
|
|
74
|
+
mesh.geometry.dispose();
|
|
75
|
+
if (mesh.material instanceof THREE.Material) {
|
|
76
|
+
mesh.material.dispose();
|
|
391
77
|
} else {
|
|
392
|
-
|
|
393
|
-
return Object.getOwnPropertyNames(target);
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function ProcessEmitWarning(warning) {
|
|
397
|
-
if (console && console.warn) console.warn(warning);
|
|
398
|
-
}
|
|
399
|
-
var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) {
|
|
400
|
-
return value !== value;
|
|
401
|
-
};
|
|
402
|
-
function EventEmitter() {
|
|
403
|
-
EventEmitter.init.call(this);
|
|
404
|
-
}
|
|
405
|
-
events.exports = EventEmitter;
|
|
406
|
-
events.exports.once = once;
|
|
407
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
408
|
-
EventEmitter.prototype._events = void 0;
|
|
409
|
-
EventEmitter.prototype._eventsCount = 0;
|
|
410
|
-
EventEmitter.prototype._maxListeners = void 0;
|
|
411
|
-
var defaultMaxListeners = 10;
|
|
412
|
-
function checkListener(listener) {
|
|
413
|
-
if (typeof listener !== "function") {
|
|
414
|
-
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
Object.defineProperty(EventEmitter, "defaultMaxListeners", {
|
|
418
|
-
enumerable: true,
|
|
419
|
-
get: function() {
|
|
420
|
-
return defaultMaxListeners;
|
|
421
|
-
},
|
|
422
|
-
set: function(arg) {
|
|
423
|
-
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) {
|
|
424
|
-
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + ".");
|
|
425
|
-
}
|
|
426
|
-
defaultMaxListeners = arg;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
EventEmitter.init = function() {
|
|
430
|
-
if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) {
|
|
431
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
432
|
-
this._eventsCount = 0;
|
|
433
|
-
}
|
|
434
|
-
this._maxListeners = this._maxListeners || void 0;
|
|
435
|
-
};
|
|
436
|
-
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
437
|
-
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) {
|
|
438
|
-
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + ".");
|
|
439
|
-
}
|
|
440
|
-
this._maxListeners = n;
|
|
441
|
-
return this;
|
|
442
|
-
};
|
|
443
|
-
function _getMaxListeners(that) {
|
|
444
|
-
if (that._maxListeners === void 0)
|
|
445
|
-
return EventEmitter.defaultMaxListeners;
|
|
446
|
-
return that._maxListeners;
|
|
447
|
-
}
|
|
448
|
-
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
449
|
-
return _getMaxListeners(this);
|
|
450
|
-
};
|
|
451
|
-
EventEmitter.prototype.emit = function emit(type) {
|
|
452
|
-
var args = [];
|
|
453
|
-
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
454
|
-
var doError = type === "error";
|
|
455
|
-
var events2 = this._events;
|
|
456
|
-
if (events2 !== void 0)
|
|
457
|
-
doError = doError && events2.error === void 0;
|
|
458
|
-
else if (!doError)
|
|
459
|
-
return false;
|
|
460
|
-
if (doError) {
|
|
461
|
-
var er;
|
|
462
|
-
if (args.length > 0)
|
|
463
|
-
er = args[0];
|
|
464
|
-
if (er instanceof Error) {
|
|
465
|
-
throw er;
|
|
466
|
-
}
|
|
467
|
-
var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : ""));
|
|
468
|
-
err.context = er;
|
|
469
|
-
throw err;
|
|
470
|
-
}
|
|
471
|
-
var handler = events2[type];
|
|
472
|
-
if (handler === void 0)
|
|
473
|
-
return false;
|
|
474
|
-
if (typeof handler === "function") {
|
|
475
|
-
ReflectApply(handler, this, args);
|
|
476
|
-
} else {
|
|
477
|
-
var len = handler.length;
|
|
478
|
-
var listeners = arrayClone(handler, len);
|
|
479
|
-
for (var i = 0; i < len; ++i)
|
|
480
|
-
ReflectApply(listeners[i], this, args);
|
|
481
|
-
}
|
|
482
|
-
return true;
|
|
483
|
-
};
|
|
484
|
-
function _addListener(target, type, listener, prepend) {
|
|
485
|
-
var m;
|
|
486
|
-
var events2;
|
|
487
|
-
var existing;
|
|
488
|
-
checkListener(listener);
|
|
489
|
-
events2 = target._events;
|
|
490
|
-
if (events2 === void 0) {
|
|
491
|
-
events2 = target._events = /* @__PURE__ */ Object.create(null);
|
|
492
|
-
target._eventsCount = 0;
|
|
493
|
-
} else {
|
|
494
|
-
if (events2.newListener !== void 0) {
|
|
495
|
-
target.emit(
|
|
496
|
-
"newListener",
|
|
497
|
-
type,
|
|
498
|
-
listener.listener ? listener.listener : listener
|
|
499
|
-
);
|
|
500
|
-
events2 = target._events;
|
|
501
|
-
}
|
|
502
|
-
existing = events2[type];
|
|
503
|
-
}
|
|
504
|
-
if (existing === void 0) {
|
|
505
|
-
existing = events2[type] = listener;
|
|
506
|
-
++target._eventsCount;
|
|
507
|
-
} else {
|
|
508
|
-
if (typeof existing === "function") {
|
|
509
|
-
existing = events2[type] = prepend ? [listener, existing] : [existing, listener];
|
|
510
|
-
} else if (prepend) {
|
|
511
|
-
existing.unshift(listener);
|
|
512
|
-
} else {
|
|
513
|
-
existing.push(listener);
|
|
514
|
-
}
|
|
515
|
-
m = _getMaxListeners(target);
|
|
516
|
-
if (m > 0 && existing.length > m && !existing.warned) {
|
|
517
|
-
existing.warned = true;
|
|
518
|
-
var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
519
|
-
w.name = "MaxListenersExceededWarning";
|
|
520
|
-
w.emitter = target;
|
|
521
|
-
w.type = type;
|
|
522
|
-
w.count = existing.length;
|
|
523
|
-
ProcessEmitWarning(w);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return target;
|
|
527
|
-
}
|
|
528
|
-
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
529
|
-
return _addListener(this, type, listener, false);
|
|
530
|
-
};
|
|
531
|
-
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
532
|
-
EventEmitter.prototype.prependListener = function prependListener(type, listener) {
|
|
533
|
-
return _addListener(this, type, listener, true);
|
|
534
|
-
};
|
|
535
|
-
function onceWrapper() {
|
|
536
|
-
if (!this.fired) {
|
|
537
|
-
this.target.removeListener(this.type, this.wrapFn);
|
|
538
|
-
this.fired = true;
|
|
539
|
-
if (arguments.length === 0)
|
|
540
|
-
return this.listener.call(this.target);
|
|
541
|
-
return this.listener.apply(this.target, arguments);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function _onceWrap(target, type, listener) {
|
|
545
|
-
var state = { fired: false, wrapFn: void 0, target, type, listener };
|
|
546
|
-
var wrapped = onceWrapper.bind(state);
|
|
547
|
-
wrapped.listener = listener;
|
|
548
|
-
state.wrapFn = wrapped;
|
|
549
|
-
return wrapped;
|
|
550
|
-
}
|
|
551
|
-
EventEmitter.prototype.once = function once2(type, listener) {
|
|
552
|
-
checkListener(listener);
|
|
553
|
-
this.on(type, _onceWrap(this, type, listener));
|
|
554
|
-
return this;
|
|
555
|
-
};
|
|
556
|
-
EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
|
|
557
|
-
checkListener(listener);
|
|
558
|
-
this.prependListener(type, _onceWrap(this, type, listener));
|
|
559
|
-
return this;
|
|
560
|
-
};
|
|
561
|
-
EventEmitter.prototype.removeListener = function removeListener(type, listener) {
|
|
562
|
-
var list, events2, position, i, originalListener;
|
|
563
|
-
checkListener(listener);
|
|
564
|
-
events2 = this._events;
|
|
565
|
-
if (events2 === void 0)
|
|
566
|
-
return this;
|
|
567
|
-
list = events2[type];
|
|
568
|
-
if (list === void 0)
|
|
569
|
-
return this;
|
|
570
|
-
if (list === listener || list.listener === listener) {
|
|
571
|
-
if (--this._eventsCount === 0)
|
|
572
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
573
|
-
else {
|
|
574
|
-
delete events2[type];
|
|
575
|
-
if (events2.removeListener)
|
|
576
|
-
this.emit("removeListener", type, list.listener || listener);
|
|
577
|
-
}
|
|
578
|
-
} else if (typeof list !== "function") {
|
|
579
|
-
position = -1;
|
|
580
|
-
for (i = list.length - 1; i >= 0; i--) {
|
|
581
|
-
if (list[i] === listener || list[i].listener === listener) {
|
|
582
|
-
originalListener = list[i].listener;
|
|
583
|
-
position = i;
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
if (position < 0)
|
|
588
|
-
return this;
|
|
589
|
-
if (position === 0)
|
|
590
|
-
list.shift();
|
|
591
|
-
else {
|
|
592
|
-
spliceOne(list, position);
|
|
593
|
-
}
|
|
594
|
-
if (list.length === 1)
|
|
595
|
-
events2[type] = list[0];
|
|
596
|
-
if (events2.removeListener !== void 0)
|
|
597
|
-
this.emit("removeListener", type, originalListener || listener);
|
|
598
|
-
}
|
|
599
|
-
return this;
|
|
600
|
-
};
|
|
601
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
602
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
|
|
603
|
-
var listeners, events2, i;
|
|
604
|
-
events2 = this._events;
|
|
605
|
-
if (events2 === void 0)
|
|
606
|
-
return this;
|
|
607
|
-
if (events2.removeListener === void 0) {
|
|
608
|
-
if (arguments.length === 0) {
|
|
609
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
610
|
-
this._eventsCount = 0;
|
|
611
|
-
} else if (events2[type] !== void 0) {
|
|
612
|
-
if (--this._eventsCount === 0)
|
|
613
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
614
|
-
else
|
|
615
|
-
delete events2[type];
|
|
616
|
-
}
|
|
617
|
-
return this;
|
|
618
|
-
}
|
|
619
|
-
if (arguments.length === 0) {
|
|
620
|
-
var keys = Object.keys(events2);
|
|
621
|
-
var key;
|
|
622
|
-
for (i = 0; i < keys.length; ++i) {
|
|
623
|
-
key = keys[i];
|
|
624
|
-
if (key === "removeListener") continue;
|
|
625
|
-
this.removeAllListeners(key);
|
|
626
|
-
}
|
|
627
|
-
this.removeAllListeners("removeListener");
|
|
628
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
629
|
-
this._eventsCount = 0;
|
|
630
|
-
return this;
|
|
631
|
-
}
|
|
632
|
-
listeners = events2[type];
|
|
633
|
-
if (typeof listeners === "function") {
|
|
634
|
-
this.removeListener(type, listeners);
|
|
635
|
-
} else if (listeners !== void 0) {
|
|
636
|
-
for (i = listeners.length - 1; i >= 0; i--) {
|
|
637
|
-
this.removeListener(type, listeners[i]);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return this;
|
|
641
|
-
};
|
|
642
|
-
function _listeners(target, type, unwrap) {
|
|
643
|
-
var events2 = target._events;
|
|
644
|
-
if (events2 === void 0)
|
|
645
|
-
return [];
|
|
646
|
-
var evlistener = events2[type];
|
|
647
|
-
if (evlistener === void 0)
|
|
648
|
-
return [];
|
|
649
|
-
if (typeof evlistener === "function")
|
|
650
|
-
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
651
|
-
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
652
|
-
}
|
|
653
|
-
EventEmitter.prototype.listeners = function listeners(type) {
|
|
654
|
-
return _listeners(this, type, true);
|
|
655
|
-
};
|
|
656
|
-
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
657
|
-
return _listeners(this, type, false);
|
|
658
|
-
};
|
|
659
|
-
EventEmitter.listenerCount = function(emitter, type) {
|
|
660
|
-
if (typeof emitter.listenerCount === "function") {
|
|
661
|
-
return emitter.listenerCount(type);
|
|
662
|
-
} else {
|
|
663
|
-
return listenerCount.call(emitter, type);
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
EventEmitter.prototype.listenerCount = listenerCount;
|
|
667
|
-
function listenerCount(type) {
|
|
668
|
-
var events2 = this._events;
|
|
669
|
-
if (events2 !== void 0) {
|
|
670
|
-
var evlistener = events2[type];
|
|
671
|
-
if (typeof evlistener === "function") {
|
|
672
|
-
return 1;
|
|
673
|
-
} else if (evlistener !== void 0) {
|
|
674
|
-
return evlistener.length;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
return 0;
|
|
678
|
-
}
|
|
679
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
680
|
-
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
681
|
-
};
|
|
682
|
-
function arrayClone(arr, n) {
|
|
683
|
-
var copy = new Array(n);
|
|
684
|
-
for (var i = 0; i < n; ++i)
|
|
685
|
-
copy[i] = arr[i];
|
|
686
|
-
return copy;
|
|
687
|
-
}
|
|
688
|
-
function spliceOne(list, index) {
|
|
689
|
-
for (; index + 1 < list.length; index++)
|
|
690
|
-
list[index] = list[index + 1];
|
|
691
|
-
list.pop();
|
|
692
|
-
}
|
|
693
|
-
function unwrapListeners(arr) {
|
|
694
|
-
var ret = new Array(arr.length);
|
|
695
|
-
for (var i = 0; i < ret.length; ++i) {
|
|
696
|
-
ret[i] = arr[i].listener || arr[i];
|
|
697
|
-
}
|
|
698
|
-
return ret;
|
|
699
|
-
}
|
|
700
|
-
function once(emitter, name) {
|
|
701
|
-
return new Promise(function(resolve, reject) {
|
|
702
|
-
function errorListener(err) {
|
|
703
|
-
emitter.removeListener(name, resolver);
|
|
704
|
-
reject(err);
|
|
705
|
-
}
|
|
706
|
-
function resolver() {
|
|
707
|
-
if (typeof emitter.removeListener === "function") {
|
|
708
|
-
emitter.removeListener("error", errorListener);
|
|
709
|
-
}
|
|
710
|
-
resolve([].slice.call(arguments));
|
|
711
|
-
}
|
|
712
|
-
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
713
|
-
if (name !== "error") {
|
|
714
|
-
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
719
|
-
if (typeof emitter.on === "function") {
|
|
720
|
-
eventTargetAgnosticAddListener(emitter, "error", handler, flags);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
724
|
-
if (typeof emitter.on === "function") {
|
|
725
|
-
if (flags.once) {
|
|
726
|
-
emitter.once(name, listener);
|
|
727
|
-
} else {
|
|
728
|
-
emitter.on(name, listener);
|
|
729
|
-
}
|
|
730
|
-
} else if (typeof emitter.addEventListener === "function") {
|
|
731
|
-
emitter.addEventListener(name, function wrapListener(arg) {
|
|
732
|
-
if (flags.once) {
|
|
733
|
-
emitter.removeEventListener(name, wrapListener);
|
|
734
|
-
}
|
|
735
|
-
listener(arg);
|
|
736
|
-
});
|
|
737
|
-
} else {
|
|
738
|
-
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return events.exports;
|
|
742
|
-
}
|
|
743
|
-
var factoryValidator;
|
|
744
|
-
var hasRequiredFactoryValidator;
|
|
745
|
-
function requireFactoryValidator() {
|
|
746
|
-
if (hasRequiredFactoryValidator) return factoryValidator;
|
|
747
|
-
hasRequiredFactoryValidator = 1;
|
|
748
|
-
factoryValidator = function(factory) {
|
|
749
|
-
if (typeof factory.create !== "function") {
|
|
750
|
-
throw new TypeError("factory.create must be a function");
|
|
751
|
-
}
|
|
752
|
-
if (typeof factory.destroy !== "function") {
|
|
753
|
-
throw new TypeError("factory.destroy must be a function");
|
|
754
|
-
}
|
|
755
|
-
if (typeof factory.validate !== "undefined" && typeof factory.validate !== "function") {
|
|
756
|
-
throw new TypeError("factory.validate must be a function");
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
return factoryValidator;
|
|
760
|
-
}
|
|
761
|
-
var PoolDefaults_1;
|
|
762
|
-
var hasRequiredPoolDefaults;
|
|
763
|
-
function requirePoolDefaults() {
|
|
764
|
-
if (hasRequiredPoolDefaults) return PoolDefaults_1;
|
|
765
|
-
hasRequiredPoolDefaults = 1;
|
|
766
|
-
class PoolDefaults {
|
|
767
|
-
constructor() {
|
|
768
|
-
this.fifo = true;
|
|
769
|
-
this.priorityRange = 1;
|
|
770
|
-
this.testOnBorrow = false;
|
|
771
|
-
this.testOnReturn = false;
|
|
772
|
-
this.autostart = true;
|
|
773
|
-
this.evictionRunIntervalMillis = 0;
|
|
774
|
-
this.numTestsPerEvictionRun = 3;
|
|
775
|
-
this.softIdleTimeoutMillis = -1;
|
|
776
|
-
this.idleTimeoutMillis = 3e4;
|
|
777
|
-
this.acquireTimeoutMillis = null;
|
|
778
|
-
this.destroyTimeoutMillis = null;
|
|
779
|
-
this.maxWaitingClients = null;
|
|
780
|
-
this.min = null;
|
|
781
|
-
this.max = null;
|
|
782
|
-
this.Promise = Promise;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
PoolDefaults_1 = PoolDefaults;
|
|
786
|
-
return PoolDefaults_1;
|
|
787
|
-
}
|
|
788
|
-
var PoolOptions_1;
|
|
789
|
-
var hasRequiredPoolOptions;
|
|
790
|
-
function requirePoolOptions() {
|
|
791
|
-
if (hasRequiredPoolOptions) return PoolOptions_1;
|
|
792
|
-
hasRequiredPoolOptions = 1;
|
|
793
|
-
const PoolDefaults = requirePoolDefaults();
|
|
794
|
-
class PoolOptions {
|
|
795
|
-
/**
|
|
796
|
-
* @param {Object} opts
|
|
797
|
-
* configuration for the pool
|
|
798
|
-
* @param {Number} [opts.max=null]
|
|
799
|
-
* Maximum number of items that can exist at the same time. Default: 1.
|
|
800
|
-
* Any further acquire requests will be pushed to the waiting list.
|
|
801
|
-
* @param {Number} [opts.min=null]
|
|
802
|
-
* Minimum number of items in pool (including in-use). Default: 0.
|
|
803
|
-
* When the pool is created, or a resource destroyed, this minimum will
|
|
804
|
-
* be checked. If the pool resource count is below the minimum, a new
|
|
805
|
-
* resource will be created and added to the pool.
|
|
806
|
-
* @param {Number} [opts.maxWaitingClients=null]
|
|
807
|
-
* maximum number of queued requests allowed after which acquire calls will be rejected
|
|
808
|
-
* @param {Boolean} [opts.testOnBorrow=false]
|
|
809
|
-
* should the pool validate resources before giving them to clients. Requires that
|
|
810
|
-
* `factory.validate` is specified.
|
|
811
|
-
* @param {Boolean} [opts.testOnReturn=false]
|
|
812
|
-
* should the pool validate resources before returning them to the pool.
|
|
813
|
-
* @param {Number} [opts.acquireTimeoutMillis=null]
|
|
814
|
-
* Delay in milliseconds after which the an `acquire` call will fail. optional.
|
|
815
|
-
* Default: undefined. Should be positive and non-zero
|
|
816
|
-
* @param {Number} [opts.destroyTimeoutMillis=null]
|
|
817
|
-
* Delay in milliseconds after which the an `destroy` call will fail, causing it to emit a factoryDestroyError event. optional.
|
|
818
|
-
* Default: undefined. Should be positive and non-zero
|
|
819
|
-
* @param {Number} [opts.priorityRange=1]
|
|
820
|
-
* The range from 1 to be treated as a valid priority
|
|
821
|
-
* @param {Boolean} [opts.fifo=true]
|
|
822
|
-
* Sets whether the pool has LIFO (last in, first out) behaviour with respect to idle objects.
|
|
823
|
-
* if false then pool has FIFO behaviour
|
|
824
|
-
* @param {Boolean} [opts.autostart=true]
|
|
825
|
-
* Should the pool start creating resources etc once the constructor is called
|
|
826
|
-
* @param {Number} [opts.evictionRunIntervalMillis=0]
|
|
827
|
-
* How often to run eviction checks. Default: 0 (does not run).
|
|
828
|
-
* @param {Number} [opts.numTestsPerEvictionRun=3]
|
|
829
|
-
* Number of resources to check each eviction run. Default: 3.
|
|
830
|
-
* @param {Number} [opts.softIdleTimeoutMillis=-1]
|
|
831
|
-
* amount of time an object may sit idle in the pool before it is eligible
|
|
832
|
-
* for eviction by the idle object evictor (if any), with the extra condition
|
|
833
|
-
* that at least "min idle" object instances remain in the pool. Default -1 (nothing can get evicted)
|
|
834
|
-
* @param {Number} [opts.idleTimeoutMillis=30000]
|
|
835
|
-
* the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction
|
|
836
|
-
* due to idle time. Supercedes "softIdleTimeoutMillis" Default: 30000
|
|
837
|
-
* @param {typeof Promise} [opts.Promise=Promise]
|
|
838
|
-
* What promise implementation should the pool use, defaults to native promises.
|
|
839
|
-
*/
|
|
840
|
-
constructor(opts) {
|
|
841
|
-
const poolDefaults = new PoolDefaults();
|
|
842
|
-
opts = opts || {};
|
|
843
|
-
this.fifo = typeof opts.fifo === "boolean" ? opts.fifo : poolDefaults.fifo;
|
|
844
|
-
this.priorityRange = opts.priorityRange || poolDefaults.priorityRange;
|
|
845
|
-
this.testOnBorrow = typeof opts.testOnBorrow === "boolean" ? opts.testOnBorrow : poolDefaults.testOnBorrow;
|
|
846
|
-
this.testOnReturn = typeof opts.testOnReturn === "boolean" ? opts.testOnReturn : poolDefaults.testOnReturn;
|
|
847
|
-
this.autostart = typeof opts.autostart === "boolean" ? opts.autostart : poolDefaults.autostart;
|
|
848
|
-
if (opts.acquireTimeoutMillis) {
|
|
849
|
-
this.acquireTimeoutMillis = parseInt(opts.acquireTimeoutMillis, 10);
|
|
850
|
-
}
|
|
851
|
-
if (opts.destroyTimeoutMillis) {
|
|
852
|
-
this.destroyTimeoutMillis = parseInt(opts.destroyTimeoutMillis, 10);
|
|
853
|
-
}
|
|
854
|
-
if (opts.maxWaitingClients !== void 0) {
|
|
855
|
-
this.maxWaitingClients = parseInt(opts.maxWaitingClients, 10);
|
|
856
|
-
}
|
|
857
|
-
this.max = parseInt(opts.max, 10);
|
|
858
|
-
this.min = parseInt(opts.min, 10);
|
|
859
|
-
this.max = Math.max(isNaN(this.max) ? 1 : this.max, 1);
|
|
860
|
-
this.min = Math.min(isNaN(this.min) ? 0 : this.min, this.max);
|
|
861
|
-
this.evictionRunIntervalMillis = opts.evictionRunIntervalMillis || poolDefaults.evictionRunIntervalMillis;
|
|
862
|
-
this.numTestsPerEvictionRun = opts.numTestsPerEvictionRun || poolDefaults.numTestsPerEvictionRun;
|
|
863
|
-
this.softIdleTimeoutMillis = opts.softIdleTimeoutMillis || poolDefaults.softIdleTimeoutMillis;
|
|
864
|
-
this.idleTimeoutMillis = opts.idleTimeoutMillis || poolDefaults.idleTimeoutMillis;
|
|
865
|
-
this.Promise = opts.Promise != null ? opts.Promise : poolDefaults.Promise;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
PoolOptions_1 = PoolOptions;
|
|
869
|
-
return PoolOptions_1;
|
|
870
|
-
}
|
|
871
|
-
var Deferred_1;
|
|
872
|
-
var hasRequiredDeferred;
|
|
873
|
-
function requireDeferred() {
|
|
874
|
-
if (hasRequiredDeferred) return Deferred_1;
|
|
875
|
-
hasRequiredDeferred = 1;
|
|
876
|
-
class Deferred {
|
|
877
|
-
constructor(Promise2) {
|
|
878
|
-
this._state = Deferred.PENDING;
|
|
879
|
-
this._resolve = void 0;
|
|
880
|
-
this._reject = void 0;
|
|
881
|
-
this._promise = new Promise2((resolve, reject) => {
|
|
882
|
-
this._resolve = resolve;
|
|
883
|
-
this._reject = reject;
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
get state() {
|
|
887
|
-
return this._state;
|
|
888
|
-
}
|
|
889
|
-
get promise() {
|
|
890
|
-
return this._promise;
|
|
891
|
-
}
|
|
892
|
-
reject(reason) {
|
|
893
|
-
if (this._state !== Deferred.PENDING) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
this._state = Deferred.REJECTED;
|
|
897
|
-
this._reject(reason);
|
|
898
|
-
}
|
|
899
|
-
resolve(value) {
|
|
900
|
-
if (this._state !== Deferred.PENDING) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
this._state = Deferred.FULFILLED;
|
|
904
|
-
this._resolve(value);
|
|
905
|
-
}
|
|
78
|
+
mesh.material.forEach((material) => material.dispose());
|
|
906
79
|
}
|
|
907
|
-
Deferred.PENDING = "PENDING";
|
|
908
|
-
Deferred.FULFILLED = "FULFILLED";
|
|
909
|
-
Deferred.REJECTED = "REJECTED";
|
|
910
|
-
Deferred_1 = Deferred;
|
|
911
|
-
return Deferred_1;
|
|
912
80
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
hasRequiredErrors = 1;
|
|
918
|
-
class ExtendableError extends Error {
|
|
919
|
-
constructor(message) {
|
|
920
|
-
super(message);
|
|
921
|
-
this.name = this.constructor.name;
|
|
922
|
-
this.message = message;
|
|
923
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
924
|
-
Error.captureStackTrace(this, this.constructor);
|
|
925
|
-
} else {
|
|
926
|
-
this.stack = new Error(message).stack;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
class TimeoutError extends ExtendableError {
|
|
931
|
-
constructor(m) {
|
|
932
|
-
super(m);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
errors = {
|
|
936
|
-
TimeoutError
|
|
937
|
-
};
|
|
938
|
-
return errors;
|
|
81
|
+
function clamp(value, min, max) {
|
|
82
|
+
value = Math.min(value, max);
|
|
83
|
+
value = Math.max(value, min);
|
|
84
|
+
return value;
|
|
939
85
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
* [constructor description]
|
|
955
|
-
* @param {Number} ttl timeout
|
|
956
|
-
*/
|
|
957
|
-
constructor(ttl, Promise2) {
|
|
958
|
-
super(Promise2);
|
|
959
|
-
this._creationTimestamp = Date.now();
|
|
960
|
-
this._timeout = null;
|
|
961
|
-
if (ttl !== void 0) {
|
|
962
|
-
this.setTimeout(ttl);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
setTimeout(delay) {
|
|
966
|
-
if (this._state !== ResourceRequest.PENDING) {
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
const ttl = parseInt(delay, 10);
|
|
970
|
-
if (isNaN(ttl) || ttl <= 0) {
|
|
971
|
-
throw new Error("delay must be a positive int");
|
|
972
|
-
}
|
|
973
|
-
const age = Date.now() - this._creationTimestamp;
|
|
974
|
-
if (this._timeout) {
|
|
975
|
-
this.removeTimeout();
|
|
976
|
-
}
|
|
977
|
-
this._timeout = setTimeout(
|
|
978
|
-
fbind(this._fireTimeout, this),
|
|
979
|
-
Math.max(ttl - age, 0)
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
removeTimeout() {
|
|
983
|
-
if (this._timeout) {
|
|
984
|
-
clearTimeout(this._timeout);
|
|
985
|
-
}
|
|
986
|
-
this._timeout = null;
|
|
987
|
-
}
|
|
988
|
-
_fireTimeout() {
|
|
989
|
-
this.reject(new errors2.TimeoutError("ResourceRequest timed out"));
|
|
990
|
-
}
|
|
991
|
-
reject(reason) {
|
|
992
|
-
this.removeTimeout();
|
|
993
|
-
super.reject(reason);
|
|
994
|
-
}
|
|
995
|
-
resolve(value) {
|
|
996
|
-
this.removeTimeout();
|
|
997
|
-
super.resolve(value);
|
|
998
|
-
}
|
|
86
|
+
class AssetService {
|
|
87
|
+
constructor(eventEmitter) {
|
|
88
|
+
__publicField(this, "serviceState", "created");
|
|
89
|
+
__publicField(this, "eventEmitter");
|
|
90
|
+
__publicField(this, "meshes", /* @__PURE__ */ new Map());
|
|
91
|
+
__publicField(this, "textures", /* @__PURE__ */ new Map());
|
|
92
|
+
__publicField(this, "gltfLoader", new GLTFLoader());
|
|
93
|
+
__publicField(this, "textureLoader", new THREE.TextureLoader());
|
|
94
|
+
__publicField(this, "dracoLoader", new DRACOLoader());
|
|
95
|
+
__publicField(this, "solidColorTexture", new THREE.DataTexture(new Uint8Array([127, 127, 127, 255]), 1, 1, THREE.RGBAFormat));
|
|
96
|
+
this.eventEmitter = eventEmitter;
|
|
97
|
+
this.dracoLoader.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.7/");
|
|
98
|
+
this.gltfLoader.setDRACOLoader(this.dracoLoader);
|
|
99
|
+
this.updateServiceState("ready");
|
|
999
100
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
constructor(pooledResource, Promise2) {
|
|
1016
|
-
super(Promise2);
|
|
1017
|
-
this._creationTimestamp = Date.now();
|
|
1018
|
-
this.pooledResource = pooledResource;
|
|
1019
|
-
}
|
|
1020
|
-
reject() {
|
|
101
|
+
/**
|
|
102
|
+
* Registers an asset.
|
|
103
|
+
* @param id - The ID of the asset.
|
|
104
|
+
* @param item - The asset to set.
|
|
105
|
+
*/
|
|
106
|
+
register(id, item) {
|
|
107
|
+
item.name = id;
|
|
108
|
+
if (item instanceof THREE.Mesh) {
|
|
109
|
+
const prev = this.meshes.get(id);
|
|
110
|
+
if (prev) disposeMesh(prev);
|
|
111
|
+
this.meshes.set(id, item);
|
|
112
|
+
} else {
|
|
113
|
+
const prev = this.textures.get(id);
|
|
114
|
+
if (prev) prev.dispose();
|
|
115
|
+
this.textures.set(id, item);
|
|
1021
116
|
}
|
|
117
|
+
this.eventEmitter.emit("assetRegistered", { id });
|
|
1022
118
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
}
|
|
1026
|
-
var PooledResourceStateEnum_1;
|
|
1027
|
-
var hasRequiredPooledResourceStateEnum;
|
|
1028
|
-
function requirePooledResourceStateEnum() {
|
|
1029
|
-
if (hasRequiredPooledResourceStateEnum) return PooledResourceStateEnum_1;
|
|
1030
|
-
hasRequiredPooledResourceStateEnum = 1;
|
|
1031
|
-
const PooledResourceStateEnum = {
|
|
1032
|
-
ALLOCATED: "ALLOCATED",
|
|
1033
|
-
// In use
|
|
1034
|
-
IDLE: "IDLE",
|
|
1035
|
-
// In the queue, not in use.
|
|
1036
|
-
INVALID: "INVALID",
|
|
1037
|
-
// Failed validation
|
|
1038
|
-
RETURNING: "RETURNING",
|
|
1039
|
-
// Resource is in process of returning
|
|
1040
|
-
VALIDATION: "VALIDATION"
|
|
1041
|
-
// Currently being tested
|
|
1042
|
-
};
|
|
1043
|
-
PooledResourceStateEnum_1 = PooledResourceStateEnum;
|
|
1044
|
-
return PooledResourceStateEnum_1;
|
|
1045
|
-
}
|
|
1046
|
-
var PooledResource_1;
|
|
1047
|
-
var hasRequiredPooledResource;
|
|
1048
|
-
function requirePooledResource() {
|
|
1049
|
-
if (hasRequiredPooledResource) return PooledResource_1;
|
|
1050
|
-
hasRequiredPooledResource = 1;
|
|
1051
|
-
const PooledResourceStateEnum = requirePooledResourceStateEnum();
|
|
1052
|
-
class PooledResource {
|
|
1053
|
-
constructor(resource) {
|
|
1054
|
-
this.creationTime = Date.now();
|
|
1055
|
-
this.lastReturnTime = null;
|
|
1056
|
-
this.lastBorrowTime = null;
|
|
1057
|
-
this.lastIdleTime = null;
|
|
1058
|
-
this.obj = resource;
|
|
1059
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1060
|
-
}
|
|
1061
|
-
// mark the resource as "allocated"
|
|
1062
|
-
allocate() {
|
|
1063
|
-
this.lastBorrowTime = Date.now();
|
|
1064
|
-
this.state = PooledResourceStateEnum.ALLOCATED;
|
|
1065
|
-
}
|
|
1066
|
-
// mark the resource as "deallocated"
|
|
1067
|
-
deallocate() {
|
|
1068
|
-
this.lastReturnTime = Date.now();
|
|
1069
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1070
|
-
}
|
|
1071
|
-
invalidate() {
|
|
1072
|
-
this.state = PooledResourceStateEnum.INVALID;
|
|
1073
|
-
}
|
|
1074
|
-
test() {
|
|
1075
|
-
this.state = PooledResourceStateEnum.VALIDATION;
|
|
1076
|
-
}
|
|
1077
|
-
idle() {
|
|
1078
|
-
this.lastIdleTime = Date.now();
|
|
1079
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1080
|
-
}
|
|
1081
|
-
returning() {
|
|
1082
|
-
this.state = PooledResourceStateEnum.RETURNING;
|
|
1083
|
-
}
|
|
119
|
+
setSolidColor(color) {
|
|
120
|
+
this.changeColor(color);
|
|
1084
121
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
var DefaultEvictor_1;
|
|
1089
|
-
var hasRequiredDefaultEvictor;
|
|
1090
|
-
function requireDefaultEvictor() {
|
|
1091
|
-
if (hasRequiredDefaultEvictor) return DefaultEvictor_1;
|
|
1092
|
-
hasRequiredDefaultEvictor = 1;
|
|
1093
|
-
class DefaultEvictor {
|
|
1094
|
-
evict(config, pooledResource, availableObjectsCount) {
|
|
1095
|
-
const idleTime = Date.now() - pooledResource.lastIdleTime;
|
|
1096
|
-
if (config.softIdleTimeoutMillis > 0 && config.softIdleTimeoutMillis < idleTime && config.min < availableObjectsCount) {
|
|
1097
|
-
return true;
|
|
1098
|
-
}
|
|
1099
|
-
if (config.idleTimeoutMillis < idleTime) {
|
|
1100
|
-
return true;
|
|
1101
|
-
}
|
|
1102
|
-
return false;
|
|
1103
|
-
}
|
|
122
|
+
getSolidColorTexture() {
|
|
123
|
+
return this.solidColorTexture;
|
|
1104
124
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
}
|
|
1108
|
-
var DoublyLinkedList_1;
|
|
1109
|
-
var hasRequiredDoublyLinkedList;
|
|
1110
|
-
function requireDoublyLinkedList() {
|
|
1111
|
-
if (hasRequiredDoublyLinkedList) return DoublyLinkedList_1;
|
|
1112
|
-
hasRequiredDoublyLinkedList = 1;
|
|
1113
|
-
class DoublyLinkedList {
|
|
1114
|
-
constructor() {
|
|
1115
|
-
this.head = null;
|
|
1116
|
-
this.tail = null;
|
|
1117
|
-
this.length = 0;
|
|
1118
|
-
}
|
|
1119
|
-
insertBeginning(node) {
|
|
1120
|
-
if (this.head === null) {
|
|
1121
|
-
this.head = node;
|
|
1122
|
-
this.tail = node;
|
|
1123
|
-
node.prev = null;
|
|
1124
|
-
node.next = null;
|
|
1125
|
-
this.length++;
|
|
1126
|
-
} else {
|
|
1127
|
-
this.insertBefore(this.head, node);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
insertEnd(node) {
|
|
1131
|
-
if (this.tail === null) {
|
|
1132
|
-
this.insertBeginning(node);
|
|
1133
|
-
} else {
|
|
1134
|
-
this.insertAfter(this.tail, node);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
insertAfter(node, newNode) {
|
|
1138
|
-
newNode.prev = node;
|
|
1139
|
-
newNode.next = node.next;
|
|
1140
|
-
if (node.next === null) {
|
|
1141
|
-
this.tail = newNode;
|
|
1142
|
-
} else {
|
|
1143
|
-
node.next.prev = newNode;
|
|
1144
|
-
}
|
|
1145
|
-
node.next = newNode;
|
|
1146
|
-
this.length++;
|
|
1147
|
-
}
|
|
1148
|
-
insertBefore(node, newNode) {
|
|
1149
|
-
newNode.prev = node.prev;
|
|
1150
|
-
newNode.next = node;
|
|
1151
|
-
if (node.prev === null) {
|
|
1152
|
-
this.head = newNode;
|
|
1153
|
-
} else {
|
|
1154
|
-
node.prev.next = newNode;
|
|
1155
|
-
}
|
|
1156
|
-
node.prev = newNode;
|
|
1157
|
-
this.length++;
|
|
1158
|
-
}
|
|
1159
|
-
remove(node) {
|
|
1160
|
-
if (node.prev === null) {
|
|
1161
|
-
this.head = node.next;
|
|
1162
|
-
} else {
|
|
1163
|
-
node.prev.next = node.next;
|
|
1164
|
-
}
|
|
1165
|
-
if (node.next === null) {
|
|
1166
|
-
this.tail = node.prev;
|
|
1167
|
-
} else {
|
|
1168
|
-
node.next.prev = node.prev;
|
|
1169
|
-
}
|
|
1170
|
-
node.prev = null;
|
|
1171
|
-
node.next = null;
|
|
1172
|
-
this.length--;
|
|
1173
|
-
}
|
|
1174
|
-
// FIXME: this should not live here and has become a dumping ground...
|
|
1175
|
-
static createNode(data) {
|
|
1176
|
-
return {
|
|
1177
|
-
prev: null,
|
|
1178
|
-
next: null,
|
|
1179
|
-
data
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
125
|
+
getMesh(id) {
|
|
126
|
+
return this.meshes.get(id) ?? null;
|
|
1182
127
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
var hasRequiredDoublyLinkedListIterator;
|
|
1188
|
-
function requireDoublyLinkedListIterator() {
|
|
1189
|
-
if (hasRequiredDoublyLinkedListIterator) return DoublyLinkedListIterator_1;
|
|
1190
|
-
hasRequiredDoublyLinkedListIterator = 1;
|
|
1191
|
-
class DoublyLinkedListIterator {
|
|
1192
|
-
/**
|
|
1193
|
-
* @param {Object} doublyLinkedList a node that is part of a doublyLinkedList
|
|
1194
|
-
* @param {Boolean} [reverse=false] is this a reverse iterator? default: false
|
|
1195
|
-
*/
|
|
1196
|
-
constructor(doublyLinkedList, reverse) {
|
|
1197
|
-
this._list = doublyLinkedList;
|
|
1198
|
-
this._direction = reverse === true ? "prev" : "next";
|
|
1199
|
-
this._startPosition = reverse === true ? "tail" : "head";
|
|
1200
|
-
this._started = false;
|
|
1201
|
-
this._cursor = null;
|
|
1202
|
-
this._done = false;
|
|
1203
|
-
}
|
|
1204
|
-
_start() {
|
|
1205
|
-
this._cursor = this._list[this._startPosition];
|
|
1206
|
-
this._started = true;
|
|
1207
|
-
}
|
|
1208
|
-
_advanceCursor() {
|
|
1209
|
-
if (this._started === false) {
|
|
1210
|
-
this._started = true;
|
|
1211
|
-
this._cursor = this._list[this._startPosition];
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
this._cursor = this._cursor[this._direction];
|
|
1215
|
-
}
|
|
1216
|
-
reset() {
|
|
1217
|
-
this._done = false;
|
|
1218
|
-
this._started = false;
|
|
1219
|
-
this._cursor = null;
|
|
1220
|
-
}
|
|
1221
|
-
remove() {
|
|
1222
|
-
if (this._started === false || this._done === true || this._isCursorDetached()) {
|
|
1223
|
-
return false;
|
|
1224
|
-
}
|
|
1225
|
-
this._list.remove(this._cursor);
|
|
1226
|
-
}
|
|
1227
|
-
next() {
|
|
1228
|
-
if (this._done === true) {
|
|
1229
|
-
return { done: true };
|
|
1230
|
-
}
|
|
1231
|
-
this._advanceCursor();
|
|
1232
|
-
if (this._cursor === null || this._isCursorDetached()) {
|
|
1233
|
-
this._done = true;
|
|
1234
|
-
return { done: true };
|
|
1235
|
-
}
|
|
1236
|
-
return {
|
|
1237
|
-
value: this._cursor,
|
|
1238
|
-
done: false
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Is the node detached from a list?
|
|
1243
|
-
* NOTE: you can trick/bypass/confuse this check by removing a node from one DoublyLinkedList
|
|
1244
|
-
* and adding it to another.
|
|
1245
|
-
* TODO: We can make this smarter by checking the direction of travel and only checking
|
|
1246
|
-
* the required next/prev/head/tail rather than all of them
|
|
1247
|
-
* @return {Boolean} [description]
|
|
1248
|
-
*/
|
|
1249
|
-
_isCursorDetached() {
|
|
1250
|
-
return this._cursor.prev === null && this._cursor.next === null && this._list.tail !== this._cursor && this._list.head !== this._cursor;
|
|
1251
|
-
}
|
|
128
|
+
getMatcap(id) {
|
|
129
|
+
const texture = this.textures.get(id);
|
|
130
|
+
if (!texture) this.eventEmitter.emit("invalidRequest", { message: `texture with id "${id}" not found. using solid color texture instead...` });
|
|
131
|
+
return texture ?? this.solidColorTexture;
|
|
1252
132
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
}
|
|
1256
|
-
var DequeIterator_1;
|
|
1257
|
-
var hasRequiredDequeIterator;
|
|
1258
|
-
function requireDequeIterator() {
|
|
1259
|
-
if (hasRequiredDequeIterator) return DequeIterator_1;
|
|
1260
|
-
hasRequiredDequeIterator = 1;
|
|
1261
|
-
const DoublyLinkedListIterator = requireDoublyLinkedListIterator();
|
|
1262
|
-
class DequeIterator extends DoublyLinkedListIterator {
|
|
1263
|
-
next() {
|
|
1264
|
-
const result = super.next();
|
|
1265
|
-
if (result.value) {
|
|
1266
|
-
result.value = result.value.data;
|
|
1267
|
-
}
|
|
1268
|
-
return result;
|
|
1269
|
-
}
|
|
133
|
+
getMeshIDs() {
|
|
134
|
+
return Array.from(this.meshes.keys());
|
|
1270
135
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
}
|
|
1274
|
-
var Deque_1;
|
|
1275
|
-
var hasRequiredDeque;
|
|
1276
|
-
function requireDeque() {
|
|
1277
|
-
if (hasRequiredDeque) return Deque_1;
|
|
1278
|
-
hasRequiredDeque = 1;
|
|
1279
|
-
const DoublyLinkedList = requireDoublyLinkedList();
|
|
1280
|
-
const DequeIterator = requireDequeIterator();
|
|
1281
|
-
class Deque {
|
|
1282
|
-
constructor() {
|
|
1283
|
-
this._list = new DoublyLinkedList();
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* removes and returns the first element from the queue
|
|
1287
|
-
* @return {any} [description]
|
|
1288
|
-
*/
|
|
1289
|
-
shift() {
|
|
1290
|
-
if (this.length === 0) {
|
|
1291
|
-
return void 0;
|
|
1292
|
-
}
|
|
1293
|
-
const node = this._list.head;
|
|
1294
|
-
this._list.remove(node);
|
|
1295
|
-
return node.data;
|
|
1296
|
-
}
|
|
1297
|
-
/**
|
|
1298
|
-
* adds one elemts to the beginning of the queue
|
|
1299
|
-
* @param {any} element [description]
|
|
1300
|
-
* @return {any} [description]
|
|
1301
|
-
*/
|
|
1302
|
-
unshift(element) {
|
|
1303
|
-
const node = DoublyLinkedList.createNode(element);
|
|
1304
|
-
this._list.insertBeginning(node);
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* adds one to the end of the queue
|
|
1308
|
-
* @param {any} element [description]
|
|
1309
|
-
* @return {any} [description]
|
|
1310
|
-
*/
|
|
1311
|
-
push(element) {
|
|
1312
|
-
const node = DoublyLinkedList.createNode(element);
|
|
1313
|
-
this._list.insertEnd(node);
|
|
1314
|
-
}
|
|
1315
|
-
/**
|
|
1316
|
-
* removes and returns the last element from the queue
|
|
1317
|
-
*/
|
|
1318
|
-
pop() {
|
|
1319
|
-
if (this.length === 0) {
|
|
1320
|
-
return void 0;
|
|
1321
|
-
}
|
|
1322
|
-
const node = this._list.tail;
|
|
1323
|
-
this._list.remove(node);
|
|
1324
|
-
return node.data;
|
|
1325
|
-
}
|
|
1326
|
-
[Symbol.iterator]() {
|
|
1327
|
-
return new DequeIterator(this._list);
|
|
1328
|
-
}
|
|
1329
|
-
iterator() {
|
|
1330
|
-
return new DequeIterator(this._list);
|
|
1331
|
-
}
|
|
1332
|
-
reverseIterator() {
|
|
1333
|
-
return new DequeIterator(this._list, true);
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* get a reference to the item at the head of the queue
|
|
1337
|
-
* @return {any} [description]
|
|
1338
|
-
*/
|
|
1339
|
-
get head() {
|
|
1340
|
-
if (this.length === 0) {
|
|
1341
|
-
return void 0;
|
|
1342
|
-
}
|
|
1343
|
-
const node = this._list.head;
|
|
1344
|
-
return node.data;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* get a reference to the item at the tail of the queue
|
|
1348
|
-
* @return {any} [description]
|
|
1349
|
-
*/
|
|
1350
|
-
get tail() {
|
|
1351
|
-
if (this.length === 0) {
|
|
1352
|
-
return void 0;
|
|
1353
|
-
}
|
|
1354
|
-
const node = this._list.tail;
|
|
1355
|
-
return node.data;
|
|
1356
|
-
}
|
|
1357
|
-
get length() {
|
|
1358
|
-
return this._list.length;
|
|
1359
|
-
}
|
|
136
|
+
getTextureIDs() {
|
|
137
|
+
return Array.from(this.textures.keys());
|
|
1360
138
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
}
|
|
1364
|
-
var Queue_1;
|
|
1365
|
-
var hasRequiredQueue;
|
|
1366
|
-
function requireQueue() {
|
|
1367
|
-
if (hasRequiredQueue) return Queue_1;
|
|
1368
|
-
hasRequiredQueue = 1;
|
|
1369
|
-
const DoublyLinkedList = requireDoublyLinkedList();
|
|
1370
|
-
const Deque = requireDeque();
|
|
1371
|
-
class Queue extends Deque {
|
|
1372
|
-
/**
|
|
1373
|
-
* Adds the obj to the end of the list for this slot
|
|
1374
|
-
* we completely override the parent method because we need access to the
|
|
1375
|
-
* node for our rejection handler
|
|
1376
|
-
* @param {any} resourceRequest [description]
|
|
1377
|
-
*/
|
|
1378
|
-
push(resourceRequest) {
|
|
1379
|
-
const node = DoublyLinkedList.createNode(resourceRequest);
|
|
1380
|
-
resourceRequest.promise.catch(this._createTimeoutRejectionHandler(node));
|
|
1381
|
-
this._list.insertEnd(node);
|
|
1382
|
-
}
|
|
1383
|
-
_createTimeoutRejectionHandler(node) {
|
|
1384
|
-
return (reason) => {
|
|
1385
|
-
if (reason.name === "TimeoutError") {
|
|
1386
|
-
this._list.remove(node);
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
}
|
|
139
|
+
getMeshes() {
|
|
140
|
+
return Array.from(this.meshes.values());
|
|
1390
141
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1394
|
-
var PriorityQueue_1;
|
|
1395
|
-
var hasRequiredPriorityQueue;
|
|
1396
|
-
function requirePriorityQueue() {
|
|
1397
|
-
if (hasRequiredPriorityQueue) return PriorityQueue_1;
|
|
1398
|
-
hasRequiredPriorityQueue = 1;
|
|
1399
|
-
const Queue = requireQueue();
|
|
1400
|
-
class PriorityQueue {
|
|
1401
|
-
constructor(size) {
|
|
1402
|
-
this._size = Math.max(+size | 0, 1);
|
|
1403
|
-
this._slots = [];
|
|
1404
|
-
for (let i = 0; i < this._size; i++) {
|
|
1405
|
-
this._slots.push(new Queue());
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
get length() {
|
|
1409
|
-
let _length = 0;
|
|
1410
|
-
for (let i = 0, slots = this._slots.length; i < slots; i++) {
|
|
1411
|
-
_length += this._slots[i].length;
|
|
1412
|
-
}
|
|
1413
|
-
return _length;
|
|
1414
|
-
}
|
|
1415
|
-
enqueue(obj, priority) {
|
|
1416
|
-
priority = priority && +priority | 0 || 0;
|
|
1417
|
-
if (priority) {
|
|
1418
|
-
if (priority < 0 || priority >= this._size) {
|
|
1419
|
-
priority = this._size - 1;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
this._slots[priority].push(obj);
|
|
1423
|
-
}
|
|
1424
|
-
dequeue() {
|
|
1425
|
-
for (let i = 0, sl = this._slots.length; i < sl; i += 1) {
|
|
1426
|
-
if (this._slots[i].length) {
|
|
1427
|
-
return this._slots[i].shift();
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
get head() {
|
|
1433
|
-
for (let i = 0, sl = this._slots.length; i < sl; i += 1) {
|
|
1434
|
-
if (this._slots[i].length > 0) {
|
|
1435
|
-
return this._slots[i].head;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
get tail() {
|
|
1441
|
-
for (let i = this._slots.length - 1; i >= 0; i--) {
|
|
1442
|
-
if (this._slots[i].length > 0) {
|
|
1443
|
-
return this._slots[i].tail;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
return;
|
|
1447
|
-
}
|
|
142
|
+
getTextures() {
|
|
143
|
+
return Array.from(this.textures.values());
|
|
1448
144
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
if (hasRequiredPool) return Pool_1;
|
|
1468
|
-
hasRequiredPool = 1;
|
|
1469
|
-
const EventEmitter = requireEvents().EventEmitter;
|
|
1470
|
-
const factoryValidator2 = requireFactoryValidator();
|
|
1471
|
-
const PoolOptions = requirePoolOptions();
|
|
1472
|
-
const ResourceRequest = requireResourceRequest();
|
|
1473
|
-
const ResourceLoan = requireResourceLoan();
|
|
1474
|
-
const PooledResource = requirePooledResource();
|
|
1475
|
-
requireDefaultEvictor();
|
|
1476
|
-
requireDeque();
|
|
1477
|
-
const Deferred = requireDeferred();
|
|
1478
|
-
requirePriorityQueue();
|
|
1479
|
-
requireDequeIterator();
|
|
1480
|
-
const reflector = requireUtils().reflector;
|
|
1481
|
-
const FACTORY_CREATE_ERROR = "factoryCreateError";
|
|
1482
|
-
const FACTORY_DESTROY_ERROR = "factoryDestroyError";
|
|
1483
|
-
class Pool extends EventEmitter {
|
|
1484
|
-
/**
|
|
1485
|
-
* Generate an Object pool with a specified `factory` and `config`.
|
|
1486
|
-
*
|
|
1487
|
-
* @param {typeof DefaultEvictor} Evictor
|
|
1488
|
-
* @param {typeof Deque} Deque
|
|
1489
|
-
* @param {typeof PriorityQueue} PriorityQueue
|
|
1490
|
-
* @param {Object} factory
|
|
1491
|
-
* Factory to be used for generating and destroying the items.
|
|
1492
|
-
* @param {Function} factory.create
|
|
1493
|
-
* Should create the item to be acquired,
|
|
1494
|
-
* and call it's first callback argument with the generated item as it's argument.
|
|
1495
|
-
* @param {Function} factory.destroy
|
|
1496
|
-
* Should gently close any resources that the item is using.
|
|
1497
|
-
* Called before the items is destroyed.
|
|
1498
|
-
* @param {Function} factory.validate
|
|
1499
|
-
* Test if a resource is still valid .Should return a promise that resolves to a boolean, true if resource is still valid and false
|
|
1500
|
-
* If it should be removed from pool.
|
|
1501
|
-
* @param {Object} options
|
|
1502
|
-
*/
|
|
1503
|
-
constructor(Evictor, Deque, PriorityQueue, factory, options) {
|
|
1504
|
-
super();
|
|
1505
|
-
factoryValidator2(factory);
|
|
1506
|
-
this._config = new PoolOptions(options);
|
|
1507
|
-
this._Promise = this._config.Promise;
|
|
1508
|
-
this._factory = factory;
|
|
1509
|
-
this._draining = false;
|
|
1510
|
-
this._started = false;
|
|
1511
|
-
this._waitingClientsQueue = new PriorityQueue(this._config.priorityRange);
|
|
1512
|
-
this._factoryCreateOperations = /* @__PURE__ */ new Set();
|
|
1513
|
-
this._factoryDestroyOperations = /* @__PURE__ */ new Set();
|
|
1514
|
-
this._availableObjects = new Deque();
|
|
1515
|
-
this._testOnBorrowResources = /* @__PURE__ */ new Set();
|
|
1516
|
-
this._testOnReturnResources = /* @__PURE__ */ new Set();
|
|
1517
|
-
this._validationOperations = /* @__PURE__ */ new Set();
|
|
1518
|
-
this._allObjects = /* @__PURE__ */ new Set();
|
|
1519
|
-
this._resourceLoans = /* @__PURE__ */ new Map();
|
|
1520
|
-
this._evictionIterator = this._availableObjects.iterator();
|
|
1521
|
-
this._evictor = new Evictor();
|
|
1522
|
-
this._scheduledEviction = null;
|
|
1523
|
-
if (this._config.autostart === true) {
|
|
1524
|
-
this.start();
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
_destroy(pooledResource) {
|
|
1528
|
-
pooledResource.invalidate();
|
|
1529
|
-
this._allObjects.delete(pooledResource);
|
|
1530
|
-
const destroyPromise = this._factory.destroy(pooledResource.obj);
|
|
1531
|
-
const wrappedDestroyPromise = this._config.destroyTimeoutMillis ? this._Promise.resolve(this._applyDestroyTimeout(destroyPromise)) : this._Promise.resolve(destroyPromise);
|
|
1532
|
-
this._trackOperation(
|
|
1533
|
-
wrappedDestroyPromise,
|
|
1534
|
-
this._factoryDestroyOperations
|
|
1535
|
-
).catch((reason) => {
|
|
1536
|
-
this.emit(FACTORY_DESTROY_ERROR, reason);
|
|
1537
|
-
});
|
|
1538
|
-
this._ensureMinimum();
|
|
1539
|
-
}
|
|
1540
|
-
_applyDestroyTimeout(promise) {
|
|
1541
|
-
const timeoutPromise = new this._Promise((resolve, reject) => {
|
|
1542
|
-
setTimeout(() => {
|
|
1543
|
-
reject(new Error("destroy timed out"));
|
|
1544
|
-
}, this._config.destroyTimeoutMillis).unref();
|
|
1545
|
-
});
|
|
1546
|
-
return this._Promise.race([timeoutPromise, promise]);
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Attempt to move an available resource into test and then onto a waiting client
|
|
1550
|
-
* @return {Boolean} could we move an available resource into test
|
|
1551
|
-
*/
|
|
1552
|
-
_testOnBorrow() {
|
|
1553
|
-
if (this._availableObjects.length < 1) {
|
|
1554
|
-
return false;
|
|
1555
|
-
}
|
|
1556
|
-
const pooledResource = this._availableObjects.shift();
|
|
1557
|
-
pooledResource.test();
|
|
1558
|
-
this._testOnBorrowResources.add(pooledResource);
|
|
1559
|
-
const validationPromise = this._factory.validate(pooledResource.obj);
|
|
1560
|
-
const wrappedValidationPromise = this._Promise.resolve(validationPromise);
|
|
1561
|
-
this._trackOperation(
|
|
1562
|
-
wrappedValidationPromise,
|
|
1563
|
-
this._validationOperations
|
|
1564
|
-
).then((isValid) => {
|
|
1565
|
-
this._testOnBorrowResources.delete(pooledResource);
|
|
1566
|
-
if (isValid === false) {
|
|
1567
|
-
pooledResource.invalidate();
|
|
1568
|
-
this._destroy(pooledResource);
|
|
1569
|
-
this._dispense();
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
this._dispatchPooledResourceToNextWaitingClient(pooledResource);
|
|
1573
|
-
});
|
|
1574
|
-
return true;
|
|
1575
|
-
}
|
|
1576
|
-
/**
|
|
1577
|
-
* Attempt to move an available resource to a waiting client
|
|
1578
|
-
* @return {Boolean} [description]
|
|
1579
|
-
*/
|
|
1580
|
-
_dispatchResource() {
|
|
1581
|
-
if (this._availableObjects.length < 1) {
|
|
1582
|
-
return false;
|
|
1583
|
-
}
|
|
1584
|
-
const pooledResource = this._availableObjects.shift();
|
|
1585
|
-
this._dispatchPooledResourceToNextWaitingClient(pooledResource);
|
|
1586
|
-
return false;
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Attempt to resolve an outstanding resource request using an available resource from
|
|
1590
|
-
* the pool, or creating new ones
|
|
1591
|
-
*
|
|
1592
|
-
* @private
|
|
1593
|
-
*/
|
|
1594
|
-
_dispense() {
|
|
1595
|
-
const numWaitingClients = this._waitingClientsQueue.length;
|
|
1596
|
-
if (numWaitingClients < 1) {
|
|
1597
|
-
return;
|
|
1598
|
-
}
|
|
1599
|
-
const resourceShortfall = numWaitingClients - this._potentiallyAllocableResourceCount;
|
|
1600
|
-
const actualNumberOfResourcesToCreate = Math.min(
|
|
1601
|
-
this.spareResourceCapacity,
|
|
1602
|
-
resourceShortfall
|
|
1603
|
-
);
|
|
1604
|
-
for (let i = 0; actualNumberOfResourcesToCreate > i; i++) {
|
|
1605
|
-
this._createResource();
|
|
1606
|
-
}
|
|
1607
|
-
if (this._config.testOnBorrow === true) {
|
|
1608
|
-
const desiredNumberOfResourcesToMoveIntoTest = numWaitingClients - this._testOnBorrowResources.size;
|
|
1609
|
-
const actualNumberOfResourcesToMoveIntoTest = Math.min(
|
|
1610
|
-
this._availableObjects.length,
|
|
1611
|
-
desiredNumberOfResourcesToMoveIntoTest
|
|
1612
|
-
);
|
|
1613
|
-
for (let i = 0; actualNumberOfResourcesToMoveIntoTest > i; i++) {
|
|
1614
|
-
this._testOnBorrow();
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
if (this._config.testOnBorrow === false) {
|
|
1618
|
-
const actualNumberOfResourcesToDispatch = Math.min(
|
|
1619
|
-
this._availableObjects.length,
|
|
1620
|
-
numWaitingClients
|
|
1621
|
-
);
|
|
1622
|
-
for (let i = 0; actualNumberOfResourcesToDispatch > i; i++) {
|
|
1623
|
-
this._dispatchResource();
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Dispatches a pooledResource to the next waiting client (if any) else
|
|
1629
|
-
* puts the PooledResource back on the available list
|
|
1630
|
-
* @param {PooledResource} pooledResource [description]
|
|
1631
|
-
* @return {Boolean} [description]
|
|
1632
|
-
*/
|
|
1633
|
-
_dispatchPooledResourceToNextWaitingClient(pooledResource) {
|
|
1634
|
-
const clientResourceRequest = this._waitingClientsQueue.dequeue();
|
|
1635
|
-
if (clientResourceRequest === void 0 || clientResourceRequest.state !== Deferred.PENDING) {
|
|
1636
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1637
|
-
return false;
|
|
1638
|
-
}
|
|
1639
|
-
const loan = new ResourceLoan(pooledResource, this._Promise);
|
|
1640
|
-
this._resourceLoans.set(pooledResource.obj, loan);
|
|
1641
|
-
pooledResource.allocate();
|
|
1642
|
-
clientResourceRequest.resolve(pooledResource.obj);
|
|
1643
|
-
return true;
|
|
1644
|
-
}
|
|
1645
|
-
/**
|
|
1646
|
-
* tracks on operation using given set
|
|
1647
|
-
* handles adding/removing from the set and resolve/rejects the value/reason
|
|
1648
|
-
* @param {Promise} operation
|
|
1649
|
-
* @param {Set} set Set holding operations
|
|
1650
|
-
* @return {Promise} Promise that resolves once operation has been removed from set
|
|
1651
|
-
*/
|
|
1652
|
-
_trackOperation(operation, set) {
|
|
1653
|
-
set.add(operation);
|
|
1654
|
-
return operation.then(
|
|
1655
|
-
(v) => {
|
|
1656
|
-
set.delete(operation);
|
|
1657
|
-
return this._Promise.resolve(v);
|
|
1658
|
-
},
|
|
1659
|
-
(e) => {
|
|
1660
|
-
set.delete(operation);
|
|
1661
|
-
return this._Promise.reject(e);
|
|
1662
|
-
}
|
|
1663
|
-
);
|
|
1664
|
-
}
|
|
1665
|
-
/**
|
|
1666
|
-
* @private
|
|
1667
|
-
*/
|
|
1668
|
-
_createResource() {
|
|
1669
|
-
const factoryPromise = this._factory.create();
|
|
1670
|
-
const wrappedFactoryPromise = this._Promise.resolve(factoryPromise).then((resource) => {
|
|
1671
|
-
const pooledResource = new PooledResource(resource);
|
|
1672
|
-
this._allObjects.add(pooledResource);
|
|
1673
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1674
|
-
});
|
|
1675
|
-
this._trackOperation(wrappedFactoryPromise, this._factoryCreateOperations).then(() => {
|
|
1676
|
-
this._dispense();
|
|
1677
|
-
return null;
|
|
1678
|
-
}).catch((reason) => {
|
|
1679
|
-
this.emit(FACTORY_CREATE_ERROR, reason);
|
|
1680
|
-
this._dispense();
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
/**
|
|
1684
|
-
* @private
|
|
1685
|
-
*/
|
|
1686
|
-
_ensureMinimum() {
|
|
1687
|
-
if (this._draining === true) {
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
const minShortfall = this._config.min - this._count;
|
|
1691
|
-
for (let i = 0; i < minShortfall; i++) {
|
|
1692
|
-
this._createResource();
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
_evict() {
|
|
1696
|
-
const testsToRun = Math.min(
|
|
1697
|
-
this._config.numTestsPerEvictionRun,
|
|
1698
|
-
this._availableObjects.length
|
|
1699
|
-
);
|
|
1700
|
-
const evictionConfig = {
|
|
1701
|
-
softIdleTimeoutMillis: this._config.softIdleTimeoutMillis,
|
|
1702
|
-
idleTimeoutMillis: this._config.idleTimeoutMillis,
|
|
1703
|
-
min: this._config.min
|
|
1704
|
-
};
|
|
1705
|
-
for (let testsHaveRun = 0; testsHaveRun < testsToRun; ) {
|
|
1706
|
-
const iterationResult = this._evictionIterator.next();
|
|
1707
|
-
if (iterationResult.done === true && this._availableObjects.length < 1) {
|
|
1708
|
-
this._evictionIterator.reset();
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
if (iterationResult.done === true && this._availableObjects.length > 0) {
|
|
1712
|
-
this._evictionIterator.reset();
|
|
1713
|
-
continue;
|
|
1714
|
-
}
|
|
1715
|
-
const resource = iterationResult.value;
|
|
1716
|
-
const shouldEvict = this._evictor.evict(
|
|
1717
|
-
evictionConfig,
|
|
1718
|
-
resource,
|
|
1719
|
-
this._availableObjects.length
|
|
1720
|
-
);
|
|
1721
|
-
testsHaveRun++;
|
|
1722
|
-
if (shouldEvict === true) {
|
|
1723
|
-
this._evictionIterator.remove();
|
|
1724
|
-
this._destroy(resource);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
_scheduleEvictorRun() {
|
|
1729
|
-
if (this._config.evictionRunIntervalMillis > 0) {
|
|
1730
|
-
this._scheduledEviction = setTimeout(() => {
|
|
1731
|
-
this._evict();
|
|
1732
|
-
this._scheduleEvictorRun();
|
|
1733
|
-
}, this._config.evictionRunIntervalMillis).unref();
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
_descheduleEvictorRun() {
|
|
1737
|
-
if (this._scheduledEviction) {
|
|
1738
|
-
clearTimeout(this._scheduledEviction);
|
|
1739
|
-
}
|
|
1740
|
-
this._scheduledEviction = null;
|
|
1741
|
-
}
|
|
1742
|
-
start() {
|
|
1743
|
-
if (this._draining === true) {
|
|
1744
|
-
return;
|
|
1745
|
-
}
|
|
1746
|
-
if (this._started === true) {
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
1749
|
-
this._started = true;
|
|
1750
|
-
this._scheduleEvictorRun();
|
|
1751
|
-
this._ensureMinimum();
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Request a new resource. The callback will be called,
|
|
1755
|
-
* when a new resource is available, passing the resource to the callback.
|
|
1756
|
-
* TODO: should we add a seperate "acquireWithPriority" function
|
|
1757
|
-
*
|
|
1758
|
-
* @param {Number} [priority=0]
|
|
1759
|
-
* Optional. Integer between 0 and (priorityRange - 1). Specifies the priority
|
|
1760
|
-
* of the caller if there are no available resources. Lower numbers mean higher
|
|
1761
|
-
* priority.
|
|
1762
|
-
*
|
|
1763
|
-
* @returns {Promise}
|
|
1764
|
-
*/
|
|
1765
|
-
acquire(priority) {
|
|
1766
|
-
if (this._started === false && this._config.autostart === false) {
|
|
1767
|
-
this.start();
|
|
1768
|
-
}
|
|
1769
|
-
if (this._draining) {
|
|
1770
|
-
return this._Promise.reject(
|
|
1771
|
-
new Error("pool is draining and cannot accept work")
|
|
1772
|
-
);
|
|
1773
|
-
}
|
|
1774
|
-
if (this.spareResourceCapacity < 1 && this._availableObjects.length < 1 && this._config.maxWaitingClients !== void 0 && this._waitingClientsQueue.length >= this._config.maxWaitingClients) {
|
|
1775
|
-
return this._Promise.reject(
|
|
1776
|
-
new Error("max waitingClients count exceeded")
|
|
1777
|
-
);
|
|
1778
|
-
}
|
|
1779
|
-
const resourceRequest = new ResourceRequest(
|
|
1780
|
-
this._config.acquireTimeoutMillis,
|
|
1781
|
-
this._Promise
|
|
1782
|
-
);
|
|
1783
|
-
this._waitingClientsQueue.enqueue(resourceRequest, priority);
|
|
1784
|
-
this._dispense();
|
|
1785
|
-
return resourceRequest.promise;
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* [use method, aquires a resource, passes the resource to a user supplied function and releases it]
|
|
1789
|
-
* @param {Function} fn [a function that accepts a resource and returns a promise that resolves/rejects once it has finished using the resource]
|
|
1790
|
-
* @return {Promise} [resolves once the resource is released to the pool]
|
|
1791
|
-
*/
|
|
1792
|
-
use(fn, priority) {
|
|
1793
|
-
return this.acquire(priority).then((resource) => {
|
|
1794
|
-
return fn(resource).then(
|
|
1795
|
-
(result) => {
|
|
1796
|
-
this.release(resource);
|
|
1797
|
-
return result;
|
|
1798
|
-
},
|
|
1799
|
-
(err) => {
|
|
1800
|
-
this.destroy(resource);
|
|
1801
|
-
throw err;
|
|
1802
|
-
}
|
|
1803
|
-
);
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
/**
|
|
1807
|
-
* Check if resource is currently on loan from the pool
|
|
1808
|
-
*
|
|
1809
|
-
* @param {Function} resource
|
|
1810
|
-
* Resource for checking.
|
|
1811
|
-
*
|
|
1812
|
-
* @returns {Boolean}
|
|
1813
|
-
* True if resource belongs to this pool and false otherwise
|
|
1814
|
-
*/
|
|
1815
|
-
isBorrowedResource(resource) {
|
|
1816
|
-
return this._resourceLoans.has(resource);
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Return the resource to the pool when it is no longer required.
|
|
1820
|
-
*
|
|
1821
|
-
* @param {Object} resource
|
|
1822
|
-
* The acquired object to be put back to the pool.
|
|
1823
|
-
*/
|
|
1824
|
-
release(resource) {
|
|
1825
|
-
const loan = this._resourceLoans.get(resource);
|
|
1826
|
-
if (loan === void 0) {
|
|
1827
|
-
return this._Promise.reject(
|
|
1828
|
-
new Error("Resource not currently part of this pool")
|
|
1829
|
-
);
|
|
1830
|
-
}
|
|
1831
|
-
this._resourceLoans.delete(resource);
|
|
1832
|
-
loan.resolve();
|
|
1833
|
-
const pooledResource = loan.pooledResource;
|
|
1834
|
-
pooledResource.deallocate();
|
|
1835
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1836
|
-
this._dispense();
|
|
1837
|
-
return this._Promise.resolve();
|
|
1838
|
-
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Request the resource to be destroyed. The factory's destroy handler
|
|
1841
|
-
* will also be called.
|
|
1842
|
-
*
|
|
1843
|
-
* This should be called within an acquire() block as an alternative to release().
|
|
1844
|
-
*
|
|
1845
|
-
* @param {Object} resource
|
|
1846
|
-
* The acquired resource to be destoyed.
|
|
1847
|
-
*/
|
|
1848
|
-
destroy(resource) {
|
|
1849
|
-
const loan = this._resourceLoans.get(resource);
|
|
1850
|
-
if (loan === void 0) {
|
|
1851
|
-
return this._Promise.reject(
|
|
1852
|
-
new Error("Resource not currently part of this pool")
|
|
1853
|
-
);
|
|
1854
|
-
}
|
|
1855
|
-
this._resourceLoans.delete(resource);
|
|
1856
|
-
loan.resolve();
|
|
1857
|
-
const pooledResource = loan.pooledResource;
|
|
1858
|
-
pooledResource.deallocate();
|
|
1859
|
-
this._destroy(pooledResource);
|
|
1860
|
-
this._dispense();
|
|
1861
|
-
return this._Promise.resolve();
|
|
1862
|
-
}
|
|
1863
|
-
_addPooledResourceToAvailableObjects(pooledResource) {
|
|
1864
|
-
pooledResource.idle();
|
|
1865
|
-
if (this._config.fifo === true) {
|
|
1866
|
-
this._availableObjects.push(pooledResource);
|
|
1867
|
-
} else {
|
|
1868
|
-
this._availableObjects.unshift(pooledResource);
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Disallow any new acquire calls and let the request backlog dissapate.
|
|
1873
|
-
* The Pool will no longer attempt to maintain a "min" number of resources
|
|
1874
|
-
* and will only make new resources on demand.
|
|
1875
|
-
* Resolves once all resource requests are fulfilled and all resources are returned to pool and available...
|
|
1876
|
-
* Should probably be called "drain work"
|
|
1877
|
-
* @returns {Promise}
|
|
1878
|
-
*/
|
|
1879
|
-
drain() {
|
|
1880
|
-
this._draining = true;
|
|
1881
|
-
return this.__allResourceRequestsSettled().then(() => {
|
|
1882
|
-
return this.__allResourcesReturned();
|
|
1883
|
-
}).then(() => {
|
|
1884
|
-
this._descheduleEvictorRun();
|
|
1885
|
-
});
|
|
1886
|
-
}
|
|
1887
|
-
__allResourceRequestsSettled() {
|
|
1888
|
-
if (this._waitingClientsQueue.length > 0) {
|
|
1889
|
-
return reflector(this._waitingClientsQueue.tail.promise);
|
|
145
|
+
/**
|
|
146
|
+
* Loads a mesh asynchronously.
|
|
147
|
+
* @param id - The ID of the mesh.
|
|
148
|
+
* @param url - The URL of the mesh.
|
|
149
|
+
* @param options - Optional parameters.
|
|
150
|
+
* @returns The loaded mesh or null.
|
|
151
|
+
*/
|
|
152
|
+
async loadMeshAsync(id, url, options = {}) {
|
|
153
|
+
const gltf = await this.gltfLoader.loadAsync(url);
|
|
154
|
+
try {
|
|
155
|
+
if (options.meshName) {
|
|
156
|
+
const mesh = gltf.scene.getObjectByName(options.meshName);
|
|
157
|
+
this.register(id, mesh);
|
|
158
|
+
return mesh;
|
|
159
|
+
} else {
|
|
160
|
+
const mesh = gltf.scene.children[0];
|
|
161
|
+
this.register(id, mesh);
|
|
162
|
+
return mesh;
|
|
1890
163
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
__allResourcesReturned() {
|
|
1895
|
-
const ps = Array.from(this._resourceLoans.values()).map((loan) => loan.promise).map(reflector);
|
|
1896
|
-
return this._Promise.all(ps);
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Forcibly destroys all available resources regardless of timeout. Intended to be
|
|
1900
|
-
* invoked as part of a drain. Does not prevent the creation of new
|
|
1901
|
-
* resources as a result of subsequent calls to acquire.
|
|
1902
|
-
*
|
|
1903
|
-
* Note that if factory.min > 0 and the pool isn't "draining", the pool will destroy all idle resources
|
|
1904
|
-
* in the pool, but replace them with newly created resources up to the
|
|
1905
|
-
* specified factory.min value. If this is not desired, set factory.min
|
|
1906
|
-
* to zero before calling clear()
|
|
1907
|
-
*
|
|
1908
|
-
*/
|
|
1909
|
-
clear() {
|
|
1910
|
-
const reflectedCreatePromises = Array.from(
|
|
1911
|
-
this._factoryCreateOperations
|
|
1912
|
-
).map(reflector);
|
|
1913
|
-
return this._Promise.all(reflectedCreatePromises).then(() => {
|
|
1914
|
-
for (const resource of this._availableObjects) {
|
|
1915
|
-
this._destroy(resource);
|
|
1916
|
-
}
|
|
1917
|
-
const reflectedDestroyPromises = Array.from(
|
|
1918
|
-
this._factoryDestroyOperations
|
|
1919
|
-
).map(reflector);
|
|
1920
|
-
return reflector(this._Promise.all(reflectedDestroyPromises));
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Waits until the pool is ready.
|
|
1925
|
-
* We define ready by checking if the current resource number is at least
|
|
1926
|
-
* the minimum number defined.
|
|
1927
|
-
* @returns {Promise} that resolves when the minimum number is ready.
|
|
1928
|
-
*/
|
|
1929
|
-
ready() {
|
|
1930
|
-
return new this._Promise((resolve) => {
|
|
1931
|
-
const isReady = () => {
|
|
1932
|
-
if (this.available >= this.min) {
|
|
1933
|
-
resolve();
|
|
1934
|
-
} else {
|
|
1935
|
-
setTimeout(isReady, 100);
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
isReady();
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* How many resources are available to allocated
|
|
1943
|
-
* (includes resources that have not been tested and may faul validation)
|
|
1944
|
-
* NOTE: internal for now as the name is awful and might not be useful to anyone
|
|
1945
|
-
* @return {Number} number of resources the pool has to allocate
|
|
1946
|
-
*/
|
|
1947
|
-
get _potentiallyAllocableResourceCount() {
|
|
1948
|
-
return this._availableObjects.length + this._testOnBorrowResources.size + this._testOnReturnResources.size + this._factoryCreateOperations.size;
|
|
1949
|
-
}
|
|
1950
|
-
/**
|
|
1951
|
-
* The combined count of the currently created objects and those in the
|
|
1952
|
-
* process of being created
|
|
1953
|
-
* Does NOT include resources in the process of being destroyed
|
|
1954
|
-
* sort of legacy...
|
|
1955
|
-
* @return {Number}
|
|
1956
|
-
*/
|
|
1957
|
-
get _count() {
|
|
1958
|
-
return this._allObjects.size + this._factoryCreateOperations.size;
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* How many more resources does the pool have room for
|
|
1962
|
-
* @return {Number} number of resources the pool could create before hitting any limits
|
|
1963
|
-
*/
|
|
1964
|
-
get spareResourceCapacity() {
|
|
1965
|
-
return this._config.max - (this._allObjects.size + this._factoryCreateOperations.size);
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* see _count above
|
|
1969
|
-
* @return {Number} [description]
|
|
1970
|
-
*/
|
|
1971
|
-
get size() {
|
|
1972
|
-
return this._count;
|
|
1973
|
-
}
|
|
1974
|
-
/**
|
|
1975
|
-
* number of available resources
|
|
1976
|
-
* @return {Number} [description]
|
|
1977
|
-
*/
|
|
1978
|
-
get available() {
|
|
1979
|
-
return this._availableObjects.length;
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* number of resources that are currently acquired
|
|
1983
|
-
* @return {Number} [description]
|
|
1984
|
-
*/
|
|
1985
|
-
get borrowed() {
|
|
1986
|
-
return this._resourceLoans.size;
|
|
1987
|
-
}
|
|
1988
|
-
/**
|
|
1989
|
-
* number of waiting acquire calls
|
|
1990
|
-
* @return {Number} [description]
|
|
1991
|
-
*/
|
|
1992
|
-
get pending() {
|
|
1993
|
-
return this._waitingClientsQueue.length;
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* maximum size of the pool
|
|
1997
|
-
* @return {Number} [description]
|
|
1998
|
-
*/
|
|
1999
|
-
get max() {
|
|
2000
|
-
return this._config.max;
|
|
2001
|
-
}
|
|
2002
|
-
/**
|
|
2003
|
-
* minimum size of the pool
|
|
2004
|
-
* @return {Number} [description]
|
|
2005
|
-
*/
|
|
2006
|
-
get min() {
|
|
2007
|
-
return this._config.min;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.eventEmitter.emit("invalidRequest", { message: `failed to load mesh: ${id}. ${error}` });
|
|
166
|
+
return null;
|
|
2008
167
|
}
|
|
2009
168
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
Deque,
|
|
2025
|
-
PriorityQueue,
|
|
2026
|
-
DefaultEvictor,
|
|
2027
|
-
createPool: function(factory, config) {
|
|
2028
|
-
return new Pool(DefaultEvictor, Deque, PriorityQueue, factory, config);
|
|
169
|
+
/**
|
|
170
|
+
* Loads a texture asynchronously.
|
|
171
|
+
* @param id - The ID of the texture.
|
|
172
|
+
* @param url - The URL of the texture.
|
|
173
|
+
* @returns The loaded texture or null.
|
|
174
|
+
*/
|
|
175
|
+
async loadTextureAsync(id, url) {
|
|
176
|
+
try {
|
|
177
|
+
const texture = await this.textureLoader.loadAsync(url);
|
|
178
|
+
this.register(id, texture);
|
|
179
|
+
return texture;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.eventEmitter.emit("invalidRequest", { message: `failed to load texture: ${id}. ${error}` });
|
|
182
|
+
return null;
|
|
2029
183
|
}
|
|
2030
|
-
};
|
|
2031
|
-
return genericPool$1;
|
|
2032
|
-
}
|
|
2033
|
-
var genericPoolExports = requireGenericPool();
|
|
2034
|
-
const genericPool = /* @__PURE__ */ getDefaultExportFromCjs(genericPoolExports);
|
|
2035
|
-
const workerFactory = {
|
|
2036
|
-
create: async () => {
|
|
2037
|
-
const workerPath = new URL("data:video/mp2t;base64,aW1wb3J0IHsgTWVzaERhdGEgfSBmcm9tICdAL2xpYi90eXBlcyc7CmltcG9ydCAqIGFzIENvbWxpbmsgZnJvbSAnY29tbGluayc7CmltcG9ydCAqIGFzIFRIUkVFIGZyb20gJ3RocmVlJzsKaW1wb3J0IHsgTWVzaFN1cmZhY2VTYW1wbGVyIH0gZnJvbSAndGhyZWUvZXhhbXBsZXMvanNtL21hdGgvTWVzaFN1cmZhY2VTYW1wbGVyLmpzJzsKCmV4cG9ydCBpbnRlcmZhY2UgTWVzaFNhbXBsZXJBUEkgewogIHNhbXBsZU1lc2g6IChtZXNoRGF0YTogTWVzaERhdGEsIHNpemU6IG51bWJlcikgPT4gUHJvbWlzZTxGbG9hdDMyQXJyYXk+Owp9Cgpjb25zdCBhcGkgPSB7CiAgc2FtcGxlTWVzaDogKG1lc2hEYXRhOiBNZXNoRGF0YSwgc2l6ZTogbnVtYmVyKTogRmxvYXQzMkFycmF5ID0+IHsKICAgIGNvbnN0IGdlb21ldHJ5ID0gbmV3IFRIUkVFLkJ1ZmZlckdlb21ldHJ5KCk7CiAgICBnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoJ3Bvc2l0aW9uJywgbmV3IFRIUkVFLkJ1ZmZlckF0dHJpYnV0ZShuZXcgRmxvYXQzMkFycmF5KG1lc2hEYXRhLnBvc2l0aW9uKSwgMykpOwogICAgaWYgKG1lc2hEYXRhLm5vcm1hbCkgewogICAgICBnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoJ25vcm1hbCcsIG5ldyBUSFJFRS5CdWZmZXJBdHRyaWJ1dGUobmV3IEZsb2F0MzJBcnJheShtZXNoRGF0YS5ub3JtYWwpLCAzKSk7CiAgICB9CiAgICBjb25zdCBtYXRlcmlhbCA9IG5ldyBUSFJFRS5NZXNoQmFzaWNNYXRlcmlhbCgpOwogICAgY29uc3QgbWVzaCA9IG5ldyBUSFJFRS5NZXNoKGdlb21ldHJ5LCBtYXRlcmlhbCk7CiAgICBtZXNoLnNjYWxlLnNldChtZXNoRGF0YS5zY2FsZS54LCBtZXNoRGF0YS5zY2FsZS55LCBtZXNoRGF0YS5zY2FsZS56KTsKCiAgICBjb25zdCBzYW1wbGVyID0gbmV3IE1lc2hTdXJmYWNlU2FtcGxlcihtZXNoKS5idWlsZCgpOwogICAgY29uc3QgZGF0YSA9IG5ldyBGbG9hdDMyQXJyYXkoc2l6ZSAqIHNpemUgKiA0KTsKICAgIGNvbnN0IHBvc2l0aW9uID0gbmV3IFRIUkVFLlZlY3RvcjMoKTsKCiAgICBmb3IgKGxldCBpID0gMDsgaSA8IHNpemU7IGkrKykgewogICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHNpemU7IGorKykgewogICAgICAgIGNvbnN0IGluZGV4ID0gaSAqIHNpemUgKyBqOwogICAgICAgIHNhbXBsZXIuc2FtcGxlKHBvc2l0aW9uKTsKICAgICAgICBkYXRhWzQgKiBpbmRleF0gPSBwb3NpdGlvbi54ICogbWVzaERhdGEuc2NhbGUueDsKICAgICAgICBkYXRhWzQgKiBpbmRleCArIDFdID0gcG9zaXRpb24ueSAqIG1lc2hEYXRhLnNjYWxlLnk7CiAgICAgICAgZGF0YVs0ICogaW5kZXggKyAyXSA9IHBvc2l0aW9uLnogKiBtZXNoRGF0YS5zY2FsZS56OwogICAgICAgIGRhdGFbNCAqIGluZGV4ICsgM10gPSAoTWF0aC5yYW5kb20oKSAtIDAuNSkgKiAwLjAxOwogICAgICB9CiAgICB9CgogICAgcmV0dXJuIGRhdGE7CiAgfSwKfTsKCkNvbWxpbmsuZXhwb3NlKGFwaSk7Cg==", import.meta.url);
|
|
2038
|
-
const worker = new Worker(workerPath, { type: "module" });
|
|
2039
|
-
return wrap(worker);
|
|
2040
|
-
},
|
|
2041
|
-
destroy: async (worker) => {
|
|
2042
|
-
return worker[releaseProxy]();
|
|
2043
184
|
}
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat, THREE.FloatType);
|
|
2051
|
-
texture.needsUpdate = true;
|
|
2052
|
-
return texture;
|
|
2053
|
-
}
|
|
2054
|
-
function createBlankDataTexture(size) {
|
|
2055
|
-
return createDataTexture(new Float32Array(4 * size * size), size);
|
|
2056
|
-
}
|
|
2057
|
-
function createSpherePoints(size) {
|
|
2058
|
-
const data = new Float32Array(size * size * 4);
|
|
2059
|
-
for (let i = 0; i < size; i++) {
|
|
2060
|
-
for (let j = 0; j < size; j++) {
|
|
2061
|
-
const index = i * size + j;
|
|
2062
|
-
let theta = Math.random() * Math.PI * 2;
|
|
2063
|
-
let phi = Math.acos(Math.random() * 2 - 1);
|
|
2064
|
-
let x = Math.sin(phi) * Math.cos(theta);
|
|
2065
|
-
let y = Math.sin(phi) * Math.sin(theta);
|
|
2066
|
-
let z = Math.cos(phi);
|
|
2067
|
-
data[4 * index] = x;
|
|
2068
|
-
data[4 * index + 1] = y;
|
|
2069
|
-
data[4 * index + 2] = z;
|
|
2070
|
-
data[4 * index + 3] = (Math.random() - 0.5) * 0.01;
|
|
2071
|
-
}
|
|
185
|
+
dispose() {
|
|
186
|
+
this.updateServiceState("disposed");
|
|
187
|
+
this.meshes.forEach((mesh) => disposeMesh(mesh));
|
|
188
|
+
this.meshes.clear();
|
|
189
|
+
this.textures.forEach((texture) => texture.dispose());
|
|
190
|
+
this.textures.clear();
|
|
2072
191
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
192
|
+
changeColor(color) {
|
|
193
|
+
const actual = new THREE.Color(color);
|
|
194
|
+
this.solidColorTexture = new THREE.DataTexture(new Uint8Array([actual.r, actual.g, actual.b, 255]), 1, 1, THREE.RGBAFormat);
|
|
195
|
+
this.solidColorTexture.needsUpdate = true;
|
|
196
|
+
}
|
|
197
|
+
updateServiceState(serviceState) {
|
|
198
|
+
this.serviceState = serviceState;
|
|
199
|
+
this.eventEmitter.emit("serviceStateUpdated", { type: "asset", state: serviceState });
|
|
2081
200
|
}
|
|
2082
201
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
202
|
+
const _face = new Triangle();
|
|
203
|
+
const _color = new Vector3();
|
|
204
|
+
const _uva = new Vector2(), _uvb = new Vector2(), _uvc = new Vector2();
|
|
205
|
+
class MeshSurfaceSampler {
|
|
206
|
+
constructor(mesh) {
|
|
207
|
+
this.geometry = mesh.geometry;
|
|
208
|
+
this.randomFunction = Math.random;
|
|
209
|
+
this.indexAttribute = this.geometry.index;
|
|
210
|
+
this.positionAttribute = this.geometry.getAttribute("position");
|
|
211
|
+
this.normalAttribute = this.geometry.getAttribute("normal");
|
|
212
|
+
this.colorAttribute = this.geometry.getAttribute("color");
|
|
213
|
+
this.uvAttribute = this.geometry.getAttribute("uv");
|
|
214
|
+
this.weightAttribute = null;
|
|
215
|
+
this.distribution = null;
|
|
216
|
+
}
|
|
217
|
+
setWeightAttribute(name) {
|
|
218
|
+
this.weightAttribute = name ? this.geometry.getAttribute(name) : null;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
build() {
|
|
222
|
+
const indexAttribute = this.indexAttribute;
|
|
223
|
+
const positionAttribute = this.positionAttribute;
|
|
224
|
+
const weightAttribute = this.weightAttribute;
|
|
225
|
+
const totalFaces = indexAttribute ? indexAttribute.count / 3 : positionAttribute.count / 3;
|
|
226
|
+
const faceWeights = new Float32Array(totalFaces);
|
|
227
|
+
for (let i = 0; i < totalFaces; i++) {
|
|
228
|
+
let faceWeight = 1;
|
|
229
|
+
let i0 = 3 * i;
|
|
230
|
+
let i1 = 3 * i + 1;
|
|
231
|
+
let i2 = 3 * i + 2;
|
|
232
|
+
if (indexAttribute) {
|
|
233
|
+
i0 = indexAttribute.getX(i0);
|
|
234
|
+
i1 = indexAttribute.getX(i1);
|
|
235
|
+
i2 = indexAttribute.getX(i2);
|
|
236
|
+
}
|
|
237
|
+
if (weightAttribute) {
|
|
238
|
+
faceWeight = weightAttribute.getX(i0) + weightAttribute.getX(i1) + weightAttribute.getX(i2);
|
|
239
|
+
}
|
|
240
|
+
_face.a.fromBufferAttribute(positionAttribute, i0);
|
|
241
|
+
_face.b.fromBufferAttribute(positionAttribute, i1);
|
|
242
|
+
_face.c.fromBufferAttribute(positionAttribute, i2);
|
|
243
|
+
faceWeight *= _face.getArea();
|
|
244
|
+
faceWeights[i] = faceWeight;
|
|
245
|
+
}
|
|
246
|
+
const distribution = new Float32Array(totalFaces);
|
|
247
|
+
let cumulativeTotal = 0;
|
|
248
|
+
for (let i = 0; i < totalFaces; i++) {
|
|
249
|
+
cumulativeTotal += faceWeights[i];
|
|
250
|
+
distribution[i] = cumulativeTotal;
|
|
251
|
+
}
|
|
252
|
+
this.distribution = distribution;
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
setRandomGenerator(randomFunction) {
|
|
256
|
+
this.randomFunction = randomFunction;
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
sample(targetPosition, targetNormal, targetColor, targetUV) {
|
|
260
|
+
const faceIndex = this.sampleFaceIndex();
|
|
261
|
+
return this.sampleFace(faceIndex, targetPosition, targetNormal, targetColor, targetUV);
|
|
262
|
+
}
|
|
263
|
+
sampleFaceIndex() {
|
|
264
|
+
const cumulativeTotal = this.distribution[this.distribution.length - 1];
|
|
265
|
+
return this.binarySearch(this.randomFunction() * cumulativeTotal);
|
|
266
|
+
}
|
|
267
|
+
binarySearch(x) {
|
|
268
|
+
const dist = this.distribution;
|
|
269
|
+
let start = 0;
|
|
270
|
+
let end = dist.length - 1;
|
|
271
|
+
let index = -1;
|
|
272
|
+
while (start <= end) {
|
|
273
|
+
const mid = Math.ceil((start + end) / 2);
|
|
274
|
+
if (mid === 0 || dist[mid - 1] <= x && dist[mid] > x) {
|
|
275
|
+
index = mid;
|
|
276
|
+
break;
|
|
277
|
+
} else if (x < dist[mid]) {
|
|
278
|
+
end = mid - 1;
|
|
279
|
+
} else {
|
|
280
|
+
start = mid + 1;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return index;
|
|
284
|
+
}
|
|
285
|
+
sampleFace(faceIndex, targetPosition, targetNormal, targetColor, targetUV) {
|
|
286
|
+
let u = this.randomFunction();
|
|
287
|
+
let v = this.randomFunction();
|
|
288
|
+
if (u + v > 1) {
|
|
289
|
+
u = 1 - u;
|
|
290
|
+
v = 1 - v;
|
|
291
|
+
}
|
|
292
|
+
const indexAttribute = this.indexAttribute;
|
|
293
|
+
let i0 = faceIndex * 3;
|
|
294
|
+
let i1 = faceIndex * 3 + 1;
|
|
295
|
+
let i2 = faceIndex * 3 + 2;
|
|
296
|
+
if (indexAttribute) {
|
|
297
|
+
i0 = indexAttribute.getX(i0);
|
|
298
|
+
i1 = indexAttribute.getX(i1);
|
|
299
|
+
i2 = indexAttribute.getX(i2);
|
|
300
|
+
}
|
|
301
|
+
_face.a.fromBufferAttribute(this.positionAttribute, i0);
|
|
302
|
+
_face.b.fromBufferAttribute(this.positionAttribute, i1);
|
|
303
|
+
_face.c.fromBufferAttribute(this.positionAttribute, i2);
|
|
304
|
+
targetPosition.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));
|
|
305
|
+
if (targetNormal !== void 0) {
|
|
306
|
+
if (this.normalAttribute !== void 0) {
|
|
307
|
+
_face.a.fromBufferAttribute(this.normalAttribute, i0);
|
|
308
|
+
_face.b.fromBufferAttribute(this.normalAttribute, i1);
|
|
309
|
+
_face.c.fromBufferAttribute(this.normalAttribute, i2);
|
|
310
|
+
targetNormal.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v)).normalize();
|
|
311
|
+
} else {
|
|
312
|
+
_face.getNormal(targetNormal);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (targetColor !== void 0 && this.colorAttribute !== void 0) {
|
|
316
|
+
_face.a.fromBufferAttribute(this.colorAttribute, i0);
|
|
317
|
+
_face.b.fromBufferAttribute(this.colorAttribute, i1);
|
|
318
|
+
_face.c.fromBufferAttribute(this.colorAttribute, i2);
|
|
319
|
+
_color.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));
|
|
320
|
+
targetColor.r = _color.x;
|
|
321
|
+
targetColor.g = _color.y;
|
|
322
|
+
targetColor.b = _color.z;
|
|
323
|
+
}
|
|
324
|
+
if (targetUV !== void 0 && this.uvAttribute !== void 0) {
|
|
325
|
+
_uva.fromBufferAttribute(this.uvAttribute, i0);
|
|
326
|
+
_uvb.fromBufferAttribute(this.uvAttribute, i1);
|
|
327
|
+
_uvc.fromBufferAttribute(this.uvAttribute, i2);
|
|
328
|
+
targetUV.set(0, 0).addScaledVector(_uva, u).addScaledVector(_uvb, v).addScaledVector(_uvc, 1 - (u + v));
|
|
329
|
+
}
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
2087
332
|
}
|
|
2088
333
|
class DataTextureService {
|
|
2089
334
|
/**
|
|
@@ -2117,15 +362,10 @@ class DataTextureService {
|
|
|
2117
362
|
return texture;
|
|
2118
363
|
}
|
|
2119
364
|
const meshData = parseMeshData(asset);
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
dataTexture.name = asset.name;
|
|
2125
|
-
return dataTexture;
|
|
2126
|
-
} finally {
|
|
2127
|
-
await pool.release(worker);
|
|
2128
|
-
}
|
|
365
|
+
const array = sampleMesh(meshData, this.textureSize);
|
|
366
|
+
const dataTexture = createDataTexture(array, this.textureSize);
|
|
367
|
+
dataTexture.name = asset.name;
|
|
368
|
+
return dataTexture;
|
|
2129
369
|
}
|
|
2130
370
|
async dispose() {
|
|
2131
371
|
this.dataTextures.clear();
|
|
@@ -2143,12 +383,36 @@ function parseMeshData(mesh) {
|
|
|
2143
383
|
scale: { x: mesh.scale.x, y: mesh.scale.y, z: mesh.scale.z }
|
|
2144
384
|
};
|
|
2145
385
|
}
|
|
386
|
+
function sampleMesh(meshData, size) {
|
|
387
|
+
const geometry = new THREE.BufferGeometry();
|
|
388
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(meshData.position), 3));
|
|
389
|
+
if (meshData.normal) {
|
|
390
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(new Float32Array(meshData.normal), 3));
|
|
391
|
+
}
|
|
392
|
+
const material = new THREE.MeshBasicMaterial();
|
|
393
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
394
|
+
mesh.scale.set(meshData.scale.x, meshData.scale.y, meshData.scale.z);
|
|
395
|
+
const sampler = new MeshSurfaceSampler(mesh).build();
|
|
396
|
+
const data = new Float32Array(size * size * 4);
|
|
397
|
+
const position = new THREE.Vector3();
|
|
398
|
+
for (let i = 0; i < size; i++) {
|
|
399
|
+
for (let j = 0; j < size; j++) {
|
|
400
|
+
const index = i * size + j;
|
|
401
|
+
sampler.sample(position);
|
|
402
|
+
data[4 * index] = position.x * meshData.scale.x;
|
|
403
|
+
data[4 * index + 1] = position.y * meshData.scale.y;
|
|
404
|
+
data[4 * index + 2] = position.z * meshData.scale.z;
|
|
405
|
+
data[4 * index + 3] = (Math.random() - 0.5) * 0.01;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return data;
|
|
409
|
+
}
|
|
2146
410
|
const instanceFragmentShader = `
|
|
2147
411
|
varying vec2 vUv;
|
|
2148
412
|
uniform sampler2D uTexture;
|
|
2149
413
|
|
|
2150
|
-
uniform sampler2D
|
|
2151
|
-
uniform sampler2D
|
|
414
|
+
uniform sampler2D uOriginTexture;
|
|
415
|
+
uniform sampler2D uDestinationTexture;
|
|
2152
416
|
|
|
2153
417
|
uniform float uProgress;
|
|
2154
418
|
varying vec3 vNormal;
|
|
@@ -2159,8 +423,8 @@ void main() {
|
|
|
2159
423
|
vec3 y = cross( viewDir, x );
|
|
2160
424
|
vec2 uv = vec2( dot( x, vNormal ), dot( y, vNormal ) ) * 0.495 + 0.5; // 0.495 to remove artifacts caused by undersized matcap disks
|
|
2161
425
|
|
|
2162
|
-
vec4 sourceMatcap = texture2D(
|
|
2163
|
-
vec4 targetMatcap = texture2D(
|
|
426
|
+
vec4 sourceMatcap = texture2D( uOriginTexture, uv );
|
|
427
|
+
vec4 targetMatcap = texture2D( uDestinationTexture, uv );
|
|
2164
428
|
|
|
2165
429
|
vec4 matcap = mix(sourceMatcap, targetMatcap, uProgress);
|
|
2166
430
|
gl_FragColor = matcap;
|
|
@@ -2220,32 +484,36 @@ class InstancedMeshManager {
|
|
|
2220
484
|
__publicField(this, "size");
|
|
2221
485
|
__publicField(this, "mesh");
|
|
2222
486
|
__publicField(this, "matcapMaterial");
|
|
2223
|
-
__publicField(this, "fallbackMaterial");
|
|
2224
487
|
__publicField(this, "fallbackGeometry");
|
|
2225
|
-
__publicField(this, "
|
|
488
|
+
__publicField(this, "uniforms");
|
|
489
|
+
__publicField(this, "originColor");
|
|
490
|
+
__publicField(this, "destinationColor");
|
|
2226
491
|
__publicField(this, "geometries");
|
|
2227
492
|
__publicField(this, "uvRefsCache");
|
|
2228
493
|
__publicField(this, "previousScale");
|
|
2229
494
|
this.size = initialSize;
|
|
2230
|
-
this.materials = /* @__PURE__ */ new Map();
|
|
2231
495
|
this.geometries = /* @__PURE__ */ new Map();
|
|
2232
496
|
this.uvRefsCache = /* @__PURE__ */ new Map();
|
|
2233
497
|
this.previousScale = { x: 1, y: 1, z: 1 };
|
|
498
|
+
this.originColor = "grey";
|
|
499
|
+
this.destinationColor = "grey";
|
|
500
|
+
this.uniforms = {
|
|
501
|
+
uTime: { value: 0 },
|
|
502
|
+
uProgress: { value: 0 },
|
|
503
|
+
uTexture: { value: null },
|
|
504
|
+
uVelocity: { value: null },
|
|
505
|
+
uOriginTexture: { value: null },
|
|
506
|
+
uDestinationTexture: { value: null }
|
|
507
|
+
};
|
|
2234
508
|
this.matcapMaterial = new THREE.ShaderMaterial({
|
|
2235
|
-
uniforms:
|
|
2236
|
-
uTime: { value: 0 },
|
|
2237
|
-
uProgress: { value: 0 },
|
|
2238
|
-
uTexture: { value: null },
|
|
2239
|
-
uVelocity: { value: null },
|
|
2240
|
-
uSourceMatcap: { value: null },
|
|
2241
|
-
uTargetMatcap: { value: null }
|
|
2242
|
-
},
|
|
509
|
+
uniforms: this.uniforms,
|
|
2243
510
|
vertexShader: instanceVertexShader,
|
|
2244
511
|
fragmentShader: instanceFragmentShader
|
|
2245
512
|
});
|
|
2246
|
-
this.
|
|
513
|
+
this.setOriginColor(this.originColor);
|
|
514
|
+
this.setDestinationColor(this.destinationColor);
|
|
2247
515
|
this.fallbackGeometry = new THREE.BoxGeometry(1e-3, 1e-3, 1e-3);
|
|
2248
|
-
this.mesh = this.createInstancedMesh(initialSize, this.fallbackGeometry, this.
|
|
516
|
+
this.mesh = this.createInstancedMesh(initialSize, this.fallbackGeometry, this.matcapMaterial);
|
|
2249
517
|
}
|
|
2250
518
|
/**
|
|
2251
519
|
* Gets the instanced mesh.
|
|
@@ -2269,10 +537,12 @@ class InstancedMeshManager {
|
|
|
2269
537
|
* @param matcap The matcap texture to set.
|
|
2270
538
|
*/
|
|
2271
539
|
setOriginMatcap(matcap) {
|
|
2272
|
-
this.
|
|
540
|
+
this.disposeSolidColorOriginTexture();
|
|
541
|
+
this.matcapMaterial.uniforms.uOriginTexture.value = matcap;
|
|
2273
542
|
}
|
|
2274
543
|
setDestinationMatcap(matcap) {
|
|
2275
|
-
this.
|
|
544
|
+
this.disposeSolidColorDestinationTexture();
|
|
545
|
+
this.matcapMaterial.uniforms.uDestinationTexture.value = matcap;
|
|
2276
546
|
}
|
|
2277
547
|
setProgress(float) {
|
|
2278
548
|
float = Math.max(0, float);
|
|
@@ -2290,16 +560,6 @@ class InstancedMeshManager {
|
|
|
2290
560
|
useMatcapMaterial() {
|
|
2291
561
|
this.mesh.material = this.matcapMaterial;
|
|
2292
562
|
}
|
|
2293
|
-
/**
|
|
2294
|
-
* Use the specified material for the instanced mesh.
|
|
2295
|
-
* @param id The ID of the material to use.
|
|
2296
|
-
*/
|
|
2297
|
-
useMaterial(id) {
|
|
2298
|
-
const material = this.materials.get(id);
|
|
2299
|
-
if (material) {
|
|
2300
|
-
this.mesh.material = material;
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
563
|
/**
|
|
2304
564
|
* Use the specified geometry for the instanced mesh.
|
|
2305
565
|
* @param id The ID of the geometry to use.
|
|
@@ -2342,10 +602,11 @@ class InstancedMeshManager {
|
|
|
2342
602
|
dispose() {
|
|
2343
603
|
this.mesh.dispose();
|
|
2344
604
|
this.geometries.forEach((geometry) => geometry.dispose());
|
|
2345
|
-
this.
|
|
605
|
+
this.disposeSolidColorOriginTexture();
|
|
606
|
+
this.disposeSolidColorDestinationTexture();
|
|
607
|
+
this.matcapMaterial.dispose();
|
|
2346
608
|
this.uvRefsCache.clear();
|
|
2347
609
|
this.geometries.clear();
|
|
2348
|
-
this.materials.clear();
|
|
2349
610
|
}
|
|
2350
611
|
/**
|
|
2351
612
|
* Registers a geometry.
|
|
@@ -2359,7 +620,7 @@ class InstancedMeshManager {
|
|
|
2359
620
|
return;
|
|
2360
621
|
}
|
|
2361
622
|
}
|
|
2362
|
-
const uvRefs = this.
|
|
623
|
+
const uvRefs = this.createUVRefs(this.size);
|
|
2363
624
|
geometry.setAttribute("uvRef", uvRefs);
|
|
2364
625
|
this.geometries.set(id, geometry);
|
|
2365
626
|
if (this.mesh.geometry === previous) {
|
|
@@ -2367,30 +628,22 @@ class InstancedMeshManager {
|
|
|
2367
628
|
}
|
|
2368
629
|
previous == null ? void 0 : previous.dispose();
|
|
2369
630
|
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
return;
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
if (this.mesh.material === previous) {
|
|
2383
|
-
this.mesh.material = material;
|
|
2384
|
-
}
|
|
2385
|
-
this.materials.set(id, material);
|
|
2386
|
-
previous == null ? void 0 : previous.dispose();
|
|
631
|
+
setOriginColor(color) {
|
|
632
|
+
this.disposeSolidColorOriginTexture();
|
|
633
|
+
this.originColor = color;
|
|
634
|
+
this.uniforms.uOriginTexture.value = this.createSolidColorDataTexture(color);
|
|
635
|
+
}
|
|
636
|
+
setDestinationColor(color) {
|
|
637
|
+
this.disposeSolidColorDestinationTexture();
|
|
638
|
+
this.destinationColor = color;
|
|
639
|
+
this.uniforms.uDestinationTexture.value = this.createSolidColorDataTexture(color);
|
|
2387
640
|
}
|
|
2388
641
|
/**
|
|
2389
642
|
* Gets the UV references for the specified size.
|
|
2390
643
|
* @param size The size for which to generate UV references.
|
|
2391
644
|
* @returns The UV references.
|
|
2392
645
|
*/
|
|
2393
|
-
|
|
646
|
+
createUVRefs(size) {
|
|
2394
647
|
const cached = this.uvRefsCache.get(size);
|
|
2395
648
|
if (cached) {
|
|
2396
649
|
return cached;
|
|
@@ -2416,10 +669,50 @@ class InstancedMeshManager {
|
|
|
2416
669
|
*/
|
|
2417
670
|
createInstancedMesh(size, geometry, material) {
|
|
2418
671
|
geometry = geometry || this.fallbackGeometry;
|
|
2419
|
-
geometry.setAttribute("uvRef", this.
|
|
672
|
+
geometry.setAttribute("uvRef", this.createUVRefs(size));
|
|
2420
673
|
const count = size * size;
|
|
2421
674
|
return new THREE.InstancedMesh(geometry, material, count);
|
|
2422
675
|
}
|
|
676
|
+
createSolidColorDataTexture(color, size = 16) {
|
|
677
|
+
const col = new THREE.Color(color);
|
|
678
|
+
const width = size;
|
|
679
|
+
const height = size;
|
|
680
|
+
const data = new Uint8Array(width * height * 4);
|
|
681
|
+
const r = Math.floor(col.r * 255);
|
|
682
|
+
const g = Math.floor(col.g * 255);
|
|
683
|
+
const b = Math.floor(col.b * 255);
|
|
684
|
+
for (let i = 0; i < width * height; i++) {
|
|
685
|
+
const index = i * 4;
|
|
686
|
+
data[index] = r;
|
|
687
|
+
data[index + 1] = g;
|
|
688
|
+
data[index + 2] = b;
|
|
689
|
+
data[index + 3] = 255;
|
|
690
|
+
}
|
|
691
|
+
const texture = new THREE.DataTexture(data, width, height, THREE.RGBAFormat);
|
|
692
|
+
texture.type = THREE.UnsignedByteType;
|
|
693
|
+
texture.wrapS = THREE.RepeatWrapping;
|
|
694
|
+
texture.wrapT = THREE.RepeatWrapping;
|
|
695
|
+
texture.minFilter = THREE.NearestFilter;
|
|
696
|
+
texture.magFilter = THREE.NearestFilter;
|
|
697
|
+
texture.needsUpdate = true;
|
|
698
|
+
return texture;
|
|
699
|
+
}
|
|
700
|
+
disposeSolidColorOriginTexture() {
|
|
701
|
+
if (this.originColor) {
|
|
702
|
+
this.originColor = null;
|
|
703
|
+
if (this.uniforms.uOriginTexture.value) {
|
|
704
|
+
this.uniforms.uOriginTexture.value.dispose();
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
disposeSolidColorDestinationTexture() {
|
|
709
|
+
if (this.destinationColor) {
|
|
710
|
+
this.destinationColor = null;
|
|
711
|
+
if (this.uniforms.uDestinationTexture.value) {
|
|
712
|
+
this.uniforms.uDestinationTexture.value.dispose();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
2423
716
|
}
|
|
2424
717
|
class IntersectionService {
|
|
2425
718
|
/**
|
|
@@ -3187,122 +1480,6 @@ class TransitionService {
|
|
|
3187
1480
|
this.eventEmitter.emit("transitionFinished", { type });
|
|
3188
1481
|
}
|
|
3189
1482
|
}
|
|
3190
|
-
class AssetService {
|
|
3191
|
-
constructor(eventEmitter) {
|
|
3192
|
-
__publicField(this, "serviceState", "created");
|
|
3193
|
-
__publicField(this, "eventEmitter");
|
|
3194
|
-
__publicField(this, "meshes", /* @__PURE__ */ new Map());
|
|
3195
|
-
__publicField(this, "textures", /* @__PURE__ */ new Map());
|
|
3196
|
-
__publicField(this, "gltfLoader", new GLTFLoader());
|
|
3197
|
-
__publicField(this, "textureLoader", new THREE.TextureLoader());
|
|
3198
|
-
__publicField(this, "dracoLoader", new DRACOLoader());
|
|
3199
|
-
__publicField(this, "solidColorTexture", new THREE.DataTexture(new Uint8Array([127, 127, 127, 255]), 1, 1, THREE.RGBAFormat));
|
|
3200
|
-
this.eventEmitter = eventEmitter;
|
|
3201
|
-
this.dracoLoader.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.7/");
|
|
3202
|
-
this.gltfLoader.setDRACOLoader(this.dracoLoader);
|
|
3203
|
-
this.updateServiceState("ready");
|
|
3204
|
-
}
|
|
3205
|
-
/**
|
|
3206
|
-
* Registers an asset.
|
|
3207
|
-
* @param id - The ID of the asset.
|
|
3208
|
-
* @param item - The asset to set.
|
|
3209
|
-
*/
|
|
3210
|
-
register(id, item) {
|
|
3211
|
-
item.name = id;
|
|
3212
|
-
if (item instanceof THREE.Mesh) {
|
|
3213
|
-
const prev = this.meshes.get(id);
|
|
3214
|
-
if (prev) disposeMesh(prev);
|
|
3215
|
-
this.meshes.set(id, item);
|
|
3216
|
-
} else {
|
|
3217
|
-
const prev = this.textures.get(id);
|
|
3218
|
-
if (prev) prev.dispose();
|
|
3219
|
-
this.textures.set(id, item);
|
|
3220
|
-
}
|
|
3221
|
-
this.eventEmitter.emit("assetRegistered", { id });
|
|
3222
|
-
}
|
|
3223
|
-
setSolidColor(color) {
|
|
3224
|
-
this.changeColor(color);
|
|
3225
|
-
}
|
|
3226
|
-
getSolidColorTexture() {
|
|
3227
|
-
return this.solidColorTexture;
|
|
3228
|
-
}
|
|
3229
|
-
getMesh(id) {
|
|
3230
|
-
return this.meshes.get(id) ?? null;
|
|
3231
|
-
}
|
|
3232
|
-
getMatcap(id) {
|
|
3233
|
-
const texture = this.textures.get(id);
|
|
3234
|
-
if (!texture) this.eventEmitter.emit("invalidRequest", { message: `texture with id "${id}" not found. using solid color texture instead...` });
|
|
3235
|
-
return texture ?? this.solidColorTexture;
|
|
3236
|
-
}
|
|
3237
|
-
getMeshIDs() {
|
|
3238
|
-
return Array.from(this.meshes.keys());
|
|
3239
|
-
}
|
|
3240
|
-
getTextureIDs() {
|
|
3241
|
-
return Array.from(this.textures.keys());
|
|
3242
|
-
}
|
|
3243
|
-
getMeshes() {
|
|
3244
|
-
return Array.from(this.meshes.values());
|
|
3245
|
-
}
|
|
3246
|
-
getTextures() {
|
|
3247
|
-
return Array.from(this.textures.values());
|
|
3248
|
-
}
|
|
3249
|
-
/**
|
|
3250
|
-
* Loads a mesh asynchronously.
|
|
3251
|
-
* @param id - The ID of the mesh.
|
|
3252
|
-
* @param url - The URL of the mesh.
|
|
3253
|
-
* @param options - Optional parameters.
|
|
3254
|
-
* @returns The loaded mesh or null.
|
|
3255
|
-
*/
|
|
3256
|
-
async loadMeshAsync(id, url, options = {}) {
|
|
3257
|
-
const gltf = await this.gltfLoader.loadAsync(url);
|
|
3258
|
-
try {
|
|
3259
|
-
if (options.meshName) {
|
|
3260
|
-
const mesh = gltf.scene.getObjectByName(options.meshName);
|
|
3261
|
-
this.register(id, mesh);
|
|
3262
|
-
return mesh;
|
|
3263
|
-
} else {
|
|
3264
|
-
const mesh = gltf.scene.children[0];
|
|
3265
|
-
this.register(id, mesh);
|
|
3266
|
-
return mesh;
|
|
3267
|
-
}
|
|
3268
|
-
} catch (error) {
|
|
3269
|
-
this.eventEmitter.emit("invalidRequest", { message: `failed to load mesh: ${id}. ${error}` });
|
|
3270
|
-
return null;
|
|
3271
|
-
}
|
|
3272
|
-
}
|
|
3273
|
-
/**
|
|
3274
|
-
* Loads a texture asynchronously.
|
|
3275
|
-
* @param id - The ID of the texture.
|
|
3276
|
-
* @param url - The URL of the texture.
|
|
3277
|
-
* @returns The loaded texture or null.
|
|
3278
|
-
*/
|
|
3279
|
-
async loadTextureAsync(id, url) {
|
|
3280
|
-
try {
|
|
3281
|
-
const texture = await this.textureLoader.loadAsync(url);
|
|
3282
|
-
this.register(id, texture);
|
|
3283
|
-
return texture;
|
|
3284
|
-
} catch (error) {
|
|
3285
|
-
this.eventEmitter.emit("invalidRequest", { message: `failed to load texture: ${id}. ${error}` });
|
|
3286
|
-
return null;
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
dispose() {
|
|
3290
|
-
this.updateServiceState("disposed");
|
|
3291
|
-
this.meshes.forEach((mesh) => disposeMesh(mesh));
|
|
3292
|
-
this.meshes.clear();
|
|
3293
|
-
this.textures.forEach((texture) => texture.dispose());
|
|
3294
|
-
this.textures.clear();
|
|
3295
|
-
}
|
|
3296
|
-
changeColor(color) {
|
|
3297
|
-
const actual = new THREE.Color(color);
|
|
3298
|
-
this.solidColorTexture = new THREE.DataTexture(new Uint8Array([actual.r, actual.g, actual.b, 255]), 1, 1, THREE.RGBAFormat);
|
|
3299
|
-
this.solidColorTexture.needsUpdate = true;
|
|
3300
|
-
}
|
|
3301
|
-
updateServiceState(serviceState) {
|
|
3302
|
-
this.serviceState = serviceState;
|
|
3303
|
-
this.eventEmitter.emit("serviceStateUpdated", { type: "asset", state: serviceState });
|
|
3304
|
-
}
|
|
3305
|
-
}
|
|
3306
1483
|
class ParticlesEngine {
|
|
3307
1484
|
/**
|
|
3308
1485
|
* Creates a new ParticlesEngine instance.
|
|
@@ -3549,6 +1726,12 @@ class ParticlesEngine {
|
|
|
3549
1726
|
handleInteractionPositionUpdated({ position }) {
|
|
3550
1727
|
this.simulationRendererService.setInteractionPosition(position);
|
|
3551
1728
|
}
|
|
1729
|
+
setOriginColor(color) {
|
|
1730
|
+
this.instancedMeshManager.setOriginColor(color);
|
|
1731
|
+
}
|
|
1732
|
+
setDestinationColor(color) {
|
|
1733
|
+
this.instancedMeshManager.setDestinationColor(color);
|
|
1734
|
+
}
|
|
3552
1735
|
}
|
|
3553
1736
|
export {
|
|
3554
1737
|
ParticlesEngine
|