minerender 2.1.0-alpha.2 → 2.1.0-alpha.20
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 +2 -0
- package/dist/browser/index.d.mts +205 -141
- package/dist/browser/index.d.ts +205 -141
- package/dist/browser/index.js +1893 -1644
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1901 -1652
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +3679 -5020
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +204 -140
- package/dist/node/index.d.ts +204 -140
- package/dist/node/index.js +1815 -1497
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1569 -1253
- package/dist/node/index.mjs.map +1 -1
- package/package.json +7 -9
package/dist/browser/index.js
CHANGED
|
@@ -28,14 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
mod
|
|
29
29
|
));
|
|
30
30
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
32
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
33
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
34
|
-
if (decorator = decorators[i])
|
|
35
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
36
|
-
if (kind && result) __defProp(target, key, result);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
31
|
|
|
40
32
|
// ../../node_modules/ts-deepmerge/dist/index.js
|
|
41
33
|
var require_dist = __commonJS({
|
|
@@ -45,8 +37,8 @@ var require_dist = __commonJS({
|
|
|
45
37
|
__assign = Object.assign || function(t) {
|
|
46
38
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
47
39
|
s = arguments[i];
|
|
48
|
-
for (var
|
|
49
|
-
t[
|
|
40
|
+
for (var p12 in s) if (Object.prototype.hasOwnProperty.call(s, p12))
|
|
41
|
+
t[p12] = s[p12];
|
|
50
42
|
}
|
|
51
43
|
return t;
|
|
52
44
|
};
|
|
@@ -90,7 +82,7 @@ var require_dist = __commonJS({
|
|
|
90
82
|
return false;
|
|
91
83
|
};
|
|
92
84
|
var PROTECTED_KEYS = ["__proto__"];
|
|
93
|
-
var
|
|
85
|
+
var merge10 = function() {
|
|
94
86
|
var objects = [];
|
|
95
87
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
96
88
|
objects[_i] = arguments[_i];
|
|
@@ -101,9 +93,9 @@ var require_dist = __commonJS({
|
|
|
101
93
|
return;
|
|
102
94
|
}
|
|
103
95
|
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
104
|
-
result[key] =
|
|
96
|
+
result[key] = merge10.options.mergeArrays ? Array.from(new Set(result[key].concat(current[key]))) : current[key];
|
|
105
97
|
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
106
|
-
result[key] =
|
|
98
|
+
result[key] = merge10(result[key], current[key]);
|
|
107
99
|
} else {
|
|
108
100
|
result[key] = current[key];
|
|
109
101
|
}
|
|
@@ -114,18 +106,18 @@ var require_dist = __commonJS({
|
|
|
114
106
|
var defaultOptions = {
|
|
115
107
|
mergeArrays: true
|
|
116
108
|
};
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
merge10.options = defaultOptions;
|
|
110
|
+
merge10.withOptions = function(options) {
|
|
119
111
|
var objects = [];
|
|
120
112
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
121
113
|
objects[_i - 1] = arguments[_i];
|
|
122
114
|
}
|
|
123
|
-
|
|
124
|
-
var result =
|
|
125
|
-
|
|
115
|
+
merge10.options = __assign({ mergeArrays: true }, options);
|
|
116
|
+
var result = merge10.apply(void 0, __spreadArray([], __read(objects), false));
|
|
117
|
+
merge10.options = defaultOptions;
|
|
126
118
|
return result;
|
|
127
119
|
};
|
|
128
|
-
exports.default =
|
|
120
|
+
exports.default = merge10;
|
|
129
121
|
}
|
|
130
122
|
});
|
|
131
123
|
|
|
@@ -135,6 +127,7 @@ __export(index_browser_exports, {
|
|
|
135
127
|
AXES: () => AXES,
|
|
136
128
|
ArchiveAssetSource: () => ArchiveAssetSource,
|
|
137
129
|
AssetKey: () => AssetKey,
|
|
130
|
+
AssetLoadError: () => AssetLoadError,
|
|
138
131
|
AssetLoader: () => AssetLoader,
|
|
139
132
|
AssetParser: () => AssetParser,
|
|
140
133
|
AssetSource: () => AssetSource,
|
|
@@ -192,6 +185,7 @@ __export(index_browser_exports, {
|
|
|
192
185
|
OrbitControls: () => OrbitControls,
|
|
193
186
|
PersistentCache: () => PersistentCache,
|
|
194
187
|
Renderer: () => Renderer,
|
|
188
|
+
RequestError: () => RequestError,
|
|
195
189
|
Requests: () => Requests,
|
|
196
190
|
SKIN_PARTS: () => SKIN_PARTS,
|
|
197
191
|
SceneInspector: () => SceneInspector,
|
|
@@ -308,17 +302,20 @@ var _PersistentCache = class _PersistentCache {
|
|
|
308
302
|
static open(name) {
|
|
309
303
|
return Env.provider.openCache(name, _PersistentCache.VERSION);
|
|
310
304
|
}
|
|
305
|
+
/** Loads a missing entry and stores only non-nullish results. */
|
|
311
306
|
async getOrLoad(key, loader) {
|
|
312
307
|
let v = await this.get(key);
|
|
313
308
|
if (typeof v === "undefined" || v === null) {
|
|
314
309
|
v = await loader(key);
|
|
315
|
-
|
|
310
|
+
if (typeof v !== "undefined" && v !== null) {
|
|
311
|
+
await this.put(key, v);
|
|
312
|
+
}
|
|
316
313
|
}
|
|
317
314
|
return v;
|
|
318
315
|
}
|
|
319
316
|
};
|
|
320
317
|
/** Bump to invalidate every persisted entry. */
|
|
321
|
-
_PersistentCache.VERSION =
|
|
318
|
+
_PersistentCache.VERSION = 2;
|
|
322
319
|
var PersistentCache = _PersistentCache;
|
|
323
320
|
|
|
324
321
|
// src/env/browser/BrowserCache.ts
|
|
@@ -419,7 +416,8 @@ var BrowserEnv = class {
|
|
|
419
416
|
}
|
|
420
417
|
openCache(name, version) {
|
|
421
418
|
return new BrowserCache(import_localforage.default.createInstance({
|
|
422
|
-
|
|
419
|
+
// IndexedDB schema upgrades retain records; each cache generation needs its own database.
|
|
420
|
+
name: name + version,
|
|
423
421
|
version
|
|
424
422
|
}));
|
|
425
423
|
}
|
|
@@ -436,7 +434,7 @@ registerBrowserEnv();
|
|
|
436
434
|
// src/Axis.ts
|
|
437
435
|
var import_three = require("three");
|
|
438
436
|
var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
439
|
-
Axis3["X"] = "
|
|
437
|
+
Axis3["X"] = "x";
|
|
440
438
|
Axis3["Y"] = "y";
|
|
441
439
|
Axis3["Z"] = "z";
|
|
442
440
|
return Axis3;
|
|
@@ -444,7 +442,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
|
444
442
|
var AXES = Object.values(Axis);
|
|
445
443
|
function axisToVec3(axis) {
|
|
446
444
|
switch (axis) {
|
|
447
|
-
case "
|
|
445
|
+
case "x" /* X */:
|
|
448
446
|
return new import_three.Vector3(1, 0, 0);
|
|
449
447
|
case "y" /* Y */:
|
|
450
448
|
return new import_three.Vector3(0, 1, 0);
|
|
@@ -547,7 +545,10 @@ function serializeMeshKey(key) {
|
|
|
547
545
|
// src/cache/Caching.ts
|
|
548
546
|
var import_loading_cache = require("@inventivetalent/loading-cache");
|
|
549
547
|
var import_time = require("@inventivetalent/time");
|
|
550
|
-
var
|
|
548
|
+
var _Caching = class _Caching {
|
|
549
|
+
static createAssetCache() {
|
|
550
|
+
return import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
551
|
+
}
|
|
551
552
|
/** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
|
|
552
553
|
static get all() {
|
|
553
554
|
return [
|
|
@@ -564,7 +565,10 @@ var Caching = class {
|
|
|
564
565
|
this.rawModelCache,
|
|
565
566
|
this.mergedModelCache,
|
|
566
567
|
this.modelTextureAtlasCache,
|
|
567
|
-
this.blockStateCache
|
|
568
|
+
this.blockStateCache,
|
|
569
|
+
this.listAssetCache,
|
|
570
|
+
this.defaultBlockStatesCache,
|
|
571
|
+
this.entityModelsCache
|
|
568
572
|
];
|
|
569
573
|
}
|
|
570
574
|
static clear() {
|
|
@@ -575,8 +579,8 @@ var Caching = class {
|
|
|
575
579
|
/**
|
|
576
580
|
* Clears every cache and stops its expiry timer.
|
|
577
581
|
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
582
|
+
* Expiry timers are unref'd in Node, so idle processes can exit without this cleanup.
|
|
583
|
+
* Use {@link shutdown} to also stop requests and the shared Ticker.
|
|
580
584
|
*/
|
|
581
585
|
static end() {
|
|
582
586
|
for (const cache of this.all) {
|
|
@@ -590,20 +594,24 @@ var Caching = class {
|
|
|
590
594
|
};
|
|
591
595
|
}
|
|
592
596
|
};
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
597
|
+
_Caching.rawImageCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(5)).buildAsync();
|
|
598
|
+
_Caching.imageDataCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(10)).buildAsync();
|
|
599
|
+
_Caching.canvasImageDataCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(10)).buildAsync();
|
|
600
|
+
_Caching.wrappedImageCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(10)).buildAsync();
|
|
601
|
+
_Caching.boxGeometryCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(20)).build();
|
|
602
|
+
_Caching.textureCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).build();
|
|
603
|
+
_Caching.materialCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).build();
|
|
604
|
+
_Caching.boxMeshCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).build();
|
|
605
|
+
_Caching.textureAssetCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
606
|
+
_Caching.textureMetaCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
607
|
+
_Caching.rawModelCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
608
|
+
_Caching.mergedModelCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
609
|
+
_Caching.modelTextureAtlasCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
610
|
+
_Caching.blockStateCache = import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
611
|
+
_Caching.listAssetCache = _Caching.createAssetCache();
|
|
612
|
+
_Caching.defaultBlockStatesCache = _Caching.createAssetCache();
|
|
613
|
+
_Caching.entityModelsCache = _Caching.createAssetCache();
|
|
614
|
+
var Caching = _Caching;
|
|
607
615
|
|
|
608
616
|
// src/Geometries.ts
|
|
609
617
|
var Geometries = class _Geometries {
|
|
@@ -624,13 +632,14 @@ var Geometries = class _Geometries {
|
|
|
624
632
|
};
|
|
625
633
|
|
|
626
634
|
// src/Materials.ts
|
|
627
|
-
var
|
|
635
|
+
var import_three5 = require("three");
|
|
628
636
|
|
|
629
637
|
// src/texture/Textures.ts
|
|
630
|
-
var
|
|
638
|
+
var import_three4 = require("three");
|
|
631
639
|
|
|
632
640
|
// src/texture/TextureLoader.ts
|
|
633
|
-
var
|
|
641
|
+
var import_three3 = require("three");
|
|
642
|
+
var THREE = __toESM(require("three"));
|
|
634
643
|
|
|
635
644
|
// src/canvas/CanvasCompat.ts
|
|
636
645
|
function createImage(width, height) {
|
|
@@ -641,9 +650,7 @@ function createCanvas(width, height) {
|
|
|
641
650
|
}
|
|
642
651
|
|
|
643
652
|
// src/request/Requests.ts
|
|
644
|
-
var import_axios = __toESM(require("axios"));
|
|
645
653
|
var import_jobqu = require("jobqu");
|
|
646
|
-
var import_time2 = require("@inventivetalent/time");
|
|
647
654
|
|
|
648
655
|
// src/util/log.ts
|
|
649
656
|
var Reset = "\x1B[0m";
|
|
@@ -653,198 +660,170 @@ function prefix(prefix2) {
|
|
|
653
660
|
return `${FgGreen}MR${BgBlack}${prefix2 ?? ""}${Reset}`;
|
|
654
661
|
}
|
|
655
662
|
|
|
656
|
-
// src/
|
|
657
|
-
var
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
this.
|
|
662
|
-
this.
|
|
663
|
-
|
|
664
|
-
submit(task) {
|
|
665
|
-
this.queue.push(task);
|
|
666
|
-
}
|
|
667
|
-
run() {
|
|
668
|
-
for (let i = 0; i < this.batch; i++) {
|
|
669
|
-
this.runNext();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
runNext() {
|
|
673
|
-
let next = this.queue.shift();
|
|
674
|
-
if (next) next();
|
|
663
|
+
// src/request/Requests.ts
|
|
664
|
+
var p = prefix("Requests");
|
|
665
|
+
var RequestError = class extends Error {
|
|
666
|
+
constructor(message, response, cause) {
|
|
667
|
+
super(message);
|
|
668
|
+
this.response = response;
|
|
669
|
+
this.cause = cause;
|
|
670
|
+
this.name = "RequestError";
|
|
675
671
|
}
|
|
676
672
|
};
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
673
|
+
async function fetchRequest(config, defaultBaseURL) {
|
|
674
|
+
const { url, baseURL = defaultBaseURL, timeout = 5e3, responseType = "json", signal, ...options } = config;
|
|
675
|
+
const target = baseURL && !/^([a-z][a-z\d+.-]*:|\/\/)/i.test(url) ? `${baseURL.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}` : url;
|
|
676
|
+
const headers = new Headers(options.headers);
|
|
677
|
+
if (typeof window === "undefined" && !headers.has("User-Agent")) {
|
|
678
|
+
headers.set("User-Agent", "MineRender");
|
|
679
|
+
}
|
|
680
|
+
const attemptSignal = AbortSignal.any([
|
|
681
|
+
...signal ? [signal] : [],
|
|
682
|
+
...timeout === 0 ? [] : [AbortSignal.timeout(timeout)]
|
|
683
|
+
]);
|
|
684
|
+
const request = new Request(target, { ...options, headers, signal: attemptSignal });
|
|
685
|
+
attemptSignal.throwIfAborted();
|
|
686
|
+
try {
|
|
687
|
+
const response = await fetch(request);
|
|
688
|
+
const result = {
|
|
689
|
+
data: void 0,
|
|
690
|
+
status: response.status,
|
|
691
|
+
statusText: response.statusText,
|
|
692
|
+
headers: response.headers,
|
|
693
|
+
url: response.url
|
|
694
|
+
};
|
|
695
|
+
if (!response.ok) {
|
|
696
|
+
await response.body?.cancel().catch(() => {
|
|
697
|
+
});
|
|
698
|
+
throw new RequestError(`Request failed with status ${response.status}`, result);
|
|
701
699
|
}
|
|
700
|
+
const emptyBody = request.method === "HEAD" || response.status === 204 || response.status === 205;
|
|
701
|
+
const data = responseType === "arraybuffer" ? await response.arrayBuffer() : emptyBody || response.body === null ? void 0 : await response.json();
|
|
702
|
+
return { ...result, data };
|
|
703
|
+
} catch (error) {
|
|
704
|
+
attemptSignal.throwIfAborted();
|
|
705
|
+
if (/^https?:/.test(request.url) && request.redirect !== "error" && error instanceof TypeError) {
|
|
706
|
+
throw new RequestError("Network request failed", void 0, error);
|
|
707
|
+
}
|
|
708
|
+
throw error;
|
|
702
709
|
}
|
|
703
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
704
|
-
}
|
|
705
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
706
|
-
const origin = new import_three3.Vector3(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
707
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
708
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
709
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
710
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
711
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
712
710
|
}
|
|
713
|
-
function
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
711
|
+
async function abortable(promise, signal) {
|
|
712
|
+
if (!signal) return promise;
|
|
713
|
+
let abort;
|
|
714
|
+
const cancelled = new Promise((_, reject) => {
|
|
715
|
+
abort = () => reject(signal.reason);
|
|
716
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
717
|
+
if (signal.aborted) abort();
|
|
718
|
+
});
|
|
719
|
+
try {
|
|
720
|
+
return await Promise.race([promise, cancelled]);
|
|
721
|
+
} finally {
|
|
722
|
+
signal.removeEventListener("abort", abort);
|
|
724
723
|
}
|
|
725
724
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
let axes = new import_three3.AxesHelper(1);
|
|
735
|
-
obj.add(axes);
|
|
736
|
-
}
|
|
737
|
-
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
738
|
-
let boxGeo = new import_three3.BoxGeometry(16, 16, 16, 1, 1, 1);
|
|
739
|
-
let wireGeo = new import_three3.EdgesGeometry(boxGeo);
|
|
740
|
-
let wireMat = new import_three3.LineBasicMaterial({ color, linewidth: w });
|
|
741
|
-
let wireframe = new import_three3.LineSegments(wireGeo, wireMat);
|
|
742
|
-
obj.add(wireframe);
|
|
743
|
-
let axes = new import_three3.AxesHelper(1);
|
|
744
|
-
obj.add(axes);
|
|
745
|
-
}
|
|
746
|
-
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
747
|
-
let wireGeo = new import_three3.EdgesGeometry(geo);
|
|
748
|
-
let wireMat = new import_three3.LineBasicMaterial({ color, linewidth: w });
|
|
749
|
-
let wireframe = new import_three3.LineSegments(wireGeo, wireMat);
|
|
750
|
-
mesh.add(wireframe);
|
|
751
|
-
let axes = new import_three3.AxesHelper(1);
|
|
752
|
-
mesh.add(axes);
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// src/util/performance.ts
|
|
756
|
-
function captureException(e, ...extra) {
|
|
757
|
-
console.error(e, extra);
|
|
758
|
-
}
|
|
759
|
-
function timingStart(marker) {
|
|
760
|
-
console.time(marker);
|
|
761
|
-
}
|
|
762
|
-
function timingEnd(marker) {
|
|
763
|
-
console.timeEnd(marker);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// src/util/three.ts
|
|
767
|
-
function isObject3D(obj) {
|
|
768
|
-
return obj.isObject3D;
|
|
769
|
-
}
|
|
770
|
-
function isMesh(obj) {
|
|
771
|
-
return obj.isMesh;
|
|
772
|
-
}
|
|
773
|
-
function isInstancedMesh(obj) {
|
|
774
|
-
return obj.isInstancedMesh;
|
|
775
|
-
}
|
|
776
|
-
function isPerspectiveCamera(obj) {
|
|
777
|
-
return obj.isPerspectiveCamera;
|
|
778
|
-
}
|
|
779
|
-
function isOrthographicCamera(obj) {
|
|
780
|
-
return obj.isOrthographicCamera;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
// src/request/Requests.ts
|
|
784
|
-
var p = prefix("Requests");
|
|
785
|
-
if (typeof window === "undefined") {
|
|
786
|
-
import_axios.default.defaults.headers["User-Agent"] = "MineRender";
|
|
787
|
-
}
|
|
788
|
-
var _Requests = class _Requests {
|
|
789
|
-
static genericRequest(request) {
|
|
790
|
-
return this.genericQueue.add(request).catch(async (e) => {
|
|
791
|
-
console.debug(p, "generic catch", e.code, e);
|
|
792
|
-
if (this.shouldRetry(e, request)) {
|
|
793
|
-
await sleep(100);
|
|
794
|
-
return this.genericRequest(request);
|
|
795
|
-
}
|
|
796
|
-
throw e;
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
static mcAssetRequest(request) {
|
|
800
|
-
return this.mcAssetRequestQueue.add(request).catch((e) => {
|
|
801
|
-
console.debug(p, "mcAssetRequest catch", e.code, e);
|
|
802
|
-
throw e;
|
|
803
|
-
});
|
|
725
|
+
var RequestQueue = class {
|
|
726
|
+
constructor() {
|
|
727
|
+
this.pendingRequests = 0;
|
|
728
|
+
this.stopped = new AbortController();
|
|
729
|
+
this.queue = new import_jobqu.JobQueue(
|
|
730
|
+
(request) => fetchRequest(request, this.baseURL),
|
|
731
|
+
{ interval: 10, maxPerRun: 1, maxActive: 8 }
|
|
732
|
+
);
|
|
804
733
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
734
|
+
async request(request) {
|
|
735
|
+
this.pendingRequests++;
|
|
736
|
+
const signal = request.signal;
|
|
737
|
+
try {
|
|
738
|
+
for (let retries = 0; ; retries++) {
|
|
739
|
+
signal?.throwIfAborted();
|
|
740
|
+
try {
|
|
741
|
+
return await abortable(this.queue.add(request), signal);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
console.debug(p, "Request failed", error);
|
|
744
|
+
const delay = this.retryDelay(error, request, retries);
|
|
745
|
+
if (delay === void 0) {
|
|
746
|
+
throw error;
|
|
812
747
|
}
|
|
813
|
-
|
|
814
|
-
request["minerenderRetry"] = 3;
|
|
815
|
-
return true;
|
|
748
|
+
await this.waitForRetry(delay, signal);
|
|
816
749
|
}
|
|
817
750
|
}
|
|
751
|
+
} finally {
|
|
752
|
+
if (signal?.aborted) {
|
|
753
|
+
this.queue.remove(request);
|
|
754
|
+
}
|
|
755
|
+
this.pendingRequests--;
|
|
818
756
|
}
|
|
819
|
-
|
|
757
|
+
}
|
|
758
|
+
retryDelay(error, request, retries) {
|
|
759
|
+
if (this.stopped.signal.aborted || retries >= 3 || (request.method ?? "get").toLowerCase() !== "get" || request.signal?.aborted) {
|
|
760
|
+
return void 0;
|
|
761
|
+
}
|
|
762
|
+
if (error instanceof RequestError) {
|
|
763
|
+
const status = error.response?.status;
|
|
764
|
+
if (status !== void 0 && status !== 408 && status !== 429 && !(status >= 500 && status < 600)) return void 0;
|
|
765
|
+
} else if (!(error instanceof DOMException && error.name === "TimeoutError")) {
|
|
766
|
+
return void 0;
|
|
767
|
+
}
|
|
768
|
+
let delay = 100 * 2 ** retries;
|
|
769
|
+
const retryAfter = error instanceof RequestError ? error.response?.headers.get("Retry-After") : void 0;
|
|
770
|
+
if (retryAfter !== void 0 && retryAfter !== null) {
|
|
771
|
+
const seconds = Number(retryAfter);
|
|
772
|
+
if (!retryAfter.trim() || !Number.isFinite(seconds) || seconds < 0) {
|
|
773
|
+
return void 0;
|
|
774
|
+
}
|
|
775
|
+
delay = Math.max(delay, seconds * 1e3);
|
|
776
|
+
}
|
|
777
|
+
return delay;
|
|
778
|
+
}
|
|
779
|
+
async waitForRetry(delay, signal) {
|
|
780
|
+
let timer;
|
|
781
|
+
const waiting = new Promise((resolve) => {
|
|
782
|
+
timer = setTimeout(resolve, delay);
|
|
783
|
+
});
|
|
784
|
+
try {
|
|
785
|
+
await abortable(waiting, AbortSignal.any([this.stopped.signal, ...signal ? [signal] : []]));
|
|
786
|
+
} finally {
|
|
787
|
+
clearTimeout(timer);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
get pendingSize() {
|
|
791
|
+
return this.pendingRequests;
|
|
792
|
+
}
|
|
793
|
+
end() {
|
|
794
|
+
this.queue.end();
|
|
795
|
+
this.stopped.abort(new import_jobqu.JobCancelledError("ended"));
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
var Requests = class {
|
|
799
|
+
static genericRequest(request) {
|
|
800
|
+
return this.genericQueue.request(request);
|
|
801
|
+
}
|
|
802
|
+
static mcAssetRequest(request) {
|
|
803
|
+
return this.mcAssetRequestQueue.request(request);
|
|
820
804
|
}
|
|
821
805
|
static setMcAssetRoot(root) {
|
|
822
|
-
this.
|
|
806
|
+
this.mcAssetRequestQueue.baseURL = root;
|
|
823
807
|
}
|
|
808
|
+
/** Counts unsettled calls, including retry delays and requests still running after shutdown. */
|
|
824
809
|
static get queueSizes() {
|
|
825
810
|
return {
|
|
826
|
-
generic: this.genericQueue.
|
|
827
|
-
mcAsset: this.mcAssetRequestQueue.
|
|
811
|
+
generic: this.genericQueue.pendingSize,
|
|
812
|
+
mcAsset: this.mcAssetRequestQueue.pendingSize
|
|
828
813
|
};
|
|
829
814
|
}
|
|
830
815
|
/**
|
|
831
|
-
*
|
|
832
|
-
*
|
|
816
|
+
* Permanently stops both queues and rejects waiting, retrying, and future requests.
|
|
817
|
+
* Requests already running can finish. Idle queues hold no timer, so Node can exit without
|
|
818
|
+
* this cleanup. See {@link shutdown}.
|
|
833
819
|
*/
|
|
834
820
|
static end() {
|
|
835
821
|
this.genericQueue.end();
|
|
836
822
|
this.mcAssetRequestQueue.end();
|
|
837
823
|
}
|
|
838
824
|
};
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
});
|
|
842
|
-
_Requests.mcAssetInstance = import_axios.default.create({
|
|
843
|
-
timeout: 5e3
|
|
844
|
-
});
|
|
845
|
-
_Requests.genericQueue = new import_jobqu.JobQueue((request) => _Requests.axiosInstance.request(request), import_time2.Time.millis(10), 1);
|
|
846
|
-
_Requests.mcAssetRequestQueue = new import_jobqu.JobQueue((request) => _Requests.mcAssetInstance.request(request), import_time2.Time.millis(10), 1);
|
|
847
|
-
var Requests = _Requests;
|
|
825
|
+
Requests.genericQueue = new RequestQueue();
|
|
826
|
+
Requests.mcAssetRequestQueue = new RequestQueue();
|
|
848
827
|
|
|
849
828
|
// src/WrappedImage.ts
|
|
850
829
|
var WrappedImage = class {
|
|
@@ -882,10 +861,10 @@ var WrappedImage = class {
|
|
|
882
861
|
return this.animated ? this.width : this.height;
|
|
883
862
|
}
|
|
884
863
|
get frameCount() {
|
|
885
|
-
return this.height / this.
|
|
864
|
+
return this.height / this.frameHeight;
|
|
886
865
|
}
|
|
887
866
|
getFrameY(frame) {
|
|
888
|
-
return this.
|
|
867
|
+
return this.frameHeight * Math.max(0, Math.min(this.frameCount - 1, frame));
|
|
889
868
|
}
|
|
890
869
|
getSectionData(sx, sy, sw, sh) {
|
|
891
870
|
return this.dta.data.getImageData(sx, sy, sw, sh);
|
|
@@ -895,7 +874,7 @@ var WrappedImage = class {
|
|
|
895
874
|
}
|
|
896
875
|
getFrameSectionData(frame) {
|
|
897
876
|
const y = this.getFrameY(frame);
|
|
898
|
-
return this.getSectionData(0, y, this.
|
|
877
|
+
return this.getSectionData(0, y, this.frameWidth, this.frameHeight);
|
|
899
878
|
}
|
|
900
879
|
};
|
|
901
880
|
|
|
@@ -909,29 +888,41 @@ var ImageLoader = class _ImageLoader {
|
|
|
909
888
|
static async loadAsync(src) {
|
|
910
889
|
return new Promise((resolve, reject) => {
|
|
911
890
|
const image = this._createImage();
|
|
912
|
-
image.src = src;
|
|
913
891
|
image.onload = () => resolve(image);
|
|
914
|
-
image.onerror = (err) => reject(err);
|
|
892
|
+
image.onerror = (err) => reject(err instanceof Error ? err : new Error("Failed to decode image"));
|
|
893
|
+
image.src = src;
|
|
915
894
|
});
|
|
916
895
|
}
|
|
917
896
|
static loadElement(src, onload, onerr) {
|
|
918
897
|
const image = this._createImage();
|
|
919
|
-
image.src = src;
|
|
920
898
|
if (onload)
|
|
921
899
|
image.onload = onload;
|
|
922
900
|
if (onerr)
|
|
923
901
|
image.onerror = onerr;
|
|
902
|
+
image.src = src;
|
|
924
903
|
return image;
|
|
925
904
|
}
|
|
926
905
|
static async loadData(src) {
|
|
927
906
|
console.debug(p2, "loadData", src);
|
|
928
|
-
|
|
907
|
+
const image = await this.loadCanvasData(src);
|
|
908
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
929
909
|
}
|
|
930
910
|
static async loadCanvasData(src) {
|
|
931
|
-
|
|
911
|
+
const keyStr = serializeImageKey({ src });
|
|
912
|
+
const info = this.getInfo(src);
|
|
913
|
+
const cached = Caching.rawImageCache.getIfPresent(keyStr);
|
|
914
|
+
try {
|
|
915
|
+
return await this.infoToCanvasData(await info);
|
|
916
|
+
} catch (err) {
|
|
917
|
+
if (cached && Caching.rawImageCache.getIfPresent(keyStr) === cached) {
|
|
918
|
+
Caching.rawImageCache.invalidate(keyStr);
|
|
919
|
+
}
|
|
920
|
+
throw err;
|
|
921
|
+
}
|
|
932
922
|
}
|
|
933
923
|
static async infoToCanvasData(info) {
|
|
934
|
-
const
|
|
924
|
+
const type = info.type === "jpg" ? "jpeg" : info.type ?? "png";
|
|
925
|
+
const image = await _ImageLoader.loadAsync(`data:image/${type};base64,${info.data.toString("base64")}`);
|
|
935
926
|
const canvas = createCanvas(info.width, info.height);
|
|
936
927
|
const context = canvas.getContext("2d");
|
|
937
928
|
context.drawImage(image, 0, 0);
|
|
@@ -942,11 +933,8 @@ var ImageLoader = class _ImageLoader {
|
|
|
942
933
|
};
|
|
943
934
|
}
|
|
944
935
|
static async infoToData(info) {
|
|
945
|
-
const image = await
|
|
946
|
-
|
|
947
|
-
const context = canvas.getContext("2d");
|
|
948
|
-
context.drawImage(image, 0, 0);
|
|
949
|
-
return context.getImageData(0, 0, canvas.width, canvas.height);
|
|
936
|
+
const image = await this.infoToCanvasData(info);
|
|
937
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
950
938
|
}
|
|
951
939
|
static async getData(src) {
|
|
952
940
|
const keyStr = serializeImageKey({ src });
|
|
@@ -961,38 +949,25 @@ var ImageLoader = class _ImageLoader {
|
|
|
961
949
|
});
|
|
962
950
|
}
|
|
963
951
|
static async processResponse(response) {
|
|
964
|
-
const src = response.
|
|
952
|
+
const src = response.url;
|
|
965
953
|
const data = import_buffer.Buffer.from(response.data);
|
|
966
954
|
const { width, height, type } = Env.provider.imageSize(data);
|
|
955
|
+
if (!width || !height) {
|
|
956
|
+
throw new Error("Invalid or unsupported image dimensions");
|
|
957
|
+
}
|
|
967
958
|
return {
|
|
968
959
|
src,
|
|
969
|
-
width
|
|
970
|
-
height
|
|
960
|
+
width,
|
|
961
|
+
height,
|
|
971
962
|
type,
|
|
972
963
|
data
|
|
973
964
|
};
|
|
974
965
|
}
|
|
975
966
|
static async loadInfo(src) {
|
|
976
|
-
if (src.startsWith("data:image/png;base64")) {
|
|
977
|
-
return this.processResponse({
|
|
978
|
-
config: {
|
|
979
|
-
url: src
|
|
980
|
-
},
|
|
981
|
-
data: import_buffer.Buffer.from(src.substr("data:image/png;base64,".length), "base64")
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
967
|
return Requests.genericRequest({
|
|
985
968
|
url: src,
|
|
986
969
|
responseType: "arraybuffer"
|
|
987
|
-
}).then(this.processResponse)
|
|
988
|
-
return {
|
|
989
|
-
src,
|
|
990
|
-
width: 0,
|
|
991
|
-
height: 0,
|
|
992
|
-
type: void 0,
|
|
993
|
-
data: import_buffer.Buffer.from([0])
|
|
994
|
-
};
|
|
995
|
-
});
|
|
970
|
+
}).then(this.processResponse);
|
|
996
971
|
}
|
|
997
972
|
static async getInfo(src) {
|
|
998
973
|
const keyStr = serializeImageKey({ src });
|
|
@@ -1014,38 +989,50 @@ var ImageLoader = class _ImageLoader {
|
|
|
1014
989
|
|
|
1015
990
|
// src/texture/TextureLoader.ts
|
|
1016
991
|
var TextureLoader = class {
|
|
992
|
+
/** Reports whether image loading failed, so cached textures can be retried. */
|
|
993
|
+
static hasFailed(texture) {
|
|
994
|
+
return this.failedTextures.has(texture);
|
|
995
|
+
}
|
|
1017
996
|
static createTexture() {
|
|
1018
|
-
return new
|
|
997
|
+
return new import_three3.Texture();
|
|
1019
998
|
}
|
|
1020
|
-
static loadInBackground(src, format =
|
|
999
|
+
static loadInBackground(src, format = import_three3.RGBAFormat, rotation = 0) {
|
|
1021
1000
|
const texture = this.createTexture();
|
|
1022
|
-
|
|
1023
|
-
image
|
|
1001
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
1002
|
+
const image = ImageLoader.loadElement(src, () => {
|
|
1024
1003
|
texture.needsUpdate = true;
|
|
1025
|
-
}
|
|
1004
|
+
}, (error) => {
|
|
1005
|
+
this.failedTextures.add(texture);
|
|
1006
|
+
console.warn("Failed to load texture", src, error);
|
|
1007
|
+
});
|
|
1026
1008
|
texture.image = image;
|
|
1027
1009
|
texture.format = format;
|
|
1028
1010
|
texture.rotation = rotation;
|
|
1029
1011
|
return Textures.initTextureProps(texture);
|
|
1030
1012
|
}
|
|
1031
|
-
static load(src, format =
|
|
1032
|
-
const texture = new
|
|
1013
|
+
static load(src, format = import_three3.RGBAFormat, rotation = 0) {
|
|
1014
|
+
const texture = new import_three3.Texture();
|
|
1015
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
1033
1016
|
ImageLoader.getData(src).then((image) => {
|
|
1034
|
-
texture.needsUpdate = true;
|
|
1035
1017
|
texture.image = image;
|
|
1018
|
+
texture.needsUpdate = true;
|
|
1019
|
+
}).catch((error) => {
|
|
1020
|
+
this.failedTextures.add(texture);
|
|
1021
|
+
console.warn("Failed to load texture", src, error);
|
|
1036
1022
|
});
|
|
1037
1023
|
texture.format = format;
|
|
1038
1024
|
texture.rotation = rotation;
|
|
1039
1025
|
return Textures.initTextureProps(texture);
|
|
1040
1026
|
}
|
|
1041
1027
|
};
|
|
1028
|
+
TextureLoader.failedTextures = /* @__PURE__ */ new WeakSet();
|
|
1042
1029
|
|
|
1043
1030
|
// src/texture/Textures.ts
|
|
1044
|
-
var
|
|
1031
|
+
var THREE2 = __toESM(require("three"));
|
|
1045
1032
|
var Textures = class _Textures {
|
|
1046
1033
|
static initTextureProps(texture) {
|
|
1047
|
-
texture.magFilter =
|
|
1048
|
-
texture.minFilter =
|
|
1034
|
+
texture.magFilter = THREE2.NearestFilter;
|
|
1035
|
+
texture.minFilter = THREE2.NearestFilter;
|
|
1049
1036
|
texture.anisotropy = 0;
|
|
1050
1037
|
return texture;
|
|
1051
1038
|
}
|
|
@@ -1053,13 +1040,19 @@ var Textures = class _Textures {
|
|
|
1053
1040
|
return TextureLoader.load(key.src, key.format, key.rotation);
|
|
1054
1041
|
}
|
|
1055
1042
|
static createAsset(key) {
|
|
1056
|
-
return new
|
|
1043
|
+
return new import_three4.Texture();
|
|
1057
1044
|
}
|
|
1058
1045
|
static createCanvasTexture(canvas) {
|
|
1059
|
-
|
|
1046
|
+
const texture = new import_three4.CanvasTexture(canvas);
|
|
1047
|
+
texture.colorSpace = THREE2.SRGBColorSpace;
|
|
1048
|
+
return this.initTextureProps(texture);
|
|
1060
1049
|
}
|
|
1061
1050
|
static getImage(key) {
|
|
1062
1051
|
const keyStr = serializeTextureKey(key);
|
|
1052
|
+
const cached = Caching.textureCache.peek(keyStr);
|
|
1053
|
+
if (cached && TextureLoader.hasFailed(cached)) {
|
|
1054
|
+
Caching.textureCache.invalidate(keyStr);
|
|
1055
|
+
}
|
|
1063
1056
|
return Caching.textureCache.get(keyStr, (k) => {
|
|
1064
1057
|
return _Textures.createImage(key);
|
|
1065
1058
|
});
|
|
@@ -1075,26 +1068,26 @@ var _Materials = class _Materials {
|
|
|
1075
1068
|
}
|
|
1076
1069
|
static createImage(key) {
|
|
1077
1070
|
const transparent = key.transparent || false;
|
|
1078
|
-
return new
|
|
1071
|
+
return new import_three5.MeshBasicMaterial({
|
|
1079
1072
|
map: Textures.getImage(key.texture),
|
|
1080
1073
|
transparent,
|
|
1081
|
-
side: transparent ?
|
|
1074
|
+
side: transparent ? import_three5.DoubleSide : import_three5.FrontSide,
|
|
1082
1075
|
alphaTest: 0.5
|
|
1083
1076
|
});
|
|
1084
1077
|
}
|
|
1085
1078
|
static createBasicCanvasMaterial(canvas, transparent = false, shade = false) {
|
|
1086
1079
|
if (shade) {
|
|
1087
|
-
return new
|
|
1080
|
+
return new import_three5.MeshStandardMaterial({
|
|
1088
1081
|
map: Textures.createCanvasTexture(canvas),
|
|
1089
1082
|
transparent,
|
|
1090
|
-
side: transparent ?
|
|
1083
|
+
side: transparent ? import_three5.DoubleSide : import_three5.FrontSide,
|
|
1091
1084
|
alphaTest: 0.5
|
|
1092
1085
|
});
|
|
1093
1086
|
}
|
|
1094
|
-
return new
|
|
1087
|
+
return new import_three5.MeshBasicMaterial({
|
|
1095
1088
|
map: Textures.createCanvasTexture(canvas),
|
|
1096
1089
|
transparent,
|
|
1097
|
-
side: transparent ?
|
|
1090
|
+
side: transparent ? import_three5.DoubleSide : import_three5.FrontSide,
|
|
1098
1091
|
alphaTest: 0.5
|
|
1099
1092
|
});
|
|
1100
1093
|
}
|
|
@@ -1103,6 +1096,7 @@ var _Materials = class _Materials {
|
|
|
1103
1096
|
uniform bool SHADE;
|
|
1104
1097
|
|
|
1105
1098
|
varying vec2 vUv;
|
|
1099
|
+
varying vec3 vTint;
|
|
1106
1100
|
varying float light;
|
|
1107
1101
|
varying float lift;
|
|
1108
1102
|
|
|
@@ -1115,7 +1109,11 @@ var _Materials = class _Materials {
|
|
|
1115
1109
|
|
|
1116
1110
|
if (SHADE) {
|
|
1117
1111
|
|
|
1118
|
-
|
|
1112
|
+
#ifdef USE_INSTANCING
|
|
1113
|
+
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
1114
|
+
#else
|
|
1115
|
+
vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
|
|
1116
|
+
#endif
|
|
1119
1117
|
|
|
1120
1118
|
float yLight = (1.0+N.y) * 0.5;
|
|
1121
1119
|
light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
|
|
@@ -1133,6 +1131,7 @@ var _Materials = class _Materials {
|
|
|
1133
1131
|
}
|
|
1134
1132
|
|
|
1135
1133
|
vUv = uv;
|
|
1134
|
+
vTint = color;
|
|
1136
1135
|
|
|
1137
1136
|
#ifdef USE_INSTANCING
|
|
1138
1137
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
|
|
@@ -1154,12 +1153,14 @@ var _Materials = class _Materials {
|
|
|
1154
1153
|
uniform float BRIGHTNESS;
|
|
1155
1154
|
|
|
1156
1155
|
varying vec2 vUv;
|
|
1156
|
+
varying vec3 vTint;
|
|
1157
1157
|
varying float light;
|
|
1158
1158
|
varying float lift;
|
|
1159
1159
|
|
|
1160
1160
|
void main(void)
|
|
1161
1161
|
{
|
|
1162
1162
|
vec4 color = texture2D(map, vUv);
|
|
1163
|
+
color.rgb *= vTint;
|
|
1163
1164
|
|
|
1164
1165
|
if (color.a < 0.01) discard;
|
|
1165
1166
|
|
|
@@ -1173,16 +1174,19 @@ var _Materials = class _Materials {
|
|
|
1173
1174
|
gl_FragColor = vec4(lift + color.rgb * light2, 1.0);
|
|
1174
1175
|
|
|
1175
1176
|
}
|
|
1177
|
+
|
|
1178
|
+
#include <tonemapping_fragment>
|
|
1179
|
+
#include <colorspace_fragment>
|
|
1176
1180
|
}
|
|
1177
1181
|
`;
|
|
1178
1182
|
try {
|
|
1179
|
-
return new
|
|
1183
|
+
return new import_three5.ShaderMaterial({
|
|
1180
1184
|
uniforms: {
|
|
1181
1185
|
SHADE: { value: true },
|
|
1182
1186
|
BRIGHTNESS: { value: 1 },
|
|
1183
1187
|
EMISSIVE: { value: false },
|
|
1184
1188
|
base: {
|
|
1185
|
-
value: new
|
|
1189
|
+
value: new import_three5.Color(12698049)
|
|
1186
1190
|
/*TODO*/
|
|
1187
1191
|
},
|
|
1188
1192
|
map: { value: Textures.createCanvasTexture(canvas) }
|
|
@@ -1191,7 +1195,7 @@ var _Materials = class _Materials {
|
|
|
1191
1195
|
fragmentShader: fragShader,
|
|
1192
1196
|
vertexColors: true,
|
|
1193
1197
|
transparent,
|
|
1194
|
-
side: transparent ?
|
|
1198
|
+
side: transparent ? import_three5.DoubleSide : import_three5.FrontSide,
|
|
1195
1199
|
alphaTest: 0.5
|
|
1196
1200
|
});
|
|
1197
1201
|
} catch (e) {
|
|
@@ -1201,6 +1205,10 @@ var _Materials = class _Materials {
|
|
|
1201
1205
|
}
|
|
1202
1206
|
static getImage(key) {
|
|
1203
1207
|
const keyStr = serializeMaterialKey(key);
|
|
1208
|
+
const map = Caching.materialCache.peek(keyStr)?.map;
|
|
1209
|
+
if (map && TextureLoader.hasFailed(map)) {
|
|
1210
|
+
Caching.materialCache.invalidate(keyStr);
|
|
1211
|
+
}
|
|
1204
1212
|
return Caching.materialCache.get(keyStr, (k) => {
|
|
1205
1213
|
return _Materials.createImage(key);
|
|
1206
1214
|
});
|
|
@@ -1225,10 +1233,10 @@ _Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA
|
|
|
1225
1233
|
var Materials = _Materials;
|
|
1226
1234
|
|
|
1227
1235
|
// src/Meshes.ts
|
|
1228
|
-
var
|
|
1236
|
+
var import_three6 = require("three");
|
|
1229
1237
|
var Meshes = class _Meshes {
|
|
1230
1238
|
static createBox(key) {
|
|
1231
|
-
return new
|
|
1239
|
+
return new import_three6.Mesh(Geometries.getBox(key.geometry), Materials.getImage(key.material));
|
|
1232
1240
|
}
|
|
1233
1241
|
static getBox(key) {
|
|
1234
1242
|
const keyStr = serializeMeshKey(key);
|
|
@@ -1275,6 +1283,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1275
1283
|
this.rootType = rootType;
|
|
1276
1284
|
this.extension = extension;
|
|
1277
1285
|
this.root = root;
|
|
1286
|
+
this.isAssetKey = true;
|
|
1278
1287
|
}
|
|
1279
1288
|
static parse(assetType, str, origin) {
|
|
1280
1289
|
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
@@ -1290,12 +1299,15 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1290
1299
|
split.shift();
|
|
1291
1300
|
}
|
|
1292
1301
|
let path = split.join("/");
|
|
1293
|
-
|
|
1302
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1303
|
+
if (extension && path.endsWith(extension)) {
|
|
1304
|
+
path = path.slice(0, -extension.length);
|
|
1305
|
+
}
|
|
1294
1306
|
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1295
1307
|
}
|
|
1296
1308
|
toString() {
|
|
1297
1309
|
let a = [
|
|
1298
|
-
|
|
1310
|
+
this.root ?? AssetLoader.ROOT,
|
|
1299
1311
|
this.rootType ?? "__rootType__",
|
|
1300
1312
|
this.assetType ?? "__assetType__",
|
|
1301
1313
|
this.type ?? "__type__",
|
|
@@ -1305,12 +1317,12 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1305
1317
|
return a.join("/");
|
|
1306
1318
|
}
|
|
1307
1319
|
getFullPath() {
|
|
1308
|
-
let
|
|
1320
|
+
let p12 = [];
|
|
1309
1321
|
if (this.type) {
|
|
1310
|
-
|
|
1322
|
+
p12.push(this.type);
|
|
1311
1323
|
}
|
|
1312
|
-
|
|
1313
|
-
return
|
|
1324
|
+
p12.push(this.path);
|
|
1325
|
+
return p12.join("/");
|
|
1314
1326
|
}
|
|
1315
1327
|
toNamespacedString() {
|
|
1316
1328
|
return this.namespace + ":" + this.getFullPath();
|
|
@@ -1320,10 +1332,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1320
1332
|
}
|
|
1321
1333
|
};
|
|
1322
1334
|
function isBasicAssetKey(obj) {
|
|
1323
|
-
return "
|
|
1335
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1324
1336
|
}
|
|
1325
1337
|
function isAssetKey(obj) {
|
|
1326
|
-
return isBasicAssetKey(obj) &&
|
|
1338
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1327
1339
|
}
|
|
1328
1340
|
|
|
1329
1341
|
// src/model/ModelMerger.ts
|
|
@@ -1332,10 +1344,10 @@ var ModelMerger = class {
|
|
|
1332
1344
|
const models = await this.collectAllParents(model);
|
|
1333
1345
|
let merged = {};
|
|
1334
1346
|
for (let parentModel of models) {
|
|
1335
|
-
merged =
|
|
1347
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
|
|
1336
1348
|
}
|
|
1337
|
-
merged =
|
|
1338
|
-
merged.hierarchy = models.map((m) => m.parent).filter((
|
|
1349
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
|
|
1350
|
+
merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
|
|
1339
1351
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1340
1352
|
return merged;
|
|
1341
1353
|
}
|
|
@@ -1345,6 +1357,7 @@ var ModelMerger = class {
|
|
|
1345
1357
|
}
|
|
1346
1358
|
const models = [];
|
|
1347
1359
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1360
|
+
parentKey.root = model.key?.root;
|
|
1348
1361
|
const parentModel = await Models.getRaw(parentKey);
|
|
1349
1362
|
if (parentModel) {
|
|
1350
1363
|
models.unshift(parentModel);
|
|
@@ -1354,9 +1367,6 @@ var ModelMerger = class {
|
|
|
1354
1367
|
}
|
|
1355
1368
|
};
|
|
1356
1369
|
|
|
1357
|
-
// src/assets/Models.ts
|
|
1358
|
-
var import_typescript_memoize = require("typescript-memoize");
|
|
1359
|
-
|
|
1360
1370
|
// src/assets/source/parser/AssetParsers.ts
|
|
1361
1371
|
var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
1362
1372
|
AssetParser2["MODEL"] = "model";
|
|
@@ -1370,30 +1380,65 @@ var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
|
1370
1380
|
})(AssetParser || {});
|
|
1371
1381
|
|
|
1372
1382
|
// src/assets/Models.ts
|
|
1373
|
-
var
|
|
1383
|
+
var Models = class _Models {
|
|
1374
1384
|
// opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
|
|
1375
1385
|
// the library, and would require an EnvProvider before any entry has had a chance to register
|
|
1376
1386
|
static get PERSISTENT_CACHE() {
|
|
1377
1387
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
|
|
1378
1388
|
}
|
|
1379
1389
|
static async getItemList() {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
"
|
|
1384
|
-
|
|
1385
|
-
"assets",
|
|
1386
|
-
".json",
|
|
1387
|
-
DEFAULT_ROOT
|
|
1388
|
-
), "list" /* LIST */).then((r) => r?.files ?? []);
|
|
1390
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1391
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1392
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1393
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1394
|
+
}).then((r) => r?.files ?? []);
|
|
1389
1395
|
}
|
|
1390
1396
|
static async loadAndMerge(key) {
|
|
1391
|
-
const model = await this.getRaw(key);
|
|
1397
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1392
1398
|
if (!model) {
|
|
1393
1399
|
return void 0;
|
|
1394
1400
|
}
|
|
1395
1401
|
return ModelMerger.mergeWithParents(model);
|
|
1396
1402
|
}
|
|
1403
|
+
static async getItemModel(key) {
|
|
1404
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1405
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1406
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1407
|
+
if (!result) return void 0;
|
|
1408
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1409
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1410
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1411
|
+
modelKey.root = key.root;
|
|
1412
|
+
const model2 = await this.getRaw(modelKey);
|
|
1413
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1414
|
+
return model2;
|
|
1415
|
+
});
|
|
1416
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1417
|
+
}
|
|
1418
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1419
|
+
static defaultItemModel(node, key) {
|
|
1420
|
+
if (!node || typeof node.type !== "string") {
|
|
1421
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1422
|
+
}
|
|
1423
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1424
|
+
case "model":
|
|
1425
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1426
|
+
break;
|
|
1427
|
+
case "condition":
|
|
1428
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1429
|
+
case "select": {
|
|
1430
|
+
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;
|
|
1431
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1432
|
+
}
|
|
1433
|
+
case "range_dispatch": {
|
|
1434
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1435
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1436
|
+
}, void 0);
|
|
1437
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1441
|
+
}
|
|
1397
1442
|
static async getRaw(key) {
|
|
1398
1443
|
if (!key.assetType) {
|
|
1399
1444
|
key.assetType = "models";
|
|
@@ -1432,19 +1477,15 @@ var _Models = class _Models {
|
|
|
1432
1477
|
return this.PERSISTENT_CACHE.clear();
|
|
1433
1478
|
}
|
|
1434
1479
|
};
|
|
1435
|
-
__decorateClass([
|
|
1436
|
-
(0, import_typescript_memoize.Memoize)()
|
|
1437
|
-
], _Models, "getItemList", 1);
|
|
1438
|
-
var Models = _Models;
|
|
1439
1480
|
|
|
1440
1481
|
// src/assets/BlockStates.ts
|
|
1441
|
-
var import_typescript_memoize2 = require("typescript-memoize");
|
|
1442
1482
|
var BlockStates = class {
|
|
1443
1483
|
static get PERSISTENT_CACHE() {
|
|
1444
1484
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-blockstates"));
|
|
1445
1485
|
}
|
|
1486
|
+
// BlockState names are hardcoded
|
|
1446
1487
|
static async getList() {
|
|
1447
|
-
|
|
1488
|
+
const key = new AssetKey(
|
|
1448
1489
|
DEFAULT_NAMESPACE,
|
|
1449
1490
|
"_list",
|
|
1450
1491
|
"blockstates",
|
|
@@ -1452,11 +1493,16 @@ var BlockStates = class {
|
|
|
1452
1493
|
"assets",
|
|
1453
1494
|
".json",
|
|
1454
1495
|
DEFAULT_ROOT
|
|
1455
|
-
)
|
|
1496
|
+
);
|
|
1497
|
+
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1498
|
+
return AssetLoader.get(key, "list" /* LIST */);
|
|
1499
|
+
}).then((r) => r?.files ?? []);
|
|
1456
1500
|
}
|
|
1457
1501
|
static async getDefaultStates() {
|
|
1458
1502
|
const key = AssetKey.parse("blockstates", "minerender:defaultBlockStates");
|
|
1459
|
-
return
|
|
1503
|
+
return Caching.defaultBlockStatesCache.get(key.serialize(), () => {
|
|
1504
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
1505
|
+
});
|
|
1460
1506
|
}
|
|
1461
1507
|
static async getDefaultState(key) {
|
|
1462
1508
|
const defaultStates = await this.getDefaultStates();
|
|
@@ -1495,17 +1541,11 @@ var BlockStates = class {
|
|
|
1495
1541
|
await this.PERSISTENT_CACHE.clear();
|
|
1496
1542
|
}
|
|
1497
1543
|
};
|
|
1498
|
-
__decorateClass([
|
|
1499
|
-
(0, import_typescript_memoize2.Memoize)()
|
|
1500
|
-
], BlockStates, "getList", 1);
|
|
1501
|
-
__decorateClass([
|
|
1502
|
-
(0, import_typescript_memoize2.Memoize)()
|
|
1503
|
-
], BlockStates, "getDefaultStates", 1);
|
|
1504
1544
|
var DefaultBlockStates = class {
|
|
1505
1545
|
};
|
|
1506
1546
|
|
|
1507
1547
|
// src/assets/Assets.ts
|
|
1508
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1548
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1509
1549
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1510
1550
|
var Assets = class {
|
|
1511
1551
|
/**
|
|
@@ -1527,82 +1567,213 @@ var AssetSource = class {
|
|
|
1527
1567
|
constructor() {
|
|
1528
1568
|
}
|
|
1529
1569
|
};
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1570
|
+
var AssetLoadError = class extends Error {
|
|
1571
|
+
constructor(source, key, path, cause) {
|
|
1572
|
+
super(`Failed to load ${key.toNamespacedString()} from ${path}${cause instanceof Error ? `: ${cause.message}` : ""}`);
|
|
1573
|
+
this.source = source;
|
|
1574
|
+
this.key = key;
|
|
1575
|
+
this.path = path;
|
|
1576
|
+
this.cause = cause;
|
|
1577
|
+
this.name = "AssetLoadError";
|
|
1537
1578
|
}
|
|
1538
1579
|
};
|
|
1539
1580
|
|
|
1540
|
-
// src/
|
|
1541
|
-
var
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
async loadOrRetryWithDefaults(key, parser) {
|
|
1548
|
-
const direct = await this.load(key, parser);
|
|
1549
|
-
if (typeof direct !== "undefined") {
|
|
1550
|
-
return direct;
|
|
1551
|
-
}
|
|
1552
|
-
if (key.namespace !== DEFAULT_NAMESPACE) {
|
|
1553
|
-
console.info(p3, "Retrying", key, "with default namespace");
|
|
1554
|
-
const namespaceKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, key.root);
|
|
1555
|
-
const namespaced = await this.load(namespaceKey, parser);
|
|
1556
|
-
if (typeof namespaced !== "undefined") {
|
|
1557
|
-
return namespaced;
|
|
1558
|
-
}
|
|
1559
|
-
if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
|
|
1560
|
-
console.info(p3, "Retrying", key, "with default root+namespace");
|
|
1561
|
-
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
|
|
1562
|
-
const namespacedRooted = await this.load(namespacedRootedKey, parser);
|
|
1563
|
-
if (typeof namespacedRooted !== "undefined") {
|
|
1564
|
-
return namespacedRooted;
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
} else if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
|
|
1568
|
-
console.info(p3, "Retrying", key, "with default root");
|
|
1569
|
-
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
|
|
1570
|
-
const rooted = await this.load(rootKey, parser);
|
|
1571
|
-
if (typeof rooted !== "undefined") {
|
|
1572
|
-
return rooted;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
return void 0;
|
|
1581
|
+
// src/util/BatchedExecutor.ts
|
|
1582
|
+
var BatchedExecutor = class {
|
|
1583
|
+
constructor(interval = 1, batch = 30) {
|
|
1584
|
+
this.interval = interval;
|
|
1585
|
+
this.batch = batch;
|
|
1586
|
+
this.queue = [];
|
|
1587
|
+
this.task = setInterval(() => this.run());
|
|
1576
1588
|
}
|
|
1577
|
-
|
|
1589
|
+
submit(task) {
|
|
1590
|
+
this.queue.push(task);
|
|
1591
|
+
}
|
|
1592
|
+
run() {
|
|
1593
|
+
for (let i = 0; i < this.batch; i++) {
|
|
1594
|
+
this.runNext();
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
runNext() {
|
|
1598
|
+
let next = this.queue.shift();
|
|
1599
|
+
if (next) next();
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/util/model.ts
|
|
1604
|
+
var import_three7 = require("three");
|
|
1605
|
+
function applyElementRotation(rotation, geometry) {
|
|
1606
|
+
const origin = new import_three7.Vector3(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1607
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1608
|
+
switch (rotation.axis) {
|
|
1609
|
+
case "x" /* X */:
|
|
1610
|
+
geometry.rotateX(toRadians(rotation.angle));
|
|
1611
|
+
break;
|
|
1612
|
+
case "y" /* Y */:
|
|
1613
|
+
geometry.rotateY(toRadians(rotation.angle));
|
|
1614
|
+
break;
|
|
1615
|
+
case "z" /* Z */:
|
|
1616
|
+
geometry.rotateZ(toRadians(rotation.angle));
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
if (rotation.rescale) {
|
|
1620
|
+
if (Math.abs(rotation.angle) === 22.5) {
|
|
1621
|
+
const s = 1 / Math.cos(0.39269909262657166);
|
|
1622
|
+
geometry.scale(s, 1, s);
|
|
1623
|
+
} else {
|
|
1624
|
+
const s = 1 / Math.cos(0.7853981852531433);
|
|
1625
|
+
geometry.scale(s, 1, s);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1629
|
+
}
|
|
1630
|
+
function applyModelPartRotation(modelPart, geometry) {
|
|
1631
|
+
const origin = new import_three7.Vector3(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1632
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1633
|
+
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1634
|
+
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1635
|
+
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1636
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1637
|
+
}
|
|
1638
|
+
function applyGenericRotation(axis, rotation, obj) {
|
|
1639
|
+
switch (axis) {
|
|
1640
|
+
case "x" /* X */:
|
|
1641
|
+
obj.rotateOnAxis(new import_three7.Vector3(1, 0, 0), toRadians(rotation));
|
|
1642
|
+
break;
|
|
1643
|
+
case "y" /* Y */:
|
|
1644
|
+
obj.rotateOnAxis(new import_three7.Vector3(0, 1, 0), toRadians(rotation));
|
|
1645
|
+
break;
|
|
1646
|
+
case "z" /* Z */:
|
|
1647
|
+
obj.rotateOnAxis(new import_three7.Vector3(0, 0, 1), toRadians(rotation));
|
|
1648
|
+
break;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
function addBox3WireframeToObject(box, obj, color = 16777215, w = 2) {
|
|
1652
|
+
let size = new import_three7.Vector3();
|
|
1653
|
+
box.getSize(size);
|
|
1654
|
+
let boxGeo = new import_three7.BoxGeometry(size.x, size.y, size.z, 1, 1, 1);
|
|
1655
|
+
let wireGeo = new import_three7.EdgesGeometry(boxGeo);
|
|
1656
|
+
let wireMat = new import_three7.LineBasicMaterial({ color, linewidth: w });
|
|
1657
|
+
let wireframe = new import_three7.LineSegments(wireGeo, wireMat);
|
|
1658
|
+
obj.add(wireframe);
|
|
1659
|
+
let axes = new import_three7.AxesHelper(1);
|
|
1660
|
+
obj.add(axes);
|
|
1661
|
+
}
|
|
1662
|
+
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
1663
|
+
let boxGeo = new import_three7.BoxGeometry(16, 16, 16, 1, 1, 1);
|
|
1664
|
+
let wireGeo = new import_three7.EdgesGeometry(boxGeo);
|
|
1665
|
+
let wireMat = new import_three7.LineBasicMaterial({ color, linewidth: w });
|
|
1666
|
+
let wireframe = new import_three7.LineSegments(wireGeo, wireMat);
|
|
1667
|
+
obj.add(wireframe);
|
|
1668
|
+
let axes = new import_three7.AxesHelper(1);
|
|
1669
|
+
obj.add(axes);
|
|
1670
|
+
}
|
|
1671
|
+
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
1672
|
+
let wireGeo = new import_three7.EdgesGeometry(geo);
|
|
1673
|
+
let wireMat = new import_three7.LineBasicMaterial({ color, linewidth: w });
|
|
1674
|
+
let wireframe = new import_three7.LineSegments(wireGeo, wireMat);
|
|
1675
|
+
mesh.add(wireframe);
|
|
1676
|
+
let axes = new import_three7.AxesHelper(1);
|
|
1677
|
+
mesh.add(axes);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
// src/util/performance.ts
|
|
1681
|
+
function captureException(e, ...extra) {
|
|
1682
|
+
console.error(e, extra);
|
|
1683
|
+
}
|
|
1684
|
+
function timingStart(marker) {
|
|
1685
|
+
console.time(marker);
|
|
1686
|
+
}
|
|
1687
|
+
function timingEnd(marker) {
|
|
1688
|
+
console.timeEnd(marker);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// src/util/three.ts
|
|
1692
|
+
function isObject3D(obj) {
|
|
1693
|
+
return obj.isObject3D;
|
|
1694
|
+
}
|
|
1695
|
+
function isMesh(obj) {
|
|
1696
|
+
return obj.isMesh;
|
|
1697
|
+
}
|
|
1698
|
+
function isInstancedMesh(obj) {
|
|
1699
|
+
return obj.isInstancedMesh;
|
|
1700
|
+
}
|
|
1701
|
+
function isPerspectiveCamera(obj) {
|
|
1702
|
+
return obj.isPerspectiveCamera;
|
|
1703
|
+
}
|
|
1704
|
+
function isOrthographicCamera(obj) {
|
|
1705
|
+
return obj.isOrthographicCamera;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// src/nbt/NBTHelper.ts
|
|
1709
|
+
var NBTHelper = class {
|
|
1710
|
+
static async fromBuffer(buffer) {
|
|
1711
|
+
const prismarineNbt = await import("prismarine-nbt");
|
|
1712
|
+
const { parsed, type, metadata } = await prismarineNbt.parse(buffer);
|
|
1713
|
+
return parsed;
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
// src/assets/source/HostedAssetSource.ts
|
|
1718
|
+
var import_ts_deepmerge2 = __toESM(require_dist());
|
|
1719
|
+
var p3 = prefix("HostedAssetSource");
|
|
1720
|
+
var DEFAULT_OPTIONS = {
|
|
1721
|
+
retryDefaults: true
|
|
1722
|
+
};
|
|
1723
|
+
var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
1724
|
+
async loadOrRetryWithDefaults(key, parser) {
|
|
1725
|
+
const direct = await this.load(key, parser);
|
|
1726
|
+
if (typeof direct !== "undefined") {
|
|
1727
|
+
return direct;
|
|
1728
|
+
}
|
|
1729
|
+
if (key.namespace !== DEFAULT_NAMESPACE) {
|
|
1730
|
+
console.info(p3, "Retrying", key, "with default namespace");
|
|
1731
|
+
const namespaceKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, key.root);
|
|
1732
|
+
const namespaced = await this.load(namespaceKey, parser);
|
|
1733
|
+
if (typeof namespaced !== "undefined") {
|
|
1734
|
+
return namespaced;
|
|
1735
|
+
}
|
|
1736
|
+
if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
|
|
1737
|
+
console.info(p3, "Retrying", key, "with default root+namespace");
|
|
1738
|
+
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
|
|
1739
|
+
const namespacedRooted = await this.load(namespacedRootedKey, parser);
|
|
1740
|
+
if (typeof namespacedRooted !== "undefined") {
|
|
1741
|
+
return namespacedRooted;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
} else if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
|
|
1745
|
+
console.info(p3, "Retrying", key, "with default root");
|
|
1746
|
+
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
|
|
1747
|
+
const rooted = await this.load(rootKey, parser);
|
|
1748
|
+
if (typeof rooted !== "undefined") {
|
|
1749
|
+
return rooted;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return void 0;
|
|
1753
|
+
}
|
|
1754
|
+
async load(key, parser) {
|
|
1578
1755
|
console.info(p3, "Loading", key);
|
|
1579
1756
|
const url = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1580
1757
|
console.debug(p3, url);
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
} catch (e) {
|
|
1590
|
-
console.warn("Parser failed to process response", response, e);
|
|
1591
|
-
throw e;
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
return void 0;
|
|
1595
|
-
}).catch((err) => {
|
|
1596
|
-
if (err.response) {
|
|
1597
|
-
let response = err.response;
|
|
1598
|
-
if (response.status === 404) {
|
|
1599
|
-
console.debug(p3, key, "not found");
|
|
1758
|
+
const request = { url };
|
|
1759
|
+
try {
|
|
1760
|
+
parser.config(request);
|
|
1761
|
+
let response;
|
|
1762
|
+
try {
|
|
1763
|
+
response = await Requests.mcAssetRequest(request);
|
|
1764
|
+
} catch (cause) {
|
|
1765
|
+
if (cause instanceof RequestError && cause.response?.status === 404) {
|
|
1600
1766
|
return void 0;
|
|
1601
1767
|
}
|
|
1768
|
+
throw cause;
|
|
1602
1769
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1770
|
+
if (response.data === void 0) {
|
|
1771
|
+
throw new Error("Asset response has no data");
|
|
1772
|
+
}
|
|
1773
|
+
return await parser.parse(response);
|
|
1774
|
+
} catch (cause) {
|
|
1775
|
+
throw new AssetLoadError(this, key, request.url, cause);
|
|
1776
|
+
}
|
|
1606
1777
|
}
|
|
1607
1778
|
assetBasePath(key) {
|
|
1608
1779
|
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 + "/" : ""}`;
|
|
@@ -1709,7 +1880,6 @@ var BrowserArchiveProxy = class {
|
|
|
1709
1880
|
};
|
|
1710
1881
|
|
|
1711
1882
|
// src/assets/source/archive/ArchiveAssetSource.ts
|
|
1712
|
-
var p4 = prefix("ArchiveAssetSource");
|
|
1713
1883
|
var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
1714
1884
|
constructor(archiveProxy) {
|
|
1715
1885
|
super();
|
|
@@ -1728,74 +1898,31 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1728
1898
|
}
|
|
1729
1899
|
async get(key, parser) {
|
|
1730
1900
|
const responseParser = HostedAssetSource.PARSER_MAP.get(parser);
|
|
1731
|
-
|
|
1732
|
-
let entries = await this.getEntries();
|
|
1733
|
-
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1734
|
-
console.log(path);
|
|
1735
|
-
const entry = await this.getEntry(path);
|
|
1736
|
-
console.log(entry);
|
|
1737
|
-
if (!entry) {
|
|
1738
|
-
return void 0;
|
|
1739
|
-
}
|
|
1740
|
-
let blob = await entry.getData();
|
|
1741
|
-
const url = URL.createObjectURL(blob);
|
|
1742
|
-
console.log(url);
|
|
1743
|
-
let req = {
|
|
1744
|
-
url
|
|
1745
|
-
};
|
|
1746
|
-
responseParser.config(req);
|
|
1747
|
-
return Requests.genericRequest(req).then((response) => {
|
|
1748
|
-
if (response && response.data) {
|
|
1749
|
-
try {
|
|
1750
|
-
return responseParser.parse(response);
|
|
1751
|
-
} catch (e) {
|
|
1752
|
-
console.warn("Parser failed to process response", response, e);
|
|
1753
|
-
throw e;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return void 0;
|
|
1757
|
-
}).catch((err) => {
|
|
1758
|
-
if (err.response) {
|
|
1759
|
-
let response = err.response;
|
|
1760
|
-
if (response.status === 404) {
|
|
1761
|
-
console.debug(p4, key, "not found");
|
|
1762
|
-
return void 0;
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
console.debug(p4, "Failed to load", key, err?.message);
|
|
1766
|
-
return void 0;
|
|
1767
|
-
});
|
|
1901
|
+
return this.load(key, responseParser);
|
|
1768
1902
|
}
|
|
1769
|
-
//TODO: abstract this
|
|
1770
1903
|
async load(key, parser) {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
parser.config(req);
|
|
1778
|
-
return await Requests.genericRequest(req).then((response) => {
|
|
1779
|
-
if (response && response.data) {
|
|
1780
|
-
try {
|
|
1781
|
-
return parser.parse(response);
|
|
1782
|
-
} catch (e) {
|
|
1783
|
-
console.warn("Parser failed to process response", response, e);
|
|
1784
|
-
throw e;
|
|
1785
|
-
}
|
|
1904
|
+
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1905
|
+
let url;
|
|
1906
|
+
try {
|
|
1907
|
+
const entry = await this.getEntry(path);
|
|
1908
|
+
if (!entry) {
|
|
1909
|
+
return void 0;
|
|
1786
1910
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
return void 0;
|
|
1794
|
-
}
|
|
1911
|
+
url = URL.createObjectURL(await entry.getData());
|
|
1912
|
+
const request = { url };
|
|
1913
|
+
parser.config(request);
|
|
1914
|
+
const response = await Requests.genericRequest(request);
|
|
1915
|
+
if (response.data === void 0) {
|
|
1916
|
+
throw new Error("Asset response has no data");
|
|
1795
1917
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1918
|
+
return await parser.parse(response);
|
|
1919
|
+
} catch (cause) {
|
|
1920
|
+
throw new AssetLoadError(this, key, path, cause);
|
|
1921
|
+
} finally {
|
|
1922
|
+
if (url !== void 0) {
|
|
1923
|
+
URL.revokeObjectURL(url);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1799
1926
|
}
|
|
1800
1927
|
assetBasePath(key) {
|
|
1801
1928
|
return `${key.rootType !== void 0 ? key.rootType + "/" : ""}${key.namespace !== void 0 ? key.namespace + "/" : ""}${key.assetType !== void 0 ? key.assetType + "/" : ""}`;
|
|
@@ -1803,18 +1930,17 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1803
1930
|
};
|
|
1804
1931
|
|
|
1805
1932
|
// src/assets/AssetLoader.ts
|
|
1806
|
-
var
|
|
1807
|
-
var p5 = prefix("AssetLoader");
|
|
1933
|
+
var p4 = prefix("AssetLoader");
|
|
1808
1934
|
var _AssetLoader = class _AssetLoader {
|
|
1809
1935
|
static addSource(key, source, override = true) {
|
|
1810
1936
|
if (override) {
|
|
1811
1937
|
const existing = this.removeSource(key);
|
|
1812
1938
|
if (existing) {
|
|
1813
|
-
console.log(
|
|
1939
|
+
console.log(p4, "Removed existing AssetSource", key);
|
|
1814
1940
|
}
|
|
1815
1941
|
}
|
|
1816
1942
|
this._SOURCES.unshift({ key, source });
|
|
1817
|
-
console.log(
|
|
1943
|
+
console.log(p4, "Added AssetSource", key);
|
|
1818
1944
|
}
|
|
1819
1945
|
static removeSource(key) {
|
|
1820
1946
|
const index = this._SOURCES.findIndex((s) => s.key === key);
|
|
@@ -1827,7 +1953,6 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1827
1953
|
return void 0;
|
|
1828
1954
|
}
|
|
1829
1955
|
static async getAll(key, parser) {
|
|
1830
|
-
console.log(this._SOURCES);
|
|
1831
1956
|
let promises = [];
|
|
1832
1957
|
for (const source of this._SOURCES) {
|
|
1833
1958
|
promises.push(source.source.get(key, parser));
|
|
@@ -1836,24 +1961,34 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1836
1961
|
return results.filter((r) => r != void 0);
|
|
1837
1962
|
});
|
|
1838
1963
|
}
|
|
1964
|
+
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1839
1965
|
static async get(key, parser) {
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1966
|
+
const keys = [key];
|
|
1967
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1968
|
+
keys.push(new AssetKey(
|
|
1969
|
+
key.namespace,
|
|
1970
|
+
key.path,
|
|
1971
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1972
|
+
key.type,
|
|
1973
|
+
key.rootType,
|
|
1974
|
+
key.extension,
|
|
1975
|
+
key.root
|
|
1976
|
+
));
|
|
1977
|
+
}
|
|
1978
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1979
|
+
}
|
|
1980
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1981
|
+
static async getFirst(keys, parser) {
|
|
1982
|
+
const sources = [...this._SOURCES];
|
|
1983
|
+
for (const source of sources) {
|
|
1984
|
+
for (const key of keys) {
|
|
1985
|
+
const result = await source.source.get(key, parser);
|
|
1986
|
+
if (result !== void 0) {
|
|
1987
|
+
return { key, asset: result };
|
|
1853
1988
|
}
|
|
1854
1989
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1990
|
+
}
|
|
1991
|
+
return void 0;
|
|
1857
1992
|
}
|
|
1858
1993
|
};
|
|
1859
1994
|
_AssetLoader.ROOT = DEFAULT_ROOT;
|
|
@@ -1868,11 +2003,21 @@ var ModelTextures = class {
|
|
|
1868
2003
|
return this._persistentMetaCache ?? (this._persistentMetaCache = PersistentCache.open("minerender-texturemeta"));
|
|
1869
2004
|
}
|
|
1870
2005
|
static async get(key) {
|
|
1871
|
-
const
|
|
1872
|
-
|
|
1873
|
-
|
|
2006
|
+
const keyStr = key.serialize();
|
|
2007
|
+
const pending = this.preload(key);
|
|
2008
|
+
const cached = Caching.textureAssetCache.getIfPresent(keyStr);
|
|
2009
|
+
try {
|
|
2010
|
+
const asset = await pending;
|
|
2011
|
+
if (asset) {
|
|
2012
|
+
return await ImageLoader.infoToCanvasData(asset);
|
|
2013
|
+
}
|
|
2014
|
+
return void 0;
|
|
2015
|
+
} catch (err) {
|
|
2016
|
+
if (cached && Caching.textureAssetCache.getIfPresent(keyStr) === cached) {
|
|
2017
|
+
Caching.textureAssetCache.invalidate(keyStr);
|
|
2018
|
+
}
|
|
2019
|
+
throw err;
|
|
1874
2020
|
}
|
|
1875
|
-
return void 0;
|
|
1876
2021
|
}
|
|
1877
2022
|
static async preload(key) {
|
|
1878
2023
|
const keyStr = key.serialize();
|
|
@@ -2042,17 +2187,20 @@ var TextureAtlas = class {
|
|
|
2042
2187
|
// src/model/ModelGenerator.ts
|
|
2043
2188
|
var ModelGenerator = class {
|
|
2044
2189
|
static generateItemModel(imageData, layer) {
|
|
2190
|
+
const tintindex = this.ITEM_LAYERS.indexOf(layer);
|
|
2045
2191
|
const mainElement = {
|
|
2046
2192
|
from: [0, 0, 7.5],
|
|
2047
2193
|
to: [16, 16, 8.5],
|
|
2048
2194
|
faces: {
|
|
2049
2195
|
"south": {
|
|
2050
2196
|
uv: [0, 0, 16, 16],
|
|
2051
|
-
texture: `#${layer}
|
|
2197
|
+
texture: `#${layer}`,
|
|
2198
|
+
tintindex
|
|
2052
2199
|
},
|
|
2053
2200
|
"north": {
|
|
2054
2201
|
uv: [16, 0, 0, 16],
|
|
2055
|
-
texture: `#${layer}
|
|
2202
|
+
texture: `#${layer}`,
|
|
2203
|
+
tintindex
|
|
2056
2204
|
}
|
|
2057
2205
|
},
|
|
2058
2206
|
shade: true
|
|
@@ -2063,11 +2211,19 @@ var ModelGenerator = class {
|
|
|
2063
2211
|
ModelGenerator.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
2064
2212
|
|
|
2065
2213
|
// src/UVMapper.ts
|
|
2066
|
-
var
|
|
2214
|
+
var p5 = prefix("UVMapper");
|
|
2067
2215
|
var DEFAULT_UV = [0, 0, 16, 16];
|
|
2068
2216
|
var X = 0;
|
|
2069
2217
|
var Y = 1;
|
|
2070
2218
|
var Z = 2;
|
|
2219
|
+
var FACE_UV_AXES = {
|
|
2220
|
+
east: [new import_three8.Vector3(0, 0, -1), new import_three8.Vector3(0, -1, 0)],
|
|
2221
|
+
west: [new import_three8.Vector3(0, 0, 1), new import_three8.Vector3(0, -1, 0)],
|
|
2222
|
+
up: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, 1)],
|
|
2223
|
+
down: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, -1)],
|
|
2224
|
+
south: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, -1, 0)],
|
|
2225
|
+
north: [new import_three8.Vector3(-1, 0, 0), new import_three8.Vector3(0, -1, 0)]
|
|
2226
|
+
};
|
|
2071
2227
|
var UVMapper = class {
|
|
2072
2228
|
static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
|
|
2073
2229
|
if (uvCoord === 0) return 0;
|
|
@@ -2165,6 +2321,42 @@ var UVMapper = class {
|
|
|
2165
2321
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
2166
2322
|
return new import_three8.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
2167
2323
|
}
|
|
2324
|
+
static lockUvs(geometry, faces, atlas, rotation) {
|
|
2325
|
+
const uv = geometry.getAttribute("uv");
|
|
2326
|
+
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
2327
|
+
const faceName = CUBE_FACES[faceIndex];
|
|
2328
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
2329
|
+
const position = texture && atlas.positions[texture];
|
|
2330
|
+
const size = texture && atlas.sizes[texture];
|
|
2331
|
+
if (!position || !size) continue;
|
|
2332
|
+
const [sourceU, sourceV] = FACE_UV_AXES[faceName];
|
|
2333
|
+
const uAxis = sourceU.clone().applyEuler(rotation);
|
|
2334
|
+
const vAxis = sourceV.clone().applyEuler(rotation);
|
|
2335
|
+
const normal = vAxis.clone().cross(uAxis);
|
|
2336
|
+
const targetFace = CUBE_FACES.find((name) => {
|
|
2337
|
+
const [u, v] = FACE_UV_AXES[name];
|
|
2338
|
+
return v.clone().cross(u).dot(normal) > 0.5;
|
|
2339
|
+
});
|
|
2340
|
+
const [targetU, targetV] = FACE_UV_AXES[targetFace];
|
|
2341
|
+
const uu = Math.round(targetU.dot(uAxis));
|
|
2342
|
+
const uvCross = Math.round(targetU.dot(vAxis));
|
|
2343
|
+
const vu = Math.round(targetV.dot(uAxis));
|
|
2344
|
+
const vv = Math.round(targetV.dot(vAxis));
|
|
2345
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
2346
|
+
const index = faceIndex * 4 + corner;
|
|
2347
|
+
const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
|
|
2348
|
+
const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
|
|
2349
|
+
const lockedU = uu * u + uvCross * v + 0.5;
|
|
2350
|
+
const lockedV = vu * u + vv * v + 0.5;
|
|
2351
|
+
uv.setXY(
|
|
2352
|
+
index,
|
|
2353
|
+
(position[0] + lockedU * size[0]) / atlas.image.width,
|
|
2354
|
+
1 - (position[1] + lockedV * size[1]) / atlas.image.height
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
uv.needsUpdate = true;
|
|
2359
|
+
}
|
|
2168
2360
|
static async getAtlas(model) {
|
|
2169
2361
|
const keyStr = model.key.serialize();
|
|
2170
2362
|
return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
|
|
@@ -2240,7 +2432,7 @@ var UVMapper = class {
|
|
|
2240
2432
|
const metaMap = {};
|
|
2241
2433
|
const model = { ...originalModel };
|
|
2242
2434
|
const isItemModel = !("elements" in model);
|
|
2243
|
-
console.debug(
|
|
2435
|
+
console.debug(p5, "Creating Atlas for", model.key);
|
|
2244
2436
|
if (model.textures) {
|
|
2245
2437
|
const promises = [];
|
|
2246
2438
|
const uniqueTextureNames = [];
|
|
@@ -2254,7 +2446,7 @@ var UVMapper = class {
|
|
|
2254
2446
|
const assetKey = AssetKey.parse("textures", textureValue, model.key);
|
|
2255
2447
|
promises.push(ModelTextures.get(assetKey).then((asset) => {
|
|
2256
2448
|
if (!asset) {
|
|
2257
|
-
console.warn(
|
|
2449
|
+
console.warn(p5, "Missing texture", assetKey);
|
|
2258
2450
|
return;
|
|
2259
2451
|
}
|
|
2260
2452
|
textureMap[textureKey] = new WrappedImage(asset);
|
|
@@ -2266,7 +2458,7 @@ var UVMapper = class {
|
|
|
2266
2458
|
}
|
|
2267
2459
|
await Promise.all(promises);
|
|
2268
2460
|
const textureCount = uniqueTextureNames.length;
|
|
2269
|
-
console.debug(
|
|
2461
|
+
console.debug(p5, "Creating Atlas for", textureCount, "textures");
|
|
2270
2462
|
this.fillMissingTextureKeys(model.textures, textureMap);
|
|
2271
2463
|
this.fillMissingTextureKeys(model.textures, metaMap);
|
|
2272
2464
|
const sizes = {};
|
|
@@ -2286,7 +2478,7 @@ var UVMapper = class {
|
|
|
2286
2478
|
this.fillMissingTextureKeys(model.textures, sizes);
|
|
2287
2479
|
const s = Math.ceil(Math.sqrt(textureCount + 1));
|
|
2288
2480
|
const size = Math.ceil(s * maxWidth);
|
|
2289
|
-
console.debug(
|
|
2481
|
+
console.debug(p5, "Atlas size:", size);
|
|
2290
2482
|
const squaredSize = size * size;
|
|
2291
2483
|
const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
|
|
2292
2484
|
const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
|
|
@@ -2341,10 +2533,10 @@ var UVMapper = class {
|
|
|
2341
2533
|
}
|
|
2342
2534
|
}
|
|
2343
2535
|
const atlasImageData = image.toDataURL();
|
|
2344
|
-
console.log(
|
|
2536
|
+
console.log(p5, "Atlas Image for", model.key, atlasImageData);
|
|
2345
2537
|
this.fillMissingTextureKeys(model.textures, positions);
|
|
2346
2538
|
if (isItemModel) {
|
|
2347
|
-
console.debug(
|
|
2539
|
+
console.debug(p5, "Generating item model for", model);
|
|
2348
2540
|
model.elements = [];
|
|
2349
2541
|
for (let layerName of ModelGenerator.ITEM_LAYERS) {
|
|
2350
2542
|
const textureImage = textureMap[layerName];
|
|
@@ -2352,7 +2544,7 @@ var UVMapper = class {
|
|
|
2352
2544
|
model.elements.push(...ModelGenerator.generateItemModel(textureImage.data, layerName));
|
|
2353
2545
|
}
|
|
2354
2546
|
}
|
|
2355
|
-
console.debug(
|
|
2547
|
+
console.debug(p5, "Item model elements", model.elements);
|
|
2356
2548
|
}
|
|
2357
2549
|
if (!model.elements) {
|
|
2358
2550
|
}
|
|
@@ -2370,17 +2562,13 @@ var UVMapper = class {
|
|
|
2370
2562
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2371
2563
|
continue;
|
|
2372
2564
|
}
|
|
2565
|
+
if (!face.texture) continue;
|
|
2373
2566
|
if (!face.uv) {
|
|
2374
2567
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2375
2568
|
}
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
if (faceTexture) {
|
|
2380
|
-
faceTexture = faceTexture.substr(1);
|
|
2381
|
-
texPosition = positions[faceTexture] || [0, 0];
|
|
2382
|
-
texSize = sizes[faceTexture] || [16, 16];
|
|
2383
|
-
}
|
|
2569
|
+
const faceTexture = face.texture.substr(1);
|
|
2570
|
+
const texPosition = positions[faceTexture] || [0, 0];
|
|
2571
|
+
const texSize = sizes[faceTexture] || [16, 16];
|
|
2384
2572
|
let texPosV = new import_three8.Vector2(texPosition[0], texPosition[1]);
|
|
2385
2573
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2386
2574
|
tl.add(texPosV);
|
|
@@ -2412,7 +2600,7 @@ var UVMapper = class {
|
|
|
2412
2600
|
hasTransparency
|
|
2413
2601
|
);
|
|
2414
2602
|
} else {
|
|
2415
|
-
console.warn(
|
|
2603
|
+
console.warn(p5, "Model does not have any textures", model);
|
|
2416
2604
|
}
|
|
2417
2605
|
return void 0;
|
|
2418
2606
|
}
|
|
@@ -2550,17 +2738,20 @@ function shutdown() {
|
|
|
2550
2738
|
}
|
|
2551
2739
|
|
|
2552
2740
|
// src/assets/Entities.ts
|
|
2553
|
-
var import_typescript_memoize3 = require("typescript-memoize");
|
|
2554
2741
|
var Entities = class {
|
|
2555
2742
|
static async getBlockEntityModels() {
|
|
2556
2743
|
const key = AssetKey.parse("models", "minerender:blockEntityModels");
|
|
2557
2744
|
console.log(key);
|
|
2558
|
-
return
|
|
2745
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2746
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2747
|
+
});
|
|
2559
2748
|
}
|
|
2560
2749
|
static async getEntityModels() {
|
|
2561
2750
|
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2562
2751
|
console.log(key);
|
|
2563
|
-
return
|
|
2752
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2753
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2754
|
+
});
|
|
2564
2755
|
}
|
|
2565
2756
|
// BlockEntity names are hardcoded
|
|
2566
2757
|
static async getBlockList() {
|
|
@@ -2606,12 +2797,6 @@ var Entities = class {
|
|
|
2606
2797
|
};
|
|
2607
2798
|
}
|
|
2608
2799
|
};
|
|
2609
|
-
__decorateClass([
|
|
2610
|
-
(0, import_typescript_memoize3.Memoize)()
|
|
2611
|
-
], Entities, "getBlockEntityModels", 1);
|
|
2612
|
-
__decorateClass([
|
|
2613
|
-
(0, import_typescript_memoize3.Memoize)()
|
|
2614
|
-
], Entities, "getEntityModels", 1);
|
|
2615
2800
|
var EntityModels = class {
|
|
2616
2801
|
};
|
|
2617
2802
|
var BlockEntityModels = class {
|
|
@@ -2675,8 +2860,8 @@ var MineRenderError = class _MineRenderError extends Error {
|
|
|
2675
2860
|
};
|
|
2676
2861
|
|
|
2677
2862
|
// src/renderer/SceneObject.ts
|
|
2678
|
-
var
|
|
2679
|
-
var
|
|
2863
|
+
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2864
|
+
var p6 = prefix("SceneObject");
|
|
2680
2865
|
var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
2681
2866
|
constructor(options) {
|
|
2682
2867
|
super();
|
|
@@ -2684,7 +2869,7 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2684
2869
|
this.materialCallbacks = {};
|
|
2685
2870
|
this._isInstanced = false;
|
|
2686
2871
|
this._instanceCounter = 0;
|
|
2687
|
-
this.options = (0,
|
|
2872
|
+
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2688
2873
|
console.log("SceneObject options", this.options);
|
|
2689
2874
|
}
|
|
2690
2875
|
set scene(scene) {
|
|
@@ -2778,6 +2963,7 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2778
2963
|
}
|
|
2779
2964
|
createInstancedMesh(name, geometry, material, count) {
|
|
2780
2965
|
const mesh = new import_three9.InstancedMesh(geometry, material, count);
|
|
2966
|
+
mesh.count = 0;
|
|
2781
2967
|
if (name) {
|
|
2782
2968
|
mesh.name = `mesh:${name}`;
|
|
2783
2969
|
}
|
|
@@ -2855,9 +3041,13 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2855
3041
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2856
3042
|
const i = this._instanceCounter++;
|
|
2857
3043
|
this.setMatrixAt(i, new import_three9.Matrix4());
|
|
2858
|
-
|
|
3044
|
+
const mesh = this.children[0];
|
|
3045
|
+
if (mesh && isInstancedMesh(mesh)) {
|
|
3046
|
+
mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
|
|
3047
|
+
}
|
|
3048
|
+
console.debug(p6, "nextInstance " + i);
|
|
2859
3049
|
if (i === this.options.maxInstanceCount) {
|
|
2860
|
-
console.warn(
|
|
3050
|
+
console.warn(p6, "Max instance count reached for " + this);
|
|
2861
3051
|
}
|
|
2862
3052
|
if (this.scene) {
|
|
2863
3053
|
this.scene.stats.instanceCount++;
|
|
@@ -3033,7 +3223,7 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
3033
3223
|
}
|
|
3034
3224
|
//</editor-fold>
|
|
3035
3225
|
};
|
|
3036
|
-
_SceneObject.DEFAULT_OPTIONS = (0,
|
|
3226
|
+
_SceneObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge3.default)({}, {
|
|
3037
3227
|
instanceMeshes: true,
|
|
3038
3228
|
maxInstanceCount: 50,
|
|
3039
3229
|
mergeMeshes: true,
|
|
@@ -3045,16 +3235,16 @@ function isSceneObject(obj) {
|
|
|
3045
3235
|
}
|
|
3046
3236
|
|
|
3047
3237
|
// src/entity/scene/EntityObject.ts
|
|
3048
|
-
var
|
|
3238
|
+
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
3049
3239
|
var import_three11 = require("three");
|
|
3050
|
-
var
|
|
3240
|
+
var THREE3 = __toESM(require("three"));
|
|
3051
3241
|
var EntityObject = class extends SceneObject {
|
|
3052
3242
|
constructor(entity, options) {
|
|
3053
3243
|
super();
|
|
3054
3244
|
this.entity = entity;
|
|
3055
3245
|
this.isEntityObject = true;
|
|
3056
3246
|
this.meshesCreated = false;
|
|
3057
|
-
this.options = (0,
|
|
3247
|
+
this.options = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
3058
3248
|
}
|
|
3059
3249
|
async init() {
|
|
3060
3250
|
this.createMeshes();
|
|
@@ -3063,8 +3253,8 @@ var EntityObject = class extends SceneObject {
|
|
|
3063
3253
|
dispose() {
|
|
3064
3254
|
super.dispose();
|
|
3065
3255
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3256
|
+
get textureKey() {
|
|
3257
|
+
return new AssetKey(
|
|
3068
3258
|
this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
|
|
3069
3259
|
this.entity.key.path,
|
|
3070
3260
|
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
@@ -3072,7 +3262,10 @@ var EntityObject = class extends SceneObject {
|
|
|
3072
3262
|
"entity",
|
|
3073
3263
|
"assets",
|
|
3074
3264
|
".png"
|
|
3075
|
-
)
|
|
3265
|
+
);
|
|
3266
|
+
}
|
|
3267
|
+
async loadTextures() {
|
|
3268
|
+
this.imageData = await ModelTextures.get(this.textureKey);
|
|
3076
3269
|
}
|
|
3077
3270
|
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
3078
3271
|
createMeshes(force = false) {
|
|
@@ -3091,8 +3284,8 @@ var EntityObject = class extends SceneObject {
|
|
|
3091
3284
|
const l = cube.maxZ - cube.minZ;
|
|
3092
3285
|
const uv = texture.toUvArray(w, h, l);
|
|
3093
3286
|
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
3094
|
-
cubeGeo.applyMatrix4(new
|
|
3095
|
-
cubeGeo.applyMatrix4(new
|
|
3287
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3288
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
3096
3289
|
applyModelPartRotation(part, cubeGeo);
|
|
3097
3290
|
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
3098
3291
|
partAnchor.add(mesh);
|
|
@@ -3105,23 +3298,26 @@ var EntityObject = class extends SceneObject {
|
|
|
3105
3298
|
this.meshesCreated = true;
|
|
3106
3299
|
}
|
|
3107
3300
|
async applyTextures() {
|
|
3108
|
-
const
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3301
|
+
const assetKeyStr = this.textureKey.serialize();
|
|
3302
|
+
const keyStr = `entity:${assetKeyStr}`;
|
|
3303
|
+
let mat = Caching.materialCache.getIfPresent(keyStr);
|
|
3304
|
+
if (!mat) {
|
|
3305
|
+
const pending = this.loadTextures();
|
|
3306
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
3307
|
+
await pending;
|
|
3308
|
+
if (!this.imageData) return;
|
|
3309
|
+
const canvas = this.imageData.data.canvas;
|
|
3310
|
+
const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
|
|
3311
|
+
mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
3312
|
+
this.imageData = void 0;
|
|
3313
|
+
}
|
|
3314
|
+
this.iterateAllMeshes((mesh) => {
|
|
3315
|
+
mesh.material = mat;
|
|
3316
|
+
});
|
|
3317
|
+
this.notifyDirty();
|
|
3122
3318
|
}
|
|
3123
3319
|
};
|
|
3124
|
-
EntityObject.DEFAULT_OPTIONS = (0,
|
|
3320
|
+
EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
3125
3321
|
function isEntityObject(obj) {
|
|
3126
3322
|
return obj.isEntityObject;
|
|
3127
3323
|
}
|
|
@@ -3133,7 +3329,7 @@ var GuiObject = class extends SceneObject {
|
|
|
3133
3329
|
|
|
3134
3330
|
// src/inspector/SceneInspector.ts
|
|
3135
3331
|
var import_three12 = require("three");
|
|
3136
|
-
var
|
|
3332
|
+
var p7 = prefix("SceneInspector");
|
|
3137
3333
|
var help = "<span>Ctrl+Click to Select<br/></span><br/>";
|
|
3138
3334
|
var SceneInspector = class {
|
|
3139
3335
|
constructor(renderer) {
|
|
@@ -3202,7 +3398,7 @@ var SceneInspector = class {
|
|
|
3202
3398
|
}
|
|
3203
3399
|
selectObject(targetObject, targetIntersection) {
|
|
3204
3400
|
this.selectedObject = targetObject;
|
|
3205
|
-
console.log(
|
|
3401
|
+
console.log(p7, "selected", targetObject);
|
|
3206
3402
|
this.redraw(targetObject, targetIntersection);
|
|
3207
3403
|
}
|
|
3208
3404
|
redraw(targetObject, targetIntersection) {
|
|
@@ -3500,7 +3696,7 @@ var SceneStatsDisplay = class {
|
|
|
3500
3696
|
};
|
|
3501
3697
|
|
|
3502
3698
|
// src/instance/InstanceManager.ts
|
|
3503
|
-
var
|
|
3699
|
+
var p8 = prefix("InstanceManager");
|
|
3504
3700
|
var InstanceManager = class {
|
|
3505
3701
|
constructor() {
|
|
3506
3702
|
this.isInstanceManager = true;
|
|
@@ -3508,7 +3704,7 @@ var InstanceManager = class {
|
|
|
3508
3704
|
}
|
|
3509
3705
|
async get(key) {
|
|
3510
3706
|
if (key in this.instanceCache) {
|
|
3511
|
-
console.debug(
|
|
3707
|
+
console.debug(p8, "key in cache", key);
|
|
3512
3708
|
return (await this.instanceCache[key]).nextInstance();
|
|
3513
3709
|
}
|
|
3514
3710
|
return void 0;
|
|
@@ -3517,13 +3713,17 @@ var InstanceManager = class {
|
|
|
3517
3713
|
if (key in this.instanceCache) {
|
|
3518
3714
|
return await this.get(key);
|
|
3519
3715
|
}
|
|
3520
|
-
console.debug(
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
})
|
|
3526
|
-
|
|
3716
|
+
console.debug(p8, "key not in cache", key);
|
|
3717
|
+
const pending = Promise.resolve().then(supplier).then((obj) => obj.nextInstance());
|
|
3718
|
+
this.instanceCache[key] = pending;
|
|
3719
|
+
try {
|
|
3720
|
+
return await pending;
|
|
3721
|
+
} catch (error) {
|
|
3722
|
+
if (this.instanceCache[key] === pending) {
|
|
3723
|
+
delete this.instanceCache[key];
|
|
3724
|
+
}
|
|
3725
|
+
throw error;
|
|
3726
|
+
}
|
|
3527
3727
|
}
|
|
3528
3728
|
reset() {
|
|
3529
3729
|
for (let instanceCacheKey in this.instanceCache) {
|
|
@@ -4112,15 +4312,16 @@ function computeMorphedAttributes(object) {
|
|
|
4112
4312
|
}
|
|
4113
4313
|
|
|
4114
4314
|
// src/model/scene/ModelObject.ts
|
|
4115
|
-
var
|
|
4116
|
-
var
|
|
4315
|
+
var import_ts_deepmerge5 = __toESM(require_dist());
|
|
4316
|
+
var p9 = prefix("ModelObject");
|
|
4117
4317
|
var _ModelObject = class _ModelObject extends SceneObject {
|
|
4118
4318
|
constructor(originalModel, options) {
|
|
4119
4319
|
super(options);
|
|
4120
4320
|
this.originalModel = originalModel;
|
|
4121
4321
|
this.isModelObject = true;
|
|
4122
4322
|
this.meshesCreated = false;
|
|
4123
|
-
this.options = (0,
|
|
4323
|
+
this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
|
|
4324
|
+
if (this.options.tints) this.options.tints = { ...this.options.tints };
|
|
4124
4325
|
console.log("ModelObject options", this.options);
|
|
4125
4326
|
}
|
|
4126
4327
|
async init() {
|
|
@@ -4147,6 +4348,23 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4147
4348
|
if (this.atlas.model.elements) {
|
|
4148
4349
|
this.atlas.model.elements?.forEach((el) => {
|
|
4149
4350
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4351
|
+
if (this.options.uvLockRotation) {
|
|
4352
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
|
|
4353
|
+
}
|
|
4354
|
+
if (this.options.tints) {
|
|
4355
|
+
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
4356
|
+
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
4357
|
+
const tintIndex = el.faces[faceName]?.tintindex;
|
|
4358
|
+
if (tintIndex === void 0 || tintIndex < 0) continue;
|
|
4359
|
+
const tint = this.options.tints[tintIndex];
|
|
4360
|
+
if (tint === void 0) continue;
|
|
4361
|
+
const color = new import_three15.Color(tint);
|
|
4362
|
+
for (let vertex = 0; vertex < 4; vertex++) {
|
|
4363
|
+
color.toArray(colors, (faceIndex * 4 + vertex) * 3);
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
elGeo.setAttribute("color", new import_three15.BufferAttribute(colors, 3));
|
|
4367
|
+
}
|
|
4150
4368
|
elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
|
|
4151
4369
|
elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
4152
4370
|
if (el.rotation) {
|
|
@@ -4163,10 +4381,10 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4163
4381
|
}
|
|
4164
4382
|
});
|
|
4165
4383
|
} else {
|
|
4166
|
-
console.debug(
|
|
4384
|
+
console.debug(p9, this.atlas.model, "has no elements");
|
|
4167
4385
|
}
|
|
4168
4386
|
} else {
|
|
4169
|
-
console.debug(
|
|
4387
|
+
console.debug(p9, "Missing atlas for", this);
|
|
4170
4388
|
}
|
|
4171
4389
|
if (this.options.mergeMeshes) {
|
|
4172
4390
|
let combinedGeo;
|
|
@@ -4203,6 +4421,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4203
4421
|
/*TODO: get this from render options*/
|
|
4204
4422
|
);
|
|
4205
4423
|
this.iterateAllMeshes((mesh) => {
|
|
4424
|
+
if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
|
|
4206
4425
|
mesh.material = mat;
|
|
4207
4426
|
});
|
|
4208
4427
|
if (this.atlas.hasAnimation) {
|
|
@@ -4218,16 +4437,26 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4218
4437
|
}
|
|
4219
4438
|
}
|
|
4220
4439
|
};
|
|
4221
|
-
_ModelObject.DEFAULT_OPTIONS = (0,
|
|
4440
|
+
_ModelObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4222
4441
|
var ModelObject = _ModelObject;
|
|
4223
4442
|
function isModelObject(obj) {
|
|
4224
4443
|
return obj.isModelObject;
|
|
4225
4444
|
}
|
|
4226
4445
|
|
|
4227
4446
|
// src/model/block/scene/BlockObject.ts
|
|
4228
|
-
var
|
|
4447
|
+
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4229
4448
|
var import_three16 = require("three");
|
|
4230
|
-
var
|
|
4449
|
+
var p10 = prefix("BlockObject");
|
|
4450
|
+
function matchesCondition(condition, state) {
|
|
4451
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4452
|
+
if (Array.isArray(value)) {
|
|
4453
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4454
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4455
|
+
return false;
|
|
4456
|
+
}
|
|
4457
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4458
|
+
});
|
|
4459
|
+
}
|
|
4231
4460
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
4232
4461
|
constructor(blockState, options) {
|
|
4233
4462
|
super(options);
|
|
@@ -4241,11 +4470,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4241
4470
|
this._instanceModel = [];
|
|
4242
4471
|
this._variants = [];
|
|
4243
4472
|
this._models = [];
|
|
4244
|
-
this.options = (0,
|
|
4473
|
+
this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
|
|
4245
4474
|
}
|
|
4246
4475
|
async init() {
|
|
4247
4476
|
if (this.options.applyDefaultState) {
|
|
4248
|
-
const defaultState = this.blockState.key ? BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4477
|
+
const defaultState = this.blockState.key ? await BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4249
4478
|
if (defaultState && Object.keys(defaultState).length > 0) {
|
|
4250
4479
|
const state = {};
|
|
4251
4480
|
for (let k in defaultState) {
|
|
@@ -4256,15 +4485,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4256
4485
|
if (this.blockState.variants) {
|
|
4257
4486
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4258
4487
|
} else if (this.blockState.multipart) {
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
if (k) {
|
|
4263
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4264
|
-
break;
|
|
4265
|
-
}
|
|
4266
|
-
}
|
|
4267
|
-
}
|
|
4488
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4489
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4490
|
+
await this.setState(state);
|
|
4268
4491
|
}
|
|
4269
4492
|
}
|
|
4270
4493
|
} else {
|
|
@@ -4321,55 +4544,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4321
4544
|
} else if (this.blockState.multipart) {
|
|
4322
4545
|
for (let part of this.blockState.multipart) {
|
|
4323
4546
|
if (!part.apply) {
|
|
4324
|
-
console.debug(
|
|
4547
|
+
console.debug(p10, "Missing apply for blockState part", part);
|
|
4325
4548
|
continue;
|
|
4326
4549
|
}
|
|
4327
|
-
if (!part.when) {
|
|
4550
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4328
4551
|
out.push(this.getSingleVariant(part.apply));
|
|
4329
|
-
} else {
|
|
4330
|
-
let matches = true;
|
|
4331
|
-
if ("OR" in part.when) {
|
|
4332
|
-
const or = part.when.OR;
|
|
4333
|
-
let anyMatch = false;
|
|
4334
|
-
for (let o of or) {
|
|
4335
|
-
for (let k in o) {
|
|
4336
|
-
const split = o[k].split("|");
|
|
4337
|
-
let m = false;
|
|
4338
|
-
for (let s of split) {
|
|
4339
|
-
if (`${state[k]}` === `${s}`) {
|
|
4340
|
-
m = true;
|
|
4341
|
-
break;
|
|
4342
|
-
}
|
|
4343
|
-
}
|
|
4344
|
-
if (m) {
|
|
4345
|
-
anyMatch = true;
|
|
4346
|
-
break;
|
|
4347
|
-
}
|
|
4348
|
-
}
|
|
4349
|
-
}
|
|
4350
|
-
if (!anyMatch) {
|
|
4351
|
-
matches = false;
|
|
4352
|
-
}
|
|
4353
|
-
} else {
|
|
4354
|
-
for (let k in part.when) {
|
|
4355
|
-
const split = part.when[k].split("|");
|
|
4356
|
-
let m = false;
|
|
4357
|
-
for (let s of split) {
|
|
4358
|
-
if (`${state[k]}` === `${s}`) {
|
|
4359
|
-
m = true;
|
|
4360
|
-
break;
|
|
4361
|
-
}
|
|
4362
|
-
}
|
|
4363
|
-
if (!m) {
|
|
4364
|
-
matches = false;
|
|
4365
|
-
break;
|
|
4366
|
-
}
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
if (matches) {
|
|
4370
|
-
const variants = part.apply;
|
|
4371
|
-
out.push(this.getSingleVariant(variants));
|
|
4372
|
-
}
|
|
4373
4552
|
}
|
|
4374
4553
|
}
|
|
4375
4554
|
}
|
|
@@ -4399,11 +4578,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4399
4578
|
}
|
|
4400
4579
|
}
|
|
4401
4580
|
getSingleVariant(variants) {
|
|
4402
|
-
if (Array.isArray(variants))
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4581
|
+
if (!Array.isArray(variants)) return variants;
|
|
4582
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4583
|
+
const total = variants.reduce((sum, variant) => {
|
|
4584
|
+
const weight = variant.weight ?? 1;
|
|
4585
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4586
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4587
|
+
}
|
|
4588
|
+
return sum + weight;
|
|
4589
|
+
}, 0);
|
|
4590
|
+
let choice = Math.random() * total;
|
|
4591
|
+
for (const variant of variants) {
|
|
4592
|
+
choice -= variant.weight ?? 1;
|
|
4593
|
+
if (choice < 0) return variant;
|
|
4594
|
+
}
|
|
4595
|
+
return variants[variants.length - 1];
|
|
4407
4596
|
}
|
|
4408
4597
|
// @deprecated
|
|
4409
4598
|
async createAVariant(variants, instanceInfo) {
|
|
@@ -4411,28 +4600,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4411
4600
|
await this.createVariant(variant);
|
|
4412
4601
|
}
|
|
4413
4602
|
async createVariant(variant) {
|
|
4414
|
-
const
|
|
4415
|
-
const obj = await this.scene.addModel(model, this.options);
|
|
4416
|
-
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4417
|
-
this._isInstanced = true;
|
|
4418
|
-
this._instanceCounter = 1;
|
|
4419
|
-
}
|
|
4420
|
-
let rotation = new import_three16.Euler(0, 0, 0);
|
|
4603
|
+
const rotation = new import_three16.Euler();
|
|
4421
4604
|
if (typeof variant.x !== "undefined") {
|
|
4422
4605
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4423
4606
|
}
|
|
4424
4607
|
if (typeof variant.y !== "undefined") {
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4608
|
+
rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
|
|
4609
|
+
}
|
|
4610
|
+
const model = await Models.getMerged(AssetKey.parse("models", variant.model));
|
|
4611
|
+
const options = {
|
|
4612
|
+
...this.options,
|
|
4613
|
+
uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
|
|
4614
|
+
};
|
|
4615
|
+
const obj = await this.scene.addModel(model, options);
|
|
4616
|
+
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4617
|
+
this._isInstanced = true;
|
|
4618
|
+
this._instanceCounter = 1;
|
|
4430
4619
|
}
|
|
4431
4620
|
obj.setRotation(rotation);
|
|
4432
|
-
setTimeout(() => {
|
|
4433
|
-
obj.setRotation(rotation);
|
|
4434
|
-
}, 150);
|
|
4435
|
-
console.log(obj);
|
|
4436
4621
|
return obj;
|
|
4437
4622
|
}
|
|
4438
4623
|
async resetState() {
|
|
@@ -4522,15 +4707,16 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4522
4707
|
}
|
|
4523
4708
|
}
|
|
4524
4709
|
setPosition(position) {
|
|
4525
|
-
|
|
4710
|
+
this.position.copy(position);
|
|
4526
4711
|
for (let model of this._models) {
|
|
4527
4712
|
model.setPosition(position);
|
|
4528
4713
|
}
|
|
4714
|
+
this.notifyDirty();
|
|
4529
4715
|
}
|
|
4530
4716
|
//TODO: should override rotation + scale methods
|
|
4531
4717
|
//TODO
|
|
4532
4718
|
};
|
|
4533
|
-
_BlockObject.DEFAULT_OPTIONS = (0,
|
|
4719
|
+
_BlockObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4534
4720
|
applyDefaultState: true
|
|
4535
4721
|
});
|
|
4536
4722
|
var BlockObject = _BlockObject;
|
|
@@ -4580,7 +4766,7 @@ var StructureParser = class {
|
|
|
4580
4766
|
|
|
4581
4767
|
// src/renderer/MineRenderScene.ts
|
|
4582
4768
|
var import_three17 = require("three");
|
|
4583
|
-
var
|
|
4769
|
+
var import_ts_deepmerge8 = __toESM(require_dist());
|
|
4584
4770
|
|
|
4585
4771
|
// src/skin/SkinPart.ts
|
|
4586
4772
|
var SkinPart = /* @__PURE__ */ ((SkinPart2) => {
|
|
@@ -5311,7 +5497,7 @@ var slimSkinGeometries = {
|
|
|
5311
5497
|
};
|
|
5312
5498
|
|
|
5313
5499
|
// src/skin/scene/SkinObject.ts
|
|
5314
|
-
var
|
|
5500
|
+
var import_ts_deepmerge7 = __toESM(require_dist());
|
|
5315
5501
|
var SkinObject = class extends SceneObject {
|
|
5316
5502
|
constructor(options) {
|
|
5317
5503
|
super();
|
|
@@ -5319,7 +5505,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5319
5505
|
this.legacy = false;
|
|
5320
5506
|
this.skinTextureWidth = 64;
|
|
5321
5507
|
this.skinTextureHeight = 64;
|
|
5322
|
-
this.options = (0,
|
|
5508
|
+
this.options = (0, import_ts_deepmerge7.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
5323
5509
|
}
|
|
5324
5510
|
async init() {
|
|
5325
5511
|
this.createMeshes();
|
|
@@ -5436,7 +5622,7 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
|
|
|
5436
5622
|
this.dirty = true;
|
|
5437
5623
|
}
|
|
5438
5624
|
};
|
|
5439
|
-
this.options = (0,
|
|
5625
|
+
this.options = (0, import_ts_deepmerge8.default)({}, _MineRenderScene.DEFAULT_OPTIONS, options ?? {});
|
|
5440
5626
|
}
|
|
5441
5627
|
add(...objects) {
|
|
5442
5628
|
for (const object of objects) {
|
|
@@ -5494,7 +5680,13 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
|
|
|
5494
5680
|
const obj = await objectSupplier();
|
|
5495
5681
|
if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
|
|
5496
5682
|
console.log("instanceMeshes + key");
|
|
5497
|
-
|
|
5683
|
+
let key = asset.key.serialize();
|
|
5684
|
+
if (isModelObject(obj)) {
|
|
5685
|
+
const { uvLockRotation, tints } = obj.options;
|
|
5686
|
+
if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
|
|
5687
|
+
const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
|
|
5688
|
+
if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
|
|
5689
|
+
}
|
|
5498
5690
|
return this.instanceManager.getOrCreate(key, async () => {
|
|
5499
5691
|
obj.scene = this;
|
|
5500
5692
|
await obj.init();
|
|
@@ -5532,1106 +5724,1163 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
|
|
|
5532
5724
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
5533
5725
|
}
|
|
5534
5726
|
};
|
|
5535
|
-
_MineRenderScene.DEFAULT_OPTIONS = (0,
|
|
5727
|
+
_MineRenderScene.DEFAULT_OPTIONS = (0, import_ts_deepmerge8.default)({}, {});
|
|
5536
5728
|
var MineRenderScene = _MineRenderScene;
|
|
5537
5729
|
function isMineRenderScene(obj) {
|
|
5538
5730
|
return obj.isMineRenderScene;
|
|
5539
5731
|
}
|
|
5540
5732
|
|
|
5541
5733
|
// src/renderer/Renderer.ts
|
|
5542
|
-
var
|
|
5543
|
-
var
|
|
5734
|
+
var import_three19 = require("three");
|
|
5735
|
+
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
5544
5736
|
var import_stats = __toESM(require("stats.js"));
|
|
5545
5737
|
var import_postprocessing = require("postprocessing");
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5738
|
+
|
|
5739
|
+
// src/three/OrbitControls.js
|
|
5740
|
+
var import_three18 = require("three");
|
|
5741
|
+
var _changeEvent = { type: "change" };
|
|
5742
|
+
var _startEvent = { type: "start" };
|
|
5743
|
+
var _endEvent = { type: "end" };
|
|
5744
|
+
var OrbitControls = class extends import_three18.EventDispatcher {
|
|
5745
|
+
constructor(object, domElement) {
|
|
5746
|
+
super();
|
|
5747
|
+
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
5748
|
+
if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
|
5749
|
+
this.object = object;
|
|
5750
|
+
this.domElement = domElement;
|
|
5751
|
+
this.domElement.style.touchAction = "none";
|
|
5752
|
+
this.enabled = true;
|
|
5753
|
+
this.target = new import_three18.Vector3();
|
|
5754
|
+
this.minDistance = 0;
|
|
5755
|
+
this.maxDistance = Infinity;
|
|
5756
|
+
this.minZoom = 0;
|
|
5757
|
+
this.maxZoom = Infinity;
|
|
5758
|
+
this.minPolarAngle = 0;
|
|
5759
|
+
this.maxPolarAngle = Math.PI;
|
|
5760
|
+
this.minAzimuthAngle = -Infinity;
|
|
5761
|
+
this.maxAzimuthAngle = Infinity;
|
|
5762
|
+
this.enableDamping = false;
|
|
5763
|
+
this.dampingFactor = 0.05;
|
|
5764
|
+
this.enableZoom = true;
|
|
5765
|
+
this.zoomSpeed = 1;
|
|
5766
|
+
this.enableRotate = true;
|
|
5767
|
+
this.rotateSpeed = 1;
|
|
5768
|
+
this.enablePan = true;
|
|
5769
|
+
this.panSpeed = 1;
|
|
5770
|
+
this.screenSpacePanning = true;
|
|
5771
|
+
this.keyPanSpeed = 7;
|
|
5772
|
+
this.autoRotate = false;
|
|
5773
|
+
this.autoRotateSpeed = 2;
|
|
5774
|
+
this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
|
|
5775
|
+
this.mouseButtons = { LEFT: import_three18.MOUSE.ROTATE, MIDDLE: import_three18.MOUSE.DOLLY, RIGHT: import_three18.MOUSE.PAN };
|
|
5776
|
+
this.touches = { ONE: import_three18.TOUCH.ROTATE, TWO: import_three18.TOUCH.DOLLY_PAN };
|
|
5777
|
+
this.target0 = this.target.clone();
|
|
5778
|
+
this.position0 = this.object.position.clone();
|
|
5779
|
+
this.zoom0 = this.object.zoom;
|
|
5780
|
+
this._domElementKeyEvents = null;
|
|
5781
|
+
this.getPolarAngle = function() {
|
|
5782
|
+
return spherical.phi;
|
|
5557
5783
|
};
|
|
5558
|
-
this.
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
this.
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
this.
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5784
|
+
this.getAzimuthalAngle = function() {
|
|
5785
|
+
return spherical.theta;
|
|
5786
|
+
};
|
|
5787
|
+
this.getDistance = function() {
|
|
5788
|
+
return this.object.position.distanceTo(this.target);
|
|
5789
|
+
};
|
|
5790
|
+
this.saveState = function() {
|
|
5791
|
+
scope.target0.copy(scope.target);
|
|
5792
|
+
scope.position0.copy(scope.object.position);
|
|
5793
|
+
scope.zoom0 = scope.object.zoom;
|
|
5794
|
+
};
|
|
5795
|
+
this.reset = function() {
|
|
5796
|
+
scope.target.copy(scope.target0);
|
|
5797
|
+
scope.object.position.copy(scope.position0);
|
|
5798
|
+
scope.object.zoom = scope.zoom0;
|
|
5799
|
+
scope.object.updateProjectionMatrix();
|
|
5800
|
+
scope.dispatchEvent(_changeEvent);
|
|
5801
|
+
scope.update();
|
|
5802
|
+
state = STATE.NONE;
|
|
5803
|
+
};
|
|
5804
|
+
this.update = function() {
|
|
5805
|
+
const offset = new import_three18.Vector3();
|
|
5806
|
+
const quat = new import_three18.Quaternion().setFromUnitVectors(object.up, new import_three18.Vector3(0, 1, 0));
|
|
5807
|
+
const quatInverse = quat.clone().invert();
|
|
5808
|
+
const lastPosition = new import_three18.Vector3();
|
|
5809
|
+
const lastQuaternion = new import_three18.Quaternion();
|
|
5810
|
+
const twoPI = 2 * Math.PI;
|
|
5811
|
+
return function update() {
|
|
5812
|
+
const position = scope.object.position;
|
|
5813
|
+
offset.copy(position).sub(scope.target);
|
|
5814
|
+
offset.applyQuaternion(quat);
|
|
5815
|
+
spherical.setFromVector3(offset);
|
|
5816
|
+
if (scope.autoRotate && state === STATE.NONE) {
|
|
5817
|
+
rotateLeft(getAutoRotationAngle());
|
|
5818
|
+
}
|
|
5819
|
+
if (scope.enableDamping) {
|
|
5820
|
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
5821
|
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
5822
|
+
} else {
|
|
5823
|
+
spherical.theta += sphericalDelta.theta;
|
|
5824
|
+
spherical.phi += sphericalDelta.phi;
|
|
5825
|
+
}
|
|
5826
|
+
let min = scope.minAzimuthAngle;
|
|
5827
|
+
let max = scope.maxAzimuthAngle;
|
|
5828
|
+
if (isFinite(min) && isFinite(max)) {
|
|
5829
|
+
if (min < -Math.PI) min += twoPI;
|
|
5830
|
+
else if (min > Math.PI) min -= twoPI;
|
|
5831
|
+
if (max < -Math.PI) max += twoPI;
|
|
5832
|
+
else if (max > Math.PI) max -= twoPI;
|
|
5833
|
+
if (min <= max) {
|
|
5834
|
+
spherical.theta = Math.max(min, Math.min(max, spherical.theta));
|
|
5835
|
+
} else {
|
|
5836
|
+
spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
|
|
5840
|
+
spherical.makeSafe();
|
|
5841
|
+
spherical.radius *= scale;
|
|
5842
|
+
spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
|
|
5843
|
+
if (scope.enableDamping === true) {
|
|
5844
|
+
scope.target.addScaledVector(panOffset, scope.dampingFactor);
|
|
5845
|
+
} else {
|
|
5846
|
+
scope.target.add(panOffset);
|
|
5847
|
+
}
|
|
5848
|
+
offset.setFromSpherical(spherical);
|
|
5849
|
+
offset.applyQuaternion(quatInverse);
|
|
5850
|
+
position.copy(scope.target).add(offset);
|
|
5851
|
+
scope.object.lookAt(scope.target);
|
|
5852
|
+
if (scope.enableDamping === true) {
|
|
5853
|
+
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
5854
|
+
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
5855
|
+
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
5856
|
+
} else {
|
|
5857
|
+
sphericalDelta.set(0, 0, 0);
|
|
5858
|
+
panOffset.set(0, 0, 0);
|
|
5859
|
+
}
|
|
5860
|
+
scale = 1;
|
|
5861
|
+
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
5862
|
+
scope.dispatchEvent(_changeEvent);
|
|
5863
|
+
lastPosition.copy(scope.object.position);
|
|
5864
|
+
lastQuaternion.copy(scope.object.quaternion);
|
|
5865
|
+
zoomChanged = false;
|
|
5866
|
+
return true;
|
|
5867
|
+
}
|
|
5868
|
+
return false;
|
|
5869
|
+
};
|
|
5870
|
+
}();
|
|
5871
|
+
this.dispose = function() {
|
|
5872
|
+
scope.domElement.removeEventListener("contextmenu", onContextMenu);
|
|
5873
|
+
scope.domElement.removeEventListener("pointerdown", onPointerDown);
|
|
5874
|
+
scope.domElement.removeEventListener("pointercancel", onPointerCancel);
|
|
5875
|
+
scope.domElement.removeEventListener("wheel", onMouseWheel);
|
|
5876
|
+
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
5877
|
+
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
5878
|
+
if (scope._domElementKeyEvents !== null) {
|
|
5879
|
+
scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
5880
|
+
}
|
|
5881
|
+
};
|
|
5882
|
+
const scope = this;
|
|
5883
|
+
const STATE = {
|
|
5884
|
+
NONE: -1,
|
|
5885
|
+
ROTATE: 0,
|
|
5886
|
+
DOLLY: 1,
|
|
5887
|
+
PAN: 2,
|
|
5888
|
+
TOUCH_ROTATE: 3,
|
|
5889
|
+
TOUCH_PAN: 4,
|
|
5890
|
+
TOUCH_DOLLY_PAN: 5,
|
|
5891
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
5892
|
+
};
|
|
5893
|
+
let state = STATE.NONE;
|
|
5894
|
+
const EPS = 1e-6;
|
|
5895
|
+
const spherical = new import_three18.Spherical();
|
|
5896
|
+
const sphericalDelta = new import_three18.Spherical();
|
|
5897
|
+
let scale = 1;
|
|
5898
|
+
const panOffset = new import_three18.Vector3();
|
|
5899
|
+
let zoomChanged = false;
|
|
5900
|
+
const rotateStart = new import_three18.Vector2();
|
|
5901
|
+
const rotateEnd = new import_three18.Vector2();
|
|
5902
|
+
const rotateDelta = new import_three18.Vector2();
|
|
5903
|
+
const panStart = new import_three18.Vector2();
|
|
5904
|
+
const panEnd = new import_three18.Vector2();
|
|
5905
|
+
const panDelta = new import_three18.Vector2();
|
|
5906
|
+
const dollyStart = new import_three18.Vector2();
|
|
5907
|
+
const dollyEnd = new import_three18.Vector2();
|
|
5908
|
+
const dollyDelta = new import_three18.Vector2();
|
|
5909
|
+
const pointers = [];
|
|
5910
|
+
const pointerPositions = {};
|
|
5911
|
+
function getAutoRotationAngle() {
|
|
5912
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
5568
5913
|
}
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
//<editor-fold desc="INIT">
|
|
5572
|
-
createScene() {
|
|
5573
|
-
return new MineRenderScene();
|
|
5574
|
-
}
|
|
5575
|
-
createCamera() {
|
|
5576
|
-
switch (this.options.camera.type) {
|
|
5577
|
-
case "perspective":
|
|
5578
|
-
default:
|
|
5579
|
-
return new import_three18.PerspectiveCamera(
|
|
5580
|
-
this.options.camera.perspective.fov,
|
|
5581
|
-
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
5582
|
-
this.options.camera.near,
|
|
5583
|
-
this.options.camera.far
|
|
5584
|
-
);
|
|
5585
|
-
case "orthographic":
|
|
5586
|
-
return new import_three18.OrthographicCamera(
|
|
5587
|
-
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
5588
|
-
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
5589
|
-
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
5590
|
-
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
5591
|
-
this.options.camera.near,
|
|
5592
|
-
this.options.camera.far
|
|
5593
|
-
);
|
|
5914
|
+
function getZoomScale() {
|
|
5915
|
+
return Math.pow(0.95, scope.zoomSpeed);
|
|
5594
5916
|
}
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
const renderer = new import_three18.WebGLRenderer({
|
|
5598
|
-
antialias: this.options.render.antialias,
|
|
5599
|
-
alpha: true,
|
|
5600
|
-
powerPreference: "high-performance",
|
|
5601
|
-
depth: true
|
|
5602
|
-
});
|
|
5603
|
-
renderer.setClearColor(0, 0);
|
|
5604
|
-
renderer.shadowMap.enabled = true;
|
|
5605
|
-
renderer.shadowMap.type = import_three18.PCFSoftShadowMap;
|
|
5606
|
-
renderer.outputEncoding = import_three18.LinearEncoding;
|
|
5607
|
-
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
5608
|
-
return renderer;
|
|
5609
|
-
}
|
|
5610
|
-
createComposer() {
|
|
5611
|
-
const composer = new import_postprocessing.EffectComposer(this.renderer);
|
|
5612
|
-
if (!this.options.composer.enabled) return composer;
|
|
5613
|
-
composer.setSize(this.viewWidth, this.viewHeight);
|
|
5614
|
-
composer.addPass(new import_postprocessing.RenderPass(this.scene, this.camera));
|
|
5615
|
-
return composer;
|
|
5616
|
-
}
|
|
5617
|
-
//</editor-fold>
|
|
5618
|
-
init() {
|
|
5619
|
-
if (this._disposed) return;
|
|
5620
|
-
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
5621
|
-
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
5622
|
-
}
|
|
5623
|
-
if (this.options.debug.grid) {
|
|
5624
|
-
const gridHelper = new import_three18.GridHelper(128, 16);
|
|
5625
|
-
this._debugHelpers.push(gridHelper);
|
|
5626
|
-
this.scene.add(gridHelper);
|
|
5627
|
-
const gridHelper2 = new import_three18.GridHelper(128, 16);
|
|
5628
|
-
this._debugHelpers.push(gridHelper2);
|
|
5629
|
-
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
5630
|
-
this.scene.add(gridHelper2);
|
|
5631
|
-
const gridHelper3 = new import_three18.GridHelper(128, 16);
|
|
5632
|
-
this._debugHelpers.push(gridHelper3);
|
|
5633
|
-
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
5634
|
-
this.scene.add(gridHelper3);
|
|
5917
|
+
function rotateLeft(angle) {
|
|
5918
|
+
sphericalDelta.theta -= angle;
|
|
5635
5919
|
}
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
this._debugHelpers.push(axesHelper);
|
|
5639
|
-
this.scene.add(axesHelper);
|
|
5920
|
+
function rotateUp(angle) {
|
|
5921
|
+
sphericalDelta.phi -= angle;
|
|
5640
5922
|
}
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5923
|
+
const panLeft = function() {
|
|
5924
|
+
const v = new import_three18.Vector3();
|
|
5925
|
+
return function panLeft2(distance, objectMatrix) {
|
|
5926
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
5927
|
+
v.multiplyScalar(-distance);
|
|
5928
|
+
panOffset.add(v);
|
|
5929
|
+
};
|
|
5930
|
+
}();
|
|
5931
|
+
const panUp = function() {
|
|
5932
|
+
const v = new import_three18.Vector3();
|
|
5933
|
+
return function panUp2(distance, objectMatrix) {
|
|
5934
|
+
if (scope.screenSpacePanning === true) {
|
|
5935
|
+
v.setFromMatrixColumn(objectMatrix, 1);
|
|
5936
|
+
} else {
|
|
5937
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
5938
|
+
v.crossVectors(scope.object.up, v);
|
|
5939
|
+
}
|
|
5940
|
+
v.multiplyScalar(distance);
|
|
5941
|
+
panOffset.add(v);
|
|
5942
|
+
};
|
|
5943
|
+
}();
|
|
5944
|
+
const pan = function() {
|
|
5945
|
+
const offset = new import_three18.Vector3();
|
|
5946
|
+
return function pan2(deltaX, deltaY) {
|
|
5947
|
+
const element = scope.domElement;
|
|
5948
|
+
if (scope.object.isPerspectiveCamera) {
|
|
5949
|
+
const position = scope.object.position;
|
|
5950
|
+
offset.copy(position).sub(scope.target);
|
|
5951
|
+
let targetDistance = offset.length();
|
|
5952
|
+
targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
|
|
5953
|
+
panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
|
|
5954
|
+
panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
|
|
5955
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
5956
|
+
panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
|
|
5957
|
+
panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
|
|
5958
|
+
} else {
|
|
5959
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
|
|
5960
|
+
scope.enablePan = false;
|
|
5961
|
+
}
|
|
5962
|
+
};
|
|
5963
|
+
}();
|
|
5964
|
+
function dollyOut(dollyScale) {
|
|
5965
|
+
if (scope.object.isPerspectiveCamera) {
|
|
5966
|
+
scale /= dollyScale;
|
|
5967
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
5968
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
|
|
5969
|
+
scope.object.updateProjectionMatrix();
|
|
5970
|
+
zoomChanged = true;
|
|
5971
|
+
} else {
|
|
5972
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
5973
|
+
scope.enableZoom = false;
|
|
5646
5974
|
}
|
|
5647
5975
|
}
|
|
5648
|
-
|
|
5649
|
-
if (
|
|
5650
|
-
|
|
5651
|
-
} else if (
|
|
5652
|
-
|
|
5976
|
+
function dollyIn(dollyScale) {
|
|
5977
|
+
if (scope.object.isPerspectiveCamera) {
|
|
5978
|
+
scale *= dollyScale;
|
|
5979
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
5980
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
|
|
5981
|
+
scope.object.updateProjectionMatrix();
|
|
5982
|
+
zoomChanged = true;
|
|
5983
|
+
} else {
|
|
5984
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
5985
|
+
scope.enableZoom = false;
|
|
5653
5986
|
}
|
|
5654
5987
|
}
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
this.resize(this.viewWidth, this.viewHeight);
|
|
5658
|
-
};
|
|
5659
|
-
window.addEventListener("resize", this._resizeListener);
|
|
5988
|
+
function handleMouseDownRotate(event) {
|
|
5989
|
+
rotateStart.set(event.clientX, event.clientY);
|
|
5660
5990
|
}
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
return this._element;
|
|
5664
|
-
}
|
|
5665
|
-
appendTo(element) {
|
|
5666
|
-
if (this._disposed) return;
|
|
5667
|
-
this._element = element;
|
|
5668
|
-
this._element.appendChild(this.renderer.domElement);
|
|
5669
|
-
if (this.viewWidth == 0) {
|
|
5670
|
-
console.warn("0 element width");
|
|
5991
|
+
function handleMouseDownDolly(event) {
|
|
5992
|
+
dollyStart.set(event.clientX, event.clientY);
|
|
5671
5993
|
}
|
|
5672
|
-
|
|
5673
|
-
|
|
5994
|
+
function handleMouseDownPan(event) {
|
|
5995
|
+
panStart.set(event.clientX, event.clientY);
|
|
5674
5996
|
}
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
let events = this._eventDispatchers.get(dispatcher);
|
|
5684
|
-
if (!events) {
|
|
5685
|
-
events = /* @__PURE__ */ new Set();
|
|
5686
|
-
this._eventDispatchers.set(dispatcher, events);
|
|
5997
|
+
function handleMouseMoveRotate(event) {
|
|
5998
|
+
rotateEnd.set(event.clientX, event.clientY);
|
|
5999
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
6000
|
+
const element = scope.domElement;
|
|
6001
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
6002
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
6003
|
+
rotateStart.copy(rotateEnd);
|
|
6004
|
+
scope.update();
|
|
5687
6005
|
}
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
this.camera.left = width / -2;
|
|
5699
|
-
this.camera.right = width / 2;
|
|
5700
|
-
this.camera.top = height / 2;
|
|
5701
|
-
this.camera.bottom = height / -2;
|
|
5702
|
-
this.camera.updateProjectionMatrix();
|
|
6006
|
+
function handleMouseMoveDolly(event) {
|
|
6007
|
+
dollyEnd.set(event.clientX, event.clientY);
|
|
6008
|
+
dollyDelta.subVectors(dollyEnd, dollyStart);
|
|
6009
|
+
if (dollyDelta.y > 0) {
|
|
6010
|
+
dollyOut(getZoomScale());
|
|
6011
|
+
} else if (dollyDelta.y < 0) {
|
|
6012
|
+
dollyIn(getZoomScale());
|
|
6013
|
+
}
|
|
6014
|
+
dollyStart.copy(dollyEnd);
|
|
6015
|
+
scope.update();
|
|
5703
6016
|
}
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
return this._dirty || this.scene.dirty;
|
|
5711
|
-
}
|
|
5712
|
-
set dirty(dirty) {
|
|
5713
|
-
this._dirty = dirty;
|
|
5714
|
-
this.scene.dirty = dirty;
|
|
5715
|
-
}
|
|
5716
|
-
start() {
|
|
5717
|
-
if (this._disposed) return;
|
|
5718
|
-
this.stop();
|
|
5719
|
-
this.renderer.setAnimationLoop(this._animationLoop);
|
|
5720
|
-
}
|
|
5721
|
-
stop() {
|
|
5722
|
-
if (this._disposed) return;
|
|
5723
|
-
this.renderer.setAnimationLoop(null);
|
|
5724
|
-
if (this._animationTimer)
|
|
5725
|
-
clearTimeout(this._animationTimer);
|
|
5726
|
-
this._animationTimer = void 0;
|
|
5727
|
-
if (this._animationFrame)
|
|
5728
|
-
cancelAnimationFrame(this._animationFrame);
|
|
5729
|
-
this._animationFrame = void 0;
|
|
5730
|
-
}
|
|
5731
|
-
/**
|
|
5732
|
-
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
5733
|
-
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
5734
|
-
* controls must be managed by their owners.
|
|
5735
|
-
*/
|
|
5736
|
-
dispose() {
|
|
5737
|
-
if (this._disposed) return;
|
|
5738
|
-
this.stop();
|
|
5739
|
-
this._disposed = true;
|
|
5740
|
-
if (this._resizeListener) {
|
|
5741
|
-
window.removeEventListener("resize", this._resizeListener);
|
|
5742
|
-
this._resizeListener = void 0;
|
|
6017
|
+
function handleMouseMovePan(event) {
|
|
6018
|
+
panEnd.set(event.clientX, event.clientY);
|
|
6019
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
6020
|
+
pan(panDelta.x, panDelta.y);
|
|
6021
|
+
panStart.copy(panEnd);
|
|
6022
|
+
scope.update();
|
|
5743
6023
|
}
|
|
5744
|
-
|
|
5745
|
-
for (const event of events) {
|
|
5746
|
-
dispatcher.removeEventListener(event, this._changeListener);
|
|
5747
|
-
}
|
|
6024
|
+
function handleMouseUp() {
|
|
5748
6025
|
}
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
this.scene.clear();
|
|
5755
|
-
for (const helper of this._debugHelpers) {
|
|
5756
|
-
helper.geometry.dispose();
|
|
5757
|
-
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
5758
|
-
for (const material of materials) {
|
|
5759
|
-
material.dispose();
|
|
6026
|
+
function handleMouseWheel(event) {
|
|
6027
|
+
if (event.deltaY < 0) {
|
|
6028
|
+
dollyIn(getZoomScale());
|
|
6029
|
+
} else if (event.deltaY > 0) {
|
|
6030
|
+
dollyOut(getZoomScale());
|
|
5760
6031
|
}
|
|
6032
|
+
scope.update();
|
|
5761
6033
|
}
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
6034
|
+
function handleKeyDown(event) {
|
|
6035
|
+
let needsUpdate = false;
|
|
6036
|
+
switch (event.code) {
|
|
6037
|
+
case scope.keys.UP:
|
|
6038
|
+
pan(0, scope.keyPanSpeed);
|
|
6039
|
+
needsUpdate = true;
|
|
6040
|
+
break;
|
|
6041
|
+
case scope.keys.BOTTOM:
|
|
6042
|
+
pan(0, -scope.keyPanSpeed);
|
|
6043
|
+
needsUpdate = true;
|
|
6044
|
+
break;
|
|
6045
|
+
case scope.keys.LEFT:
|
|
6046
|
+
pan(scope.keyPanSpeed, 0);
|
|
6047
|
+
needsUpdate = true;
|
|
6048
|
+
break;
|
|
6049
|
+
case scope.keys.RIGHT:
|
|
6050
|
+
pan(-scope.keyPanSpeed, 0);
|
|
6051
|
+
needsUpdate = true;
|
|
6052
|
+
break;
|
|
6053
|
+
}
|
|
6054
|
+
if (needsUpdate) {
|
|
6055
|
+
event.preventDefault();
|
|
6056
|
+
scope.update();
|
|
6057
|
+
}
|
|
5771
6058
|
}
|
|
5772
|
-
|
|
5773
|
-
if (
|
|
5774
|
-
|
|
6059
|
+
function handleTouchStartRotate() {
|
|
6060
|
+
if (pointers.length === 1) {
|
|
6061
|
+
rotateStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
5775
6062
|
} else {
|
|
5776
|
-
|
|
6063
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
6064
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
6065
|
+
rotateStart.set(x, y);
|
|
5777
6066
|
}
|
|
5778
6067
|
}
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
6068
|
+
function handleTouchStartPan() {
|
|
6069
|
+
if (pointers.length === 1) {
|
|
6070
|
+
panStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
6071
|
+
} else {
|
|
6072
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
6073
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
6074
|
+
panStart.set(x, y);
|
|
6075
|
+
}
|
|
5782
6076
|
}
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
///
|
|
5789
|
-
get attachedToBody() {
|
|
5790
|
-
return this.element === document.body;
|
|
5791
|
-
}
|
|
5792
|
-
get viewWidth() {
|
|
5793
|
-
return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
|
|
5794
|
-
}
|
|
5795
|
-
get viewHeight() {
|
|
5796
|
-
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
5797
|
-
}
|
|
5798
|
-
get scene() {
|
|
5799
|
-
return this._scene;
|
|
5800
|
-
}
|
|
5801
|
-
get camera() {
|
|
5802
|
-
return this._camera;
|
|
5803
|
-
}
|
|
5804
|
-
get renderer() {
|
|
5805
|
-
return this._renderer;
|
|
5806
|
-
}
|
|
5807
|
-
get composer() {
|
|
5808
|
-
return this._composer;
|
|
5809
|
-
}
|
|
5810
|
-
///
|
|
5811
|
-
};
|
|
5812
|
-
_Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge10.default)({}, {
|
|
5813
|
-
camera: {
|
|
5814
|
-
type: "perspective",
|
|
5815
|
-
near: 1,
|
|
5816
|
-
far: 5e3,
|
|
5817
|
-
perspective: {
|
|
5818
|
-
aspect: void 0,
|
|
5819
|
-
fov: 50
|
|
5820
|
-
},
|
|
5821
|
-
orthographic: {
|
|
5822
|
-
left: void 0,
|
|
5823
|
-
right: void 0,
|
|
5824
|
-
top: void 0,
|
|
5825
|
-
bottom: void 0
|
|
5826
|
-
},
|
|
5827
|
-
position: new import_three18.Vector3(50, 50, 50),
|
|
5828
|
-
lookingAt: new import_three18.Vector3(0, 0, 0)
|
|
5829
|
-
},
|
|
5830
|
-
render: {
|
|
5831
|
-
fpsLimit: 60,
|
|
5832
|
-
stats: false,
|
|
5833
|
-
antialias: true,
|
|
5834
|
-
shade: true,
|
|
5835
|
-
autoResize: true,
|
|
5836
|
-
renderAlways: false
|
|
5837
|
-
},
|
|
5838
|
-
composer: {
|
|
5839
|
-
enabled: true
|
|
5840
|
-
},
|
|
5841
|
-
debug: {
|
|
5842
|
-
grid: false,
|
|
5843
|
-
axes: false
|
|
5844
|
-
}
|
|
5845
|
-
});
|
|
5846
|
-
var Renderer = _Renderer;
|
|
5847
|
-
|
|
5848
|
-
// src/skin/Skins.ts
|
|
5849
|
-
var Skins = class {
|
|
5850
|
-
//<editor-fold desc="Skins">
|
|
5851
|
-
static async fromUuidOrUsername(uuidOrUsername) {
|
|
5852
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5853
|
-
return this.fromUuid(uuidOrUsername);
|
|
6077
|
+
function handleTouchStartDolly() {
|
|
6078
|
+
const dx = pointers[0].pageX - pointers[1].pageX;
|
|
6079
|
+
const dy = pointers[0].pageY - pointers[1].pageY;
|
|
6080
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
6081
|
+
dollyStart.set(0, distance);
|
|
5854
6082
|
}
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
6083
|
+
function handleTouchStartDollyPan() {
|
|
6084
|
+
if (scope.enableZoom) handleTouchStartDolly();
|
|
6085
|
+
if (scope.enablePan) handleTouchStartPan();
|
|
6086
|
+
}
|
|
6087
|
+
function handleTouchStartDollyRotate() {
|
|
6088
|
+
if (scope.enableZoom) handleTouchStartDolly();
|
|
6089
|
+
if (scope.enableRotate) handleTouchStartRotate();
|
|
6090
|
+
}
|
|
6091
|
+
function handleTouchMoveRotate(event) {
|
|
6092
|
+
if (pointers.length == 1) {
|
|
6093
|
+
rotateEnd.set(event.pageX, event.pageY);
|
|
6094
|
+
} else {
|
|
6095
|
+
const position = getSecondPointerPosition(event);
|
|
6096
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
6097
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
6098
|
+
rotateEnd.set(x, y);
|
|
5872
6099
|
}
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
5879
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5880
|
-
return this.capeFromUuid(uuidOrUsername);
|
|
6100
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
6101
|
+
const element = scope.domElement;
|
|
6102
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
6103
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
6104
|
+
rotateStart.copy(rotateEnd);
|
|
5881
6105
|
}
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
return this.capeFromUuid(uuid);
|
|
6106
|
+
function handleTouchMovePan(event) {
|
|
6107
|
+
if (pointers.length === 1) {
|
|
6108
|
+
panEnd.set(event.pageX, event.pageY);
|
|
6109
|
+
} else {
|
|
6110
|
+
const position = getSecondPointerPosition(event);
|
|
6111
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
6112
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
6113
|
+
panEnd.set(x, y);
|
|
5891
6114
|
}
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
6115
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
6116
|
+
pan(panDelta.x, panDelta.y);
|
|
6117
|
+
panStart.copy(panEnd);
|
|
6118
|
+
}
|
|
6119
|
+
function handleTouchMoveDolly(event) {
|
|
6120
|
+
const position = getSecondPointerPosition(event);
|
|
6121
|
+
const dx = event.pageX - position.x;
|
|
6122
|
+
const dy = event.pageY - position.y;
|
|
6123
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
6124
|
+
dollyEnd.set(0, distance);
|
|
6125
|
+
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
6126
|
+
dollyOut(dollyDelta.y);
|
|
6127
|
+
dollyStart.copy(dollyEnd);
|
|
6128
|
+
}
|
|
6129
|
+
function handleTouchMoveDollyPan(event) {
|
|
6130
|
+
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
6131
|
+
if (scope.enablePan) handleTouchMovePan(event);
|
|
6132
|
+
}
|
|
6133
|
+
function handleTouchMoveDollyRotate(event) {
|
|
6134
|
+
if (scope.enableZoom) handleTouchMoveDolly(event);
|
|
6135
|
+
if (scope.enableRotate) handleTouchMoveRotate(event);
|
|
6136
|
+
}
|
|
6137
|
+
function handleTouchEnd() {
|
|
6138
|
+
}
|
|
6139
|
+
function onPointerDown(event) {
|
|
6140
|
+
if (scope.enabled === false) return;
|
|
6141
|
+
if (pointers.length === 0) {
|
|
6142
|
+
scope.domElement.setPointerCapture(event.pointerId);
|
|
6143
|
+
scope.domElement.addEventListener("pointermove", onPointerMove);
|
|
6144
|
+
scope.domElement.addEventListener("pointerup", onPointerUp);
|
|
5899
6145
|
}
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
static async usernameToUuid(username) {
|
|
5906
|
-
return this.usernameToUuidSkinProxy(username);
|
|
5907
|
-
}
|
|
5908
|
-
static async usernameToUuidSkinProxy(username) {
|
|
5909
|
-
return Requests.genericRequest({
|
|
5910
|
-
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
5911
|
-
url: "/uuid/" + username
|
|
5912
|
-
}).then((res) => {
|
|
5913
|
-
if (res.status === 200) {
|
|
5914
|
-
return res.data["id"];
|
|
6146
|
+
addPointer(event);
|
|
6147
|
+
if (event.pointerType === "touch") {
|
|
6148
|
+
onTouchStart(event);
|
|
6149
|
+
} else {
|
|
6150
|
+
onMouseDown(event);
|
|
5915
6151
|
}
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
return Requests.genericRequest({
|
|
5924
|
-
baseURL: "https://api.minetools.eu",
|
|
5925
|
-
url: "/uuid/" + username
|
|
5926
|
-
}).then((res) => {
|
|
5927
|
-
if (res.status === 200) {
|
|
5928
|
-
return res.data["id"];
|
|
6152
|
+
}
|
|
6153
|
+
function onPointerMove(event) {
|
|
6154
|
+
if (scope.enabled === false) return;
|
|
6155
|
+
if (event.pointerType === "touch") {
|
|
6156
|
+
onTouchMove(event);
|
|
6157
|
+
} else {
|
|
6158
|
+
onMouseMove(event);
|
|
5929
6159
|
}
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
return Requests.genericRequest({
|
|
5938
|
-
baseURL: "https://api.minetools.eu",
|
|
5939
|
-
url: "/profile/" + uuid
|
|
5940
|
-
}).then((res) => {
|
|
5941
|
-
if (res.status === 200) {
|
|
5942
|
-
return res.data;
|
|
6160
|
+
}
|
|
6161
|
+
function onPointerUp(event) {
|
|
6162
|
+
if (scope.enabled === false) return;
|
|
6163
|
+
if (event.pointerType === "touch") {
|
|
6164
|
+
onTouchEnd();
|
|
6165
|
+
} else {
|
|
6166
|
+
onMouseUp(event);
|
|
5943
6167
|
}
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
url: "/get/uuid/" + mineskinId
|
|
5950
|
-
}).then((res) => {
|
|
5951
|
-
if (res.status === 200) {
|
|
5952
|
-
return res.data;
|
|
6168
|
+
removePointer(event);
|
|
6169
|
+
if (pointers.length === 0) {
|
|
6170
|
+
scope.domElement.releasePointerCapture(event.pointerId);
|
|
6171
|
+
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
6172
|
+
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
5953
6173
|
}
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
6174
|
+
}
|
|
6175
|
+
function onPointerCancel(event) {
|
|
6176
|
+
removePointer(event);
|
|
6177
|
+
}
|
|
6178
|
+
function onMouseDown(event) {
|
|
6179
|
+
let mouseAction;
|
|
6180
|
+
switch (event.button) {
|
|
6181
|
+
case 0:
|
|
6182
|
+
mouseAction = scope.mouseButtons.LEFT;
|
|
6183
|
+
break;
|
|
6184
|
+
case 1:
|
|
6185
|
+
mouseAction = scope.mouseButtons.MIDDLE;
|
|
6186
|
+
break;
|
|
6187
|
+
case 2:
|
|
6188
|
+
mouseAction = scope.mouseButtons.RIGHT;
|
|
6189
|
+
break;
|
|
6190
|
+
default:
|
|
6191
|
+
mouseAction = -1;
|
|
5967
6192
|
}
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
5991
|
-
}
|
|
5992
|
-
//</editor-fold>
|
|
5993
|
-
};
|
|
5994
|
-
|
|
5995
|
-
// src/three/OrbitControls.js
|
|
5996
|
-
var import_three20 = require("three");
|
|
5997
|
-
var _changeEvent = { type: "change" };
|
|
5998
|
-
var _startEvent = { type: "start" };
|
|
5999
|
-
var _endEvent = { type: "end" };
|
|
6000
|
-
var OrbitControls = class extends import_three20.EventDispatcher {
|
|
6001
|
-
constructor(object, domElement) {
|
|
6002
|
-
super();
|
|
6003
|
-
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
6004
|
-
if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
|
6005
|
-
this.object = object;
|
|
6006
|
-
this.domElement = domElement;
|
|
6007
|
-
this.domElement.style.touchAction = "none";
|
|
6008
|
-
this.enabled = true;
|
|
6009
|
-
this.target = new import_three20.Vector3();
|
|
6010
|
-
this.minDistance = 0;
|
|
6011
|
-
this.maxDistance = Infinity;
|
|
6012
|
-
this.minZoom = 0;
|
|
6013
|
-
this.maxZoom = Infinity;
|
|
6014
|
-
this.minPolarAngle = 0;
|
|
6015
|
-
this.maxPolarAngle = Math.PI;
|
|
6016
|
-
this.minAzimuthAngle = -Infinity;
|
|
6017
|
-
this.maxAzimuthAngle = Infinity;
|
|
6018
|
-
this.enableDamping = false;
|
|
6019
|
-
this.dampingFactor = 0.05;
|
|
6020
|
-
this.enableZoom = true;
|
|
6021
|
-
this.zoomSpeed = 1;
|
|
6022
|
-
this.enableRotate = true;
|
|
6023
|
-
this.rotateSpeed = 1;
|
|
6024
|
-
this.enablePan = true;
|
|
6025
|
-
this.panSpeed = 1;
|
|
6026
|
-
this.screenSpacePanning = true;
|
|
6027
|
-
this.keyPanSpeed = 7;
|
|
6028
|
-
this.autoRotate = false;
|
|
6029
|
-
this.autoRotateSpeed = 2;
|
|
6030
|
-
this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
|
|
6031
|
-
this.mouseButtons = { LEFT: import_three20.MOUSE.ROTATE, MIDDLE: import_three20.MOUSE.DOLLY, RIGHT: import_three20.MOUSE.PAN };
|
|
6032
|
-
this.touches = { ONE: import_three20.TOUCH.ROTATE, TWO: import_three20.TOUCH.DOLLY_PAN };
|
|
6033
|
-
this.target0 = this.target.clone();
|
|
6034
|
-
this.position0 = this.object.position.clone();
|
|
6035
|
-
this.zoom0 = this.object.zoom;
|
|
6036
|
-
this._domElementKeyEvents = null;
|
|
6037
|
-
this.getPolarAngle = function() {
|
|
6038
|
-
return spherical.phi;
|
|
6039
|
-
};
|
|
6040
|
-
this.getAzimuthalAngle = function() {
|
|
6041
|
-
return spherical.theta;
|
|
6042
|
-
};
|
|
6043
|
-
this.getDistance = function() {
|
|
6044
|
-
return this.object.position.distanceTo(this.target);
|
|
6045
|
-
};
|
|
6046
|
-
this.saveState = function() {
|
|
6047
|
-
scope.target0.copy(scope.target);
|
|
6048
|
-
scope.position0.copy(scope.object.position);
|
|
6049
|
-
scope.zoom0 = scope.object.zoom;
|
|
6050
|
-
};
|
|
6051
|
-
this.reset = function() {
|
|
6052
|
-
scope.target.copy(scope.target0);
|
|
6053
|
-
scope.object.position.copy(scope.position0);
|
|
6054
|
-
scope.object.zoom = scope.zoom0;
|
|
6055
|
-
scope.object.updateProjectionMatrix();
|
|
6056
|
-
scope.dispatchEvent(_changeEvent);
|
|
6057
|
-
scope.update();
|
|
6058
|
-
state = STATE.NONE;
|
|
6059
|
-
};
|
|
6060
|
-
this.update = function() {
|
|
6061
|
-
const offset = new import_three20.Vector3();
|
|
6062
|
-
const quat = new import_three20.Quaternion().setFromUnitVectors(object.up, new import_three20.Vector3(0, 1, 0));
|
|
6063
|
-
const quatInverse = quat.clone().invert();
|
|
6064
|
-
const lastPosition = new import_three20.Vector3();
|
|
6065
|
-
const lastQuaternion = new import_three20.Quaternion();
|
|
6066
|
-
const twoPI = 2 * Math.PI;
|
|
6067
|
-
return function update() {
|
|
6068
|
-
const position = scope.object.position;
|
|
6069
|
-
offset.copy(position).sub(scope.target);
|
|
6070
|
-
offset.applyQuaternion(quat);
|
|
6071
|
-
spherical.setFromVector3(offset);
|
|
6072
|
-
if (scope.autoRotate && state === STATE.NONE) {
|
|
6073
|
-
rotateLeft(getAutoRotationAngle());
|
|
6074
|
-
}
|
|
6075
|
-
if (scope.enableDamping) {
|
|
6076
|
-
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
6077
|
-
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
6078
|
-
} else {
|
|
6079
|
-
spherical.theta += sphericalDelta.theta;
|
|
6080
|
-
spherical.phi += sphericalDelta.phi;
|
|
6081
|
-
}
|
|
6082
|
-
let min = scope.minAzimuthAngle;
|
|
6083
|
-
let max = scope.maxAzimuthAngle;
|
|
6084
|
-
if (isFinite(min) && isFinite(max)) {
|
|
6085
|
-
if (min < -Math.PI) min += twoPI;
|
|
6086
|
-
else if (min > Math.PI) min -= twoPI;
|
|
6087
|
-
if (max < -Math.PI) max += twoPI;
|
|
6088
|
-
else if (max > Math.PI) max -= twoPI;
|
|
6089
|
-
if (min <= max) {
|
|
6090
|
-
spherical.theta = Math.max(min, Math.min(max, spherical.theta));
|
|
6193
|
+
switch (mouseAction) {
|
|
6194
|
+
case import_three18.MOUSE.DOLLY:
|
|
6195
|
+
if (scope.enableZoom === false) return;
|
|
6196
|
+
handleMouseDownDolly(event);
|
|
6197
|
+
state = STATE.DOLLY;
|
|
6198
|
+
break;
|
|
6199
|
+
case import_three18.MOUSE.ROTATE:
|
|
6200
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6201
|
+
if (scope.enablePan === false) return;
|
|
6202
|
+
handleMouseDownPan(event);
|
|
6203
|
+
state = STATE.PAN;
|
|
6204
|
+
} else {
|
|
6205
|
+
if (scope.enableRotate === false) return;
|
|
6206
|
+
handleMouseDownRotate(event);
|
|
6207
|
+
state = STATE.ROTATE;
|
|
6208
|
+
}
|
|
6209
|
+
break;
|
|
6210
|
+
case import_three18.MOUSE.PAN:
|
|
6211
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6212
|
+
if (scope.enableRotate === false) return;
|
|
6213
|
+
handleMouseDownRotate(event);
|
|
6214
|
+
state = STATE.ROTATE;
|
|
6091
6215
|
} else {
|
|
6092
|
-
|
|
6216
|
+
if (scope.enablePan === false) return;
|
|
6217
|
+
handleMouseDownPan(event);
|
|
6218
|
+
state = STATE.PAN;
|
|
6093
6219
|
}
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
scope.target.addScaledVector(panOffset, scope.dampingFactor);
|
|
6101
|
-
} else {
|
|
6102
|
-
scope.target.add(panOffset);
|
|
6103
|
-
}
|
|
6104
|
-
offset.setFromSpherical(spherical);
|
|
6105
|
-
offset.applyQuaternion(quatInverse);
|
|
6106
|
-
position.copy(scope.target).add(offset);
|
|
6107
|
-
scope.object.lookAt(scope.target);
|
|
6108
|
-
if (scope.enableDamping === true) {
|
|
6109
|
-
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
6110
|
-
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
6111
|
-
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
6112
|
-
} else {
|
|
6113
|
-
sphericalDelta.set(0, 0, 0);
|
|
6114
|
-
panOffset.set(0, 0, 0);
|
|
6115
|
-
}
|
|
6116
|
-
scale = 1;
|
|
6117
|
-
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
6118
|
-
scope.dispatchEvent(_changeEvent);
|
|
6119
|
-
lastPosition.copy(scope.object.position);
|
|
6120
|
-
lastQuaternion.copy(scope.object.quaternion);
|
|
6121
|
-
zoomChanged = false;
|
|
6122
|
-
return true;
|
|
6123
|
-
}
|
|
6124
|
-
return false;
|
|
6125
|
-
};
|
|
6126
|
-
}();
|
|
6127
|
-
this.dispose = function() {
|
|
6128
|
-
scope.domElement.removeEventListener("contextmenu", onContextMenu);
|
|
6129
|
-
scope.domElement.removeEventListener("pointerdown", onPointerDown);
|
|
6130
|
-
scope.domElement.removeEventListener("pointercancel", onPointerCancel);
|
|
6131
|
-
scope.domElement.removeEventListener("wheel", onMouseWheel);
|
|
6132
|
-
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
6133
|
-
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
6134
|
-
if (scope._domElementKeyEvents !== null) {
|
|
6135
|
-
scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
6220
|
+
break;
|
|
6221
|
+
default:
|
|
6222
|
+
state = STATE.NONE;
|
|
6223
|
+
}
|
|
6224
|
+
if (state !== STATE.NONE) {
|
|
6225
|
+
scope.dispatchEvent(_startEvent);
|
|
6136
6226
|
}
|
|
6137
|
-
};
|
|
6138
|
-
const scope = this;
|
|
6139
|
-
const STATE = {
|
|
6140
|
-
NONE: -1,
|
|
6141
|
-
ROTATE: 0,
|
|
6142
|
-
DOLLY: 1,
|
|
6143
|
-
PAN: 2,
|
|
6144
|
-
TOUCH_ROTATE: 3,
|
|
6145
|
-
TOUCH_PAN: 4,
|
|
6146
|
-
TOUCH_DOLLY_PAN: 5,
|
|
6147
|
-
TOUCH_DOLLY_ROTATE: 6
|
|
6148
|
-
};
|
|
6149
|
-
let state = STATE.NONE;
|
|
6150
|
-
const EPS = 1e-6;
|
|
6151
|
-
const spherical = new import_three20.Spherical();
|
|
6152
|
-
const sphericalDelta = new import_three20.Spherical();
|
|
6153
|
-
let scale = 1;
|
|
6154
|
-
const panOffset = new import_three20.Vector3();
|
|
6155
|
-
let zoomChanged = false;
|
|
6156
|
-
const rotateStart = new import_three20.Vector2();
|
|
6157
|
-
const rotateEnd = new import_three20.Vector2();
|
|
6158
|
-
const rotateDelta = new import_three20.Vector2();
|
|
6159
|
-
const panStart = new import_three20.Vector2();
|
|
6160
|
-
const panEnd = new import_three20.Vector2();
|
|
6161
|
-
const panDelta = new import_three20.Vector2();
|
|
6162
|
-
const dollyStart = new import_three20.Vector2();
|
|
6163
|
-
const dollyEnd = new import_three20.Vector2();
|
|
6164
|
-
const dollyDelta = new import_three20.Vector2();
|
|
6165
|
-
const pointers = [];
|
|
6166
|
-
const pointerPositions = {};
|
|
6167
|
-
function getAutoRotationAngle() {
|
|
6168
|
-
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
6169
6227
|
}
|
|
6170
|
-
function
|
|
6171
|
-
|
|
6228
|
+
function onMouseMove(event) {
|
|
6229
|
+
if (scope.enabled === false) return;
|
|
6230
|
+
switch (state) {
|
|
6231
|
+
case STATE.ROTATE:
|
|
6232
|
+
if (scope.enableRotate === false) return;
|
|
6233
|
+
handleMouseMoveRotate(event);
|
|
6234
|
+
break;
|
|
6235
|
+
case STATE.DOLLY:
|
|
6236
|
+
if (scope.enableZoom === false) return;
|
|
6237
|
+
handleMouseMoveDolly(event);
|
|
6238
|
+
break;
|
|
6239
|
+
case STATE.PAN:
|
|
6240
|
+
if (scope.enablePan === false) return;
|
|
6241
|
+
handleMouseMovePan(event);
|
|
6242
|
+
break;
|
|
6243
|
+
}
|
|
6172
6244
|
}
|
|
6173
|
-
function
|
|
6174
|
-
|
|
6245
|
+
function onMouseUp(event) {
|
|
6246
|
+
handleMouseUp(event);
|
|
6247
|
+
scope.dispatchEvent(_endEvent);
|
|
6248
|
+
state = STATE.NONE;
|
|
6175
6249
|
}
|
|
6176
|
-
function
|
|
6177
|
-
|
|
6250
|
+
function onMouseWheel(event) {
|
|
6251
|
+
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
|
|
6252
|
+
event.preventDefault();
|
|
6253
|
+
scope.dispatchEvent(_startEvent);
|
|
6254
|
+
handleMouseWheel(event);
|
|
6255
|
+
scope.dispatchEvent(_endEvent);
|
|
6178
6256
|
}
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6257
|
+
function onKeyDown(event) {
|
|
6258
|
+
if (scope.enabled === false || scope.enablePan === false) return;
|
|
6259
|
+
handleKeyDown(event);
|
|
6260
|
+
}
|
|
6261
|
+
function onTouchStart(event) {
|
|
6262
|
+
trackPointer(event);
|
|
6263
|
+
switch (pointers.length) {
|
|
6264
|
+
case 1:
|
|
6265
|
+
switch (scope.touches.ONE) {
|
|
6266
|
+
case import_three18.TOUCH.ROTATE:
|
|
6267
|
+
if (scope.enableRotate === false) return;
|
|
6268
|
+
handleTouchStartRotate();
|
|
6269
|
+
state = STATE.TOUCH_ROTATE;
|
|
6270
|
+
break;
|
|
6271
|
+
case import_three18.TOUCH.PAN:
|
|
6272
|
+
if (scope.enablePan === false) return;
|
|
6273
|
+
handleTouchStartPan();
|
|
6274
|
+
state = STATE.TOUCH_PAN;
|
|
6275
|
+
break;
|
|
6276
|
+
default:
|
|
6277
|
+
state = STATE.NONE;
|
|
6278
|
+
}
|
|
6279
|
+
break;
|
|
6280
|
+
case 2:
|
|
6281
|
+
switch (scope.touches.TWO) {
|
|
6282
|
+
case import_three18.TOUCH.DOLLY_PAN:
|
|
6283
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6284
|
+
handleTouchStartDollyPan();
|
|
6285
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
|
6286
|
+
break;
|
|
6287
|
+
case import_three18.TOUCH.DOLLY_ROTATE:
|
|
6288
|
+
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6289
|
+
handleTouchStartDollyRotate();
|
|
6290
|
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
6291
|
+
break;
|
|
6292
|
+
default:
|
|
6293
|
+
state = STATE.NONE;
|
|
6294
|
+
}
|
|
6295
|
+
break;
|
|
6296
|
+
default:
|
|
6297
|
+
state = STATE.NONE;
|
|
6298
|
+
}
|
|
6299
|
+
if (state !== STATE.NONE) {
|
|
6300
|
+
scope.dispatchEvent(_startEvent);
|
|
6301
|
+
}
|
|
6302
|
+
}
|
|
6303
|
+
function onTouchMove(event) {
|
|
6304
|
+
trackPointer(event);
|
|
6305
|
+
switch (state) {
|
|
6306
|
+
case STATE.TOUCH_ROTATE:
|
|
6307
|
+
if (scope.enableRotate === false) return;
|
|
6308
|
+
handleTouchMoveRotate(event);
|
|
6309
|
+
scope.update();
|
|
6310
|
+
break;
|
|
6311
|
+
case STATE.TOUCH_PAN:
|
|
6312
|
+
if (scope.enablePan === false) return;
|
|
6313
|
+
handleTouchMovePan(event);
|
|
6314
|
+
scope.update();
|
|
6315
|
+
break;
|
|
6316
|
+
case STATE.TOUCH_DOLLY_PAN:
|
|
6317
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6318
|
+
handleTouchMoveDollyPan(event);
|
|
6319
|
+
scope.update();
|
|
6320
|
+
break;
|
|
6321
|
+
case STATE.TOUCH_DOLLY_ROTATE:
|
|
6322
|
+
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6323
|
+
handleTouchMoveDollyRotate(event);
|
|
6324
|
+
scope.update();
|
|
6325
|
+
break;
|
|
6326
|
+
default:
|
|
6327
|
+
state = STATE.NONE;
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
function onTouchEnd(event) {
|
|
6331
|
+
handleTouchEnd(event);
|
|
6332
|
+
scope.dispatchEvent(_endEvent);
|
|
6333
|
+
state = STATE.NONE;
|
|
6334
|
+
}
|
|
6335
|
+
function onContextMenu(event) {
|
|
6336
|
+
if (scope.enabled === false) return;
|
|
6337
|
+
event.preventDefault();
|
|
6338
|
+
}
|
|
6339
|
+
function addPointer(event) {
|
|
6340
|
+
pointers.push(event);
|
|
6341
|
+
}
|
|
6342
|
+
function removePointer(event) {
|
|
6343
|
+
delete pointerPositions[event.pointerId];
|
|
6344
|
+
for (let i = 0; i < pointers.length; i++) {
|
|
6345
|
+
if (pointers[i].pointerId == event.pointerId) {
|
|
6346
|
+
pointers.splice(i, 1);
|
|
6347
|
+
return;
|
|
6217
6348
|
}
|
|
6218
|
-
};
|
|
6219
|
-
}();
|
|
6220
|
-
function dollyOut(dollyScale) {
|
|
6221
|
-
if (scope.object.isPerspectiveCamera) {
|
|
6222
|
-
scale /= dollyScale;
|
|
6223
|
-
} else if (scope.object.isOrthographicCamera) {
|
|
6224
|
-
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
|
|
6225
|
-
scope.object.updateProjectionMatrix();
|
|
6226
|
-
zoomChanged = true;
|
|
6227
|
-
} else {
|
|
6228
|
-
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
6229
|
-
scope.enableZoom = false;
|
|
6230
6349
|
}
|
|
6231
6350
|
}
|
|
6232
|
-
function
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
scope.object.updateProjectionMatrix();
|
|
6238
|
-
zoomChanged = true;
|
|
6239
|
-
} else {
|
|
6240
|
-
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
6241
|
-
scope.enableZoom = false;
|
|
6351
|
+
function trackPointer(event) {
|
|
6352
|
+
let position = pointerPositions[event.pointerId];
|
|
6353
|
+
if (position === void 0) {
|
|
6354
|
+
position = new import_three18.Vector2();
|
|
6355
|
+
pointerPositions[event.pointerId] = position;
|
|
6242
6356
|
}
|
|
6357
|
+
position.set(event.pageX, event.pageY);
|
|
6243
6358
|
}
|
|
6244
|
-
function
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
function handleMouseDownDolly(event) {
|
|
6248
|
-
dollyStart.set(event.clientX, event.clientY);
|
|
6359
|
+
function getSecondPointerPosition(event) {
|
|
6360
|
+
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
6361
|
+
return pointerPositions[pointer.pointerId];
|
|
6249
6362
|
}
|
|
6250
|
-
|
|
6251
|
-
|
|
6363
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6364
|
+
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6365
|
+
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6366
|
+
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6367
|
+
this.update();
|
|
6368
|
+
}
|
|
6369
|
+
};
|
|
6370
|
+
var MapControls = class extends OrbitControls {
|
|
6371
|
+
constructor(object, domElement) {
|
|
6372
|
+
super(object, domElement);
|
|
6373
|
+
this.screenSpacePanning = false;
|
|
6374
|
+
this.mouseButtons.LEFT = import_three18.MOUSE.PAN;
|
|
6375
|
+
this.mouseButtons.RIGHT = import_three18.MOUSE.ROTATE;
|
|
6376
|
+
this.touches.ONE = import_three18.TOUCH.PAN;
|
|
6377
|
+
this.touches.TWO = import_three18.TOUCH.DOLLY_ROTATE;
|
|
6378
|
+
}
|
|
6379
|
+
};
|
|
6380
|
+
|
|
6381
|
+
// src/renderer/Renderer.ts
|
|
6382
|
+
var _Renderer = class _Renderer {
|
|
6383
|
+
constructor(options) {
|
|
6384
|
+
this._dirty = true;
|
|
6385
|
+
this._resizeListener = void 0;
|
|
6386
|
+
this._disposed = false;
|
|
6387
|
+
this._debugHelpers = [];
|
|
6388
|
+
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
6389
|
+
this._changeListener = () => {
|
|
6390
|
+
this._dirty = true;
|
|
6391
|
+
};
|
|
6392
|
+
this.options = (0, import_ts_deepmerge9.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
6393
|
+
this._animationLoop = this.animate.bind(this);
|
|
6394
|
+
this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
6395
|
+
this._scene = this.createScene();
|
|
6396
|
+
this._camera = this.createCamera();
|
|
6397
|
+
this._renderer = this.createRenderer();
|
|
6398
|
+
this._composer = this.createComposer();
|
|
6399
|
+
if (this.options.render.stats) {
|
|
6400
|
+
this._stats = new import_stats.default();
|
|
6401
|
+
document.body.appendChild(this._stats.dom);
|
|
6252
6402
|
}
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6403
|
+
this.init();
|
|
6404
|
+
this._controls = this.createControls();
|
|
6405
|
+
}
|
|
6406
|
+
//<editor-fold desc="INIT">
|
|
6407
|
+
createScene() {
|
|
6408
|
+
return new MineRenderScene();
|
|
6409
|
+
}
|
|
6410
|
+
createCamera() {
|
|
6411
|
+
switch (this.options.camera.type) {
|
|
6412
|
+
case "perspective":
|
|
6413
|
+
default:
|
|
6414
|
+
return new import_three19.PerspectiveCamera(
|
|
6415
|
+
this.options.camera.perspective.fov,
|
|
6416
|
+
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
6417
|
+
this.options.camera.near,
|
|
6418
|
+
this.options.camera.far
|
|
6419
|
+
);
|
|
6420
|
+
case "orthographic":
|
|
6421
|
+
return new import_three19.OrthographicCamera(
|
|
6422
|
+
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
6423
|
+
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
6424
|
+
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
6425
|
+
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
6426
|
+
this.options.camera.near,
|
|
6427
|
+
this.options.camera.far
|
|
6428
|
+
);
|
|
6261
6429
|
}
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6430
|
+
}
|
|
6431
|
+
createRenderer() {
|
|
6432
|
+
const renderer = new import_three19.WebGLRenderer({
|
|
6433
|
+
antialias: this.options.render.antialias,
|
|
6434
|
+
alpha: true,
|
|
6435
|
+
powerPreference: "high-performance",
|
|
6436
|
+
depth: true
|
|
6437
|
+
});
|
|
6438
|
+
renderer.setClearColor(0, 0);
|
|
6439
|
+
renderer.shadowMap.enabled = true;
|
|
6440
|
+
renderer.shadowMap.type = import_three19.PCFSoftShadowMap;
|
|
6441
|
+
renderer.outputColorSpace = import_three19.SRGBColorSpace;
|
|
6442
|
+
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
6443
|
+
return renderer;
|
|
6444
|
+
}
|
|
6445
|
+
createComposer() {
|
|
6446
|
+
if (!this.options.composer.enabled) return void 0;
|
|
6447
|
+
const composer = new import_postprocessing.EffectComposer(this.renderer);
|
|
6448
|
+
composer.setSize(this.viewWidth, this.viewHeight);
|
|
6449
|
+
composer.addPass(new import_postprocessing.RenderPass(this.scene, this.camera));
|
|
6450
|
+
return composer;
|
|
6451
|
+
}
|
|
6452
|
+
createControls() {
|
|
6453
|
+
if (!this.options.controls?.enabled) return void 0;
|
|
6454
|
+
const position = this.camera.position.clone();
|
|
6455
|
+
const controls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
6456
|
+
this.camera.position.copy(position);
|
|
6457
|
+
const target = this.options.camera.lookingAt;
|
|
6458
|
+
if (isVector3(target)) {
|
|
6459
|
+
controls.target.copy(target);
|
|
6460
|
+
} else if (isTripleArray(target)) {
|
|
6461
|
+
controls.target.set(target[0], target[1], target[2]);
|
|
6462
|
+
}
|
|
6463
|
+
controls.update();
|
|
6464
|
+
controls.saveState();
|
|
6465
|
+
this.registerEventDispatcher(controls);
|
|
6466
|
+
return controls;
|
|
6467
|
+
}
|
|
6468
|
+
//</editor-fold>
|
|
6469
|
+
init() {
|
|
6470
|
+
if (this._disposed) return;
|
|
6471
|
+
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
6472
|
+
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
6272
6473
|
}
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6474
|
+
if (this.options.debug.grid) {
|
|
6475
|
+
const gridHelper = new import_three19.GridHelper(128, 16);
|
|
6476
|
+
this._debugHelpers.push(gridHelper);
|
|
6477
|
+
this.scene.add(gridHelper);
|
|
6478
|
+
const gridHelper2 = new import_three19.GridHelper(128, 16);
|
|
6479
|
+
this._debugHelpers.push(gridHelper2);
|
|
6480
|
+
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
6481
|
+
this.scene.add(gridHelper2);
|
|
6482
|
+
const gridHelper3 = new import_three19.GridHelper(128, 16);
|
|
6483
|
+
this._debugHelpers.push(gridHelper3);
|
|
6484
|
+
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
6485
|
+
this.scene.add(gridHelper3);
|
|
6279
6486
|
}
|
|
6280
|
-
|
|
6487
|
+
if (this.options.debug.axes) {
|
|
6488
|
+
const axesHelper = new import_three19.AxesHelper(64);
|
|
6489
|
+
this._debugHelpers.push(axesHelper);
|
|
6490
|
+
this.scene.add(axesHelper);
|
|
6281
6491
|
}
|
|
6282
|
-
|
|
6283
|
-
if (
|
|
6284
|
-
|
|
6285
|
-
} else if (
|
|
6286
|
-
|
|
6492
|
+
if (this.options.camera.position) {
|
|
6493
|
+
if (isVector3(this.options.camera.position)) {
|
|
6494
|
+
this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
|
|
6495
|
+
} else if (isTripleArray(this.options.camera.position)) {
|
|
6496
|
+
this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
|
|
6287
6497
|
}
|
|
6288
|
-
scope.update();
|
|
6289
6498
|
}
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
needsUpdate = true;
|
|
6296
|
-
break;
|
|
6297
|
-
case scope.keys.BOTTOM:
|
|
6298
|
-
pan(0, -scope.keyPanSpeed);
|
|
6299
|
-
needsUpdate = true;
|
|
6300
|
-
break;
|
|
6301
|
-
case scope.keys.LEFT:
|
|
6302
|
-
pan(scope.keyPanSpeed, 0);
|
|
6303
|
-
needsUpdate = true;
|
|
6304
|
-
break;
|
|
6305
|
-
case scope.keys.RIGHT:
|
|
6306
|
-
pan(-scope.keyPanSpeed, 0);
|
|
6307
|
-
needsUpdate = true;
|
|
6308
|
-
break;
|
|
6309
|
-
}
|
|
6310
|
-
if (needsUpdate) {
|
|
6311
|
-
event.preventDefault();
|
|
6312
|
-
scope.update();
|
|
6499
|
+
if (this.options.camera.lookingAt) {
|
|
6500
|
+
if (isVector3(this.options.camera.lookingAt)) {
|
|
6501
|
+
this.camera.lookAt(this.options.camera.lookingAt);
|
|
6502
|
+
} else if (isTripleArray(this.options.camera.lookingAt)) {
|
|
6503
|
+
this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
|
|
6313
6504
|
}
|
|
6314
6505
|
}
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
}
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6506
|
+
if (this.options.render.autoResize && !this._resizeListener) {
|
|
6507
|
+
this._resizeListener = () => {
|
|
6508
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6509
|
+
};
|
|
6510
|
+
window.addEventListener("resize", this._resizeListener);
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
get element() {
|
|
6514
|
+
return this._element;
|
|
6515
|
+
}
|
|
6516
|
+
appendTo(element) {
|
|
6517
|
+
if (this._disposed) return;
|
|
6518
|
+
this._element = element;
|
|
6519
|
+
this._element.appendChild(this.renderer.domElement);
|
|
6520
|
+
if (this.viewWidth == 0) {
|
|
6521
|
+
console.warn("0 element width");
|
|
6522
|
+
}
|
|
6523
|
+
if (this.viewHeight == 0) {
|
|
6524
|
+
console.warn("0 element height");
|
|
6525
|
+
}
|
|
6526
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6527
|
+
}
|
|
6528
|
+
/**
|
|
6529
|
+
* Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
|
|
6530
|
+
* The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
|
|
6531
|
+
*/
|
|
6532
|
+
registerEventDispatcher(dispatcher, changeEvent2 = "change") {
|
|
6533
|
+
if (this._disposed) return;
|
|
6534
|
+
let events = this._eventDispatchers.get(dispatcher);
|
|
6535
|
+
if (!events) {
|
|
6536
|
+
events = /* @__PURE__ */ new Set();
|
|
6537
|
+
this._eventDispatchers.set(dispatcher, events);
|
|
6538
|
+
}
|
|
6539
|
+
if (events.has(changeEvent2)) return;
|
|
6540
|
+
events.add(changeEvent2);
|
|
6541
|
+
dispatcher.addEventListener(changeEvent2, this._changeListener);
|
|
6542
|
+
}
|
|
6543
|
+
resize(width, height) {
|
|
6544
|
+
if (this._disposed) return;
|
|
6545
|
+
if (isPerspectiveCamera(this.camera)) {
|
|
6546
|
+
this.camera.aspect = width / height;
|
|
6547
|
+
this.camera.updateProjectionMatrix();
|
|
6548
|
+
} else if (isOrthographicCamera(this.camera)) {
|
|
6549
|
+
this.camera.left = width / -2;
|
|
6550
|
+
this.camera.right = width / 2;
|
|
6551
|
+
this.camera.top = height / 2;
|
|
6552
|
+
this.camera.bottom = height / -2;
|
|
6553
|
+
this.camera.updateProjectionMatrix();
|
|
6554
|
+
}
|
|
6555
|
+
this.renderer.setSize(width, height);
|
|
6556
|
+
this.composer?.setSize(width, height);
|
|
6557
|
+
this._dirty = true;
|
|
6558
|
+
}
|
|
6559
|
+
//<editor-fold desc="RENDER">
|
|
6560
|
+
get dirty() {
|
|
6561
|
+
return this._dirty || this.scene.dirty;
|
|
6562
|
+
}
|
|
6563
|
+
set dirty(dirty) {
|
|
6564
|
+
this._dirty = dirty;
|
|
6565
|
+
this.scene.dirty = dirty;
|
|
6566
|
+
}
|
|
6567
|
+
start() {
|
|
6568
|
+
if (this._disposed) return;
|
|
6569
|
+
this.stop();
|
|
6570
|
+
this.renderer.setAnimationLoop(this._animationLoop);
|
|
6571
|
+
}
|
|
6572
|
+
stop() {
|
|
6573
|
+
if (this._disposed) return;
|
|
6574
|
+
this.renderer.setAnimationLoop(null);
|
|
6575
|
+
this._nextFrameTime = void 0;
|
|
6576
|
+
}
|
|
6577
|
+
/**
|
|
6578
|
+
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
6579
|
+
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
6580
|
+
* controls must be managed by their owners.
|
|
6581
|
+
*/
|
|
6582
|
+
dispose() {
|
|
6583
|
+
if (this._disposed) return;
|
|
6584
|
+
this.stop();
|
|
6585
|
+
this._disposed = true;
|
|
6586
|
+
if (this._resizeListener) {
|
|
6587
|
+
window.removeEventListener("resize", this._resizeListener);
|
|
6588
|
+
this._resizeListener = void 0;
|
|
6323
6589
|
}
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
} else {
|
|
6328
|
-
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
6329
|
-
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
6330
|
-
panStart.set(x, y);
|
|
6590
|
+
for (const [dispatcher, events] of this._eventDispatchers) {
|
|
6591
|
+
for (const event of events) {
|
|
6592
|
+
dispatcher.removeEventListener(event, this._changeListener);
|
|
6331
6593
|
}
|
|
6332
6594
|
}
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
function handleTouchStartDollyRotate() {
|
|
6344
|
-
if (scope.enableZoom) handleTouchStartDolly();
|
|
6345
|
-
if (scope.enableRotate) handleTouchStartRotate();
|
|
6346
|
-
}
|
|
6347
|
-
function handleTouchMoveRotate(event) {
|
|
6348
|
-
if (pointers.length == 1) {
|
|
6349
|
-
rotateEnd.set(event.pageX, event.pageY);
|
|
6350
|
-
} else {
|
|
6351
|
-
const position = getSecondPointerPosition(event);
|
|
6352
|
-
const x = 0.5 * (event.pageX + position.x);
|
|
6353
|
-
const y = 0.5 * (event.pageY + position.y);
|
|
6354
|
-
rotateEnd.set(x, y);
|
|
6355
|
-
}
|
|
6356
|
-
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
6357
|
-
const element = scope.domElement;
|
|
6358
|
-
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
6359
|
-
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
6360
|
-
rotateStart.copy(rotateEnd);
|
|
6595
|
+
this._eventDispatchers.clear();
|
|
6596
|
+
this._stats?.dom.remove();
|
|
6597
|
+
this._stats = void 0;
|
|
6598
|
+
this.renderer.domElement.remove();
|
|
6599
|
+
this._element = void 0;
|
|
6600
|
+
if (this._controls) {
|
|
6601
|
+
const controls = this._controls;
|
|
6602
|
+
this._controls = void 0;
|
|
6603
|
+
controls.enabled = false;
|
|
6604
|
+
controls.dispose();
|
|
6361
6605
|
}
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
const y = 0.5 * (event.pageY + position.y);
|
|
6369
|
-
panEnd.set(x, y);
|
|
6606
|
+
this.scene.clear();
|
|
6607
|
+
for (const helper of this._debugHelpers) {
|
|
6608
|
+
helper.geometry.dispose();
|
|
6609
|
+
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
6610
|
+
for (const material of materials) {
|
|
6611
|
+
material.dispose();
|
|
6370
6612
|
}
|
|
6371
|
-
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
6372
|
-
pan(panDelta.x, panDelta.y);
|
|
6373
|
-
panStart.copy(panEnd);
|
|
6374
|
-
}
|
|
6375
|
-
function handleTouchMoveDolly(event) {
|
|
6376
|
-
const position = getSecondPointerPosition(event);
|
|
6377
|
-
const dx = event.pageX - position.x;
|
|
6378
|
-
const dy = event.pageY - position.y;
|
|
6379
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
6380
|
-
dollyEnd.set(0, distance);
|
|
6381
|
-
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
6382
|
-
dollyOut(dollyDelta.y);
|
|
6383
|
-
dollyStart.copy(dollyEnd);
|
|
6384
6613
|
}
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6614
|
+
this._debugHelpers.length = 0;
|
|
6615
|
+
this.composer?.dispose();
|
|
6616
|
+
this.renderer.dispose();
|
|
6617
|
+
this.renderer.forceContextLoss();
|
|
6618
|
+
}
|
|
6619
|
+
animate(t = performance.now()) {
|
|
6620
|
+
if (this._disposed) return;
|
|
6621
|
+
if (this._controls?.enabled) {
|
|
6622
|
+
this._controls.update();
|
|
6392
6623
|
}
|
|
6393
|
-
|
|
6624
|
+
if (this._disposed) return;
|
|
6625
|
+
if (!this.dirty && !this.options.render.renderAlways) return;
|
|
6626
|
+
const interval = this._frameInterval;
|
|
6627
|
+
if (interval) {
|
|
6628
|
+
const next = this._nextFrameTime;
|
|
6629
|
+
if (next !== void 0 && t + 0.1 < next) return;
|
|
6630
|
+
this._nextFrameTime = next !== void 0 && t - next < interval ? next + interval : t + interval;
|
|
6394
6631
|
}
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
if (pointers.length === 0) {
|
|
6398
|
-
scope.domElement.setPointerCapture(event.pointerId);
|
|
6399
|
-
scope.domElement.addEventListener("pointermove", onPointerMove);
|
|
6400
|
-
scope.domElement.addEventListener("pointerup", onPointerUp);
|
|
6401
|
-
}
|
|
6402
|
-
addPointer(event);
|
|
6403
|
-
if (event.pointerType === "touch") {
|
|
6404
|
-
onTouchStart(event);
|
|
6405
|
-
} else {
|
|
6406
|
-
onMouseDown(event);
|
|
6407
|
-
}
|
|
6632
|
+
if (this._stats) {
|
|
6633
|
+
this._stats.begin();
|
|
6408
6634
|
}
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
} else {
|
|
6414
|
-
onMouseMove(event);
|
|
6415
|
-
}
|
|
6635
|
+
if (this.options.composer.enabled && this.composer) {
|
|
6636
|
+
this.composer.render();
|
|
6637
|
+
} else {
|
|
6638
|
+
this.renderer.render(this.scene, this.camera);
|
|
6416
6639
|
}
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
onTouchEnd();
|
|
6421
|
-
} else {
|
|
6422
|
-
onMouseUp(event);
|
|
6423
|
-
}
|
|
6424
|
-
removePointer(event);
|
|
6425
|
-
if (pointers.length === 0) {
|
|
6426
|
-
scope.domElement.releasePointerCapture(event.pointerId);
|
|
6427
|
-
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
6428
|
-
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
6429
|
-
}
|
|
6640
|
+
this.dirty = false;
|
|
6641
|
+
if (this._stats) {
|
|
6642
|
+
this._stats.end();
|
|
6430
6643
|
}
|
|
6431
|
-
|
|
6432
|
-
|
|
6644
|
+
}
|
|
6645
|
+
//</editor-fold>
|
|
6646
|
+
toImage() {
|
|
6647
|
+
return this.renderer.domElement.toDataURL();
|
|
6648
|
+
}
|
|
6649
|
+
///
|
|
6650
|
+
get attachedToBody() {
|
|
6651
|
+
return this.element === document.body;
|
|
6652
|
+
}
|
|
6653
|
+
get viewWidth() {
|
|
6654
|
+
return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
|
|
6655
|
+
}
|
|
6656
|
+
get viewHeight() {
|
|
6657
|
+
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
6658
|
+
}
|
|
6659
|
+
get scene() {
|
|
6660
|
+
return this._scene;
|
|
6661
|
+
}
|
|
6662
|
+
get camera() {
|
|
6663
|
+
return this._camera;
|
|
6664
|
+
}
|
|
6665
|
+
get renderer() {
|
|
6666
|
+
return this._renderer;
|
|
6667
|
+
}
|
|
6668
|
+
get composer() {
|
|
6669
|
+
return this._composer;
|
|
6670
|
+
}
|
|
6671
|
+
/** Renderer-owned controls, or undefined when disabled at construction or after disposal. */
|
|
6672
|
+
get controls() {
|
|
6673
|
+
return this._controls;
|
|
6674
|
+
}
|
|
6675
|
+
///
|
|
6676
|
+
};
|
|
6677
|
+
_Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
|
|
6678
|
+
camera: {
|
|
6679
|
+
type: "perspective",
|
|
6680
|
+
near: 1,
|
|
6681
|
+
far: 5e3,
|
|
6682
|
+
perspective: {
|
|
6683
|
+
aspect: void 0,
|
|
6684
|
+
fov: 50
|
|
6685
|
+
},
|
|
6686
|
+
orthographic: {
|
|
6687
|
+
left: void 0,
|
|
6688
|
+
right: void 0,
|
|
6689
|
+
top: void 0,
|
|
6690
|
+
bottom: void 0
|
|
6691
|
+
},
|
|
6692
|
+
position: new import_three19.Vector3(50, 50, 50),
|
|
6693
|
+
lookingAt: new import_three19.Vector3(0, 0, 0)
|
|
6694
|
+
},
|
|
6695
|
+
render: {
|
|
6696
|
+
fpsLimit: 60,
|
|
6697
|
+
stats: false,
|
|
6698
|
+
antialias: true,
|
|
6699
|
+
shade: true,
|
|
6700
|
+
autoResize: true,
|
|
6701
|
+
renderAlways: false
|
|
6702
|
+
},
|
|
6703
|
+
composer: {
|
|
6704
|
+
enabled: true
|
|
6705
|
+
},
|
|
6706
|
+
controls: {
|
|
6707
|
+
enabled: false
|
|
6708
|
+
},
|
|
6709
|
+
debug: {
|
|
6710
|
+
grid: false,
|
|
6711
|
+
axes: false
|
|
6712
|
+
}
|
|
6713
|
+
});
|
|
6714
|
+
var Renderer = _Renderer;
|
|
6715
|
+
|
|
6716
|
+
// src/skin/Skins.ts
|
|
6717
|
+
var Skins = class {
|
|
6718
|
+
//<editor-fold desc="Skins">
|
|
6719
|
+
static async fromUuidOrUsername(uuidOrUsername) {
|
|
6720
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6721
|
+
return this.fromUuid(uuidOrUsername);
|
|
6433
6722
|
}
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
case 2:
|
|
6444
|
-
mouseAction = scope.mouseButtons.RIGHT;
|
|
6445
|
-
break;
|
|
6446
|
-
default:
|
|
6447
|
-
mouseAction = -1;
|
|
6448
|
-
}
|
|
6449
|
-
switch (mouseAction) {
|
|
6450
|
-
case import_three20.MOUSE.DOLLY:
|
|
6451
|
-
if (scope.enableZoom === false) return;
|
|
6452
|
-
handleMouseDownDolly(event);
|
|
6453
|
-
state = STATE.DOLLY;
|
|
6454
|
-
break;
|
|
6455
|
-
case import_three20.MOUSE.ROTATE:
|
|
6456
|
-
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6457
|
-
if (scope.enablePan === false) return;
|
|
6458
|
-
handleMouseDownPan(event);
|
|
6459
|
-
state = STATE.PAN;
|
|
6460
|
-
} else {
|
|
6461
|
-
if (scope.enableRotate === false) return;
|
|
6462
|
-
handleMouseDownRotate(event);
|
|
6463
|
-
state = STATE.ROTATE;
|
|
6464
|
-
}
|
|
6465
|
-
break;
|
|
6466
|
-
case import_three20.MOUSE.PAN:
|
|
6467
|
-
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
6468
|
-
if (scope.enableRotate === false) return;
|
|
6469
|
-
handleMouseDownRotate(event);
|
|
6470
|
-
state = STATE.ROTATE;
|
|
6471
|
-
} else {
|
|
6472
|
-
if (scope.enablePan === false) return;
|
|
6473
|
-
handleMouseDownPan(event);
|
|
6474
|
-
state = STATE.PAN;
|
|
6475
|
-
}
|
|
6476
|
-
break;
|
|
6477
|
-
default:
|
|
6478
|
-
state = STATE.NONE;
|
|
6723
|
+
return this.fromUsername(uuidOrUsername);
|
|
6724
|
+
}
|
|
6725
|
+
static async fromUuid(uuid) {
|
|
6726
|
+
return this.getMcProxySkinUrl(uuid);
|
|
6727
|
+
}
|
|
6728
|
+
static async fromUsername(username) {
|
|
6729
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6730
|
+
if (uuid) {
|
|
6731
|
+
return this.fromUuid(uuid);
|
|
6479
6732
|
}
|
|
6480
|
-
|
|
6481
|
-
|
|
6733
|
+
return void 0;
|
|
6734
|
+
});
|
|
6735
|
+
}
|
|
6736
|
+
static async fromMineSkin(mineskinId) {
|
|
6737
|
+
return this.getMineSkin(mineskinId).then((mineskin) => {
|
|
6738
|
+
if (mineskin) {
|
|
6739
|
+
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
6482
6740
|
}
|
|
6741
|
+
return void 0;
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6744
|
+
//</editor-fold>
|
|
6745
|
+
//<editor-fold desc="Capes">
|
|
6746
|
+
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
6747
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6748
|
+
return this.capeFromUuid(uuidOrUsername);
|
|
6483
6749
|
}
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
handleMouseMoveDolly(event);
|
|
6494
|
-
break;
|
|
6495
|
-
case STATE.PAN:
|
|
6496
|
-
if (scope.enablePan === false) return;
|
|
6497
|
-
handleMouseMovePan(event);
|
|
6498
|
-
break;
|
|
6750
|
+
return this.capeFromUsername(uuidOrUsername);
|
|
6751
|
+
}
|
|
6752
|
+
static async capeFromUuid(uuid) {
|
|
6753
|
+
return this.getMcProxyCapeUrl(uuid);
|
|
6754
|
+
}
|
|
6755
|
+
static async capeFromUsername(username) {
|
|
6756
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6757
|
+
if (uuid) {
|
|
6758
|
+
return this.capeFromUuid(uuid);
|
|
6499
6759
|
}
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
|
|
6508
|
-
event.preventDefault();
|
|
6509
|
-
scope.dispatchEvent(_startEvent);
|
|
6510
|
-
handleMouseWheel(event);
|
|
6511
|
-
scope.dispatchEvent(_endEvent);
|
|
6512
|
-
}
|
|
6513
|
-
function onKeyDown(event) {
|
|
6514
|
-
if (scope.enabled === false || scope.enablePan === false) return;
|
|
6515
|
-
handleKeyDown(event);
|
|
6516
|
-
}
|
|
6517
|
-
function onTouchStart(event) {
|
|
6518
|
-
trackPointer(event);
|
|
6519
|
-
switch (pointers.length) {
|
|
6520
|
-
case 1:
|
|
6521
|
-
switch (scope.touches.ONE) {
|
|
6522
|
-
case import_three20.TOUCH.ROTATE:
|
|
6523
|
-
if (scope.enableRotate === false) return;
|
|
6524
|
-
handleTouchStartRotate();
|
|
6525
|
-
state = STATE.TOUCH_ROTATE;
|
|
6526
|
-
break;
|
|
6527
|
-
case import_three20.TOUCH.PAN:
|
|
6528
|
-
if (scope.enablePan === false) return;
|
|
6529
|
-
handleTouchStartPan();
|
|
6530
|
-
state = STATE.TOUCH_PAN;
|
|
6531
|
-
break;
|
|
6532
|
-
default:
|
|
6533
|
-
state = STATE.NONE;
|
|
6534
|
-
}
|
|
6535
|
-
break;
|
|
6536
|
-
case 2:
|
|
6537
|
-
switch (scope.touches.TWO) {
|
|
6538
|
-
case import_three20.TOUCH.DOLLY_PAN:
|
|
6539
|
-
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6540
|
-
handleTouchStartDollyPan();
|
|
6541
|
-
state = STATE.TOUCH_DOLLY_PAN;
|
|
6542
|
-
break;
|
|
6543
|
-
case import_three20.TOUCH.DOLLY_ROTATE:
|
|
6544
|
-
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6545
|
-
handleTouchStartDollyRotate();
|
|
6546
|
-
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
6547
|
-
break;
|
|
6548
|
-
default:
|
|
6549
|
-
state = STATE.NONE;
|
|
6550
|
-
}
|
|
6551
|
-
break;
|
|
6552
|
-
default:
|
|
6553
|
-
state = STATE.NONE;
|
|
6760
|
+
return void 0;
|
|
6761
|
+
});
|
|
6762
|
+
}
|
|
6763
|
+
static async capeFromCapesDev(uuid, capeType = "minecraft") {
|
|
6764
|
+
return this.getCapesDev(uuid, capeType).then((cape) => {
|
|
6765
|
+
if (cape) {
|
|
6766
|
+
return cape?.stillImageUrl;
|
|
6554
6767
|
}
|
|
6555
|
-
|
|
6556
|
-
|
|
6768
|
+
return void 0;
|
|
6769
|
+
});
|
|
6770
|
+
}
|
|
6771
|
+
//</editor-fold>
|
|
6772
|
+
//<editor-fold desc="Helpers">
|
|
6773
|
+
static async usernameToUuid(username) {
|
|
6774
|
+
return this.usernameToUuidMcProxy(username);
|
|
6775
|
+
}
|
|
6776
|
+
static async usernameToUuidMcProxy(username) {
|
|
6777
|
+
return Requests.genericRequest({
|
|
6778
|
+
baseURL: "https://mcproxy.dev",
|
|
6779
|
+
url: "/uuid/" + username
|
|
6780
|
+
}).then((res) => {
|
|
6781
|
+
if (res.status === 200) {
|
|
6782
|
+
return res.data["data"]["id"];
|
|
6557
6783
|
}
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
case STATE.TOUCH_DOLLY_PAN:
|
|
6573
|
-
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
6574
|
-
handleTouchMoveDollyPan(event);
|
|
6575
|
-
scope.update();
|
|
6576
|
-
break;
|
|
6577
|
-
case STATE.TOUCH_DOLLY_ROTATE:
|
|
6578
|
-
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
6579
|
-
handleTouchMoveDollyRotate(event);
|
|
6580
|
-
scope.update();
|
|
6581
|
-
break;
|
|
6582
|
-
default:
|
|
6583
|
-
state = STATE.NONE;
|
|
6784
|
+
return void 0;
|
|
6785
|
+
}).catch((err) => {
|
|
6786
|
+
console.warn(err);
|
|
6787
|
+
return void 0;
|
|
6788
|
+
});
|
|
6789
|
+
}
|
|
6790
|
+
/** @deprecated **/
|
|
6791
|
+
static async usernameToUuidSkinProxy(username) {
|
|
6792
|
+
return Requests.genericRequest({
|
|
6793
|
+
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
6794
|
+
url: "/uuid/" + username
|
|
6795
|
+
}).then((res) => {
|
|
6796
|
+
if (res.status === 200) {
|
|
6797
|
+
return res.data["id"];
|
|
6584
6798
|
}
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
function removePointer(event) {
|
|
6599
|
-
delete pointerPositions[event.pointerId];
|
|
6600
|
-
for (let i = 0; i < pointers.length; i++) {
|
|
6601
|
-
if (pointers[i].pointerId == event.pointerId) {
|
|
6602
|
-
pointers.splice(i, 1);
|
|
6603
|
-
return;
|
|
6604
|
-
}
|
|
6799
|
+
return void 0;
|
|
6800
|
+
}).catch((err) => {
|
|
6801
|
+
console.warn(err);
|
|
6802
|
+
return void 0;
|
|
6803
|
+
});
|
|
6804
|
+
}
|
|
6805
|
+
static async usernameToUuidMineTools(username) {
|
|
6806
|
+
return Requests.genericRequest({
|
|
6807
|
+
baseURL: "https://api.minetools.eu",
|
|
6808
|
+
url: "/uuid/" + username
|
|
6809
|
+
}).then((res) => {
|
|
6810
|
+
if (res.status === 200) {
|
|
6811
|
+
return res.data["id"];
|
|
6605
6812
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6813
|
+
return void 0;
|
|
6814
|
+
}).catch((err) => {
|
|
6815
|
+
console.warn(err);
|
|
6816
|
+
return void 0;
|
|
6817
|
+
});
|
|
6818
|
+
}
|
|
6819
|
+
static async getProfileFromMinetools(uuid) {
|
|
6820
|
+
return Requests.genericRequest({
|
|
6821
|
+
baseURL: "https://api.minetools.eu",
|
|
6822
|
+
url: "/profile/" + uuid
|
|
6823
|
+
}).then((res) => {
|
|
6824
|
+
if (res.status === 200) {
|
|
6825
|
+
return res.data;
|
|
6612
6826
|
}
|
|
6613
|
-
|
|
6614
|
-
}
|
|
6615
|
-
function getSecondPointerPosition(event) {
|
|
6616
|
-
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
6617
|
-
return pointerPositions[pointer.pointerId];
|
|
6618
|
-
}
|
|
6619
|
-
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6620
|
-
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6621
|
-
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6622
|
-
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6623
|
-
this.update();
|
|
6827
|
+
});
|
|
6624
6828
|
}
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6829
|
+
static async getMineSkin(mineskinId) {
|
|
6830
|
+
return Requests.genericRequest({
|
|
6831
|
+
baseURL: "https://api.mineskin.org",
|
|
6832
|
+
url: "/get/uuid/" + mineskinId
|
|
6833
|
+
}).then((res) => {
|
|
6834
|
+
if (res.status === 200) {
|
|
6835
|
+
return res.data;
|
|
6836
|
+
}
|
|
6837
|
+
return void 0;
|
|
6838
|
+
}).catch((err) => {
|
|
6839
|
+
console.warn(err);
|
|
6840
|
+
return void 0;
|
|
6841
|
+
});
|
|
6842
|
+
}
|
|
6843
|
+
static async getCapesDev(uuid, type = "all") {
|
|
6844
|
+
return Requests.genericRequest({
|
|
6845
|
+
baseURL: "https://api.capes.dev",
|
|
6846
|
+
url: "/load/" + uuid + "/" + type
|
|
6847
|
+
}).then((res) => {
|
|
6848
|
+
if (res.status === 200) {
|
|
6849
|
+
return res.data;
|
|
6850
|
+
}
|
|
6851
|
+
return void 0;
|
|
6852
|
+
}).catch((err) => {
|
|
6853
|
+
console.warn(err);
|
|
6854
|
+
return void 0;
|
|
6855
|
+
});
|
|
6856
|
+
}
|
|
6857
|
+
static getCrafatarSkinUrl(uuid) {
|
|
6858
|
+
return "https://crafatar.com/skins/" + uuid;
|
|
6859
|
+
}
|
|
6860
|
+
static getCrafatarCapeUrl(uuid) {
|
|
6861
|
+
return "https://crafatar.com/capes/" + uuid;
|
|
6862
|
+
}
|
|
6863
|
+
static getMcHeadsSkinUrl(uuid) {
|
|
6864
|
+
return "https://mc-heads.net/skin/" + uuid;
|
|
6865
|
+
}
|
|
6866
|
+
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6867
|
+
return "https://mineskin.org/skin/player/" + uuid;
|
|
6868
|
+
}
|
|
6869
|
+
/** @deprecated **/
|
|
6870
|
+
static getSkinProxySkinUrl(uuid) {
|
|
6871
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6872
|
+
}
|
|
6873
|
+
/** @deprecated **/
|
|
6874
|
+
static getSkinProxyCapeUrl(uuid) {
|
|
6875
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6876
|
+
}
|
|
6877
|
+
static getMcProxySkinUrl(uuid) {
|
|
6878
|
+
return "https://mcproxy.dev/skin/" + uuid;
|
|
6634
6879
|
}
|
|
6880
|
+
static getMcProxyCapeUrl(uuid) {
|
|
6881
|
+
return "https://mcproxy.dev/cape/" + uuid;
|
|
6882
|
+
}
|
|
6883
|
+
//</editor-fold>
|
|
6635
6884
|
};
|
|
6636
6885
|
|
|
6637
6886
|
// src/world/Chunk.ts
|
|
@@ -6748,7 +6997,7 @@ var MineRenderWorld = class {
|
|
|
6748
6997
|
};
|
|
6749
6998
|
|
|
6750
6999
|
// src/world/Chunk.ts
|
|
6751
|
-
var
|
|
7000
|
+
var p11 = prefix("Chunk");
|
|
6752
7001
|
var Chunk = class _Chunk {
|
|
6753
7002
|
constructor(scene, x, y, z) {
|
|
6754
7003
|
this._blocks = [];
|
|
@@ -6800,7 +7049,7 @@ var Chunk = class _Chunk {
|
|
|
6800
7049
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
6801
7050
|
const current = this._blocks[index];
|
|
6802
7051
|
if (typeof current !== "undefined") {
|
|
6803
|
-
console.debug(
|
|
7052
|
+
console.debug(p11, "deleting existing block at", pos, worldPos, index);
|
|
6804
7053
|
current.object.removeFromScene();
|
|
6805
7054
|
delete this._blocks[index];
|
|
6806
7055
|
}
|