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/node/index.mjs
CHANGED
|
@@ -23,14 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
24
|
mod
|
|
25
25
|
));
|
|
26
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
27
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
28
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
29
|
-
if (decorator = decorators[i])
|
|
30
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
31
|
-
if (kind && result) __defProp(target, key, result);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
26
|
|
|
35
27
|
// ../../node_modules/ts-deepmerge/dist/index.js
|
|
36
28
|
var require_dist = __commonJS({
|
|
@@ -40,8 +32,8 @@ var require_dist = __commonJS({
|
|
|
40
32
|
__assign = Object.assign || function(t) {
|
|
41
33
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
42
34
|
s = arguments[i];
|
|
43
|
-
for (var
|
|
44
|
-
t[
|
|
35
|
+
for (var p12 in s) if (Object.prototype.hasOwnProperty.call(s, p12))
|
|
36
|
+
t[p12] = s[p12];
|
|
45
37
|
}
|
|
46
38
|
return t;
|
|
47
39
|
};
|
|
@@ -85,7 +77,7 @@ var require_dist = __commonJS({
|
|
|
85
77
|
return false;
|
|
86
78
|
};
|
|
87
79
|
var PROTECTED_KEYS = ["__proto__"];
|
|
88
|
-
var
|
|
80
|
+
var merge10 = function() {
|
|
89
81
|
var objects = [];
|
|
90
82
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
91
83
|
objects[_i] = arguments[_i];
|
|
@@ -96,9 +88,9 @@ var require_dist = __commonJS({
|
|
|
96
88
|
return;
|
|
97
89
|
}
|
|
98
90
|
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
99
|
-
result[key] =
|
|
91
|
+
result[key] = merge10.options.mergeArrays ? Array.from(new Set(result[key].concat(current[key]))) : current[key];
|
|
100
92
|
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
101
|
-
result[key] =
|
|
93
|
+
result[key] = merge10(result[key], current[key]);
|
|
102
94
|
} else {
|
|
103
95
|
result[key] = current[key];
|
|
104
96
|
}
|
|
@@ -109,18 +101,18 @@ var require_dist = __commonJS({
|
|
|
109
101
|
var defaultOptions = {
|
|
110
102
|
mergeArrays: true
|
|
111
103
|
};
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
merge10.options = defaultOptions;
|
|
105
|
+
merge10.withOptions = function(options) {
|
|
114
106
|
var objects = [];
|
|
115
107
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
116
108
|
objects[_i - 1] = arguments[_i];
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
var result =
|
|
120
|
-
|
|
110
|
+
merge10.options = __assign({ mergeArrays: true }, options);
|
|
111
|
+
var result = merge10.apply(void 0, __spreadArray([], __read(objects), false));
|
|
112
|
+
merge10.options = defaultOptions;
|
|
121
113
|
return result;
|
|
122
114
|
};
|
|
123
|
-
exports.default =
|
|
115
|
+
exports.default = merge10;
|
|
124
116
|
}
|
|
125
117
|
});
|
|
126
118
|
|
|
@@ -149,25 +141,29 @@ var Env = class {
|
|
|
149
141
|
};
|
|
150
142
|
|
|
151
143
|
// src/cache/PersistentCache.ts
|
|
152
|
-
var
|
|
144
|
+
var PersistentCache = class _PersistentCache {
|
|
153
145
|
constructor(backing) {
|
|
154
146
|
this.backing = backing;
|
|
155
147
|
}
|
|
148
|
+
static {
|
|
149
|
+
/** Bump to invalidate every persisted entry. */
|
|
150
|
+
this.VERSION = 2;
|
|
151
|
+
}
|
|
156
152
|
static open(name) {
|
|
157
153
|
return Env.provider.openCache(name, _PersistentCache.VERSION);
|
|
158
154
|
}
|
|
155
|
+
/** Loads a missing entry and stores only non-nullish results. */
|
|
159
156
|
async getOrLoad(key, loader) {
|
|
160
157
|
let v = await this.get(key);
|
|
161
158
|
if (typeof v === "undefined" || v === null) {
|
|
162
159
|
v = await loader(key);
|
|
163
|
-
|
|
160
|
+
if (typeof v !== "undefined" && v !== null) {
|
|
161
|
+
await this.put(key, v);
|
|
162
|
+
}
|
|
164
163
|
}
|
|
165
164
|
return v;
|
|
166
165
|
}
|
|
167
166
|
};
|
|
168
|
-
/** Bump to invalidate every persisted entry. */
|
|
169
|
-
_PersistentCache.VERSION = 1;
|
|
170
|
-
var PersistentCache = _PersistentCache;
|
|
171
167
|
|
|
172
168
|
// src/env/node/NodeCache.ts
|
|
173
169
|
var NodeCache = class extends PersistentCache {
|
|
@@ -245,7 +241,7 @@ registerNodeEnv();
|
|
|
245
241
|
// src/Axis.ts
|
|
246
242
|
import { Vector3 } from "three";
|
|
247
243
|
var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
248
|
-
Axis3["X"] = "
|
|
244
|
+
Axis3["X"] = "x";
|
|
249
245
|
Axis3["Y"] = "y";
|
|
250
246
|
Axis3["Z"] = "z";
|
|
251
247
|
return Axis3;
|
|
@@ -253,7 +249,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
|
253
249
|
var AXES = Object.values(Axis);
|
|
254
250
|
function axisToVec3(axis) {
|
|
255
251
|
switch (axis) {
|
|
256
|
-
case "
|
|
252
|
+
case "x" /* X */:
|
|
257
253
|
return new Vector3(1, 0, 0);
|
|
258
254
|
case "y" /* Y */:
|
|
259
255
|
return new Vector3(0, 1, 0);
|
|
@@ -341,8 +337,7 @@ function serializeImageKey(key) {
|
|
|
341
337
|
return md5(key.src);
|
|
342
338
|
}
|
|
343
339
|
function serializeBoxGeometryKey(key) {
|
|
344
|
-
|
|
345
|
-
return md5([key.width, key.height, key.depth, (_a = key.uv) == null ? void 0 : _a.join(":")].join("_"));
|
|
340
|
+
return md5([key.width, key.height, key.depth, key.uv?.join(":")].join("_"));
|
|
346
341
|
}
|
|
347
342
|
function serializeTextureKey(key) {
|
|
348
343
|
return md5([key.src, key.format, key.rotation].join("$"));
|
|
@@ -357,7 +352,61 @@ function serializeMeshKey(key) {
|
|
|
357
352
|
// src/cache/Caching.ts
|
|
358
353
|
import { Caches } from "@inventivetalent/loading-cache";
|
|
359
354
|
import { Time } from "@inventivetalent/time";
|
|
360
|
-
var Caching = class {
|
|
355
|
+
var Caching = class _Caching {
|
|
356
|
+
static {
|
|
357
|
+
this.rawImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(5)).buildAsync();
|
|
358
|
+
}
|
|
359
|
+
static {
|
|
360
|
+
this.imageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
361
|
+
}
|
|
362
|
+
static {
|
|
363
|
+
this.canvasImageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
364
|
+
}
|
|
365
|
+
static {
|
|
366
|
+
this.wrappedImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
367
|
+
}
|
|
368
|
+
static {
|
|
369
|
+
this.boxGeometryCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(20)).build();
|
|
370
|
+
}
|
|
371
|
+
static {
|
|
372
|
+
this.textureCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
373
|
+
}
|
|
374
|
+
static {
|
|
375
|
+
this.materialCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
376
|
+
}
|
|
377
|
+
static {
|
|
378
|
+
this.boxMeshCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
379
|
+
}
|
|
380
|
+
static {
|
|
381
|
+
this.textureAssetCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
382
|
+
}
|
|
383
|
+
static {
|
|
384
|
+
this.textureMetaCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
385
|
+
}
|
|
386
|
+
static {
|
|
387
|
+
this.rawModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
388
|
+
}
|
|
389
|
+
static {
|
|
390
|
+
this.mergedModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
391
|
+
}
|
|
392
|
+
static {
|
|
393
|
+
this.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
394
|
+
}
|
|
395
|
+
static {
|
|
396
|
+
this.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
397
|
+
}
|
|
398
|
+
static {
|
|
399
|
+
this.listAssetCache = _Caching.createAssetCache();
|
|
400
|
+
}
|
|
401
|
+
static {
|
|
402
|
+
this.defaultBlockStatesCache = _Caching.createAssetCache();
|
|
403
|
+
}
|
|
404
|
+
static {
|
|
405
|
+
this.entityModelsCache = _Caching.createAssetCache();
|
|
406
|
+
}
|
|
407
|
+
static createAssetCache() {
|
|
408
|
+
return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
409
|
+
}
|
|
361
410
|
/** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
|
|
362
411
|
static get all() {
|
|
363
412
|
return [
|
|
@@ -374,7 +423,10 @@ var Caching = class {
|
|
|
374
423
|
this.rawModelCache,
|
|
375
424
|
this.mergedModelCache,
|
|
376
425
|
this.modelTextureAtlasCache,
|
|
377
|
-
this.blockStateCache
|
|
426
|
+
this.blockStateCache,
|
|
427
|
+
this.listAssetCache,
|
|
428
|
+
this.defaultBlockStatesCache,
|
|
429
|
+
this.entityModelsCache
|
|
378
430
|
];
|
|
379
431
|
}
|
|
380
432
|
static clear() {
|
|
@@ -385,8 +437,8 @@ var Caching = class {
|
|
|
385
437
|
/**
|
|
386
438
|
* Clears every cache and stops its expiry timer.
|
|
387
439
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
440
|
+
* Expiry timers are unref'd in Node, so idle processes can exit without this cleanup.
|
|
441
|
+
* Use {@link shutdown} to also stop requests and the shared Ticker.
|
|
390
442
|
*/
|
|
391
443
|
static end() {
|
|
392
444
|
for (const cache of this.all) {
|
|
@@ -400,20 +452,6 @@ var Caching = class {
|
|
|
400
452
|
};
|
|
401
453
|
}
|
|
402
454
|
};
|
|
403
|
-
Caching.rawImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(5)).buildAsync();
|
|
404
|
-
Caching.imageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
405
|
-
Caching.canvasImageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
406
|
-
Caching.wrappedImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
|
|
407
|
-
Caching.boxGeometryCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(20)).build();
|
|
408
|
-
Caching.textureCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
409
|
-
Caching.materialCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
410
|
-
Caching.boxMeshCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
|
|
411
|
-
Caching.textureAssetCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
412
|
-
Caching.textureMetaCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
413
|
-
Caching.rawModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
414
|
-
Caching.mergedModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
415
|
-
Caching.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
416
|
-
Caching.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
417
455
|
|
|
418
456
|
// src/Geometries.ts
|
|
419
457
|
var Geometries = class _Geometries {
|
|
@@ -441,6 +479,7 @@ import { CanvasTexture, Texture as Texture2 } from "three";
|
|
|
441
479
|
|
|
442
480
|
// src/texture/TextureLoader.ts
|
|
443
481
|
import { RGBAFormat, Texture } from "three";
|
|
482
|
+
import * as THREE from "three";
|
|
444
483
|
|
|
445
484
|
// src/canvas/CanvasCompat.ts
|
|
446
485
|
function createImage(width, height) {
|
|
@@ -451,9 +490,7 @@ function createCanvas2(width, height) {
|
|
|
451
490
|
}
|
|
452
491
|
|
|
453
492
|
// src/request/Requests.ts
|
|
454
|
-
import
|
|
455
|
-
import { JobQueue } from "jobqu";
|
|
456
|
-
import { Time as Time2 } from "@inventivetalent/time";
|
|
493
|
+
import { JobCancelledError, JobQueue } from "jobqu";
|
|
457
494
|
|
|
458
495
|
// src/util/log.ts
|
|
459
496
|
var Reset = "\x1B[0m";
|
|
@@ -463,198 +500,174 @@ function prefix(prefix2) {
|
|
|
463
500
|
return `${FgGreen}MR${BgBlack}${prefix2 ?? ""}${Reset}`;
|
|
464
501
|
}
|
|
465
502
|
|
|
466
|
-
// src/
|
|
467
|
-
var
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
this.
|
|
472
|
-
this.
|
|
473
|
-
|
|
474
|
-
submit(task) {
|
|
475
|
-
this.queue.push(task);
|
|
476
|
-
}
|
|
477
|
-
run() {
|
|
478
|
-
for (let i = 0; i < this.batch; i++) {
|
|
479
|
-
this.runNext();
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
runNext() {
|
|
483
|
-
let next = this.queue.shift();
|
|
484
|
-
if (next) next();
|
|
503
|
+
// src/request/Requests.ts
|
|
504
|
+
var p = prefix("Requests");
|
|
505
|
+
var RequestError = class extends Error {
|
|
506
|
+
constructor(message, response, cause) {
|
|
507
|
+
super(message);
|
|
508
|
+
this.response = response;
|
|
509
|
+
this.cause = cause;
|
|
510
|
+
this.name = "RequestError";
|
|
485
511
|
}
|
|
486
512
|
};
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
513
|
+
async function fetchRequest(config, defaultBaseURL) {
|
|
514
|
+
const { url, baseURL = defaultBaseURL, timeout = 5e3, responseType = "json", signal, ...options } = config;
|
|
515
|
+
const target = baseURL && !/^([a-z][a-z\d+.-]*:|\/\/)/i.test(url) ? `${baseURL.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}` : url;
|
|
516
|
+
const headers = new Headers(options.headers);
|
|
517
|
+
if (typeof window === "undefined" && !headers.has("User-Agent")) {
|
|
518
|
+
headers.set("User-Agent", "MineRender");
|
|
519
|
+
}
|
|
520
|
+
const attemptSignal = AbortSignal.any([
|
|
521
|
+
...signal ? [signal] : [],
|
|
522
|
+
...timeout === 0 ? [] : [AbortSignal.timeout(timeout)]
|
|
523
|
+
]);
|
|
524
|
+
const request = new Request(target, { ...options, headers, signal: attemptSignal });
|
|
525
|
+
attemptSignal.throwIfAborted();
|
|
526
|
+
try {
|
|
527
|
+
const response = await fetch(request);
|
|
528
|
+
const result = {
|
|
529
|
+
data: void 0,
|
|
530
|
+
status: response.status,
|
|
531
|
+
statusText: response.statusText,
|
|
532
|
+
headers: response.headers,
|
|
533
|
+
url: response.url
|
|
534
|
+
};
|
|
535
|
+
if (!response.ok) {
|
|
536
|
+
await response.body?.cancel().catch(() => {
|
|
537
|
+
});
|
|
538
|
+
throw new RequestError(`Request failed with status ${response.status}`, result);
|
|
539
|
+
}
|
|
540
|
+
const emptyBody = request.method === "HEAD" || response.status === 204 || response.status === 205;
|
|
541
|
+
const data = responseType === "arraybuffer" ? await response.arrayBuffer() : emptyBody || response.body === null ? void 0 : await response.json();
|
|
542
|
+
return { ...result, data };
|
|
543
|
+
} catch (error) {
|
|
544
|
+
attemptSignal.throwIfAborted();
|
|
545
|
+
if (/^https?:/.test(request.url) && request.redirect !== "error" && error instanceof TypeError) {
|
|
546
|
+
throw new RequestError("Network request failed", void 0, error);
|
|
511
547
|
}
|
|
548
|
+
throw error;
|
|
512
549
|
}
|
|
513
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
514
|
-
}
|
|
515
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
516
|
-
const origin = new Vector32(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
517
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
518
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
519
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
520
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
521
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
522
550
|
}
|
|
523
|
-
function
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
551
|
+
async function abortable(promise, signal) {
|
|
552
|
+
if (!signal) return promise;
|
|
553
|
+
let abort;
|
|
554
|
+
const cancelled = new Promise((_, reject) => {
|
|
555
|
+
abort = () => reject(signal.reason);
|
|
556
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
557
|
+
if (signal.aborted) abort();
|
|
558
|
+
});
|
|
559
|
+
try {
|
|
560
|
+
return await Promise.race([promise, cancelled]);
|
|
561
|
+
} finally {
|
|
562
|
+
signal.removeEventListener("abort", abort);
|
|
534
563
|
}
|
|
535
564
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
let axes = new AxesHelper(1);
|
|
545
|
-
obj.add(axes);
|
|
546
|
-
}
|
|
547
|
-
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
548
|
-
let boxGeo = new BoxGeometry2(16, 16, 16, 1, 1, 1);
|
|
549
|
-
let wireGeo = new EdgesGeometry(boxGeo);
|
|
550
|
-
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
551
|
-
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
552
|
-
obj.add(wireframe);
|
|
553
|
-
let axes = new AxesHelper(1);
|
|
554
|
-
obj.add(axes);
|
|
555
|
-
}
|
|
556
|
-
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
557
|
-
let wireGeo = new EdgesGeometry(geo);
|
|
558
|
-
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
559
|
-
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
560
|
-
mesh.add(wireframe);
|
|
561
|
-
let axes = new AxesHelper(1);
|
|
562
|
-
mesh.add(axes);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/util/performance.ts
|
|
566
|
-
function captureException(e, ...extra) {
|
|
567
|
-
console.error(e, extra);
|
|
568
|
-
}
|
|
569
|
-
function timingStart(marker) {
|
|
570
|
-
console.time(marker);
|
|
571
|
-
}
|
|
572
|
-
function timingEnd(marker) {
|
|
573
|
-
console.timeEnd(marker);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// src/util/three.ts
|
|
577
|
-
function isObject3D(obj) {
|
|
578
|
-
return obj.isObject3D;
|
|
579
|
-
}
|
|
580
|
-
function isMesh(obj) {
|
|
581
|
-
return obj.isMesh;
|
|
582
|
-
}
|
|
583
|
-
function isInstancedMesh(obj) {
|
|
584
|
-
return obj.isInstancedMesh;
|
|
585
|
-
}
|
|
586
|
-
function isPerspectiveCamera(obj) {
|
|
587
|
-
return obj.isPerspectiveCamera;
|
|
588
|
-
}
|
|
589
|
-
function isOrthographicCamera(obj) {
|
|
590
|
-
return obj.isOrthographicCamera;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// src/request/Requests.ts
|
|
594
|
-
var p = prefix("Requests");
|
|
595
|
-
if (typeof window === "undefined") {
|
|
596
|
-
axios.defaults.headers["User-Agent"] = "MineRender";
|
|
597
|
-
}
|
|
598
|
-
var _Requests = class _Requests {
|
|
599
|
-
static genericRequest(request) {
|
|
600
|
-
return this.genericQueue.add(request).catch(async (e) => {
|
|
601
|
-
console.debug(p, "generic catch", e.code, e);
|
|
602
|
-
if (this.shouldRetry(e, request)) {
|
|
603
|
-
await sleep(100);
|
|
604
|
-
return this.genericRequest(request);
|
|
605
|
-
}
|
|
606
|
-
throw e;
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
static mcAssetRequest(request) {
|
|
610
|
-
return this.mcAssetRequestQueue.add(request).catch((e) => {
|
|
611
|
-
console.debug(p, "mcAssetRequest catch", e.code, e);
|
|
612
|
-
throw e;
|
|
613
|
-
});
|
|
565
|
+
var RequestQueue = class {
|
|
566
|
+
constructor() {
|
|
567
|
+
this.pendingRequests = 0;
|
|
568
|
+
this.stopped = new AbortController();
|
|
569
|
+
this.queue = new JobQueue(
|
|
570
|
+
(request) => fetchRequest(request, this.baseURL),
|
|
571
|
+
{ interval: 10, maxPerRun: 1, maxActive: 8 }
|
|
572
|
+
);
|
|
614
573
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
574
|
+
async request(request) {
|
|
575
|
+
this.pendingRequests++;
|
|
576
|
+
const signal = request.signal;
|
|
577
|
+
try {
|
|
578
|
+
for (let retries = 0; ; retries++) {
|
|
579
|
+
signal?.throwIfAborted();
|
|
580
|
+
try {
|
|
581
|
+
return await abortable(this.queue.add(request), signal);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
console.debug(p, "Request failed", error);
|
|
584
|
+
const delay = this.retryDelay(error, request, retries);
|
|
585
|
+
if (delay === void 0) {
|
|
586
|
+
throw error;
|
|
622
587
|
}
|
|
623
|
-
|
|
624
|
-
request["minerenderRetry"] = 3;
|
|
625
|
-
return true;
|
|
588
|
+
await this.waitForRetry(delay, signal);
|
|
626
589
|
}
|
|
627
590
|
}
|
|
591
|
+
} finally {
|
|
592
|
+
if (signal?.aborted) {
|
|
593
|
+
this.queue.remove(request);
|
|
594
|
+
}
|
|
595
|
+
this.pendingRequests--;
|
|
628
596
|
}
|
|
629
|
-
|
|
597
|
+
}
|
|
598
|
+
retryDelay(error, request, retries) {
|
|
599
|
+
if (this.stopped.signal.aborted || retries >= 3 || (request.method ?? "get").toLowerCase() !== "get" || request.signal?.aborted) {
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
if (error instanceof RequestError) {
|
|
603
|
+
const status = error.response?.status;
|
|
604
|
+
if (status !== void 0 && status !== 408 && status !== 429 && !(status >= 500 && status < 600)) return void 0;
|
|
605
|
+
} else if (!(error instanceof DOMException && error.name === "TimeoutError")) {
|
|
606
|
+
return void 0;
|
|
607
|
+
}
|
|
608
|
+
let delay = 100 * 2 ** retries;
|
|
609
|
+
const retryAfter = error instanceof RequestError ? error.response?.headers.get("Retry-After") : void 0;
|
|
610
|
+
if (retryAfter !== void 0 && retryAfter !== null) {
|
|
611
|
+
const seconds = Number(retryAfter);
|
|
612
|
+
if (!retryAfter.trim() || !Number.isFinite(seconds) || seconds < 0) {
|
|
613
|
+
return void 0;
|
|
614
|
+
}
|
|
615
|
+
delay = Math.max(delay, seconds * 1e3);
|
|
616
|
+
}
|
|
617
|
+
return delay;
|
|
618
|
+
}
|
|
619
|
+
async waitForRetry(delay, signal) {
|
|
620
|
+
let timer;
|
|
621
|
+
const waiting = new Promise((resolve) => {
|
|
622
|
+
timer = setTimeout(resolve, delay);
|
|
623
|
+
});
|
|
624
|
+
try {
|
|
625
|
+
await abortable(waiting, AbortSignal.any([this.stopped.signal, ...signal ? [signal] : []]));
|
|
626
|
+
} finally {
|
|
627
|
+
clearTimeout(timer);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
get pendingSize() {
|
|
631
|
+
return this.pendingRequests;
|
|
632
|
+
}
|
|
633
|
+
end() {
|
|
634
|
+
this.queue.end();
|
|
635
|
+
this.stopped.abort(new JobCancelledError("ended"));
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
var Requests = class {
|
|
639
|
+
static {
|
|
640
|
+
this.genericQueue = new RequestQueue();
|
|
641
|
+
}
|
|
642
|
+
static {
|
|
643
|
+
this.mcAssetRequestQueue = new RequestQueue();
|
|
644
|
+
}
|
|
645
|
+
static genericRequest(request) {
|
|
646
|
+
return this.genericQueue.request(request);
|
|
647
|
+
}
|
|
648
|
+
static mcAssetRequest(request) {
|
|
649
|
+
return this.mcAssetRequestQueue.request(request);
|
|
630
650
|
}
|
|
631
651
|
static setMcAssetRoot(root) {
|
|
632
|
-
this.
|
|
652
|
+
this.mcAssetRequestQueue.baseURL = root;
|
|
633
653
|
}
|
|
654
|
+
/** Counts unsettled calls, including retry delays and requests still running after shutdown. */
|
|
634
655
|
static get queueSizes() {
|
|
635
656
|
return {
|
|
636
|
-
generic: this.genericQueue.
|
|
637
|
-
mcAsset: this.mcAssetRequestQueue.
|
|
657
|
+
generic: this.genericQueue.pendingSize,
|
|
658
|
+
mcAsset: this.mcAssetRequestQueue.pendingSize
|
|
638
659
|
};
|
|
639
660
|
}
|
|
640
661
|
/**
|
|
641
|
-
*
|
|
642
|
-
*
|
|
662
|
+
* Permanently stops both queues and rejects waiting, retrying, and future requests.
|
|
663
|
+
* Requests already running can finish. Idle queues hold no timer, so Node can exit without
|
|
664
|
+
* this cleanup. See {@link shutdown}.
|
|
643
665
|
*/
|
|
644
666
|
static end() {
|
|
645
667
|
this.genericQueue.end();
|
|
646
668
|
this.mcAssetRequestQueue.end();
|
|
647
669
|
}
|
|
648
670
|
};
|
|
649
|
-
_Requests.axiosInstance = axios.create({
|
|
650
|
-
timeout: 5e3
|
|
651
|
-
});
|
|
652
|
-
_Requests.mcAssetInstance = axios.create({
|
|
653
|
-
timeout: 5e3
|
|
654
|
-
});
|
|
655
|
-
_Requests.genericQueue = new JobQueue((request) => _Requests.axiosInstance.request(request), Time2.millis(10), 1);
|
|
656
|
-
_Requests.mcAssetRequestQueue = new JobQueue((request) => _Requests.mcAssetInstance.request(request), Time2.millis(10), 1);
|
|
657
|
-
var Requests = _Requests;
|
|
658
671
|
|
|
659
672
|
// src/WrappedImage.ts
|
|
660
673
|
var WrappedImage = class {
|
|
@@ -692,10 +705,10 @@ var WrappedImage = class {
|
|
|
692
705
|
return this.animated ? this.width : this.height;
|
|
693
706
|
}
|
|
694
707
|
get frameCount() {
|
|
695
|
-
return this.height / this.
|
|
708
|
+
return this.height / this.frameHeight;
|
|
696
709
|
}
|
|
697
710
|
getFrameY(frame) {
|
|
698
|
-
return this.
|
|
711
|
+
return this.frameHeight * Math.max(0, Math.min(this.frameCount - 1, frame));
|
|
699
712
|
}
|
|
700
713
|
getSectionData(sx, sy, sw, sh) {
|
|
701
714
|
return this.dta.data.getImageData(sx, sy, sw, sh);
|
|
@@ -705,7 +718,7 @@ var WrappedImage = class {
|
|
|
705
718
|
}
|
|
706
719
|
getFrameSectionData(frame) {
|
|
707
720
|
const y = this.getFrameY(frame);
|
|
708
|
-
return this.getSectionData(0, y, this.
|
|
721
|
+
return this.getSectionData(0, y, this.frameWidth, this.frameHeight);
|
|
709
722
|
}
|
|
710
723
|
};
|
|
711
724
|
|
|
@@ -719,29 +732,41 @@ var ImageLoader = class _ImageLoader {
|
|
|
719
732
|
static async loadAsync(src) {
|
|
720
733
|
return new Promise((resolve, reject) => {
|
|
721
734
|
const image = this._createImage();
|
|
722
|
-
image.src = src;
|
|
723
735
|
image.onload = () => resolve(image);
|
|
724
|
-
image.onerror = (err) => reject(err);
|
|
736
|
+
image.onerror = (err) => reject(err instanceof Error ? err : new Error("Failed to decode image"));
|
|
737
|
+
image.src = src;
|
|
725
738
|
});
|
|
726
739
|
}
|
|
727
740
|
static loadElement(src, onload, onerr) {
|
|
728
741
|
const image = this._createImage();
|
|
729
|
-
image.src = src;
|
|
730
742
|
if (onload)
|
|
731
743
|
image.onload = onload;
|
|
732
744
|
if (onerr)
|
|
733
745
|
image.onerror = onerr;
|
|
746
|
+
image.src = src;
|
|
734
747
|
return image;
|
|
735
748
|
}
|
|
736
749
|
static async loadData(src) {
|
|
737
750
|
console.debug(p2, "loadData", src);
|
|
738
|
-
|
|
751
|
+
const image = await this.loadCanvasData(src);
|
|
752
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
739
753
|
}
|
|
740
754
|
static async loadCanvasData(src) {
|
|
741
|
-
|
|
755
|
+
const keyStr = serializeImageKey({ src });
|
|
756
|
+
const info = this.getInfo(src);
|
|
757
|
+
const cached = Caching.rawImageCache.getIfPresent(keyStr);
|
|
758
|
+
try {
|
|
759
|
+
return await this.infoToCanvasData(await info);
|
|
760
|
+
} catch (err) {
|
|
761
|
+
if (cached && Caching.rawImageCache.getIfPresent(keyStr) === cached) {
|
|
762
|
+
Caching.rawImageCache.invalidate(keyStr);
|
|
763
|
+
}
|
|
764
|
+
throw err;
|
|
765
|
+
}
|
|
742
766
|
}
|
|
743
767
|
static async infoToCanvasData(info) {
|
|
744
|
-
const
|
|
768
|
+
const type = info.type === "jpg" ? "jpeg" : info.type ?? "png";
|
|
769
|
+
const image = await _ImageLoader.loadAsync(`data:image/${type};base64,${info.data.toString("base64")}`);
|
|
745
770
|
const canvas = createCanvas2(info.width, info.height);
|
|
746
771
|
const context = canvas.getContext("2d");
|
|
747
772
|
context.drawImage(image, 0, 0);
|
|
@@ -752,11 +777,8 @@ var ImageLoader = class _ImageLoader {
|
|
|
752
777
|
};
|
|
753
778
|
}
|
|
754
779
|
static async infoToData(info) {
|
|
755
|
-
const image = await
|
|
756
|
-
|
|
757
|
-
const context = canvas.getContext("2d");
|
|
758
|
-
context.drawImage(image, 0, 0);
|
|
759
|
-
return context.getImageData(0, 0, canvas.width, canvas.height);
|
|
780
|
+
const image = await this.infoToCanvasData(info);
|
|
781
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
760
782
|
}
|
|
761
783
|
static async getData(src) {
|
|
762
784
|
const keyStr = serializeImageKey({ src });
|
|
@@ -771,38 +793,25 @@ var ImageLoader = class _ImageLoader {
|
|
|
771
793
|
});
|
|
772
794
|
}
|
|
773
795
|
static async processResponse(response) {
|
|
774
|
-
const src = response.
|
|
796
|
+
const src = response.url;
|
|
775
797
|
const data = Buffer2.from(response.data);
|
|
776
798
|
const { width, height, type } = Env.provider.imageSize(data);
|
|
799
|
+
if (!width || !height) {
|
|
800
|
+
throw new Error("Invalid or unsupported image dimensions");
|
|
801
|
+
}
|
|
777
802
|
return {
|
|
778
803
|
src,
|
|
779
|
-
width
|
|
780
|
-
height
|
|
804
|
+
width,
|
|
805
|
+
height,
|
|
781
806
|
type,
|
|
782
807
|
data
|
|
783
808
|
};
|
|
784
809
|
}
|
|
785
810
|
static async loadInfo(src) {
|
|
786
|
-
if (src.startsWith("data:image/png;base64")) {
|
|
787
|
-
return this.processResponse({
|
|
788
|
-
config: {
|
|
789
|
-
url: src
|
|
790
|
-
},
|
|
791
|
-
data: Buffer2.from(src.substr("data:image/png;base64,".length), "base64")
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
811
|
return Requests.genericRequest({
|
|
795
812
|
url: src,
|
|
796
813
|
responseType: "arraybuffer"
|
|
797
|
-
}).then(this.processResponse)
|
|
798
|
-
return {
|
|
799
|
-
src,
|
|
800
|
-
width: 0,
|
|
801
|
-
height: 0,
|
|
802
|
-
type: void 0,
|
|
803
|
-
data: Buffer2.from([0])
|
|
804
|
-
};
|
|
805
|
-
});
|
|
814
|
+
}).then(this.processResponse);
|
|
806
815
|
}
|
|
807
816
|
static async getInfo(src) {
|
|
808
817
|
const keyStr = serializeImageKey({ src });
|
|
@@ -824,15 +833,25 @@ var ImageLoader = class _ImageLoader {
|
|
|
824
833
|
|
|
825
834
|
// src/texture/TextureLoader.ts
|
|
826
835
|
var TextureLoader = class {
|
|
836
|
+
static {
|
|
837
|
+
this.failedTextures = /* @__PURE__ */ new WeakSet();
|
|
838
|
+
}
|
|
839
|
+
/** Reports whether image loading failed, so cached textures can be retried. */
|
|
840
|
+
static hasFailed(texture) {
|
|
841
|
+
return this.failedTextures.has(texture);
|
|
842
|
+
}
|
|
827
843
|
static createTexture() {
|
|
828
844
|
return new Texture();
|
|
829
845
|
}
|
|
830
846
|
static loadInBackground(src, format = RGBAFormat, rotation = 0) {
|
|
831
847
|
const texture = this.createTexture();
|
|
832
|
-
|
|
833
|
-
image
|
|
848
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
849
|
+
const image = ImageLoader.loadElement(src, () => {
|
|
834
850
|
texture.needsUpdate = true;
|
|
835
|
-
}
|
|
851
|
+
}, (error) => {
|
|
852
|
+
this.failedTextures.add(texture);
|
|
853
|
+
console.warn("Failed to load texture", src, error);
|
|
854
|
+
});
|
|
836
855
|
texture.image = image;
|
|
837
856
|
texture.format = format;
|
|
838
857
|
texture.rotation = rotation;
|
|
@@ -840,9 +859,13 @@ var TextureLoader = class {
|
|
|
840
859
|
}
|
|
841
860
|
static load(src, format = RGBAFormat, rotation = 0) {
|
|
842
861
|
const texture = new Texture();
|
|
862
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
843
863
|
ImageLoader.getData(src).then((image) => {
|
|
844
|
-
texture.needsUpdate = true;
|
|
845
864
|
texture.image = image;
|
|
865
|
+
texture.needsUpdate = true;
|
|
866
|
+
}).catch((error) => {
|
|
867
|
+
this.failedTextures.add(texture);
|
|
868
|
+
console.warn("Failed to load texture", src, error);
|
|
846
869
|
});
|
|
847
870
|
texture.format = format;
|
|
848
871
|
texture.rotation = rotation;
|
|
@@ -851,11 +874,11 @@ var TextureLoader = class {
|
|
|
851
874
|
};
|
|
852
875
|
|
|
853
876
|
// src/texture/Textures.ts
|
|
854
|
-
import * as
|
|
877
|
+
import * as THREE2 from "three";
|
|
855
878
|
var Textures = class _Textures {
|
|
856
879
|
static initTextureProps(texture) {
|
|
857
|
-
texture.magFilter =
|
|
858
|
-
texture.minFilter =
|
|
880
|
+
texture.magFilter = THREE2.NearestFilter;
|
|
881
|
+
texture.minFilter = THREE2.NearestFilter;
|
|
859
882
|
texture.anisotropy = 0;
|
|
860
883
|
return texture;
|
|
861
884
|
}
|
|
@@ -866,10 +889,16 @@ var Textures = class _Textures {
|
|
|
866
889
|
return new Texture2();
|
|
867
890
|
}
|
|
868
891
|
static createCanvasTexture(canvas) {
|
|
869
|
-
|
|
892
|
+
const texture = new CanvasTexture(canvas);
|
|
893
|
+
texture.colorSpace = THREE2.SRGBColorSpace;
|
|
894
|
+
return this.initTextureProps(texture);
|
|
870
895
|
}
|
|
871
896
|
static getImage(key) {
|
|
872
897
|
const keyStr = serializeTextureKey(key);
|
|
898
|
+
const cached = Caching.textureCache.peek(keyStr);
|
|
899
|
+
if (cached && TextureLoader.hasFailed(cached)) {
|
|
900
|
+
Caching.textureCache.invalidate(keyStr);
|
|
901
|
+
}
|
|
873
902
|
return Caching.textureCache.get(keyStr, (k) => {
|
|
874
903
|
return _Textures.createImage(key);
|
|
875
904
|
});
|
|
@@ -877,7 +906,10 @@ var Textures = class _Textures {
|
|
|
877
906
|
};
|
|
878
907
|
|
|
879
908
|
// src/Materials.ts
|
|
880
|
-
var
|
|
909
|
+
var Materials = class _Materials {
|
|
910
|
+
static {
|
|
911
|
+
this.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
|
|
912
|
+
}
|
|
881
913
|
// resolved lazily: as a static field this decoded an image the moment the library was
|
|
882
914
|
// imported, which needs both a DOM and an EnvProvider to already be in place
|
|
883
915
|
static get MISSING_TEXTURE() {
|
|
@@ -913,6 +945,7 @@ var _Materials = class _Materials {
|
|
|
913
945
|
uniform bool SHADE;
|
|
914
946
|
|
|
915
947
|
varying vec2 vUv;
|
|
948
|
+
varying vec3 vTint;
|
|
916
949
|
varying float light;
|
|
917
950
|
varying float lift;
|
|
918
951
|
|
|
@@ -925,7 +958,11 @@ var _Materials = class _Materials {
|
|
|
925
958
|
|
|
926
959
|
if (SHADE) {
|
|
927
960
|
|
|
928
|
-
|
|
961
|
+
#ifdef USE_INSTANCING
|
|
962
|
+
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
963
|
+
#else
|
|
964
|
+
vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
|
|
965
|
+
#endif
|
|
929
966
|
|
|
930
967
|
float yLight = (1.0+N.y) * 0.5;
|
|
931
968
|
light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
|
|
@@ -943,6 +980,7 @@ var _Materials = class _Materials {
|
|
|
943
980
|
}
|
|
944
981
|
|
|
945
982
|
vUv = uv;
|
|
983
|
+
vTint = color;
|
|
946
984
|
|
|
947
985
|
#ifdef USE_INSTANCING
|
|
948
986
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
|
|
@@ -964,12 +1002,14 @@ var _Materials = class _Materials {
|
|
|
964
1002
|
uniform float BRIGHTNESS;
|
|
965
1003
|
|
|
966
1004
|
varying vec2 vUv;
|
|
1005
|
+
varying vec3 vTint;
|
|
967
1006
|
varying float light;
|
|
968
1007
|
varying float lift;
|
|
969
1008
|
|
|
970
1009
|
void main(void)
|
|
971
1010
|
{
|
|
972
1011
|
vec4 color = texture2D(map, vUv);
|
|
1012
|
+
color.rgb *= vTint;
|
|
973
1013
|
|
|
974
1014
|
if (color.a < 0.01) discard;
|
|
975
1015
|
|
|
@@ -983,6 +1023,9 @@ var _Materials = class _Materials {
|
|
|
983
1023
|
gl_FragColor = vec4(lift + color.rgb * light2, 1.0);
|
|
984
1024
|
|
|
985
1025
|
}
|
|
1026
|
+
|
|
1027
|
+
#include <tonemapping_fragment>
|
|
1028
|
+
#include <colorspace_fragment>
|
|
986
1029
|
}
|
|
987
1030
|
`;
|
|
988
1031
|
try {
|
|
@@ -1011,6 +1054,10 @@ var _Materials = class _Materials {
|
|
|
1011
1054
|
}
|
|
1012
1055
|
static getImage(key) {
|
|
1013
1056
|
const keyStr = serializeMaterialKey(key);
|
|
1057
|
+
const map = Caching.materialCache.peek(keyStr)?.map;
|
|
1058
|
+
if (map && TextureLoader.hasFailed(map)) {
|
|
1059
|
+
Caching.materialCache.invalidate(keyStr);
|
|
1060
|
+
}
|
|
1014
1061
|
return Caching.materialCache.get(keyStr, (k) => {
|
|
1015
1062
|
return _Materials.createImage(key);
|
|
1016
1063
|
});
|
|
@@ -1031,14 +1078,12 @@ var _Materials = class _Materials {
|
|
|
1031
1078
|
}
|
|
1032
1079
|
}
|
|
1033
1080
|
};
|
|
1034
|
-
_Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
|
|
1035
|
-
var Materials = _Materials;
|
|
1036
1081
|
|
|
1037
1082
|
// src/Meshes.ts
|
|
1038
|
-
import { Mesh
|
|
1083
|
+
import { Mesh } from "three";
|
|
1039
1084
|
var Meshes = class _Meshes {
|
|
1040
1085
|
static createBox(key) {
|
|
1041
|
-
return new
|
|
1086
|
+
return new Mesh(Geometries.getBox(key.geometry), Materials.getImage(key.material));
|
|
1042
1087
|
}
|
|
1043
1088
|
static getBox(key) {
|
|
1044
1089
|
const keyStr = serializeMeshKey(key);
|
|
@@ -1049,7 +1094,7 @@ var Meshes = class _Meshes {
|
|
|
1049
1094
|
};
|
|
1050
1095
|
|
|
1051
1096
|
// src/UVMapper.ts
|
|
1052
|
-
import { Float32BufferAttribute as Float32BufferAttribute2, Vector2 } from "three";
|
|
1097
|
+
import { Float32BufferAttribute as Float32BufferAttribute2, Vector2, Vector3 as Vector33 } from "three";
|
|
1053
1098
|
|
|
1054
1099
|
// src/model/ModelMerger.ts
|
|
1055
1100
|
var import_ts_deepmerge = __toESM(require_dist());
|
|
@@ -1085,9 +1130,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1085
1130
|
this.rootType = rootType;
|
|
1086
1131
|
this.extension = extension;
|
|
1087
1132
|
this.root = root;
|
|
1133
|
+
this.isAssetKey = true;
|
|
1088
1134
|
}
|
|
1089
1135
|
static parse(assetType, str, origin) {
|
|
1090
|
-
let namespace =
|
|
1136
|
+
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
1091
1137
|
if (str.includes(":")) {
|
|
1092
1138
|
let split2 = str.split(":");
|
|
1093
1139
|
namespace = split2[0];
|
|
@@ -1100,12 +1146,15 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1100
1146
|
split.shift();
|
|
1101
1147
|
}
|
|
1102
1148
|
let path = split.join("/");
|
|
1103
|
-
|
|
1104
|
-
|
|
1149
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1150
|
+
if (extension && path.endsWith(extension)) {
|
|
1151
|
+
path = path.slice(0, -extension.length);
|
|
1152
|
+
}
|
|
1153
|
+
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1105
1154
|
}
|
|
1106
1155
|
toString() {
|
|
1107
1156
|
let a = [
|
|
1108
|
-
|
|
1157
|
+
this.root ?? AssetLoader.ROOT,
|
|
1109
1158
|
this.rootType ?? "__rootType__",
|
|
1110
1159
|
this.assetType ?? "__assetType__",
|
|
1111
1160
|
this.type ?? "__type__",
|
|
@@ -1115,12 +1164,12 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1115
1164
|
return a.join("/");
|
|
1116
1165
|
}
|
|
1117
1166
|
getFullPath() {
|
|
1118
|
-
let
|
|
1167
|
+
let p12 = [];
|
|
1119
1168
|
if (this.type) {
|
|
1120
|
-
|
|
1169
|
+
p12.push(this.type);
|
|
1121
1170
|
}
|
|
1122
|
-
|
|
1123
|
-
return
|
|
1171
|
+
p12.push(this.path);
|
|
1172
|
+
return p12.join("/");
|
|
1124
1173
|
}
|
|
1125
1174
|
toNamespacedString() {
|
|
1126
1175
|
return this.namespace + ":" + this.getFullPath();
|
|
@@ -1130,10 +1179,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1130
1179
|
}
|
|
1131
1180
|
};
|
|
1132
1181
|
function isBasicAssetKey(obj) {
|
|
1133
|
-
return "
|
|
1182
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1134
1183
|
}
|
|
1135
1184
|
function isAssetKey(obj) {
|
|
1136
|
-
return isBasicAssetKey(obj) &&
|
|
1185
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1137
1186
|
}
|
|
1138
1187
|
|
|
1139
1188
|
// src/model/ModelMerger.ts
|
|
@@ -1142,10 +1191,10 @@ var ModelMerger = class {
|
|
|
1142
1191
|
const models = await this.collectAllParents(model);
|
|
1143
1192
|
let merged = {};
|
|
1144
1193
|
for (let parentModel of models) {
|
|
1145
|
-
merged =
|
|
1194
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
|
|
1146
1195
|
}
|
|
1147
|
-
merged =
|
|
1148
|
-
merged.hierarchy = models.map((m) => m.parent).filter((
|
|
1196
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
|
|
1197
|
+
merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
|
|
1149
1198
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1150
1199
|
return merged;
|
|
1151
1200
|
}
|
|
@@ -1155,6 +1204,7 @@ var ModelMerger = class {
|
|
|
1155
1204
|
}
|
|
1156
1205
|
const models = [];
|
|
1157
1206
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1207
|
+
parentKey.root = model.key?.root;
|
|
1158
1208
|
const parentModel = await Models.getRaw(parentKey);
|
|
1159
1209
|
if (parentModel) {
|
|
1160
1210
|
models.unshift(parentModel);
|
|
@@ -1164,9 +1214,6 @@ var ModelMerger = class {
|
|
|
1164
1214
|
}
|
|
1165
1215
|
};
|
|
1166
1216
|
|
|
1167
|
-
// src/assets/Models.ts
|
|
1168
|
-
import { Memoize } from "typescript-memoize";
|
|
1169
|
-
|
|
1170
1217
|
// src/assets/source/parser/AssetParsers.ts
|
|
1171
1218
|
var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
1172
1219
|
AssetParser2["MODEL"] = "model";
|
|
@@ -1180,30 +1227,65 @@ var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
|
1180
1227
|
})(AssetParser || {});
|
|
1181
1228
|
|
|
1182
1229
|
// src/assets/Models.ts
|
|
1183
|
-
var
|
|
1230
|
+
var Models = class _Models {
|
|
1184
1231
|
// opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
|
|
1185
1232
|
// the library, and would require an EnvProvider before any entry has had a chance to register
|
|
1186
1233
|
static get PERSISTENT_CACHE() {
|
|
1187
1234
|
return this._persistentCache ??= PersistentCache.open("minerender-models");
|
|
1188
1235
|
}
|
|
1189
1236
|
static async getItemList() {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
"
|
|
1194
|
-
|
|
1195
|
-
"assets",
|
|
1196
|
-
".json",
|
|
1197
|
-
DEFAULT_ROOT
|
|
1198
|
-
), "list" /* LIST */).then((r) => (r == null ? void 0 : r.files) ?? []);
|
|
1237
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1238
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1239
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1240
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1241
|
+
}).then((r) => r?.files ?? []);
|
|
1199
1242
|
}
|
|
1200
1243
|
static async loadAndMerge(key) {
|
|
1201
|
-
const model = await this.getRaw(key);
|
|
1244
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1202
1245
|
if (!model) {
|
|
1203
1246
|
return void 0;
|
|
1204
1247
|
}
|
|
1205
1248
|
return ModelMerger.mergeWithParents(model);
|
|
1206
1249
|
}
|
|
1250
|
+
static async getItemModel(key) {
|
|
1251
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1252
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1253
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1254
|
+
if (!result) return void 0;
|
|
1255
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1256
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1257
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1258
|
+
modelKey.root = key.root;
|
|
1259
|
+
const model2 = await this.getRaw(modelKey);
|
|
1260
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1261
|
+
return model2;
|
|
1262
|
+
});
|
|
1263
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1264
|
+
}
|
|
1265
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1266
|
+
static defaultItemModel(node, key) {
|
|
1267
|
+
if (!node || typeof node.type !== "string") {
|
|
1268
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1269
|
+
}
|
|
1270
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1271
|
+
case "model":
|
|
1272
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1273
|
+
break;
|
|
1274
|
+
case "condition":
|
|
1275
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1276
|
+
case "select": {
|
|
1277
|
+
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;
|
|
1278
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1279
|
+
}
|
|
1280
|
+
case "range_dispatch": {
|
|
1281
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1282
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1283
|
+
}, void 0);
|
|
1284
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1288
|
+
}
|
|
1207
1289
|
static async getRaw(key) {
|
|
1208
1290
|
if (!key.assetType) {
|
|
1209
1291
|
key.assetType = "models";
|
|
@@ -1242,19 +1324,15 @@ var _Models = class _Models {
|
|
|
1242
1324
|
return this.PERSISTENT_CACHE.clear();
|
|
1243
1325
|
}
|
|
1244
1326
|
};
|
|
1245
|
-
__decorateClass([
|
|
1246
|
-
Memoize()
|
|
1247
|
-
], _Models, "getItemList", 1);
|
|
1248
|
-
var Models = _Models;
|
|
1249
1327
|
|
|
1250
1328
|
// src/assets/BlockStates.ts
|
|
1251
|
-
import { Memoize as Memoize2 } from "typescript-memoize";
|
|
1252
1329
|
var BlockStates = class {
|
|
1253
1330
|
static get PERSISTENT_CACHE() {
|
|
1254
1331
|
return this._persistentCache ??= PersistentCache.open("minerender-blockstates");
|
|
1255
1332
|
}
|
|
1333
|
+
// BlockState names are hardcoded
|
|
1256
1334
|
static async getList() {
|
|
1257
|
-
|
|
1335
|
+
const key = new AssetKey(
|
|
1258
1336
|
DEFAULT_NAMESPACE,
|
|
1259
1337
|
"_list",
|
|
1260
1338
|
"blockstates",
|
|
@@ -1262,11 +1340,16 @@ var BlockStates = class {
|
|
|
1262
1340
|
"assets",
|
|
1263
1341
|
".json",
|
|
1264
1342
|
DEFAULT_ROOT
|
|
1265
|
-
)
|
|
1343
|
+
);
|
|
1344
|
+
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1345
|
+
return AssetLoader.get(key, "list" /* LIST */);
|
|
1346
|
+
}).then((r) => r?.files ?? []);
|
|
1266
1347
|
}
|
|
1267
1348
|
static async getDefaultStates() {
|
|
1268
1349
|
const key = AssetKey.parse("blockstates", "minerender:defaultBlockStates");
|
|
1269
|
-
return
|
|
1350
|
+
return Caching.defaultBlockStatesCache.get(key.serialize(), () => {
|
|
1351
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
1352
|
+
});
|
|
1270
1353
|
}
|
|
1271
1354
|
static async getDefaultState(key) {
|
|
1272
1355
|
const defaultStates = await this.getDefaultStates();
|
|
@@ -1305,17 +1388,11 @@ var BlockStates = class {
|
|
|
1305
1388
|
await this.PERSISTENT_CACHE.clear();
|
|
1306
1389
|
}
|
|
1307
1390
|
};
|
|
1308
|
-
__decorateClass([
|
|
1309
|
-
Memoize2()
|
|
1310
|
-
], BlockStates, "getList", 1);
|
|
1311
|
-
__decorateClass([
|
|
1312
|
-
Memoize2()
|
|
1313
|
-
], BlockStates, "getDefaultStates", 1);
|
|
1314
1391
|
var DefaultBlockStates = class {
|
|
1315
1392
|
};
|
|
1316
1393
|
|
|
1317
1394
|
// src/assets/Assets.ts
|
|
1318
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1395
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1319
1396
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1320
1397
|
var Assets = class {
|
|
1321
1398
|
/**
|
|
@@ -1337,29 +1414,242 @@ var AssetSource = class {
|
|
|
1337
1414
|
constructor() {
|
|
1338
1415
|
}
|
|
1339
1416
|
};
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1417
|
+
var AssetLoadError = class extends Error {
|
|
1418
|
+
constructor(source, key, path, cause) {
|
|
1419
|
+
super(`Failed to load ${key.toNamespacedString()} from ${path}${cause instanceof Error ? `: ${cause.message}` : ""}`);
|
|
1420
|
+
this.source = source;
|
|
1421
|
+
this.key = key;
|
|
1422
|
+
this.path = path;
|
|
1423
|
+
this.cause = cause;
|
|
1424
|
+
this.name = "AssetLoadError";
|
|
1347
1425
|
}
|
|
1348
1426
|
};
|
|
1349
1427
|
|
|
1350
|
-
// src/
|
|
1351
|
-
var
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1428
|
+
// src/util/BatchedExecutor.ts
|
|
1429
|
+
var BatchedExecutor = class {
|
|
1430
|
+
constructor(interval = 1, batch = 30) {
|
|
1431
|
+
this.interval = interval;
|
|
1432
|
+
this.batch = batch;
|
|
1433
|
+
this.queue = [];
|
|
1434
|
+
this.task = setInterval(() => this.run());
|
|
1435
|
+
}
|
|
1436
|
+
submit(task) {
|
|
1437
|
+
this.queue.push(task);
|
|
1438
|
+
}
|
|
1439
|
+
run() {
|
|
1440
|
+
for (let i = 0; i < this.batch; i++) {
|
|
1441
|
+
this.runNext();
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
runNext() {
|
|
1445
|
+
let next = this.queue.shift();
|
|
1446
|
+
if (next) next();
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
// src/util/model.ts
|
|
1451
|
+
import { AxesHelper, BoxGeometry as BoxGeometry2, EdgesGeometry, LineBasicMaterial, LineSegments, Vector3 as Vector32 } from "three";
|
|
1452
|
+
function applyElementRotation(rotation, geometry) {
|
|
1453
|
+
const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1454
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1455
|
+
switch (rotation.axis) {
|
|
1456
|
+
case "x" /* X */:
|
|
1457
|
+
geometry.rotateX(toRadians(rotation.angle));
|
|
1458
|
+
break;
|
|
1459
|
+
case "y" /* Y */:
|
|
1460
|
+
geometry.rotateY(toRadians(rotation.angle));
|
|
1461
|
+
break;
|
|
1462
|
+
case "z" /* Z */:
|
|
1463
|
+
geometry.rotateZ(toRadians(rotation.angle));
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
if (rotation.rescale) {
|
|
1467
|
+
if (Math.abs(rotation.angle) === 22.5) {
|
|
1468
|
+
const s = 1 / Math.cos(0.39269909262657166);
|
|
1469
|
+
geometry.scale(s, 1, s);
|
|
1470
|
+
} else {
|
|
1471
|
+
const s = 1 / Math.cos(0.7853981852531433);
|
|
1472
|
+
geometry.scale(s, 1, s);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1476
|
+
}
|
|
1477
|
+
function applyModelPartRotation(modelPart, geometry) {
|
|
1478
|
+
const origin = new Vector32(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1479
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1480
|
+
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1481
|
+
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1482
|
+
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1483
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1484
|
+
}
|
|
1485
|
+
function applyGenericRotation(axis, rotation, obj) {
|
|
1486
|
+
switch (axis) {
|
|
1487
|
+
case "x" /* X */:
|
|
1488
|
+
obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
|
|
1489
|
+
break;
|
|
1490
|
+
case "y" /* Y */:
|
|
1491
|
+
obj.rotateOnAxis(new Vector32(0, 1, 0), toRadians(rotation));
|
|
1492
|
+
break;
|
|
1493
|
+
case "z" /* Z */:
|
|
1494
|
+
obj.rotateOnAxis(new Vector32(0, 0, 1), toRadians(rotation));
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
function addBox3WireframeToObject(box, obj, color = 16777215, w = 2) {
|
|
1499
|
+
let size = new Vector32();
|
|
1500
|
+
box.getSize(size);
|
|
1501
|
+
let boxGeo = new BoxGeometry2(size.x, size.y, size.z, 1, 1, 1);
|
|
1502
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1503
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1504
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1505
|
+
obj.add(wireframe);
|
|
1506
|
+
let axes = new AxesHelper(1);
|
|
1507
|
+
obj.add(axes);
|
|
1508
|
+
}
|
|
1509
|
+
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
1510
|
+
let boxGeo = new BoxGeometry2(16, 16, 16, 1, 1, 1);
|
|
1511
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1512
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1513
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1514
|
+
obj.add(wireframe);
|
|
1515
|
+
let axes = new AxesHelper(1);
|
|
1516
|
+
obj.add(axes);
|
|
1517
|
+
}
|
|
1518
|
+
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
1519
|
+
let wireGeo = new EdgesGeometry(geo);
|
|
1520
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1521
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1522
|
+
mesh.add(wireframe);
|
|
1523
|
+
let axes = new AxesHelper(1);
|
|
1524
|
+
mesh.add(axes);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/util/performance.ts
|
|
1528
|
+
function captureException(e, ...extra) {
|
|
1529
|
+
console.error(e, extra);
|
|
1530
|
+
}
|
|
1531
|
+
function timingStart(marker) {
|
|
1532
|
+
console.time(marker);
|
|
1533
|
+
}
|
|
1534
|
+
function timingEnd(marker) {
|
|
1535
|
+
console.timeEnd(marker);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// src/util/three.ts
|
|
1539
|
+
function isObject3D(obj) {
|
|
1540
|
+
return obj.isObject3D;
|
|
1541
|
+
}
|
|
1542
|
+
function isMesh(obj) {
|
|
1543
|
+
return obj.isMesh;
|
|
1544
|
+
}
|
|
1545
|
+
function isInstancedMesh(obj) {
|
|
1546
|
+
return obj.isInstancedMesh;
|
|
1547
|
+
}
|
|
1548
|
+
function isPerspectiveCamera(obj) {
|
|
1549
|
+
return obj.isPerspectiveCamera;
|
|
1550
|
+
}
|
|
1551
|
+
function isOrthographicCamera(obj) {
|
|
1552
|
+
return obj.isOrthographicCamera;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/nbt/NBTHelper.ts
|
|
1556
|
+
var NBTHelper = class {
|
|
1557
|
+
static async fromBuffer(buffer) {
|
|
1558
|
+
const prismarineNbt = await import("prismarine-nbt");
|
|
1559
|
+
const { parsed, type, metadata } = await prismarineNbt.parse(buffer);
|
|
1560
|
+
return parsed;
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
|
|
1564
|
+
// src/assets/source/HostedAssetSource.ts
|
|
1565
|
+
var import_ts_deepmerge2 = __toESM(require_dist());
|
|
1566
|
+
var p3 = prefix("HostedAssetSource");
|
|
1567
|
+
var DEFAULT_OPTIONS = {
|
|
1568
|
+
retryDefaults: true
|
|
1569
|
+
};
|
|
1570
|
+
var HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
1571
|
+
static {
|
|
1572
|
+
this.MODEL = {
|
|
1573
|
+
config(request) {
|
|
1574
|
+
},
|
|
1575
|
+
parse(response) {
|
|
1576
|
+
return response.data;
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
static {
|
|
1581
|
+
this.BLOCKSTATE = {
|
|
1582
|
+
config(request) {
|
|
1583
|
+
},
|
|
1584
|
+
parse(response) {
|
|
1585
|
+
return response.data;
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
static {
|
|
1590
|
+
this.META = {
|
|
1591
|
+
config(request) {
|
|
1592
|
+
},
|
|
1593
|
+
parse(response) {
|
|
1594
|
+
return response.data;
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
static {
|
|
1599
|
+
this.NBT = {
|
|
1600
|
+
config(request) {
|
|
1601
|
+
request.responseType = "arraybuffer";
|
|
1602
|
+
},
|
|
1603
|
+
parse(response) {
|
|
1604
|
+
return NBTHelper.fromBuffer(Buffer.from(response.data));
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
static {
|
|
1609
|
+
this.IMAGE = {
|
|
1610
|
+
config(request) {
|
|
1611
|
+
request.responseType = "arraybuffer";
|
|
1612
|
+
},
|
|
1613
|
+
async parse(response) {
|
|
1614
|
+
return await ImageLoader.processResponse(response);
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
static {
|
|
1619
|
+
this.LIST = {
|
|
1620
|
+
config(request) {
|
|
1621
|
+
},
|
|
1622
|
+
parse(response) {
|
|
1623
|
+
return response.data;
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
static {
|
|
1628
|
+
this.JSON = {
|
|
1629
|
+
config(request) {
|
|
1630
|
+
},
|
|
1631
|
+
parse(response) {
|
|
1632
|
+
return response.data;
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
static {
|
|
1637
|
+
this.PARSER_MAP = /* @__PURE__ */ new Map([
|
|
1638
|
+
["model" /* MODEL */, _HostedAssetSource.MODEL],
|
|
1639
|
+
["blockstate" /* BLOCKSTATE */, _HostedAssetSource.BLOCKSTATE],
|
|
1640
|
+
["meta" /* META */, _HostedAssetSource.META],
|
|
1641
|
+
["nbt" /* NBT */, _HostedAssetSource.NBT],
|
|
1642
|
+
["image" /* IMAGE */, _HostedAssetSource.IMAGE],
|
|
1643
|
+
["list" /* LIST */, _HostedAssetSource.LIST],
|
|
1644
|
+
["json" /* JSON */, _HostedAssetSource.JSON]
|
|
1645
|
+
]);
|
|
1646
|
+
}
|
|
1647
|
+
async loadOrRetryWithDefaults(key, parser) {
|
|
1648
|
+
const direct = await this.load(key, parser);
|
|
1649
|
+
if (typeof direct !== "undefined") {
|
|
1650
|
+
return direct;
|
|
1651
|
+
}
|
|
1652
|
+
if (key.namespace !== DEFAULT_NAMESPACE) {
|
|
1363
1653
|
console.info(p3, "Retrying", key, "with default namespace");
|
|
1364
1654
|
const namespaceKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, key.root);
|
|
1365
1655
|
const namespaced = await this.load(namespaceKey, parser);
|
|
@@ -1388,31 +1678,25 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1388
1678
|
console.info(p3, "Loading", key);
|
|
1389
1679
|
const url = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1390
1680
|
console.debug(p3, url);
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
} catch (e) {
|
|
1400
|
-
console.warn("Parser failed to process response", response, e);
|
|
1401
|
-
throw e;
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
return void 0;
|
|
1405
|
-
}).catch((err) => {
|
|
1406
|
-
if (err.response) {
|
|
1407
|
-
let response = err.response;
|
|
1408
|
-
if (response.status === 404) {
|
|
1409
|
-
console.debug(p3, key, "not found");
|
|
1681
|
+
const request = { url };
|
|
1682
|
+
try {
|
|
1683
|
+
parser.config(request);
|
|
1684
|
+
let response;
|
|
1685
|
+
try {
|
|
1686
|
+
response = await Requests.mcAssetRequest(request);
|
|
1687
|
+
} catch (cause) {
|
|
1688
|
+
if (cause instanceof RequestError && cause.response?.status === 404) {
|
|
1410
1689
|
return void 0;
|
|
1411
1690
|
}
|
|
1691
|
+
throw cause;
|
|
1412
1692
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1693
|
+
if (response.data === void 0) {
|
|
1694
|
+
throw new Error("Asset response has no data");
|
|
1695
|
+
}
|
|
1696
|
+
return await parser.parse(response);
|
|
1697
|
+
} catch (cause) {
|
|
1698
|
+
throw new AssetLoadError(this, key, request.url, cause);
|
|
1699
|
+
}
|
|
1416
1700
|
}
|
|
1417
1701
|
assetBasePath(key) {
|
|
1418
1702
|
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 + "/" : ""}`;
|
|
@@ -1436,67 +1720,6 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1436
1720
|
return this.load(key, responseParser);
|
|
1437
1721
|
}
|
|
1438
1722
|
};
|
|
1439
|
-
_HostedAssetSource.MODEL = {
|
|
1440
|
-
config(request) {
|
|
1441
|
-
},
|
|
1442
|
-
parse(response) {
|
|
1443
|
-
return response.data;
|
|
1444
|
-
}
|
|
1445
|
-
};
|
|
1446
|
-
_HostedAssetSource.BLOCKSTATE = {
|
|
1447
|
-
config(request) {
|
|
1448
|
-
},
|
|
1449
|
-
parse(response) {
|
|
1450
|
-
return response.data;
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
_HostedAssetSource.META = {
|
|
1454
|
-
config(request) {
|
|
1455
|
-
},
|
|
1456
|
-
parse(response) {
|
|
1457
|
-
return response.data;
|
|
1458
|
-
}
|
|
1459
|
-
};
|
|
1460
|
-
_HostedAssetSource.NBT = {
|
|
1461
|
-
config(request) {
|
|
1462
|
-
request.responseType = "arraybuffer";
|
|
1463
|
-
},
|
|
1464
|
-
parse(response) {
|
|
1465
|
-
return NBTHelper.fromBuffer(Buffer.from(response.data));
|
|
1466
|
-
}
|
|
1467
|
-
};
|
|
1468
|
-
_HostedAssetSource.IMAGE = {
|
|
1469
|
-
config(request) {
|
|
1470
|
-
request.responseType = "arraybuffer";
|
|
1471
|
-
},
|
|
1472
|
-
async parse(response) {
|
|
1473
|
-
return await ImageLoader.processResponse(response);
|
|
1474
|
-
}
|
|
1475
|
-
};
|
|
1476
|
-
_HostedAssetSource.LIST = {
|
|
1477
|
-
config(request) {
|
|
1478
|
-
},
|
|
1479
|
-
parse(response) {
|
|
1480
|
-
return response.data;
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1483
|
-
_HostedAssetSource.JSON = {
|
|
1484
|
-
config(request) {
|
|
1485
|
-
},
|
|
1486
|
-
parse(response) {
|
|
1487
|
-
return response.data;
|
|
1488
|
-
}
|
|
1489
|
-
};
|
|
1490
|
-
_HostedAssetSource.PARSER_MAP = /* @__PURE__ */ new Map([
|
|
1491
|
-
["model" /* MODEL */, _HostedAssetSource.MODEL],
|
|
1492
|
-
["blockstate" /* BLOCKSTATE */, _HostedAssetSource.BLOCKSTATE],
|
|
1493
|
-
["meta" /* META */, _HostedAssetSource.META],
|
|
1494
|
-
["nbt" /* NBT */, _HostedAssetSource.NBT],
|
|
1495
|
-
["image" /* IMAGE */, _HostedAssetSource.IMAGE],
|
|
1496
|
-
["list" /* LIST */, _HostedAssetSource.LIST],
|
|
1497
|
-
["json" /* JSON */, _HostedAssetSource.JSON]
|
|
1498
|
-
]);
|
|
1499
|
-
var HostedAssetSource = _HostedAssetSource;
|
|
1500
1723
|
|
|
1501
1724
|
// src/assets/source/archive/BrowserArchiveProxy.ts
|
|
1502
1725
|
import { BlobReader, BlobWriter, ZipReader } from "@zip.js/zip.js";
|
|
@@ -1519,7 +1742,6 @@ var BrowserArchiveProxy = class {
|
|
|
1519
1742
|
};
|
|
1520
1743
|
|
|
1521
1744
|
// src/assets/source/archive/ArchiveAssetSource.ts
|
|
1522
|
-
var p4 = prefix("ArchiveAssetSource");
|
|
1523
1745
|
var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
1524
1746
|
constructor(archiveProxy) {
|
|
1525
1747
|
super();
|
|
@@ -1538,74 +1760,31 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1538
1760
|
}
|
|
1539
1761
|
async get(key, parser) {
|
|
1540
1762
|
const responseParser = HostedAssetSource.PARSER_MAP.get(parser);
|
|
1541
|
-
|
|
1542
|
-
let entries = await this.getEntries();
|
|
1543
|
-
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1544
|
-
console.log(path);
|
|
1545
|
-
const entry = await this.getEntry(path);
|
|
1546
|
-
console.log(entry);
|
|
1547
|
-
if (!entry) {
|
|
1548
|
-
return void 0;
|
|
1549
|
-
}
|
|
1550
|
-
let blob = await entry.getData();
|
|
1551
|
-
const url = URL.createObjectURL(blob);
|
|
1552
|
-
console.log(url);
|
|
1553
|
-
let req = {
|
|
1554
|
-
url
|
|
1555
|
-
};
|
|
1556
|
-
responseParser.config(req);
|
|
1557
|
-
return Requests.genericRequest(req).then((response) => {
|
|
1558
|
-
if (response && response.data) {
|
|
1559
|
-
try {
|
|
1560
|
-
return responseParser.parse(response);
|
|
1561
|
-
} catch (e) {
|
|
1562
|
-
console.warn("Parser failed to process response", response, e);
|
|
1563
|
-
throw e;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
return void 0;
|
|
1567
|
-
}).catch((err) => {
|
|
1568
|
-
if (err.response) {
|
|
1569
|
-
let response = err.response;
|
|
1570
|
-
if (response.status === 404) {
|
|
1571
|
-
console.debug(p4, key, "not found");
|
|
1572
|
-
return void 0;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
console.debug(p4, "Failed to load", key, err == null ? void 0 : err.message);
|
|
1576
|
-
return void 0;
|
|
1577
|
-
});
|
|
1763
|
+
return this.load(key, responseParser);
|
|
1578
1764
|
}
|
|
1579
|
-
//TODO: abstract this
|
|
1580
1765
|
async load(key, parser) {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
parser.config(req);
|
|
1588
|
-
return await Requests.genericRequest(req).then((response) => {
|
|
1589
|
-
if (response && response.data) {
|
|
1590
|
-
try {
|
|
1591
|
-
return parser.parse(response);
|
|
1592
|
-
} catch (e) {
|
|
1593
|
-
console.warn("Parser failed to process response", response, e);
|
|
1594
|
-
throw e;
|
|
1595
|
-
}
|
|
1766
|
+
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1767
|
+
let url;
|
|
1768
|
+
try {
|
|
1769
|
+
const entry = await this.getEntry(path);
|
|
1770
|
+
if (!entry) {
|
|
1771
|
+
return void 0;
|
|
1596
1772
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
return void 0;
|
|
1604
|
-
}
|
|
1773
|
+
url = URL.createObjectURL(await entry.getData());
|
|
1774
|
+
const request = { url };
|
|
1775
|
+
parser.config(request);
|
|
1776
|
+
const response = await Requests.genericRequest(request);
|
|
1777
|
+
if (response.data === void 0) {
|
|
1778
|
+
throw new Error("Asset response has no data");
|
|
1605
1779
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1780
|
+
return await parser.parse(response);
|
|
1781
|
+
} catch (cause) {
|
|
1782
|
+
throw new AssetLoadError(this, key, path, cause);
|
|
1783
|
+
} finally {
|
|
1784
|
+
if (url !== void 0) {
|
|
1785
|
+
URL.revokeObjectURL(url);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1609
1788
|
}
|
|
1610
1789
|
assetBasePath(key) {
|
|
1611
1790
|
return `${key.rootType !== void 0 ? key.rootType + "/" : ""}${key.namespace !== void 0 ? key.namespace + "/" : ""}${key.assetType !== void 0 ? key.assetType + "/" : ""}`;
|
|
@@ -1613,18 +1792,23 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1613
1792
|
};
|
|
1614
1793
|
|
|
1615
1794
|
// src/assets/AssetLoader.ts
|
|
1616
|
-
var
|
|
1617
|
-
var
|
|
1618
|
-
|
|
1795
|
+
var p4 = prefix("AssetLoader");
|
|
1796
|
+
var AssetLoader = class {
|
|
1797
|
+
static {
|
|
1798
|
+
this.ROOT = DEFAULT_ROOT;
|
|
1799
|
+
}
|
|
1800
|
+
static {
|
|
1801
|
+
this._SOURCES = [];
|
|
1802
|
+
}
|
|
1619
1803
|
static addSource(key, source, override = true) {
|
|
1620
1804
|
if (override) {
|
|
1621
1805
|
const existing = this.removeSource(key);
|
|
1622
1806
|
if (existing) {
|
|
1623
|
-
console.log(
|
|
1807
|
+
console.log(p4, "Removed existing AssetSource", key);
|
|
1624
1808
|
}
|
|
1625
1809
|
}
|
|
1626
1810
|
this._SOURCES.unshift({ key, source });
|
|
1627
|
-
console.log(
|
|
1811
|
+
console.log(p4, "Added AssetSource", key);
|
|
1628
1812
|
}
|
|
1629
1813
|
static removeSource(key) {
|
|
1630
1814
|
const index = this._SOURCES.findIndex((s) => s.key === key);
|
|
@@ -1636,8 +1820,11 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1636
1820
|
}
|
|
1637
1821
|
return void 0;
|
|
1638
1822
|
}
|
|
1823
|
+
static {
|
|
1824
|
+
this.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
|
|
1825
|
+
this.addSource("mcassets", new HostedAssetSource(DEFAULT_ROOT, { retryDefaults: false }));
|
|
1826
|
+
}
|
|
1639
1827
|
static async getAll(key, parser) {
|
|
1640
|
-
console.log(this._SOURCES);
|
|
1641
1828
|
let promises = [];
|
|
1642
1829
|
for (const source of this._SOURCES) {
|
|
1643
1830
|
promises.push(source.source.get(key, parser));
|
|
@@ -1646,31 +1833,36 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1646
1833
|
return results.filter((r) => r != void 0);
|
|
1647
1834
|
});
|
|
1648
1835
|
}
|
|
1836
|
+
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1649
1837
|
static async get(key, parser) {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1838
|
+
const keys = [key];
|
|
1839
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1840
|
+
keys.push(new AssetKey(
|
|
1841
|
+
key.namespace,
|
|
1842
|
+
key.path,
|
|
1843
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1844
|
+
key.type,
|
|
1845
|
+
key.rootType,
|
|
1846
|
+
key.extension,
|
|
1847
|
+
key.root
|
|
1848
|
+
));
|
|
1849
|
+
}
|
|
1850
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1851
|
+
}
|
|
1852
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1853
|
+
static async getFirst(keys, parser) {
|
|
1854
|
+
const sources = [...this._SOURCES];
|
|
1855
|
+
for (const source of sources) {
|
|
1856
|
+
for (const key of keys) {
|
|
1857
|
+
const result = await source.source.get(key, parser);
|
|
1858
|
+
if (result !== void 0) {
|
|
1859
|
+
return { key, asset: result };
|
|
1663
1860
|
}
|
|
1664
1861
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1862
|
+
}
|
|
1863
|
+
return void 0;
|
|
1667
1864
|
}
|
|
1668
1865
|
};
|
|
1669
|
-
_AssetLoader.ROOT = DEFAULT_ROOT;
|
|
1670
|
-
_AssetLoader._SOURCES = [];
|
|
1671
|
-
_AssetLoader.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
|
|
1672
|
-
_AssetLoader.addSource("mcassets", new HostedAssetSource(DEFAULT_ROOT, { retryDefaults: false }));
|
|
1673
|
-
var AssetLoader = _AssetLoader;
|
|
1674
1866
|
|
|
1675
1867
|
// src/assets/ModelTextures.ts
|
|
1676
1868
|
var ModelTextures = class {
|
|
@@ -1678,11 +1870,21 @@ var ModelTextures = class {
|
|
|
1678
1870
|
return this._persistentMetaCache ??= PersistentCache.open("minerender-texturemeta");
|
|
1679
1871
|
}
|
|
1680
1872
|
static async get(key) {
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1873
|
+
const keyStr = key.serialize();
|
|
1874
|
+
const pending = this.preload(key);
|
|
1875
|
+
const cached = Caching.textureAssetCache.getIfPresent(keyStr);
|
|
1876
|
+
try {
|
|
1877
|
+
const asset = await pending;
|
|
1878
|
+
if (asset) {
|
|
1879
|
+
return await ImageLoader.infoToCanvasData(asset);
|
|
1880
|
+
}
|
|
1881
|
+
return void 0;
|
|
1882
|
+
} catch (err) {
|
|
1883
|
+
if (cached && Caching.textureAssetCache.getIfPresent(keyStr) === cached) {
|
|
1884
|
+
Caching.textureAssetCache.invalidate(keyStr);
|
|
1885
|
+
}
|
|
1886
|
+
throw err;
|
|
1887
|
+
}
|
|
1686
1888
|
}
|
|
1687
1889
|
static async preload(key) {
|
|
1688
1890
|
const keyStr = key.serialize();
|
|
@@ -1756,7 +1958,28 @@ var CanvasImage = class {
|
|
|
1756
1958
|
};
|
|
1757
1959
|
|
|
1758
1960
|
// src/Ticker.ts
|
|
1759
|
-
var
|
|
1961
|
+
var Ticker = class _Ticker {
|
|
1962
|
+
static {
|
|
1963
|
+
this.TPS = 20;
|
|
1964
|
+
}
|
|
1965
|
+
static {
|
|
1966
|
+
this.counter = 0;
|
|
1967
|
+
}
|
|
1968
|
+
static {
|
|
1969
|
+
this._tickers = /* @__PURE__ */ new Map();
|
|
1970
|
+
}
|
|
1971
|
+
static {
|
|
1972
|
+
this.oneSecondTps = 0;
|
|
1973
|
+
}
|
|
1974
|
+
static {
|
|
1975
|
+
this.oneSecondTicks = 0;
|
|
1976
|
+
}
|
|
1977
|
+
static {
|
|
1978
|
+
this.fiveSecondTps = 0;
|
|
1979
|
+
}
|
|
1980
|
+
static {
|
|
1981
|
+
this.fiveSecondTicks = 0;
|
|
1982
|
+
}
|
|
1760
1983
|
static schedule(fn, ms) {
|
|
1761
1984
|
const handle = setInterval(fn, ms);
|
|
1762
1985
|
const unref = handle.unref;
|
|
@@ -1818,14 +2041,6 @@ var _Ticker = class _Ticker {
|
|
|
1818
2041
|
this._tickers.clear();
|
|
1819
2042
|
}
|
|
1820
2043
|
};
|
|
1821
|
-
_Ticker.TPS = 20;
|
|
1822
|
-
_Ticker.counter = 0;
|
|
1823
|
-
_Ticker._tickers = /* @__PURE__ */ new Map();
|
|
1824
|
-
_Ticker.oneSecondTps = 0;
|
|
1825
|
-
_Ticker.oneSecondTicks = 0;
|
|
1826
|
-
_Ticker.fiveSecondTps = 0;
|
|
1827
|
-
_Ticker.fiveSecondTicks = 0;
|
|
1828
|
-
var Ticker = _Ticker;
|
|
1829
2044
|
|
|
1830
2045
|
// src/texture/TextureAtlas.ts
|
|
1831
2046
|
var TextureAtlas = class {
|
|
@@ -1851,18 +2066,24 @@ var TextureAtlas = class {
|
|
|
1851
2066
|
|
|
1852
2067
|
// src/model/ModelGenerator.ts
|
|
1853
2068
|
var ModelGenerator = class {
|
|
2069
|
+
static {
|
|
2070
|
+
this.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
2071
|
+
}
|
|
1854
2072
|
static generateItemModel(imageData, layer) {
|
|
2073
|
+
const tintindex = this.ITEM_LAYERS.indexOf(layer);
|
|
1855
2074
|
const mainElement = {
|
|
1856
2075
|
from: [0, 0, 7.5],
|
|
1857
2076
|
to: [16, 16, 8.5],
|
|
1858
2077
|
faces: {
|
|
1859
2078
|
"south": {
|
|
1860
2079
|
uv: [0, 0, 16, 16],
|
|
1861
|
-
texture: `#${layer}
|
|
2080
|
+
texture: `#${layer}`,
|
|
2081
|
+
tintindex
|
|
1862
2082
|
},
|
|
1863
2083
|
"north": {
|
|
1864
2084
|
uv: [16, 0, 0, 16],
|
|
1865
|
-
texture: `#${layer}
|
|
2085
|
+
texture: `#${layer}`,
|
|
2086
|
+
tintindex
|
|
1866
2087
|
}
|
|
1867
2088
|
},
|
|
1868
2089
|
shade: true
|
|
@@ -1870,14 +2091,21 @@ var ModelGenerator = class {
|
|
|
1870
2091
|
return [mainElement];
|
|
1871
2092
|
}
|
|
1872
2093
|
};
|
|
1873
|
-
ModelGenerator.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
1874
2094
|
|
|
1875
2095
|
// src/UVMapper.ts
|
|
1876
|
-
var
|
|
2096
|
+
var p5 = prefix("UVMapper");
|
|
1877
2097
|
var DEFAULT_UV = [0, 0, 16, 16];
|
|
1878
2098
|
var X = 0;
|
|
1879
2099
|
var Y = 1;
|
|
1880
2100
|
var Z = 2;
|
|
2101
|
+
var FACE_UV_AXES = {
|
|
2102
|
+
east: [new Vector33(0, 0, -1), new Vector33(0, -1, 0)],
|
|
2103
|
+
west: [new Vector33(0, 0, 1), new Vector33(0, -1, 0)],
|
|
2104
|
+
up: [new Vector33(1, 0, 0), new Vector33(0, 0, 1)],
|
|
2105
|
+
down: [new Vector33(1, 0, 0), new Vector33(0, 0, -1)],
|
|
2106
|
+
south: [new Vector33(1, 0, 0), new Vector33(0, -1, 0)],
|
|
2107
|
+
north: [new Vector33(-1, 0, 0), new Vector33(0, -1, 0)]
|
|
2108
|
+
};
|
|
1881
2109
|
var UVMapper = class {
|
|
1882
2110
|
static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
|
|
1883
2111
|
if (uvCoord === 0) return 0;
|
|
@@ -1975,6 +2203,42 @@ var UVMapper = class {
|
|
|
1975
2203
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
1976
2204
|
return new Float32BufferAttribute2(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
1977
2205
|
}
|
|
2206
|
+
static lockUvs(geometry, faces, atlas, rotation) {
|
|
2207
|
+
const uv = geometry.getAttribute("uv");
|
|
2208
|
+
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
2209
|
+
const faceName = CUBE_FACES[faceIndex];
|
|
2210
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
2211
|
+
const position = texture && atlas.positions[texture];
|
|
2212
|
+
const size = texture && atlas.sizes[texture];
|
|
2213
|
+
if (!position || !size) continue;
|
|
2214
|
+
const [sourceU, sourceV] = FACE_UV_AXES[faceName];
|
|
2215
|
+
const uAxis = sourceU.clone().applyEuler(rotation);
|
|
2216
|
+
const vAxis = sourceV.clone().applyEuler(rotation);
|
|
2217
|
+
const normal = vAxis.clone().cross(uAxis);
|
|
2218
|
+
const targetFace = CUBE_FACES.find((name) => {
|
|
2219
|
+
const [u, v] = FACE_UV_AXES[name];
|
|
2220
|
+
return v.clone().cross(u).dot(normal) > 0.5;
|
|
2221
|
+
});
|
|
2222
|
+
const [targetU, targetV] = FACE_UV_AXES[targetFace];
|
|
2223
|
+
const uu = Math.round(targetU.dot(uAxis));
|
|
2224
|
+
const uvCross = Math.round(targetU.dot(vAxis));
|
|
2225
|
+
const vu = Math.round(targetV.dot(uAxis));
|
|
2226
|
+
const vv = Math.round(targetV.dot(vAxis));
|
|
2227
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
2228
|
+
const index = faceIndex * 4 + corner;
|
|
2229
|
+
const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
|
|
2230
|
+
const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
|
|
2231
|
+
const lockedU = uu * u + uvCross * v + 0.5;
|
|
2232
|
+
const lockedV = vu * u + vv * v + 0.5;
|
|
2233
|
+
uv.setXY(
|
|
2234
|
+
index,
|
|
2235
|
+
(position[0] + lockedU * size[0]) / atlas.image.width,
|
|
2236
|
+
1 - (position[1] + lockedV * size[1]) / atlas.image.height
|
|
2237
|
+
);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
uv.needsUpdate = true;
|
|
2241
|
+
}
|
|
1978
2242
|
static async getAtlas(model) {
|
|
1979
2243
|
const keyStr = model.key.serialize();
|
|
1980
2244
|
return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
|
|
@@ -2046,12 +2310,11 @@ var UVMapper = class {
|
|
|
2046
2310
|
return [tl, tr, bl, br];
|
|
2047
2311
|
}
|
|
2048
2312
|
static async createAtlas(originalModel) {
|
|
2049
|
-
var _a;
|
|
2050
2313
|
const textureMap = {};
|
|
2051
2314
|
const metaMap = {};
|
|
2052
2315
|
const model = { ...originalModel };
|
|
2053
2316
|
const isItemModel = !("elements" in model);
|
|
2054
|
-
console.debug(
|
|
2317
|
+
console.debug(p5, "Creating Atlas for", model.key);
|
|
2055
2318
|
if (model.textures) {
|
|
2056
2319
|
const promises = [];
|
|
2057
2320
|
const uniqueTextureNames = [];
|
|
@@ -2065,7 +2328,7 @@ var UVMapper = class {
|
|
|
2065
2328
|
const assetKey = AssetKey.parse("textures", textureValue, model.key);
|
|
2066
2329
|
promises.push(ModelTextures.get(assetKey).then((asset) => {
|
|
2067
2330
|
if (!asset) {
|
|
2068
|
-
console.warn(
|
|
2331
|
+
console.warn(p5, "Missing texture", assetKey);
|
|
2069
2332
|
return;
|
|
2070
2333
|
}
|
|
2071
2334
|
textureMap[textureKey] = new WrappedImage(asset);
|
|
@@ -2077,7 +2340,7 @@ var UVMapper = class {
|
|
|
2077
2340
|
}
|
|
2078
2341
|
await Promise.all(promises);
|
|
2079
2342
|
const textureCount = uniqueTextureNames.length;
|
|
2080
|
-
console.debug(
|
|
2343
|
+
console.debug(p5, "Creating Atlas for", textureCount, "textures");
|
|
2081
2344
|
this.fillMissingTextureKeys(model.textures, textureMap);
|
|
2082
2345
|
this.fillMissingTextureKeys(model.textures, metaMap);
|
|
2083
2346
|
const sizes = {};
|
|
@@ -2097,7 +2360,7 @@ var UVMapper = class {
|
|
|
2097
2360
|
this.fillMissingTextureKeys(model.textures, sizes);
|
|
2098
2361
|
const s = Math.ceil(Math.sqrt(textureCount + 1));
|
|
2099
2362
|
const size = Math.ceil(s * maxWidth);
|
|
2100
|
-
console.debug(
|
|
2363
|
+
console.debug(p5, "Atlas size:", size);
|
|
2101
2364
|
const squaredSize = size * size;
|
|
2102
2365
|
const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
|
|
2103
2366
|
const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
|
|
@@ -2126,16 +2389,15 @@ var UVMapper = class {
|
|
|
2126
2389
|
if (texture.animated) {
|
|
2127
2390
|
hasAnimation = true;
|
|
2128
2391
|
const meta = metaMap[textureKey];
|
|
2129
|
-
const frameTime =
|
|
2392
|
+
const frameTime = meta?.animation?.frametime ?? 1;
|
|
2130
2393
|
console.log(meta);
|
|
2131
2394
|
console.log(frameTime);
|
|
2132
2395
|
let t = 0;
|
|
2133
2396
|
let f = 0;
|
|
2134
2397
|
animatorFunctions[textureKey] = () => {
|
|
2135
|
-
var _a2;
|
|
2136
2398
|
if (t++ >= frameTime) {
|
|
2137
2399
|
t = 0;
|
|
2138
|
-
const frames =
|
|
2400
|
+
const frames = meta?.animation?.frames;
|
|
2139
2401
|
const frame = frames ? frames[f] : f;
|
|
2140
2402
|
image.putData(texture.getFrameSectionData(frame), x, y, 0, 0, maxWidth, maxWidth);
|
|
2141
2403
|
f++;
|
|
@@ -2153,10 +2415,10 @@ var UVMapper = class {
|
|
|
2153
2415
|
}
|
|
2154
2416
|
}
|
|
2155
2417
|
const atlasImageData = image.toDataURL();
|
|
2156
|
-
console.log(
|
|
2418
|
+
console.log(p5, "Atlas Image for", model.key, atlasImageData);
|
|
2157
2419
|
this.fillMissingTextureKeys(model.textures, positions);
|
|
2158
2420
|
if (isItemModel) {
|
|
2159
|
-
console.debug(
|
|
2421
|
+
console.debug(p5, "Generating item model for", model);
|
|
2160
2422
|
model.elements = [];
|
|
2161
2423
|
for (let layerName of ModelGenerator.ITEM_LAYERS) {
|
|
2162
2424
|
const textureImage = textureMap[layerName];
|
|
@@ -2164,7 +2426,7 @@ var UVMapper = class {
|
|
|
2164
2426
|
model.elements.push(...ModelGenerator.generateItemModel(textureImage.data, layerName));
|
|
2165
2427
|
}
|
|
2166
2428
|
}
|
|
2167
|
-
console.debug(
|
|
2429
|
+
console.debug(p5, "Item model elements", model.elements);
|
|
2168
2430
|
}
|
|
2169
2431
|
if (!model.elements) {
|
|
2170
2432
|
}
|
|
@@ -2182,17 +2444,13 @@ var UVMapper = class {
|
|
|
2182
2444
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2183
2445
|
continue;
|
|
2184
2446
|
}
|
|
2447
|
+
if (!face.texture) continue;
|
|
2185
2448
|
if (!face.uv) {
|
|
2186
2449
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2187
2450
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
if (faceTexture) {
|
|
2192
|
-
faceTexture = faceTexture.substr(1);
|
|
2193
|
-
texPosition = positions[faceTexture] || [0, 0];
|
|
2194
|
-
texSize = sizes[faceTexture] || [16, 16];
|
|
2195
|
-
}
|
|
2451
|
+
const faceTexture = face.texture.substr(1);
|
|
2452
|
+
const texPosition = positions[faceTexture] || [0, 0];
|
|
2453
|
+
const texSize = sizes[faceTexture] || [16, 16];
|
|
2196
2454
|
let texPosV = new Vector2(texPosition[0], texPosition[1]);
|
|
2197
2455
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2198
2456
|
tl.add(texPosV);
|
|
@@ -2224,7 +2482,7 @@ var UVMapper = class {
|
|
|
2224
2482
|
hasTransparency
|
|
2225
2483
|
);
|
|
2226
2484
|
} else {
|
|
2227
|
-
console.warn(
|
|
2485
|
+
console.warn(p5, "Model does not have any textures", model);
|
|
2228
2486
|
}
|
|
2229
2487
|
return void 0;
|
|
2230
2488
|
}
|
|
@@ -2362,17 +2620,20 @@ function shutdown() {
|
|
|
2362
2620
|
}
|
|
2363
2621
|
|
|
2364
2622
|
// src/assets/Entities.ts
|
|
2365
|
-
import { Memoize as Memoize3 } from "typescript-memoize";
|
|
2366
2623
|
var Entities = class {
|
|
2367
2624
|
static async getBlockEntityModels() {
|
|
2368
2625
|
const key = AssetKey.parse("models", "minerender:blockEntityModels");
|
|
2369
2626
|
console.log(key);
|
|
2370
|
-
return
|
|
2627
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2628
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2629
|
+
});
|
|
2371
2630
|
}
|
|
2372
2631
|
static async getEntityModels() {
|
|
2373
2632
|
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2374
2633
|
console.log(key);
|
|
2375
|
-
return
|
|
2634
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2635
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2636
|
+
});
|
|
2376
2637
|
}
|
|
2377
2638
|
// BlockEntity names are hardcoded
|
|
2378
2639
|
static async getBlockList() {
|
|
@@ -2418,19 +2679,13 @@ var Entities = class {
|
|
|
2418
2679
|
};
|
|
2419
2680
|
}
|
|
2420
2681
|
};
|
|
2421
|
-
__decorateClass([
|
|
2422
|
-
Memoize3()
|
|
2423
|
-
], Entities, "getBlockEntityModels", 1);
|
|
2424
|
-
__decorateClass([
|
|
2425
|
-
Memoize3()
|
|
2426
|
-
], Entities, "getEntityModels", 1);
|
|
2427
2682
|
var EntityModels = class {
|
|
2428
2683
|
};
|
|
2429
2684
|
var BlockEntityModels = class {
|
|
2430
2685
|
};
|
|
2431
2686
|
|
|
2432
2687
|
// src/renderer/SceneObject.ts
|
|
2433
|
-
import { Euler, InstancedMesh, MathUtils, Matrix4 as Matrix42, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion2, Vector3 as
|
|
2688
|
+
import { Euler as Euler2, InstancedMesh, MathUtils, Matrix4 as Matrix42, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion2, Vector3 as Vector34 } from "three";
|
|
2434
2689
|
|
|
2435
2690
|
// src/instance/InstanceReference.ts
|
|
2436
2691
|
var InstanceReference = class {
|
|
@@ -2487,18 +2742,26 @@ var MineRenderError = class _MineRenderError extends Error {
|
|
|
2487
2742
|
};
|
|
2488
2743
|
|
|
2489
2744
|
// src/renderer/SceneObject.ts
|
|
2490
|
-
var
|
|
2491
|
-
var
|
|
2492
|
-
var
|
|
2745
|
+
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2746
|
+
var p6 = prefix("SceneObject");
|
|
2747
|
+
var SceneObject = class _SceneObject extends Object3D2 {
|
|
2493
2748
|
constructor(options) {
|
|
2494
2749
|
super();
|
|
2495
2750
|
this.isSceneObject = true;
|
|
2496
2751
|
this.materialCallbacks = {};
|
|
2497
2752
|
this._isInstanced = false;
|
|
2498
2753
|
this._instanceCounter = 0;
|
|
2499
|
-
this.options = (0,
|
|
2754
|
+
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2500
2755
|
console.log("SceneObject options", this.options);
|
|
2501
2756
|
}
|
|
2757
|
+
static {
|
|
2758
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge3.default)({}, {
|
|
2759
|
+
instanceMeshes: true,
|
|
2760
|
+
maxInstanceCount: 50,
|
|
2761
|
+
mergeMeshes: true,
|
|
2762
|
+
wireframe: false
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2502
2765
|
set scene(scene) {
|
|
2503
2766
|
if (!!this._scene) throw new MineRenderError("Scene already set");
|
|
2504
2767
|
this._scene = scene;
|
|
@@ -2590,6 +2853,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2590
2853
|
}
|
|
2591
2854
|
createInstancedMesh(name, geometry, material, count) {
|
|
2592
2855
|
const mesh = new InstancedMesh(geometry, material, count);
|
|
2856
|
+
mesh.count = 0;
|
|
2593
2857
|
if (name) {
|
|
2594
2858
|
mesh.name = `mesh:${name}`;
|
|
2595
2859
|
}
|
|
@@ -2667,9 +2931,13 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2667
2931
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2668
2932
|
const i = this._instanceCounter++;
|
|
2669
2933
|
this.setMatrixAt(i, new Matrix42());
|
|
2670
|
-
|
|
2934
|
+
const mesh = this.children[0];
|
|
2935
|
+
if (mesh && isInstancedMesh(mesh)) {
|
|
2936
|
+
mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
|
|
2937
|
+
}
|
|
2938
|
+
console.debug(p6, "nextInstance " + i);
|
|
2671
2939
|
if (i === this.options.maxInstanceCount) {
|
|
2672
|
-
console.warn(
|
|
2940
|
+
console.warn(p6, "Max instance count reached for " + this);
|
|
2673
2941
|
}
|
|
2674
2942
|
if (this.scene) {
|
|
2675
2943
|
this.scene.stats.instanceCount++;
|
|
@@ -2698,9 +2966,9 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2698
2966
|
}
|
|
2699
2967
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
2700
2968
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2701
|
-
const oldPosition = new
|
|
2969
|
+
const oldPosition = new Vector34();
|
|
2702
2970
|
const oldRotation = new Quaternion2();
|
|
2703
|
-
const oldScale = new
|
|
2971
|
+
const oldScale = new Vector34();
|
|
2704
2972
|
const matrix = new Matrix42();
|
|
2705
2973
|
if (!scale || !rotation || !position) {
|
|
2706
2974
|
this.getMatrixAt(index, matrix).decompose(oldPosition, oldRotation, oldScale);
|
|
@@ -2716,7 +2984,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2716
2984
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2717
2985
|
this.setPositionRotationScaleAt(index, position);
|
|
2718
2986
|
}
|
|
2719
|
-
getPositionAt(index, vector = new
|
|
2987
|
+
getPositionAt(index, vector = new Vector34()) {
|
|
2720
2988
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2721
2989
|
const matrix = this.getMatrixAt(index);
|
|
2722
2990
|
vector.setFromMatrixPosition(matrix);
|
|
@@ -2726,7 +2994,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2726
2994
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2727
2995
|
this.setPositionRotationScaleAt(index, void 0, rotation, void 0);
|
|
2728
2996
|
}
|
|
2729
|
-
getRotationAt(index, euler = new
|
|
2997
|
+
getRotationAt(index, euler = new Euler2()) {
|
|
2730
2998
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2731
2999
|
const matrix = this.getMatrixAt(index);
|
|
2732
3000
|
euler.setFromRotationMatrix(matrix);
|
|
@@ -2736,7 +3004,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2736
3004
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2737
3005
|
this.setPositionRotationScaleAt(index, void 0, void 0, scale);
|
|
2738
3006
|
}
|
|
2739
|
-
getScaleAt(index, vector = new
|
|
3007
|
+
getScaleAt(index, vector = new Vector34()) {
|
|
2740
3008
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2741
3009
|
const matrix = this.getMatrixAt(index);
|
|
2742
3010
|
vector.setFromMatrixScale(matrix);
|
|
@@ -2840,34 +3108,29 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2840
3108
|
this.notifyDirty();
|
|
2841
3109
|
}
|
|
2842
3110
|
removeFromScene() {
|
|
2843
|
-
|
|
2844
|
-
(_a = this._scene) == null ? void 0 : _a.remove(this);
|
|
3111
|
+
this._scene?.remove(this);
|
|
2845
3112
|
this.notifyDirty();
|
|
2846
3113
|
}
|
|
2847
3114
|
//</editor-fold>
|
|
2848
3115
|
};
|
|
2849
|
-
_SceneObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, {
|
|
2850
|
-
instanceMeshes: true,
|
|
2851
|
-
maxInstanceCount: 50,
|
|
2852
|
-
mergeMeshes: true,
|
|
2853
|
-
wireframe: false
|
|
2854
|
-
});
|
|
2855
|
-
var SceneObject = _SceneObject;
|
|
2856
3116
|
function isSceneObject(obj) {
|
|
2857
3117
|
return obj.isSceneObject;
|
|
2858
3118
|
}
|
|
2859
3119
|
|
|
2860
3120
|
// src/entity/scene/EntityObject.ts
|
|
2861
|
-
var
|
|
3121
|
+
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
2862
3122
|
import { Object3D as Object3D3 } from "three";
|
|
2863
|
-
import * as
|
|
3123
|
+
import * as THREE3 from "three";
|
|
2864
3124
|
var EntityObject = class extends SceneObject {
|
|
2865
3125
|
constructor(entity, options) {
|
|
2866
3126
|
super();
|
|
2867
3127
|
this.entity = entity;
|
|
2868
3128
|
this.isEntityObject = true;
|
|
2869
3129
|
this.meshesCreated = false;
|
|
2870
|
-
this.options = (0,
|
|
3130
|
+
this.options = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
3131
|
+
}
|
|
3132
|
+
static {
|
|
3133
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
2871
3134
|
}
|
|
2872
3135
|
async init() {
|
|
2873
3136
|
this.createMeshes();
|
|
@@ -2876,17 +3139,19 @@ var EntityObject = class extends SceneObject {
|
|
|
2876
3139
|
dispose() {
|
|
2877
3140
|
super.dispose();
|
|
2878
3141
|
}
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
((_a = this.entity.key) == null ? void 0 : _a.namespace) ?? DEFAULT_NAMESPACE,
|
|
3142
|
+
get textureKey() {
|
|
3143
|
+
return new AssetKey(
|
|
3144
|
+
this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
|
|
2883
3145
|
this.entity.key.path,
|
|
2884
3146
|
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
2885
3147
|
"textures",
|
|
2886
3148
|
"entity",
|
|
2887
3149
|
"assets",
|
|
2888
3150
|
".png"
|
|
2889
|
-
)
|
|
3151
|
+
);
|
|
3152
|
+
}
|
|
3153
|
+
async loadTextures() {
|
|
3154
|
+
this.imageData = await ModelTextures.get(this.textureKey);
|
|
2890
3155
|
}
|
|
2891
3156
|
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
2892
3157
|
createMeshes(force = false) {
|
|
@@ -2905,8 +3170,8 @@ var EntityObject = class extends SceneObject {
|
|
|
2905
3170
|
const l = cube.maxZ - cube.minZ;
|
|
2906
3171
|
const uv = texture.toUvArray(w, h, l);
|
|
2907
3172
|
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
2908
|
-
cubeGeo.applyMatrix4(new
|
|
2909
|
-
cubeGeo.applyMatrix4(new
|
|
3173
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3174
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
2910
3175
|
applyModelPartRotation(part, cubeGeo);
|
|
2911
3176
|
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
2912
3177
|
partAnchor.add(mesh);
|
|
@@ -2919,24 +3184,25 @@ var EntityObject = class extends SceneObject {
|
|
|
2919
3184
|
this.meshesCreated = true;
|
|
2920
3185
|
}
|
|
2921
3186
|
async applyTextures() {
|
|
2922
|
-
|
|
2923
|
-
const
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
this.
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
3187
|
+
const assetKeyStr = this.textureKey.serialize();
|
|
3188
|
+
const keyStr = `entity:${assetKeyStr}`;
|
|
3189
|
+
let mat = Caching.materialCache.getIfPresent(keyStr);
|
|
3190
|
+
if (!mat) {
|
|
3191
|
+
const pending = this.loadTextures();
|
|
3192
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
3193
|
+
await pending;
|
|
3194
|
+
if (!this.imageData) return;
|
|
3195
|
+
const canvas = this.imageData.data.canvas;
|
|
3196
|
+
const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
|
|
3197
|
+
mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
3198
|
+
this.imageData = void 0;
|
|
3199
|
+
}
|
|
3200
|
+
this.iterateAllMeshes((mesh) => {
|
|
3201
|
+
mesh.material = mat;
|
|
3202
|
+
});
|
|
3203
|
+
this.notifyDirty();
|
|
2937
3204
|
}
|
|
2938
3205
|
};
|
|
2939
|
-
EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
2940
3206
|
function isEntityObject(obj) {
|
|
2941
3207
|
return obj.isEntityObject;
|
|
2942
3208
|
}
|
|
@@ -2948,7 +3214,7 @@ var GuiObject = class extends SceneObject {
|
|
|
2948
3214
|
|
|
2949
3215
|
// src/inspector/SceneInspector.ts
|
|
2950
3216
|
import { Raycaster, Vector2 as Vector22 } from "three";
|
|
2951
|
-
var
|
|
3217
|
+
var p7 = prefix("SceneInspector");
|
|
2952
3218
|
var help = "<span>Ctrl+Click to Select<br/></span><br/>";
|
|
2953
3219
|
var SceneInspector = class {
|
|
2954
3220
|
constructor(renderer) {
|
|
@@ -2977,8 +3243,7 @@ var SceneInspector = class {
|
|
|
2977
3243
|
return out;
|
|
2978
3244
|
}
|
|
2979
3245
|
onClick(event) {
|
|
2980
|
-
|
|
2981
|
-
if (((_a = event.target) == null ? void 0 : _a.nodeName) !== "CANVAS") return;
|
|
3246
|
+
if (event.target?.nodeName !== "CANVAS") return;
|
|
2982
3247
|
if (!event.ctrlKey) return;
|
|
2983
3248
|
setTimeout(() => {
|
|
2984
3249
|
this.mouse.x = event.clientX / window.innerWidth * 2 - 1;
|
|
@@ -3018,7 +3283,7 @@ var SceneInspector = class {
|
|
|
3018
3283
|
}
|
|
3019
3284
|
selectObject(targetObject, targetIntersection) {
|
|
3020
3285
|
this.selectedObject = targetObject;
|
|
3021
|
-
console.log(
|
|
3286
|
+
console.log(p7, "selected", targetObject);
|
|
3022
3287
|
this.redraw(targetObject, targetIntersection);
|
|
3023
3288
|
}
|
|
3024
3289
|
redraw(targetObject, targetIntersection) {
|
|
@@ -3316,7 +3581,7 @@ var SceneStatsDisplay = class {
|
|
|
3316
3581
|
};
|
|
3317
3582
|
|
|
3318
3583
|
// src/instance/InstanceManager.ts
|
|
3319
|
-
var
|
|
3584
|
+
var p8 = prefix("InstanceManager");
|
|
3320
3585
|
var InstanceManager = class {
|
|
3321
3586
|
constructor() {
|
|
3322
3587
|
this.isInstanceManager = true;
|
|
@@ -3324,7 +3589,7 @@ var InstanceManager = class {
|
|
|
3324
3589
|
}
|
|
3325
3590
|
async get(key) {
|
|
3326
3591
|
if (key in this.instanceCache) {
|
|
3327
|
-
console.debug(
|
|
3592
|
+
console.debug(p8, "key in cache", key);
|
|
3328
3593
|
return (await this.instanceCache[key]).nextInstance();
|
|
3329
3594
|
}
|
|
3330
3595
|
return void 0;
|
|
@@ -3333,13 +3598,17 @@ var InstanceManager = class {
|
|
|
3333
3598
|
if (key in this.instanceCache) {
|
|
3334
3599
|
return await this.get(key);
|
|
3335
3600
|
}
|
|
3336
|
-
console.debug(
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
})
|
|
3342
|
-
|
|
3601
|
+
console.debug(p8, "key not in cache", key);
|
|
3602
|
+
const pending = Promise.resolve().then(supplier).then((obj) => obj.nextInstance());
|
|
3603
|
+
this.instanceCache[key] = pending;
|
|
3604
|
+
try {
|
|
3605
|
+
return await pending;
|
|
3606
|
+
} catch (error) {
|
|
3607
|
+
if (this.instanceCache[key] === pending) {
|
|
3608
|
+
delete this.instanceCache[key];
|
|
3609
|
+
}
|
|
3610
|
+
throw error;
|
|
3611
|
+
}
|
|
3343
3612
|
}
|
|
3344
3613
|
reset() {
|
|
3345
3614
|
for (let instanceCacheKey in this.instanceCache) {
|
|
@@ -3393,7 +3662,7 @@ function isQuadArray(obj) {
|
|
|
3393
3662
|
}
|
|
3394
3663
|
|
|
3395
3664
|
// src/model/scene/ModelObject.ts
|
|
3396
|
-
import { BoxGeometry as BoxGeometry5, Matrix4 as Matrix45 } from "three";
|
|
3665
|
+
import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix45 } from "three";
|
|
3397
3666
|
|
|
3398
3667
|
// src/three/BufferGeometryUtils.js
|
|
3399
3668
|
import {
|
|
@@ -3405,7 +3674,7 @@ import {
|
|
|
3405
3674
|
TriangleFanDrawMode,
|
|
3406
3675
|
TriangleStripDrawMode,
|
|
3407
3676
|
TrianglesDrawMode,
|
|
3408
|
-
Vector3 as
|
|
3677
|
+
Vector3 as Vector36
|
|
3409
3678
|
} from "three";
|
|
3410
3679
|
function computeTangents(geometry) {
|
|
3411
3680
|
geometry.computeTangents();
|
|
@@ -3724,15 +3993,15 @@ function computeMorphedAttributes(object) {
|
|
|
3724
3993
|
console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
|
|
3725
3994
|
return null;
|
|
3726
3995
|
}
|
|
3727
|
-
const _vA = new
|
|
3728
|
-
const _vB = new
|
|
3729
|
-
const _vC = new
|
|
3730
|
-
const _tempA = new
|
|
3731
|
-
const _tempB = new
|
|
3732
|
-
const _tempC = new
|
|
3733
|
-
const _morphA = new
|
|
3734
|
-
const _morphB = new
|
|
3735
|
-
const _morphC = new
|
|
3996
|
+
const _vA = new Vector36();
|
|
3997
|
+
const _vB = new Vector36();
|
|
3998
|
+
const _vC = new Vector36();
|
|
3999
|
+
const _tempA = new Vector36();
|
|
4000
|
+
const _tempB = new Vector36();
|
|
4001
|
+
const _tempC = new Vector36();
|
|
4002
|
+
const _morphA = new Vector36();
|
|
4003
|
+
const _morphB = new Vector36();
|
|
4004
|
+
const _morphC = new Vector36();
|
|
3736
4005
|
function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
|
|
3737
4006
|
_vA.fromBufferAttribute(attribute, a2);
|
|
3738
4007
|
_vB.fromBufferAttribute(attribute, b2);
|
|
@@ -3938,26 +4207,29 @@ function computeMorphedAttributes(object) {
|
|
|
3938
4207
|
}
|
|
3939
4208
|
|
|
3940
4209
|
// src/model/scene/ModelObject.ts
|
|
3941
|
-
var
|
|
3942
|
-
var
|
|
3943
|
-
var
|
|
4210
|
+
var import_ts_deepmerge5 = __toESM(require_dist());
|
|
4211
|
+
var p9 = prefix("ModelObject");
|
|
4212
|
+
var ModelObject = class _ModelObject extends SceneObject {
|
|
3944
4213
|
constructor(originalModel, options) {
|
|
3945
4214
|
super(options);
|
|
3946
4215
|
this.originalModel = originalModel;
|
|
3947
4216
|
this.isModelObject = true;
|
|
3948
4217
|
this.meshesCreated = false;
|
|
3949
|
-
this.options = (0,
|
|
4218
|
+
this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
|
|
4219
|
+
if (this.options.tints) this.options.tints = { ...this.options.tints };
|
|
3950
4220
|
console.log("ModelObject options", this.options);
|
|
3951
4221
|
}
|
|
4222
|
+
static {
|
|
4223
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4224
|
+
}
|
|
3952
4225
|
async init() {
|
|
3953
4226
|
await this.loadTextures();
|
|
3954
4227
|
this.createMeshes();
|
|
3955
4228
|
this.applyTextures();
|
|
3956
4229
|
}
|
|
3957
4230
|
dispose() {
|
|
3958
|
-
var _a;
|
|
3959
4231
|
super.dispose();
|
|
3960
|
-
|
|
4232
|
+
this.atlas?.dispose();
|
|
3961
4233
|
}
|
|
3962
4234
|
get textureAtlas() {
|
|
3963
4235
|
return this.atlas;
|
|
@@ -3967,14 +4239,30 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
3967
4239
|
this.atlas = await UVMapper.getAtlas(this.originalModel);
|
|
3968
4240
|
}
|
|
3969
4241
|
createMeshes(force = false) {
|
|
3970
|
-
var _a;
|
|
3971
4242
|
if (this.meshesCreated && !force) return;
|
|
3972
4243
|
const mat = Materials.MISSING_TEXTURE;
|
|
3973
4244
|
let allGeos = [];
|
|
3974
4245
|
if (this.atlas) {
|
|
3975
4246
|
if (this.atlas.model.elements) {
|
|
3976
|
-
|
|
4247
|
+
this.atlas.model.elements?.forEach((el) => {
|
|
3977
4248
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4249
|
+
if (this.options.uvLockRotation) {
|
|
4250
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler4(...this.options.uvLockRotation));
|
|
4251
|
+
}
|
|
4252
|
+
if (this.options.tints) {
|
|
4253
|
+
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
4254
|
+
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
4255
|
+
const tintIndex = el.faces[faceName]?.tintindex;
|
|
4256
|
+
if (tintIndex === void 0 || tintIndex < 0) continue;
|
|
4257
|
+
const tint = this.options.tints[tintIndex];
|
|
4258
|
+
if (tint === void 0) continue;
|
|
4259
|
+
const color = new Color3(tint);
|
|
4260
|
+
for (let vertex = 0; vertex < 4; vertex++) {
|
|
4261
|
+
color.toArray(colors, (faceIndex * 4 + vertex) * 3);
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
elGeo.setAttribute("color", new BufferAttribute4(colors, 3));
|
|
4265
|
+
}
|
|
3978
4266
|
elGeo.applyMatrix4(new Matrix45().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
|
|
3979
4267
|
elGeo.applyMatrix4(new Matrix45().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
3980
4268
|
if (el.rotation) {
|
|
@@ -3991,10 +4279,10 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
3991
4279
|
}
|
|
3992
4280
|
});
|
|
3993
4281
|
} else {
|
|
3994
|
-
console.debug(
|
|
4282
|
+
console.debug(p9, this.atlas.model, "has no elements");
|
|
3995
4283
|
}
|
|
3996
4284
|
} else {
|
|
3997
|
-
console.debug(
|
|
4285
|
+
console.debug(p9, "Missing atlas for", this);
|
|
3998
4286
|
}
|
|
3999
4287
|
if (this.options.mergeMeshes) {
|
|
4000
4288
|
let combinedGeo;
|
|
@@ -4031,6 +4319,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4031
4319
|
/*TODO: get this from render options*/
|
|
4032
4320
|
);
|
|
4033
4321
|
this.iterateAllMeshes((mesh) => {
|
|
4322
|
+
if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
|
|
4034
4323
|
mesh.material = mat;
|
|
4035
4324
|
});
|
|
4036
4325
|
if (this.atlas.hasAnimation) {
|
|
@@ -4046,17 +4335,25 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4046
4335
|
}
|
|
4047
4336
|
}
|
|
4048
4337
|
};
|
|
4049
|
-
_ModelObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4050
|
-
var ModelObject = _ModelObject;
|
|
4051
4338
|
function isModelObject(obj) {
|
|
4052
4339
|
return obj.isModelObject;
|
|
4053
4340
|
}
|
|
4054
4341
|
|
|
4055
4342
|
// src/model/block/scene/BlockObject.ts
|
|
4056
|
-
var
|
|
4057
|
-
import { Euler as
|
|
4058
|
-
var
|
|
4059
|
-
|
|
4343
|
+
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4344
|
+
import { Euler as Euler5, Matrix4 as Matrix46, Vector3 as Vector37 } from "three";
|
|
4345
|
+
var p10 = prefix("BlockObject");
|
|
4346
|
+
function matchesCondition(condition, state) {
|
|
4347
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4348
|
+
if (Array.isArray(value)) {
|
|
4349
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4350
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4351
|
+
return false;
|
|
4352
|
+
}
|
|
4353
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4354
|
+
});
|
|
4355
|
+
}
|
|
4356
|
+
var BlockObject = class _BlockObject extends SceneObject {
|
|
4060
4357
|
constructor(blockState, options) {
|
|
4061
4358
|
super(options);
|
|
4062
4359
|
this.blockState = blockState;
|
|
@@ -4069,11 +4366,16 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4069
4366
|
this._instanceModel = [];
|
|
4070
4367
|
this._variants = [];
|
|
4071
4368
|
this._models = [];
|
|
4072
|
-
this.options = (0,
|
|
4369
|
+
this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
|
|
4370
|
+
}
|
|
4371
|
+
static {
|
|
4372
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4373
|
+
applyDefaultState: true
|
|
4374
|
+
});
|
|
4073
4375
|
}
|
|
4074
4376
|
async init() {
|
|
4075
4377
|
if (this.options.applyDefaultState) {
|
|
4076
|
-
const defaultState = this.blockState.key ? BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4378
|
+
const defaultState = this.blockState.key ? await BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4077
4379
|
if (defaultState && Object.keys(defaultState).length > 0) {
|
|
4078
4380
|
const state = {};
|
|
4079
4381
|
for (let k in defaultState) {
|
|
@@ -4084,15 +4386,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4084
4386
|
if (this.blockState.variants) {
|
|
4085
4387
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4086
4388
|
} else if (this.blockState.multipart) {
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
if (k) {
|
|
4091
|
-
await this.setState(k, part.when[k].split("|")[0]);
|
|
4092
|
-
break;
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
}
|
|
4389
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4390
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4391
|
+
await this.setState(state);
|
|
4096
4392
|
}
|
|
4097
4393
|
}
|
|
4098
4394
|
} else {
|
|
@@ -4107,7 +4403,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4107
4403
|
if (isModelObject(model)) {
|
|
4108
4404
|
model.removeFromScene();
|
|
4109
4405
|
} else if (isInstanceReference(model)) {
|
|
4110
|
-
model.setScale(new
|
|
4406
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4111
4407
|
}
|
|
4112
4408
|
}
|
|
4113
4409
|
super.removeFromScene();
|
|
@@ -4149,55 +4445,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4149
4445
|
} else if (this.blockState.multipart) {
|
|
4150
4446
|
for (let part of this.blockState.multipart) {
|
|
4151
4447
|
if (!part.apply) {
|
|
4152
|
-
console.debug(
|
|
4448
|
+
console.debug(p10, "Missing apply for blockState part", part);
|
|
4153
4449
|
continue;
|
|
4154
4450
|
}
|
|
4155
|
-
if (!part.when) {
|
|
4451
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4156
4452
|
out.push(this.getSingleVariant(part.apply));
|
|
4157
|
-
} else {
|
|
4158
|
-
let matches = true;
|
|
4159
|
-
if ("OR" in part.when) {
|
|
4160
|
-
const or = part.when.OR;
|
|
4161
|
-
let anyMatch = false;
|
|
4162
|
-
for (let o of or) {
|
|
4163
|
-
for (let k in o) {
|
|
4164
|
-
const split = o[k].split("|");
|
|
4165
|
-
let m = false;
|
|
4166
|
-
for (let s of split) {
|
|
4167
|
-
if (`${state[k]}` === `${s}`) {
|
|
4168
|
-
m = true;
|
|
4169
|
-
break;
|
|
4170
|
-
}
|
|
4171
|
-
}
|
|
4172
|
-
if (m) {
|
|
4173
|
-
anyMatch = true;
|
|
4174
|
-
break;
|
|
4175
|
-
}
|
|
4176
|
-
}
|
|
4177
|
-
}
|
|
4178
|
-
if (!anyMatch) {
|
|
4179
|
-
matches = false;
|
|
4180
|
-
}
|
|
4181
|
-
} else {
|
|
4182
|
-
for (let k in part.when) {
|
|
4183
|
-
const split = part.when[k].split("|");
|
|
4184
|
-
let m = false;
|
|
4185
|
-
for (let s of split) {
|
|
4186
|
-
if (`${state[k]}` === `${s}`) {
|
|
4187
|
-
m = true;
|
|
4188
|
-
break;
|
|
4189
|
-
}
|
|
4190
|
-
}
|
|
4191
|
-
if (!m) {
|
|
4192
|
-
matches = false;
|
|
4193
|
-
break;
|
|
4194
|
-
}
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
if (matches) {
|
|
4198
|
-
const variants = part.apply;
|
|
4199
|
-
out.push(this.getSingleVariant(variants));
|
|
4200
|
-
}
|
|
4201
4453
|
}
|
|
4202
4454
|
}
|
|
4203
4455
|
}
|
|
@@ -4212,7 +4464,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4212
4464
|
}
|
|
4213
4465
|
for (let model of this._models) {
|
|
4214
4466
|
if (isInstanceReference(model)) {
|
|
4215
|
-
model.setScale(new
|
|
4467
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4216
4468
|
} else {
|
|
4217
4469
|
model.dispose();
|
|
4218
4470
|
}
|
|
@@ -4227,11 +4479,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4227
4479
|
}
|
|
4228
4480
|
}
|
|
4229
4481
|
getSingleVariant(variants) {
|
|
4230
|
-
if (Array.isArray(variants))
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4482
|
+
if (!Array.isArray(variants)) return variants;
|
|
4483
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4484
|
+
const total = variants.reduce((sum, variant) => {
|
|
4485
|
+
const weight = variant.weight ?? 1;
|
|
4486
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4487
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4488
|
+
}
|
|
4489
|
+
return sum + weight;
|
|
4490
|
+
}, 0);
|
|
4491
|
+
let choice = Math.random() * total;
|
|
4492
|
+
for (const variant of variants) {
|
|
4493
|
+
choice -= variant.weight ?? 1;
|
|
4494
|
+
if (choice < 0) return variant;
|
|
4495
|
+
}
|
|
4496
|
+
return variants[variants.length - 1];
|
|
4235
4497
|
}
|
|
4236
4498
|
// @deprecated
|
|
4237
4499
|
async createAVariant(variants, instanceInfo) {
|
|
@@ -4239,28 +4501,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4239
4501
|
await this.createVariant(variant);
|
|
4240
4502
|
}
|
|
4241
4503
|
async createVariant(variant) {
|
|
4242
|
-
const
|
|
4243
|
-
const obj = await this.scene.addModel(model, this.options);
|
|
4244
|
-
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4245
|
-
this._isInstanced = true;
|
|
4246
|
-
this._instanceCounter = 1;
|
|
4247
|
-
}
|
|
4248
|
-
let rotation = new Euler3(0, 0, 0);
|
|
4504
|
+
const rotation = new Euler5();
|
|
4249
4505
|
if (typeof variant.x !== "undefined") {
|
|
4250
4506
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4251
4507
|
}
|
|
4252
4508
|
if (typeof variant.y !== "undefined") {
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4509
|
+
rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
|
|
4510
|
+
}
|
|
4511
|
+
const model = await Models.getMerged(AssetKey.parse("models", variant.model));
|
|
4512
|
+
const options = {
|
|
4513
|
+
...this.options,
|
|
4514
|
+
uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
|
|
4515
|
+
};
|
|
4516
|
+
const obj = await this.scene.addModel(model, options);
|
|
4517
|
+
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4518
|
+
this._isInstanced = true;
|
|
4519
|
+
this._instanceCounter = 1;
|
|
4258
4520
|
}
|
|
4259
4521
|
obj.setRotation(rotation);
|
|
4260
|
-
setTimeout(() => {
|
|
4261
|
-
obj.setRotation(rotation);
|
|
4262
|
-
}, 150);
|
|
4263
|
-
console.log(obj);
|
|
4264
4522
|
return obj;
|
|
4265
4523
|
}
|
|
4266
4524
|
async resetState() {
|
|
@@ -4350,18 +4608,15 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4350
4608
|
}
|
|
4351
4609
|
}
|
|
4352
4610
|
setPosition(position) {
|
|
4353
|
-
|
|
4611
|
+
this.position.copy(position);
|
|
4354
4612
|
for (let model of this._models) {
|
|
4355
4613
|
model.setPosition(position);
|
|
4356
4614
|
}
|
|
4615
|
+
this.notifyDirty();
|
|
4357
4616
|
}
|
|
4358
4617
|
//TODO: should override rotation + scale methods
|
|
4359
4618
|
//TODO
|
|
4360
4619
|
};
|
|
4361
|
-
_BlockObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge7.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4362
|
-
applyDefaultState: true
|
|
4363
|
-
});
|
|
4364
|
-
var BlockObject = _BlockObject;
|
|
4365
4620
|
function isBlockObject(obj) {
|
|
4366
4621
|
return obj.isBlockObject;
|
|
4367
4622
|
}
|
|
@@ -4386,11 +4641,10 @@ var StructureParser = class {
|
|
|
4386
4641
|
throw new MineRenderError("Structure does not have palette(s)");
|
|
4387
4642
|
}
|
|
4388
4643
|
const blocks = nbt.blocks.value.value.map((block) => {
|
|
4389
|
-
var _a;
|
|
4390
4644
|
const state = palette.value.value[block.state.value];
|
|
4391
4645
|
if (state.Name.value === "minecraft:air") return void 0;
|
|
4392
4646
|
const props = {};
|
|
4393
|
-
for (let k in
|
|
4647
|
+
for (let k in state.Properties?.value) {
|
|
4394
4648
|
props[k] = state.Properties.value[k].value;
|
|
4395
4649
|
}
|
|
4396
4650
|
return {
|
|
@@ -4409,7 +4663,7 @@ var StructureParser = class {
|
|
|
4409
4663
|
|
|
4410
4664
|
// src/renderer/MineRenderScene.ts
|
|
4411
4665
|
import { Scene as Scene2 } from "three";
|
|
4412
|
-
var
|
|
4666
|
+
var import_ts_deepmerge8 = __toESM(require_dist());
|
|
4413
4667
|
|
|
4414
4668
|
// src/skin/SkinPart.ts
|
|
4415
4669
|
var SkinPart = /* @__PURE__ */ ((SkinPart2) => {
|
|
@@ -5140,7 +5394,7 @@ var slimSkinGeometries = {
|
|
|
5140
5394
|
};
|
|
5141
5395
|
|
|
5142
5396
|
// src/skin/scene/SkinObject.ts
|
|
5143
|
-
var
|
|
5397
|
+
var import_ts_deepmerge7 = __toESM(require_dist());
|
|
5144
5398
|
var SkinObject = class extends SceneObject {
|
|
5145
5399
|
constructor(options) {
|
|
5146
5400
|
super();
|
|
@@ -5148,7 +5402,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5148
5402
|
this.legacy = false;
|
|
5149
5403
|
this.skinTextureWidth = 64;
|
|
5150
5404
|
this.skinTextureHeight = 64;
|
|
5151
|
-
this.options = (0,
|
|
5405
|
+
this.options = (0, import_ts_deepmerge7.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
5152
5406
|
}
|
|
5153
5407
|
async init() {
|
|
5154
5408
|
this.createMeshes();
|
|
@@ -5252,7 +5506,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5252
5506
|
};
|
|
5253
5507
|
|
|
5254
5508
|
// src/renderer/MineRenderScene.ts
|
|
5255
|
-
var
|
|
5509
|
+
var MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
5256
5510
|
constructor(options) {
|
|
5257
5511
|
super();
|
|
5258
5512
|
this.isMineRenderScene = true;
|
|
@@ -5261,12 +5515,14 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5261
5515
|
this.dirty = true;
|
|
5262
5516
|
this.observedObjects = /* @__PURE__ */ new Set();
|
|
5263
5517
|
this.onObjectChange = (event) => {
|
|
5264
|
-
|
|
5265
|
-
if (((_a = event.target) == null ? void 0 : _a.parent) === this) {
|
|
5518
|
+
if (event.target?.parent === this) {
|
|
5266
5519
|
this.dirty = true;
|
|
5267
5520
|
}
|
|
5268
5521
|
};
|
|
5269
|
-
this.options = (0,
|
|
5522
|
+
this.options = (0, import_ts_deepmerge8.default)({}, _MineRenderScene.DEFAULT_OPTIONS, options ?? {});
|
|
5523
|
+
}
|
|
5524
|
+
static {
|
|
5525
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge8.default)({}, {});
|
|
5270
5526
|
}
|
|
5271
5527
|
add(...objects) {
|
|
5272
5528
|
for (const object of objects) {
|
|
@@ -5274,7 +5530,7 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5274
5530
|
try {
|
|
5275
5531
|
super.add(object);
|
|
5276
5532
|
} finally {
|
|
5277
|
-
if (
|
|
5533
|
+
if (object?.isObject3D && object !== this) {
|
|
5278
5534
|
this.updateObjectRegistration(object, object.parent === this);
|
|
5279
5535
|
}
|
|
5280
5536
|
}
|
|
@@ -5317,15 +5573,20 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5317
5573
|
return this.add(...object);
|
|
5318
5574
|
}
|
|
5319
5575
|
async addSceneObject(asset, objectSupplier, _options, parent = this) {
|
|
5320
|
-
var _a, _b;
|
|
5321
5576
|
console.log("addSceneObject", asset);
|
|
5322
5577
|
console.log("parent", parent);
|
|
5323
5578
|
console.log(_options);
|
|
5324
5579
|
this.dirty = true;
|
|
5325
5580
|
const obj = await objectSupplier();
|
|
5326
|
-
if (
|
|
5581
|
+
if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
|
|
5327
5582
|
console.log("instanceMeshes + key");
|
|
5328
|
-
|
|
5583
|
+
let key = asset.key.serialize();
|
|
5584
|
+
if (isModelObject(obj)) {
|
|
5585
|
+
const { uvLockRotation, tints } = obj.options;
|
|
5586
|
+
if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
|
|
5587
|
+
const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
|
|
5588
|
+
if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
|
|
5589
|
+
}
|
|
5329
5590
|
return this.instanceManager.getOrCreate(key, async () => {
|
|
5330
5591
|
obj.scene = this;
|
|
5331
5592
|
await obj.init();
|
|
@@ -5363,472 +5624,19 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5363
5624
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
5364
5625
|
}
|
|
5365
5626
|
};
|
|
5366
|
-
_MineRenderScene.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {});
|
|
5367
|
-
var MineRenderScene = _MineRenderScene;
|
|
5368
5627
|
function isMineRenderScene(obj) {
|
|
5369
5628
|
return obj.isMineRenderScene;
|
|
5370
|
-
}
|
|
5371
|
-
|
|
5372
|
-
// src/renderer/Renderer.ts
|
|
5373
|
-
import { AxesHelper as AxesHelper3, GridHelper,
|
|
5374
|
-
var
|
|
5375
|
-
import Stats from "stats.js";
|
|
5376
|
-
import { EffectComposer, RenderPass } from "postprocessing";
|
|
5377
|
-
var _Renderer = class _Renderer {
|
|
5378
|
-
constructor(options) {
|
|
5379
|
-
this._dirty = true;
|
|
5380
|
-
this._animationTimer = void 0;
|
|
5381
|
-
this._animationFrame = void 0;
|
|
5382
|
-
this._resizeListener = void 0;
|
|
5383
|
-
this._disposed = false;
|
|
5384
|
-
this._debugHelpers = [];
|
|
5385
|
-
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
5386
|
-
this._changeListener = () => {
|
|
5387
|
-
this._dirty = true;
|
|
5388
|
-
};
|
|
5389
|
-
this.options = (0, import_ts_deepmerge10.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
5390
|
-
this._animationLoop = this.animate.bind(this);
|
|
5391
|
-
this._fpsTimer = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
5392
|
-
this._scene = this.createScene();
|
|
5393
|
-
this._camera = this.createCamera();
|
|
5394
|
-
this._renderer = this.createRenderer();
|
|
5395
|
-
this._composer = this.createComposer();
|
|
5396
|
-
if (this.options.render.stats) {
|
|
5397
|
-
this._stats = new Stats();
|
|
5398
|
-
document.body.appendChild(this._stats.dom);
|
|
5399
|
-
}
|
|
5400
|
-
this.init();
|
|
5401
|
-
}
|
|
5402
|
-
//<editor-fold desc="INIT">
|
|
5403
|
-
createScene() {
|
|
5404
|
-
return new MineRenderScene();
|
|
5405
|
-
}
|
|
5406
|
-
createCamera() {
|
|
5407
|
-
switch (this.options.camera.type) {
|
|
5408
|
-
case "perspective":
|
|
5409
|
-
default:
|
|
5410
|
-
return new PerspectiveCamera(
|
|
5411
|
-
this.options.camera.perspective.fov,
|
|
5412
|
-
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
5413
|
-
this.options.camera.near,
|
|
5414
|
-
this.options.camera.far
|
|
5415
|
-
);
|
|
5416
|
-
case "orthographic":
|
|
5417
|
-
return new OrthographicCamera(
|
|
5418
|
-
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
5419
|
-
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
5420
|
-
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
5421
|
-
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
5422
|
-
this.options.camera.near,
|
|
5423
|
-
this.options.camera.far
|
|
5424
|
-
);
|
|
5425
|
-
}
|
|
5426
|
-
}
|
|
5427
|
-
createRenderer() {
|
|
5428
|
-
const renderer = new WebGLRenderer({
|
|
5429
|
-
antialias: this.options.render.antialias,
|
|
5430
|
-
alpha: true,
|
|
5431
|
-
powerPreference: "high-performance",
|
|
5432
|
-
depth: true
|
|
5433
|
-
});
|
|
5434
|
-
renderer.setClearColor(0, 0);
|
|
5435
|
-
renderer.shadowMap.enabled = true;
|
|
5436
|
-
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
5437
|
-
renderer.outputEncoding = LinearEncoding;
|
|
5438
|
-
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
5439
|
-
return renderer;
|
|
5440
|
-
}
|
|
5441
|
-
createComposer() {
|
|
5442
|
-
const composer = new EffectComposer(this.renderer);
|
|
5443
|
-
if (!this.options.composer.enabled) return composer;
|
|
5444
|
-
composer.setSize(this.viewWidth, this.viewHeight);
|
|
5445
|
-
composer.addPass(new RenderPass(this.scene, this.camera));
|
|
5446
|
-
return composer;
|
|
5447
|
-
}
|
|
5448
|
-
//</editor-fold>
|
|
5449
|
-
init() {
|
|
5450
|
-
if (this._disposed) return;
|
|
5451
|
-
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
5452
|
-
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
5453
|
-
}
|
|
5454
|
-
if (this.options.debug.grid) {
|
|
5455
|
-
const gridHelper = new GridHelper(128, 16);
|
|
5456
|
-
this._debugHelpers.push(gridHelper);
|
|
5457
|
-
this.scene.add(gridHelper);
|
|
5458
|
-
const gridHelper2 = new GridHelper(128, 16);
|
|
5459
|
-
this._debugHelpers.push(gridHelper2);
|
|
5460
|
-
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
5461
|
-
this.scene.add(gridHelper2);
|
|
5462
|
-
const gridHelper3 = new GridHelper(128, 16);
|
|
5463
|
-
this._debugHelpers.push(gridHelper3);
|
|
5464
|
-
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
5465
|
-
this.scene.add(gridHelper3);
|
|
5466
|
-
}
|
|
5467
|
-
if (this.options.debug.axes) {
|
|
5468
|
-
const axesHelper = new AxesHelper3(64);
|
|
5469
|
-
this._debugHelpers.push(axesHelper);
|
|
5470
|
-
this.scene.add(axesHelper);
|
|
5471
|
-
}
|
|
5472
|
-
if (this.options.camera.position) {
|
|
5473
|
-
if (isVector3(this.options.camera.position)) {
|
|
5474
|
-
this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
|
|
5475
|
-
} else if (isTripleArray(this.options.camera.position)) {
|
|
5476
|
-
this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
|
|
5477
|
-
}
|
|
5478
|
-
}
|
|
5479
|
-
if (this.options.camera.lookingAt) {
|
|
5480
|
-
if (isVector3(this.options.camera.lookingAt)) {
|
|
5481
|
-
this.camera.lookAt(this.options.camera.lookingAt);
|
|
5482
|
-
} else if (isTripleArray(this.options.camera.lookingAt)) {
|
|
5483
|
-
this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
|
|
5484
|
-
}
|
|
5485
|
-
}
|
|
5486
|
-
if (this.options.render.autoResize && !this._resizeListener) {
|
|
5487
|
-
this._resizeListener = () => {
|
|
5488
|
-
this.resize(this.viewWidth, this.viewHeight);
|
|
5489
|
-
};
|
|
5490
|
-
window.addEventListener("resize", this._resizeListener);
|
|
5491
|
-
}
|
|
5492
|
-
}
|
|
5493
|
-
get element() {
|
|
5494
|
-
return this._element;
|
|
5495
|
-
}
|
|
5496
|
-
appendTo(element) {
|
|
5497
|
-
if (this._disposed) return;
|
|
5498
|
-
this._element = element;
|
|
5499
|
-
this._element.appendChild(this.renderer.domElement);
|
|
5500
|
-
if (this.viewWidth == 0) {
|
|
5501
|
-
console.warn("0 element width");
|
|
5502
|
-
}
|
|
5503
|
-
if (this.viewHeight == 0) {
|
|
5504
|
-
console.warn("0 element height");
|
|
5505
|
-
}
|
|
5506
|
-
this.resize(this.viewWidth, this.viewHeight);
|
|
5507
|
-
}
|
|
5508
|
-
/**
|
|
5509
|
-
* Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
|
|
5510
|
-
* The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
|
|
5511
|
-
*/
|
|
5512
|
-
registerEventDispatcher(dispatcher, changeEvent2 = "change") {
|
|
5513
|
-
if (this._disposed) return;
|
|
5514
|
-
let events = this._eventDispatchers.get(dispatcher);
|
|
5515
|
-
if (!events) {
|
|
5516
|
-
events = /* @__PURE__ */ new Set();
|
|
5517
|
-
this._eventDispatchers.set(dispatcher, events);
|
|
5518
|
-
}
|
|
5519
|
-
if (events.has(changeEvent2)) return;
|
|
5520
|
-
events.add(changeEvent2);
|
|
5521
|
-
dispatcher.addEventListener(changeEvent2, this._changeListener);
|
|
5522
|
-
}
|
|
5523
|
-
resize(width, height) {
|
|
5524
|
-
if (this._disposed) return;
|
|
5525
|
-
if (isPerspectiveCamera(this.camera)) {
|
|
5526
|
-
this.camera.aspect = width / height;
|
|
5527
|
-
this.camera.updateProjectionMatrix();
|
|
5528
|
-
} else if (isOrthographicCamera(this.camera)) {
|
|
5529
|
-
this.camera.left = width / -2;
|
|
5530
|
-
this.camera.right = width / 2;
|
|
5531
|
-
this.camera.top = height / 2;
|
|
5532
|
-
this.camera.bottom = height / -2;
|
|
5533
|
-
this.camera.updateProjectionMatrix();
|
|
5534
|
-
}
|
|
5535
|
-
this.renderer.setSize(width, height);
|
|
5536
|
-
this.composer.setSize(width, height);
|
|
5537
|
-
this._dirty = true;
|
|
5538
|
-
}
|
|
5539
|
-
//<editor-fold desc="RENDER">
|
|
5540
|
-
get dirty() {
|
|
5541
|
-
return this._dirty || this.scene.dirty;
|
|
5542
|
-
}
|
|
5543
|
-
set dirty(dirty) {
|
|
5544
|
-
this._dirty = dirty;
|
|
5545
|
-
this.scene.dirty = dirty;
|
|
5546
|
-
}
|
|
5547
|
-
start() {
|
|
5548
|
-
if (this._disposed) return;
|
|
5549
|
-
this.stop();
|
|
5550
|
-
this.renderer.setAnimationLoop(this._animationLoop);
|
|
5551
|
-
}
|
|
5552
|
-
stop() {
|
|
5553
|
-
if (this._disposed) return;
|
|
5554
|
-
this.renderer.setAnimationLoop(null);
|
|
5555
|
-
if (this._animationTimer)
|
|
5556
|
-
clearTimeout(this._animationTimer);
|
|
5557
|
-
this._animationTimer = void 0;
|
|
5558
|
-
if (this._animationFrame)
|
|
5559
|
-
cancelAnimationFrame(this._animationFrame);
|
|
5560
|
-
this._animationFrame = void 0;
|
|
5561
|
-
}
|
|
5562
|
-
/**
|
|
5563
|
-
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
5564
|
-
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
5565
|
-
* controls must be managed by their owners.
|
|
5566
|
-
*/
|
|
5567
|
-
dispose() {
|
|
5568
|
-
var _a;
|
|
5569
|
-
if (this._disposed) return;
|
|
5570
|
-
this.stop();
|
|
5571
|
-
this._disposed = true;
|
|
5572
|
-
if (this._resizeListener) {
|
|
5573
|
-
window.removeEventListener("resize", this._resizeListener);
|
|
5574
|
-
this._resizeListener = void 0;
|
|
5575
|
-
}
|
|
5576
|
-
for (const [dispatcher, events] of this._eventDispatchers) {
|
|
5577
|
-
for (const event of events) {
|
|
5578
|
-
dispatcher.removeEventListener(event, this._changeListener);
|
|
5579
|
-
}
|
|
5580
|
-
}
|
|
5581
|
-
this._eventDispatchers.clear();
|
|
5582
|
-
(_a = this._stats) == null ? void 0 : _a.dom.remove();
|
|
5583
|
-
this._stats = void 0;
|
|
5584
|
-
this.renderer.domElement.remove();
|
|
5585
|
-
this._element = void 0;
|
|
5586
|
-
this.scene.clear();
|
|
5587
|
-
for (const helper of this._debugHelpers) {
|
|
5588
|
-
helper.geometry.dispose();
|
|
5589
|
-
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
5590
|
-
for (const material of materials) {
|
|
5591
|
-
material.dispose();
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
this._debugHelpers.length = 0;
|
|
5595
|
-
this.composer.dispose();
|
|
5596
|
-
this.renderer.dispose();
|
|
5597
|
-
this.renderer.forceContextLoss();
|
|
5598
|
-
}
|
|
5599
|
-
animate(t) {
|
|
5600
|
-
if (this._disposed) return;
|
|
5601
|
-
if (this._stats) {
|
|
5602
|
-
this._stats.begin();
|
|
5603
|
-
}
|
|
5604
|
-
if (this.dirty || this.options.render.renderAlways) {
|
|
5605
|
-
if (this.options.composer.enabled) {
|
|
5606
|
-
this.composer.render();
|
|
5607
|
-
} else {
|
|
5608
|
-
this.renderer.render(this.scene, this.camera);
|
|
5609
|
-
}
|
|
5610
|
-
}
|
|
5611
|
-
this.dirty = false;
|
|
5612
|
-
if (this._stats) {
|
|
5613
|
-
this._stats.end();
|
|
5614
|
-
}
|
|
5615
|
-
}
|
|
5616
|
-
//</editor-fold>
|
|
5617
|
-
toImage() {
|
|
5618
|
-
return this.renderer.domElement.toDataURL();
|
|
5619
|
-
}
|
|
5620
|
-
///
|
|
5621
|
-
get attachedToBody() {
|
|
5622
|
-
return this.element === document.body;
|
|
5623
|
-
}
|
|
5624
|
-
get viewWidth() {
|
|
5625
|
-
var _a;
|
|
5626
|
-
return this.attachedToBody ? window.innerWidth : ((_a = this.element) == null ? void 0 : _a.offsetWidth) || 0;
|
|
5627
|
-
}
|
|
5628
|
-
get viewHeight() {
|
|
5629
|
-
var _a;
|
|
5630
|
-
return this.attachedToBody ? window.innerHeight : ((_a = this.element) == null ? void 0 : _a.offsetHeight) || 0;
|
|
5631
|
-
}
|
|
5632
|
-
get scene() {
|
|
5633
|
-
return this._scene;
|
|
5634
|
-
}
|
|
5635
|
-
get camera() {
|
|
5636
|
-
return this._camera;
|
|
5637
|
-
}
|
|
5638
|
-
get renderer() {
|
|
5639
|
-
return this._renderer;
|
|
5640
|
-
}
|
|
5641
|
-
get composer() {
|
|
5642
|
-
return this._composer;
|
|
5643
|
-
}
|
|
5644
|
-
///
|
|
5645
|
-
};
|
|
5646
|
-
_Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge10.default)({}, {
|
|
5647
|
-
camera: {
|
|
5648
|
-
type: "perspective",
|
|
5649
|
-
near: 1,
|
|
5650
|
-
far: 5e3,
|
|
5651
|
-
perspective: {
|
|
5652
|
-
aspect: void 0,
|
|
5653
|
-
fov: 50
|
|
5654
|
-
},
|
|
5655
|
-
orthographic: {
|
|
5656
|
-
left: void 0,
|
|
5657
|
-
right: void 0,
|
|
5658
|
-
top: void 0,
|
|
5659
|
-
bottom: void 0
|
|
5660
|
-
},
|
|
5661
|
-
position: new Vector37(50, 50, 50),
|
|
5662
|
-
lookingAt: new Vector37(0, 0, 0)
|
|
5663
|
-
},
|
|
5664
|
-
render: {
|
|
5665
|
-
fpsLimit: 60,
|
|
5666
|
-
stats: false,
|
|
5667
|
-
antialias: true,
|
|
5668
|
-
shade: true,
|
|
5669
|
-
autoResize: true,
|
|
5670
|
-
renderAlways: false
|
|
5671
|
-
},
|
|
5672
|
-
composer: {
|
|
5673
|
-
enabled: true
|
|
5674
|
-
},
|
|
5675
|
-
debug: {
|
|
5676
|
-
grid: false,
|
|
5677
|
-
axes: false
|
|
5678
|
-
}
|
|
5679
|
-
});
|
|
5680
|
-
var Renderer = _Renderer;
|
|
5681
|
-
|
|
5682
|
-
// src/skin/Skins.ts
|
|
5683
|
-
var Skins = class {
|
|
5684
|
-
//<editor-fold desc="Skins">
|
|
5685
|
-
static async fromUuidOrUsername(uuidOrUsername) {
|
|
5686
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5687
|
-
return this.fromUuid(uuidOrUsername);
|
|
5688
|
-
}
|
|
5689
|
-
return this.fromUsername(uuidOrUsername);
|
|
5690
|
-
}
|
|
5691
|
-
static async fromUuid(uuid) {
|
|
5692
|
-
return this.getSkinProxySkinUrl(uuid);
|
|
5693
|
-
}
|
|
5694
|
-
static async fromUsername(username) {
|
|
5695
|
-
return this.usernameToUuid(username).then((uuid) => {
|
|
5696
|
-
if (uuid) {
|
|
5697
|
-
return this.fromUuid(uuid);
|
|
5698
|
-
}
|
|
5699
|
-
return void 0;
|
|
5700
|
-
});
|
|
5701
|
-
}
|
|
5702
|
-
static async fromMineSkin(mineskinId) {
|
|
5703
|
-
return this.getMineSkin(mineskinId).then((mineskin) => {
|
|
5704
|
-
if (mineskin) {
|
|
5705
|
-
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
5706
|
-
}
|
|
5707
|
-
return void 0;
|
|
5708
|
-
});
|
|
5709
|
-
}
|
|
5710
|
-
//</editor-fold>
|
|
5711
|
-
//<editor-fold desc="Capes">
|
|
5712
|
-
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
5713
|
-
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
5714
|
-
return this.capeFromUuid(uuidOrUsername);
|
|
5715
|
-
}
|
|
5716
|
-
return this.capeFromUsername(uuidOrUsername);
|
|
5717
|
-
}
|
|
5718
|
-
static async capeFromUuid(uuid) {
|
|
5719
|
-
return this.getSkinProxyCapeUrl(uuid);
|
|
5720
|
-
}
|
|
5721
|
-
static async capeFromUsername(username) {
|
|
5722
|
-
return this.usernameToUuid(username).then((uuid) => {
|
|
5723
|
-
if (uuid) {
|
|
5724
|
-
return this.capeFromUuid(uuid);
|
|
5725
|
-
}
|
|
5726
|
-
return void 0;
|
|
5727
|
-
});
|
|
5728
|
-
}
|
|
5729
|
-
static async capeFromCapesDev(uuid, capeType = "minecraft") {
|
|
5730
|
-
return this.getCapesDev(uuid, capeType).then((cape) => {
|
|
5731
|
-
if (cape) {
|
|
5732
|
-
return cape == null ? void 0 : cape.stillImageUrl;
|
|
5733
|
-
}
|
|
5734
|
-
return void 0;
|
|
5735
|
-
});
|
|
5736
|
-
}
|
|
5737
|
-
//</editor-fold>
|
|
5738
|
-
//<editor-fold desc="Helpers">
|
|
5739
|
-
static async usernameToUuid(username) {
|
|
5740
|
-
return this.usernameToUuidSkinProxy(username);
|
|
5741
|
-
}
|
|
5742
|
-
static async usernameToUuidSkinProxy(username) {
|
|
5743
|
-
return Requests.genericRequest({
|
|
5744
|
-
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
5745
|
-
url: "/uuid/" + username
|
|
5746
|
-
}).then((res) => {
|
|
5747
|
-
if (res.status === 200) {
|
|
5748
|
-
return res.data["id"];
|
|
5749
|
-
}
|
|
5750
|
-
return void 0;
|
|
5751
|
-
}).catch((err) => {
|
|
5752
|
-
console.warn(err);
|
|
5753
|
-
return void 0;
|
|
5754
|
-
});
|
|
5755
|
-
}
|
|
5756
|
-
static async usernameToUuidMineTools(username) {
|
|
5757
|
-
return Requests.genericRequest({
|
|
5758
|
-
baseURL: "https://api.minetools.eu",
|
|
5759
|
-
url: "/uuid/" + username
|
|
5760
|
-
}).then((res) => {
|
|
5761
|
-
if (res.status === 200) {
|
|
5762
|
-
return res.data["id"];
|
|
5763
|
-
}
|
|
5764
|
-
return void 0;
|
|
5765
|
-
}).catch((err) => {
|
|
5766
|
-
console.warn(err);
|
|
5767
|
-
return void 0;
|
|
5768
|
-
});
|
|
5769
|
-
}
|
|
5770
|
-
static async getProfileFromMinetools(uuid) {
|
|
5771
|
-
return Requests.genericRequest({
|
|
5772
|
-
baseURL: "https://api.minetools.eu",
|
|
5773
|
-
url: "/profile/" + uuid
|
|
5774
|
-
}).then((res) => {
|
|
5775
|
-
if (res.status === 200) {
|
|
5776
|
-
return res.data;
|
|
5777
|
-
}
|
|
5778
|
-
});
|
|
5779
|
-
}
|
|
5780
|
-
static async getMineSkin(mineskinId) {
|
|
5781
|
-
return Requests.genericRequest({
|
|
5782
|
-
baseURL: "https://api.mineskin.org",
|
|
5783
|
-
url: "/get/uuid/" + mineskinId
|
|
5784
|
-
}).then((res) => {
|
|
5785
|
-
if (res.status === 200) {
|
|
5786
|
-
return res.data;
|
|
5787
|
-
}
|
|
5788
|
-
return void 0;
|
|
5789
|
-
}).catch((err) => {
|
|
5790
|
-
console.warn(err);
|
|
5791
|
-
return void 0;
|
|
5792
|
-
});
|
|
5793
|
-
}
|
|
5794
|
-
static async getCapesDev(uuid, type = "all") {
|
|
5795
|
-
return Requests.genericRequest({
|
|
5796
|
-
baseURL: "https://api.capes.dev",
|
|
5797
|
-
url: "/load/" + uuid + "/" + type
|
|
5798
|
-
}).then((res) => {
|
|
5799
|
-
if (res.status === 200) {
|
|
5800
|
-
return res.data;
|
|
5801
|
-
}
|
|
5802
|
-
return void 0;
|
|
5803
|
-
}).catch((err) => {
|
|
5804
|
-
console.warn(err);
|
|
5805
|
-
return void 0;
|
|
5806
|
-
});
|
|
5807
|
-
}
|
|
5808
|
-
static getCrafatarSkinUrl(uuid) {
|
|
5809
|
-
return "https://crafatar.com/skins/" + uuid;
|
|
5810
|
-
}
|
|
5811
|
-
static getCrafatarCapeUrl(uuid) {
|
|
5812
|
-
return "https://crafatar.com/capes/" + uuid;
|
|
5813
|
-
}
|
|
5814
|
-
static getMcHeadsSkinUrl(uuid) {
|
|
5815
|
-
return "https://mc-heads.net/skin/" + uuid;
|
|
5816
|
-
}
|
|
5817
|
-
static getMineSkinPlayerSkinUrl(uuid) {
|
|
5818
|
-
return "https://mineskin.org/skin/player/" + uuid;
|
|
5819
|
-
}
|
|
5820
|
-
static getSkinProxySkinUrl(uuid) {
|
|
5821
|
-
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
5822
|
-
}
|
|
5823
|
-
static getSkinProxyCapeUrl(uuid) {
|
|
5824
|
-
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
5825
|
-
}
|
|
5826
|
-
//</editor-fold>
|
|
5827
|
-
};
|
|
5629
|
+
}
|
|
5630
|
+
|
|
5631
|
+
// src/renderer/Renderer.ts
|
|
5632
|
+
import { AxesHelper as AxesHelper3, GridHelper, OrthographicCamera, PCFSoftShadowMap, PerspectiveCamera, SRGBColorSpace as SRGBColorSpace3, Vector3 as Vector39, WebGLRenderer } from "three";
|
|
5633
|
+
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
5634
|
+
import Stats from "stats.js";
|
|
5635
|
+
import { EffectComposer, RenderPass } from "postprocessing";
|
|
5828
5636
|
|
|
5829
5637
|
// src/three/OrbitControls.js
|
|
5830
5638
|
import {
|
|
5831
|
-
EventDispatcher
|
|
5639
|
+
EventDispatcher,
|
|
5832
5640
|
MOUSE,
|
|
5833
5641
|
Quaternion as Quaternion3,
|
|
5834
5642
|
Spherical,
|
|
@@ -5839,7 +5647,7 @@ import {
|
|
|
5839
5647
|
var _changeEvent = { type: "change" };
|
|
5840
5648
|
var _startEvent = { type: "start" };
|
|
5841
5649
|
var _endEvent = { type: "end" };
|
|
5842
|
-
var OrbitControls = class extends
|
|
5650
|
+
var OrbitControls = class extends EventDispatcher {
|
|
5843
5651
|
constructor(object, domElement) {
|
|
5844
5652
|
super();
|
|
5845
5653
|
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
@@ -6425,62 +6233,568 @@ var OrbitControls = class extends EventDispatcher2 {
|
|
|
6425
6233
|
state = STATE.NONE;
|
|
6426
6234
|
}
|
|
6427
6235
|
}
|
|
6428
|
-
function onTouchEnd(event) {
|
|
6429
|
-
handleTouchEnd(event);
|
|
6430
|
-
scope.dispatchEvent(_endEvent);
|
|
6431
|
-
state = STATE.NONE;
|
|
6236
|
+
function onTouchEnd(event) {
|
|
6237
|
+
handleTouchEnd(event);
|
|
6238
|
+
scope.dispatchEvent(_endEvent);
|
|
6239
|
+
state = STATE.NONE;
|
|
6240
|
+
}
|
|
6241
|
+
function onContextMenu(event) {
|
|
6242
|
+
if (scope.enabled === false) return;
|
|
6243
|
+
event.preventDefault();
|
|
6244
|
+
}
|
|
6245
|
+
function addPointer(event) {
|
|
6246
|
+
pointers.push(event);
|
|
6247
|
+
}
|
|
6248
|
+
function removePointer(event) {
|
|
6249
|
+
delete pointerPositions[event.pointerId];
|
|
6250
|
+
for (let i = 0; i < pointers.length; i++) {
|
|
6251
|
+
if (pointers[i].pointerId == event.pointerId) {
|
|
6252
|
+
pointers.splice(i, 1);
|
|
6253
|
+
return;
|
|
6254
|
+
}
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
function trackPointer(event) {
|
|
6258
|
+
let position = pointerPositions[event.pointerId];
|
|
6259
|
+
if (position === void 0) {
|
|
6260
|
+
position = new Vector23();
|
|
6261
|
+
pointerPositions[event.pointerId] = position;
|
|
6262
|
+
}
|
|
6263
|
+
position.set(event.pageX, event.pageY);
|
|
6264
|
+
}
|
|
6265
|
+
function getSecondPointerPosition(event) {
|
|
6266
|
+
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
6267
|
+
return pointerPositions[pointer.pointerId];
|
|
6268
|
+
}
|
|
6269
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6270
|
+
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6271
|
+
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6272
|
+
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6273
|
+
this.update();
|
|
6274
|
+
}
|
|
6275
|
+
};
|
|
6276
|
+
var MapControls = class extends OrbitControls {
|
|
6277
|
+
constructor(object, domElement) {
|
|
6278
|
+
super(object, domElement);
|
|
6279
|
+
this.screenSpacePanning = false;
|
|
6280
|
+
this.mouseButtons.LEFT = MOUSE.PAN;
|
|
6281
|
+
this.mouseButtons.RIGHT = MOUSE.ROTATE;
|
|
6282
|
+
this.touches.ONE = TOUCH.PAN;
|
|
6283
|
+
this.touches.TWO = TOUCH.DOLLY_ROTATE;
|
|
6284
|
+
}
|
|
6285
|
+
};
|
|
6286
|
+
|
|
6287
|
+
// src/renderer/Renderer.ts
|
|
6288
|
+
var Renderer = class _Renderer {
|
|
6289
|
+
constructor(options) {
|
|
6290
|
+
this._dirty = true;
|
|
6291
|
+
this._resizeListener = void 0;
|
|
6292
|
+
this._disposed = false;
|
|
6293
|
+
this._debugHelpers = [];
|
|
6294
|
+
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
6295
|
+
this._changeListener = () => {
|
|
6296
|
+
this._dirty = true;
|
|
6297
|
+
};
|
|
6298
|
+
this.options = (0, import_ts_deepmerge9.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
6299
|
+
this._animationLoop = this.animate.bind(this);
|
|
6300
|
+
this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
6301
|
+
this._scene = this.createScene();
|
|
6302
|
+
this._camera = this.createCamera();
|
|
6303
|
+
this._renderer = this.createRenderer();
|
|
6304
|
+
this._composer = this.createComposer();
|
|
6305
|
+
if (this.options.render.stats) {
|
|
6306
|
+
this._stats = new Stats();
|
|
6307
|
+
document.body.appendChild(this._stats.dom);
|
|
6308
|
+
}
|
|
6309
|
+
this.init();
|
|
6310
|
+
this._controls = this.createControls();
|
|
6311
|
+
}
|
|
6312
|
+
static {
|
|
6313
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
|
|
6314
|
+
camera: {
|
|
6315
|
+
type: "perspective",
|
|
6316
|
+
near: 1,
|
|
6317
|
+
far: 5e3,
|
|
6318
|
+
perspective: {
|
|
6319
|
+
aspect: void 0,
|
|
6320
|
+
fov: 50
|
|
6321
|
+
},
|
|
6322
|
+
orthographic: {
|
|
6323
|
+
left: void 0,
|
|
6324
|
+
right: void 0,
|
|
6325
|
+
top: void 0,
|
|
6326
|
+
bottom: void 0
|
|
6327
|
+
},
|
|
6328
|
+
position: new Vector39(50, 50, 50),
|
|
6329
|
+
lookingAt: new Vector39(0, 0, 0)
|
|
6330
|
+
},
|
|
6331
|
+
render: {
|
|
6332
|
+
fpsLimit: 60,
|
|
6333
|
+
stats: false,
|
|
6334
|
+
antialias: true,
|
|
6335
|
+
shade: true,
|
|
6336
|
+
autoResize: true,
|
|
6337
|
+
renderAlways: false
|
|
6338
|
+
},
|
|
6339
|
+
composer: {
|
|
6340
|
+
enabled: true
|
|
6341
|
+
},
|
|
6342
|
+
controls: {
|
|
6343
|
+
enabled: false
|
|
6344
|
+
},
|
|
6345
|
+
debug: {
|
|
6346
|
+
grid: false,
|
|
6347
|
+
axes: false
|
|
6348
|
+
}
|
|
6349
|
+
});
|
|
6350
|
+
}
|
|
6351
|
+
//<editor-fold desc="INIT">
|
|
6352
|
+
createScene() {
|
|
6353
|
+
return new MineRenderScene();
|
|
6354
|
+
}
|
|
6355
|
+
createCamera() {
|
|
6356
|
+
switch (this.options.camera.type) {
|
|
6357
|
+
case "perspective":
|
|
6358
|
+
default:
|
|
6359
|
+
return new PerspectiveCamera(
|
|
6360
|
+
this.options.camera.perspective.fov,
|
|
6361
|
+
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
6362
|
+
this.options.camera.near,
|
|
6363
|
+
this.options.camera.far
|
|
6364
|
+
);
|
|
6365
|
+
case "orthographic":
|
|
6366
|
+
return new OrthographicCamera(
|
|
6367
|
+
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
6368
|
+
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
6369
|
+
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
6370
|
+
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
6371
|
+
this.options.camera.near,
|
|
6372
|
+
this.options.camera.far
|
|
6373
|
+
);
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
createRenderer() {
|
|
6377
|
+
const renderer = new WebGLRenderer({
|
|
6378
|
+
antialias: this.options.render.antialias,
|
|
6379
|
+
alpha: true,
|
|
6380
|
+
powerPreference: "high-performance",
|
|
6381
|
+
depth: true
|
|
6382
|
+
});
|
|
6383
|
+
renderer.setClearColor(0, 0);
|
|
6384
|
+
renderer.shadowMap.enabled = true;
|
|
6385
|
+
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
6386
|
+
renderer.outputColorSpace = SRGBColorSpace3;
|
|
6387
|
+
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
6388
|
+
return renderer;
|
|
6389
|
+
}
|
|
6390
|
+
createComposer() {
|
|
6391
|
+
if (!this.options.composer.enabled) return void 0;
|
|
6392
|
+
const composer = new EffectComposer(this.renderer);
|
|
6393
|
+
composer.setSize(this.viewWidth, this.viewHeight);
|
|
6394
|
+
composer.addPass(new RenderPass(this.scene, this.camera));
|
|
6395
|
+
return composer;
|
|
6396
|
+
}
|
|
6397
|
+
createControls() {
|
|
6398
|
+
if (!this.options.controls?.enabled) return void 0;
|
|
6399
|
+
const position = this.camera.position.clone();
|
|
6400
|
+
const controls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
6401
|
+
this.camera.position.copy(position);
|
|
6402
|
+
const target = this.options.camera.lookingAt;
|
|
6403
|
+
if (isVector3(target)) {
|
|
6404
|
+
controls.target.copy(target);
|
|
6405
|
+
} else if (isTripleArray(target)) {
|
|
6406
|
+
controls.target.set(target[0], target[1], target[2]);
|
|
6407
|
+
}
|
|
6408
|
+
controls.update();
|
|
6409
|
+
controls.saveState();
|
|
6410
|
+
this.registerEventDispatcher(controls);
|
|
6411
|
+
return controls;
|
|
6412
|
+
}
|
|
6413
|
+
//</editor-fold>
|
|
6414
|
+
init() {
|
|
6415
|
+
if (this._disposed) return;
|
|
6416
|
+
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
6417
|
+
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
6418
|
+
}
|
|
6419
|
+
if (this.options.debug.grid) {
|
|
6420
|
+
const gridHelper = new GridHelper(128, 16);
|
|
6421
|
+
this._debugHelpers.push(gridHelper);
|
|
6422
|
+
this.scene.add(gridHelper);
|
|
6423
|
+
const gridHelper2 = new GridHelper(128, 16);
|
|
6424
|
+
this._debugHelpers.push(gridHelper2);
|
|
6425
|
+
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
6426
|
+
this.scene.add(gridHelper2);
|
|
6427
|
+
const gridHelper3 = new GridHelper(128, 16);
|
|
6428
|
+
this._debugHelpers.push(gridHelper3);
|
|
6429
|
+
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
6430
|
+
this.scene.add(gridHelper3);
|
|
6431
|
+
}
|
|
6432
|
+
if (this.options.debug.axes) {
|
|
6433
|
+
const axesHelper = new AxesHelper3(64);
|
|
6434
|
+
this._debugHelpers.push(axesHelper);
|
|
6435
|
+
this.scene.add(axesHelper);
|
|
6436
|
+
}
|
|
6437
|
+
if (this.options.camera.position) {
|
|
6438
|
+
if (isVector3(this.options.camera.position)) {
|
|
6439
|
+
this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
|
|
6440
|
+
} else if (isTripleArray(this.options.camera.position)) {
|
|
6441
|
+
this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
if (this.options.camera.lookingAt) {
|
|
6445
|
+
if (isVector3(this.options.camera.lookingAt)) {
|
|
6446
|
+
this.camera.lookAt(this.options.camera.lookingAt);
|
|
6447
|
+
} else if (isTripleArray(this.options.camera.lookingAt)) {
|
|
6448
|
+
this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
|
|
6449
|
+
}
|
|
6450
|
+
}
|
|
6451
|
+
if (this.options.render.autoResize && !this._resizeListener) {
|
|
6452
|
+
this._resizeListener = () => {
|
|
6453
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6454
|
+
};
|
|
6455
|
+
window.addEventListener("resize", this._resizeListener);
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
get element() {
|
|
6459
|
+
return this._element;
|
|
6460
|
+
}
|
|
6461
|
+
appendTo(element) {
|
|
6462
|
+
if (this._disposed) return;
|
|
6463
|
+
this._element = element;
|
|
6464
|
+
this._element.appendChild(this.renderer.domElement);
|
|
6465
|
+
if (this.viewWidth == 0) {
|
|
6466
|
+
console.warn("0 element width");
|
|
6467
|
+
}
|
|
6468
|
+
if (this.viewHeight == 0) {
|
|
6469
|
+
console.warn("0 element height");
|
|
6470
|
+
}
|
|
6471
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6472
|
+
}
|
|
6473
|
+
/**
|
|
6474
|
+
* Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
|
|
6475
|
+
* The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
|
|
6476
|
+
*/
|
|
6477
|
+
registerEventDispatcher(dispatcher, changeEvent2 = "change") {
|
|
6478
|
+
if (this._disposed) return;
|
|
6479
|
+
let events = this._eventDispatchers.get(dispatcher);
|
|
6480
|
+
if (!events) {
|
|
6481
|
+
events = /* @__PURE__ */ new Set();
|
|
6482
|
+
this._eventDispatchers.set(dispatcher, events);
|
|
6483
|
+
}
|
|
6484
|
+
if (events.has(changeEvent2)) return;
|
|
6485
|
+
events.add(changeEvent2);
|
|
6486
|
+
dispatcher.addEventListener(changeEvent2, this._changeListener);
|
|
6487
|
+
}
|
|
6488
|
+
resize(width, height) {
|
|
6489
|
+
if (this._disposed) return;
|
|
6490
|
+
if (isPerspectiveCamera(this.camera)) {
|
|
6491
|
+
this.camera.aspect = width / height;
|
|
6492
|
+
this.camera.updateProjectionMatrix();
|
|
6493
|
+
} else if (isOrthographicCamera(this.camera)) {
|
|
6494
|
+
this.camera.left = width / -2;
|
|
6495
|
+
this.camera.right = width / 2;
|
|
6496
|
+
this.camera.top = height / 2;
|
|
6497
|
+
this.camera.bottom = height / -2;
|
|
6498
|
+
this.camera.updateProjectionMatrix();
|
|
6499
|
+
}
|
|
6500
|
+
this.renderer.setSize(width, height);
|
|
6501
|
+
this.composer?.setSize(width, height);
|
|
6502
|
+
this._dirty = true;
|
|
6503
|
+
}
|
|
6504
|
+
//<editor-fold desc="RENDER">
|
|
6505
|
+
get dirty() {
|
|
6506
|
+
return this._dirty || this.scene.dirty;
|
|
6507
|
+
}
|
|
6508
|
+
set dirty(dirty) {
|
|
6509
|
+
this._dirty = dirty;
|
|
6510
|
+
this.scene.dirty = dirty;
|
|
6511
|
+
}
|
|
6512
|
+
start() {
|
|
6513
|
+
if (this._disposed) return;
|
|
6514
|
+
this.stop();
|
|
6515
|
+
this.renderer.setAnimationLoop(this._animationLoop);
|
|
6516
|
+
}
|
|
6517
|
+
stop() {
|
|
6518
|
+
if (this._disposed) return;
|
|
6519
|
+
this.renderer.setAnimationLoop(null);
|
|
6520
|
+
this._nextFrameTime = void 0;
|
|
6521
|
+
}
|
|
6522
|
+
/**
|
|
6523
|
+
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
6524
|
+
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
6525
|
+
* controls must be managed by their owners.
|
|
6526
|
+
*/
|
|
6527
|
+
dispose() {
|
|
6528
|
+
if (this._disposed) return;
|
|
6529
|
+
this.stop();
|
|
6530
|
+
this._disposed = true;
|
|
6531
|
+
if (this._resizeListener) {
|
|
6532
|
+
window.removeEventListener("resize", this._resizeListener);
|
|
6533
|
+
this._resizeListener = void 0;
|
|
6534
|
+
}
|
|
6535
|
+
for (const [dispatcher, events] of this._eventDispatchers) {
|
|
6536
|
+
for (const event of events) {
|
|
6537
|
+
dispatcher.removeEventListener(event, this._changeListener);
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
this._eventDispatchers.clear();
|
|
6541
|
+
this._stats?.dom.remove();
|
|
6542
|
+
this._stats = void 0;
|
|
6543
|
+
this.renderer.domElement.remove();
|
|
6544
|
+
this._element = void 0;
|
|
6545
|
+
if (this._controls) {
|
|
6546
|
+
const controls = this._controls;
|
|
6547
|
+
this._controls = void 0;
|
|
6548
|
+
controls.enabled = false;
|
|
6549
|
+
controls.dispose();
|
|
6432
6550
|
}
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6551
|
+
this.scene.clear();
|
|
6552
|
+
for (const helper of this._debugHelpers) {
|
|
6553
|
+
helper.geometry.dispose();
|
|
6554
|
+
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
6555
|
+
for (const material of materials) {
|
|
6556
|
+
material.dispose();
|
|
6557
|
+
}
|
|
6436
6558
|
}
|
|
6437
|
-
|
|
6438
|
-
|
|
6559
|
+
this._debugHelpers.length = 0;
|
|
6560
|
+
this.composer?.dispose();
|
|
6561
|
+
this.renderer.dispose();
|
|
6562
|
+
this.renderer.forceContextLoss();
|
|
6563
|
+
}
|
|
6564
|
+
animate(t = performance.now()) {
|
|
6565
|
+
if (this._disposed) return;
|
|
6566
|
+
if (this._controls?.enabled) {
|
|
6567
|
+
this._controls.update();
|
|
6439
6568
|
}
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
}
|
|
6569
|
+
if (this._disposed) return;
|
|
6570
|
+
if (!this.dirty && !this.options.render.renderAlways) return;
|
|
6571
|
+
const interval = this._frameInterval;
|
|
6572
|
+
if (interval) {
|
|
6573
|
+
const next = this._nextFrameTime;
|
|
6574
|
+
if (next !== void 0 && t + 0.1 < next) return;
|
|
6575
|
+
this._nextFrameTime = next !== void 0 && t - next < interval ? next + interval : t + interval;
|
|
6448
6576
|
}
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
if (position === void 0) {
|
|
6452
|
-
position = new Vector23();
|
|
6453
|
-
pointerPositions[event.pointerId] = position;
|
|
6454
|
-
}
|
|
6455
|
-
position.set(event.pageX, event.pageY);
|
|
6577
|
+
if (this._stats) {
|
|
6578
|
+
this._stats.begin();
|
|
6456
6579
|
}
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6580
|
+
if (this.options.composer.enabled && this.composer) {
|
|
6581
|
+
this.composer.render();
|
|
6582
|
+
} else {
|
|
6583
|
+
this.renderer.render(this.scene, this.camera);
|
|
6460
6584
|
}
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6585
|
+
this.dirty = false;
|
|
6586
|
+
if (this._stats) {
|
|
6587
|
+
this._stats.end();
|
|
6588
|
+
}
|
|
6589
|
+
}
|
|
6590
|
+
//</editor-fold>
|
|
6591
|
+
toImage() {
|
|
6592
|
+
return this.renderer.domElement.toDataURL();
|
|
6593
|
+
}
|
|
6594
|
+
///
|
|
6595
|
+
get attachedToBody() {
|
|
6596
|
+
return this.element === document.body;
|
|
6466
6597
|
}
|
|
6598
|
+
get viewWidth() {
|
|
6599
|
+
return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
|
|
6600
|
+
}
|
|
6601
|
+
get viewHeight() {
|
|
6602
|
+
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
6603
|
+
}
|
|
6604
|
+
get scene() {
|
|
6605
|
+
return this._scene;
|
|
6606
|
+
}
|
|
6607
|
+
get camera() {
|
|
6608
|
+
return this._camera;
|
|
6609
|
+
}
|
|
6610
|
+
get renderer() {
|
|
6611
|
+
return this._renderer;
|
|
6612
|
+
}
|
|
6613
|
+
get composer() {
|
|
6614
|
+
return this._composer;
|
|
6615
|
+
}
|
|
6616
|
+
/** Renderer-owned controls, or undefined when disabled at construction or after disposal. */
|
|
6617
|
+
get controls() {
|
|
6618
|
+
return this._controls;
|
|
6619
|
+
}
|
|
6620
|
+
///
|
|
6467
6621
|
};
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6622
|
+
|
|
6623
|
+
// src/skin/Skins.ts
|
|
6624
|
+
var Skins = class {
|
|
6625
|
+
//<editor-fold desc="Skins">
|
|
6626
|
+
static async fromUuidOrUsername(uuidOrUsername) {
|
|
6627
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6628
|
+
return this.fromUuid(uuidOrUsername);
|
|
6629
|
+
}
|
|
6630
|
+
return this.fromUsername(uuidOrUsername);
|
|
6631
|
+
}
|
|
6632
|
+
static async fromUuid(uuid) {
|
|
6633
|
+
return this.getMcProxySkinUrl(uuid);
|
|
6634
|
+
}
|
|
6635
|
+
static async fromUsername(username) {
|
|
6636
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6637
|
+
if (uuid) {
|
|
6638
|
+
return this.fromUuid(uuid);
|
|
6639
|
+
}
|
|
6640
|
+
return void 0;
|
|
6641
|
+
});
|
|
6642
|
+
}
|
|
6643
|
+
static async fromMineSkin(mineskinId) {
|
|
6644
|
+
return this.getMineSkin(mineskinId).then((mineskin) => {
|
|
6645
|
+
if (mineskin) {
|
|
6646
|
+
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
6647
|
+
}
|
|
6648
|
+
return void 0;
|
|
6649
|
+
});
|
|
6650
|
+
}
|
|
6651
|
+
//</editor-fold>
|
|
6652
|
+
//<editor-fold desc="Capes">
|
|
6653
|
+
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
6654
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6655
|
+
return this.capeFromUuid(uuidOrUsername);
|
|
6656
|
+
}
|
|
6657
|
+
return this.capeFromUsername(uuidOrUsername);
|
|
6658
|
+
}
|
|
6659
|
+
static async capeFromUuid(uuid) {
|
|
6660
|
+
return this.getMcProxyCapeUrl(uuid);
|
|
6661
|
+
}
|
|
6662
|
+
static async capeFromUsername(username) {
|
|
6663
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6664
|
+
if (uuid) {
|
|
6665
|
+
return this.capeFromUuid(uuid);
|
|
6666
|
+
}
|
|
6667
|
+
return void 0;
|
|
6668
|
+
});
|
|
6669
|
+
}
|
|
6670
|
+
static async capeFromCapesDev(uuid, capeType = "minecraft") {
|
|
6671
|
+
return this.getCapesDev(uuid, capeType).then((cape) => {
|
|
6672
|
+
if (cape) {
|
|
6673
|
+
return cape?.stillImageUrl;
|
|
6674
|
+
}
|
|
6675
|
+
return void 0;
|
|
6676
|
+
});
|
|
6677
|
+
}
|
|
6678
|
+
//</editor-fold>
|
|
6679
|
+
//<editor-fold desc="Helpers">
|
|
6680
|
+
static async usernameToUuid(username) {
|
|
6681
|
+
return this.usernameToUuidMcProxy(username);
|
|
6682
|
+
}
|
|
6683
|
+
static async usernameToUuidMcProxy(username) {
|
|
6684
|
+
return Requests.genericRequest({
|
|
6685
|
+
baseURL: "https://mcproxy.dev",
|
|
6686
|
+
url: "/uuid/" + username
|
|
6687
|
+
}).then((res) => {
|
|
6688
|
+
if (res.status === 200) {
|
|
6689
|
+
return res.data["data"]["id"];
|
|
6690
|
+
}
|
|
6691
|
+
return void 0;
|
|
6692
|
+
}).catch((err) => {
|
|
6693
|
+
console.warn(err);
|
|
6694
|
+
return void 0;
|
|
6695
|
+
});
|
|
6696
|
+
}
|
|
6697
|
+
/** @deprecated **/
|
|
6698
|
+
static async usernameToUuidSkinProxy(username) {
|
|
6699
|
+
return Requests.genericRequest({
|
|
6700
|
+
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
6701
|
+
url: "/uuid/" + username
|
|
6702
|
+
}).then((res) => {
|
|
6703
|
+
if (res.status === 200) {
|
|
6704
|
+
return res.data["id"];
|
|
6705
|
+
}
|
|
6706
|
+
return void 0;
|
|
6707
|
+
}).catch((err) => {
|
|
6708
|
+
console.warn(err);
|
|
6709
|
+
return void 0;
|
|
6710
|
+
});
|
|
6711
|
+
}
|
|
6712
|
+
static async usernameToUuidMineTools(username) {
|
|
6713
|
+
return Requests.genericRequest({
|
|
6714
|
+
baseURL: "https://api.minetools.eu",
|
|
6715
|
+
url: "/uuid/" + username
|
|
6716
|
+
}).then((res) => {
|
|
6717
|
+
if (res.status === 200) {
|
|
6718
|
+
return res.data["id"];
|
|
6719
|
+
}
|
|
6720
|
+
return void 0;
|
|
6721
|
+
}).catch((err) => {
|
|
6722
|
+
console.warn(err);
|
|
6723
|
+
return void 0;
|
|
6724
|
+
});
|
|
6725
|
+
}
|
|
6726
|
+
static async getProfileFromMinetools(uuid) {
|
|
6727
|
+
return Requests.genericRequest({
|
|
6728
|
+
baseURL: "https://api.minetools.eu",
|
|
6729
|
+
url: "/profile/" + uuid
|
|
6730
|
+
}).then((res) => {
|
|
6731
|
+
if (res.status === 200) {
|
|
6732
|
+
return res.data;
|
|
6733
|
+
}
|
|
6734
|
+
});
|
|
6735
|
+
}
|
|
6736
|
+
static async getMineSkin(mineskinId) {
|
|
6737
|
+
return Requests.genericRequest({
|
|
6738
|
+
baseURL: "https://api.mineskin.org",
|
|
6739
|
+
url: "/get/uuid/" + mineskinId
|
|
6740
|
+
}).then((res) => {
|
|
6741
|
+
if (res.status === 200) {
|
|
6742
|
+
return res.data;
|
|
6743
|
+
}
|
|
6744
|
+
return void 0;
|
|
6745
|
+
}).catch((err) => {
|
|
6746
|
+
console.warn(err);
|
|
6747
|
+
return void 0;
|
|
6748
|
+
});
|
|
6749
|
+
}
|
|
6750
|
+
static async getCapesDev(uuid, type = "all") {
|
|
6751
|
+
return Requests.genericRequest({
|
|
6752
|
+
baseURL: "https://api.capes.dev",
|
|
6753
|
+
url: "/load/" + uuid + "/" + type
|
|
6754
|
+
}).then((res) => {
|
|
6755
|
+
if (res.status === 200) {
|
|
6756
|
+
return res.data;
|
|
6757
|
+
}
|
|
6758
|
+
return void 0;
|
|
6759
|
+
}).catch((err) => {
|
|
6760
|
+
console.warn(err);
|
|
6761
|
+
return void 0;
|
|
6762
|
+
});
|
|
6763
|
+
}
|
|
6764
|
+
static getCrafatarSkinUrl(uuid) {
|
|
6765
|
+
return "https://crafatar.com/skins/" + uuid;
|
|
6766
|
+
}
|
|
6767
|
+
static getCrafatarCapeUrl(uuid) {
|
|
6768
|
+
return "https://crafatar.com/capes/" + uuid;
|
|
6769
|
+
}
|
|
6770
|
+
static getMcHeadsSkinUrl(uuid) {
|
|
6771
|
+
return "https://mc-heads.net/skin/" + uuid;
|
|
6772
|
+
}
|
|
6773
|
+
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6774
|
+
return "https://mineskin.org/skin/player/" + uuid;
|
|
6775
|
+
}
|
|
6776
|
+
/** @deprecated **/
|
|
6777
|
+
static getSkinProxySkinUrl(uuid) {
|
|
6778
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6779
|
+
}
|
|
6780
|
+
/** @deprecated **/
|
|
6781
|
+
static getSkinProxyCapeUrl(uuid) {
|
|
6782
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6783
|
+
}
|
|
6784
|
+
static getMcProxySkinUrl(uuid) {
|
|
6785
|
+
return "https://mcproxy.dev/skin/" + uuid;
|
|
6476
6786
|
}
|
|
6787
|
+
static getMcProxyCapeUrl(uuid) {
|
|
6788
|
+
return "https://mcproxy.dev/cape/" + uuid;
|
|
6789
|
+
}
|
|
6790
|
+
//</editor-fold>
|
|
6477
6791
|
};
|
|
6478
6792
|
|
|
6479
6793
|
// src/world/Chunk.ts
|
|
6480
|
-
import { Box3 as Box32, Object3D as Object3D6, Vector3 as
|
|
6794
|
+
import { Box3 as Box32, Object3D as Object3D6, Vector3 as Vector311 } from "three";
|
|
6481
6795
|
|
|
6482
6796
|
// src/world/MineRenderWorld.ts
|
|
6483
|
-
import { Vector3 as
|
|
6797
|
+
import { Vector3 as Vector310 } from "three";
|
|
6484
6798
|
var MineRenderWorld = class {
|
|
6485
6799
|
constructor(scene) {
|
|
6486
6800
|
this._size = 4;
|
|
@@ -6491,10 +6805,10 @@ var MineRenderWorld = class {
|
|
|
6491
6805
|
}
|
|
6492
6806
|
getBlockAt(posOrX, y, z) {
|
|
6493
6807
|
if (typeof posOrX == "number") {
|
|
6494
|
-
return this.getBlockAt(new
|
|
6808
|
+
return this.getBlockAt(new Vector310(posOrX, y, z));
|
|
6495
6809
|
}
|
|
6496
6810
|
if (isTripleArray(posOrX)) {
|
|
6497
|
-
return this.getBlockAt(new
|
|
6811
|
+
return this.getBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]));
|
|
6498
6812
|
}
|
|
6499
6813
|
const chunk = this.getChunkAt(posOrX);
|
|
6500
6814
|
if (typeof chunk === "undefined") {
|
|
@@ -6505,10 +6819,10 @@ var MineRenderWorld = class {
|
|
|
6505
6819
|
}
|
|
6506
6820
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
6507
6821
|
if (typeof posOrX == "number") {
|
|
6508
|
-
return this.setBlockAt(new
|
|
6822
|
+
return this.setBlockAt(new Vector310(posOrX, yOrBlock, z), block);
|
|
6509
6823
|
}
|
|
6510
6824
|
if (isTripleArray(posOrX)) {
|
|
6511
|
-
return this.setBlockAt(new
|
|
6825
|
+
return this.setBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
6512
6826
|
}
|
|
6513
6827
|
this.validatePosBounds(posOrX);
|
|
6514
6828
|
const chunk = this.getOrCreateChunkAt(posOrX);
|
|
@@ -6536,7 +6850,7 @@ var MineRenderWorld = class {
|
|
|
6536
6850
|
console.log("CHUNKS", this._chunks);
|
|
6537
6851
|
for (let chunk of this._chunks.values()) {
|
|
6538
6852
|
console.log("dispose chunk", chunk);
|
|
6539
|
-
await
|
|
6853
|
+
await chunk?.dispose();
|
|
6540
6854
|
}
|
|
6541
6855
|
this._chunks.clear();
|
|
6542
6856
|
}
|
|
@@ -6554,14 +6868,14 @@ var MineRenderWorld = class {
|
|
|
6554
6868
|
return this._chunks[index];
|
|
6555
6869
|
}
|
|
6556
6870
|
static worldToScenePosition(pos) {
|
|
6557
|
-
return new
|
|
6871
|
+
return new Vector310(
|
|
6558
6872
|
pos.x * 16,
|
|
6559
6873
|
pos.y * 16,
|
|
6560
6874
|
pos.z * 16
|
|
6561
6875
|
);
|
|
6562
6876
|
}
|
|
6563
6877
|
static sceneToWorldPosition(pos) {
|
|
6564
|
-
return new
|
|
6878
|
+
return new Vector310(
|
|
6565
6879
|
pos.x / 16,
|
|
6566
6880
|
pos.y / 16,
|
|
6567
6881
|
pos.z / 16
|
|
@@ -6590,7 +6904,7 @@ var MineRenderWorld = class {
|
|
|
6590
6904
|
};
|
|
6591
6905
|
|
|
6592
6906
|
// src/world/Chunk.ts
|
|
6593
|
-
var
|
|
6907
|
+
var p11 = prefix("Chunk");
|
|
6594
6908
|
var Chunk = class _Chunk {
|
|
6595
6909
|
constructor(scene, x, y, z) {
|
|
6596
6910
|
this._blocks = [];
|
|
@@ -6603,7 +6917,7 @@ var Chunk = class _Chunk {
|
|
|
6603
6917
|
scene.add(anchor);
|
|
6604
6918
|
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
6605
6919
|
addBox3WireframeToObject(
|
|
6606
|
-
new Box32(new
|
|
6920
|
+
new Box32(new Vector311(0, 0, 0), new Vector311(256, 256, 256)),
|
|
6607
6921
|
anchor,
|
|
6608
6922
|
16776960,
|
|
6609
6923
|
4
|
|
@@ -6611,10 +6925,10 @@ var Chunk = class _Chunk {
|
|
|
6611
6925
|
}
|
|
6612
6926
|
getBlockAt(posOrX, y, z) {
|
|
6613
6927
|
if (typeof posOrX == "number") {
|
|
6614
|
-
return this.getBlockAt(new
|
|
6928
|
+
return this.getBlockAt(new Vector311(posOrX, y, z));
|
|
6615
6929
|
}
|
|
6616
6930
|
if (isTripleArray(posOrX)) {
|
|
6617
|
-
return this.getBlockAt(new
|
|
6931
|
+
return this.getBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]));
|
|
6618
6932
|
}
|
|
6619
6933
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
6620
6934
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
@@ -6622,10 +6936,10 @@ var Chunk = class _Chunk {
|
|
|
6622
6936
|
}
|
|
6623
6937
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
6624
6938
|
if (typeof posOrX == "number") {
|
|
6625
|
-
return this.setBlockAt(new
|
|
6939
|
+
return this.setBlockAt(new Vector311(posOrX, yOrBlock, z), block);
|
|
6626
6940
|
}
|
|
6627
6941
|
if (isTripleArray(posOrX)) {
|
|
6628
|
-
return this.setBlockAt(new
|
|
6942
|
+
return this.setBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
6629
6943
|
}
|
|
6630
6944
|
const worldPos = posOrX;
|
|
6631
6945
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -6642,7 +6956,7 @@ var Chunk = class _Chunk {
|
|
|
6642
6956
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
6643
6957
|
const current = this._blocks[index];
|
|
6644
6958
|
if (typeof current !== "undefined") {
|
|
6645
|
-
console.debug(
|
|
6959
|
+
console.debug(p11, "deleting existing block at", pos, worldPos, index);
|
|
6646
6960
|
current.object.removeFromScene();
|
|
6647
6961
|
delete this._blocks[index];
|
|
6648
6962
|
}
|
|
@@ -6671,7 +6985,7 @@ var Chunk = class _Chunk {
|
|
|
6671
6985
|
}
|
|
6672
6986
|
async clear() {
|
|
6673
6987
|
let promises = [];
|
|
6674
|
-
let pos = new
|
|
6988
|
+
let pos = new Vector311();
|
|
6675
6989
|
for (let x = 0; x < 16; x++) {
|
|
6676
6990
|
for (let z = 0; z < 16; z++) {
|
|
6677
6991
|
for (let y = 0; y < 16; y++) {
|
|
@@ -6690,14 +7004,14 @@ var Chunk = class _Chunk {
|
|
|
6690
7004
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
6691
7005
|
}
|
|
6692
7006
|
worldPosToChunkPos(pos) {
|
|
6693
|
-
return new
|
|
7007
|
+
return new Vector311(
|
|
6694
7008
|
pos.x - this.x * 16,
|
|
6695
7009
|
pos.y - this.y * 16,
|
|
6696
7010
|
pos.z - this.z * 16
|
|
6697
7011
|
);
|
|
6698
7012
|
}
|
|
6699
7013
|
chunkPosToWorldPos(pos) {
|
|
6700
|
-
return new
|
|
7014
|
+
return new Vector311(
|
|
6701
7015
|
this.x * 16 + pos.x,
|
|
6702
7016
|
this.y * 16 + pos.y,
|
|
6703
7017
|
this.z * 16 + pos.z
|
|
@@ -6708,6 +7022,7 @@ export {
|
|
|
6708
7022
|
AXES,
|
|
6709
7023
|
ArchiveAssetSource,
|
|
6710
7024
|
AssetKey,
|
|
7025
|
+
AssetLoadError,
|
|
6711
7026
|
AssetLoader,
|
|
6712
7027
|
AssetParser,
|
|
6713
7028
|
AssetSource,
|
|
@@ -6765,6 +7080,7 @@ export {
|
|
|
6765
7080
|
OrbitControls,
|
|
6766
7081
|
PersistentCache,
|
|
6767
7082
|
Renderer,
|
|
7083
|
+
RequestError,
|
|
6768
7084
|
Requests,
|
|
6769
7085
|
SKIN_PARTS,
|
|
6770
7086
|
SceneInspector,
|