minerender 2.1.0-alpha.17 → 2.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/browser/index.d.mts +141 -193
- package/dist/browser/index.d.ts +141 -193
- package/dist/browser/index.js +1589 -1731
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1587 -1729
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +4968 -3520
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +140 -192
- package/dist/node/index.d.ts +140 -192
- package/dist/node/index.js +1710 -1921
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1703 -1912
- package/dist/node/index.mjs.map +1 -1
- package/package.json +9 -7
package/dist/browser/index.mjs
CHANGED
|
@@ -23,6 +23,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
24
|
mod
|
|
25
25
|
));
|
|
26
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
27
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
28
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
29
|
+
if (decorator = decorators[i])
|
|
30
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
31
|
+
if (kind && result) __defProp(target, key, result);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
26
34
|
|
|
27
35
|
// ../../node_modules/ts-deepmerge/dist/index.js
|
|
28
36
|
var require_dist = __commonJS({
|
|
@@ -32,8 +40,8 @@ var require_dist = __commonJS({
|
|
|
32
40
|
__assign = Object.assign || function(t) {
|
|
33
41
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
42
|
s = arguments[i];
|
|
35
|
-
for (var
|
|
36
|
-
t[
|
|
43
|
+
for (var p13 in s) if (Object.prototype.hasOwnProperty.call(s, p13))
|
|
44
|
+
t[p13] = s[p13];
|
|
37
45
|
}
|
|
38
46
|
return t;
|
|
39
47
|
};
|
|
@@ -77,7 +85,7 @@ var require_dist = __commonJS({
|
|
|
77
85
|
return false;
|
|
78
86
|
};
|
|
79
87
|
var PROTECTED_KEYS = ["__proto__"];
|
|
80
|
-
var
|
|
88
|
+
var merge11 = function() {
|
|
81
89
|
var objects = [];
|
|
82
90
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
83
91
|
objects[_i] = arguments[_i];
|
|
@@ -88,9 +96,9 @@ var require_dist = __commonJS({
|
|
|
88
96
|
return;
|
|
89
97
|
}
|
|
90
98
|
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
91
|
-
result[key] =
|
|
99
|
+
result[key] = merge11.options.mergeArrays ? Array.from(new Set(result[key].concat(current[key]))) : current[key];
|
|
92
100
|
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
93
|
-
result[key] =
|
|
101
|
+
result[key] = merge11(result[key], current[key]);
|
|
94
102
|
} else {
|
|
95
103
|
result[key] = current[key];
|
|
96
104
|
}
|
|
@@ -101,18 +109,18 @@ var require_dist = __commonJS({
|
|
|
101
109
|
var defaultOptions = {
|
|
102
110
|
mergeArrays: true
|
|
103
111
|
};
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
merge11.options = defaultOptions;
|
|
113
|
+
merge11.withOptions = function(options) {
|
|
106
114
|
var objects = [];
|
|
107
115
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
108
116
|
objects[_i - 1] = arguments[_i];
|
|
109
117
|
}
|
|
110
|
-
|
|
111
|
-
var result =
|
|
112
|
-
|
|
118
|
+
merge11.options = __assign({ mergeArrays: true }, options);
|
|
119
|
+
var result = merge11.apply(void 0, __spreadArray([], __read(objects), false));
|
|
120
|
+
merge11.options = defaultOptions;
|
|
113
121
|
return result;
|
|
114
122
|
};
|
|
115
|
-
exports.default =
|
|
123
|
+
exports.default = merge11;
|
|
116
124
|
}
|
|
117
125
|
});
|
|
118
126
|
|
|
@@ -146,20 +154,17 @@ var _PersistentCache = class _PersistentCache {
|
|
|
146
154
|
static open(name) {
|
|
147
155
|
return Env.provider.openCache(name, _PersistentCache.VERSION);
|
|
148
156
|
}
|
|
149
|
-
/** Loads a missing entry and stores only non-nullish results. */
|
|
150
157
|
async getOrLoad(key, loader) {
|
|
151
158
|
let v = await this.get(key);
|
|
152
159
|
if (typeof v === "undefined" || v === null) {
|
|
153
160
|
v = await loader(key);
|
|
154
|
-
|
|
155
|
-
await this.put(key, v);
|
|
156
|
-
}
|
|
161
|
+
await this.put(key, v);
|
|
157
162
|
}
|
|
158
163
|
return v;
|
|
159
164
|
}
|
|
160
165
|
};
|
|
161
166
|
/** Bump to invalidate every persisted entry. */
|
|
162
|
-
_PersistentCache.VERSION =
|
|
167
|
+
_PersistentCache.VERSION = 1;
|
|
163
168
|
var PersistentCache = _PersistentCache;
|
|
164
169
|
|
|
165
170
|
// src/env/browser/BrowserCache.ts
|
|
@@ -260,8 +265,7 @@ var BrowserEnv = class {
|
|
|
260
265
|
}
|
|
261
266
|
openCache(name, version) {
|
|
262
267
|
return new BrowserCache(localforage.createInstance({
|
|
263
|
-
|
|
264
|
-
name: name + version,
|
|
268
|
+
name,
|
|
265
269
|
version
|
|
266
270
|
}));
|
|
267
271
|
}
|
|
@@ -278,7 +282,7 @@ registerBrowserEnv();
|
|
|
278
282
|
// src/Axis.ts
|
|
279
283
|
import { Vector3 } from "three";
|
|
280
284
|
var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
281
|
-
Axis3["X"] = "
|
|
285
|
+
Axis3["X"] = "X";
|
|
282
286
|
Axis3["Y"] = "y";
|
|
283
287
|
Axis3["Z"] = "z";
|
|
284
288
|
return Axis3;
|
|
@@ -286,7 +290,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
|
286
290
|
var AXES = Object.values(Axis);
|
|
287
291
|
function axisToVec3(axis) {
|
|
288
292
|
switch (axis) {
|
|
289
|
-
case "
|
|
293
|
+
case "X" /* X */:
|
|
290
294
|
return new Vector3(1, 0, 0);
|
|
291
295
|
case "y" /* Y */:
|
|
292
296
|
return new Vector3(0, 1, 0);
|
|
@@ -389,10 +393,7 @@ function serializeMeshKey(key) {
|
|
|
389
393
|
// src/cache/Caching.ts
|
|
390
394
|
import { Caches } from "@inventivetalent/loading-cache";
|
|
391
395
|
import { Time } from "@inventivetalent/time";
|
|
392
|
-
var
|
|
393
|
-
static createAssetCache() {
|
|
394
|
-
return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
395
|
-
}
|
|
396
|
+
var Caching = class {
|
|
396
397
|
/** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
|
|
397
398
|
static get all() {
|
|
398
399
|
return [
|
|
@@ -409,10 +410,7 @@ var _Caching = class _Caching {
|
|
|
409
410
|
this.rawModelCache,
|
|
410
411
|
this.mergedModelCache,
|
|
411
412
|
this.modelTextureAtlasCache,
|
|
412
|
-
this.blockStateCache
|
|
413
|
-
this.listAssetCache,
|
|
414
|
-
this.defaultBlockStatesCache,
|
|
415
|
-
this.entityModelsCache
|
|
413
|
+
this.blockStateCache
|
|
416
414
|
];
|
|
417
415
|
}
|
|
418
416
|
static clear() {
|
|
@@ -423,8 +421,8 @@ var _Caching = class _Caching {
|
|
|
423
421
|
/**
|
|
424
422
|
* Clears every cache and stops its expiry timer.
|
|
425
423
|
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
424
|
+
* loading-cache reschedules that timer indefinitely, so a Node process will not exit until
|
|
425
|
+
* this is called - see {@link shutdown}.
|
|
428
426
|
*/
|
|
429
427
|
static end() {
|
|
430
428
|
for (const cache of this.all) {
|
|
@@ -438,24 +436,20 @@ var _Caching = class _Caching {
|
|
|
438
436
|
};
|
|
439
437
|
}
|
|
440
438
|
};
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
_Caching.listAssetCache = _Caching.createAssetCache();
|
|
456
|
-
_Caching.defaultBlockStatesCache = _Caching.createAssetCache();
|
|
457
|
-
_Caching.entityModelsCache = _Caching.createAssetCache();
|
|
458
|
-
var Caching = _Caching;
|
|
439
|
+
Caching.rawImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(5)).buildAsync();
|
|
440
|
+
Caching.imageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
441
|
+
Caching.canvasImageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
442
|
+
Caching.wrappedImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
443
|
+
Caching.boxGeometryCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(20)).build();
|
|
444
|
+
Caching.textureCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
445
|
+
Caching.materialCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
446
|
+
Caching.boxMeshCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
447
|
+
Caching.textureAssetCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
448
|
+
Caching.textureMetaCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
449
|
+
Caching.rawModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
450
|
+
Caching.mergedModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
451
|
+
Caching.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
452
|
+
Caching.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
459
453
|
|
|
460
454
|
// src/Geometries.ts
|
|
461
455
|
var Geometries = class _Geometries {
|
|
@@ -483,7 +477,6 @@ import { CanvasTexture, Texture as Texture2 } from "three";
|
|
|
483
477
|
|
|
484
478
|
// src/texture/TextureLoader.ts
|
|
485
479
|
import { RGBAFormat, Texture } from "three";
|
|
486
|
-
import * as THREE from "three";
|
|
487
480
|
|
|
488
481
|
// src/canvas/CanvasCompat.ts
|
|
489
482
|
function createImage(width, height) {
|
|
@@ -494,7 +487,9 @@ function createCanvas(width, height) {
|
|
|
494
487
|
}
|
|
495
488
|
|
|
496
489
|
// src/request/Requests.ts
|
|
497
|
-
import
|
|
490
|
+
import axios from "axios";
|
|
491
|
+
import { JobQueue } from "jobqu";
|
|
492
|
+
import { Time as Time2 } from "@inventivetalent/time";
|
|
498
493
|
|
|
499
494
|
// src/util/log.ts
|
|
500
495
|
var Reset = "\x1B[0m";
|
|
@@ -504,170 +499,198 @@ function prefix(prefix2) {
|
|
|
504
499
|
return `${FgGreen}MR${BgBlack}${prefix2 ?? ""}${Reset}`;
|
|
505
500
|
}
|
|
506
501
|
|
|
507
|
-
// src/
|
|
508
|
-
var
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
this.
|
|
513
|
-
this.
|
|
514
|
-
this.name = "RequestError";
|
|
502
|
+
// src/util/BatchedExecutor.ts
|
|
503
|
+
var BatchedExecutor = class {
|
|
504
|
+
constructor(interval = 1, batch = 30) {
|
|
505
|
+
this.interval = interval;
|
|
506
|
+
this.batch = batch;
|
|
507
|
+
this.queue = [];
|
|
508
|
+
this.task = setInterval(() => this.run());
|
|
515
509
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
headers.set("User-Agent", "MineRender");
|
|
523
|
-
}
|
|
524
|
-
const attemptSignal = AbortSignal.any([
|
|
525
|
-
...signal ? [signal] : [],
|
|
526
|
-
...timeout === 0 ? [] : [AbortSignal.timeout(timeout)]
|
|
527
|
-
]);
|
|
528
|
-
const request = new Request(target, { ...options, headers, signal: attemptSignal });
|
|
529
|
-
attemptSignal.throwIfAborted();
|
|
530
|
-
try {
|
|
531
|
-
const response = await fetch(request);
|
|
532
|
-
const result = {
|
|
533
|
-
data: void 0,
|
|
534
|
-
status: response.status,
|
|
535
|
-
statusText: response.statusText,
|
|
536
|
-
headers: response.headers,
|
|
537
|
-
url: response.url
|
|
538
|
-
};
|
|
539
|
-
if (!response.ok) {
|
|
540
|
-
await response.body?.cancel().catch(() => {
|
|
541
|
-
});
|
|
542
|
-
throw new RequestError(`Request failed with status ${response.status}`, result);
|
|
510
|
+
submit(task) {
|
|
511
|
+
this.queue.push(task);
|
|
512
|
+
}
|
|
513
|
+
run() {
|
|
514
|
+
for (let i = 0; i < this.batch; i++) {
|
|
515
|
+
this.runNext();
|
|
543
516
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
517
|
+
}
|
|
518
|
+
runNext() {
|
|
519
|
+
let next = this.queue.shift();
|
|
520
|
+
if (next) next();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/util/model.ts
|
|
525
|
+
import { AxesHelper, BoxGeometry as BoxGeometry2, EdgesGeometry, LineBasicMaterial, LineSegments, Vector3 as Vector32 } from "three";
|
|
526
|
+
function applyElementRotation(rotation, geometry) {
|
|
527
|
+
const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
528
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
529
|
+
switch (rotation.axis) {
|
|
530
|
+
case "X" /* X */:
|
|
531
|
+
geometry.rotateX(toRadians(rotation.angle));
|
|
532
|
+
break;
|
|
533
|
+
case "y" /* Y */:
|
|
534
|
+
geometry.rotateY(toRadians(rotation.angle));
|
|
535
|
+
break;
|
|
536
|
+
case "z" /* Z */:
|
|
537
|
+
geometry.rotateZ(toRadians(rotation.angle));
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
if (rotation.rescale) {
|
|
541
|
+
if (Math.abs(rotation.angle) === 22.5) {
|
|
542
|
+
const s = 1 / Math.cos(0.39269909262657166);
|
|
543
|
+
geometry.scale(s, 1, s);
|
|
544
|
+
} else {
|
|
545
|
+
const s = 1 / Math.cos(0.7853981852531433);
|
|
546
|
+
geometry.scale(s, 1, s);
|
|
551
547
|
}
|
|
552
|
-
throw error;
|
|
553
548
|
}
|
|
549
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
554
550
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
551
|
+
function applyModelPartRotation(modelPart, geometry) {
|
|
552
|
+
const origin = new Vector32(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
553
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
554
|
+
geometry.rotateX(toRadians(modelPart.pitch));
|
|
555
|
+
geometry.rotateY(toRadians(modelPart.yaw));
|
|
556
|
+
geometry.rotateZ(toRadians(modelPart.roll));
|
|
557
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
558
|
+
}
|
|
559
|
+
function applyGenericRotation(axis, rotation, obj) {
|
|
560
|
+
switch (axis) {
|
|
561
|
+
case "X" /* X */:
|
|
562
|
+
obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
|
|
563
|
+
break;
|
|
564
|
+
case "y" /* Y */:
|
|
565
|
+
obj.rotateOnAxis(new Vector32(0, 1, 0), toRadians(rotation));
|
|
566
|
+
break;
|
|
567
|
+
case "z" /* Z */:
|
|
568
|
+
obj.rotateOnAxis(new Vector32(0, 0, 1), toRadians(rotation));
|
|
569
|
+
break;
|
|
567
570
|
}
|
|
568
571
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
572
|
+
function addBox3WireframeToObject(box, obj, color = 16777215, w = 2) {
|
|
573
|
+
let size = new Vector32();
|
|
574
|
+
box.getSize(size);
|
|
575
|
+
let boxGeo = new BoxGeometry2(size.x, size.y, size.z, 1, 1, 1);
|
|
576
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
577
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
578
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
579
|
+
obj.add(wireframe);
|
|
580
|
+
let axes = new AxesHelper(1);
|
|
581
|
+
obj.add(axes);
|
|
582
|
+
}
|
|
583
|
+
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
584
|
+
let boxGeo = new BoxGeometry2(16, 16, 16, 1, 1, 1);
|
|
585
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
586
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
587
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
588
|
+
obj.add(wireframe);
|
|
589
|
+
let axes = new AxesHelper(1);
|
|
590
|
+
obj.add(axes);
|
|
591
|
+
}
|
|
592
|
+
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
593
|
+
let wireGeo = new EdgesGeometry(geo);
|
|
594
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
595
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
596
|
+
mesh.add(wireframe);
|
|
597
|
+
let axes = new AxesHelper(1);
|
|
598
|
+
mesh.add(axes);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/util/performance.ts
|
|
602
|
+
function captureException(e, ...extra) {
|
|
603
|
+
console.error(e, extra);
|
|
604
|
+
}
|
|
605
|
+
function timingStart(marker) {
|
|
606
|
+
console.time(marker);
|
|
607
|
+
}
|
|
608
|
+
function timingEnd(marker) {
|
|
609
|
+
console.timeEnd(marker);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/util/three.ts
|
|
613
|
+
function isObject3D(obj) {
|
|
614
|
+
return obj.isObject3D;
|
|
615
|
+
}
|
|
616
|
+
function isMesh(obj) {
|
|
617
|
+
return obj.isMesh;
|
|
618
|
+
}
|
|
619
|
+
function isInstancedMesh(obj) {
|
|
620
|
+
return obj.isInstancedMesh;
|
|
621
|
+
}
|
|
622
|
+
function isPerspectiveCamera(obj) {
|
|
623
|
+
return obj.isPerspectiveCamera;
|
|
624
|
+
}
|
|
625
|
+
function isOrthographicCamera(obj) {
|
|
626
|
+
return obj.isOrthographicCamera;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/request/Requests.ts
|
|
630
|
+
var p = prefix("Requests");
|
|
631
|
+
if (typeof window === "undefined") {
|
|
632
|
+
axios.defaults.headers["User-Agent"] = "MineRender";
|
|
633
|
+
}
|
|
634
|
+
var _Requests = class _Requests {
|
|
635
|
+
static genericRequest(request) {
|
|
636
|
+
return this.genericQueue.add(request).catch(async (e) => {
|
|
637
|
+
console.debug(p, "generic catch", e.code, e);
|
|
638
|
+
if (this.shouldRetry(e, request)) {
|
|
639
|
+
await sleep(100);
|
|
640
|
+
return this.genericRequest(request);
|
|
641
|
+
}
|
|
642
|
+
throw e;
|
|
643
|
+
});
|
|
577
644
|
}
|
|
578
|
-
|
|
579
|
-
this.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
645
|
+
static mcAssetRequest(request) {
|
|
646
|
+
return this.mcAssetRequestQueue.add(request).catch((e) => {
|
|
647
|
+
console.debug(p, "mcAssetRequest catch", e.code, e);
|
|
648
|
+
throw e;
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
static shouldRetry(e, request) {
|
|
652
|
+
if ("code" in e) {
|
|
653
|
+
if ("ECONNABORTED" === e.code) {
|
|
654
|
+
if ("minerenderRetry" in request) {
|
|
655
|
+
if (request["minerenderRetry"] > 0) {
|
|
656
|
+
request["minerenderRetry"]--;
|
|
657
|
+
return true;
|
|
591
658
|
}
|
|
592
|
-
|
|
659
|
+
} else {
|
|
660
|
+
request["minerenderRetry"] = 3;
|
|
661
|
+
return true;
|
|
593
662
|
}
|
|
594
663
|
}
|
|
595
|
-
} finally {
|
|
596
|
-
if (signal?.aborted) {
|
|
597
|
-
this.queue.remove(request);
|
|
598
|
-
}
|
|
599
|
-
this.pendingRequests--;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
retryDelay(error, request, retries) {
|
|
603
|
-
if (this.stopped.signal.aborted || retries >= 3 || (request.method ?? "get").toLowerCase() !== "get" || request.signal?.aborted) {
|
|
604
|
-
return void 0;
|
|
605
|
-
}
|
|
606
|
-
if (error instanceof RequestError) {
|
|
607
|
-
const status = error.response?.status;
|
|
608
|
-
if (status !== void 0 && status !== 408 && status !== 429 && !(status >= 500 && status < 600)) return void 0;
|
|
609
|
-
} else if (!(error instanceof DOMException && error.name === "TimeoutError")) {
|
|
610
|
-
return void 0;
|
|
611
|
-
}
|
|
612
|
-
let delay = 100 * 2 ** retries;
|
|
613
|
-
const retryAfter = error instanceof RequestError ? error.response?.headers.get("Retry-After") : void 0;
|
|
614
|
-
if (retryAfter !== void 0 && retryAfter !== null) {
|
|
615
|
-
const seconds = Number(retryAfter);
|
|
616
|
-
if (!retryAfter.trim() || !Number.isFinite(seconds) || seconds < 0) {
|
|
617
|
-
return void 0;
|
|
618
|
-
}
|
|
619
|
-
delay = Math.max(delay, seconds * 1e3);
|
|
620
664
|
}
|
|
621
|
-
return
|
|
622
|
-
}
|
|
623
|
-
async waitForRetry(delay, signal) {
|
|
624
|
-
let timer;
|
|
625
|
-
const waiting = new Promise((resolve) => {
|
|
626
|
-
timer = setTimeout(resolve, delay);
|
|
627
|
-
});
|
|
628
|
-
try {
|
|
629
|
-
await abortable(waiting, AbortSignal.any([this.stopped.signal, ...signal ? [signal] : []]));
|
|
630
|
-
} finally {
|
|
631
|
-
clearTimeout(timer);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
get pendingSize() {
|
|
635
|
-
return this.pendingRequests;
|
|
636
|
-
}
|
|
637
|
-
end() {
|
|
638
|
-
this.queue.end();
|
|
639
|
-
this.stopped.abort(new JobCancelledError("ended"));
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
var Requests = class {
|
|
643
|
-
static genericRequest(request) {
|
|
644
|
-
return this.genericQueue.request(request);
|
|
645
|
-
}
|
|
646
|
-
static mcAssetRequest(request) {
|
|
647
|
-
return this.mcAssetRequestQueue.request(request);
|
|
665
|
+
return false;
|
|
648
666
|
}
|
|
649
667
|
static setMcAssetRoot(root) {
|
|
650
|
-
this.
|
|
668
|
+
this.mcAssetInstance.defaults.baseURL = root;
|
|
651
669
|
}
|
|
652
|
-
/** Counts unsettled calls, including retry delays and requests still running after shutdown. */
|
|
653
670
|
static get queueSizes() {
|
|
654
671
|
return {
|
|
655
|
-
generic: this.genericQueue.
|
|
656
|
-
mcAsset: this.mcAssetRequestQueue.
|
|
672
|
+
generic: this.genericQueue.size,
|
|
673
|
+
mcAsset: this.mcAssetRequestQueue.size
|
|
657
674
|
};
|
|
658
675
|
}
|
|
659
676
|
/**
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
* this cleanup. See {@link shutdown}.
|
|
677
|
+
* Stops both queue timers. jobqu reschedules itself indefinitely, so a Node process will not
|
|
678
|
+
* exit until this is called - see {@link shutdown}.
|
|
663
679
|
*/
|
|
664
680
|
static end() {
|
|
665
681
|
this.genericQueue.end();
|
|
666
682
|
this.mcAssetRequestQueue.end();
|
|
667
683
|
}
|
|
668
684
|
};
|
|
669
|
-
|
|
670
|
-
|
|
685
|
+
_Requests.axiosInstance = axios.create({
|
|
686
|
+
timeout: 5e3
|
|
687
|
+
});
|
|
688
|
+
_Requests.mcAssetInstance = axios.create({
|
|
689
|
+
timeout: 5e3
|
|
690
|
+
});
|
|
691
|
+
_Requests.genericQueue = new JobQueue((request) => _Requests.axiosInstance.request(request), Time2.millis(10), 1);
|
|
692
|
+
_Requests.mcAssetRequestQueue = new JobQueue((request) => _Requests.mcAssetInstance.request(request), Time2.millis(10), 1);
|
|
693
|
+
var Requests = _Requests;
|
|
671
694
|
|
|
672
695
|
// src/WrappedImage.ts
|
|
673
696
|
var WrappedImage = class {
|
|
@@ -705,10 +728,10 @@ var WrappedImage = class {
|
|
|
705
728
|
return this.animated ? this.width : this.height;
|
|
706
729
|
}
|
|
707
730
|
get frameCount() {
|
|
708
|
-
return this.height / this.
|
|
731
|
+
return this.height / this.width;
|
|
709
732
|
}
|
|
710
733
|
getFrameY(frame) {
|
|
711
|
-
return this.
|
|
734
|
+
return this.height / this.frameCount * Math.max(0, Math.min(this.frameCount, frame));
|
|
712
735
|
}
|
|
713
736
|
getSectionData(sx, sy, sw, sh) {
|
|
714
737
|
return this.dta.data.getImageData(sx, sy, sw, sh);
|
|
@@ -718,7 +741,7 @@ var WrappedImage = class {
|
|
|
718
741
|
}
|
|
719
742
|
getFrameSectionData(frame) {
|
|
720
743
|
const y = this.getFrameY(frame);
|
|
721
|
-
return this.getSectionData(0, y, this.
|
|
744
|
+
return this.getSectionData(0, y, this.width, this.width + y);
|
|
722
745
|
}
|
|
723
746
|
};
|
|
724
747
|
|
|
@@ -732,41 +755,29 @@ var ImageLoader = class _ImageLoader {
|
|
|
732
755
|
static async loadAsync(src) {
|
|
733
756
|
return new Promise((resolve, reject) => {
|
|
734
757
|
const image = this._createImage();
|
|
735
|
-
image.onload = () => resolve(image);
|
|
736
|
-
image.onerror = (err) => reject(err instanceof Error ? err : new Error("Failed to decode image"));
|
|
737
758
|
image.src = src;
|
|
759
|
+
image.onload = () => resolve(image);
|
|
760
|
+
image.onerror = (err) => reject(err);
|
|
738
761
|
});
|
|
739
762
|
}
|
|
740
763
|
static loadElement(src, onload, onerr) {
|
|
741
764
|
const image = this._createImage();
|
|
765
|
+
image.src = src;
|
|
742
766
|
if (onload)
|
|
743
767
|
image.onload = onload;
|
|
744
768
|
if (onerr)
|
|
745
769
|
image.onerror = onerr;
|
|
746
|
-
image.src = src;
|
|
747
770
|
return image;
|
|
748
771
|
}
|
|
749
772
|
static async loadData(src) {
|
|
750
773
|
console.debug(p2, "loadData", src);
|
|
751
|
-
|
|
752
|
-
return image.data.getImageData(0, 0, image.width, image.height);
|
|
774
|
+
return await this.infoToData(await this.getInfo(src));
|
|
753
775
|
}
|
|
754
776
|
static async loadCanvasData(src) {
|
|
755
|
-
|
|
756
|
-
const info = this.getInfo(src);
|
|
757
|
-
const cached = Caching.rawImageCache.getIfPresent(keyStr);
|
|
758
|
-
try {
|
|
759
|
-
return await this.infoToCanvasData(await info);
|
|
760
|
-
} catch (err) {
|
|
761
|
-
if (cached && Caching.rawImageCache.getIfPresent(keyStr) === cached) {
|
|
762
|
-
Caching.rawImageCache.invalidate(keyStr);
|
|
763
|
-
}
|
|
764
|
-
throw err;
|
|
765
|
-
}
|
|
777
|
+
return await this.infoToCanvasData(await this.getInfo(src));
|
|
766
778
|
}
|
|
767
779
|
static async infoToCanvasData(info) {
|
|
768
|
-
const
|
|
769
|
-
const image = await _ImageLoader.loadAsync(`data:image/${type};base64,${info.data.toString("base64")}`);
|
|
780
|
+
const image = await _ImageLoader.loadAsync(info.src);
|
|
770
781
|
const canvas = createCanvas(info.width, info.height);
|
|
771
782
|
const context = canvas.getContext("2d");
|
|
772
783
|
context.drawImage(image, 0, 0);
|
|
@@ -777,8 +788,11 @@ var ImageLoader = class _ImageLoader {
|
|
|
777
788
|
};
|
|
778
789
|
}
|
|
779
790
|
static async infoToData(info) {
|
|
780
|
-
const image = await
|
|
781
|
-
|
|
791
|
+
const image = await _ImageLoader.loadAsync(info.src);
|
|
792
|
+
const canvas = createCanvas(info.width, info.height);
|
|
793
|
+
const context = canvas.getContext("2d");
|
|
794
|
+
context.drawImage(image, 0, 0);
|
|
795
|
+
return context.getImageData(0, 0, canvas.width, canvas.height);
|
|
782
796
|
}
|
|
783
797
|
static async getData(src) {
|
|
784
798
|
const keyStr = serializeImageKey({ src });
|
|
@@ -793,25 +807,38 @@ var ImageLoader = class _ImageLoader {
|
|
|
793
807
|
});
|
|
794
808
|
}
|
|
795
809
|
static async processResponse(response) {
|
|
796
|
-
const src = response.url;
|
|
810
|
+
const src = response.config.url;
|
|
797
811
|
const data = Buffer2.from(response.data);
|
|
798
812
|
const { width, height, type } = Env.provider.imageSize(data);
|
|
799
|
-
if (!width || !height) {
|
|
800
|
-
throw new Error("Invalid or unsupported image dimensions");
|
|
801
|
-
}
|
|
802
813
|
return {
|
|
803
814
|
src,
|
|
804
|
-
width,
|
|
805
|
-
height,
|
|
815
|
+
width: width || 0,
|
|
816
|
+
height: height || 0,
|
|
806
817
|
type,
|
|
807
818
|
data
|
|
808
819
|
};
|
|
809
820
|
}
|
|
810
821
|
static async loadInfo(src) {
|
|
822
|
+
if (src.startsWith("data:image/png;base64")) {
|
|
823
|
+
return this.processResponse({
|
|
824
|
+
config: {
|
|
825
|
+
url: src
|
|
826
|
+
},
|
|
827
|
+
data: Buffer2.from(src.substr("data:image/png;base64,".length), "base64")
|
|
828
|
+
});
|
|
829
|
+
}
|
|
811
830
|
return Requests.genericRequest({
|
|
812
831
|
url: src,
|
|
813
832
|
responseType: "arraybuffer"
|
|
814
|
-
}).then(this.processResponse)
|
|
833
|
+
}).then(this.processResponse).catch((err) => {
|
|
834
|
+
return {
|
|
835
|
+
src,
|
|
836
|
+
width: 0,
|
|
837
|
+
height: 0,
|
|
838
|
+
type: void 0,
|
|
839
|
+
data: Buffer2.from([0])
|
|
840
|
+
};
|
|
841
|
+
});
|
|
815
842
|
}
|
|
816
843
|
static async getInfo(src) {
|
|
817
844
|
const keyStr = serializeImageKey({ src });
|
|
@@ -833,22 +860,15 @@ var ImageLoader = class _ImageLoader {
|
|
|
833
860
|
|
|
834
861
|
// src/texture/TextureLoader.ts
|
|
835
862
|
var TextureLoader = class {
|
|
836
|
-
/** Reports whether image loading failed, so cached textures can be retried. */
|
|
837
|
-
static hasFailed(texture) {
|
|
838
|
-
return this.failedTextures.has(texture);
|
|
839
|
-
}
|
|
840
863
|
static createTexture() {
|
|
841
864
|
return new Texture();
|
|
842
865
|
}
|
|
843
866
|
static loadInBackground(src, format = RGBAFormat, rotation = 0) {
|
|
844
867
|
const texture = this.createTexture();
|
|
845
|
-
|
|
846
|
-
|
|
868
|
+
const image = ImageLoader.loadElement(src);
|
|
869
|
+
image.onload = function() {
|
|
847
870
|
texture.needsUpdate = true;
|
|
848
|
-
}
|
|
849
|
-
this.failedTextures.add(texture);
|
|
850
|
-
console.warn("Failed to load texture", src, error);
|
|
851
|
-
});
|
|
871
|
+
};
|
|
852
872
|
texture.image = image;
|
|
853
873
|
texture.format = format;
|
|
854
874
|
texture.rotation = rotation;
|
|
@@ -856,27 +876,22 @@ var TextureLoader = class {
|
|
|
856
876
|
}
|
|
857
877
|
static load(src, format = RGBAFormat, rotation = 0) {
|
|
858
878
|
const texture = new Texture();
|
|
859
|
-
texture.colorSpace = THREE.SRGBColorSpace;
|
|
860
879
|
ImageLoader.getData(src).then((image) => {
|
|
861
|
-
texture.image = image;
|
|
862
880
|
texture.needsUpdate = true;
|
|
863
|
-
|
|
864
|
-
this.failedTextures.add(texture);
|
|
865
|
-
console.warn("Failed to load texture", src, error);
|
|
881
|
+
texture.image = image;
|
|
866
882
|
});
|
|
867
883
|
texture.format = format;
|
|
868
884
|
texture.rotation = rotation;
|
|
869
885
|
return Textures.initTextureProps(texture);
|
|
870
886
|
}
|
|
871
887
|
};
|
|
872
|
-
TextureLoader.failedTextures = /* @__PURE__ */ new WeakSet();
|
|
873
888
|
|
|
874
889
|
// src/texture/Textures.ts
|
|
875
|
-
import * as
|
|
890
|
+
import * as THREE from "three";
|
|
876
891
|
var Textures = class _Textures {
|
|
877
892
|
static initTextureProps(texture) {
|
|
878
|
-
texture.magFilter =
|
|
879
|
-
texture.minFilter =
|
|
893
|
+
texture.magFilter = THREE.NearestFilter;
|
|
894
|
+
texture.minFilter = THREE.NearestFilter;
|
|
880
895
|
texture.anisotropy = 0;
|
|
881
896
|
return texture;
|
|
882
897
|
}
|
|
@@ -887,16 +902,10 @@ var Textures = class _Textures {
|
|
|
887
902
|
return new Texture2();
|
|
888
903
|
}
|
|
889
904
|
static createCanvasTexture(canvas) {
|
|
890
|
-
|
|
891
|
-
texture.colorSpace = THREE2.SRGBColorSpace;
|
|
892
|
-
return this.initTextureProps(texture);
|
|
905
|
+
return this.initTextureProps(new CanvasTexture(canvas));
|
|
893
906
|
}
|
|
894
907
|
static getImage(key) {
|
|
895
908
|
const keyStr = serializeTextureKey(key);
|
|
896
|
-
const cached = Caching.textureCache.peek(keyStr);
|
|
897
|
-
if (cached && TextureLoader.hasFailed(cached)) {
|
|
898
|
-
Caching.textureCache.invalidate(keyStr);
|
|
899
|
-
}
|
|
900
909
|
return Caching.textureCache.get(keyStr, (k) => {
|
|
901
910
|
return _Textures.createImage(key);
|
|
902
911
|
});
|
|
@@ -952,11 +961,7 @@ var _Materials = class _Materials {
|
|
|
952
961
|
|
|
953
962
|
if (SHADE) {
|
|
954
963
|
|
|
955
|
-
|
|
956
|
-
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
957
|
-
#else
|
|
958
|
-
vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
|
|
959
|
-
#endif
|
|
964
|
+
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
960
965
|
|
|
961
966
|
float yLight = (1.0+N.y) * 0.5;
|
|
962
967
|
light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
|
|
@@ -1014,9 +1019,6 @@ var _Materials = class _Materials {
|
|
|
1014
1019
|
gl_FragColor = vec4(lift + color.rgb * light2, 1.0);
|
|
1015
1020
|
|
|
1016
1021
|
}
|
|
1017
|
-
|
|
1018
|
-
#include <tonemapping_fragment>
|
|
1019
|
-
#include <colorspace_fragment>
|
|
1020
1022
|
}
|
|
1021
1023
|
`;
|
|
1022
1024
|
try {
|
|
@@ -1045,10 +1047,6 @@ var _Materials = class _Materials {
|
|
|
1045
1047
|
}
|
|
1046
1048
|
static getImage(key) {
|
|
1047
1049
|
const keyStr = serializeMaterialKey(key);
|
|
1048
|
-
const map = Caching.materialCache.peek(keyStr)?.map;
|
|
1049
|
-
if (map && TextureLoader.hasFailed(map)) {
|
|
1050
|
-
Caching.materialCache.invalidate(keyStr);
|
|
1051
|
-
}
|
|
1052
1050
|
return Caching.materialCache.get(keyStr, (k) => {
|
|
1053
1051
|
return _Materials.createImage(key);
|
|
1054
1052
|
});
|
|
@@ -1073,10 +1071,10 @@ _Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA
|
|
|
1073
1071
|
var Materials = _Materials;
|
|
1074
1072
|
|
|
1075
1073
|
// src/Meshes.ts
|
|
1076
|
-
import { Mesh } from "three";
|
|
1074
|
+
import { Mesh as Mesh2 } from "three";
|
|
1077
1075
|
var Meshes = class _Meshes {
|
|
1078
1076
|
static createBox(key) {
|
|
1079
|
-
return new
|
|
1077
|
+
return new Mesh2(Geometries.getBox(key.geometry), Materials.getImage(key.material));
|
|
1080
1078
|
}
|
|
1081
1079
|
static getBox(key) {
|
|
1082
1080
|
const keyStr = serializeMeshKey(key);
|
|
@@ -1143,7 +1141,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1143
1141
|
}
|
|
1144
1142
|
toString() {
|
|
1145
1143
|
let a = [
|
|
1146
|
-
this.root ?? AssetLoader.ROOT,
|
|
1144
|
+
typeof this.root !== "undefined" || AssetLoader.ROOT !== DEFAULT_ROOT ? this.root ?? AssetLoader.ROOT : "__root__",
|
|
1147
1145
|
this.rootType ?? "__rootType__",
|
|
1148
1146
|
this.assetType ?? "__assetType__",
|
|
1149
1147
|
this.type ?? "__type__",
|
|
@@ -1153,12 +1151,12 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1153
1151
|
return a.join("/");
|
|
1154
1152
|
}
|
|
1155
1153
|
getFullPath() {
|
|
1156
|
-
let
|
|
1154
|
+
let p13 = [];
|
|
1157
1155
|
if (this.type) {
|
|
1158
|
-
|
|
1156
|
+
p13.push(this.type);
|
|
1159
1157
|
}
|
|
1160
|
-
|
|
1161
|
-
return
|
|
1158
|
+
p13.push(this.path);
|
|
1159
|
+
return p13.join("/");
|
|
1162
1160
|
}
|
|
1163
1161
|
toNamespacedString() {
|
|
1164
1162
|
return this.namespace + ":" + this.getFullPath();
|
|
@@ -1180,10 +1178,10 @@ var ModelMerger = class {
|
|
|
1180
1178
|
const models = await this.collectAllParents(model);
|
|
1181
1179
|
let merged = {};
|
|
1182
1180
|
for (let parentModel of models) {
|
|
1183
|
-
merged = import_ts_deepmerge.default
|
|
1181
|
+
merged = (0, import_ts_deepmerge.default)(merged, parentModel);
|
|
1184
1182
|
}
|
|
1185
|
-
merged = import_ts_deepmerge.default
|
|
1186
|
-
merged.hierarchy = models.map((m) => m.parent).filter((
|
|
1183
|
+
merged = (0, import_ts_deepmerge.default)(merged, model);
|
|
1184
|
+
merged.hierarchy = models.map((m) => m.parent).filter((p13) => `${p13}`);
|
|
1187
1185
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1188
1186
|
return merged;
|
|
1189
1187
|
}
|
|
@@ -1193,7 +1191,6 @@ var ModelMerger = class {
|
|
|
1193
1191
|
}
|
|
1194
1192
|
const models = [];
|
|
1195
1193
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1196
|
-
parentKey.root = model.key?.root;
|
|
1197
1194
|
const parentModel = await Models.getRaw(parentKey);
|
|
1198
1195
|
if (parentModel) {
|
|
1199
1196
|
models.unshift(parentModel);
|
|
@@ -1203,6 +1200,9 @@ var ModelMerger = class {
|
|
|
1203
1200
|
}
|
|
1204
1201
|
};
|
|
1205
1202
|
|
|
1203
|
+
// src/assets/Models.ts
|
|
1204
|
+
import { Memoize } from "typescript-memoize";
|
|
1205
|
+
|
|
1206
1206
|
// src/assets/source/parser/AssetParsers.ts
|
|
1207
1207
|
var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
1208
1208
|
AssetParser2["MODEL"] = "model";
|
|
@@ -1216,65 +1216,30 @@ var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
|
1216
1216
|
})(AssetParser || {});
|
|
1217
1217
|
|
|
1218
1218
|
// src/assets/Models.ts
|
|
1219
|
-
var
|
|
1219
|
+
var _Models = class _Models {
|
|
1220
1220
|
// opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
|
|
1221
1221
|
// the library, and would require an EnvProvider before any entry has had a chance to register
|
|
1222
1222
|
static get PERSISTENT_CACHE() {
|
|
1223
1223
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
|
|
1224
1224
|
}
|
|
1225
1225
|
static async getItemList() {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1226
|
+
return AssetLoader.get(new AssetKey(
|
|
1227
|
+
DEFAULT_NAMESPACE,
|
|
1228
|
+
"_list",
|
|
1229
|
+
"models",
|
|
1230
|
+
"item",
|
|
1231
|
+
"assets",
|
|
1232
|
+
".json",
|
|
1233
|
+
DEFAULT_ROOT
|
|
1234
|
+
), "list" /* LIST */).then((r) => r?.files ?? []);
|
|
1231
1235
|
}
|
|
1232
1236
|
static async loadAndMerge(key) {
|
|
1233
|
-
const model =
|
|
1237
|
+
const model = await this.getRaw(key);
|
|
1234
1238
|
if (!model) {
|
|
1235
1239
|
return void 0;
|
|
1236
1240
|
}
|
|
1237
1241
|
return ModelMerger.mergeWithParents(model);
|
|
1238
1242
|
}
|
|
1239
|
-
static async getItemModel(key) {
|
|
1240
|
-
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1241
|
-
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1242
|
-
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1243
|
-
if (!result) return void 0;
|
|
1244
|
-
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1245
|
-
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1246
|
-
const modelKey = AssetKey.parse("models", reference);
|
|
1247
|
-
modelKey.root = key.root;
|
|
1248
|
-
const model2 = await this.getRaw(modelKey);
|
|
1249
|
-
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1250
|
-
return model2;
|
|
1251
|
-
});
|
|
1252
|
-
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1253
|
-
}
|
|
1254
|
-
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1255
|
-
static defaultItemModel(node, key) {
|
|
1256
|
-
if (!node || typeof node.type !== "string") {
|
|
1257
|
-
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1258
|
-
}
|
|
1259
|
-
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1260
|
-
case "model":
|
|
1261
|
-
if (typeof node.model === "string" && node.model) return node.model;
|
|
1262
|
-
break;
|
|
1263
|
-
case "condition":
|
|
1264
|
-
return this.defaultItemModel(node.on_false, key);
|
|
1265
|
-
case "select": {
|
|
1266
|
-
const selected = node.property?.replace(/^minecraft:/, "") === "display_context" ? node.cases?.find((entry) => Array.isArray(entry.when) ? entry.when.includes("gui") : entry.when === "gui")?.model : void 0;
|
|
1267
|
-
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1268
|
-
}
|
|
1269
|
-
case "range_dispatch": {
|
|
1270
|
-
const selected = node.entries?.reduce((match, entry) => {
|
|
1271
|
-
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1272
|
-
}, void 0);
|
|
1273
|
-
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1277
|
-
}
|
|
1278
1243
|
static async getRaw(key) {
|
|
1279
1244
|
if (!key.assetType) {
|
|
1280
1245
|
key.assetType = "models";
|
|
@@ -1313,15 +1278,19 @@ var Models = class _Models {
|
|
|
1313
1278
|
return this.PERSISTENT_CACHE.clear();
|
|
1314
1279
|
}
|
|
1315
1280
|
};
|
|
1281
|
+
__decorateClass([
|
|
1282
|
+
Memoize()
|
|
1283
|
+
], _Models, "getItemList", 1);
|
|
1284
|
+
var Models = _Models;
|
|
1316
1285
|
|
|
1317
1286
|
// src/assets/BlockStates.ts
|
|
1287
|
+
import { Memoize as Memoize2 } from "typescript-memoize";
|
|
1318
1288
|
var BlockStates = class {
|
|
1319
1289
|
static get PERSISTENT_CACHE() {
|
|
1320
1290
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-blockstates"));
|
|
1321
1291
|
}
|
|
1322
|
-
// BlockState names are hardcoded
|
|
1323
1292
|
static async getList() {
|
|
1324
|
-
|
|
1293
|
+
return AssetLoader.get(new AssetKey(
|
|
1325
1294
|
DEFAULT_NAMESPACE,
|
|
1326
1295
|
"_list",
|
|
1327
1296
|
"blockstates",
|
|
@@ -1329,16 +1298,11 @@ var BlockStates = class {
|
|
|
1329
1298
|
"assets",
|
|
1330
1299
|
".json",
|
|
1331
1300
|
DEFAULT_ROOT
|
|
1332
|
-
);
|
|
1333
|
-
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1334
|
-
return AssetLoader.get(key, "list" /* LIST */);
|
|
1335
|
-
}).then((r) => r?.files ?? []);
|
|
1301
|
+
), "list" /* LIST */).then((r) => r?.files ?? []);
|
|
1336
1302
|
}
|
|
1337
1303
|
static async getDefaultStates() {
|
|
1338
1304
|
const key = AssetKey.parse("blockstates", "minerender:defaultBlockStates");
|
|
1339
|
-
return
|
|
1340
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
1341
|
-
});
|
|
1305
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
1342
1306
|
}
|
|
1343
1307
|
static async getDefaultState(key) {
|
|
1344
1308
|
const defaultStates = await this.getDefaultStates();
|
|
@@ -1377,11 +1341,17 @@ var BlockStates = class {
|
|
|
1377
1341
|
await this.PERSISTENT_CACHE.clear();
|
|
1378
1342
|
}
|
|
1379
1343
|
};
|
|
1344
|
+
__decorateClass([
|
|
1345
|
+
Memoize2()
|
|
1346
|
+
], BlockStates, "getList", 1);
|
|
1347
|
+
__decorateClass([
|
|
1348
|
+
Memoize2()
|
|
1349
|
+
], BlockStates, "getDefaultStates", 1);
|
|
1380
1350
|
var DefaultBlockStates = class {
|
|
1381
1351
|
};
|
|
1382
1352
|
|
|
1383
1353
|
// src/assets/Assets.ts
|
|
1384
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1354
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.17.1";
|
|
1385
1355
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1386
1356
|
var Assets = class {
|
|
1387
1357
|
/**
|
|
@@ -1403,150 +1373,13 @@ var AssetSource = class {
|
|
|
1403
1373
|
constructor() {
|
|
1404
1374
|
}
|
|
1405
1375
|
};
|
|
1406
|
-
var AssetLoadError = class extends Error {
|
|
1407
|
-
constructor(source, key, path, cause) {
|
|
1408
|
-
super(`Failed to load ${key.toNamespacedString()} from ${path}${cause instanceof Error ? `: ${cause.message}` : ""}`);
|
|
1409
|
-
this.source = source;
|
|
1410
|
-
this.key = key;
|
|
1411
|
-
this.path = path;
|
|
1412
|
-
this.cause = cause;
|
|
1413
|
-
this.name = "AssetLoadError";
|
|
1414
|
-
}
|
|
1415
|
-
};
|
|
1416
1376
|
|
|
1417
|
-
// src/
|
|
1418
|
-
var
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
this.task = setInterval(() => this.run());
|
|
1424
|
-
}
|
|
1425
|
-
submit(task) {
|
|
1426
|
-
this.queue.push(task);
|
|
1427
|
-
}
|
|
1428
|
-
run() {
|
|
1429
|
-
for (let i = 0; i < this.batch; i++) {
|
|
1430
|
-
this.runNext();
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
runNext() {
|
|
1434
|
-
let next = this.queue.shift();
|
|
1435
|
-
if (next) next();
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
// src/util/model.ts
|
|
1440
|
-
import { AxesHelper, BoxGeometry as BoxGeometry2, EdgesGeometry, LineBasicMaterial, LineSegments, Vector3 as Vector32 } from "three";
|
|
1441
|
-
function applyElementRotation(rotation, geometry) {
|
|
1442
|
-
const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1443
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1444
|
-
switch (rotation.axis) {
|
|
1445
|
-
case "x" /* X */:
|
|
1446
|
-
geometry.rotateX(toRadians(rotation.angle));
|
|
1447
|
-
break;
|
|
1448
|
-
case "y" /* Y */:
|
|
1449
|
-
geometry.rotateY(toRadians(rotation.angle));
|
|
1450
|
-
break;
|
|
1451
|
-
case "z" /* Z */:
|
|
1452
|
-
geometry.rotateZ(toRadians(rotation.angle));
|
|
1453
|
-
break;
|
|
1454
|
-
}
|
|
1455
|
-
if (rotation.rescale) {
|
|
1456
|
-
if (Math.abs(rotation.angle) === 22.5) {
|
|
1457
|
-
const s = 1 / Math.cos(0.39269909262657166);
|
|
1458
|
-
geometry.scale(s, 1, s);
|
|
1459
|
-
} else {
|
|
1460
|
-
const s = 1 / Math.cos(0.7853981852531433);
|
|
1461
|
-
geometry.scale(s, 1, s);
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
1465
|
-
}
|
|
1466
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
1467
|
-
const origin = new Vector32(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1468
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1469
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1470
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1471
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1472
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
1473
|
-
}
|
|
1474
|
-
function applyGenericRotation(axis, rotation, obj) {
|
|
1475
|
-
switch (axis) {
|
|
1476
|
-
case "x" /* X */:
|
|
1477
|
-
obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
|
|
1478
|
-
break;
|
|
1479
|
-
case "y" /* Y */:
|
|
1480
|
-
obj.rotateOnAxis(new Vector32(0, 1, 0), toRadians(rotation));
|
|
1481
|
-
break;
|
|
1482
|
-
case "z" /* Z */:
|
|
1483
|
-
obj.rotateOnAxis(new Vector32(0, 0, 1), toRadians(rotation));
|
|
1484
|
-
break;
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
function addBox3WireframeToObject(box, obj, color = 16777215, w = 2) {
|
|
1488
|
-
let size = new Vector32();
|
|
1489
|
-
box.getSize(size);
|
|
1490
|
-
let boxGeo = new BoxGeometry2(size.x, size.y, size.z, 1, 1, 1);
|
|
1491
|
-
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1492
|
-
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1493
|
-
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1494
|
-
obj.add(wireframe);
|
|
1495
|
-
let axes = new AxesHelper(1);
|
|
1496
|
-
obj.add(axes);
|
|
1497
|
-
}
|
|
1498
|
-
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
1499
|
-
let boxGeo = new BoxGeometry2(16, 16, 16, 1, 1, 1);
|
|
1500
|
-
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1501
|
-
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1502
|
-
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1503
|
-
obj.add(wireframe);
|
|
1504
|
-
let axes = new AxesHelper(1);
|
|
1505
|
-
obj.add(axes);
|
|
1506
|
-
}
|
|
1507
|
-
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
1508
|
-
let wireGeo = new EdgesGeometry(geo);
|
|
1509
|
-
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1510
|
-
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1511
|
-
mesh.add(wireframe);
|
|
1512
|
-
let axes = new AxesHelper(1);
|
|
1513
|
-
mesh.add(axes);
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
// src/util/performance.ts
|
|
1517
|
-
function captureException(e, ...extra) {
|
|
1518
|
-
console.error(e, extra);
|
|
1519
|
-
}
|
|
1520
|
-
function timingStart(marker) {
|
|
1521
|
-
console.time(marker);
|
|
1522
|
-
}
|
|
1523
|
-
function timingEnd(marker) {
|
|
1524
|
-
console.timeEnd(marker);
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
// src/util/three.ts
|
|
1528
|
-
function isObject3D(obj) {
|
|
1529
|
-
return obj.isObject3D;
|
|
1530
|
-
}
|
|
1531
|
-
function isMesh(obj) {
|
|
1532
|
-
return obj.isMesh;
|
|
1533
|
-
}
|
|
1534
|
-
function isInstancedMesh(obj) {
|
|
1535
|
-
return obj.isInstancedMesh;
|
|
1536
|
-
}
|
|
1537
|
-
function isPerspectiveCamera(obj) {
|
|
1538
|
-
return obj.isPerspectiveCamera;
|
|
1539
|
-
}
|
|
1540
|
-
function isOrthographicCamera(obj) {
|
|
1541
|
-
return obj.isOrthographicCamera;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
// src/nbt/NBTHelper.ts
|
|
1545
|
-
var NBTHelper = class {
|
|
1546
|
-
static async fromBuffer(buffer) {
|
|
1547
|
-
const prismarineNbt = await import("prismarine-nbt");
|
|
1548
|
-
const { parsed, type, metadata } = await prismarineNbt.parse(buffer);
|
|
1549
|
-
return parsed;
|
|
1377
|
+
// src/nbt/NBTHelper.ts
|
|
1378
|
+
var NBTHelper = class {
|
|
1379
|
+
static async fromBuffer(buffer) {
|
|
1380
|
+
const prismarineNbt = await import("prismarine-nbt");
|
|
1381
|
+
const { parsed, type, metadata } = await prismarineNbt.parse(buffer);
|
|
1382
|
+
return parsed;
|
|
1550
1383
|
}
|
|
1551
1384
|
};
|
|
1552
1385
|
|
|
@@ -1591,25 +1424,31 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1591
1424
|
console.info(p3, "Loading", key);
|
|
1592
1425
|
const url = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1593
1426
|
console.debug(p3, url);
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1427
|
+
let req = {
|
|
1428
|
+
url
|
|
1429
|
+
};
|
|
1430
|
+
parser.config(req);
|
|
1431
|
+
return await Requests.mcAssetRequest(req).then((response) => {
|
|
1432
|
+
if (response && response.data) {
|
|
1433
|
+
try {
|
|
1434
|
+
return parser.parse(response);
|
|
1435
|
+
} catch (e) {
|
|
1436
|
+
console.warn("Parser failed to process response", response, e);
|
|
1437
|
+
throw e;
|
|
1603
1438
|
}
|
|
1604
|
-
throw cause;
|
|
1605
1439
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1440
|
+
return void 0;
|
|
1441
|
+
}).catch((err) => {
|
|
1442
|
+
if (err.response) {
|
|
1443
|
+
let response = err.response;
|
|
1444
|
+
if (response.status === 404) {
|
|
1445
|
+
console.debug(p3, key, "not found");
|
|
1446
|
+
return void 0;
|
|
1447
|
+
}
|
|
1608
1448
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
}
|
|
1449
|
+
console.debug(p3, "Failed to load", key, err?.message);
|
|
1450
|
+
return void 0;
|
|
1451
|
+
});
|
|
1613
1452
|
}
|
|
1614
1453
|
assetBasePath(key) {
|
|
1615
1454
|
return `${key.root ?? this.root ?? AssetLoader.ROOT}/${key.rootType !== void 0 ? key.rootType + "/" : ""}${key.namespace !== void 0 ? key.namespace + "/" : ""}${key.assetType !== void 0 ? key.assetType + "/" : ""}`;
|
|
@@ -1716,6 +1555,7 @@ var BrowserArchiveProxy = class {
|
|
|
1716
1555
|
};
|
|
1717
1556
|
|
|
1718
1557
|
// src/assets/source/archive/ArchiveAssetSource.ts
|
|
1558
|
+
var p4 = prefix("ArchiveAssetSource");
|
|
1719
1559
|
var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
1720
1560
|
constructor(archiveProxy) {
|
|
1721
1561
|
super();
|
|
@@ -1734,31 +1574,74 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1734
1574
|
}
|
|
1735
1575
|
async get(key, parser) {
|
|
1736
1576
|
const responseParser = HostedAssetSource.PARSER_MAP.get(parser);
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
async load(key, parser) {
|
|
1577
|
+
console.log("ArchiveAssetSource.get", key, parser);
|
|
1578
|
+
let entries = await this.getEntries();
|
|
1740
1579
|
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1580
|
+
console.log(path);
|
|
1581
|
+
const entry = await this.getEntry(path);
|
|
1582
|
+
console.log(entry);
|
|
1583
|
+
if (!entry) {
|
|
1584
|
+
return void 0;
|
|
1585
|
+
}
|
|
1586
|
+
let blob = await entry.getData();
|
|
1587
|
+
const url = URL.createObjectURL(blob);
|
|
1588
|
+
console.log(url);
|
|
1589
|
+
let req = {
|
|
1590
|
+
url
|
|
1591
|
+
};
|
|
1592
|
+
responseParser.config(req);
|
|
1593
|
+
return Requests.genericRequest(req).then((response) => {
|
|
1594
|
+
if (response && response.data) {
|
|
1595
|
+
try {
|
|
1596
|
+
return responseParser.parse(response);
|
|
1597
|
+
} catch (e) {
|
|
1598
|
+
console.warn("Parser failed to process response", response, e);
|
|
1599
|
+
throw e;
|
|
1600
|
+
}
|
|
1746
1601
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1602
|
+
return void 0;
|
|
1603
|
+
}).catch((err) => {
|
|
1604
|
+
if (err.response) {
|
|
1605
|
+
let response = err.response;
|
|
1606
|
+
if (response.status === 404) {
|
|
1607
|
+
console.debug(p4, key, "not found");
|
|
1608
|
+
return void 0;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
console.debug(p4, "Failed to load", key, err?.message);
|
|
1612
|
+
return void 0;
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
//TODO: abstract this
|
|
1616
|
+
async load(key, parser) {
|
|
1617
|
+
console.info(p4, "Loading", key);
|
|
1618
|
+
const url = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1619
|
+
console.debug(p4, url);
|
|
1620
|
+
let req = {
|
|
1621
|
+
url
|
|
1622
|
+
};
|
|
1623
|
+
parser.config(req);
|
|
1624
|
+
return await Requests.genericRequest(req).then((response) => {
|
|
1625
|
+
if (response && response.data) {
|
|
1626
|
+
try {
|
|
1627
|
+
return parser.parse(response);
|
|
1628
|
+
} catch (e) {
|
|
1629
|
+
console.warn("Parser failed to process response", response, e);
|
|
1630
|
+
throw e;
|
|
1631
|
+
}
|
|
1753
1632
|
}
|
|
1754
|
-
return
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1633
|
+
return void 0;
|
|
1634
|
+
}).catch((err) => {
|
|
1635
|
+
if (err.response) {
|
|
1636
|
+
let response = err.response;
|
|
1637
|
+
if (response.status === 404) {
|
|
1638
|
+
console.debug(p4, key, "not found");
|
|
1639
|
+
return void 0;
|
|
1640
|
+
}
|
|
1760
1641
|
}
|
|
1761
|
-
|
|
1642
|
+
console.debug(p4, "Failed to load", key, err?.message);
|
|
1643
|
+
return void 0;
|
|
1644
|
+
});
|
|
1762
1645
|
}
|
|
1763
1646
|
assetBasePath(key) {
|
|
1764
1647
|
return `${key.rootType !== void 0 ? key.rootType + "/" : ""}${key.namespace !== void 0 ? key.namespace + "/" : ""}${key.assetType !== void 0 ? key.assetType + "/" : ""}`;
|
|
@@ -1766,17 +1649,18 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1766
1649
|
};
|
|
1767
1650
|
|
|
1768
1651
|
// src/assets/AssetLoader.ts
|
|
1769
|
-
var
|
|
1652
|
+
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
1653
|
+
var p5 = prefix("AssetLoader");
|
|
1770
1654
|
var _AssetLoader = class _AssetLoader {
|
|
1771
1655
|
static addSource(key, source, override = true) {
|
|
1772
1656
|
if (override) {
|
|
1773
1657
|
const existing = this.removeSource(key);
|
|
1774
1658
|
if (existing) {
|
|
1775
|
-
console.log(
|
|
1659
|
+
console.log(p5, "Removed existing AssetSource", key);
|
|
1776
1660
|
}
|
|
1777
1661
|
}
|
|
1778
1662
|
this._SOURCES.unshift({ key, source });
|
|
1779
|
-
console.log(
|
|
1663
|
+
console.log(p5, "Added AssetSource", key);
|
|
1780
1664
|
}
|
|
1781
1665
|
static removeSource(key) {
|
|
1782
1666
|
const index = this._SOURCES.findIndex((s) => s.key === key);
|
|
@@ -1789,6 +1673,7 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1789
1673
|
return void 0;
|
|
1790
1674
|
}
|
|
1791
1675
|
static async getAll(key, parser) {
|
|
1676
|
+
console.log(this._SOURCES);
|
|
1792
1677
|
let promises = [];
|
|
1793
1678
|
for (const source of this._SOURCES) {
|
|
1794
1679
|
promises.push(source.source.get(key, parser));
|
|
@@ -1797,34 +1682,24 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1797
1682
|
return results.filter((r) => r != void 0);
|
|
1798
1683
|
});
|
|
1799
1684
|
}
|
|
1800
|
-
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1801
1685
|
static async get(key, parser) {
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
}
|
|
1816
|
-
/** Tries each path within a source before considering lower-priority sources. */
|
|
1817
|
-
static async getFirst(keys, parser) {
|
|
1818
|
-
const sources = [...this._SOURCES];
|
|
1819
|
-
for (const source of sources) {
|
|
1820
|
-
for (const key of keys) {
|
|
1821
|
-
const result = await source.source.get(key, parser);
|
|
1822
|
-
if (result !== void 0) {
|
|
1823
|
-
return { key, asset: result };
|
|
1686
|
+
console.log(this._SOURCES);
|
|
1687
|
+
let promises = [];
|
|
1688
|
+
for (const source of this._SOURCES) {
|
|
1689
|
+
promises.push(source.source.get(key, parser));
|
|
1690
|
+
}
|
|
1691
|
+
return Promise.all(promises).then((results) => {
|
|
1692
|
+
const fallback = results[results.length - 1];
|
|
1693
|
+
for (const result of results) {
|
|
1694
|
+
if (result) {
|
|
1695
|
+
if (fallback) {
|
|
1696
|
+
return (0, import_ts_deepmerge3.default)({}, fallback, result);
|
|
1697
|
+
}
|
|
1698
|
+
return result;
|
|
1824
1699
|
}
|
|
1825
1700
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1701
|
+
return void 0;
|
|
1702
|
+
});
|
|
1828
1703
|
}
|
|
1829
1704
|
};
|
|
1830
1705
|
_AssetLoader.ROOT = DEFAULT_ROOT;
|
|
@@ -1839,21 +1714,11 @@ var ModelTextures = class {
|
|
|
1839
1714
|
return this._persistentMetaCache ?? (this._persistentMetaCache = PersistentCache.open("minerender-texturemeta"));
|
|
1840
1715
|
}
|
|
1841
1716
|
static async get(key) {
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
try {
|
|
1846
|
-
const asset = await pending;
|
|
1847
|
-
if (asset) {
|
|
1848
|
-
return await ImageLoader.infoToCanvasData(asset);
|
|
1849
|
-
}
|
|
1850
|
-
return void 0;
|
|
1851
|
-
} catch (err) {
|
|
1852
|
-
if (cached && Caching.textureAssetCache.getIfPresent(keyStr) === cached) {
|
|
1853
|
-
Caching.textureAssetCache.invalidate(keyStr);
|
|
1854
|
-
}
|
|
1855
|
-
throw err;
|
|
1717
|
+
const asset = await this.preload(key);
|
|
1718
|
+
if (asset) {
|
|
1719
|
+
return ImageLoader.infoToCanvasData(asset);
|
|
1856
1720
|
}
|
|
1721
|
+
return void 0;
|
|
1857
1722
|
}
|
|
1858
1723
|
static async preload(key) {
|
|
1859
1724
|
const keyStr = key.serialize();
|
|
@@ -2044,7 +1909,7 @@ var ModelGenerator = class {
|
|
|
2044
1909
|
ModelGenerator.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
2045
1910
|
|
|
2046
1911
|
// src/UVMapper.ts
|
|
2047
|
-
var
|
|
1912
|
+
var p6 = prefix("UVMapper");
|
|
2048
1913
|
var DEFAULT_UV = [0, 0, 16, 16];
|
|
2049
1914
|
var X = 0;
|
|
2050
1915
|
var Y = 1;
|
|
@@ -2221,7 +2086,7 @@ var UVMapper = class {
|
|
|
2221
2086
|
const metaMap = {};
|
|
2222
2087
|
const model = { ...originalModel };
|
|
2223
2088
|
const isItemModel = !("elements" in model);
|
|
2224
|
-
console.debug(
|
|
2089
|
+
console.debug(p6, "Creating Atlas for", model.key);
|
|
2225
2090
|
if (model.textures) {
|
|
2226
2091
|
const promises = [];
|
|
2227
2092
|
const uniqueTextureNames = [];
|
|
@@ -2235,7 +2100,7 @@ var UVMapper = class {
|
|
|
2235
2100
|
const assetKey = AssetKey.parse("textures", textureValue, model.key);
|
|
2236
2101
|
promises.push(ModelTextures.get(assetKey).then((asset) => {
|
|
2237
2102
|
if (!asset) {
|
|
2238
|
-
console.warn(
|
|
2103
|
+
console.warn(p6, "Missing texture", assetKey);
|
|
2239
2104
|
return;
|
|
2240
2105
|
}
|
|
2241
2106
|
textureMap[textureKey] = new WrappedImage(asset);
|
|
@@ -2247,7 +2112,7 @@ var UVMapper = class {
|
|
|
2247
2112
|
}
|
|
2248
2113
|
await Promise.all(promises);
|
|
2249
2114
|
const textureCount = uniqueTextureNames.length;
|
|
2250
|
-
console.debug(
|
|
2115
|
+
console.debug(p6, "Creating Atlas for", textureCount, "textures");
|
|
2251
2116
|
this.fillMissingTextureKeys(model.textures, textureMap);
|
|
2252
2117
|
this.fillMissingTextureKeys(model.textures, metaMap);
|
|
2253
2118
|
const sizes = {};
|
|
@@ -2267,7 +2132,7 @@ var UVMapper = class {
|
|
|
2267
2132
|
this.fillMissingTextureKeys(model.textures, sizes);
|
|
2268
2133
|
const s = Math.ceil(Math.sqrt(textureCount + 1));
|
|
2269
2134
|
const size = Math.ceil(s * maxWidth);
|
|
2270
|
-
console.debug(
|
|
2135
|
+
console.debug(p6, "Atlas size:", size);
|
|
2271
2136
|
const squaredSize = size * size;
|
|
2272
2137
|
const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
|
|
2273
2138
|
const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
|
|
@@ -2322,10 +2187,10 @@ var UVMapper = class {
|
|
|
2322
2187
|
}
|
|
2323
2188
|
}
|
|
2324
2189
|
const atlasImageData = image.toDataURL();
|
|
2325
|
-
console.log(
|
|
2190
|
+
console.log(p6, "Atlas Image for", model.key, atlasImageData);
|
|
2326
2191
|
this.fillMissingTextureKeys(model.textures, positions);
|
|
2327
2192
|
if (isItemModel) {
|
|
2328
|
-
console.debug(
|
|
2193
|
+
console.debug(p6, "Generating item model for", model);
|
|
2329
2194
|
model.elements = [];
|
|
2330
2195
|
for (let layerName of ModelGenerator.ITEM_LAYERS) {
|
|
2331
2196
|
const textureImage = textureMap[layerName];
|
|
@@ -2333,7 +2198,7 @@ var UVMapper = class {
|
|
|
2333
2198
|
model.elements.push(...ModelGenerator.generateItemModel(textureImage.data, layerName));
|
|
2334
2199
|
}
|
|
2335
2200
|
}
|
|
2336
|
-
console.debug(
|
|
2201
|
+
console.debug(p6, "Item model elements", model.elements);
|
|
2337
2202
|
}
|
|
2338
2203
|
if (!model.elements) {
|
|
2339
2204
|
}
|
|
@@ -2351,13 +2216,17 @@ var UVMapper = class {
|
|
|
2351
2216
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2352
2217
|
continue;
|
|
2353
2218
|
}
|
|
2354
|
-
if (!face.texture) continue;
|
|
2355
2219
|
if (!face.uv) {
|
|
2356
2220
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2357
2221
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2222
|
+
let faceTexture = face.texture;
|
|
2223
|
+
let texPosition;
|
|
2224
|
+
let texSize;
|
|
2225
|
+
if (faceTexture) {
|
|
2226
|
+
faceTexture = faceTexture.substr(1);
|
|
2227
|
+
texPosition = positions[faceTexture] || [0, 0];
|
|
2228
|
+
texSize = sizes[faceTexture] || [16, 16];
|
|
2229
|
+
}
|
|
2361
2230
|
let texPosV = new Vector2(texPosition[0], texPosition[1]);
|
|
2362
2231
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2363
2232
|
tl.add(texPosV);
|
|
@@ -2389,7 +2258,7 @@ var UVMapper = class {
|
|
|
2389
2258
|
hasTransparency
|
|
2390
2259
|
);
|
|
2391
2260
|
} else {
|
|
2392
|
-
console.warn(
|
|
2261
|
+
console.warn(p6, "Model does not have any textures", model);
|
|
2393
2262
|
}
|
|
2394
2263
|
return void 0;
|
|
2395
2264
|
}
|
|
@@ -2527,20 +2396,17 @@ function shutdown() {
|
|
|
2527
2396
|
}
|
|
2528
2397
|
|
|
2529
2398
|
// src/assets/Entities.ts
|
|
2399
|
+
import { Memoize as Memoize3 } from "typescript-memoize";
|
|
2530
2400
|
var Entities = class {
|
|
2531
2401
|
static async getBlockEntityModels() {
|
|
2532
2402
|
const key = AssetKey.parse("models", "minerender:blockEntityModels");
|
|
2533
2403
|
console.log(key);
|
|
2534
|
-
return
|
|
2535
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2536
|
-
});
|
|
2404
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2537
2405
|
}
|
|
2538
2406
|
static async getEntityModels() {
|
|
2539
2407
|
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2540
2408
|
console.log(key);
|
|
2541
|
-
return
|
|
2542
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2543
|
-
});
|
|
2409
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2544
2410
|
}
|
|
2545
2411
|
// BlockEntity names are hardcoded
|
|
2546
2412
|
static async getBlockList() {
|
|
@@ -2586,6 +2452,12 @@ var Entities = class {
|
|
|
2586
2452
|
};
|
|
2587
2453
|
}
|
|
2588
2454
|
};
|
|
2455
|
+
__decorateClass([
|
|
2456
|
+
Memoize3()
|
|
2457
|
+
], Entities, "getBlockEntityModels", 1);
|
|
2458
|
+
__decorateClass([
|
|
2459
|
+
Memoize3()
|
|
2460
|
+
], Entities, "getEntityModels", 1);
|
|
2589
2461
|
var EntityModels = class {
|
|
2590
2462
|
};
|
|
2591
2463
|
var BlockEntityModels = class {
|
|
@@ -2649,8 +2521,8 @@ var MineRenderError = class _MineRenderError extends Error {
|
|
|
2649
2521
|
};
|
|
2650
2522
|
|
|
2651
2523
|
// src/renderer/SceneObject.ts
|
|
2652
|
-
var
|
|
2653
|
-
var
|
|
2524
|
+
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
2525
|
+
var p7 = prefix("SceneObject");
|
|
2654
2526
|
var _SceneObject = class _SceneObject extends Object3D2 {
|
|
2655
2527
|
constructor(options) {
|
|
2656
2528
|
super();
|
|
@@ -2658,7 +2530,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2658
2530
|
this.materialCallbacks = {};
|
|
2659
2531
|
this._isInstanced = false;
|
|
2660
2532
|
this._instanceCounter = 0;
|
|
2661
|
-
this.options = (0,
|
|
2533
|
+
this.options = (0, import_ts_deepmerge4.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2662
2534
|
console.log("SceneObject options", this.options);
|
|
2663
2535
|
}
|
|
2664
2536
|
set scene(scene) {
|
|
@@ -2829,9 +2701,9 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2829
2701
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2830
2702
|
const i = this._instanceCounter++;
|
|
2831
2703
|
this.setMatrixAt(i, new Matrix42());
|
|
2832
|
-
console.debug(
|
|
2704
|
+
console.debug(p7, "nextInstance " + i);
|
|
2833
2705
|
if (i === this.options.maxInstanceCount) {
|
|
2834
|
-
console.warn(
|
|
2706
|
+
console.warn(p7, "Max instance count reached for " + this);
|
|
2835
2707
|
}
|
|
2836
2708
|
if (this.scene) {
|
|
2837
2709
|
this.scene.stats.instanceCount++;
|
|
@@ -3007,7 +2879,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3007
2879
|
}
|
|
3008
2880
|
//</editor-fold>
|
|
3009
2881
|
};
|
|
3010
|
-
_SceneObject.DEFAULT_OPTIONS = (0,
|
|
2882
|
+
_SceneObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, {
|
|
3011
2883
|
instanceMeshes: true,
|
|
3012
2884
|
maxInstanceCount: 50,
|
|
3013
2885
|
mergeMeshes: true,
|
|
@@ -3019,16 +2891,16 @@ function isSceneObject(obj) {
|
|
|
3019
2891
|
}
|
|
3020
2892
|
|
|
3021
2893
|
// src/entity/scene/EntityObject.ts
|
|
3022
|
-
var
|
|
2894
|
+
var import_ts_deepmerge5 = __toESM(require_dist());
|
|
3023
2895
|
import { Object3D as Object3D3 } from "three";
|
|
3024
|
-
import * as
|
|
2896
|
+
import * as THREE2 from "three";
|
|
3025
2897
|
var EntityObject = class extends SceneObject {
|
|
3026
2898
|
constructor(entity, options) {
|
|
3027
2899
|
super();
|
|
3028
2900
|
this.entity = entity;
|
|
3029
2901
|
this.isEntityObject = true;
|
|
3030
2902
|
this.meshesCreated = false;
|
|
3031
|
-
this.options = (0,
|
|
2903
|
+
this.options = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
3032
2904
|
}
|
|
3033
2905
|
async init() {
|
|
3034
2906
|
this.createMeshes();
|
|
@@ -3037,8 +2909,8 @@ var EntityObject = class extends SceneObject {
|
|
|
3037
2909
|
dispose() {
|
|
3038
2910
|
super.dispose();
|
|
3039
2911
|
}
|
|
3040
|
-
|
|
3041
|
-
|
|
2912
|
+
async loadTextures() {
|
|
2913
|
+
this.imageData = await ModelTextures.get(new AssetKey(
|
|
3042
2914
|
this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
|
|
3043
2915
|
this.entity.key.path,
|
|
3044
2916
|
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
@@ -3046,10 +2918,7 @@ var EntityObject = class extends SceneObject {
|
|
|
3046
2918
|
"entity",
|
|
3047
2919
|
"assets",
|
|
3048
2920
|
".png"
|
|
3049
|
-
);
|
|
3050
|
-
}
|
|
3051
|
-
async loadTextures() {
|
|
3052
|
-
this.imageData = await ModelTextures.get(this.textureKey);
|
|
2921
|
+
));
|
|
3053
2922
|
}
|
|
3054
2923
|
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
3055
2924
|
createMeshes(force = false) {
|
|
@@ -3068,8 +2937,8 @@ var EntityObject = class extends SceneObject {
|
|
|
3068
2937
|
const l = cube.maxZ - cube.minZ;
|
|
3069
2938
|
const uv = texture.toUvArray(w, h, l);
|
|
3070
2939
|
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
3071
|
-
cubeGeo.applyMatrix4(new
|
|
3072
|
-
cubeGeo.applyMatrix4(new
|
|
2940
|
+
cubeGeo.applyMatrix4(new THREE2.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
2941
|
+
cubeGeo.applyMatrix4(new THREE2.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
3073
2942
|
applyModelPartRotation(part, cubeGeo);
|
|
3074
2943
|
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
3075
2944
|
partAnchor.add(mesh);
|
|
@@ -3082,26 +2951,23 @@ var EntityObject = class extends SceneObject {
|
|
|
3082
2951
|
this.meshesCreated = true;
|
|
3083
2952
|
}
|
|
3084
2953
|
async applyTextures() {
|
|
3085
|
-
const
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
mesh.material = mat;
|
|
3100
|
-
});
|
|
3101
|
-
this.notifyDirty();
|
|
2954
|
+
const textureAsset = await ModelTextures.preload(new AssetKey(
|
|
2955
|
+
this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
|
|
2956
|
+
this.entity.key.path,
|
|
2957
|
+
"textures",
|
|
2958
|
+
"entity",
|
|
2959
|
+
"assets",
|
|
2960
|
+
".png"
|
|
2961
|
+
));
|
|
2962
|
+
if (textureAsset) {
|
|
2963
|
+
let mat = Materials.getImage({ texture: { src: textureAsset.src } });
|
|
2964
|
+
this.iterateAllMeshes((mesh) => {
|
|
2965
|
+
mesh.material = mat;
|
|
2966
|
+
});
|
|
2967
|
+
}
|
|
3102
2968
|
}
|
|
3103
2969
|
};
|
|
3104
|
-
EntityObject.DEFAULT_OPTIONS = (0,
|
|
2970
|
+
EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
3105
2971
|
function isEntityObject(obj) {
|
|
3106
2972
|
return obj.isEntityObject;
|
|
3107
2973
|
}
|
|
@@ -3113,7 +2979,7 @@ var GuiObject = class extends SceneObject {
|
|
|
3113
2979
|
|
|
3114
2980
|
// src/inspector/SceneInspector.ts
|
|
3115
2981
|
import { Raycaster, Vector2 as Vector22 } from "three";
|
|
3116
|
-
var
|
|
2982
|
+
var p8 = prefix("SceneInspector");
|
|
3117
2983
|
var help = "<span>Ctrl+Click to Select<br/></span><br/>";
|
|
3118
2984
|
var SceneInspector = class {
|
|
3119
2985
|
constructor(renderer) {
|
|
@@ -3182,7 +3048,7 @@ var SceneInspector = class {
|
|
|
3182
3048
|
}
|
|
3183
3049
|
selectObject(targetObject, targetIntersection) {
|
|
3184
3050
|
this.selectedObject = targetObject;
|
|
3185
|
-
console.log(
|
|
3051
|
+
console.log(p8, "selected", targetObject);
|
|
3186
3052
|
this.redraw(targetObject, targetIntersection);
|
|
3187
3053
|
}
|
|
3188
3054
|
redraw(targetObject, targetIntersection) {
|
|
@@ -3480,7 +3346,7 @@ var SceneStatsDisplay = class {
|
|
|
3480
3346
|
};
|
|
3481
3347
|
|
|
3482
3348
|
// src/instance/InstanceManager.ts
|
|
3483
|
-
var
|
|
3349
|
+
var p9 = prefix("InstanceManager");
|
|
3484
3350
|
var InstanceManager = class {
|
|
3485
3351
|
constructor() {
|
|
3486
3352
|
this.isInstanceManager = true;
|
|
@@ -3488,7 +3354,7 @@ var InstanceManager = class {
|
|
|
3488
3354
|
}
|
|
3489
3355
|
async get(key) {
|
|
3490
3356
|
if (key in this.instanceCache) {
|
|
3491
|
-
console.debug(
|
|
3357
|
+
console.debug(p9, "key in cache", key);
|
|
3492
3358
|
return (await this.instanceCache[key]).nextInstance();
|
|
3493
3359
|
}
|
|
3494
3360
|
return void 0;
|
|
@@ -3497,17 +3363,13 @@ var InstanceManager = class {
|
|
|
3497
3363
|
if (key in this.instanceCache) {
|
|
3498
3364
|
return await this.get(key);
|
|
3499
3365
|
}
|
|
3500
|
-
console.debug(
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
}
|
|
3506
|
-
|
|
3507
|
-
delete this.instanceCache[key];
|
|
3508
|
-
}
|
|
3509
|
-
throw error;
|
|
3510
|
-
}
|
|
3366
|
+
console.debug(p9, "key not in cache", key);
|
|
3367
|
+
this.instanceCache[key] = new Promise(async (resolve) => {
|
|
3368
|
+
const obj = await supplier();
|
|
3369
|
+
const instance = obj.nextInstance();
|
|
3370
|
+
resolve(instance);
|
|
3371
|
+
});
|
|
3372
|
+
return await this.instanceCache[key];
|
|
3511
3373
|
}
|
|
3512
3374
|
reset() {
|
|
3513
3375
|
for (let instanceCacheKey in this.instanceCache) {
|
|
@@ -4106,15 +3968,15 @@ function computeMorphedAttributes(object) {
|
|
|
4106
3968
|
}
|
|
4107
3969
|
|
|
4108
3970
|
// src/model/scene/ModelObject.ts
|
|
4109
|
-
var
|
|
4110
|
-
var
|
|
3971
|
+
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
3972
|
+
var p10 = prefix("ModelObject");
|
|
4111
3973
|
var _ModelObject = class _ModelObject extends SceneObject {
|
|
4112
3974
|
constructor(originalModel, options) {
|
|
4113
3975
|
super(options);
|
|
4114
3976
|
this.originalModel = originalModel;
|
|
4115
3977
|
this.isModelObject = true;
|
|
4116
3978
|
this.meshesCreated = false;
|
|
4117
|
-
this.options = (0,
|
|
3979
|
+
this.options = (0, import_ts_deepmerge6.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
|
|
4118
3980
|
console.log("ModelObject options", this.options);
|
|
4119
3981
|
}
|
|
4120
3982
|
async init() {
|
|
@@ -4157,10 +4019,10 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4157
4019
|
}
|
|
4158
4020
|
});
|
|
4159
4021
|
} else {
|
|
4160
|
-
console.debug(
|
|
4022
|
+
console.debug(p10, this.atlas.model, "has no elements");
|
|
4161
4023
|
}
|
|
4162
4024
|
} else {
|
|
4163
|
-
console.debug(
|
|
4025
|
+
console.debug(p10, "Missing atlas for", this);
|
|
4164
4026
|
}
|
|
4165
4027
|
if (this.options.mergeMeshes) {
|
|
4166
4028
|
let combinedGeo;
|
|
@@ -4212,26 +4074,16 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4212
4074
|
}
|
|
4213
4075
|
}
|
|
4214
4076
|
};
|
|
4215
|
-
_ModelObject.DEFAULT_OPTIONS = (0,
|
|
4077
|
+
_ModelObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4216
4078
|
var ModelObject = _ModelObject;
|
|
4217
4079
|
function isModelObject(obj) {
|
|
4218
4080
|
return obj.isModelObject;
|
|
4219
4081
|
}
|
|
4220
4082
|
|
|
4221
4083
|
// src/model/block/scene/BlockObject.ts
|
|
4222
|
-
var
|
|
4084
|
+
var import_ts_deepmerge7 = __toESM(require_dist());
|
|
4223
4085
|
import { Euler as Euler3, Matrix4 as Matrix46, Vector3 as Vector36 } from "three";
|
|
4224
|
-
var
|
|
4225
|
-
function matchesCondition(condition, state) {
|
|
4226
|
-
return Object.entries(condition).every(([key, value]) => {
|
|
4227
|
-
if (Array.isArray(value)) {
|
|
4228
|
-
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4229
|
-
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4230
|
-
return false;
|
|
4231
|
-
}
|
|
4232
|
-
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4233
|
-
});
|
|
4234
|
-
}
|
|
4086
|
+
var p11 = prefix("BlockObject");
|
|
4235
4087
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
4236
4088
|
constructor(blockState, options) {
|
|
4237
4089
|
super(options);
|
|
@@ -4245,11 +4097,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4245
4097
|
this._instanceModel = [];
|
|
4246
4098
|
this._variants = [];
|
|
4247
4099
|
this._models = [];
|
|
4248
|
-
this.options = (0,
|
|
4100
|
+
this.options = (0, import_ts_deepmerge7.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
|
|
4249
4101
|
}
|
|
4250
4102
|
async init() {
|
|
4251
4103
|
if (this.options.applyDefaultState) {
|
|
4252
|
-
const defaultState = this.blockState.key ?
|
|
4104
|
+
const defaultState = this.blockState.key ? BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4253
4105
|
if (defaultState && Object.keys(defaultState).length > 0) {
|
|
4254
4106
|
const state = {};
|
|
4255
4107
|
for (let k in defaultState) {
|
|
@@ -4260,9 +4112,15 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4260
4112
|
if (this.blockState.variants) {
|
|
4261
4113
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4262
4114
|
} else if (this.blockState.multipart) {
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4115
|
+
for (let part of this.blockState.multipart) {
|
|
4116
|
+
if (part.when && !("OR" in part.when)) {
|
|
4117
|
+
const k = Object.keys(part.when)[0];
|
|
4118
|
+
if (k) {
|
|
4119
|
+
await this.setState(k, part.when[k].split("|")[0]);
|
|
4120
|
+
break;
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4266
4124
|
}
|
|
4267
4125
|
}
|
|
4268
4126
|
} else {
|
|
@@ -4319,11 +4177,55 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4319
4177
|
} else if (this.blockState.multipart) {
|
|
4320
4178
|
for (let part of this.blockState.multipart) {
|
|
4321
4179
|
if (!part.apply) {
|
|
4322
|
-
console.debug(
|
|
4180
|
+
console.debug(p11, "Missing apply for blockState part", part);
|
|
4323
4181
|
continue;
|
|
4324
4182
|
}
|
|
4325
|
-
if (!part.when
|
|
4183
|
+
if (!part.when) {
|
|
4326
4184
|
out.push(this.getSingleVariant(part.apply));
|
|
4185
|
+
} else {
|
|
4186
|
+
let matches = true;
|
|
4187
|
+
if ("OR" in part.when) {
|
|
4188
|
+
const or = part.when.OR;
|
|
4189
|
+
let anyMatch = false;
|
|
4190
|
+
for (let o of or) {
|
|
4191
|
+
for (let k in o) {
|
|
4192
|
+
const split = o[k].split("|");
|
|
4193
|
+
let m = false;
|
|
4194
|
+
for (let s of split) {
|
|
4195
|
+
if (`${state[k]}` === `${s}`) {
|
|
4196
|
+
m = true;
|
|
4197
|
+
break;
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
if (m) {
|
|
4201
|
+
anyMatch = true;
|
|
4202
|
+
break;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
}
|
|
4206
|
+
if (!anyMatch) {
|
|
4207
|
+
matches = false;
|
|
4208
|
+
}
|
|
4209
|
+
} else {
|
|
4210
|
+
for (let k in part.when) {
|
|
4211
|
+
const split = part.when[k].split("|");
|
|
4212
|
+
let m = false;
|
|
4213
|
+
for (let s of split) {
|
|
4214
|
+
if (`${state[k]}` === `${s}`) {
|
|
4215
|
+
m = true;
|
|
4216
|
+
break;
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
if (!m) {
|
|
4220
|
+
matches = false;
|
|
4221
|
+
break;
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
if (matches) {
|
|
4226
|
+
const variants = part.apply;
|
|
4227
|
+
out.push(this.getSingleVariant(variants));
|
|
4228
|
+
}
|
|
4327
4229
|
}
|
|
4328
4230
|
}
|
|
4329
4231
|
}
|
|
@@ -4353,21 +4255,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4353
4255
|
}
|
|
4354
4256
|
}
|
|
4355
4257
|
getSingleVariant(variants) {
|
|
4356
|
-
if (
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4362
|
-
}
|
|
4363
|
-
return sum + weight;
|
|
4364
|
-
}, 0);
|
|
4365
|
-
let choice = Math.random() * total;
|
|
4366
|
-
for (const variant of variants) {
|
|
4367
|
-
choice -= variant.weight ?? 1;
|
|
4368
|
-
if (choice < 0) return variant;
|
|
4369
|
-
}
|
|
4370
|
-
return variants[variants.length - 1];
|
|
4258
|
+
if (Array.isArray(variants)) {
|
|
4259
|
+
return variants[0];
|
|
4260
|
+
} else {
|
|
4261
|
+
return variants;
|
|
4262
|
+
}
|
|
4371
4263
|
}
|
|
4372
4264
|
// @deprecated
|
|
4373
4265
|
async createAVariant(variants, instanceInfo) {
|
|
@@ -4393,6 +4285,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4393
4285
|
}
|
|
4394
4286
|
}
|
|
4395
4287
|
obj.setRotation(rotation);
|
|
4288
|
+
setTimeout(() => {
|
|
4289
|
+
obj.setRotation(rotation);
|
|
4290
|
+
}, 150);
|
|
4396
4291
|
console.log(obj);
|
|
4397
4292
|
return obj;
|
|
4398
4293
|
}
|
|
@@ -4483,16 +4378,15 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4483
4378
|
}
|
|
4484
4379
|
}
|
|
4485
4380
|
setPosition(position) {
|
|
4486
|
-
|
|
4381
|
+
super.setPosition(position);
|
|
4487
4382
|
for (let model of this._models) {
|
|
4488
4383
|
model.setPosition(position);
|
|
4489
4384
|
}
|
|
4490
|
-
this.notifyDirty();
|
|
4491
4385
|
}
|
|
4492
4386
|
//TODO: should override rotation + scale methods
|
|
4493
4387
|
//TODO
|
|
4494
4388
|
};
|
|
4495
|
-
_BlockObject.DEFAULT_OPTIONS = (0,
|
|
4389
|
+
_BlockObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge7.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4496
4390
|
applyDefaultState: true
|
|
4497
4391
|
});
|
|
4498
4392
|
var BlockObject = _BlockObject;
|
|
@@ -4542,7 +4436,7 @@ var StructureParser = class {
|
|
|
4542
4436
|
|
|
4543
4437
|
// src/renderer/MineRenderScene.ts
|
|
4544
4438
|
import { Scene as Scene2 } from "three";
|
|
4545
|
-
var
|
|
4439
|
+
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
4546
4440
|
|
|
4547
4441
|
// src/skin/SkinPart.ts
|
|
4548
4442
|
var SkinPart = /* @__PURE__ */ ((SkinPart2) => {
|
|
@@ -5273,7 +5167,7 @@ var slimSkinGeometries = {
|
|
|
5273
5167
|
};
|
|
5274
5168
|
|
|
5275
5169
|
// src/skin/scene/SkinObject.ts
|
|
5276
|
-
var
|
|
5170
|
+
var import_ts_deepmerge8 = __toESM(require_dist());
|
|
5277
5171
|
var SkinObject = class extends SceneObject {
|
|
5278
5172
|
constructor(options) {
|
|
5279
5173
|
super();
|
|
@@ -5281,7 +5175,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5281
5175
|
this.legacy = false;
|
|
5282
5176
|
this.skinTextureWidth = 64;
|
|
5283
5177
|
this.skinTextureHeight = 64;
|
|
5284
|
-
this.options = (0,
|
|
5178
|
+
this.options = (0, import_ts_deepmerge8.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
5285
5179
|
}
|
|
5286
5180
|
async init() {
|
|
5287
5181
|
this.createMeshes();
|
|
@@ -5398,7 +5292,7 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5398
5292
|
this.dirty = true;
|
|
5399
5293
|
}
|
|
5400
5294
|
};
|
|
5401
|
-
this.options = (0,
|
|
5295
|
+
this.options = (0, import_ts_deepmerge9.default)({}, _MineRenderScene.DEFAULT_OPTIONS, options ?? {});
|
|
5402
5296
|
}
|
|
5403
5297
|
add(...objects) {
|
|
5404
5298
|
for (const object of objects) {
|
|
@@ -5494,1148 +5388,1114 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5494
5388
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
5495
5389
|
}
|
|
5496
5390
|
};
|
|
5497
|
-
_MineRenderScene.DEFAULT_OPTIONS = (0,
|
|
5391
|
+
_MineRenderScene.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {});
|
|
5498
5392
|
var MineRenderScene = _MineRenderScene;
|
|
5499
5393
|
function isMineRenderScene(obj) {
|
|
5500
5394
|
return obj.isMineRenderScene;
|
|
5501
5395
|
}
|
|
5502
5396
|
|
|
5503
5397
|
// src/renderer/Renderer.ts
|
|
5504
|
-
import { AxesHelper as AxesHelper3, GridHelper, OrthographicCamera, PCFSoftShadowMap, PerspectiveCamera,
|
|
5505
|
-
var
|
|
5398
|
+
import { AxesHelper as AxesHelper3, GridHelper, LinearEncoding, OrthographicCamera, PCFSoftShadowMap, PerspectiveCamera, Vector3 as Vector37, WebGLRenderer } from "three";
|
|
5399
|
+
var import_ts_deepmerge10 = __toESM(require_dist());
|
|
5506
5400
|
import Stats from "stats.js";
|
|
5507
5401
|
import { EffectComposer, RenderPass } from "postprocessing";
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
var _changeEvent = { type: "change" };
|
|
5520
|
-
var _startEvent = { type: "start" };
|
|
5521
|
-
var _endEvent = { type: "end" };
|
|
5522
|
-
var OrbitControls = class extends EventDispatcher {
|
|
5523
|
-
constructor(object, domElement) {
|
|
5524
|
-
super();
|
|
5525
|
-
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
5526
|
-
if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
|
5527
|
-
this.object = object;
|
|
5528
|
-
this.domElement = domElement;
|
|
5529
|
-
this.domElement.style.touchAction = "none";
|
|
5530
|
-
this.enabled = true;
|
|
5531
|
-
this.target = new Vector37();
|
|
5532
|
-
this.minDistance = 0;
|
|
5533
|
-
this.maxDistance = Infinity;
|
|
5534
|
-
this.minZoom = 0;
|
|
5535
|
-
this.maxZoom = Infinity;
|
|
5536
|
-
this.minPolarAngle = 0;
|
|
5537
|
-
this.maxPolarAngle = Math.PI;
|
|
5538
|
-
this.minAzimuthAngle = -Infinity;
|
|
5539
|
-
this.maxAzimuthAngle = Infinity;
|
|
5540
|
-
this.enableDamping = false;
|
|
5541
|
-
this.dampingFactor = 0.05;
|
|
5542
|
-
this.enableZoom = true;
|
|
5543
|
-
this.zoomSpeed = 1;
|
|
5544
|
-
this.enableRotate = true;
|
|
5545
|
-
this.rotateSpeed = 1;
|
|
5546
|
-
this.enablePan = true;
|
|
5547
|
-
this.panSpeed = 1;
|
|
5548
|
-
this.screenSpacePanning = true;
|
|
5549
|
-
this.keyPanSpeed = 7;
|
|
5550
|
-
this.autoRotate = false;
|
|
5551
|
-
this.autoRotateSpeed = 2;
|
|
5552
|
-
this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
|
|
5553
|
-
this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
|
|
5554
|
-
this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
|
|
5555
|
-
this.target0 = this.target.clone();
|
|
5556
|
-
this.position0 = this.object.position.clone();
|
|
5557
|
-
this.zoom0 = this.object.zoom;
|
|
5558
|
-
this._domElementKeyEvents = null;
|
|
5559
|
-
this.getPolarAngle = function() {
|
|
5560
|
-
return spherical.phi;
|
|
5561
|
-
};
|
|
5562
|
-
this.getAzimuthalAngle = function() {
|
|
5563
|
-
return spherical.theta;
|
|
5564
|
-
};
|
|
5565
|
-
this.getDistance = function() {
|
|
5566
|
-
return this.object.position.distanceTo(this.target);
|
|
5567
|
-
};
|
|
5568
|
-
this.saveState = function() {
|
|
5569
|
-
scope.target0.copy(scope.target);
|
|
5570
|
-
scope.position0.copy(scope.object.position);
|
|
5571
|
-
scope.zoom0 = scope.object.zoom;
|
|
5572
|
-
};
|
|
5573
|
-
this.reset = function() {
|
|
5574
|
-
scope.target.copy(scope.target0);
|
|
5575
|
-
scope.object.position.copy(scope.position0);
|
|
5576
|
-
scope.object.zoom = scope.zoom0;
|
|
5577
|
-
scope.object.updateProjectionMatrix();
|
|
5578
|
-
scope.dispatchEvent(_changeEvent);
|
|
5579
|
-
scope.update();
|
|
5580
|
-
state = STATE.NONE;
|
|
5581
|
-
};
|
|
5582
|
-
this.update = function() {
|
|
5583
|
-
const offset = new Vector37();
|
|
5584
|
-
const quat = new Quaternion3().setFromUnitVectors(object.up, new Vector37(0, 1, 0));
|
|
5585
|
-
const quatInverse = quat.clone().invert();
|
|
5586
|
-
const lastPosition = new Vector37();
|
|
5587
|
-
const lastQuaternion = new Quaternion3();
|
|
5588
|
-
const twoPI = 2 * Math.PI;
|
|
5589
|
-
return function update() {
|
|
5590
|
-
const position = scope.object.position;
|
|
5591
|
-
offset.copy(position).sub(scope.target);
|
|
5592
|
-
offset.applyQuaternion(quat);
|
|
5593
|
-
spherical.setFromVector3(offset);
|
|
5594
|
-
if (scope.autoRotate && state === STATE.NONE) {
|
|
5595
|
-
rotateLeft(getAutoRotationAngle());
|
|
5596
|
-
}
|
|
5597
|
-
if (scope.enableDamping) {
|
|
5598
|
-
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
5599
|
-
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
5600
|
-
} else {
|
|
5601
|
-
spherical.theta += sphericalDelta.theta;
|
|
5602
|
-
spherical.phi += sphericalDelta.phi;
|
|
5603
|
-
}
|
|
5604
|
-
let min = scope.minAzimuthAngle;
|
|
5605
|
-
let max = scope.maxAzimuthAngle;
|
|
5606
|
-
if (isFinite(min) && isFinite(max)) {
|
|
5607
|
-
if (min < -Math.PI) min += twoPI;
|
|
5608
|
-
else if (min > Math.PI) min -= twoPI;
|
|
5609
|
-
if (max < -Math.PI) max += twoPI;
|
|
5610
|
-
else if (max > Math.PI) max -= twoPI;
|
|
5611
|
-
if (min <= max) {
|
|
5612
|
-
spherical.theta = Math.max(min, Math.min(max, spherical.theta));
|
|
5613
|
-
} else {
|
|
5614
|
-
spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
|
|
5615
|
-
}
|
|
5616
|
-
}
|
|
5617
|
-
spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
|
|
5618
|
-
spherical.makeSafe();
|
|
5619
|
-
spherical.radius *= scale;
|
|
5620
|
-
spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
|
|
5621
|
-
if (scope.enableDamping === true) {
|
|
5622
|
-
scope.target.addScaledVector(panOffset, scope.dampingFactor);
|
|
5623
|
-
} else {
|
|
5624
|
-
scope.target.add(panOffset);
|
|
5625
|
-
}
|
|
5626
|
-
offset.setFromSpherical(spherical);
|
|
5627
|
-
offset.applyQuaternion(quatInverse);
|
|
5628
|
-
position.copy(scope.target).add(offset);
|
|
5629
|
-
scope.object.lookAt(scope.target);
|
|
5630
|
-
if (scope.enableDamping === true) {
|
|
5631
|
-
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
5632
|
-
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
5633
|
-
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
5634
|
-
} else {
|
|
5635
|
-
sphericalDelta.set(0, 0, 0);
|
|
5636
|
-
panOffset.set(0, 0, 0);
|
|
5637
|
-
}
|
|
5638
|
-
scale = 1;
|
|
5639
|
-
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
5640
|
-
scope.dispatchEvent(_changeEvent);
|
|
5641
|
-
lastPosition.copy(scope.object.position);
|
|
5642
|
-
lastQuaternion.copy(scope.object.quaternion);
|
|
5643
|
-
zoomChanged = false;
|
|
5644
|
-
return true;
|
|
5645
|
-
}
|
|
5646
|
-
return false;
|
|
5647
|
-
};
|
|
5648
|
-
}();
|
|
5649
|
-
this.dispose = function() {
|
|
5650
|
-
scope.domElement.removeEventListener("contextmenu", onContextMenu);
|
|
5651
|
-
scope.domElement.removeEventListener("pointerdown", onPointerDown);
|
|
5652
|
-
scope.domElement.removeEventListener("pointercancel", onPointerCancel);
|
|
5653
|
-
scope.domElement.removeEventListener("wheel", onMouseWheel);
|
|
5654
|
-
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
5655
|
-
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
5656
|
-
if (scope._domElementKeyEvents !== null) {
|
|
5657
|
-
scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
5658
|
-
}
|
|
5659
|
-
};
|
|
5660
|
-
const scope = this;
|
|
5661
|
-
const STATE = {
|
|
5662
|
-
NONE: -1,
|
|
5663
|
-
ROTATE: 0,
|
|
5664
|
-
DOLLY: 1,
|
|
5665
|
-
PAN: 2,
|
|
5666
|
-
TOUCH_ROTATE: 3,
|
|
5667
|
-
TOUCH_PAN: 4,
|
|
5668
|
-
TOUCH_DOLLY_PAN: 5,
|
|
5669
|
-
TOUCH_DOLLY_ROTATE: 6
|
|
5402
|
+
var _Renderer = class _Renderer {
|
|
5403
|
+
constructor(options) {
|
|
5404
|
+
this._dirty = true;
|
|
5405
|
+
this._animationTimer = void 0;
|
|
5406
|
+
this._animationFrame = void 0;
|
|
5407
|
+
this._resizeListener = void 0;
|
|
5408
|
+
this._disposed = false;
|
|
5409
|
+
this._debugHelpers = [];
|
|
5410
|
+
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
5411
|
+
this._changeListener = () => {
|
|
5412
|
+
this._dirty = true;
|
|
5670
5413
|
};
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
const panStart = new Vector23();
|
|
5682
|
-
const panEnd = new Vector23();
|
|
5683
|
-
const panDelta = new Vector23();
|
|
5684
|
-
const dollyStart = new Vector23();
|
|
5685
|
-
const dollyEnd = new Vector23();
|
|
5686
|
-
const dollyDelta = new Vector23();
|
|
5687
|
-
const pointers = [];
|
|
5688
|
-
const pointerPositions = {};
|
|
5689
|
-
function getAutoRotationAngle() {
|
|
5690
|
-
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
5691
|
-
}
|
|
5692
|
-
function getZoomScale() {
|
|
5693
|
-
return Math.pow(0.95, scope.zoomSpeed);
|
|
5694
|
-
}
|
|
5695
|
-
function rotateLeft(angle) {
|
|
5696
|
-
sphericalDelta.theta -= angle;
|
|
5697
|
-
}
|
|
5698
|
-
function rotateUp(angle) {
|
|
5699
|
-
sphericalDelta.phi -= angle;
|
|
5700
|
-
}
|
|
5701
|
-
const panLeft = function() {
|
|
5702
|
-
const v = new Vector37();
|
|
5703
|
-
return function panLeft2(distance, objectMatrix) {
|
|
5704
|
-
v.setFromMatrixColumn(objectMatrix, 0);
|
|
5705
|
-
v.multiplyScalar(-distance);
|
|
5706
|
-
panOffset.add(v);
|
|
5707
|
-
};
|
|
5708
|
-
}();
|
|
5709
|
-
const panUp = function() {
|
|
5710
|
-
const v = new Vector37();
|
|
5711
|
-
return function panUp2(distance, objectMatrix) {
|
|
5712
|
-
if (scope.screenSpacePanning === true) {
|
|
5713
|
-
v.setFromMatrixColumn(objectMatrix, 1);
|
|
5714
|
-
} else {
|
|
5715
|
-
v.setFromMatrixColumn(objectMatrix, 0);
|
|
5716
|
-
v.crossVectors(scope.object.up, v);
|
|
5717
|
-
}
|
|
5718
|
-
v.multiplyScalar(distance);
|
|
5719
|
-
panOffset.add(v);
|
|
5720
|
-
};
|
|
5721
|
-
}();
|
|
5722
|
-
const pan = function() {
|
|
5723
|
-
const offset = new Vector37();
|
|
5724
|
-
return function pan2(deltaX, deltaY) {
|
|
5725
|
-
const element = scope.domElement;
|
|
5726
|
-
if (scope.object.isPerspectiveCamera) {
|
|
5727
|
-
const position = scope.object.position;
|
|
5728
|
-
offset.copy(position).sub(scope.target);
|
|
5729
|
-
let targetDistance = offset.length();
|
|
5730
|
-
targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
|
|
5731
|
-
panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
|
|
5732
|
-
panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
|
|
5733
|
-
} else if (scope.object.isOrthographicCamera) {
|
|
5734
|
-
panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
|
|
5735
|
-
panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
|
|
5736
|
-
} else {
|
|
5737
|
-
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
|
|
5738
|
-
scope.enablePan = false;
|
|
5739
|
-
}
|
|
5740
|
-
};
|
|
5741
|
-
}();
|
|
5742
|
-
function dollyOut(dollyScale) {
|
|
5743
|
-
if (scope.object.isPerspectiveCamera) {
|
|
5744
|
-
scale /= dollyScale;
|
|
5745
|
-
} else if (scope.object.isOrthographicCamera) {
|
|
5746
|
-
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
|
|
5747
|
-
scope.object.updateProjectionMatrix();
|
|
5748
|
-
zoomChanged = true;
|
|
5749
|
-
} else {
|
|
5750
|
-
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
5751
|
-
scope.enableZoom = false;
|
|
5752
|
-
}
|
|
5753
|
-
}
|
|
5754
|
-
function dollyIn(dollyScale) {
|
|
5755
|
-
if (scope.object.isPerspectiveCamera) {
|
|
5756
|
-
scale *= dollyScale;
|
|
5757
|
-
} else if (scope.object.isOrthographicCamera) {
|
|
5758
|
-
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
|
|
5759
|
-
scope.object.updateProjectionMatrix();
|
|
5760
|
-
zoomChanged = true;
|
|
5761
|
-
} else {
|
|
5762
|
-
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
5763
|
-
scope.enableZoom = false;
|
|
5764
|
-
}
|
|
5765
|
-
}
|
|
5766
|
-
function handleMouseDownRotate(event) {
|
|
5767
|
-
rotateStart.set(event.clientX, event.clientY);
|
|
5768
|
-
}
|
|
5769
|
-
function handleMouseDownDolly(event) {
|
|
5770
|
-
dollyStart.set(event.clientX, event.clientY);
|
|
5771
|
-
}
|
|
5772
|
-
function handleMouseDownPan(event) {
|
|
5773
|
-
panStart.set(event.clientX, event.clientY);
|
|
5774
|
-
}
|
|
5775
|
-
function handleMouseMoveRotate(event) {
|
|
5776
|
-
rotateEnd.set(event.clientX, event.clientY);
|
|
5777
|
-
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
5778
|
-
const element = scope.domElement;
|
|
5779
|
-
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
5780
|
-
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
5781
|
-
rotateStart.copy(rotateEnd);
|
|
5782
|
-
scope.update();
|
|
5783
|
-
}
|
|
5784
|
-
function handleMouseMoveDolly(event) {
|
|
5785
|
-
dollyEnd.set(event.clientX, event.clientY);
|
|
5786
|
-
dollyDelta.subVectors(dollyEnd, dollyStart);
|
|
5787
|
-
if (dollyDelta.y > 0) {
|
|
5788
|
-
dollyOut(getZoomScale());
|
|
5789
|
-
} else if (dollyDelta.y < 0) {
|
|
5790
|
-
dollyIn(getZoomScale());
|
|
5791
|
-
}
|
|
5792
|
-
dollyStart.copy(dollyEnd);
|
|
5793
|
-
scope.update();
|
|
5794
|
-
}
|
|
5795
|
-
function handleMouseMovePan(event) {
|
|
5796
|
-
panEnd.set(event.clientX, event.clientY);
|
|
5797
|
-
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
5798
|
-
pan(panDelta.x, panDelta.y);
|
|
5799
|
-
panStart.copy(panEnd);
|
|
5800
|
-
scope.update();
|
|
5801
|
-
}
|
|
5802
|
-
function handleMouseUp() {
|
|
5803
|
-
}
|
|
5804
|
-
function handleMouseWheel(event) {
|
|
5805
|
-
if (event.deltaY < 0) {
|
|
5806
|
-
dollyIn(getZoomScale());
|
|
5807
|
-
} else if (event.deltaY > 0) {
|
|
5808
|
-
dollyOut(getZoomScale());
|
|
5809
|
-
}
|
|
5810
|
-
scope.update();
|
|
5811
|
-
}
|
|
5812
|
-
function handleKeyDown(event) {
|
|
5813
|
-
let needsUpdate = false;
|
|
5814
|
-
switch (event.code) {
|
|
5815
|
-
case scope.keys.UP:
|
|
5816
|
-
pan(0, scope.keyPanSpeed);
|
|
5817
|
-
needsUpdate = true;
|
|
5818
|
-
break;
|
|
5819
|
-
case scope.keys.BOTTOM:
|
|
5820
|
-
pan(0, -scope.keyPanSpeed);
|
|
5821
|
-
needsUpdate = true;
|
|
5822
|
-
break;
|
|
5823
|
-
case scope.keys.LEFT:
|
|
5824
|
-
pan(scope.keyPanSpeed, 0);
|
|
5825
|
-
needsUpdate = true;
|
|
5826
|
-
break;
|
|
5827
|
-
case scope.keys.RIGHT:
|
|
5828
|
-
pan(-scope.keyPanSpeed, 0);
|
|
5829
|
-
needsUpdate = true;
|
|
5830
|
-
break;
|
|
5831
|
-
}
|
|
5832
|
-
if (needsUpdate) {
|
|
5833
|
-
event.preventDefault();
|
|
5834
|
-
scope.update();
|
|
5835
|
-
}
|
|
5836
|
-
}
|
|
5837
|
-
function handleTouchStartRotate() {
|
|
5838
|
-
if (pointers.length === 1) {
|
|
5839
|
-
rotateStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
5840
|
-
} else {
|
|
5841
|
-
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
5842
|
-
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
5843
|
-
rotateStart.set(x, y);
|
|
5844
|
-
}
|
|
5845
|
-
}
|
|
5846
|
-
function handleTouchStartPan() {
|
|
5847
|
-
if (pointers.length === 1) {
|
|
5848
|
-
panStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
5849
|
-
} else {
|
|
5850
|
-
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
5851
|
-
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
5852
|
-
panStart.set(x, y);
|
|
5853
|
-
}
|
|
5854
|
-
}
|
|
5855
|
-
function handleTouchStartDolly() {
|
|
5856
|
-
const dx = pointers[0].pageX - pointers[1].pageX;
|
|
5857
|
-
const dy = pointers[0].pageY - pointers[1].pageY;
|
|
5858
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
5859
|
-
dollyStart.set(0, distance);
|
|
5860
|
-
}
|
|
5861
|
-
function handleTouchStartDollyPan() {
|
|
5862
|
-
if (scope.enableZoom) handleTouchStartDolly();
|
|
5863
|
-
if (scope.enablePan) handleTouchStartPan();
|
|
5864
|
-
}
|
|
5865
|
-
function handleTouchStartDollyRotate() {
|
|
5866
|
-
if (scope.enableZoom) handleTouchStartDolly();
|
|
5867
|
-
if (scope.enableRotate) handleTouchStartRotate();
|
|
5868
|
-
}
|
|
5869
|
-
function handleTouchMoveRotate(event) {
|
|
5870
|
-
if (pointers.length == 1) {
|
|
5871
|
-
rotateEnd.set(event.pageX, event.pageY);
|
|
5872
|
-
} else {
|
|
5873
|
-
const position = getSecondPointerPosition(event);
|
|
5874
|
-
const x = 0.5 * (event.pageX + position.x);
|
|
5875
|
-
const y = 0.5 * (event.pageY + position.y);
|
|
5876
|
-
rotateEnd.set(x, y);
|
|
5877
|
-
}
|
|
5878
|
-
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
5879
|
-
const element = scope.domElement;
|
|
5880
|
-
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
5881
|
-
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
5882
|
-
rotateStart.copy(rotateEnd);
|
|
5883
|
-
}
|
|
5884
|
-
function handleTouchMovePan(event) {
|
|
5885
|
-
if (pointers.length === 1) {
|
|
5886
|
-
panEnd.set(event.pageX, event.pageY);
|
|
5887
|
-
} else {
|
|
5888
|
-
const position = getSecondPointerPosition(event);
|
|
5889
|
-
const x = 0.5 * (event.pageX + position.x);
|
|
5890
|
-
const y = 0.5 * (event.pageY + position.y);
|
|
5891
|
-
panEnd.set(x, y);
|
|
5892
|
-
}
|
|
5893
|
-
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
5894
|
-
pan(panDelta.x, panDelta.y);
|
|
5895
|
-
panStart.copy(panEnd);
|
|
5896
|
-
}
|
|
5897
|
-
function handleTouchMoveDolly(event) {
|
|
5898
|
-
const position = getSecondPointerPosition(event);
|
|
5899
|
-
const dx = event.pageX - position.x;
|
|
5900
|
-
const dy = event.pageY - position.y;
|
|
5901
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
5902
|
-
dollyEnd.set(0, distance);
|
|
5903
|
-
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
5904
|
-
dollyOut(dollyDelta.y);
|
|
5905
|
-
dollyStart.copy(dollyEnd);
|
|
5906
|
-
}
|
|
5907
|
-
function handleTouchMoveDollyPan(event) {
|
|
5908
|
-
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
5909
|
-
if (scope.enablePan) handleTouchMovePan(event);
|
|
5910
|
-
}
|
|
5911
|
-
function handleTouchMoveDollyRotate(event) {
|
|
5912
|
-
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
5913
|
-
if (scope.enableRotate) handleTouchMoveRotate(event);
|
|
5914
|
-
}
|
|
5915
|
-
function handleTouchEnd() {
|
|
5414
|
+
this.options = (0, import_ts_deepmerge10.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
5415
|
+
this._animationLoop = this.animate.bind(this);
|
|
5416
|
+
this._fpsTimer = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
5417
|
+
this._scene = this.createScene();
|
|
5418
|
+
this._camera = this.createCamera();
|
|
5419
|
+
this._renderer = this.createRenderer();
|
|
5420
|
+
this._composer = this.createComposer();
|
|
5421
|
+
if (this.options.render.stats) {
|
|
5422
|
+
this._stats = new Stats();
|
|
5423
|
+
document.body.appendChild(this._stats.dom);
|
|
5916
5424
|
}
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5425
|
+
this.init();
|
|
5426
|
+
}
|
|
5427
|
+
//<editor-fold desc="INIT">
|
|
5428
|
+
createScene() {
|
|
5429
|
+
return new MineRenderScene();
|
|
5430
|
+
}
|
|
5431
|
+
createCamera() {
|
|
5432
|
+
switch (this.options.camera.type) {
|
|
5433
|
+
case "perspective":
|
|
5434
|
+
default:
|
|
5435
|
+
return new PerspectiveCamera(
|
|
5436
|
+
this.options.camera.perspective.fov,
|
|
5437
|
+
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
5438
|
+
this.options.camera.near,
|
|
5439
|
+
this.options.camera.far
|
|
5440
|
+
);
|
|
5441
|
+
case "orthographic":
|
|
5442
|
+
return new OrthographicCamera(
|
|
5443
|
+
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
5444
|
+
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
5445
|
+
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
5446
|
+
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
5447
|
+
this.options.camera.near,
|
|
5448
|
+
this.options.camera.far
|
|
5449
|
+
);
|
|
5930
5450
|
}
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5451
|
+
}
|
|
5452
|
+
createRenderer() {
|
|
5453
|
+
const renderer = new WebGLRenderer({
|
|
5454
|
+
antialias: this.options.render.antialias,
|
|
5455
|
+
alpha: true,
|
|
5456
|
+
powerPreference: "high-performance",
|
|
5457
|
+
depth: true
|
|
5458
|
+
});
|
|
5459
|
+
renderer.setClearColor(0, 0);
|
|
5460
|
+
renderer.shadowMap.enabled = true;
|
|
5461
|
+
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
5462
|
+
renderer.outputEncoding = LinearEncoding;
|
|
5463
|
+
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
5464
|
+
return renderer;
|
|
5465
|
+
}
|
|
5466
|
+
createComposer() {
|
|
5467
|
+
const composer = new EffectComposer(this.renderer);
|
|
5468
|
+
if (!this.options.composer.enabled) return composer;
|
|
5469
|
+
composer.setSize(this.viewWidth, this.viewHeight);
|
|
5470
|
+
composer.addPass(new RenderPass(this.scene, this.camera));
|
|
5471
|
+
return composer;
|
|
5472
|
+
}
|
|
5473
|
+
//</editor-fold>
|
|
5474
|
+
init() {
|
|
5475
|
+
if (this._disposed) return;
|
|
5476
|
+
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
5477
|
+
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
5938
5478
|
}
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
}
|
|
5479
|
+
if (this.options.debug.grid) {
|
|
5480
|
+
const gridHelper = new GridHelper(128, 16);
|
|
5481
|
+
this._debugHelpers.push(gridHelper);
|
|
5482
|
+
this.scene.add(gridHelper);
|
|
5483
|
+
const gridHelper2 = new GridHelper(128, 16);
|
|
5484
|
+
this._debugHelpers.push(gridHelper2);
|
|
5485
|
+
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
5486
|
+
this.scene.add(gridHelper2);
|
|
5487
|
+
const gridHelper3 = new GridHelper(128, 16);
|
|
5488
|
+
this._debugHelpers.push(gridHelper3);
|
|
5489
|
+
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
5490
|
+
this.scene.add(gridHelper3);
|
|
5952
5491
|
}
|
|
5953
|
-
|
|
5954
|
-
|
|
5492
|
+
if (this.options.debug.axes) {
|
|
5493
|
+
const axesHelper = new AxesHelper3(64);
|
|
5494
|
+
this._debugHelpers.push(axesHelper);
|
|
5495
|
+
this.scene.add(axesHelper);
|
|
5955
5496
|
}
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
break;
|
|
5962
|
-
case 1:
|
|
5963
|
-
mouseAction = scope.mouseButtons.MIDDLE;
|
|
5964
|
-
break;
|
|
5965
|
-
case 2:
|
|
5966
|
-
mouseAction = scope.mouseButtons.RIGHT;
|
|
5967
|
-
break;
|
|
5968
|
-
default:
|
|
5969
|
-
mouseAction = -1;
|
|
5970
|
-
}
|
|
5971
|
-
switch (mouseAction) {
|
|
5972
|
-
case MOUSE.DOLLY:
|
|
5973
|
-
if (scope.enableZoom === false) return;
|
|
5974
|
-
handleMouseDownDolly(event);
|
|
5975
|
-
state = STATE.DOLLY;
|
|
5976
|
-
break;
|
|
5977
|
-
case MOUSE.ROTATE:
|
|
5978
|
-
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
5979
|
-
if (scope.enablePan === false) return;
|
|
5980
|
-
handleMouseDownPan(event);
|
|
5981
|
-
state = STATE.PAN;
|
|
5982
|
-
} else {
|
|
5983
|
-
if (scope.enableRotate === false) return;
|
|
5984
|
-
handleMouseDownRotate(event);
|
|
5985
|
-
state = STATE.ROTATE;
|
|
5986
|
-
}
|
|
5987
|
-
break;
|
|
5988
|
-
case MOUSE.PAN:
|
|
5989
|
-
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
5990
|
-
if (scope.enableRotate === false) return;
|
|
5991
|
-
handleMouseDownRotate(event);
|
|
5992
|
-
state = STATE.ROTATE;
|
|
5993
|
-
} else {
|
|
5994
|
-
if (scope.enablePan === false) return;
|
|
5995
|
-
handleMouseDownPan(event);
|
|
5996
|
-
state = STATE.PAN;
|
|
5997
|
-
}
|
|
5998
|
-
break;
|
|
5999
|
-
default:
|
|
6000
|
-
state = STATE.NONE;
|
|
6001
|
-
}
|
|
6002
|
-
if (state !== STATE.NONE) {
|
|
6003
|
-
scope.dispatchEvent(_startEvent);
|
|
5497
|
+
if (this.options.camera.position) {
|
|
5498
|
+
if (isVector3(this.options.camera.position)) {
|
|
5499
|
+
this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
|
|
5500
|
+
} else if (isTripleArray(this.options.camera.position)) {
|
|
5501
|
+
this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
|
|
6004
5502
|
}
|
|
6005
5503
|
}
|
|
6006
|
-
|
|
6007
|
-
if (
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
handleMouseMoveRotate(event);
|
|
6012
|
-
break;
|
|
6013
|
-
case STATE.DOLLY:
|
|
6014
|
-
if (scope.enableZoom === false) return;
|
|
6015
|
-
handleMouseMoveDolly(event);
|
|
6016
|
-
break;
|
|
6017
|
-
case STATE.PAN:
|
|
6018
|
-
if (scope.enablePan === false) return;
|
|
6019
|
-
handleMouseMovePan(event);
|
|
6020
|
-
break;
|
|
5504
|
+
if (this.options.camera.lookingAt) {
|
|
5505
|
+
if (isVector3(this.options.camera.lookingAt)) {
|
|
5506
|
+
this.camera.lookAt(this.options.camera.lookingAt);
|
|
5507
|
+
} else if (isTripleArray(this.options.camera.lookingAt)) {
|
|
5508
|
+
this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
|
|
6021
5509
|
}
|
|
6022
5510
|
}
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
function onMouseWheel(event) {
|
|
6029
|
-
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
|
|
6030
|
-
event.preventDefault();
|
|
6031
|
-
scope.dispatchEvent(_startEvent);
|
|
6032
|
-
handleMouseWheel(event);
|
|
6033
|
-
scope.dispatchEvent(_endEvent);
|
|
5511
|
+
if (this.options.render.autoResize && !this._resizeListener) {
|
|
5512
|
+
this._resizeListener = () => {
|
|
5513
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
5514
|
+
};
|
|
5515
|
+
window.addEventListener("resize", this._resizeListener);
|
|
6034
5516
|
}
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
5517
|
+
}
|
|
5518
|
+
get element() {
|
|
5519
|
+
return this._element;
|
|
5520
|
+
}
|
|
5521
|
+
appendTo(element) {
|
|
5522
|
+
if (this._disposed) return;
|
|
5523
|
+
this._element = element;
|
|
5524
|
+
this._element.appendChild(this.renderer.domElement);
|
|
5525
|
+
if (this.viewWidth == 0) {
|
|
5526
|
+
console.warn("0 element width");
|
|
6038
5527
|
}
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
switch (pointers.length) {
|
|
6042
|
-
case 1:
|
|
6043
|
-
switch (scope.touches.ONE) {
|
|
6044
|
-
case TOUCH.ROTATE:
|
|
6045
|
-
if (scope.enableRotate === false) return;
|
|
6046
|
-
handleTouchStartRotate();
|
|
6047
|
-
state = STATE.TOUCH_ROTATE;
|
|
6048
|
-
break;
|
|
6049
|
-
case TOUCH.PAN:
|
|
6050
|
-
if (scope.enablePan === false) return;
|
|
6051
|
-
handleTouchStartPan();
|
|
6052
|
-
state = STATE.TOUCH_PAN;
|
|
6053
|
-
break;
|
|
6054
|
-
default:
|
|
6055
|
-
state = STATE.NONE;
|
|
6056
|
-
}
|
|
6057
|
-
break;
|
|
6058
|
-
case 2:
|
|
6059
|
-
switch (scope.touches.TWO) {
|
|
6060
|
-
case TOUCH.DOLLY_PAN:
|
|
6061
|
-
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6062
|
-
handleTouchStartDollyPan();
|
|
6063
|
-
state = STATE.TOUCH_DOLLY_PAN;
|
|
6064
|
-
break;
|
|
6065
|
-
case TOUCH.DOLLY_ROTATE:
|
|
6066
|
-
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6067
|
-
handleTouchStartDollyRotate();
|
|
6068
|
-
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
6069
|
-
break;
|
|
6070
|
-
default:
|
|
6071
|
-
state = STATE.NONE;
|
|
6072
|
-
}
|
|
6073
|
-
break;
|
|
6074
|
-
default:
|
|
6075
|
-
state = STATE.NONE;
|
|
6076
|
-
}
|
|
6077
|
-
if (state !== STATE.NONE) {
|
|
6078
|
-
scope.dispatchEvent(_startEvent);
|
|
6079
|
-
}
|
|
5528
|
+
if (this.viewHeight == 0) {
|
|
5529
|
+
console.warn("0 element height");
|
|
6080
5530
|
}
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
break;
|
|
6094
|
-
case STATE.TOUCH_DOLLY_PAN:
|
|
6095
|
-
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6096
|
-
handleTouchMoveDollyPan(event);
|
|
6097
|
-
scope.update();
|
|
6098
|
-
break;
|
|
6099
|
-
case STATE.TOUCH_DOLLY_ROTATE:
|
|
6100
|
-
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6101
|
-
handleTouchMoveDollyRotate(event);
|
|
6102
|
-
scope.update();
|
|
6103
|
-
break;
|
|
6104
|
-
default:
|
|
6105
|
-
state = STATE.NONE;
|
|
6106
|
-
}
|
|
5531
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
5532
|
+
}
|
|
5533
|
+
/**
|
|
5534
|
+
* Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
|
|
5535
|
+
* The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
|
|
5536
|
+
*/
|
|
5537
|
+
registerEventDispatcher(dispatcher, changeEvent2 = "change") {
|
|
5538
|
+
if (this._disposed) return;
|
|
5539
|
+
let events = this._eventDispatchers.get(dispatcher);
|
|
5540
|
+
if (!events) {
|
|
5541
|
+
events = /* @__PURE__ */ new Set();
|
|
5542
|
+
this._eventDispatchers.set(dispatcher, events);
|
|
6107
5543
|
}
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
5544
|
+
if (events.has(changeEvent2)) return;
|
|
5545
|
+
events.add(changeEvent2);
|
|
5546
|
+
dispatcher.addEventListener(changeEvent2, this._changeListener);
|
|
5547
|
+
}
|
|
5548
|
+
resize(width, height) {
|
|
5549
|
+
if (this._disposed) return;
|
|
5550
|
+
if (isPerspectiveCamera(this.camera)) {
|
|
5551
|
+
this.camera.aspect = width / height;
|
|
5552
|
+
this.camera.updateProjectionMatrix();
|
|
5553
|
+
} else if (isOrthographicCamera(this.camera)) {
|
|
5554
|
+
this.camera.left = width / -2;
|
|
5555
|
+
this.camera.right = width / 2;
|
|
5556
|
+
this.camera.top = height / 2;
|
|
5557
|
+
this.camera.bottom = height / -2;
|
|
5558
|
+
this.camera.updateProjectionMatrix();
|
|
6112
5559
|
}
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
5560
|
+
this.renderer.setSize(width, height);
|
|
5561
|
+
this.composer.setSize(width, height);
|
|
5562
|
+
this._dirty = true;
|
|
5563
|
+
}
|
|
5564
|
+
//<editor-fold desc="RENDER">
|
|
5565
|
+
get dirty() {
|
|
5566
|
+
return this._dirty || this.scene.dirty;
|
|
5567
|
+
}
|
|
5568
|
+
set dirty(dirty) {
|
|
5569
|
+
this._dirty = dirty;
|
|
5570
|
+
this.scene.dirty = dirty;
|
|
5571
|
+
}
|
|
5572
|
+
start() {
|
|
5573
|
+
if (this._disposed) return;
|
|
5574
|
+
this.stop();
|
|
5575
|
+
this.renderer.setAnimationLoop(this._animationLoop);
|
|
5576
|
+
}
|
|
5577
|
+
stop() {
|
|
5578
|
+
if (this._disposed) return;
|
|
5579
|
+
this.renderer.setAnimationLoop(null);
|
|
5580
|
+
if (this._animationTimer)
|
|
5581
|
+
clearTimeout(this._animationTimer);
|
|
5582
|
+
this._animationTimer = void 0;
|
|
5583
|
+
if (this._animationFrame)
|
|
5584
|
+
cancelAnimationFrame(this._animationFrame);
|
|
5585
|
+
this._animationFrame = void 0;
|
|
5586
|
+
}
|
|
5587
|
+
/**
|
|
5588
|
+
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
5589
|
+
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
5590
|
+
* controls must be managed by their owners.
|
|
5591
|
+
*/
|
|
5592
|
+
dispose() {
|
|
5593
|
+
if (this._disposed) return;
|
|
5594
|
+
this.stop();
|
|
5595
|
+
this._disposed = true;
|
|
5596
|
+
if (this._resizeListener) {
|
|
5597
|
+
window.removeEventListener("resize", this._resizeListener);
|
|
5598
|
+
this._resizeListener = void 0;
|
|
6116
5599
|
}
|
|
6117
|
-
|
|
6118
|
-
|
|
5600
|
+
for (const [dispatcher, events] of this._eventDispatchers) {
|
|
5601
|
+
for (const event of events) {
|
|
5602
|
+
dispatcher.removeEventListener(event, this._changeListener);
|
|
5603
|
+
}
|
|
6119
5604
|
}
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
5605
|
+
this._eventDispatchers.clear();
|
|
5606
|
+
this._stats?.dom.remove();
|
|
5607
|
+
this._stats = void 0;
|
|
5608
|
+
this.renderer.domElement.remove();
|
|
5609
|
+
this._element = void 0;
|
|
5610
|
+
this.scene.clear();
|
|
5611
|
+
for (const helper of this._debugHelpers) {
|
|
5612
|
+
helper.geometry.dispose();
|
|
5613
|
+
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
5614
|
+
for (const material of materials) {
|
|
5615
|
+
material.dispose();
|
|
6127
5616
|
}
|
|
6128
5617
|
}
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
5618
|
+
this._debugHelpers.length = 0;
|
|
5619
|
+
this.composer.dispose();
|
|
5620
|
+
this.renderer.dispose();
|
|
5621
|
+
this.renderer.forceContextLoss();
|
|
5622
|
+
}
|
|
5623
|
+
animate(t) {
|
|
5624
|
+
if (this._disposed) return;
|
|
5625
|
+
if (this._stats) {
|
|
5626
|
+
this._stats.begin();
|
|
5627
|
+
}
|
|
5628
|
+
if (this.dirty || this.options.render.renderAlways) {
|
|
5629
|
+
if (this.options.composer.enabled) {
|
|
5630
|
+
this.composer.render();
|
|
5631
|
+
} else {
|
|
5632
|
+
this.renderer.render(this.scene, this.camera);
|
|
6134
5633
|
}
|
|
6135
|
-
position.set(event.pageX, event.pageY);
|
|
6136
5634
|
}
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
5635
|
+
this.dirty = false;
|
|
5636
|
+
if (this._stats) {
|
|
5637
|
+
this._stats.end();
|
|
6140
5638
|
}
|
|
6141
|
-
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6142
|
-
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6143
|
-
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6144
|
-
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6145
|
-
this.update();
|
|
6146
5639
|
}
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
this.
|
|
6154
|
-
|
|
6155
|
-
|
|
5640
|
+
//</editor-fold>
|
|
5641
|
+
toImage() {
|
|
5642
|
+
return this.renderer.domElement.toDataURL();
|
|
5643
|
+
}
|
|
5644
|
+
///
|
|
5645
|
+
get attachedToBody() {
|
|
5646
|
+
return this.element === document.body;
|
|
5647
|
+
}
|
|
5648
|
+
get viewWidth() {
|
|
5649
|
+
return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
|
|
5650
|
+
}
|
|
5651
|
+
get viewHeight() {
|
|
5652
|
+
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
5653
|
+
}
|
|
5654
|
+
get scene() {
|
|
5655
|
+
return this._scene;
|
|
5656
|
+
}
|
|
5657
|
+
get camera() {
|
|
5658
|
+
return this._camera;
|
|
5659
|
+
}
|
|
5660
|
+
get renderer() {
|
|
5661
|
+
return this._renderer;
|
|
6156
5662
|
}
|
|
5663
|
+
get composer() {
|
|
5664
|
+
return this._composer;
|
|
5665
|
+
}
|
|
5666
|
+
///
|
|
6157
5667
|
};
|
|
5668
|
+
_Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge10.default)({}, {
|
|
5669
|
+
camera: {
|
|
5670
|
+
type: "perspective",
|
|
5671
|
+
near: 1,
|
|
5672
|
+
far: 5e3,
|
|
5673
|
+
perspective: {
|
|
5674
|
+
aspect: void 0,
|
|
5675
|
+
fov: 50
|
|
5676
|
+
},
|
|
5677
|
+
orthographic: {
|
|
5678
|
+
left: void 0,
|
|
5679
|
+
right: void 0,
|
|
5680
|
+
top: void 0,
|
|
5681
|
+
bottom: void 0
|
|
5682
|
+
},
|
|
5683
|
+
position: new Vector37(50, 50, 50),
|
|
5684
|
+
lookingAt: new Vector37(0, 0, 0)
|
|
5685
|
+
},
|
|
5686
|
+
render: {
|
|
5687
|
+
fpsLimit: 60,
|
|
5688
|
+
stats: false,
|
|
5689
|
+
antialias: true,
|
|
5690
|
+
shade: true,
|
|
5691
|
+
autoResize: true,
|
|
5692
|
+
renderAlways: false
|
|
5693
|
+
},
|
|
5694
|
+
composer: {
|
|
5695
|
+
enabled: true
|
|
5696
|
+
},
|
|
5697
|
+
debug: {
|
|
5698
|
+
grid: false,
|
|
5699
|
+
axes: false
|
|
5700
|
+
}
|
|
5701
|
+
});
|
|
5702
|
+
var Renderer = _Renderer;
|
|
6158
5703
|
|
|
6159
|
-
// src/
|
|
6160
|
-
var
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
this._debugHelpers = [];
|
|
6166
|
-
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
6167
|
-
this._changeListener = () => {
|
|
6168
|
-
this._dirty = true;
|
|
6169
|
-
};
|
|
6170
|
-
this.options = (0, import_ts_deepmerge9.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
6171
|
-
this._animationLoop = this.animate.bind(this);
|
|
6172
|
-
this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
6173
|
-
this._scene = this.createScene();
|
|
6174
|
-
this._camera = this.createCamera();
|
|
6175
|
-
this._renderer = this.createRenderer();
|
|
6176
|
-
this._composer = this.createComposer();
|
|
6177
|
-
if (this.options.render.stats) {
|
|
6178
|
-
this._stats = new Stats();
|
|
6179
|
-
document.body.appendChild(this._stats.dom);
|
|
5704
|
+
// src/skin/Skins.ts
|
|
5705
|
+
var Skins = class {
|
|
5706
|
+
//<editor-fold desc="Skins">
|
|
5707
|
+
static async fromUuidOrUsername(uuidOrUsername) {
|
|
5708
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5709
|
+
return this.fromUuid(uuidOrUsername);
|
|
6180
5710
|
}
|
|
6181
|
-
this.
|
|
6182
|
-
|
|
5711
|
+
return this.fromUsername(uuidOrUsername);
|
|
5712
|
+
}
|
|
5713
|
+
static async fromUuid(uuid) {
|
|
5714
|
+
return this.getSkinProxySkinUrl(uuid);
|
|
5715
|
+
}
|
|
5716
|
+
static async fromUsername(username) {
|
|
5717
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
5718
|
+
if (uuid) {
|
|
5719
|
+
return this.fromUuid(uuid);
|
|
5720
|
+
}
|
|
5721
|
+
return void 0;
|
|
5722
|
+
});
|
|
5723
|
+
}
|
|
5724
|
+
static async fromMineSkin(mineskinId) {
|
|
5725
|
+
return this.getMineSkin(mineskinId).then((mineskin) => {
|
|
5726
|
+
if (mineskin) {
|
|
5727
|
+
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
5728
|
+
}
|
|
5729
|
+
return void 0;
|
|
5730
|
+
});
|
|
5731
|
+
}
|
|
5732
|
+
//</editor-fold>
|
|
5733
|
+
//<editor-fold desc="Capes">
|
|
5734
|
+
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
5735
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5736
|
+
return this.capeFromUuid(uuidOrUsername);
|
|
5737
|
+
}
|
|
5738
|
+
return this.capeFromUsername(uuidOrUsername);
|
|
5739
|
+
}
|
|
5740
|
+
static async capeFromUuid(uuid) {
|
|
5741
|
+
return this.getSkinProxyCapeUrl(uuid);
|
|
5742
|
+
}
|
|
5743
|
+
static async capeFromUsername(username) {
|
|
5744
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
5745
|
+
if (uuid) {
|
|
5746
|
+
return this.capeFromUuid(uuid);
|
|
5747
|
+
}
|
|
5748
|
+
return void 0;
|
|
5749
|
+
});
|
|
5750
|
+
}
|
|
5751
|
+
static async capeFromCapesDev(uuid, capeType = "minecraft") {
|
|
5752
|
+
return this.getCapesDev(uuid, capeType).then((cape) => {
|
|
5753
|
+
if (cape) {
|
|
5754
|
+
return cape?.stillImageUrl;
|
|
5755
|
+
}
|
|
5756
|
+
return void 0;
|
|
5757
|
+
});
|
|
5758
|
+
}
|
|
5759
|
+
//</editor-fold>
|
|
5760
|
+
//<editor-fold desc="Helpers">
|
|
5761
|
+
static async usernameToUuid(username) {
|
|
5762
|
+
return this.usernameToUuidSkinProxy(username);
|
|
5763
|
+
}
|
|
5764
|
+
static async usernameToUuidSkinProxy(username) {
|
|
5765
|
+
return Requests.genericRequest({
|
|
5766
|
+
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
5767
|
+
url: "/uuid/" + username
|
|
5768
|
+
}).then((res) => {
|
|
5769
|
+
if (res.status === 200) {
|
|
5770
|
+
return res.data["id"];
|
|
5771
|
+
}
|
|
5772
|
+
return void 0;
|
|
5773
|
+
}).catch((err) => {
|
|
5774
|
+
console.warn(err);
|
|
5775
|
+
return void 0;
|
|
5776
|
+
});
|
|
5777
|
+
}
|
|
5778
|
+
static async usernameToUuidMineTools(username) {
|
|
5779
|
+
return Requests.genericRequest({
|
|
5780
|
+
baseURL: "https://api.minetools.eu",
|
|
5781
|
+
url: "/uuid/" + username
|
|
5782
|
+
}).then((res) => {
|
|
5783
|
+
if (res.status === 200) {
|
|
5784
|
+
return res.data["id"];
|
|
5785
|
+
}
|
|
5786
|
+
return void 0;
|
|
5787
|
+
}).catch((err) => {
|
|
5788
|
+
console.warn(err);
|
|
5789
|
+
return void 0;
|
|
5790
|
+
});
|
|
6183
5791
|
}
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
5792
|
+
static async getProfileFromMinetools(uuid) {
|
|
5793
|
+
return Requests.genericRequest({
|
|
5794
|
+
baseURL: "https://api.minetools.eu",
|
|
5795
|
+
url: "/profile/" + uuid
|
|
5796
|
+
}).then((res) => {
|
|
5797
|
+
if (res.status === 200) {
|
|
5798
|
+
return res.data;
|
|
5799
|
+
}
|
|
5800
|
+
});
|
|
6187
5801
|
}
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
6202
|
-
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
6203
|
-
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
6204
|
-
this.options.camera.near,
|
|
6205
|
-
this.options.camera.far
|
|
6206
|
-
);
|
|
6207
|
-
}
|
|
5802
|
+
static async getMineSkin(mineskinId) {
|
|
5803
|
+
return Requests.genericRequest({
|
|
5804
|
+
baseURL: "https://api.mineskin.org",
|
|
5805
|
+
url: "/get/uuid/" + mineskinId
|
|
5806
|
+
}).then((res) => {
|
|
5807
|
+
if (res.status === 200) {
|
|
5808
|
+
return res.data;
|
|
5809
|
+
}
|
|
5810
|
+
return void 0;
|
|
5811
|
+
}).catch((err) => {
|
|
5812
|
+
console.warn(err);
|
|
5813
|
+
return void 0;
|
|
5814
|
+
});
|
|
6208
5815
|
}
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
5816
|
+
static async getCapesDev(uuid, type = "all") {
|
|
5817
|
+
return Requests.genericRequest({
|
|
5818
|
+
baseURL: "https://api.capes.dev",
|
|
5819
|
+
url: "/load/" + uuid + "/" + type
|
|
5820
|
+
}).then((res) => {
|
|
5821
|
+
if (res.status === 200) {
|
|
5822
|
+
return res.data;
|
|
5823
|
+
}
|
|
5824
|
+
return void 0;
|
|
5825
|
+
}).catch((err) => {
|
|
5826
|
+
console.warn(err);
|
|
5827
|
+
return void 0;
|
|
6215
5828
|
});
|
|
6216
|
-
renderer.setClearColor(0, 0);
|
|
6217
|
-
renderer.shadowMap.enabled = true;
|
|
6218
|
-
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
6219
|
-
renderer.outputColorSpace = SRGBColorSpace3;
|
|
6220
|
-
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
6221
|
-
return renderer;
|
|
6222
5829
|
}
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
return composer;
|
|
5830
|
+
static getCrafatarSkinUrl(uuid) {
|
|
5831
|
+
return "https://crafatar.com/skins/" + uuid;
|
|
5832
|
+
}
|
|
5833
|
+
static getCrafatarCapeUrl(uuid) {
|
|
5834
|
+
return "https://crafatar.com/capes/" + uuid;
|
|
6229
5835
|
}
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
controls.update();
|
|
6242
|
-
controls.saveState();
|
|
6243
|
-
this.registerEventDispatcher(controls);
|
|
6244
|
-
return controls;
|
|
5836
|
+
static getMcHeadsSkinUrl(uuid) {
|
|
5837
|
+
return "https://mc-heads.net/skin/" + uuid;
|
|
5838
|
+
}
|
|
5839
|
+
static getMineSkinPlayerSkinUrl(uuid) {
|
|
5840
|
+
return "https://mineskin.org/skin/player/" + uuid;
|
|
5841
|
+
}
|
|
5842
|
+
static getSkinProxySkinUrl(uuid) {
|
|
5843
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
5844
|
+
}
|
|
5845
|
+
static getSkinProxyCapeUrl(uuid) {
|
|
5846
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6245
5847
|
}
|
|
6246
5848
|
//</editor-fold>
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
5849
|
+
};
|
|
5850
|
+
|
|
5851
|
+
// src/three/OrbitControls.js
|
|
5852
|
+
import {
|
|
5853
|
+
EventDispatcher as EventDispatcher2,
|
|
5854
|
+
MOUSE,
|
|
5855
|
+
Quaternion as Quaternion3,
|
|
5856
|
+
Spherical,
|
|
5857
|
+
TOUCH,
|
|
5858
|
+
Vector2 as Vector23,
|
|
5859
|
+
Vector3 as Vector38
|
|
5860
|
+
} from "three";
|
|
5861
|
+
var _changeEvent = { type: "change" };
|
|
5862
|
+
var _startEvent = { type: "start" };
|
|
5863
|
+
var _endEvent = { type: "end" };
|
|
5864
|
+
var OrbitControls = class extends EventDispatcher2 {
|
|
5865
|
+
constructor(object, domElement) {
|
|
5866
|
+
super();
|
|
5867
|
+
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
5868
|
+
if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
|
5869
|
+
this.object = object;
|
|
5870
|
+
this.domElement = domElement;
|
|
5871
|
+
this.domElement.style.touchAction = "none";
|
|
5872
|
+
this.enabled = true;
|
|
5873
|
+
this.target = new Vector38();
|
|
5874
|
+
this.minDistance = 0;
|
|
5875
|
+
this.maxDistance = Infinity;
|
|
5876
|
+
this.minZoom = 0;
|
|
5877
|
+
this.maxZoom = Infinity;
|
|
5878
|
+
this.minPolarAngle = 0;
|
|
5879
|
+
this.maxPolarAngle = Math.PI;
|
|
5880
|
+
this.minAzimuthAngle = -Infinity;
|
|
5881
|
+
this.maxAzimuthAngle = Infinity;
|
|
5882
|
+
this.enableDamping = false;
|
|
5883
|
+
this.dampingFactor = 0.05;
|
|
5884
|
+
this.enableZoom = true;
|
|
5885
|
+
this.zoomSpeed = 1;
|
|
5886
|
+
this.enableRotate = true;
|
|
5887
|
+
this.rotateSpeed = 1;
|
|
5888
|
+
this.enablePan = true;
|
|
5889
|
+
this.panSpeed = 1;
|
|
5890
|
+
this.screenSpacePanning = true;
|
|
5891
|
+
this.keyPanSpeed = 7;
|
|
5892
|
+
this.autoRotate = false;
|
|
5893
|
+
this.autoRotateSpeed = 2;
|
|
5894
|
+
this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
|
|
5895
|
+
this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
|
|
5896
|
+
this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
|
|
5897
|
+
this.target0 = this.target.clone();
|
|
5898
|
+
this.position0 = this.object.position.clone();
|
|
5899
|
+
this.zoom0 = this.object.zoom;
|
|
5900
|
+
this._domElementKeyEvents = null;
|
|
5901
|
+
this.getPolarAngle = function() {
|
|
5902
|
+
return spherical.phi;
|
|
5903
|
+
};
|
|
5904
|
+
this.getAzimuthalAngle = function() {
|
|
5905
|
+
return spherical.theta;
|
|
5906
|
+
};
|
|
5907
|
+
this.getDistance = function() {
|
|
5908
|
+
return this.object.position.distanceTo(this.target);
|
|
5909
|
+
};
|
|
5910
|
+
this.saveState = function() {
|
|
5911
|
+
scope.target0.copy(scope.target);
|
|
5912
|
+
scope.position0.copy(scope.object.position);
|
|
5913
|
+
scope.zoom0 = scope.object.zoom;
|
|
5914
|
+
};
|
|
5915
|
+
this.reset = function() {
|
|
5916
|
+
scope.target.copy(scope.target0);
|
|
5917
|
+
scope.object.position.copy(scope.position0);
|
|
5918
|
+
scope.object.zoom = scope.zoom0;
|
|
5919
|
+
scope.object.updateProjectionMatrix();
|
|
5920
|
+
scope.dispatchEvent(_changeEvent);
|
|
5921
|
+
scope.update();
|
|
5922
|
+
state = STATE.NONE;
|
|
5923
|
+
};
|
|
5924
|
+
this.update = function() {
|
|
5925
|
+
const offset = new Vector38();
|
|
5926
|
+
const quat = new Quaternion3().setFromUnitVectors(object.up, new Vector38(0, 1, 0));
|
|
5927
|
+
const quatInverse = quat.clone().invert();
|
|
5928
|
+
const lastPosition = new Vector38();
|
|
5929
|
+
const lastQuaternion = new Quaternion3();
|
|
5930
|
+
const twoPI = 2 * Math.PI;
|
|
5931
|
+
return function update() {
|
|
5932
|
+
const position = scope.object.position;
|
|
5933
|
+
offset.copy(position).sub(scope.target);
|
|
5934
|
+
offset.applyQuaternion(quat);
|
|
5935
|
+
spherical.setFromVector3(offset);
|
|
5936
|
+
if (scope.autoRotate && state === STATE.NONE) {
|
|
5937
|
+
rotateLeft(getAutoRotationAngle());
|
|
5938
|
+
}
|
|
5939
|
+
if (scope.enableDamping) {
|
|
5940
|
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
5941
|
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
5942
|
+
} else {
|
|
5943
|
+
spherical.theta += sphericalDelta.theta;
|
|
5944
|
+
spherical.phi += sphericalDelta.phi;
|
|
5945
|
+
}
|
|
5946
|
+
let min = scope.minAzimuthAngle;
|
|
5947
|
+
let max = scope.maxAzimuthAngle;
|
|
5948
|
+
if (isFinite(min) && isFinite(max)) {
|
|
5949
|
+
if (min < -Math.PI) min += twoPI;
|
|
5950
|
+
else if (min > Math.PI) min -= twoPI;
|
|
5951
|
+
if (max < -Math.PI) max += twoPI;
|
|
5952
|
+
else if (max > Math.PI) max -= twoPI;
|
|
5953
|
+
if (min <= max) {
|
|
5954
|
+
spherical.theta = Math.max(min, Math.min(max, spherical.theta));
|
|
5955
|
+
} else {
|
|
5956
|
+
spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5959
|
+
spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
|
|
5960
|
+
spherical.makeSafe();
|
|
5961
|
+
spherical.radius *= scale;
|
|
5962
|
+
spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
|
|
5963
|
+
if (scope.enableDamping === true) {
|
|
5964
|
+
scope.target.addScaledVector(panOffset, scope.dampingFactor);
|
|
5965
|
+
} else {
|
|
5966
|
+
scope.target.add(panOffset);
|
|
5967
|
+
}
|
|
5968
|
+
offset.setFromSpherical(spherical);
|
|
5969
|
+
offset.applyQuaternion(quatInverse);
|
|
5970
|
+
position.copy(scope.target).add(offset);
|
|
5971
|
+
scope.object.lookAt(scope.target);
|
|
5972
|
+
if (scope.enableDamping === true) {
|
|
5973
|
+
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
5974
|
+
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
5975
|
+
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
5976
|
+
} else {
|
|
5977
|
+
sphericalDelta.set(0, 0, 0);
|
|
5978
|
+
panOffset.set(0, 0, 0);
|
|
5979
|
+
}
|
|
5980
|
+
scale = 1;
|
|
5981
|
+
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
5982
|
+
scope.dispatchEvent(_changeEvent);
|
|
5983
|
+
lastPosition.copy(scope.object.position);
|
|
5984
|
+
lastQuaternion.copy(scope.object.quaternion);
|
|
5985
|
+
zoomChanged = false;
|
|
5986
|
+
return true;
|
|
5987
|
+
}
|
|
5988
|
+
return false;
|
|
5989
|
+
};
|
|
5990
|
+
}();
|
|
5991
|
+
this.dispose = function() {
|
|
5992
|
+
scope.domElement.removeEventListener("contextmenu", onContextMenu);
|
|
5993
|
+
scope.domElement.removeEventListener("pointerdown", onPointerDown);
|
|
5994
|
+
scope.domElement.removeEventListener("pointercancel", onPointerCancel);
|
|
5995
|
+
scope.domElement.removeEventListener("wheel", onMouseWheel);
|
|
5996
|
+
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
5997
|
+
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
5998
|
+
if (scope._domElementKeyEvents !== null) {
|
|
5999
|
+
scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
6000
|
+
}
|
|
6001
|
+
};
|
|
6002
|
+
const scope = this;
|
|
6003
|
+
const STATE = {
|
|
6004
|
+
NONE: -1,
|
|
6005
|
+
ROTATE: 0,
|
|
6006
|
+
DOLLY: 1,
|
|
6007
|
+
PAN: 2,
|
|
6008
|
+
TOUCH_ROTATE: 3,
|
|
6009
|
+
TOUCH_PAN: 4,
|
|
6010
|
+
TOUCH_DOLLY_PAN: 5,
|
|
6011
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
6012
|
+
};
|
|
6013
|
+
let state = STATE.NONE;
|
|
6014
|
+
const EPS = 1e-6;
|
|
6015
|
+
const spherical = new Spherical();
|
|
6016
|
+
const sphericalDelta = new Spherical();
|
|
6017
|
+
let scale = 1;
|
|
6018
|
+
const panOffset = new Vector38();
|
|
6019
|
+
let zoomChanged = false;
|
|
6020
|
+
const rotateStart = new Vector23();
|
|
6021
|
+
const rotateEnd = new Vector23();
|
|
6022
|
+
const rotateDelta = new Vector23();
|
|
6023
|
+
const panStart = new Vector23();
|
|
6024
|
+
const panEnd = new Vector23();
|
|
6025
|
+
const panDelta = new Vector23();
|
|
6026
|
+
const dollyStart = new Vector23();
|
|
6027
|
+
const dollyEnd = new Vector23();
|
|
6028
|
+
const dollyDelta = new Vector23();
|
|
6029
|
+
const pointers = [];
|
|
6030
|
+
const pointerPositions = {};
|
|
6031
|
+
function getAutoRotationAngle() {
|
|
6032
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
6251
6033
|
}
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
this._debugHelpers.push(gridHelper);
|
|
6255
|
-
this.scene.add(gridHelper);
|
|
6256
|
-
const gridHelper2 = new GridHelper(128, 16);
|
|
6257
|
-
this._debugHelpers.push(gridHelper2);
|
|
6258
|
-
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
6259
|
-
this.scene.add(gridHelper2);
|
|
6260
|
-
const gridHelper3 = new GridHelper(128, 16);
|
|
6261
|
-
this._debugHelpers.push(gridHelper3);
|
|
6262
|
-
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
6263
|
-
this.scene.add(gridHelper3);
|
|
6034
|
+
function getZoomScale() {
|
|
6035
|
+
return Math.pow(0.95, scope.zoomSpeed);
|
|
6264
6036
|
}
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
this._debugHelpers.push(axesHelper);
|
|
6268
|
-
this.scene.add(axesHelper);
|
|
6037
|
+
function rotateLeft(angle) {
|
|
6038
|
+
sphericalDelta.theta -= angle;
|
|
6269
6039
|
}
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6040
|
+
function rotateUp(angle) {
|
|
6041
|
+
sphericalDelta.phi -= angle;
|
|
6042
|
+
}
|
|
6043
|
+
const panLeft = function() {
|
|
6044
|
+
const v = new Vector38();
|
|
6045
|
+
return function panLeft2(distance, objectMatrix) {
|
|
6046
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
6047
|
+
v.multiplyScalar(-distance);
|
|
6048
|
+
panOffset.add(v);
|
|
6049
|
+
};
|
|
6050
|
+
}();
|
|
6051
|
+
const panUp = function() {
|
|
6052
|
+
const v = new Vector38();
|
|
6053
|
+
return function panUp2(distance, objectMatrix) {
|
|
6054
|
+
if (scope.screenSpacePanning === true) {
|
|
6055
|
+
v.setFromMatrixColumn(objectMatrix, 1);
|
|
6056
|
+
} else {
|
|
6057
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
6058
|
+
v.crossVectors(scope.object.up, v);
|
|
6059
|
+
}
|
|
6060
|
+
v.multiplyScalar(distance);
|
|
6061
|
+
panOffset.add(v);
|
|
6062
|
+
};
|
|
6063
|
+
}();
|
|
6064
|
+
const pan = function() {
|
|
6065
|
+
const offset = new Vector38();
|
|
6066
|
+
return function pan2(deltaX, deltaY) {
|
|
6067
|
+
const element = scope.domElement;
|
|
6068
|
+
if (scope.object.isPerspectiveCamera) {
|
|
6069
|
+
const position = scope.object.position;
|
|
6070
|
+
offset.copy(position).sub(scope.target);
|
|
6071
|
+
let targetDistance = offset.length();
|
|
6072
|
+
targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
|
|
6073
|
+
panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
|
|
6074
|
+
panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
|
|
6075
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
6076
|
+
panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
|
|
6077
|
+
panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
|
|
6078
|
+
} else {
|
|
6079
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
|
|
6080
|
+
scope.enablePan = false;
|
|
6081
|
+
}
|
|
6082
|
+
};
|
|
6083
|
+
}();
|
|
6084
|
+
function dollyOut(dollyScale) {
|
|
6085
|
+
if (scope.object.isPerspectiveCamera) {
|
|
6086
|
+
scale /= dollyScale;
|
|
6087
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
6088
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
|
|
6089
|
+
scope.object.updateProjectionMatrix();
|
|
6090
|
+
zoomChanged = true;
|
|
6091
|
+
} else {
|
|
6092
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
6093
|
+
scope.enableZoom = false;
|
|
6275
6094
|
}
|
|
6276
6095
|
}
|
|
6277
|
-
|
|
6278
|
-
if (
|
|
6279
|
-
|
|
6280
|
-
} else if (
|
|
6281
|
-
|
|
6096
|
+
function dollyIn(dollyScale) {
|
|
6097
|
+
if (scope.object.isPerspectiveCamera) {
|
|
6098
|
+
scale *= dollyScale;
|
|
6099
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
6100
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
|
|
6101
|
+
scope.object.updateProjectionMatrix();
|
|
6102
|
+
zoomChanged = true;
|
|
6103
|
+
} else {
|
|
6104
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
6105
|
+
scope.enableZoom = false;
|
|
6282
6106
|
}
|
|
6283
6107
|
}
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
this.resize(this.viewWidth, this.viewHeight);
|
|
6287
|
-
};
|
|
6288
|
-
window.addEventListener("resize", this._resizeListener);
|
|
6108
|
+
function handleMouseDownRotate(event) {
|
|
6109
|
+
rotateStart.set(event.clientX, event.clientY);
|
|
6289
6110
|
}
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
return this._element;
|
|
6293
|
-
}
|
|
6294
|
-
appendTo(element) {
|
|
6295
|
-
if (this._disposed) return;
|
|
6296
|
-
this._element = element;
|
|
6297
|
-
this._element.appendChild(this.renderer.domElement);
|
|
6298
|
-
if (this.viewWidth == 0) {
|
|
6299
|
-
console.warn("0 element width");
|
|
6111
|
+
function handleMouseDownDolly(event) {
|
|
6112
|
+
dollyStart.set(event.clientX, event.clientY);
|
|
6300
6113
|
}
|
|
6301
|
-
|
|
6302
|
-
|
|
6114
|
+
function handleMouseDownPan(event) {
|
|
6115
|
+
panStart.set(event.clientX, event.clientY);
|
|
6303
6116
|
}
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
let events = this._eventDispatchers.get(dispatcher);
|
|
6313
|
-
if (!events) {
|
|
6314
|
-
events = /* @__PURE__ */ new Set();
|
|
6315
|
-
this._eventDispatchers.set(dispatcher, events);
|
|
6117
|
+
function handleMouseMoveRotate(event) {
|
|
6118
|
+
rotateEnd.set(event.clientX, event.clientY);
|
|
6119
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
6120
|
+
const element = scope.domElement;
|
|
6121
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
6122
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
6123
|
+
rotateStart.copy(rotateEnd);
|
|
6124
|
+
scope.update();
|
|
6316
6125
|
}
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
this.camera.left = width / -2;
|
|
6328
|
-
this.camera.right = width / 2;
|
|
6329
|
-
this.camera.top = height / 2;
|
|
6330
|
-
this.camera.bottom = height / -2;
|
|
6331
|
-
this.camera.updateProjectionMatrix();
|
|
6126
|
+
function handleMouseMoveDolly(event) {
|
|
6127
|
+
dollyEnd.set(event.clientX, event.clientY);
|
|
6128
|
+
dollyDelta.subVectors(dollyEnd, dollyStart);
|
|
6129
|
+
if (dollyDelta.y > 0) {
|
|
6130
|
+
dollyOut(getZoomScale());
|
|
6131
|
+
} else if (dollyDelta.y < 0) {
|
|
6132
|
+
dollyIn(getZoomScale());
|
|
6133
|
+
}
|
|
6134
|
+
dollyStart.copy(dollyEnd);
|
|
6135
|
+
scope.update();
|
|
6332
6136
|
}
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6137
|
+
function handleMouseMovePan(event) {
|
|
6138
|
+
panEnd.set(event.clientX, event.clientY);
|
|
6139
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
6140
|
+
pan(panDelta.x, panDelta.y);
|
|
6141
|
+
panStart.copy(panEnd);
|
|
6142
|
+
scope.update();
|
|
6143
|
+
}
|
|
6144
|
+
function handleMouseUp() {
|
|
6145
|
+
}
|
|
6146
|
+
function handleMouseWheel(event) {
|
|
6147
|
+
if (event.deltaY < 0) {
|
|
6148
|
+
dollyIn(getZoomScale());
|
|
6149
|
+
} else if (event.deltaY > 0) {
|
|
6150
|
+
dollyOut(getZoomScale());
|
|
6151
|
+
}
|
|
6152
|
+
scope.update();
|
|
6153
|
+
}
|
|
6154
|
+
function handleKeyDown(event) {
|
|
6155
|
+
let needsUpdate = false;
|
|
6156
|
+
switch (event.code) {
|
|
6157
|
+
case scope.keys.UP:
|
|
6158
|
+
pan(0, scope.keyPanSpeed);
|
|
6159
|
+
needsUpdate = true;
|
|
6160
|
+
break;
|
|
6161
|
+
case scope.keys.BOTTOM:
|
|
6162
|
+
pan(0, -scope.keyPanSpeed);
|
|
6163
|
+
needsUpdate = true;
|
|
6164
|
+
break;
|
|
6165
|
+
case scope.keys.LEFT:
|
|
6166
|
+
pan(scope.keyPanSpeed, 0);
|
|
6167
|
+
needsUpdate = true;
|
|
6168
|
+
break;
|
|
6169
|
+
case scope.keys.RIGHT:
|
|
6170
|
+
pan(-scope.keyPanSpeed, 0);
|
|
6171
|
+
needsUpdate = true;
|
|
6172
|
+
break;
|
|
6173
|
+
}
|
|
6174
|
+
if (needsUpdate) {
|
|
6175
|
+
event.preventDefault();
|
|
6176
|
+
scope.update();
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6179
|
+
function handleTouchStartRotate() {
|
|
6180
|
+
if (pointers.length === 1) {
|
|
6181
|
+
rotateStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
6182
|
+
} else {
|
|
6183
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
6184
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
6185
|
+
rotateStart.set(x, y);
|
|
6186
|
+
}
|
|
6367
6187
|
}
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6188
|
+
function handleTouchStartPan() {
|
|
6189
|
+
if (pointers.length === 1) {
|
|
6190
|
+
panStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
6191
|
+
} else {
|
|
6192
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
6193
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
6194
|
+
panStart.set(x, y);
|
|
6371
6195
|
}
|
|
6372
6196
|
}
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
if (this._controls) {
|
|
6379
|
-
const controls = this._controls;
|
|
6380
|
-
this._controls = void 0;
|
|
6381
|
-
controls.enabled = false;
|
|
6382
|
-
controls.dispose();
|
|
6197
|
+
function handleTouchStartDolly() {
|
|
6198
|
+
const dx = pointers[0].pageX - pointers[1].pageX;
|
|
6199
|
+
const dy = pointers[0].pageY - pointers[1].pageY;
|
|
6200
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
6201
|
+
dollyStart.set(0, distance);
|
|
6383
6202
|
}
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6203
|
+
function handleTouchStartDollyPan() {
|
|
6204
|
+
if (scope.enableZoom) handleTouchStartDolly();
|
|
6205
|
+
if (scope.enablePan) handleTouchStartPan();
|
|
6206
|
+
}
|
|
6207
|
+
function handleTouchStartDollyRotate() {
|
|
6208
|
+
if (scope.enableZoom) handleTouchStartDolly();
|
|
6209
|
+
if (scope.enableRotate) handleTouchStartRotate();
|
|
6210
|
+
}
|
|
6211
|
+
function handleTouchMoveRotate(event) {
|
|
6212
|
+
if (pointers.length == 1) {
|
|
6213
|
+
rotateEnd.set(event.pageX, event.pageY);
|
|
6214
|
+
} else {
|
|
6215
|
+
const position = getSecondPointerPosition(event);
|
|
6216
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
6217
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
6218
|
+
rotateEnd.set(x, y);
|
|
6390
6219
|
}
|
|
6220
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
6221
|
+
const element = scope.domElement;
|
|
6222
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
6223
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
6224
|
+
rotateStart.copy(rotateEnd);
|
|
6391
6225
|
}
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6226
|
+
function handleTouchMovePan(event) {
|
|
6227
|
+
if (pointers.length === 1) {
|
|
6228
|
+
panEnd.set(event.pageX, event.pageY);
|
|
6229
|
+
} else {
|
|
6230
|
+
const position = getSecondPointerPosition(event);
|
|
6231
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
6232
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
6233
|
+
panEnd.set(x, y);
|
|
6234
|
+
}
|
|
6235
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
6236
|
+
pan(panDelta.x, panDelta.y);
|
|
6237
|
+
panStart.copy(panEnd);
|
|
6401
6238
|
}
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
const
|
|
6407
|
-
|
|
6408
|
-
|
|
6239
|
+
function handleTouchMoveDolly(event) {
|
|
6240
|
+
const position = getSecondPointerPosition(event);
|
|
6241
|
+
const dx = event.pageX - position.x;
|
|
6242
|
+
const dy = event.pageY - position.y;
|
|
6243
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
6244
|
+
dollyEnd.set(0, distance);
|
|
6245
|
+
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
6246
|
+
dollyOut(dollyDelta.y);
|
|
6247
|
+
dollyStart.copy(dollyEnd);
|
|
6409
6248
|
}
|
|
6410
|
-
|
|
6411
|
-
|
|
6249
|
+
function handleTouchMoveDollyPan(event) {
|
|
6250
|
+
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
6251
|
+
if (scope.enablePan) handleTouchMovePan(event);
|
|
6412
6252
|
}
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
this.renderer.render(this.scene, this.camera);
|
|
6253
|
+
function handleTouchMoveDollyRotate(event) {
|
|
6254
|
+
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
6255
|
+
if (scope.enableRotate) handleTouchMoveRotate(event);
|
|
6417
6256
|
}
|
|
6418
|
-
|
|
6419
|
-
if (this._stats) {
|
|
6420
|
-
this._stats.end();
|
|
6257
|
+
function handleTouchEnd() {
|
|
6421
6258
|
}
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
6436
|
-
}
|
|
6437
|
-
get scene() {
|
|
6438
|
-
return this._scene;
|
|
6439
|
-
}
|
|
6440
|
-
get camera() {
|
|
6441
|
-
return this._camera;
|
|
6442
|
-
}
|
|
6443
|
-
get renderer() {
|
|
6444
|
-
return this._renderer;
|
|
6445
|
-
}
|
|
6446
|
-
get composer() {
|
|
6447
|
-
return this._composer;
|
|
6448
|
-
}
|
|
6449
|
-
/** Renderer-owned controls, or undefined when disabled at construction or after disposal. */
|
|
6450
|
-
get controls() {
|
|
6451
|
-
return this._controls;
|
|
6452
|
-
}
|
|
6453
|
-
///
|
|
6454
|
-
};
|
|
6455
|
-
_Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
|
|
6456
|
-
camera: {
|
|
6457
|
-
type: "perspective",
|
|
6458
|
-
near: 1,
|
|
6459
|
-
far: 5e3,
|
|
6460
|
-
perspective: {
|
|
6461
|
-
aspect: void 0,
|
|
6462
|
-
fov: 50
|
|
6463
|
-
},
|
|
6464
|
-
orthographic: {
|
|
6465
|
-
left: void 0,
|
|
6466
|
-
right: void 0,
|
|
6467
|
-
top: void 0,
|
|
6468
|
-
bottom: void 0
|
|
6469
|
-
},
|
|
6470
|
-
position: new Vector38(50, 50, 50),
|
|
6471
|
-
lookingAt: new Vector38(0, 0, 0)
|
|
6472
|
-
},
|
|
6473
|
-
render: {
|
|
6474
|
-
fpsLimit: 60,
|
|
6475
|
-
stats: false,
|
|
6476
|
-
antialias: true,
|
|
6477
|
-
shade: true,
|
|
6478
|
-
autoResize: true,
|
|
6479
|
-
renderAlways: false
|
|
6480
|
-
},
|
|
6481
|
-
composer: {
|
|
6482
|
-
enabled: true
|
|
6483
|
-
},
|
|
6484
|
-
controls: {
|
|
6485
|
-
enabled: false
|
|
6486
|
-
},
|
|
6487
|
-
debug: {
|
|
6488
|
-
grid: false,
|
|
6489
|
-
axes: false
|
|
6490
|
-
}
|
|
6491
|
-
});
|
|
6492
|
-
var Renderer = _Renderer;
|
|
6493
|
-
|
|
6494
|
-
// src/skin/Skins.ts
|
|
6495
|
-
var Skins = class {
|
|
6496
|
-
//<editor-fold desc="Skins">
|
|
6497
|
-
static async fromUuidOrUsername(uuidOrUsername) {
|
|
6498
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6499
|
-
return this.fromUuid(uuidOrUsername);
|
|
6259
|
+
function onPointerDown(event) {
|
|
6260
|
+
if (scope.enabled === false) return;
|
|
6261
|
+
if (pointers.length === 0) {
|
|
6262
|
+
scope.domElement.setPointerCapture(event.pointerId);
|
|
6263
|
+
scope.domElement.addEventListener("pointermove", onPointerMove);
|
|
6264
|
+
scope.domElement.addEventListener("pointerup", onPointerUp);
|
|
6265
|
+
}
|
|
6266
|
+
addPointer(event);
|
|
6267
|
+
if (event.pointerType === "touch") {
|
|
6268
|
+
onTouchStart(event);
|
|
6269
|
+
} else {
|
|
6270
|
+
onMouseDown(event);
|
|
6271
|
+
}
|
|
6500
6272
|
}
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
return this.usernameToUuid(username).then((uuid) => {
|
|
6508
|
-
if (uuid) {
|
|
6509
|
-
return this.fromUuid(uuid);
|
|
6273
|
+
function onPointerMove(event) {
|
|
6274
|
+
if (scope.enabled === false) return;
|
|
6275
|
+
if (event.pointerType === "touch") {
|
|
6276
|
+
onTouchMove(event);
|
|
6277
|
+
} else {
|
|
6278
|
+
onMouseMove(event);
|
|
6510
6279
|
}
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6280
|
+
}
|
|
6281
|
+
function onPointerUp(event) {
|
|
6282
|
+
if (scope.enabled === false) return;
|
|
6283
|
+
if (event.pointerType === "touch") {
|
|
6284
|
+
onTouchEnd();
|
|
6285
|
+
} else {
|
|
6286
|
+
onMouseUp(event);
|
|
6287
|
+
}
|
|
6288
|
+
removePointer(event);
|
|
6289
|
+
if (pointers.length === 0) {
|
|
6290
|
+
scope.domElement.releasePointerCapture(event.pointerId);
|
|
6291
|
+
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
6292
|
+
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
6295
|
+
function onPointerCancel(event) {
|
|
6296
|
+
removePointer(event);
|
|
6297
|
+
}
|
|
6298
|
+
function onMouseDown(event) {
|
|
6299
|
+
let mouseAction;
|
|
6300
|
+
switch (event.button) {
|
|
6301
|
+
case 0:
|
|
6302
|
+
mouseAction = scope.mouseButtons.LEFT;
|
|
6303
|
+
break;
|
|
6304
|
+
case 1:
|
|
6305
|
+
mouseAction = scope.mouseButtons.MIDDLE;
|
|
6306
|
+
break;
|
|
6307
|
+
case 2:
|
|
6308
|
+
mouseAction = scope.mouseButtons.RIGHT;
|
|
6309
|
+
break;
|
|
6310
|
+
default:
|
|
6311
|
+
mouseAction = -1;
|
|
6312
|
+
}
|
|
6313
|
+
switch (mouseAction) {
|
|
6314
|
+
case MOUSE.DOLLY:
|
|
6315
|
+
if (scope.enableZoom === false) return;
|
|
6316
|
+
handleMouseDownDolly(event);
|
|
6317
|
+
state = STATE.DOLLY;
|
|
6318
|
+
break;
|
|
6319
|
+
case MOUSE.ROTATE:
|
|
6320
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6321
|
+
if (scope.enablePan === false) return;
|
|
6322
|
+
handleMouseDownPan(event);
|
|
6323
|
+
state = STATE.PAN;
|
|
6324
|
+
} else {
|
|
6325
|
+
if (scope.enableRotate === false) return;
|
|
6326
|
+
handleMouseDownRotate(event);
|
|
6327
|
+
state = STATE.ROTATE;
|
|
6328
|
+
}
|
|
6329
|
+
break;
|
|
6330
|
+
case MOUSE.PAN:
|
|
6331
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6332
|
+
if (scope.enableRotate === false) return;
|
|
6333
|
+
handleMouseDownRotate(event);
|
|
6334
|
+
state = STATE.ROTATE;
|
|
6335
|
+
} else {
|
|
6336
|
+
if (scope.enablePan === false) return;
|
|
6337
|
+
handleMouseDownPan(event);
|
|
6338
|
+
state = STATE.PAN;
|
|
6339
|
+
}
|
|
6340
|
+
break;
|
|
6341
|
+
default:
|
|
6342
|
+
state = STATE.NONE;
|
|
6343
|
+
}
|
|
6344
|
+
if (state !== STATE.NONE) {
|
|
6345
|
+
scope.dispatchEvent(_startEvent);
|
|
6518
6346
|
}
|
|
6519
|
-
return void 0;
|
|
6520
|
-
});
|
|
6521
|
-
}
|
|
6522
|
-
//</editor-fold>
|
|
6523
|
-
//<editor-fold desc="Capes">
|
|
6524
|
-
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
6525
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6526
|
-
return this.capeFromUuid(uuidOrUsername);
|
|
6527
6347
|
}
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
if (cape) {
|
|
6544
|
-
return cape?.stillImageUrl;
|
|
6348
|
+
function onMouseMove(event) {
|
|
6349
|
+
if (scope.enabled === false) return;
|
|
6350
|
+
switch (state) {
|
|
6351
|
+
case STATE.ROTATE:
|
|
6352
|
+
if (scope.enableRotate === false) return;
|
|
6353
|
+
handleMouseMoveRotate(event);
|
|
6354
|
+
break;
|
|
6355
|
+
case STATE.DOLLY:
|
|
6356
|
+
if (scope.enableZoom === false) return;
|
|
6357
|
+
handleMouseMoveDolly(event);
|
|
6358
|
+
break;
|
|
6359
|
+
case STATE.PAN:
|
|
6360
|
+
if (scope.enablePan === false) return;
|
|
6361
|
+
handleMouseMovePan(event);
|
|
6362
|
+
break;
|
|
6545
6363
|
}
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
}
|
|
6559
|
-
|
|
6560
|
-
|
|
6364
|
+
}
|
|
6365
|
+
function onMouseUp(event) {
|
|
6366
|
+
handleMouseUp(event);
|
|
6367
|
+
scope.dispatchEvent(_endEvent);
|
|
6368
|
+
state = STATE.NONE;
|
|
6369
|
+
}
|
|
6370
|
+
function onMouseWheel(event) {
|
|
6371
|
+
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
|
|
6372
|
+
event.preventDefault();
|
|
6373
|
+
scope.dispatchEvent(_startEvent);
|
|
6374
|
+
handleMouseWheel(event);
|
|
6375
|
+
scope.dispatchEvent(_endEvent);
|
|
6376
|
+
}
|
|
6377
|
+
function onKeyDown(event) {
|
|
6378
|
+
if (scope.enabled === false || scope.enablePan === false) return;
|
|
6379
|
+
handleKeyDown(event);
|
|
6380
|
+
}
|
|
6381
|
+
function onTouchStart(event) {
|
|
6382
|
+
trackPointer(event);
|
|
6383
|
+
switch (pointers.length) {
|
|
6384
|
+
case 1:
|
|
6385
|
+
switch (scope.touches.ONE) {
|
|
6386
|
+
case TOUCH.ROTATE:
|
|
6387
|
+
if (scope.enableRotate === false) return;
|
|
6388
|
+
handleTouchStartRotate();
|
|
6389
|
+
state = STATE.TOUCH_ROTATE;
|
|
6390
|
+
break;
|
|
6391
|
+
case TOUCH.PAN:
|
|
6392
|
+
if (scope.enablePan === false) return;
|
|
6393
|
+
handleTouchStartPan();
|
|
6394
|
+
state = STATE.TOUCH_PAN;
|
|
6395
|
+
break;
|
|
6396
|
+
default:
|
|
6397
|
+
state = STATE.NONE;
|
|
6398
|
+
}
|
|
6399
|
+
break;
|
|
6400
|
+
case 2:
|
|
6401
|
+
switch (scope.touches.TWO) {
|
|
6402
|
+
case TOUCH.DOLLY_PAN:
|
|
6403
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6404
|
+
handleTouchStartDollyPan();
|
|
6405
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
|
6406
|
+
break;
|
|
6407
|
+
case TOUCH.DOLLY_ROTATE:
|
|
6408
|
+
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6409
|
+
handleTouchStartDollyRotate();
|
|
6410
|
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
6411
|
+
break;
|
|
6412
|
+
default:
|
|
6413
|
+
state = STATE.NONE;
|
|
6414
|
+
}
|
|
6415
|
+
break;
|
|
6416
|
+
default:
|
|
6417
|
+
state = STATE.NONE;
|
|
6561
6418
|
}
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
console.warn(err);
|
|
6565
|
-
return void 0;
|
|
6566
|
-
});
|
|
6567
|
-
}
|
|
6568
|
-
static async usernameToUuidMineTools(username) {
|
|
6569
|
-
return Requests.genericRequest({
|
|
6570
|
-
baseURL: "https://api.minetools.eu",
|
|
6571
|
-
url: "/uuid/" + username
|
|
6572
|
-
}).then((res) => {
|
|
6573
|
-
if (res.status === 200) {
|
|
6574
|
-
return res.data["id"];
|
|
6419
|
+
if (state !== STATE.NONE) {
|
|
6420
|
+
scope.dispatchEvent(_startEvent);
|
|
6575
6421
|
}
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6422
|
+
}
|
|
6423
|
+
function onTouchMove(event) {
|
|
6424
|
+
trackPointer(event);
|
|
6425
|
+
switch (state) {
|
|
6426
|
+
case STATE.TOUCH_ROTATE:
|
|
6427
|
+
if (scope.enableRotate === false) return;
|
|
6428
|
+
handleTouchMoveRotate(event);
|
|
6429
|
+
scope.update();
|
|
6430
|
+
break;
|
|
6431
|
+
case STATE.TOUCH_PAN:
|
|
6432
|
+
if (scope.enablePan === false) return;
|
|
6433
|
+
handleTouchMovePan(event);
|
|
6434
|
+
scope.update();
|
|
6435
|
+
break;
|
|
6436
|
+
case STATE.TOUCH_DOLLY_PAN:
|
|
6437
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6438
|
+
handleTouchMoveDollyPan(event);
|
|
6439
|
+
scope.update();
|
|
6440
|
+
break;
|
|
6441
|
+
case STATE.TOUCH_DOLLY_ROTATE:
|
|
6442
|
+
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6443
|
+
handleTouchMoveDollyRotate(event);
|
|
6444
|
+
scope.update();
|
|
6445
|
+
break;
|
|
6446
|
+
default:
|
|
6447
|
+
state = STATE.NONE;
|
|
6589
6448
|
}
|
|
6590
|
-
}
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
if (
|
|
6598
|
-
|
|
6449
|
+
}
|
|
6450
|
+
function onTouchEnd(event) {
|
|
6451
|
+
handleTouchEnd(event);
|
|
6452
|
+
scope.dispatchEvent(_endEvent);
|
|
6453
|
+
state = STATE.NONE;
|
|
6454
|
+
}
|
|
6455
|
+
function onContextMenu(event) {
|
|
6456
|
+
if (scope.enabled === false) return;
|
|
6457
|
+
event.preventDefault();
|
|
6458
|
+
}
|
|
6459
|
+
function addPointer(event) {
|
|
6460
|
+
pointers.push(event);
|
|
6461
|
+
}
|
|
6462
|
+
function removePointer(event) {
|
|
6463
|
+
delete pointerPositions[event.pointerId];
|
|
6464
|
+
for (let i = 0; i < pointers.length; i++) {
|
|
6465
|
+
if (pointers[i].pointerId == event.pointerId) {
|
|
6466
|
+
pointers.splice(i, 1);
|
|
6467
|
+
return;
|
|
6468
|
+
}
|
|
6599
6469
|
}
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
static async getCapesDev(uuid, type = "all") {
|
|
6607
|
-
return Requests.genericRequest({
|
|
6608
|
-
baseURL: "https://api.capes.dev",
|
|
6609
|
-
url: "/load/" + uuid + "/" + type
|
|
6610
|
-
}).then((res) => {
|
|
6611
|
-
if (res.status === 200) {
|
|
6612
|
-
return res.data;
|
|
6470
|
+
}
|
|
6471
|
+
function trackPointer(event) {
|
|
6472
|
+
let position = pointerPositions[event.pointerId];
|
|
6473
|
+
if (position === void 0) {
|
|
6474
|
+
position = new Vector23();
|
|
6475
|
+
pointerPositions[event.pointerId] = position;
|
|
6613
6476
|
}
|
|
6614
|
-
|
|
6615
|
-
}
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
}
|
|
6626
|
-
static getMcHeadsSkinUrl(uuid) {
|
|
6627
|
-
return "https://mc-heads.net/skin/" + uuid;
|
|
6628
|
-
}
|
|
6629
|
-
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6630
|
-
return "https://mineskin.org/skin/player/" + uuid;
|
|
6631
|
-
}
|
|
6632
|
-
static getSkinProxySkinUrl(uuid) {
|
|
6633
|
-
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6477
|
+
position.set(event.pageX, event.pageY);
|
|
6478
|
+
}
|
|
6479
|
+
function getSecondPointerPosition(event) {
|
|
6480
|
+
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
6481
|
+
return pointerPositions[pointer.pointerId];
|
|
6482
|
+
}
|
|
6483
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6484
|
+
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6485
|
+
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6486
|
+
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6487
|
+
this.update();
|
|
6634
6488
|
}
|
|
6635
|
-
|
|
6636
|
-
|
|
6489
|
+
};
|
|
6490
|
+
var MapControls = class extends OrbitControls {
|
|
6491
|
+
constructor(object, domElement) {
|
|
6492
|
+
super(object, domElement);
|
|
6493
|
+
this.screenSpacePanning = false;
|
|
6494
|
+
this.mouseButtons.LEFT = MOUSE.PAN;
|
|
6495
|
+
this.mouseButtons.RIGHT = MOUSE.ROTATE;
|
|
6496
|
+
this.touches.ONE = TOUCH.PAN;
|
|
6497
|
+
this.touches.TWO = TOUCH.DOLLY_ROTATE;
|
|
6637
6498
|
}
|
|
6638
|
-
//</editor-fold>
|
|
6639
6499
|
};
|
|
6640
6500
|
|
|
6641
6501
|
// src/world/Chunk.ts
|
|
@@ -6752,7 +6612,7 @@ var MineRenderWorld = class {
|
|
|
6752
6612
|
};
|
|
6753
6613
|
|
|
6754
6614
|
// src/world/Chunk.ts
|
|
6755
|
-
var
|
|
6615
|
+
var p12 = prefix("Chunk");
|
|
6756
6616
|
var Chunk = class _Chunk {
|
|
6757
6617
|
constructor(scene, x, y, z) {
|
|
6758
6618
|
this._blocks = [];
|
|
@@ -6804,7 +6664,7 @@ var Chunk = class _Chunk {
|
|
|
6804
6664
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
6805
6665
|
const current = this._blocks[index];
|
|
6806
6666
|
if (typeof current !== "undefined") {
|
|
6807
|
-
console.debug(
|
|
6667
|
+
console.debug(p12, "deleting existing block at", pos, worldPos, index);
|
|
6808
6668
|
current.object.removeFromScene();
|
|
6809
6669
|
delete this._blocks[index];
|
|
6810
6670
|
}
|
|
@@ -6870,7 +6730,6 @@ export {
|
|
|
6870
6730
|
AXES,
|
|
6871
6731
|
ArchiveAssetSource,
|
|
6872
6732
|
AssetKey,
|
|
6873
|
-
AssetLoadError,
|
|
6874
6733
|
AssetLoader,
|
|
6875
6734
|
AssetParser,
|
|
6876
6735
|
AssetSource,
|
|
@@ -6928,7 +6787,6 @@ export {
|
|
|
6928
6787
|
OrbitControls,
|
|
6929
6788
|
PersistentCache,
|
|
6930
6789
|
Renderer,
|
|
6931
|
-
RequestError,
|
|
6932
6790
|
Requests,
|
|
6933
6791
|
SKIN_PARTS,
|
|
6934
6792
|
SceneInspector,
|