minerender 2.1.0-alpha.2 → 2.1.0-alpha.21
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 +212 -141
- package/dist/browser/index.d.ts +212 -141
- package/dist/browser/index.js +2007 -1669
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1990 -1652
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +3789 -5036
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +211 -140
- package/dist/node/index.d.ts +211 -140
- package/dist/node/index.js +2034 -1624
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1660 -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,64 @@ 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.blockTintCache = _Caching.createAssetCache();
|
|
406
|
+
}
|
|
407
|
+
static {
|
|
408
|
+
this.entityModelsCache = _Caching.createAssetCache();
|
|
409
|
+
}
|
|
410
|
+
static createAssetCache() {
|
|
411
|
+
return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
412
|
+
}
|
|
361
413
|
/** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
|
|
362
414
|
static get all() {
|
|
363
415
|
return [
|
|
@@ -374,7 +426,11 @@ var Caching = class {
|
|
|
374
426
|
this.rawModelCache,
|
|
375
427
|
this.mergedModelCache,
|
|
376
428
|
this.modelTextureAtlasCache,
|
|
377
|
-
this.blockStateCache
|
|
429
|
+
this.blockStateCache,
|
|
430
|
+
this.listAssetCache,
|
|
431
|
+
this.defaultBlockStatesCache,
|
|
432
|
+
this.blockTintCache,
|
|
433
|
+
this.entityModelsCache
|
|
378
434
|
];
|
|
379
435
|
}
|
|
380
436
|
static clear() {
|
|
@@ -385,8 +441,8 @@ var Caching = class {
|
|
|
385
441
|
/**
|
|
386
442
|
* Clears every cache and stops its expiry timer.
|
|
387
443
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
444
|
+
* Expiry timers are unref'd in Node, so idle processes can exit without this cleanup.
|
|
445
|
+
* Use {@link shutdown} to also stop requests and the shared Ticker.
|
|
390
446
|
*/
|
|
391
447
|
static end() {
|
|
392
448
|
for (const cache of this.all) {
|
|
@@ -400,20 +456,6 @@ var Caching = class {
|
|
|
400
456
|
};
|
|
401
457
|
}
|
|
402
458
|
};
|
|
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
459
|
|
|
418
460
|
// src/Geometries.ts
|
|
419
461
|
var Geometries = class _Geometries {
|
|
@@ -441,6 +483,7 @@ import { CanvasTexture, Texture as Texture2 } from "three";
|
|
|
441
483
|
|
|
442
484
|
// src/texture/TextureLoader.ts
|
|
443
485
|
import { RGBAFormat, Texture } from "three";
|
|
486
|
+
import * as THREE from "three";
|
|
444
487
|
|
|
445
488
|
// src/canvas/CanvasCompat.ts
|
|
446
489
|
function createImage(width, height) {
|
|
@@ -451,9 +494,7 @@ function createCanvas2(width, height) {
|
|
|
451
494
|
}
|
|
452
495
|
|
|
453
496
|
// src/request/Requests.ts
|
|
454
|
-
import
|
|
455
|
-
import { JobQueue } from "jobqu";
|
|
456
|
-
import { Time as Time2 } from "@inventivetalent/time";
|
|
497
|
+
import { JobCancelledError, JobQueue } from "jobqu";
|
|
457
498
|
|
|
458
499
|
// src/util/log.ts
|
|
459
500
|
var Reset = "\x1B[0m";
|
|
@@ -463,198 +504,174 @@ function prefix(prefix2) {
|
|
|
463
504
|
return `${FgGreen}MR${BgBlack}${prefix2 ?? ""}${Reset}`;
|
|
464
505
|
}
|
|
465
506
|
|
|
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();
|
|
507
|
+
// src/request/Requests.ts
|
|
508
|
+
var p = prefix("Requests");
|
|
509
|
+
var RequestError = class extends Error {
|
|
510
|
+
constructor(message, response, cause) {
|
|
511
|
+
super(message);
|
|
512
|
+
this.response = response;
|
|
513
|
+
this.cause = cause;
|
|
514
|
+
this.name = "RequestError";
|
|
485
515
|
}
|
|
486
516
|
};
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
517
|
+
async function fetchRequest(config, defaultBaseURL) {
|
|
518
|
+
const { url, baseURL = defaultBaseURL, timeout = 5e3, responseType = "json", signal, ...options } = config;
|
|
519
|
+
const target = baseURL && !/^([a-z][a-z\d+.-]*:|\/\/)/i.test(url) ? `${baseURL.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}` : url;
|
|
520
|
+
const headers = new Headers(options.headers);
|
|
521
|
+
if (typeof window === "undefined" && !headers.has("User-Agent")) {
|
|
522
|
+
headers.set("User-Agent", "MineRender");
|
|
523
|
+
}
|
|
524
|
+
const attemptSignal = AbortSignal.any([
|
|
525
|
+
...signal ? [signal] : [],
|
|
526
|
+
...timeout === 0 ? [] : [AbortSignal.timeout(timeout)]
|
|
527
|
+
]);
|
|
528
|
+
const request = new Request(target, { ...options, headers, signal: attemptSignal });
|
|
529
|
+
attemptSignal.throwIfAborted();
|
|
530
|
+
try {
|
|
531
|
+
const response = await fetch(request);
|
|
532
|
+
const result = {
|
|
533
|
+
data: void 0,
|
|
534
|
+
status: response.status,
|
|
535
|
+
statusText: response.statusText,
|
|
536
|
+
headers: response.headers,
|
|
537
|
+
url: response.url
|
|
538
|
+
};
|
|
539
|
+
if (!response.ok) {
|
|
540
|
+
await response.body?.cancel().catch(() => {
|
|
541
|
+
});
|
|
542
|
+
throw new RequestError(`Request failed with status ${response.status}`, result);
|
|
511
543
|
}
|
|
544
|
+
const emptyBody = request.method === "HEAD" || response.status === 204 || response.status === 205;
|
|
545
|
+
const data = responseType === "arraybuffer" ? await response.arrayBuffer() : emptyBody || response.body === null ? void 0 : await response.json();
|
|
546
|
+
return { ...result, data };
|
|
547
|
+
} catch (error) {
|
|
548
|
+
attemptSignal.throwIfAborted();
|
|
549
|
+
if (/^https?:/.test(request.url) && request.redirect !== "error" && error instanceof TypeError) {
|
|
550
|
+
throw new RequestError("Network request failed", void 0, error);
|
|
551
|
+
}
|
|
552
|
+
throw error;
|
|
512
553
|
}
|
|
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
554
|
}
|
|
523
|
-
function
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
555
|
+
async function abortable(promise, signal) {
|
|
556
|
+
if (!signal) return promise;
|
|
557
|
+
let abort;
|
|
558
|
+
const cancelled = new Promise((_, reject) => {
|
|
559
|
+
abort = () => reject(signal.reason);
|
|
560
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
561
|
+
if (signal.aborted) abort();
|
|
562
|
+
});
|
|
563
|
+
try {
|
|
564
|
+
return await Promise.race([promise, cancelled]);
|
|
565
|
+
} finally {
|
|
566
|
+
signal.removeEventListener("abort", abort);
|
|
534
567
|
}
|
|
535
568
|
}
|
|
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
|
-
});
|
|
569
|
+
var RequestQueue = class {
|
|
570
|
+
constructor() {
|
|
571
|
+
this.pendingRequests = 0;
|
|
572
|
+
this.stopped = new AbortController();
|
|
573
|
+
this.queue = new JobQueue(
|
|
574
|
+
(request) => fetchRequest(request, this.baseURL),
|
|
575
|
+
{ interval: 10, maxPerRun: 1, maxActive: 8 }
|
|
576
|
+
);
|
|
614
577
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
578
|
+
async request(request) {
|
|
579
|
+
this.pendingRequests++;
|
|
580
|
+
const signal = request.signal;
|
|
581
|
+
try {
|
|
582
|
+
for (let retries = 0; ; retries++) {
|
|
583
|
+
signal?.throwIfAborted();
|
|
584
|
+
try {
|
|
585
|
+
return await abortable(this.queue.add(request), signal);
|
|
586
|
+
} catch (error) {
|
|
587
|
+
console.debug(p, "Request failed", error);
|
|
588
|
+
const delay = this.retryDelay(error, request, retries);
|
|
589
|
+
if (delay === void 0) {
|
|
590
|
+
throw error;
|
|
622
591
|
}
|
|
623
|
-
|
|
624
|
-
request["minerenderRetry"] = 3;
|
|
625
|
-
return true;
|
|
592
|
+
await this.waitForRetry(delay, signal);
|
|
626
593
|
}
|
|
627
594
|
}
|
|
595
|
+
} finally {
|
|
596
|
+
if (signal?.aborted) {
|
|
597
|
+
this.queue.remove(request);
|
|
598
|
+
}
|
|
599
|
+
this.pendingRequests--;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
retryDelay(error, request, retries) {
|
|
603
|
+
if (this.stopped.signal.aborted || retries >= 3 || (request.method ?? "get").toLowerCase() !== "get" || request.signal?.aborted) {
|
|
604
|
+
return void 0;
|
|
605
|
+
}
|
|
606
|
+
if (error instanceof RequestError) {
|
|
607
|
+
const status = error.response?.status;
|
|
608
|
+
if (status !== void 0 && status !== 408 && status !== 429 && !(status >= 500 && status < 600)) return void 0;
|
|
609
|
+
} else if (!(error instanceof DOMException && error.name === "TimeoutError")) {
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
let delay = 100 * 2 ** retries;
|
|
613
|
+
const retryAfter = error instanceof RequestError ? error.response?.headers.get("Retry-After") : void 0;
|
|
614
|
+
if (retryAfter !== void 0 && retryAfter !== null) {
|
|
615
|
+
const seconds = Number(retryAfter);
|
|
616
|
+
if (!retryAfter.trim() || !Number.isFinite(seconds) || seconds < 0) {
|
|
617
|
+
return void 0;
|
|
618
|
+
}
|
|
619
|
+
delay = Math.max(delay, seconds * 1e3);
|
|
620
|
+
}
|
|
621
|
+
return delay;
|
|
622
|
+
}
|
|
623
|
+
async waitForRetry(delay, signal) {
|
|
624
|
+
let timer;
|
|
625
|
+
const waiting = new Promise((resolve) => {
|
|
626
|
+
timer = setTimeout(resolve, delay);
|
|
627
|
+
});
|
|
628
|
+
try {
|
|
629
|
+
await abortable(waiting, AbortSignal.any([this.stopped.signal, ...signal ? [signal] : []]));
|
|
630
|
+
} finally {
|
|
631
|
+
clearTimeout(timer);
|
|
628
632
|
}
|
|
629
|
-
|
|
633
|
+
}
|
|
634
|
+
get pendingSize() {
|
|
635
|
+
return this.pendingRequests;
|
|
636
|
+
}
|
|
637
|
+
end() {
|
|
638
|
+
this.queue.end();
|
|
639
|
+
this.stopped.abort(new JobCancelledError("ended"));
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
var Requests = class {
|
|
643
|
+
static {
|
|
644
|
+
this.genericQueue = new RequestQueue();
|
|
645
|
+
}
|
|
646
|
+
static {
|
|
647
|
+
this.mcAssetRequestQueue = new RequestQueue();
|
|
648
|
+
}
|
|
649
|
+
static genericRequest(request) {
|
|
650
|
+
return this.genericQueue.request(request);
|
|
651
|
+
}
|
|
652
|
+
static mcAssetRequest(request) {
|
|
653
|
+
return this.mcAssetRequestQueue.request(request);
|
|
630
654
|
}
|
|
631
655
|
static setMcAssetRoot(root) {
|
|
632
|
-
this.
|
|
656
|
+
this.mcAssetRequestQueue.baseURL = root;
|
|
633
657
|
}
|
|
658
|
+
/** Counts unsettled calls, including retry delays and requests still running after shutdown. */
|
|
634
659
|
static get queueSizes() {
|
|
635
660
|
return {
|
|
636
|
-
generic: this.genericQueue.
|
|
637
|
-
mcAsset: this.mcAssetRequestQueue.
|
|
661
|
+
generic: this.genericQueue.pendingSize,
|
|
662
|
+
mcAsset: this.mcAssetRequestQueue.pendingSize
|
|
638
663
|
};
|
|
639
664
|
}
|
|
640
665
|
/**
|
|
641
|
-
*
|
|
642
|
-
*
|
|
666
|
+
* Permanently stops both queues and rejects waiting, retrying, and future requests.
|
|
667
|
+
* Requests already running can finish. Idle queues hold no timer, so Node can exit without
|
|
668
|
+
* this cleanup. See {@link shutdown}.
|
|
643
669
|
*/
|
|
644
670
|
static end() {
|
|
645
671
|
this.genericQueue.end();
|
|
646
672
|
this.mcAssetRequestQueue.end();
|
|
647
673
|
}
|
|
648
674
|
};
|
|
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
675
|
|
|
659
676
|
// src/WrappedImage.ts
|
|
660
677
|
var WrappedImage = class {
|
|
@@ -692,10 +709,10 @@ var WrappedImage = class {
|
|
|
692
709
|
return this.animated ? this.width : this.height;
|
|
693
710
|
}
|
|
694
711
|
get frameCount() {
|
|
695
|
-
return this.height / this.
|
|
712
|
+
return this.height / this.frameHeight;
|
|
696
713
|
}
|
|
697
714
|
getFrameY(frame) {
|
|
698
|
-
return this.
|
|
715
|
+
return this.frameHeight * Math.max(0, Math.min(this.frameCount - 1, frame));
|
|
699
716
|
}
|
|
700
717
|
getSectionData(sx, sy, sw, sh) {
|
|
701
718
|
return this.dta.data.getImageData(sx, sy, sw, sh);
|
|
@@ -705,7 +722,7 @@ var WrappedImage = class {
|
|
|
705
722
|
}
|
|
706
723
|
getFrameSectionData(frame) {
|
|
707
724
|
const y = this.getFrameY(frame);
|
|
708
|
-
return this.getSectionData(0, y, this.
|
|
725
|
+
return this.getSectionData(0, y, this.frameWidth, this.frameHeight);
|
|
709
726
|
}
|
|
710
727
|
};
|
|
711
728
|
|
|
@@ -719,29 +736,41 @@ var ImageLoader = class _ImageLoader {
|
|
|
719
736
|
static async loadAsync(src) {
|
|
720
737
|
return new Promise((resolve, reject) => {
|
|
721
738
|
const image = this._createImage();
|
|
722
|
-
image.src = src;
|
|
723
739
|
image.onload = () => resolve(image);
|
|
724
|
-
image.onerror = (err) => reject(err);
|
|
740
|
+
image.onerror = (err) => reject(err instanceof Error ? err : new Error("Failed to decode image"));
|
|
741
|
+
image.src = src;
|
|
725
742
|
});
|
|
726
743
|
}
|
|
727
744
|
static loadElement(src, onload, onerr) {
|
|
728
745
|
const image = this._createImage();
|
|
729
|
-
image.src = src;
|
|
730
746
|
if (onload)
|
|
731
747
|
image.onload = onload;
|
|
732
748
|
if (onerr)
|
|
733
749
|
image.onerror = onerr;
|
|
750
|
+
image.src = src;
|
|
734
751
|
return image;
|
|
735
752
|
}
|
|
736
753
|
static async loadData(src) {
|
|
737
754
|
console.debug(p2, "loadData", src);
|
|
738
|
-
|
|
755
|
+
const image = await this.loadCanvasData(src);
|
|
756
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
739
757
|
}
|
|
740
758
|
static async loadCanvasData(src) {
|
|
741
|
-
|
|
759
|
+
const keyStr = serializeImageKey({ src });
|
|
760
|
+
const info = this.getInfo(src);
|
|
761
|
+
const cached = Caching.rawImageCache.getIfPresent(keyStr);
|
|
762
|
+
try {
|
|
763
|
+
return await this.infoToCanvasData(await info);
|
|
764
|
+
} catch (err) {
|
|
765
|
+
if (cached && Caching.rawImageCache.getIfPresent(keyStr) === cached) {
|
|
766
|
+
Caching.rawImageCache.invalidate(keyStr);
|
|
767
|
+
}
|
|
768
|
+
throw err;
|
|
769
|
+
}
|
|
742
770
|
}
|
|
743
771
|
static async infoToCanvasData(info) {
|
|
744
|
-
const
|
|
772
|
+
const type = info.type === "jpg" ? "jpeg" : info.type ?? "png";
|
|
773
|
+
const image = await _ImageLoader.loadAsync(`data:image/${type};base64,${info.data.toString("base64")}`);
|
|
745
774
|
const canvas = createCanvas2(info.width, info.height);
|
|
746
775
|
const context = canvas.getContext("2d");
|
|
747
776
|
context.drawImage(image, 0, 0);
|
|
@@ -752,11 +781,8 @@ var ImageLoader = class _ImageLoader {
|
|
|
752
781
|
};
|
|
753
782
|
}
|
|
754
783
|
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);
|
|
784
|
+
const image = await this.infoToCanvasData(info);
|
|
785
|
+
return image.data.getImageData(0, 0, image.width, image.height);
|
|
760
786
|
}
|
|
761
787
|
static async getData(src) {
|
|
762
788
|
const keyStr = serializeImageKey({ src });
|
|
@@ -771,38 +797,25 @@ var ImageLoader = class _ImageLoader {
|
|
|
771
797
|
});
|
|
772
798
|
}
|
|
773
799
|
static async processResponse(response) {
|
|
774
|
-
const src = response.
|
|
800
|
+
const src = response.url;
|
|
775
801
|
const data = Buffer2.from(response.data);
|
|
776
802
|
const { width, height, type } = Env.provider.imageSize(data);
|
|
803
|
+
if (!width || !height) {
|
|
804
|
+
throw new Error("Invalid or unsupported image dimensions");
|
|
805
|
+
}
|
|
777
806
|
return {
|
|
778
807
|
src,
|
|
779
|
-
width
|
|
780
|
-
height
|
|
808
|
+
width,
|
|
809
|
+
height,
|
|
781
810
|
type,
|
|
782
811
|
data
|
|
783
812
|
};
|
|
784
813
|
}
|
|
785
814
|
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
815
|
return Requests.genericRequest({
|
|
795
816
|
url: src,
|
|
796
817
|
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
|
-
});
|
|
818
|
+
}).then(this.processResponse);
|
|
806
819
|
}
|
|
807
820
|
static async getInfo(src) {
|
|
808
821
|
const keyStr = serializeImageKey({ src });
|
|
@@ -824,15 +837,25 @@ var ImageLoader = class _ImageLoader {
|
|
|
824
837
|
|
|
825
838
|
// src/texture/TextureLoader.ts
|
|
826
839
|
var TextureLoader = class {
|
|
840
|
+
static {
|
|
841
|
+
this.failedTextures = /* @__PURE__ */ new WeakSet();
|
|
842
|
+
}
|
|
843
|
+
/** Reports whether image loading failed, so cached textures can be retried. */
|
|
844
|
+
static hasFailed(texture) {
|
|
845
|
+
return this.failedTextures.has(texture);
|
|
846
|
+
}
|
|
827
847
|
static createTexture() {
|
|
828
848
|
return new Texture();
|
|
829
849
|
}
|
|
830
850
|
static loadInBackground(src, format = RGBAFormat, rotation = 0) {
|
|
831
851
|
const texture = this.createTexture();
|
|
832
|
-
|
|
833
|
-
image
|
|
852
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
853
|
+
const image = ImageLoader.loadElement(src, () => {
|
|
834
854
|
texture.needsUpdate = true;
|
|
835
|
-
}
|
|
855
|
+
}, (error) => {
|
|
856
|
+
this.failedTextures.add(texture);
|
|
857
|
+
console.warn("Failed to load texture", src, error);
|
|
858
|
+
});
|
|
836
859
|
texture.image = image;
|
|
837
860
|
texture.format = format;
|
|
838
861
|
texture.rotation = rotation;
|
|
@@ -840,9 +863,13 @@ var TextureLoader = class {
|
|
|
840
863
|
}
|
|
841
864
|
static load(src, format = RGBAFormat, rotation = 0) {
|
|
842
865
|
const texture = new Texture();
|
|
866
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
843
867
|
ImageLoader.getData(src).then((image) => {
|
|
844
|
-
texture.needsUpdate = true;
|
|
845
868
|
texture.image = image;
|
|
869
|
+
texture.needsUpdate = true;
|
|
870
|
+
}).catch((error) => {
|
|
871
|
+
this.failedTextures.add(texture);
|
|
872
|
+
console.warn("Failed to load texture", src, error);
|
|
846
873
|
});
|
|
847
874
|
texture.format = format;
|
|
848
875
|
texture.rotation = rotation;
|
|
@@ -851,11 +878,11 @@ var TextureLoader = class {
|
|
|
851
878
|
};
|
|
852
879
|
|
|
853
880
|
// src/texture/Textures.ts
|
|
854
|
-
import * as
|
|
881
|
+
import * as THREE2 from "three";
|
|
855
882
|
var Textures = class _Textures {
|
|
856
883
|
static initTextureProps(texture) {
|
|
857
|
-
texture.magFilter =
|
|
858
|
-
texture.minFilter =
|
|
884
|
+
texture.magFilter = THREE2.NearestFilter;
|
|
885
|
+
texture.minFilter = THREE2.NearestFilter;
|
|
859
886
|
texture.anisotropy = 0;
|
|
860
887
|
return texture;
|
|
861
888
|
}
|
|
@@ -866,10 +893,16 @@ var Textures = class _Textures {
|
|
|
866
893
|
return new Texture2();
|
|
867
894
|
}
|
|
868
895
|
static createCanvasTexture(canvas) {
|
|
869
|
-
|
|
896
|
+
const texture = new CanvasTexture(canvas);
|
|
897
|
+
texture.colorSpace = THREE2.SRGBColorSpace;
|
|
898
|
+
return this.initTextureProps(texture);
|
|
870
899
|
}
|
|
871
900
|
static getImage(key) {
|
|
872
901
|
const keyStr = serializeTextureKey(key);
|
|
902
|
+
const cached = Caching.textureCache.peek(keyStr);
|
|
903
|
+
if (cached && TextureLoader.hasFailed(cached)) {
|
|
904
|
+
Caching.textureCache.invalidate(keyStr);
|
|
905
|
+
}
|
|
873
906
|
return Caching.textureCache.get(keyStr, (k) => {
|
|
874
907
|
return _Textures.createImage(key);
|
|
875
908
|
});
|
|
@@ -877,7 +910,10 @@ var Textures = class _Textures {
|
|
|
877
910
|
};
|
|
878
911
|
|
|
879
912
|
// src/Materials.ts
|
|
880
|
-
var
|
|
913
|
+
var Materials = class _Materials {
|
|
914
|
+
static {
|
|
915
|
+
this.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
|
|
916
|
+
}
|
|
881
917
|
// resolved lazily: as a static field this decoded an image the moment the library was
|
|
882
918
|
// imported, which needs both a DOM and an EnvProvider to already be in place
|
|
883
919
|
static get MISSING_TEXTURE() {
|
|
@@ -913,6 +949,7 @@ var _Materials = class _Materials {
|
|
|
913
949
|
uniform bool SHADE;
|
|
914
950
|
|
|
915
951
|
varying vec2 vUv;
|
|
952
|
+
varying vec3 vTint;
|
|
916
953
|
varying float light;
|
|
917
954
|
varying float lift;
|
|
918
955
|
|
|
@@ -925,7 +962,11 @@ var _Materials = class _Materials {
|
|
|
925
962
|
|
|
926
963
|
if (SHADE) {
|
|
927
964
|
|
|
928
|
-
|
|
965
|
+
#ifdef USE_INSTANCING
|
|
966
|
+
vec3 N = vec3( modelMatrix * instanceMatrix * vec4(normal, 0.0) );
|
|
967
|
+
#else
|
|
968
|
+
vec3 N = vec3( modelMatrix * vec4(normal, 0.0) );
|
|
969
|
+
#endif
|
|
929
970
|
|
|
930
971
|
float yLight = (1.0+N.y) * 0.5;
|
|
931
972
|
light = yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
|
|
@@ -943,6 +984,7 @@ var _Materials = class _Materials {
|
|
|
943
984
|
}
|
|
944
985
|
|
|
945
986
|
vUv = uv;
|
|
987
|
+
vTint = color;
|
|
946
988
|
|
|
947
989
|
#ifdef USE_INSTANCING
|
|
948
990
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
|
|
@@ -964,12 +1006,14 @@ var _Materials = class _Materials {
|
|
|
964
1006
|
uniform float BRIGHTNESS;
|
|
965
1007
|
|
|
966
1008
|
varying vec2 vUv;
|
|
1009
|
+
varying vec3 vTint;
|
|
967
1010
|
varying float light;
|
|
968
1011
|
varying float lift;
|
|
969
1012
|
|
|
970
1013
|
void main(void)
|
|
971
1014
|
{
|
|
972
1015
|
vec4 color = texture2D(map, vUv);
|
|
1016
|
+
color.rgb *= vTint;
|
|
973
1017
|
|
|
974
1018
|
if (color.a < 0.01) discard;
|
|
975
1019
|
|
|
@@ -983,6 +1027,9 @@ var _Materials = class _Materials {
|
|
|
983
1027
|
gl_FragColor = vec4(lift + color.rgb * light2, 1.0);
|
|
984
1028
|
|
|
985
1029
|
}
|
|
1030
|
+
|
|
1031
|
+
#include <tonemapping_fragment>
|
|
1032
|
+
#include <colorspace_fragment>
|
|
986
1033
|
}
|
|
987
1034
|
`;
|
|
988
1035
|
try {
|
|
@@ -1011,6 +1058,10 @@ var _Materials = class _Materials {
|
|
|
1011
1058
|
}
|
|
1012
1059
|
static getImage(key) {
|
|
1013
1060
|
const keyStr = serializeMaterialKey(key);
|
|
1061
|
+
const map = Caching.materialCache.peek(keyStr)?.map;
|
|
1062
|
+
if (map && TextureLoader.hasFailed(map)) {
|
|
1063
|
+
Caching.materialCache.invalidate(keyStr);
|
|
1064
|
+
}
|
|
1014
1065
|
return Caching.materialCache.get(keyStr, (k) => {
|
|
1015
1066
|
return _Materials.createImage(key);
|
|
1016
1067
|
});
|
|
@@ -1031,14 +1082,12 @@ var _Materials = class _Materials {
|
|
|
1031
1082
|
}
|
|
1032
1083
|
}
|
|
1033
1084
|
};
|
|
1034
|
-
_Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
|
|
1035
|
-
var Materials = _Materials;
|
|
1036
1085
|
|
|
1037
1086
|
// src/Meshes.ts
|
|
1038
|
-
import { Mesh
|
|
1087
|
+
import { Mesh } from "three";
|
|
1039
1088
|
var Meshes = class _Meshes {
|
|
1040
1089
|
static createBox(key) {
|
|
1041
|
-
return new
|
|
1090
|
+
return new Mesh(Geometries.getBox(key.geometry), Materials.getImage(key.material));
|
|
1042
1091
|
}
|
|
1043
1092
|
static getBox(key) {
|
|
1044
1093
|
const keyStr = serializeMeshKey(key);
|
|
@@ -1049,7 +1098,7 @@ var Meshes = class _Meshes {
|
|
|
1049
1098
|
};
|
|
1050
1099
|
|
|
1051
1100
|
// src/UVMapper.ts
|
|
1052
|
-
import { Float32BufferAttribute as Float32BufferAttribute2, Vector2 } from "three";
|
|
1101
|
+
import { Float32BufferAttribute as Float32BufferAttribute2, Vector2, Vector3 as Vector33 } from "three";
|
|
1053
1102
|
|
|
1054
1103
|
// src/model/ModelMerger.ts
|
|
1055
1104
|
var import_ts_deepmerge = __toESM(require_dist());
|
|
@@ -1085,9 +1134,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1085
1134
|
this.rootType = rootType;
|
|
1086
1135
|
this.extension = extension;
|
|
1087
1136
|
this.root = root;
|
|
1137
|
+
this.isAssetKey = true;
|
|
1088
1138
|
}
|
|
1089
1139
|
static parse(assetType, str, origin) {
|
|
1090
|
-
let namespace =
|
|
1140
|
+
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
1091
1141
|
if (str.includes(":")) {
|
|
1092
1142
|
let split2 = str.split(":");
|
|
1093
1143
|
namespace = split2[0];
|
|
@@ -1100,12 +1150,15 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1100
1150
|
split.shift();
|
|
1101
1151
|
}
|
|
1102
1152
|
let path = split.join("/");
|
|
1103
|
-
|
|
1104
|
-
|
|
1153
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1154
|
+
if (extension && path.endsWith(extension)) {
|
|
1155
|
+
path = path.slice(0, -extension.length);
|
|
1156
|
+
}
|
|
1157
|
+
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1105
1158
|
}
|
|
1106
1159
|
toString() {
|
|
1107
1160
|
let a = [
|
|
1108
|
-
|
|
1161
|
+
this.root ?? AssetLoader.ROOT,
|
|
1109
1162
|
this.rootType ?? "__rootType__",
|
|
1110
1163
|
this.assetType ?? "__assetType__",
|
|
1111
1164
|
this.type ?? "__type__",
|
|
@@ -1115,12 +1168,12 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1115
1168
|
return a.join("/");
|
|
1116
1169
|
}
|
|
1117
1170
|
getFullPath() {
|
|
1118
|
-
let
|
|
1171
|
+
let p12 = [];
|
|
1119
1172
|
if (this.type) {
|
|
1120
|
-
|
|
1173
|
+
p12.push(this.type);
|
|
1121
1174
|
}
|
|
1122
|
-
|
|
1123
|
-
return
|
|
1175
|
+
p12.push(this.path);
|
|
1176
|
+
return p12.join("/");
|
|
1124
1177
|
}
|
|
1125
1178
|
toNamespacedString() {
|
|
1126
1179
|
return this.namespace + ":" + this.getFullPath();
|
|
@@ -1130,10 +1183,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1130
1183
|
}
|
|
1131
1184
|
};
|
|
1132
1185
|
function isBasicAssetKey(obj) {
|
|
1133
|
-
return "
|
|
1186
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1134
1187
|
}
|
|
1135
1188
|
function isAssetKey(obj) {
|
|
1136
|
-
return isBasicAssetKey(obj) &&
|
|
1189
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1137
1190
|
}
|
|
1138
1191
|
|
|
1139
1192
|
// src/model/ModelMerger.ts
|
|
@@ -1142,10 +1195,10 @@ var ModelMerger = class {
|
|
|
1142
1195
|
const models = await this.collectAllParents(model);
|
|
1143
1196
|
let merged = {};
|
|
1144
1197
|
for (let parentModel of models) {
|
|
1145
|
-
merged =
|
|
1198
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
|
|
1146
1199
|
}
|
|
1147
|
-
merged =
|
|
1148
|
-
merged.hierarchy = models.map((m) => m.parent).filter((
|
|
1200
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
|
|
1201
|
+
merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
|
|
1149
1202
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1150
1203
|
return merged;
|
|
1151
1204
|
}
|
|
@@ -1155,6 +1208,7 @@ var ModelMerger = class {
|
|
|
1155
1208
|
}
|
|
1156
1209
|
const models = [];
|
|
1157
1210
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1211
|
+
parentKey.root = model.key?.root;
|
|
1158
1212
|
const parentModel = await Models.getRaw(parentKey);
|
|
1159
1213
|
if (parentModel) {
|
|
1160
1214
|
models.unshift(parentModel);
|
|
@@ -1164,9 +1218,6 @@ var ModelMerger = class {
|
|
|
1164
1218
|
}
|
|
1165
1219
|
};
|
|
1166
1220
|
|
|
1167
|
-
// src/assets/Models.ts
|
|
1168
|
-
import { Memoize } from "typescript-memoize";
|
|
1169
|
-
|
|
1170
1221
|
// src/assets/source/parser/AssetParsers.ts
|
|
1171
1222
|
var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
1172
1223
|
AssetParser2["MODEL"] = "model";
|
|
@@ -1180,30 +1231,65 @@ var AssetParser = /* @__PURE__ */ ((AssetParser2) => {
|
|
|
1180
1231
|
})(AssetParser || {});
|
|
1181
1232
|
|
|
1182
1233
|
// src/assets/Models.ts
|
|
1183
|
-
var
|
|
1234
|
+
var Models = class _Models {
|
|
1184
1235
|
// opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
|
|
1185
1236
|
// the library, and would require an EnvProvider before any entry has had a chance to register
|
|
1186
1237
|
static get PERSISTENT_CACHE() {
|
|
1187
1238
|
return this._persistentCache ??= PersistentCache.open("minerender-models");
|
|
1188
1239
|
}
|
|
1189
1240
|
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) ?? []);
|
|
1241
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1242
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1243
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1244
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1245
|
+
}).then((r) => r?.files ?? []);
|
|
1199
1246
|
}
|
|
1200
1247
|
static async loadAndMerge(key) {
|
|
1201
|
-
const model = await this.getRaw(key);
|
|
1248
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1202
1249
|
if (!model) {
|
|
1203
1250
|
return void 0;
|
|
1204
1251
|
}
|
|
1205
1252
|
return ModelMerger.mergeWithParents(model);
|
|
1206
1253
|
}
|
|
1254
|
+
static async getItemModel(key) {
|
|
1255
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1256
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1257
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1258
|
+
if (!result) return void 0;
|
|
1259
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1260
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1261
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1262
|
+
modelKey.root = key.root;
|
|
1263
|
+
const model2 = await this.getRaw(modelKey);
|
|
1264
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1265
|
+
return model2;
|
|
1266
|
+
});
|
|
1267
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1268
|
+
}
|
|
1269
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1270
|
+
static defaultItemModel(node, key) {
|
|
1271
|
+
if (!node || typeof node.type !== "string") {
|
|
1272
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1273
|
+
}
|
|
1274
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1275
|
+
case "model":
|
|
1276
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1277
|
+
break;
|
|
1278
|
+
case "condition":
|
|
1279
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1280
|
+
case "select": {
|
|
1281
|
+
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;
|
|
1282
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1283
|
+
}
|
|
1284
|
+
case "range_dispatch": {
|
|
1285
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1286
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1287
|
+
}, void 0);
|
|
1288
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1292
|
+
}
|
|
1207
1293
|
static async getRaw(key) {
|
|
1208
1294
|
if (!key.assetType) {
|
|
1209
1295
|
key.assetType = "models";
|
|
@@ -1242,19 +1328,15 @@ var _Models = class _Models {
|
|
|
1242
1328
|
return this.PERSISTENT_CACHE.clear();
|
|
1243
1329
|
}
|
|
1244
1330
|
};
|
|
1245
|
-
__decorateClass([
|
|
1246
|
-
Memoize()
|
|
1247
|
-
], _Models, "getItemList", 1);
|
|
1248
|
-
var Models = _Models;
|
|
1249
1331
|
|
|
1250
1332
|
// src/assets/BlockStates.ts
|
|
1251
|
-
import { Memoize as Memoize2 } from "typescript-memoize";
|
|
1252
1333
|
var BlockStates = class {
|
|
1253
1334
|
static get PERSISTENT_CACHE() {
|
|
1254
1335
|
return this._persistentCache ??= PersistentCache.open("minerender-blockstates");
|
|
1255
1336
|
}
|
|
1337
|
+
// BlockState names are hardcoded
|
|
1256
1338
|
static async getList() {
|
|
1257
|
-
|
|
1339
|
+
const key = new AssetKey(
|
|
1258
1340
|
DEFAULT_NAMESPACE,
|
|
1259
1341
|
"_list",
|
|
1260
1342
|
"blockstates",
|
|
@@ -1262,11 +1344,16 @@ var BlockStates = class {
|
|
|
1262
1344
|
"assets",
|
|
1263
1345
|
".json",
|
|
1264
1346
|
DEFAULT_ROOT
|
|
1265
|
-
)
|
|
1347
|
+
);
|
|
1348
|
+
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1349
|
+
return AssetLoader.get(key, "list" /* LIST */);
|
|
1350
|
+
}).then((r) => r?.files ?? []);
|
|
1266
1351
|
}
|
|
1267
1352
|
static async getDefaultStates() {
|
|
1268
1353
|
const key = AssetKey.parse("blockstates", "minerender:defaultBlockStates");
|
|
1269
|
-
return
|
|
1354
|
+
return Caching.defaultBlockStatesCache.get(key.serialize(), () => {
|
|
1355
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
1356
|
+
});
|
|
1270
1357
|
}
|
|
1271
1358
|
static async getDefaultState(key) {
|
|
1272
1359
|
const defaultStates = await this.getDefaultStates();
|
|
@@ -1305,17 +1392,11 @@ var BlockStates = class {
|
|
|
1305
1392
|
await this.PERSISTENT_CACHE.clear();
|
|
1306
1393
|
}
|
|
1307
1394
|
};
|
|
1308
|
-
__decorateClass([
|
|
1309
|
-
Memoize2()
|
|
1310
|
-
], BlockStates, "getList", 1);
|
|
1311
|
-
__decorateClass([
|
|
1312
|
-
Memoize2()
|
|
1313
|
-
], BlockStates, "getDefaultStates", 1);
|
|
1314
1395
|
var DefaultBlockStates = class {
|
|
1315
1396
|
};
|
|
1316
1397
|
|
|
1317
1398
|
// src/assets/Assets.ts
|
|
1318
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1399
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1319
1400
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1320
1401
|
var Assets = class {
|
|
1321
1402
|
/**
|
|
@@ -1337,28 +1418,241 @@ var AssetSource = class {
|
|
|
1337
1418
|
constructor() {
|
|
1338
1419
|
}
|
|
1339
1420
|
};
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1421
|
+
var AssetLoadError = class extends Error {
|
|
1422
|
+
constructor(source, key, path, cause) {
|
|
1423
|
+
super(`Failed to load ${key.toNamespacedString()} from ${path}${cause instanceof Error ? `: ${cause.message}` : ""}`);
|
|
1424
|
+
this.source = source;
|
|
1425
|
+
this.key = key;
|
|
1426
|
+
this.path = path;
|
|
1427
|
+
this.cause = cause;
|
|
1428
|
+
this.name = "AssetLoadError";
|
|
1347
1429
|
}
|
|
1348
1430
|
};
|
|
1349
1431
|
|
|
1350
|
-
// src/
|
|
1351
|
-
var
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1432
|
+
// src/util/BatchedExecutor.ts
|
|
1433
|
+
var BatchedExecutor = class {
|
|
1434
|
+
constructor(interval = 1, batch = 30) {
|
|
1435
|
+
this.interval = interval;
|
|
1436
|
+
this.batch = batch;
|
|
1437
|
+
this.queue = [];
|
|
1438
|
+
this.task = setInterval(() => this.run());
|
|
1439
|
+
}
|
|
1440
|
+
submit(task) {
|
|
1441
|
+
this.queue.push(task);
|
|
1442
|
+
}
|
|
1443
|
+
run() {
|
|
1444
|
+
for (let i = 0; i < this.batch; i++) {
|
|
1445
|
+
this.runNext();
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
runNext() {
|
|
1449
|
+
let next = this.queue.shift();
|
|
1450
|
+
if (next) next();
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
// src/util/model.ts
|
|
1455
|
+
import { AxesHelper, BoxGeometry as BoxGeometry2, EdgesGeometry, LineBasicMaterial, LineSegments, Vector3 as Vector32 } from "three";
|
|
1456
|
+
function applyElementRotation(rotation, geometry) {
|
|
1457
|
+
const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1458
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1459
|
+
switch (rotation.axis) {
|
|
1460
|
+
case "x" /* X */:
|
|
1461
|
+
geometry.rotateX(toRadians(rotation.angle));
|
|
1462
|
+
break;
|
|
1463
|
+
case "y" /* Y */:
|
|
1464
|
+
geometry.rotateY(toRadians(rotation.angle));
|
|
1465
|
+
break;
|
|
1466
|
+
case "z" /* Z */:
|
|
1467
|
+
geometry.rotateZ(toRadians(rotation.angle));
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
if (rotation.rescale) {
|
|
1471
|
+
if (Math.abs(rotation.angle) === 22.5) {
|
|
1472
|
+
const s = 1 / Math.cos(0.39269909262657166);
|
|
1473
|
+
geometry.scale(s, 1, s);
|
|
1474
|
+
} else {
|
|
1475
|
+
const s = 1 / Math.cos(0.7853981852531433);
|
|
1476
|
+
geometry.scale(s, 1, s);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1480
|
+
}
|
|
1481
|
+
function applyModelPartRotation(modelPart, geometry) {
|
|
1482
|
+
const origin = new Vector32(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1483
|
+
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1484
|
+
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1485
|
+
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1486
|
+
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1487
|
+
geometry.translate(origin.x, origin.y, origin.z);
|
|
1488
|
+
}
|
|
1489
|
+
function applyGenericRotation(axis, rotation, obj) {
|
|
1490
|
+
switch (axis) {
|
|
1491
|
+
case "x" /* X */:
|
|
1492
|
+
obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
|
|
1493
|
+
break;
|
|
1494
|
+
case "y" /* Y */:
|
|
1495
|
+
obj.rotateOnAxis(new Vector32(0, 1, 0), toRadians(rotation));
|
|
1496
|
+
break;
|
|
1497
|
+
case "z" /* Z */:
|
|
1498
|
+
obj.rotateOnAxis(new Vector32(0, 0, 1), toRadians(rotation));
|
|
1499
|
+
break;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function addBox3WireframeToObject(box, obj, color = 16777215, w = 2) {
|
|
1503
|
+
let size = new Vector32();
|
|
1504
|
+
box.getSize(size);
|
|
1505
|
+
let boxGeo = new BoxGeometry2(size.x, size.y, size.z, 1, 1, 1);
|
|
1506
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1507
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1508
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1509
|
+
obj.add(wireframe);
|
|
1510
|
+
let axes = new AxesHelper(1);
|
|
1511
|
+
obj.add(axes);
|
|
1512
|
+
}
|
|
1513
|
+
function addWireframeToObject(obj, color = 16777215, w = 2) {
|
|
1514
|
+
let boxGeo = new BoxGeometry2(16, 16, 16, 1, 1, 1);
|
|
1515
|
+
let wireGeo = new EdgesGeometry(boxGeo);
|
|
1516
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1517
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1518
|
+
obj.add(wireframe);
|
|
1519
|
+
let axes = new AxesHelper(1);
|
|
1520
|
+
obj.add(axes);
|
|
1521
|
+
}
|
|
1522
|
+
function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
|
|
1523
|
+
let wireGeo = new EdgesGeometry(geo);
|
|
1524
|
+
let wireMat = new LineBasicMaterial({ color, linewidth: w });
|
|
1525
|
+
let wireframe = new LineSegments(wireGeo, wireMat);
|
|
1526
|
+
mesh.add(wireframe);
|
|
1527
|
+
let axes = new AxesHelper(1);
|
|
1528
|
+
mesh.add(axes);
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// src/util/performance.ts
|
|
1532
|
+
function captureException(e, ...extra) {
|
|
1533
|
+
console.error(e, extra);
|
|
1534
|
+
}
|
|
1535
|
+
function timingStart(marker) {
|
|
1536
|
+
console.time(marker);
|
|
1537
|
+
}
|
|
1538
|
+
function timingEnd(marker) {
|
|
1539
|
+
console.timeEnd(marker);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/util/three.ts
|
|
1543
|
+
function isObject3D(obj) {
|
|
1544
|
+
return obj.isObject3D;
|
|
1545
|
+
}
|
|
1546
|
+
function isMesh(obj) {
|
|
1547
|
+
return obj.isMesh;
|
|
1548
|
+
}
|
|
1549
|
+
function isInstancedMesh(obj) {
|
|
1550
|
+
return obj.isInstancedMesh;
|
|
1551
|
+
}
|
|
1552
|
+
function isPerspectiveCamera(obj) {
|
|
1553
|
+
return obj.isPerspectiveCamera;
|
|
1554
|
+
}
|
|
1555
|
+
function isOrthographicCamera(obj) {
|
|
1556
|
+
return obj.isOrthographicCamera;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// src/nbt/NBTHelper.ts
|
|
1560
|
+
var NBTHelper = class {
|
|
1561
|
+
static async fromBuffer(buffer) {
|
|
1562
|
+
const prismarineNbt = await import("prismarine-nbt");
|
|
1563
|
+
const { parsed, type, metadata } = await prismarineNbt.parse(buffer);
|
|
1564
|
+
return parsed;
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
// src/assets/source/HostedAssetSource.ts
|
|
1569
|
+
var import_ts_deepmerge2 = __toESM(require_dist());
|
|
1570
|
+
var p3 = prefix("HostedAssetSource");
|
|
1571
|
+
var DEFAULT_OPTIONS = {
|
|
1572
|
+
retryDefaults: true
|
|
1573
|
+
};
|
|
1574
|
+
var HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
1575
|
+
static {
|
|
1576
|
+
this.MODEL = {
|
|
1577
|
+
config(request) {
|
|
1578
|
+
},
|
|
1579
|
+
parse(response) {
|
|
1580
|
+
return response.data;
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
static {
|
|
1585
|
+
this.BLOCKSTATE = {
|
|
1586
|
+
config(request) {
|
|
1587
|
+
},
|
|
1588
|
+
parse(response) {
|
|
1589
|
+
return response.data;
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
static {
|
|
1594
|
+
this.META = {
|
|
1595
|
+
config(request) {
|
|
1596
|
+
},
|
|
1597
|
+
parse(response) {
|
|
1598
|
+
return response.data;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
static {
|
|
1603
|
+
this.NBT = {
|
|
1604
|
+
config(request) {
|
|
1605
|
+
request.responseType = "arraybuffer";
|
|
1606
|
+
},
|
|
1607
|
+
parse(response) {
|
|
1608
|
+
return NBTHelper.fromBuffer(Buffer.from(response.data));
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
static {
|
|
1613
|
+
this.IMAGE = {
|
|
1614
|
+
config(request) {
|
|
1615
|
+
request.responseType = "arraybuffer";
|
|
1616
|
+
},
|
|
1617
|
+
async parse(response) {
|
|
1618
|
+
return await ImageLoader.processResponse(response);
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
static {
|
|
1623
|
+
this.LIST = {
|
|
1624
|
+
config(request) {
|
|
1625
|
+
},
|
|
1626
|
+
parse(response) {
|
|
1627
|
+
return response.data;
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
static {
|
|
1632
|
+
this.JSON = {
|
|
1633
|
+
config(request) {
|
|
1634
|
+
},
|
|
1635
|
+
parse(response) {
|
|
1636
|
+
return response.data;
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
static {
|
|
1641
|
+
this.PARSER_MAP = /* @__PURE__ */ new Map([
|
|
1642
|
+
["model" /* MODEL */, _HostedAssetSource.MODEL],
|
|
1643
|
+
["blockstate" /* BLOCKSTATE */, _HostedAssetSource.BLOCKSTATE],
|
|
1644
|
+
["meta" /* META */, _HostedAssetSource.META],
|
|
1645
|
+
["nbt" /* NBT */, _HostedAssetSource.NBT],
|
|
1646
|
+
["image" /* IMAGE */, _HostedAssetSource.IMAGE],
|
|
1647
|
+
["list" /* LIST */, _HostedAssetSource.LIST],
|
|
1648
|
+
["json" /* JSON */, _HostedAssetSource.JSON]
|
|
1649
|
+
]);
|
|
1650
|
+
}
|
|
1651
|
+
async loadOrRetryWithDefaults(key, parser) {
|
|
1652
|
+
const direct = await this.load(key, parser);
|
|
1653
|
+
if (typeof direct !== "undefined") {
|
|
1654
|
+
return direct;
|
|
1655
|
+
}
|
|
1362
1656
|
if (key.namespace !== DEFAULT_NAMESPACE) {
|
|
1363
1657
|
console.info(p3, "Retrying", key, "with default namespace");
|
|
1364
1658
|
const namespaceKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, key.root);
|
|
@@ -1388,31 +1682,25 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1388
1682
|
console.info(p3, "Loading", key);
|
|
1389
1683
|
const url = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1390
1684
|
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");
|
|
1685
|
+
const request = { url };
|
|
1686
|
+
try {
|
|
1687
|
+
parser.config(request);
|
|
1688
|
+
let response;
|
|
1689
|
+
try {
|
|
1690
|
+
response = await Requests.mcAssetRequest(request);
|
|
1691
|
+
} catch (cause) {
|
|
1692
|
+
if (cause instanceof RequestError && cause.response?.status === 404) {
|
|
1410
1693
|
return void 0;
|
|
1411
1694
|
}
|
|
1695
|
+
throw cause;
|
|
1412
1696
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1697
|
+
if (response.data === void 0) {
|
|
1698
|
+
throw new Error("Asset response has no data");
|
|
1699
|
+
}
|
|
1700
|
+
return await parser.parse(response);
|
|
1701
|
+
} catch (cause) {
|
|
1702
|
+
throw new AssetLoadError(this, key, request.url, cause);
|
|
1703
|
+
}
|
|
1416
1704
|
}
|
|
1417
1705
|
assetBasePath(key) {
|
|
1418
1706
|
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 +1724,6 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1436
1724
|
return this.load(key, responseParser);
|
|
1437
1725
|
}
|
|
1438
1726
|
};
|
|
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
1727
|
|
|
1501
1728
|
// src/assets/source/archive/BrowserArchiveProxy.ts
|
|
1502
1729
|
import { BlobReader, BlobWriter, ZipReader } from "@zip.js/zip.js";
|
|
@@ -1519,7 +1746,6 @@ var BrowserArchiveProxy = class {
|
|
|
1519
1746
|
};
|
|
1520
1747
|
|
|
1521
1748
|
// src/assets/source/archive/ArchiveAssetSource.ts
|
|
1522
|
-
var p4 = prefix("ArchiveAssetSource");
|
|
1523
1749
|
var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
1524
1750
|
constructor(archiveProxy) {
|
|
1525
1751
|
super();
|
|
@@ -1538,74 +1764,31 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1538
1764
|
}
|
|
1539
1765
|
async get(key, parser) {
|
|
1540
1766
|
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
|
-
});
|
|
1767
|
+
return this.load(key, responseParser);
|
|
1578
1768
|
}
|
|
1579
|
-
//TODO: abstract this
|
|
1580
1769
|
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
|
-
}
|
|
1770
|
+
const path = `${this.assetBasePath(key)}${key.type !== void 0 ? key.type + "/" : ""}${key.path}${key.extension}`;
|
|
1771
|
+
let url;
|
|
1772
|
+
try {
|
|
1773
|
+
const entry = await this.getEntry(path);
|
|
1774
|
+
if (!entry) {
|
|
1775
|
+
return void 0;
|
|
1596
1776
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
return void 0;
|
|
1604
|
-
}
|
|
1777
|
+
url = URL.createObjectURL(await entry.getData());
|
|
1778
|
+
const request = { url };
|
|
1779
|
+
parser.config(request);
|
|
1780
|
+
const response = await Requests.genericRequest(request);
|
|
1781
|
+
if (response.data === void 0) {
|
|
1782
|
+
throw new Error("Asset response has no data");
|
|
1605
1783
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1784
|
+
return await parser.parse(response);
|
|
1785
|
+
} catch (cause) {
|
|
1786
|
+
throw new AssetLoadError(this, key, path, cause);
|
|
1787
|
+
} finally {
|
|
1788
|
+
if (url !== void 0) {
|
|
1789
|
+
URL.revokeObjectURL(url);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1609
1792
|
}
|
|
1610
1793
|
assetBasePath(key) {
|
|
1611
1794
|
return `${key.rootType !== void 0 ? key.rootType + "/" : ""}${key.namespace !== void 0 ? key.namespace + "/" : ""}${key.assetType !== void 0 ? key.assetType + "/" : ""}`;
|
|
@@ -1613,18 +1796,23 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1613
1796
|
};
|
|
1614
1797
|
|
|
1615
1798
|
// src/assets/AssetLoader.ts
|
|
1616
|
-
var
|
|
1617
|
-
var
|
|
1618
|
-
|
|
1799
|
+
var p4 = prefix("AssetLoader");
|
|
1800
|
+
var AssetLoader = class {
|
|
1801
|
+
static {
|
|
1802
|
+
this.ROOT = DEFAULT_ROOT;
|
|
1803
|
+
}
|
|
1804
|
+
static {
|
|
1805
|
+
this._SOURCES = [];
|
|
1806
|
+
}
|
|
1619
1807
|
static addSource(key, source, override = true) {
|
|
1620
1808
|
if (override) {
|
|
1621
1809
|
const existing = this.removeSource(key);
|
|
1622
1810
|
if (existing) {
|
|
1623
|
-
console.log(
|
|
1811
|
+
console.log(p4, "Removed existing AssetSource", key);
|
|
1624
1812
|
}
|
|
1625
1813
|
}
|
|
1626
1814
|
this._SOURCES.unshift({ key, source });
|
|
1627
|
-
console.log(
|
|
1815
|
+
console.log(p4, "Added AssetSource", key);
|
|
1628
1816
|
}
|
|
1629
1817
|
static removeSource(key) {
|
|
1630
1818
|
const index = this._SOURCES.findIndex((s) => s.key === key);
|
|
@@ -1636,8 +1824,11 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1636
1824
|
}
|
|
1637
1825
|
return void 0;
|
|
1638
1826
|
}
|
|
1827
|
+
static {
|
|
1828
|
+
this.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
|
|
1829
|
+
this.addSource("mcassets", new HostedAssetSource(DEFAULT_ROOT, { retryDefaults: false }));
|
|
1830
|
+
}
|
|
1639
1831
|
static async getAll(key, parser) {
|
|
1640
|
-
console.log(this._SOURCES);
|
|
1641
1832
|
let promises = [];
|
|
1642
1833
|
for (const source of this._SOURCES) {
|
|
1643
1834
|
promises.push(source.source.get(key, parser));
|
|
@@ -1646,31 +1837,36 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1646
1837
|
return results.filter((r) => r != void 0);
|
|
1647
1838
|
});
|
|
1648
1839
|
}
|
|
1840
|
+
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1649
1841
|
static async get(key, parser) {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1842
|
+
const keys = [key];
|
|
1843
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1844
|
+
keys.push(new AssetKey(
|
|
1845
|
+
key.namespace,
|
|
1846
|
+
key.path,
|
|
1847
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1848
|
+
key.type,
|
|
1849
|
+
key.rootType,
|
|
1850
|
+
key.extension,
|
|
1851
|
+
key.root
|
|
1852
|
+
));
|
|
1853
|
+
}
|
|
1854
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1855
|
+
}
|
|
1856
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1857
|
+
static async getFirst(keys, parser) {
|
|
1858
|
+
const sources = [...this._SOURCES];
|
|
1859
|
+
for (const source of sources) {
|
|
1860
|
+
for (const key of keys) {
|
|
1861
|
+
const result = await source.source.get(key, parser);
|
|
1862
|
+
if (result !== void 0) {
|
|
1863
|
+
return { key, asset: result };
|
|
1663
1864
|
}
|
|
1664
1865
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1866
|
+
}
|
|
1867
|
+
return void 0;
|
|
1667
1868
|
}
|
|
1668
1869
|
};
|
|
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
1870
|
|
|
1675
1871
|
// src/assets/ModelTextures.ts
|
|
1676
1872
|
var ModelTextures = class {
|
|
@@ -1678,12 +1874,22 @@ var ModelTextures = class {
|
|
|
1678
1874
|
return this._persistentMetaCache ??= PersistentCache.open("minerender-texturemeta");
|
|
1679
1875
|
}
|
|
1680
1876
|
static async get(key) {
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1877
|
+
const keyStr = key.serialize();
|
|
1878
|
+
const pending = this.preload(key);
|
|
1879
|
+
const cached = Caching.textureAssetCache.getIfPresent(keyStr);
|
|
1880
|
+
try {
|
|
1881
|
+
const asset = await pending;
|
|
1882
|
+
if (asset) {
|
|
1883
|
+
return await ImageLoader.infoToCanvasData(asset);
|
|
1884
|
+
}
|
|
1885
|
+
return void 0;
|
|
1886
|
+
} catch (err) {
|
|
1887
|
+
if (cached && Caching.textureAssetCache.getIfPresent(keyStr) === cached) {
|
|
1888
|
+
Caching.textureAssetCache.invalidate(keyStr);
|
|
1889
|
+
}
|
|
1890
|
+
throw err;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1687
1893
|
static async preload(key) {
|
|
1688
1894
|
const keyStr = key.serialize();
|
|
1689
1895
|
return Caching.textureAssetCache.get(keyStr, (k) => {
|
|
@@ -1756,7 +1962,28 @@ var CanvasImage = class {
|
|
|
1756
1962
|
};
|
|
1757
1963
|
|
|
1758
1964
|
// src/Ticker.ts
|
|
1759
|
-
var
|
|
1965
|
+
var Ticker = class _Ticker {
|
|
1966
|
+
static {
|
|
1967
|
+
this.TPS = 20;
|
|
1968
|
+
}
|
|
1969
|
+
static {
|
|
1970
|
+
this.counter = 0;
|
|
1971
|
+
}
|
|
1972
|
+
static {
|
|
1973
|
+
this._tickers = /* @__PURE__ */ new Map();
|
|
1974
|
+
}
|
|
1975
|
+
static {
|
|
1976
|
+
this.oneSecondTps = 0;
|
|
1977
|
+
}
|
|
1978
|
+
static {
|
|
1979
|
+
this.oneSecondTicks = 0;
|
|
1980
|
+
}
|
|
1981
|
+
static {
|
|
1982
|
+
this.fiveSecondTps = 0;
|
|
1983
|
+
}
|
|
1984
|
+
static {
|
|
1985
|
+
this.fiveSecondTicks = 0;
|
|
1986
|
+
}
|
|
1760
1987
|
static schedule(fn, ms) {
|
|
1761
1988
|
const handle = setInterval(fn, ms);
|
|
1762
1989
|
const unref = handle.unref;
|
|
@@ -1818,14 +2045,6 @@ var _Ticker = class _Ticker {
|
|
|
1818
2045
|
this._tickers.clear();
|
|
1819
2046
|
}
|
|
1820
2047
|
};
|
|
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
2048
|
|
|
1830
2049
|
// src/texture/TextureAtlas.ts
|
|
1831
2050
|
var TextureAtlas = class {
|
|
@@ -1851,18 +2070,24 @@ var TextureAtlas = class {
|
|
|
1851
2070
|
|
|
1852
2071
|
// src/model/ModelGenerator.ts
|
|
1853
2072
|
var ModelGenerator = class {
|
|
2073
|
+
static {
|
|
2074
|
+
this.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
2075
|
+
}
|
|
1854
2076
|
static generateItemModel(imageData, layer) {
|
|
2077
|
+
const tintindex = this.ITEM_LAYERS.indexOf(layer);
|
|
1855
2078
|
const mainElement = {
|
|
1856
2079
|
from: [0, 0, 7.5],
|
|
1857
2080
|
to: [16, 16, 8.5],
|
|
1858
2081
|
faces: {
|
|
1859
2082
|
"south": {
|
|
1860
2083
|
uv: [0, 0, 16, 16],
|
|
1861
|
-
texture: `#${layer}
|
|
2084
|
+
texture: `#${layer}`,
|
|
2085
|
+
tintindex
|
|
1862
2086
|
},
|
|
1863
2087
|
"north": {
|
|
1864
2088
|
uv: [16, 0, 0, 16],
|
|
1865
|
-
texture: `#${layer}
|
|
2089
|
+
texture: `#${layer}`,
|
|
2090
|
+
tintindex
|
|
1866
2091
|
}
|
|
1867
2092
|
},
|
|
1868
2093
|
shade: true
|
|
@@ -1870,14 +2095,21 @@ var ModelGenerator = class {
|
|
|
1870
2095
|
return [mainElement];
|
|
1871
2096
|
}
|
|
1872
2097
|
};
|
|
1873
|
-
ModelGenerator.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
|
|
1874
2098
|
|
|
1875
2099
|
// src/UVMapper.ts
|
|
1876
|
-
var
|
|
2100
|
+
var p5 = prefix("UVMapper");
|
|
1877
2101
|
var DEFAULT_UV = [0, 0, 16, 16];
|
|
1878
2102
|
var X = 0;
|
|
1879
2103
|
var Y = 1;
|
|
1880
2104
|
var Z = 2;
|
|
2105
|
+
var FACE_UV_AXES = {
|
|
2106
|
+
east: [new Vector33(0, 0, -1), new Vector33(0, -1, 0)],
|
|
2107
|
+
west: [new Vector33(0, 0, 1), new Vector33(0, -1, 0)],
|
|
2108
|
+
up: [new Vector33(1, 0, 0), new Vector33(0, 0, 1)],
|
|
2109
|
+
down: [new Vector33(1, 0, 0), new Vector33(0, 0, -1)],
|
|
2110
|
+
south: [new Vector33(1, 0, 0), new Vector33(0, -1, 0)],
|
|
2111
|
+
north: [new Vector33(-1, 0, 0), new Vector33(0, -1, 0)]
|
|
2112
|
+
};
|
|
1881
2113
|
var UVMapper = class {
|
|
1882
2114
|
static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
|
|
1883
2115
|
if (uvCoord === 0) return 0;
|
|
@@ -1975,6 +2207,42 @@ var UVMapper = class {
|
|
|
1975
2207
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
1976
2208
|
return new Float32BufferAttribute2(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
1977
2209
|
}
|
|
2210
|
+
static lockUvs(geometry, faces, atlas, rotation) {
|
|
2211
|
+
const uv = geometry.getAttribute("uv");
|
|
2212
|
+
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
2213
|
+
const faceName = CUBE_FACES[faceIndex];
|
|
2214
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
2215
|
+
const position = texture && atlas.positions[texture];
|
|
2216
|
+
const size = texture && atlas.sizes[texture];
|
|
2217
|
+
if (!position || !size) continue;
|
|
2218
|
+
const [sourceU, sourceV] = FACE_UV_AXES[faceName];
|
|
2219
|
+
const uAxis = sourceU.clone().applyEuler(rotation);
|
|
2220
|
+
const vAxis = sourceV.clone().applyEuler(rotation);
|
|
2221
|
+
const normal = vAxis.clone().cross(uAxis);
|
|
2222
|
+
const targetFace = CUBE_FACES.find((name) => {
|
|
2223
|
+
const [u, v] = FACE_UV_AXES[name];
|
|
2224
|
+
return v.clone().cross(u).dot(normal) > 0.5;
|
|
2225
|
+
});
|
|
2226
|
+
const [targetU, targetV] = FACE_UV_AXES[targetFace];
|
|
2227
|
+
const uu = Math.round(targetU.dot(uAxis));
|
|
2228
|
+
const uvCross = Math.round(targetU.dot(vAxis));
|
|
2229
|
+
const vu = Math.round(targetV.dot(uAxis));
|
|
2230
|
+
const vv = Math.round(targetV.dot(vAxis));
|
|
2231
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
2232
|
+
const index = faceIndex * 4 + corner;
|
|
2233
|
+
const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
|
|
2234
|
+
const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
|
|
2235
|
+
const lockedU = uu * u + uvCross * v + 0.5;
|
|
2236
|
+
const lockedV = vu * u + vv * v + 0.5;
|
|
2237
|
+
uv.setXY(
|
|
2238
|
+
index,
|
|
2239
|
+
(position[0] + lockedU * size[0]) / atlas.image.width,
|
|
2240
|
+
1 - (position[1] + lockedV * size[1]) / atlas.image.height
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
uv.needsUpdate = true;
|
|
2245
|
+
}
|
|
1978
2246
|
static async getAtlas(model) {
|
|
1979
2247
|
const keyStr = model.key.serialize();
|
|
1980
2248
|
return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
|
|
@@ -2046,12 +2314,11 @@ var UVMapper = class {
|
|
|
2046
2314
|
return [tl, tr, bl, br];
|
|
2047
2315
|
}
|
|
2048
2316
|
static async createAtlas(originalModel) {
|
|
2049
|
-
var _a;
|
|
2050
2317
|
const textureMap = {};
|
|
2051
2318
|
const metaMap = {};
|
|
2052
2319
|
const model = { ...originalModel };
|
|
2053
2320
|
const isItemModel = !("elements" in model);
|
|
2054
|
-
console.debug(
|
|
2321
|
+
console.debug(p5, "Creating Atlas for", model.key);
|
|
2055
2322
|
if (model.textures) {
|
|
2056
2323
|
const promises = [];
|
|
2057
2324
|
const uniqueTextureNames = [];
|
|
@@ -2065,7 +2332,7 @@ var UVMapper = class {
|
|
|
2065
2332
|
const assetKey = AssetKey.parse("textures", textureValue, model.key);
|
|
2066
2333
|
promises.push(ModelTextures.get(assetKey).then((asset) => {
|
|
2067
2334
|
if (!asset) {
|
|
2068
|
-
console.warn(
|
|
2335
|
+
console.warn(p5, "Missing texture", assetKey);
|
|
2069
2336
|
return;
|
|
2070
2337
|
}
|
|
2071
2338
|
textureMap[textureKey] = new WrappedImage(asset);
|
|
@@ -2077,7 +2344,7 @@ var UVMapper = class {
|
|
|
2077
2344
|
}
|
|
2078
2345
|
await Promise.all(promises);
|
|
2079
2346
|
const textureCount = uniqueTextureNames.length;
|
|
2080
|
-
console.debug(
|
|
2347
|
+
console.debug(p5, "Creating Atlas for", textureCount, "textures");
|
|
2081
2348
|
this.fillMissingTextureKeys(model.textures, textureMap);
|
|
2082
2349
|
this.fillMissingTextureKeys(model.textures, metaMap);
|
|
2083
2350
|
const sizes = {};
|
|
@@ -2097,7 +2364,7 @@ var UVMapper = class {
|
|
|
2097
2364
|
this.fillMissingTextureKeys(model.textures, sizes);
|
|
2098
2365
|
const s = Math.ceil(Math.sqrt(textureCount + 1));
|
|
2099
2366
|
const size = Math.ceil(s * maxWidth);
|
|
2100
|
-
console.debug(
|
|
2367
|
+
console.debug(p5, "Atlas size:", size);
|
|
2101
2368
|
const squaredSize = size * size;
|
|
2102
2369
|
const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
|
|
2103
2370
|
const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
|
|
@@ -2126,16 +2393,15 @@ var UVMapper = class {
|
|
|
2126
2393
|
if (texture.animated) {
|
|
2127
2394
|
hasAnimation = true;
|
|
2128
2395
|
const meta = metaMap[textureKey];
|
|
2129
|
-
const frameTime =
|
|
2396
|
+
const frameTime = meta?.animation?.frametime ?? 1;
|
|
2130
2397
|
console.log(meta);
|
|
2131
2398
|
console.log(frameTime);
|
|
2132
2399
|
let t = 0;
|
|
2133
2400
|
let f = 0;
|
|
2134
2401
|
animatorFunctions[textureKey] = () => {
|
|
2135
|
-
var _a2;
|
|
2136
2402
|
if (t++ >= frameTime) {
|
|
2137
2403
|
t = 0;
|
|
2138
|
-
const frames =
|
|
2404
|
+
const frames = meta?.animation?.frames;
|
|
2139
2405
|
const frame = frames ? frames[f] : f;
|
|
2140
2406
|
image.putData(texture.getFrameSectionData(frame), x, y, 0, 0, maxWidth, maxWidth);
|
|
2141
2407
|
f++;
|
|
@@ -2153,10 +2419,10 @@ var UVMapper = class {
|
|
|
2153
2419
|
}
|
|
2154
2420
|
}
|
|
2155
2421
|
const atlasImageData = image.toDataURL();
|
|
2156
|
-
console.log(
|
|
2422
|
+
console.log(p5, "Atlas Image for", model.key, atlasImageData);
|
|
2157
2423
|
this.fillMissingTextureKeys(model.textures, positions);
|
|
2158
2424
|
if (isItemModel) {
|
|
2159
|
-
console.debug(
|
|
2425
|
+
console.debug(p5, "Generating item model for", model);
|
|
2160
2426
|
model.elements = [];
|
|
2161
2427
|
for (let layerName of ModelGenerator.ITEM_LAYERS) {
|
|
2162
2428
|
const textureImage = textureMap[layerName];
|
|
@@ -2164,7 +2430,7 @@ var UVMapper = class {
|
|
|
2164
2430
|
model.elements.push(...ModelGenerator.generateItemModel(textureImage.data, layerName));
|
|
2165
2431
|
}
|
|
2166
2432
|
}
|
|
2167
|
-
console.debug(
|
|
2433
|
+
console.debug(p5, "Item model elements", model.elements);
|
|
2168
2434
|
}
|
|
2169
2435
|
if (!model.elements) {
|
|
2170
2436
|
}
|
|
@@ -2182,17 +2448,13 @@ var UVMapper = class {
|
|
|
2182
2448
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2183
2449
|
continue;
|
|
2184
2450
|
}
|
|
2451
|
+
if (!face.texture) continue;
|
|
2185
2452
|
if (!face.uv) {
|
|
2186
2453
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2187
2454
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
if (faceTexture) {
|
|
2192
|
-
faceTexture = faceTexture.substr(1);
|
|
2193
|
-
texPosition = positions[faceTexture] || [0, 0];
|
|
2194
|
-
texSize = sizes[faceTexture] || [16, 16];
|
|
2195
|
-
}
|
|
2455
|
+
const faceTexture = face.texture.substr(1);
|
|
2456
|
+
const texPosition = positions[faceTexture] || [0, 0];
|
|
2457
|
+
const texSize = sizes[faceTexture] || [16, 16];
|
|
2196
2458
|
let texPosV = new Vector2(texPosition[0], texPosition[1]);
|
|
2197
2459
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2198
2460
|
tl.add(texPosV);
|
|
@@ -2224,7 +2486,7 @@ var UVMapper = class {
|
|
|
2224
2486
|
hasTransparency
|
|
2225
2487
|
);
|
|
2226
2488
|
} else {
|
|
2227
|
-
console.warn(
|
|
2489
|
+
console.warn(p5, "Model does not have any textures", model);
|
|
2228
2490
|
}
|
|
2229
2491
|
return void 0;
|
|
2230
2492
|
}
|
|
@@ -2362,17 +2624,20 @@ function shutdown() {
|
|
|
2362
2624
|
}
|
|
2363
2625
|
|
|
2364
2626
|
// src/assets/Entities.ts
|
|
2365
|
-
import { Memoize as Memoize3 } from "typescript-memoize";
|
|
2366
2627
|
var Entities = class {
|
|
2367
2628
|
static async getBlockEntityModels() {
|
|
2368
2629
|
const key = AssetKey.parse("models", "minerender:blockEntityModels");
|
|
2369
2630
|
console.log(key);
|
|
2370
|
-
return
|
|
2631
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2632
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2633
|
+
});
|
|
2371
2634
|
}
|
|
2372
2635
|
static async getEntityModels() {
|
|
2373
2636
|
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2374
2637
|
console.log(key);
|
|
2375
|
-
return
|
|
2638
|
+
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2639
|
+
return AssetLoader.get(key, "json" /* JSON */);
|
|
2640
|
+
});
|
|
2376
2641
|
}
|
|
2377
2642
|
// BlockEntity names are hardcoded
|
|
2378
2643
|
static async getBlockList() {
|
|
@@ -2418,19 +2683,13 @@ var Entities = class {
|
|
|
2418
2683
|
};
|
|
2419
2684
|
}
|
|
2420
2685
|
};
|
|
2421
|
-
__decorateClass([
|
|
2422
|
-
Memoize3()
|
|
2423
|
-
], Entities, "getBlockEntityModels", 1);
|
|
2424
|
-
__decorateClass([
|
|
2425
|
-
Memoize3()
|
|
2426
|
-
], Entities, "getEntityModels", 1);
|
|
2427
2686
|
var EntityModels = class {
|
|
2428
2687
|
};
|
|
2429
2688
|
var BlockEntityModels = class {
|
|
2430
2689
|
};
|
|
2431
2690
|
|
|
2432
2691
|
// src/renderer/SceneObject.ts
|
|
2433
|
-
import { Euler, InstancedMesh, MathUtils, Matrix4 as Matrix42, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion2, Vector3 as
|
|
2692
|
+
import { Euler as Euler2, InstancedMesh, MathUtils, Matrix4 as Matrix42, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion2, Vector3 as Vector34 } from "three";
|
|
2434
2693
|
|
|
2435
2694
|
// src/instance/InstanceReference.ts
|
|
2436
2695
|
var InstanceReference = class {
|
|
@@ -2487,18 +2746,26 @@ var MineRenderError = class _MineRenderError extends Error {
|
|
|
2487
2746
|
};
|
|
2488
2747
|
|
|
2489
2748
|
// src/renderer/SceneObject.ts
|
|
2490
|
-
var
|
|
2491
|
-
var
|
|
2492
|
-
var
|
|
2749
|
+
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2750
|
+
var p6 = prefix("SceneObject");
|
|
2751
|
+
var SceneObject = class _SceneObject extends Object3D2 {
|
|
2493
2752
|
constructor(options) {
|
|
2494
2753
|
super();
|
|
2495
2754
|
this.isSceneObject = true;
|
|
2496
2755
|
this.materialCallbacks = {};
|
|
2497
2756
|
this._isInstanced = false;
|
|
2498
2757
|
this._instanceCounter = 0;
|
|
2499
|
-
this.options = (0,
|
|
2758
|
+
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2500
2759
|
console.log("SceneObject options", this.options);
|
|
2501
2760
|
}
|
|
2761
|
+
static {
|
|
2762
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge3.default)({}, {
|
|
2763
|
+
instanceMeshes: true,
|
|
2764
|
+
maxInstanceCount: 50,
|
|
2765
|
+
mergeMeshes: true,
|
|
2766
|
+
wireframe: false
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2502
2769
|
set scene(scene) {
|
|
2503
2770
|
if (!!this._scene) throw new MineRenderError("Scene already set");
|
|
2504
2771
|
this._scene = scene;
|
|
@@ -2590,6 +2857,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2590
2857
|
}
|
|
2591
2858
|
createInstancedMesh(name, geometry, material, count) {
|
|
2592
2859
|
const mesh = new InstancedMesh(geometry, material, count);
|
|
2860
|
+
mesh.count = 0;
|
|
2593
2861
|
if (name) {
|
|
2594
2862
|
mesh.name = `mesh:${name}`;
|
|
2595
2863
|
}
|
|
@@ -2667,9 +2935,13 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2667
2935
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2668
2936
|
const i = this._instanceCounter++;
|
|
2669
2937
|
this.setMatrixAt(i, new Matrix42());
|
|
2670
|
-
|
|
2938
|
+
const mesh = this.children[0];
|
|
2939
|
+
if (mesh && isInstancedMesh(mesh)) {
|
|
2940
|
+
mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
|
|
2941
|
+
}
|
|
2942
|
+
console.debug(p6, "nextInstance " + i);
|
|
2671
2943
|
if (i === this.options.maxInstanceCount) {
|
|
2672
|
-
console.warn(
|
|
2944
|
+
console.warn(p6, "Max instance count reached for " + this);
|
|
2673
2945
|
}
|
|
2674
2946
|
if (this.scene) {
|
|
2675
2947
|
this.scene.stats.instanceCount++;
|
|
@@ -2698,9 +2970,9 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2698
2970
|
}
|
|
2699
2971
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
2700
2972
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2701
|
-
const oldPosition = new
|
|
2973
|
+
const oldPosition = new Vector34();
|
|
2702
2974
|
const oldRotation = new Quaternion2();
|
|
2703
|
-
const oldScale = new
|
|
2975
|
+
const oldScale = new Vector34();
|
|
2704
2976
|
const matrix = new Matrix42();
|
|
2705
2977
|
if (!scale || !rotation || !position) {
|
|
2706
2978
|
this.getMatrixAt(index, matrix).decompose(oldPosition, oldRotation, oldScale);
|
|
@@ -2716,7 +2988,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2716
2988
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2717
2989
|
this.setPositionRotationScaleAt(index, position);
|
|
2718
2990
|
}
|
|
2719
|
-
getPositionAt(index, vector = new
|
|
2991
|
+
getPositionAt(index, vector = new Vector34()) {
|
|
2720
2992
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2721
2993
|
const matrix = this.getMatrixAt(index);
|
|
2722
2994
|
vector.setFromMatrixPosition(matrix);
|
|
@@ -2726,7 +2998,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2726
2998
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2727
2999
|
this.setPositionRotationScaleAt(index, void 0, rotation, void 0);
|
|
2728
3000
|
}
|
|
2729
|
-
getRotationAt(index, euler = new
|
|
3001
|
+
getRotationAt(index, euler = new Euler2()) {
|
|
2730
3002
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2731
3003
|
const matrix = this.getMatrixAt(index);
|
|
2732
3004
|
euler.setFromRotationMatrix(matrix);
|
|
@@ -2736,7 +3008,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2736
3008
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2737
3009
|
this.setPositionRotationScaleAt(index, void 0, void 0, scale);
|
|
2738
3010
|
}
|
|
2739
|
-
getScaleAt(index, vector = new
|
|
3011
|
+
getScaleAt(index, vector = new Vector34()) {
|
|
2740
3012
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2741
3013
|
const matrix = this.getMatrixAt(index);
|
|
2742
3014
|
vector.setFromMatrixScale(matrix);
|
|
@@ -2840,34 +3112,29 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2840
3112
|
this.notifyDirty();
|
|
2841
3113
|
}
|
|
2842
3114
|
removeFromScene() {
|
|
2843
|
-
|
|
2844
|
-
(_a = this._scene) == null ? void 0 : _a.remove(this);
|
|
3115
|
+
this._scene?.remove(this);
|
|
2845
3116
|
this.notifyDirty();
|
|
2846
3117
|
}
|
|
2847
3118
|
//</editor-fold>
|
|
2848
3119
|
};
|
|
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
3120
|
function isSceneObject(obj) {
|
|
2857
3121
|
return obj.isSceneObject;
|
|
2858
3122
|
}
|
|
2859
3123
|
|
|
2860
3124
|
// src/entity/scene/EntityObject.ts
|
|
2861
|
-
var
|
|
3125
|
+
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
2862
3126
|
import { Object3D as Object3D3 } from "three";
|
|
2863
|
-
import * as
|
|
3127
|
+
import * as THREE3 from "three";
|
|
2864
3128
|
var EntityObject = class extends SceneObject {
|
|
2865
3129
|
constructor(entity, options) {
|
|
2866
3130
|
super();
|
|
2867
3131
|
this.entity = entity;
|
|
2868
3132
|
this.isEntityObject = true;
|
|
2869
3133
|
this.meshesCreated = false;
|
|
2870
|
-
this.options = (0,
|
|
3134
|
+
this.options = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
3135
|
+
}
|
|
3136
|
+
static {
|
|
3137
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
2871
3138
|
}
|
|
2872
3139
|
async init() {
|
|
2873
3140
|
this.createMeshes();
|
|
@@ -2876,17 +3143,19 @@ var EntityObject = class extends SceneObject {
|
|
|
2876
3143
|
dispose() {
|
|
2877
3144
|
super.dispose();
|
|
2878
3145
|
}
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
((_a = this.entity.key) == null ? void 0 : _a.namespace) ?? DEFAULT_NAMESPACE,
|
|
3146
|
+
get textureKey() {
|
|
3147
|
+
return new AssetKey(
|
|
3148
|
+
this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
|
|
2883
3149
|
this.entity.key.path,
|
|
2884
3150
|
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
2885
3151
|
"textures",
|
|
2886
3152
|
"entity",
|
|
2887
3153
|
"assets",
|
|
2888
3154
|
".png"
|
|
2889
|
-
)
|
|
3155
|
+
);
|
|
3156
|
+
}
|
|
3157
|
+
async loadTextures() {
|
|
3158
|
+
this.imageData = await ModelTextures.get(this.textureKey);
|
|
2890
3159
|
}
|
|
2891
3160
|
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
2892
3161
|
createMeshes(force = false) {
|
|
@@ -2905,8 +3174,8 @@ var EntityObject = class extends SceneObject {
|
|
|
2905
3174
|
const l = cube.maxZ - cube.minZ;
|
|
2906
3175
|
const uv = texture.toUvArray(w, h, l);
|
|
2907
3176
|
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
2908
|
-
cubeGeo.applyMatrix4(new
|
|
2909
|
-
cubeGeo.applyMatrix4(new
|
|
3177
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3178
|
+
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
2910
3179
|
applyModelPartRotation(part, cubeGeo);
|
|
2911
3180
|
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
2912
3181
|
partAnchor.add(mesh);
|
|
@@ -2919,24 +3188,25 @@ var EntityObject = class extends SceneObject {
|
|
|
2919
3188
|
this.meshesCreated = true;
|
|
2920
3189
|
}
|
|
2921
3190
|
async applyTextures() {
|
|
2922
|
-
|
|
2923
|
-
const
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
this.
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
3191
|
+
const assetKeyStr = this.textureKey.serialize();
|
|
3192
|
+
const keyStr = `entity:${assetKeyStr}`;
|
|
3193
|
+
let mat = Caching.materialCache.getIfPresent(keyStr);
|
|
3194
|
+
if (!mat) {
|
|
3195
|
+
const pending = this.loadTextures();
|
|
3196
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
3197
|
+
await pending;
|
|
3198
|
+
if (!this.imageData) return;
|
|
3199
|
+
const canvas = this.imageData.data.canvas;
|
|
3200
|
+
const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
|
|
3201
|
+
mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
3202
|
+
this.imageData = void 0;
|
|
3203
|
+
}
|
|
3204
|
+
this.iterateAllMeshes((mesh) => {
|
|
3205
|
+
mesh.material = mat;
|
|
3206
|
+
});
|
|
3207
|
+
this.notifyDirty();
|
|
2937
3208
|
}
|
|
2938
3209
|
};
|
|
2939
|
-
EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
2940
3210
|
function isEntityObject(obj) {
|
|
2941
3211
|
return obj.isEntityObject;
|
|
2942
3212
|
}
|
|
@@ -2948,7 +3218,7 @@ var GuiObject = class extends SceneObject {
|
|
|
2948
3218
|
|
|
2949
3219
|
// src/inspector/SceneInspector.ts
|
|
2950
3220
|
import { Raycaster, Vector2 as Vector22 } from "three";
|
|
2951
|
-
var
|
|
3221
|
+
var p7 = prefix("SceneInspector");
|
|
2952
3222
|
var help = "<span>Ctrl+Click to Select<br/></span><br/>";
|
|
2953
3223
|
var SceneInspector = class {
|
|
2954
3224
|
constructor(renderer) {
|
|
@@ -2977,8 +3247,7 @@ var SceneInspector = class {
|
|
|
2977
3247
|
return out;
|
|
2978
3248
|
}
|
|
2979
3249
|
onClick(event) {
|
|
2980
|
-
|
|
2981
|
-
if (((_a = event.target) == null ? void 0 : _a.nodeName) !== "CANVAS") return;
|
|
3250
|
+
if (event.target?.nodeName !== "CANVAS") return;
|
|
2982
3251
|
if (!event.ctrlKey) return;
|
|
2983
3252
|
setTimeout(() => {
|
|
2984
3253
|
this.mouse.x = event.clientX / window.innerWidth * 2 - 1;
|
|
@@ -3018,7 +3287,7 @@ var SceneInspector = class {
|
|
|
3018
3287
|
}
|
|
3019
3288
|
selectObject(targetObject, targetIntersection) {
|
|
3020
3289
|
this.selectedObject = targetObject;
|
|
3021
|
-
console.log(
|
|
3290
|
+
console.log(p7, "selected", targetObject);
|
|
3022
3291
|
this.redraw(targetObject, targetIntersection);
|
|
3023
3292
|
}
|
|
3024
3293
|
redraw(targetObject, targetIntersection) {
|
|
@@ -3316,7 +3585,7 @@ var SceneStatsDisplay = class {
|
|
|
3316
3585
|
};
|
|
3317
3586
|
|
|
3318
3587
|
// src/instance/InstanceManager.ts
|
|
3319
|
-
var
|
|
3588
|
+
var p8 = prefix("InstanceManager");
|
|
3320
3589
|
var InstanceManager = class {
|
|
3321
3590
|
constructor() {
|
|
3322
3591
|
this.isInstanceManager = true;
|
|
@@ -3324,7 +3593,7 @@ var InstanceManager = class {
|
|
|
3324
3593
|
}
|
|
3325
3594
|
async get(key) {
|
|
3326
3595
|
if (key in this.instanceCache) {
|
|
3327
|
-
console.debug(
|
|
3596
|
+
console.debug(p8, "key in cache", key);
|
|
3328
3597
|
return (await this.instanceCache[key]).nextInstance();
|
|
3329
3598
|
}
|
|
3330
3599
|
return void 0;
|
|
@@ -3333,13 +3602,17 @@ var InstanceManager = class {
|
|
|
3333
3602
|
if (key in this.instanceCache) {
|
|
3334
3603
|
return await this.get(key);
|
|
3335
3604
|
}
|
|
3336
|
-
console.debug(
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
})
|
|
3342
|
-
|
|
3605
|
+
console.debug(p8, "key not in cache", key);
|
|
3606
|
+
const pending = Promise.resolve().then(supplier).then((obj) => obj.nextInstance());
|
|
3607
|
+
this.instanceCache[key] = pending;
|
|
3608
|
+
try {
|
|
3609
|
+
return await pending;
|
|
3610
|
+
} catch (error) {
|
|
3611
|
+
if (this.instanceCache[key] === pending) {
|
|
3612
|
+
delete this.instanceCache[key];
|
|
3613
|
+
}
|
|
3614
|
+
throw error;
|
|
3615
|
+
}
|
|
3343
3616
|
}
|
|
3344
3617
|
reset() {
|
|
3345
3618
|
for (let instanceCacheKey in this.instanceCache) {
|
|
@@ -3392,8 +3665,93 @@ function isQuadArray(obj) {
|
|
|
3392
3665
|
return Array.isArray(obj) && obj.length === 4;
|
|
3393
3666
|
}
|
|
3394
3667
|
|
|
3668
|
+
// src/model/block/blockTints.json
|
|
3669
|
+
var blockTints_default = {
|
|
3670
|
+
"minecraft:large_fern": { source: "grass" },
|
|
3671
|
+
"minecraft:tall_grass": { source: "grass" },
|
|
3672
|
+
"minecraft:grass_block": { source: "grass" },
|
|
3673
|
+
"minecraft:fern": { source: "grass" },
|
|
3674
|
+
"minecraft:grass": { source: "grass" },
|
|
3675
|
+
"minecraft:short_grass": { source: "grass" },
|
|
3676
|
+
"minecraft:potted_fern": { source: "grass" },
|
|
3677
|
+
"minecraft:bush": { source: "grass" },
|
|
3678
|
+
"minecraft:pink_petals": { source: "grass", untinted: [0] },
|
|
3679
|
+
"minecraft:wildflowers": { source: "grass", untinted: [0] },
|
|
3680
|
+
"minecraft:spruce_leaves": { source: "constant", color: 6396257 },
|
|
3681
|
+
"minecraft:birch_leaves": { source: "constant", color: 8431445 },
|
|
3682
|
+
"minecraft:oak_leaves": { source: "constant", color: 4764952 },
|
|
3683
|
+
"minecraft:jungle_leaves": { source: "constant", color: 4764952 },
|
|
3684
|
+
"minecraft:acacia_leaves": { source: "constant", color: 4764952 },
|
|
3685
|
+
"minecraft:dark_oak_leaves": { source: "constant", color: 4764952 },
|
|
3686
|
+
"minecraft:vine": { source: "constant", color: 4764952 },
|
|
3687
|
+
"minecraft:mangrove_leaves": { source: "constant", color: 4764952 },
|
|
3688
|
+
"minecraft:leaf_litter": { source: "constant", color: 6044722 },
|
|
3689
|
+
"minecraft:water_cauldron": { source: "constant", color: 4159204 },
|
|
3690
|
+
"minecraft:redstone_wire": { source: "redstone" },
|
|
3691
|
+
"minecraft:attached_melon_stem": { source: "constant", color: 14731036 },
|
|
3692
|
+
"minecraft:attached_pumpkin_stem": { source: "constant", color: 14731036 },
|
|
3693
|
+
"minecraft:melon_stem": { source: "stem" },
|
|
3694
|
+
"minecraft:pumpkin_stem": { source: "stem" },
|
|
3695
|
+
"minecraft:lily_pad": { source: "constant", color: 7455580 }
|
|
3696
|
+
};
|
|
3697
|
+
|
|
3698
|
+
// src/model/block/BlockTints.ts
|
|
3699
|
+
var rules = blockTints_default;
|
|
3700
|
+
var BlockTints = class {
|
|
3701
|
+
/** Resolves block preview colors without biome context; explicit tints take precedence. */
|
|
3702
|
+
static async get(key, state, model, tints) {
|
|
3703
|
+
const rule = key && rules[key.toNamespacedString()];
|
|
3704
|
+
if (!key || !rule) return tints;
|
|
3705
|
+
const indices = /* @__PURE__ */ new Set();
|
|
3706
|
+
for (const element of model.elements ?? []) {
|
|
3707
|
+
for (const face of Object.values(element.faces)) {
|
|
3708
|
+
const index = face?.tintindex;
|
|
3709
|
+
if (index !== void 0 && index >= 0 && tints?.[index] === void 0 && !rule.untinted?.includes(index)) {
|
|
3710
|
+
indices.add(index);
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
if (!indices.size) return tints;
|
|
3715
|
+
let color;
|
|
3716
|
+
switch (rule.source) {
|
|
3717
|
+
case "constant":
|
|
3718
|
+
color = rule.color;
|
|
3719
|
+
break;
|
|
3720
|
+
case "grass":
|
|
3721
|
+
color = await this.grassColor(key);
|
|
3722
|
+
break;
|
|
3723
|
+
case "redstone": {
|
|
3724
|
+
const power = Number(state.power ?? 0) / 15;
|
|
3725
|
+
const red = power * 0.6 + (power > 0 ? 0.4 : 0.3);
|
|
3726
|
+
const green = Math.max(0, power * power * 0.7 - 0.5);
|
|
3727
|
+
const blue = Math.max(0, power * power * 0.6 - 0.7);
|
|
3728
|
+
color = Math.floor(red * 255) << 16 | Math.floor(green * 255) << 8 | Math.floor(blue * 255);
|
|
3729
|
+
break;
|
|
3730
|
+
}
|
|
3731
|
+
case "stem": {
|
|
3732
|
+
const age = Number(state.age ?? 0);
|
|
3733
|
+
color = age * 32 << 16 | 255 - age * 8 << 8 | age * 4;
|
|
3734
|
+
break;
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
return { ...Object.fromEntries([...indices].map((index) => [index, color])), ...tints };
|
|
3738
|
+
}
|
|
3739
|
+
static async grassColor(origin) {
|
|
3740
|
+
const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
|
|
3741
|
+
return await Caching.blockTintCache.get(key.serialize(), async () => {
|
|
3742
|
+
const image = await ModelTextures.get(key);
|
|
3743
|
+
if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
|
|
3744
|
+
if (image.width !== 256 || image.height !== 256) {
|
|
3745
|
+
throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
|
|
3746
|
+
}
|
|
3747
|
+
const [red, green, blue] = image.data.getImageData(127, 127, 1, 1).data;
|
|
3748
|
+
return red << 16 | green << 8 | blue;
|
|
3749
|
+
});
|
|
3750
|
+
}
|
|
3751
|
+
};
|
|
3752
|
+
|
|
3395
3753
|
// src/model/scene/ModelObject.ts
|
|
3396
|
-
import { BoxGeometry as BoxGeometry5, Matrix4 as Matrix45 } from "three";
|
|
3754
|
+
import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix45 } from "three";
|
|
3397
3755
|
|
|
3398
3756
|
// src/three/BufferGeometryUtils.js
|
|
3399
3757
|
import {
|
|
@@ -3405,7 +3763,7 @@ import {
|
|
|
3405
3763
|
TriangleFanDrawMode,
|
|
3406
3764
|
TriangleStripDrawMode,
|
|
3407
3765
|
TrianglesDrawMode,
|
|
3408
|
-
Vector3 as
|
|
3766
|
+
Vector3 as Vector36
|
|
3409
3767
|
} from "three";
|
|
3410
3768
|
function computeTangents(geometry) {
|
|
3411
3769
|
geometry.computeTangents();
|
|
@@ -3724,15 +4082,15 @@ function computeMorphedAttributes(object) {
|
|
|
3724
4082
|
console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
|
|
3725
4083
|
return null;
|
|
3726
4084
|
}
|
|
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
|
|
4085
|
+
const _vA = new Vector36();
|
|
4086
|
+
const _vB = new Vector36();
|
|
4087
|
+
const _vC = new Vector36();
|
|
4088
|
+
const _tempA = new Vector36();
|
|
4089
|
+
const _tempB = new Vector36();
|
|
4090
|
+
const _tempC = new Vector36();
|
|
4091
|
+
const _morphA = new Vector36();
|
|
4092
|
+
const _morphB = new Vector36();
|
|
4093
|
+
const _morphC = new Vector36();
|
|
3736
4094
|
function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
|
|
3737
4095
|
_vA.fromBufferAttribute(attribute, a2);
|
|
3738
4096
|
_vB.fromBufferAttribute(attribute, b2);
|
|
@@ -3938,26 +4296,29 @@ function computeMorphedAttributes(object) {
|
|
|
3938
4296
|
}
|
|
3939
4297
|
|
|
3940
4298
|
// src/model/scene/ModelObject.ts
|
|
3941
|
-
var
|
|
3942
|
-
var
|
|
3943
|
-
var
|
|
4299
|
+
var import_ts_deepmerge5 = __toESM(require_dist());
|
|
4300
|
+
var p9 = prefix("ModelObject");
|
|
4301
|
+
var ModelObject = class _ModelObject extends SceneObject {
|
|
3944
4302
|
constructor(originalModel, options) {
|
|
3945
4303
|
super(options);
|
|
3946
4304
|
this.originalModel = originalModel;
|
|
3947
4305
|
this.isModelObject = true;
|
|
3948
4306
|
this.meshesCreated = false;
|
|
3949
|
-
this.options = (0,
|
|
4307
|
+
this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
|
|
4308
|
+
if (this.options.tints) this.options.tints = { ...this.options.tints };
|
|
3950
4309
|
console.log("ModelObject options", this.options);
|
|
3951
4310
|
}
|
|
4311
|
+
static {
|
|
4312
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4313
|
+
}
|
|
3952
4314
|
async init() {
|
|
3953
4315
|
await this.loadTextures();
|
|
3954
4316
|
this.createMeshes();
|
|
3955
4317
|
this.applyTextures();
|
|
3956
4318
|
}
|
|
3957
4319
|
dispose() {
|
|
3958
|
-
var _a;
|
|
3959
4320
|
super.dispose();
|
|
3960
|
-
|
|
4321
|
+
this.atlas?.dispose();
|
|
3961
4322
|
}
|
|
3962
4323
|
get textureAtlas() {
|
|
3963
4324
|
return this.atlas;
|
|
@@ -3967,14 +4328,30 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
3967
4328
|
this.atlas = await UVMapper.getAtlas(this.originalModel);
|
|
3968
4329
|
}
|
|
3969
4330
|
createMeshes(force = false) {
|
|
3970
|
-
var _a;
|
|
3971
4331
|
if (this.meshesCreated && !force) return;
|
|
3972
4332
|
const mat = Materials.MISSING_TEXTURE;
|
|
3973
4333
|
let allGeos = [];
|
|
3974
4334
|
if (this.atlas) {
|
|
3975
4335
|
if (this.atlas.model.elements) {
|
|
3976
|
-
|
|
4336
|
+
this.atlas.model.elements?.forEach((el) => {
|
|
3977
4337
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4338
|
+
if (this.options.uvLockRotation) {
|
|
4339
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler4(...this.options.uvLockRotation));
|
|
4340
|
+
}
|
|
4341
|
+
if (this.options.tints) {
|
|
4342
|
+
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
4343
|
+
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
4344
|
+
const tintIndex = el.faces[faceName]?.tintindex;
|
|
4345
|
+
if (tintIndex === void 0 || tintIndex < 0) continue;
|
|
4346
|
+
const tint = this.options.tints[tintIndex];
|
|
4347
|
+
if (tint === void 0) continue;
|
|
4348
|
+
const color = new Color3(tint);
|
|
4349
|
+
for (let vertex = 0; vertex < 4; vertex++) {
|
|
4350
|
+
color.toArray(colors, (faceIndex * 4 + vertex) * 3);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
elGeo.setAttribute("color", new BufferAttribute4(colors, 3));
|
|
4354
|
+
}
|
|
3978
4355
|
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
4356
|
elGeo.applyMatrix4(new Matrix45().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
3980
4357
|
if (el.rotation) {
|
|
@@ -3991,10 +4368,10 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
3991
4368
|
}
|
|
3992
4369
|
});
|
|
3993
4370
|
} else {
|
|
3994
|
-
console.debug(
|
|
4371
|
+
console.debug(p9, this.atlas.model, "has no elements");
|
|
3995
4372
|
}
|
|
3996
4373
|
} else {
|
|
3997
|
-
console.debug(
|
|
4374
|
+
console.debug(p9, "Missing atlas for", this);
|
|
3998
4375
|
}
|
|
3999
4376
|
if (this.options.mergeMeshes) {
|
|
4000
4377
|
let combinedGeo;
|
|
@@ -4031,6 +4408,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4031
4408
|
/*TODO: get this from render options*/
|
|
4032
4409
|
);
|
|
4033
4410
|
this.iterateAllMeshes((mesh) => {
|
|
4411
|
+
if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
|
|
4034
4412
|
mesh.material = mat;
|
|
4035
4413
|
});
|
|
4036
4414
|
if (this.atlas.hasAnimation) {
|
|
@@ -4046,17 +4424,25 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4046
4424
|
}
|
|
4047
4425
|
}
|
|
4048
4426
|
};
|
|
4049
|
-
_ModelObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
4050
|
-
var ModelObject = _ModelObject;
|
|
4051
4427
|
function isModelObject(obj) {
|
|
4052
4428
|
return obj.isModelObject;
|
|
4053
4429
|
}
|
|
4054
4430
|
|
|
4055
4431
|
// src/model/block/scene/BlockObject.ts
|
|
4056
|
-
var
|
|
4057
|
-
import { Euler as
|
|
4058
|
-
var
|
|
4059
|
-
|
|
4432
|
+
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4433
|
+
import { Euler as Euler5, Matrix4 as Matrix46, Vector3 as Vector37 } from "three";
|
|
4434
|
+
var p10 = prefix("BlockObject");
|
|
4435
|
+
function matchesCondition(condition, state) {
|
|
4436
|
+
return Object.entries(condition).every(([key, value]) => {
|
|
4437
|
+
if (Array.isArray(value)) {
|
|
4438
|
+
if (key === "OR") return value.some((child) => matchesCondition(child, state));
|
|
4439
|
+
if (key === "AND") return value.every((child) => matchesCondition(child, state));
|
|
4440
|
+
return false;
|
|
4441
|
+
}
|
|
4442
|
+
return typeof value === "string" && state[key] !== void 0 && value.split("|").includes(`${state[key]}`);
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
var BlockObject = class _BlockObject extends SceneObject {
|
|
4060
4446
|
constructor(blockState, options) {
|
|
4061
4447
|
super(options);
|
|
4062
4448
|
this.blockState = blockState;
|
|
@@ -4069,11 +4455,16 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4069
4455
|
this._instanceModel = [];
|
|
4070
4456
|
this._variants = [];
|
|
4071
4457
|
this._models = [];
|
|
4072
|
-
this.options = (0,
|
|
4458
|
+
this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
|
|
4459
|
+
}
|
|
4460
|
+
static {
|
|
4461
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge6.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4462
|
+
applyDefaultState: true
|
|
4463
|
+
});
|
|
4073
4464
|
}
|
|
4074
4465
|
async init() {
|
|
4075
4466
|
if (this.options.applyDefaultState) {
|
|
4076
|
-
const defaultState = this.blockState.key ? BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4467
|
+
const defaultState = this.blockState.key ? await BlockStates.getDefaultState(this.blockState.key) : void 0;
|
|
4077
4468
|
if (defaultState && Object.keys(defaultState).length > 0) {
|
|
4078
4469
|
const state = {};
|
|
4079
4470
|
for (let k in defaultState) {
|
|
@@ -4084,15 +4475,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4084
4475
|
if (this.blockState.variants) {
|
|
4085
4476
|
await this.setState(Object.keys(this.blockState.variants)[0]);
|
|
4086
4477
|
} 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
|
-
}
|
|
4478
|
+
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4479
|
+
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4480
|
+
await this.setState(state);
|
|
4096
4481
|
}
|
|
4097
4482
|
}
|
|
4098
4483
|
} else {
|
|
@@ -4107,7 +4492,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4107
4492
|
if (isModelObject(model)) {
|
|
4108
4493
|
model.removeFromScene();
|
|
4109
4494
|
} else if (isInstanceReference(model)) {
|
|
4110
|
-
model.setScale(new
|
|
4495
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4111
4496
|
}
|
|
4112
4497
|
}
|
|
4113
4498
|
super.removeFromScene();
|
|
@@ -4149,55 +4534,11 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4149
4534
|
} else if (this.blockState.multipart) {
|
|
4150
4535
|
for (let part of this.blockState.multipart) {
|
|
4151
4536
|
if (!part.apply) {
|
|
4152
|
-
console.debug(
|
|
4537
|
+
console.debug(p10, "Missing apply for blockState part", part);
|
|
4153
4538
|
continue;
|
|
4154
4539
|
}
|
|
4155
|
-
if (!part.when) {
|
|
4540
|
+
if (!part.when || matchesCondition(part.when, state)) {
|
|
4156
4541
|
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
4542
|
}
|
|
4202
4543
|
}
|
|
4203
4544
|
}
|
|
@@ -4212,7 +4553,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4212
4553
|
}
|
|
4213
4554
|
for (let model of this._models) {
|
|
4214
4555
|
if (isInstanceReference(model)) {
|
|
4215
|
-
model.setScale(new
|
|
4556
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4216
4557
|
} else {
|
|
4217
4558
|
model.dispose();
|
|
4218
4559
|
}
|
|
@@ -4227,11 +4568,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4227
4568
|
}
|
|
4228
4569
|
}
|
|
4229
4570
|
getSingleVariant(variants) {
|
|
4230
|
-
if (Array.isArray(variants))
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4571
|
+
if (!Array.isArray(variants)) return variants;
|
|
4572
|
+
if (!variants.length) throw new MineRenderError("Blockstate variant arrays must not be empty");
|
|
4573
|
+
const total = variants.reduce((sum, variant) => {
|
|
4574
|
+
const weight = variant.weight ?? 1;
|
|
4575
|
+
if (!Number.isInteger(weight) || weight < 1) {
|
|
4576
|
+
throw new MineRenderError(`Invalid blockstate variant weight: ${weight}`);
|
|
4577
|
+
}
|
|
4578
|
+
return sum + weight;
|
|
4579
|
+
}, 0);
|
|
4580
|
+
let choice = Math.random() * total;
|
|
4581
|
+
for (const variant of variants) {
|
|
4582
|
+
choice -= variant.weight ?? 1;
|
|
4583
|
+
if (choice < 0) return variant;
|
|
4584
|
+
}
|
|
4585
|
+
return variants[variants.length - 1];
|
|
4235
4586
|
}
|
|
4236
4587
|
// @deprecated
|
|
4237
4588
|
async createAVariant(variants, instanceInfo) {
|
|
@@ -4239,28 +4590,25 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4239
4590
|
await this.createVariant(variant);
|
|
4240
4591
|
}
|
|
4241
4592
|
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);
|
|
4593
|
+
const rotation = new Euler5();
|
|
4249
4594
|
if (typeof variant.x !== "undefined") {
|
|
4250
4595
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4251
4596
|
}
|
|
4252
4597
|
if (typeof variant.y !== "undefined") {
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4598
|
+
rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
|
|
4599
|
+
}
|
|
4600
|
+
const model = await Models.getMerged(AssetKey.parse("models", variant.model));
|
|
4601
|
+
const options = {
|
|
4602
|
+
...this.options,
|
|
4603
|
+
tints: model ? await BlockTints.get(this.blockState.key, this.state, model, this.options.tints) : this.options.tints,
|
|
4604
|
+
uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
|
|
4605
|
+
};
|
|
4606
|
+
const obj = await this.scene.addModel(model, options);
|
|
4607
|
+
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4608
|
+
this._isInstanced = true;
|
|
4609
|
+
this._instanceCounter = 1;
|
|
4258
4610
|
}
|
|
4259
4611
|
obj.setRotation(rotation);
|
|
4260
|
-
setTimeout(() => {
|
|
4261
|
-
obj.setRotation(rotation);
|
|
4262
|
-
}, 150);
|
|
4263
|
-
console.log(obj);
|
|
4264
4612
|
return obj;
|
|
4265
4613
|
}
|
|
4266
4614
|
async resetState() {
|
|
@@ -4350,18 +4698,15 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4350
4698
|
}
|
|
4351
4699
|
}
|
|
4352
4700
|
setPosition(position) {
|
|
4353
|
-
|
|
4701
|
+
this.position.copy(position);
|
|
4354
4702
|
for (let model of this._models) {
|
|
4355
4703
|
model.setPosition(position);
|
|
4356
4704
|
}
|
|
4705
|
+
this.notifyDirty();
|
|
4357
4706
|
}
|
|
4358
4707
|
//TODO: should override rotation + scale methods
|
|
4359
4708
|
//TODO
|
|
4360
4709
|
};
|
|
4361
|
-
_BlockObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge7.default)({}, ModelObject.DEFAULT_OPTIONS, {
|
|
4362
|
-
applyDefaultState: true
|
|
4363
|
-
});
|
|
4364
|
-
var BlockObject = _BlockObject;
|
|
4365
4710
|
function isBlockObject(obj) {
|
|
4366
4711
|
return obj.isBlockObject;
|
|
4367
4712
|
}
|
|
@@ -4386,11 +4731,10 @@ var StructureParser = class {
|
|
|
4386
4731
|
throw new MineRenderError("Structure does not have palette(s)");
|
|
4387
4732
|
}
|
|
4388
4733
|
const blocks = nbt.blocks.value.value.map((block) => {
|
|
4389
|
-
var _a;
|
|
4390
4734
|
const state = palette.value.value[block.state.value];
|
|
4391
4735
|
if (state.Name.value === "minecraft:air") return void 0;
|
|
4392
4736
|
const props = {};
|
|
4393
|
-
for (let k in
|
|
4737
|
+
for (let k in state.Properties?.value) {
|
|
4394
4738
|
props[k] = state.Properties.value[k].value;
|
|
4395
4739
|
}
|
|
4396
4740
|
return {
|
|
@@ -4409,7 +4753,7 @@ var StructureParser = class {
|
|
|
4409
4753
|
|
|
4410
4754
|
// src/renderer/MineRenderScene.ts
|
|
4411
4755
|
import { Scene as Scene2 } from "three";
|
|
4412
|
-
var
|
|
4756
|
+
var import_ts_deepmerge8 = __toESM(require_dist());
|
|
4413
4757
|
|
|
4414
4758
|
// src/skin/SkinPart.ts
|
|
4415
4759
|
var SkinPart = /* @__PURE__ */ ((SkinPart2) => {
|
|
@@ -5140,7 +5484,7 @@ var slimSkinGeometries = {
|
|
|
5140
5484
|
};
|
|
5141
5485
|
|
|
5142
5486
|
// src/skin/scene/SkinObject.ts
|
|
5143
|
-
var
|
|
5487
|
+
var import_ts_deepmerge7 = __toESM(require_dist());
|
|
5144
5488
|
var SkinObject = class extends SceneObject {
|
|
5145
5489
|
constructor(options) {
|
|
5146
5490
|
super();
|
|
@@ -5148,7 +5492,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5148
5492
|
this.legacy = false;
|
|
5149
5493
|
this.skinTextureWidth = 64;
|
|
5150
5494
|
this.skinTextureHeight = 64;
|
|
5151
|
-
this.options = (0,
|
|
5495
|
+
this.options = (0, import_ts_deepmerge7.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
5152
5496
|
}
|
|
5153
5497
|
async init() {
|
|
5154
5498
|
this.createMeshes();
|
|
@@ -5252,7 +5596,7 @@ var SkinObject = class extends SceneObject {
|
|
|
5252
5596
|
};
|
|
5253
5597
|
|
|
5254
5598
|
// src/renderer/MineRenderScene.ts
|
|
5255
|
-
var
|
|
5599
|
+
var MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
5256
5600
|
constructor(options) {
|
|
5257
5601
|
super();
|
|
5258
5602
|
this.isMineRenderScene = true;
|
|
@@ -5261,12 +5605,14 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5261
5605
|
this.dirty = true;
|
|
5262
5606
|
this.observedObjects = /* @__PURE__ */ new Set();
|
|
5263
5607
|
this.onObjectChange = (event) => {
|
|
5264
|
-
|
|
5265
|
-
if (((_a = event.target) == null ? void 0 : _a.parent) === this) {
|
|
5608
|
+
if (event.target?.parent === this) {
|
|
5266
5609
|
this.dirty = true;
|
|
5267
5610
|
}
|
|
5268
5611
|
};
|
|
5269
|
-
this.options = (0,
|
|
5612
|
+
this.options = (0, import_ts_deepmerge8.default)({}, _MineRenderScene.DEFAULT_OPTIONS, options ?? {});
|
|
5613
|
+
}
|
|
5614
|
+
static {
|
|
5615
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge8.default)({}, {});
|
|
5270
5616
|
}
|
|
5271
5617
|
add(...objects) {
|
|
5272
5618
|
for (const object of objects) {
|
|
@@ -5274,7 +5620,7 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5274
5620
|
try {
|
|
5275
5621
|
super.add(object);
|
|
5276
5622
|
} finally {
|
|
5277
|
-
if (
|
|
5623
|
+
if (object?.isObject3D && object !== this) {
|
|
5278
5624
|
this.updateObjectRegistration(object, object.parent === this);
|
|
5279
5625
|
}
|
|
5280
5626
|
}
|
|
@@ -5317,15 +5663,20 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5317
5663
|
return this.add(...object);
|
|
5318
5664
|
}
|
|
5319
5665
|
async addSceneObject(asset, objectSupplier, _options, parent = this) {
|
|
5320
|
-
var _a, _b;
|
|
5321
5666
|
console.log("addSceneObject", asset);
|
|
5322
5667
|
console.log("parent", parent);
|
|
5323
5668
|
console.log(_options);
|
|
5324
5669
|
this.dirty = true;
|
|
5325
5670
|
const obj = await objectSupplier();
|
|
5326
|
-
if (
|
|
5671
|
+
if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
|
|
5327
5672
|
console.log("instanceMeshes + key");
|
|
5328
|
-
|
|
5673
|
+
let key = asset.key.serialize();
|
|
5674
|
+
if (isModelObject(obj)) {
|
|
5675
|
+
const { uvLockRotation, tints } = obj.options;
|
|
5676
|
+
if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
|
|
5677
|
+
const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
|
|
5678
|
+
if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
|
|
5679
|
+
}
|
|
5329
5680
|
return this.instanceManager.getOrCreate(key, async () => {
|
|
5330
5681
|
obj.scene = this;
|
|
5331
5682
|
await obj.init();
|
|
@@ -5363,472 +5714,19 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
5363
5714
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
5364
5715
|
}
|
|
5365
5716
|
};
|
|
5366
|
-
_MineRenderScene.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {});
|
|
5367
|
-
var MineRenderScene = _MineRenderScene;
|
|
5368
5717
|
function isMineRenderScene(obj) {
|
|
5369
5718
|
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
|
-
};
|
|
5719
|
+
}
|
|
5720
|
+
|
|
5721
|
+
// src/renderer/Renderer.ts
|
|
5722
|
+
import { AxesHelper as AxesHelper3, GridHelper, OrthographicCamera, PCFSoftShadowMap, PerspectiveCamera, SRGBColorSpace as SRGBColorSpace3, Vector3 as Vector39, WebGLRenderer } from "three";
|
|
5723
|
+
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
5724
|
+
import Stats from "stats.js";
|
|
5725
|
+
import { EffectComposer, RenderPass } from "postprocessing";
|
|
5828
5726
|
|
|
5829
5727
|
// src/three/OrbitControls.js
|
|
5830
5728
|
import {
|
|
5831
|
-
EventDispatcher
|
|
5729
|
+
EventDispatcher,
|
|
5832
5730
|
MOUSE,
|
|
5833
5731
|
Quaternion as Quaternion3,
|
|
5834
5732
|
Spherical,
|
|
@@ -5839,7 +5737,7 @@ import {
|
|
|
5839
5737
|
var _changeEvent = { type: "change" };
|
|
5840
5738
|
var _startEvent = { type: "start" };
|
|
5841
5739
|
var _endEvent = { type: "end" };
|
|
5842
|
-
var OrbitControls = class extends
|
|
5740
|
+
var OrbitControls = class extends EventDispatcher {
|
|
5843
5741
|
constructor(object, domElement) {
|
|
5844
5742
|
super();
|
|
5845
5743
|
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
@@ -6425,62 +6323,568 @@ var OrbitControls = class extends EventDispatcher2 {
|
|
|
6425
6323
|
state = STATE.NONE;
|
|
6426
6324
|
}
|
|
6427
6325
|
}
|
|
6428
|
-
function onTouchEnd(event) {
|
|
6429
|
-
handleTouchEnd(event);
|
|
6430
|
-
scope.dispatchEvent(_endEvent);
|
|
6431
|
-
state = STATE.NONE;
|
|
6326
|
+
function onTouchEnd(event) {
|
|
6327
|
+
handleTouchEnd(event);
|
|
6328
|
+
scope.dispatchEvent(_endEvent);
|
|
6329
|
+
state = STATE.NONE;
|
|
6330
|
+
}
|
|
6331
|
+
function onContextMenu(event) {
|
|
6332
|
+
if (scope.enabled === false) return;
|
|
6333
|
+
event.preventDefault();
|
|
6334
|
+
}
|
|
6335
|
+
function addPointer(event) {
|
|
6336
|
+
pointers.push(event);
|
|
6337
|
+
}
|
|
6338
|
+
function removePointer(event) {
|
|
6339
|
+
delete pointerPositions[event.pointerId];
|
|
6340
|
+
for (let i = 0; i < pointers.length; i++) {
|
|
6341
|
+
if (pointers[i].pointerId == event.pointerId) {
|
|
6342
|
+
pointers.splice(i, 1);
|
|
6343
|
+
return;
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
}
|
|
6347
|
+
function trackPointer(event) {
|
|
6348
|
+
let position = pointerPositions[event.pointerId];
|
|
6349
|
+
if (position === void 0) {
|
|
6350
|
+
position = new Vector23();
|
|
6351
|
+
pointerPositions[event.pointerId] = position;
|
|
6352
|
+
}
|
|
6353
|
+
position.set(event.pageX, event.pageY);
|
|
6354
|
+
}
|
|
6355
|
+
function getSecondPointerPosition(event) {
|
|
6356
|
+
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
6357
|
+
return pointerPositions[pointer.pointerId];
|
|
6358
|
+
}
|
|
6359
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
6360
|
+
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
6361
|
+
scope.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
6362
|
+
scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
6363
|
+
this.update();
|
|
6364
|
+
}
|
|
6365
|
+
};
|
|
6366
|
+
var MapControls = class extends OrbitControls {
|
|
6367
|
+
constructor(object, domElement) {
|
|
6368
|
+
super(object, domElement);
|
|
6369
|
+
this.screenSpacePanning = false;
|
|
6370
|
+
this.mouseButtons.LEFT = MOUSE.PAN;
|
|
6371
|
+
this.mouseButtons.RIGHT = MOUSE.ROTATE;
|
|
6372
|
+
this.touches.ONE = TOUCH.PAN;
|
|
6373
|
+
this.touches.TWO = TOUCH.DOLLY_ROTATE;
|
|
6374
|
+
}
|
|
6375
|
+
};
|
|
6376
|
+
|
|
6377
|
+
// src/renderer/Renderer.ts
|
|
6378
|
+
var Renderer = class _Renderer {
|
|
6379
|
+
constructor(options) {
|
|
6380
|
+
this._dirty = true;
|
|
6381
|
+
this._resizeListener = void 0;
|
|
6382
|
+
this._disposed = false;
|
|
6383
|
+
this._debugHelpers = [];
|
|
6384
|
+
this._eventDispatchers = /* @__PURE__ */ new Map();
|
|
6385
|
+
this._changeListener = () => {
|
|
6386
|
+
this._dirty = true;
|
|
6387
|
+
};
|
|
6388
|
+
this.options = (0, import_ts_deepmerge9.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
6389
|
+
this._animationLoop = this.animate.bind(this);
|
|
6390
|
+
this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
6391
|
+
this._scene = this.createScene();
|
|
6392
|
+
this._camera = this.createCamera();
|
|
6393
|
+
this._renderer = this.createRenderer();
|
|
6394
|
+
this._composer = this.createComposer();
|
|
6395
|
+
if (this.options.render.stats) {
|
|
6396
|
+
this._stats = new Stats();
|
|
6397
|
+
document.body.appendChild(this._stats.dom);
|
|
6398
|
+
}
|
|
6399
|
+
this.init();
|
|
6400
|
+
this._controls = this.createControls();
|
|
6401
|
+
}
|
|
6402
|
+
static {
|
|
6403
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
|
|
6404
|
+
camera: {
|
|
6405
|
+
type: "perspective",
|
|
6406
|
+
near: 1,
|
|
6407
|
+
far: 5e3,
|
|
6408
|
+
perspective: {
|
|
6409
|
+
aspect: void 0,
|
|
6410
|
+
fov: 50
|
|
6411
|
+
},
|
|
6412
|
+
orthographic: {
|
|
6413
|
+
left: void 0,
|
|
6414
|
+
right: void 0,
|
|
6415
|
+
top: void 0,
|
|
6416
|
+
bottom: void 0
|
|
6417
|
+
},
|
|
6418
|
+
position: new Vector39(50, 50, 50),
|
|
6419
|
+
lookingAt: new Vector39(0, 0, 0)
|
|
6420
|
+
},
|
|
6421
|
+
render: {
|
|
6422
|
+
fpsLimit: 60,
|
|
6423
|
+
stats: false,
|
|
6424
|
+
antialias: true,
|
|
6425
|
+
shade: true,
|
|
6426
|
+
autoResize: true,
|
|
6427
|
+
renderAlways: false
|
|
6428
|
+
},
|
|
6429
|
+
composer: {
|
|
6430
|
+
enabled: true
|
|
6431
|
+
},
|
|
6432
|
+
controls: {
|
|
6433
|
+
enabled: false
|
|
6434
|
+
},
|
|
6435
|
+
debug: {
|
|
6436
|
+
grid: false,
|
|
6437
|
+
axes: false
|
|
6438
|
+
}
|
|
6439
|
+
});
|
|
6440
|
+
}
|
|
6441
|
+
//<editor-fold desc="INIT">
|
|
6442
|
+
createScene() {
|
|
6443
|
+
return new MineRenderScene();
|
|
6444
|
+
}
|
|
6445
|
+
createCamera() {
|
|
6446
|
+
switch (this.options.camera.type) {
|
|
6447
|
+
case "perspective":
|
|
6448
|
+
default:
|
|
6449
|
+
return new PerspectiveCamera(
|
|
6450
|
+
this.options.camera.perspective.fov,
|
|
6451
|
+
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
6452
|
+
this.options.camera.near,
|
|
6453
|
+
this.options.camera.far
|
|
6454
|
+
);
|
|
6455
|
+
case "orthographic":
|
|
6456
|
+
return new OrthographicCamera(
|
|
6457
|
+
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
6458
|
+
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
6459
|
+
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
6460
|
+
this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
|
|
6461
|
+
this.options.camera.near,
|
|
6462
|
+
this.options.camera.far
|
|
6463
|
+
);
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
6466
|
+
createRenderer() {
|
|
6467
|
+
const renderer = new WebGLRenderer({
|
|
6468
|
+
antialias: this.options.render.antialias,
|
|
6469
|
+
alpha: true,
|
|
6470
|
+
powerPreference: "high-performance",
|
|
6471
|
+
depth: true
|
|
6472
|
+
});
|
|
6473
|
+
renderer.setClearColor(0, 0);
|
|
6474
|
+
renderer.shadowMap.enabled = true;
|
|
6475
|
+
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
6476
|
+
renderer.outputColorSpace = SRGBColorSpace3;
|
|
6477
|
+
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
6478
|
+
return renderer;
|
|
6479
|
+
}
|
|
6480
|
+
createComposer() {
|
|
6481
|
+
if (!this.options.composer.enabled) return void 0;
|
|
6482
|
+
const composer = new EffectComposer(this.renderer);
|
|
6483
|
+
composer.setSize(this.viewWidth, this.viewHeight);
|
|
6484
|
+
composer.addPass(new RenderPass(this.scene, this.camera));
|
|
6485
|
+
return composer;
|
|
6486
|
+
}
|
|
6487
|
+
createControls() {
|
|
6488
|
+
if (!this.options.controls?.enabled) return void 0;
|
|
6489
|
+
const position = this.camera.position.clone();
|
|
6490
|
+
const controls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
6491
|
+
this.camera.position.copy(position);
|
|
6492
|
+
const target = this.options.camera.lookingAt;
|
|
6493
|
+
if (isVector3(target)) {
|
|
6494
|
+
controls.target.copy(target);
|
|
6495
|
+
} else if (isTripleArray(target)) {
|
|
6496
|
+
controls.target.set(target[0], target[1], target[2]);
|
|
6497
|
+
}
|
|
6498
|
+
controls.update();
|
|
6499
|
+
controls.saveState();
|
|
6500
|
+
this.registerEventDispatcher(controls);
|
|
6501
|
+
return controls;
|
|
6502
|
+
}
|
|
6503
|
+
//</editor-fold>
|
|
6504
|
+
init() {
|
|
6505
|
+
if (this._disposed) return;
|
|
6506
|
+
if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
|
|
6507
|
+
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
6508
|
+
}
|
|
6509
|
+
if (this.options.debug.grid) {
|
|
6510
|
+
const gridHelper = new GridHelper(128, 16);
|
|
6511
|
+
this._debugHelpers.push(gridHelper);
|
|
6512
|
+
this.scene.add(gridHelper);
|
|
6513
|
+
const gridHelper2 = new GridHelper(128, 16);
|
|
6514
|
+
this._debugHelpers.push(gridHelper2);
|
|
6515
|
+
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
6516
|
+
this.scene.add(gridHelper2);
|
|
6517
|
+
const gridHelper3 = new GridHelper(128, 16);
|
|
6518
|
+
this._debugHelpers.push(gridHelper3);
|
|
6519
|
+
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
6520
|
+
this.scene.add(gridHelper3);
|
|
6521
|
+
}
|
|
6522
|
+
if (this.options.debug.axes) {
|
|
6523
|
+
const axesHelper = new AxesHelper3(64);
|
|
6524
|
+
this._debugHelpers.push(axesHelper);
|
|
6525
|
+
this.scene.add(axesHelper);
|
|
6526
|
+
}
|
|
6527
|
+
if (this.options.camera.position) {
|
|
6528
|
+
if (isVector3(this.options.camera.position)) {
|
|
6529
|
+
this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
|
|
6530
|
+
} else if (isTripleArray(this.options.camera.position)) {
|
|
6531
|
+
this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
|
|
6532
|
+
}
|
|
6533
|
+
}
|
|
6534
|
+
if (this.options.camera.lookingAt) {
|
|
6535
|
+
if (isVector3(this.options.camera.lookingAt)) {
|
|
6536
|
+
this.camera.lookAt(this.options.camera.lookingAt);
|
|
6537
|
+
} else if (isTripleArray(this.options.camera.lookingAt)) {
|
|
6538
|
+
this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
|
|
6539
|
+
}
|
|
6540
|
+
}
|
|
6541
|
+
if (this.options.render.autoResize && !this._resizeListener) {
|
|
6542
|
+
this._resizeListener = () => {
|
|
6543
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6544
|
+
};
|
|
6545
|
+
window.addEventListener("resize", this._resizeListener);
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
get element() {
|
|
6549
|
+
return this._element;
|
|
6550
|
+
}
|
|
6551
|
+
appendTo(element) {
|
|
6552
|
+
if (this._disposed) return;
|
|
6553
|
+
this._element = element;
|
|
6554
|
+
this._element.appendChild(this.renderer.domElement);
|
|
6555
|
+
if (this.viewWidth == 0) {
|
|
6556
|
+
console.warn("0 element width");
|
|
6557
|
+
}
|
|
6558
|
+
if (this.viewHeight == 0) {
|
|
6559
|
+
console.warn("0 element height");
|
|
6560
|
+
}
|
|
6561
|
+
this.resize(this.viewWidth, this.viewHeight);
|
|
6562
|
+
}
|
|
6563
|
+
/**
|
|
6564
|
+
* Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
|
|
6565
|
+
* The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
|
|
6566
|
+
*/
|
|
6567
|
+
registerEventDispatcher(dispatcher, changeEvent2 = "change") {
|
|
6568
|
+
if (this._disposed) return;
|
|
6569
|
+
let events = this._eventDispatchers.get(dispatcher);
|
|
6570
|
+
if (!events) {
|
|
6571
|
+
events = /* @__PURE__ */ new Set();
|
|
6572
|
+
this._eventDispatchers.set(dispatcher, events);
|
|
6573
|
+
}
|
|
6574
|
+
if (events.has(changeEvent2)) return;
|
|
6575
|
+
events.add(changeEvent2);
|
|
6576
|
+
dispatcher.addEventListener(changeEvent2, this._changeListener);
|
|
6577
|
+
}
|
|
6578
|
+
resize(width, height) {
|
|
6579
|
+
if (this._disposed) return;
|
|
6580
|
+
if (isPerspectiveCamera(this.camera)) {
|
|
6581
|
+
this.camera.aspect = width / height;
|
|
6582
|
+
this.camera.updateProjectionMatrix();
|
|
6583
|
+
} else if (isOrthographicCamera(this.camera)) {
|
|
6584
|
+
this.camera.left = width / -2;
|
|
6585
|
+
this.camera.right = width / 2;
|
|
6586
|
+
this.camera.top = height / 2;
|
|
6587
|
+
this.camera.bottom = height / -2;
|
|
6588
|
+
this.camera.updateProjectionMatrix();
|
|
6589
|
+
}
|
|
6590
|
+
this.renderer.setSize(width, height);
|
|
6591
|
+
this.composer?.setSize(width, height);
|
|
6592
|
+
this._dirty = true;
|
|
6593
|
+
}
|
|
6594
|
+
//<editor-fold desc="RENDER">
|
|
6595
|
+
get dirty() {
|
|
6596
|
+
return this._dirty || this.scene.dirty;
|
|
6597
|
+
}
|
|
6598
|
+
set dirty(dirty) {
|
|
6599
|
+
this._dirty = dirty;
|
|
6600
|
+
this.scene.dirty = dirty;
|
|
6601
|
+
}
|
|
6602
|
+
start() {
|
|
6603
|
+
if (this._disposed) return;
|
|
6604
|
+
this.stop();
|
|
6605
|
+
this.renderer.setAnimationLoop(this._animationLoop);
|
|
6606
|
+
}
|
|
6607
|
+
stop() {
|
|
6608
|
+
if (this._disposed) return;
|
|
6609
|
+
this.renderer.setAnimationLoop(null);
|
|
6610
|
+
this._nextFrameTime = void 0;
|
|
6611
|
+
}
|
|
6612
|
+
/**
|
|
6613
|
+
* Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
|
|
6614
|
+
* renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
|
|
6615
|
+
* controls must be managed by their owners.
|
|
6616
|
+
*/
|
|
6617
|
+
dispose() {
|
|
6618
|
+
if (this._disposed) return;
|
|
6619
|
+
this.stop();
|
|
6620
|
+
this._disposed = true;
|
|
6621
|
+
if (this._resizeListener) {
|
|
6622
|
+
window.removeEventListener("resize", this._resizeListener);
|
|
6623
|
+
this._resizeListener = void 0;
|
|
6624
|
+
}
|
|
6625
|
+
for (const [dispatcher, events] of this._eventDispatchers) {
|
|
6626
|
+
for (const event of events) {
|
|
6627
|
+
dispatcher.removeEventListener(event, this._changeListener);
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6630
|
+
this._eventDispatchers.clear();
|
|
6631
|
+
this._stats?.dom.remove();
|
|
6632
|
+
this._stats = void 0;
|
|
6633
|
+
this.renderer.domElement.remove();
|
|
6634
|
+
this._element = void 0;
|
|
6635
|
+
if (this._controls) {
|
|
6636
|
+
const controls = this._controls;
|
|
6637
|
+
this._controls = void 0;
|
|
6638
|
+
controls.enabled = false;
|
|
6639
|
+
controls.dispose();
|
|
6432
6640
|
}
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6641
|
+
this.scene.clear();
|
|
6642
|
+
for (const helper of this._debugHelpers) {
|
|
6643
|
+
helper.geometry.dispose();
|
|
6644
|
+
const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
|
|
6645
|
+
for (const material of materials) {
|
|
6646
|
+
material.dispose();
|
|
6647
|
+
}
|
|
6436
6648
|
}
|
|
6437
|
-
|
|
6438
|
-
|
|
6649
|
+
this._debugHelpers.length = 0;
|
|
6650
|
+
this.composer?.dispose();
|
|
6651
|
+
this.renderer.dispose();
|
|
6652
|
+
this.renderer.forceContextLoss();
|
|
6653
|
+
}
|
|
6654
|
+
animate(t = performance.now()) {
|
|
6655
|
+
if (this._disposed) return;
|
|
6656
|
+
if (this._controls?.enabled) {
|
|
6657
|
+
this._controls.update();
|
|
6439
6658
|
}
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
}
|
|
6659
|
+
if (this._disposed) return;
|
|
6660
|
+
if (!this.dirty && !this.options.render.renderAlways) return;
|
|
6661
|
+
const interval = this._frameInterval;
|
|
6662
|
+
if (interval) {
|
|
6663
|
+
const next = this._nextFrameTime;
|
|
6664
|
+
if (next !== void 0 && t + 0.1 < next) return;
|
|
6665
|
+
this._nextFrameTime = next !== void 0 && t - next < interval ? next + interval : t + interval;
|
|
6448
6666
|
}
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
if (position === void 0) {
|
|
6452
|
-
position = new Vector23();
|
|
6453
|
-
pointerPositions[event.pointerId] = position;
|
|
6454
|
-
}
|
|
6455
|
-
position.set(event.pageX, event.pageY);
|
|
6667
|
+
if (this._stats) {
|
|
6668
|
+
this._stats.begin();
|
|
6456
6669
|
}
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6670
|
+
if (this.options.composer.enabled && this.composer) {
|
|
6671
|
+
this.composer.render();
|
|
6672
|
+
} else {
|
|
6673
|
+
this.renderer.render(this.scene, this.camera);
|
|
6460
6674
|
}
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6675
|
+
this.dirty = false;
|
|
6676
|
+
if (this._stats) {
|
|
6677
|
+
this._stats.end();
|
|
6678
|
+
}
|
|
6679
|
+
}
|
|
6680
|
+
//</editor-fold>
|
|
6681
|
+
toImage() {
|
|
6682
|
+
return this.renderer.domElement.toDataURL();
|
|
6683
|
+
}
|
|
6684
|
+
///
|
|
6685
|
+
get attachedToBody() {
|
|
6686
|
+
return this.element === document.body;
|
|
6466
6687
|
}
|
|
6688
|
+
get viewWidth() {
|
|
6689
|
+
return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
|
|
6690
|
+
}
|
|
6691
|
+
get viewHeight() {
|
|
6692
|
+
return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
|
|
6693
|
+
}
|
|
6694
|
+
get scene() {
|
|
6695
|
+
return this._scene;
|
|
6696
|
+
}
|
|
6697
|
+
get camera() {
|
|
6698
|
+
return this._camera;
|
|
6699
|
+
}
|
|
6700
|
+
get renderer() {
|
|
6701
|
+
return this._renderer;
|
|
6702
|
+
}
|
|
6703
|
+
get composer() {
|
|
6704
|
+
return this._composer;
|
|
6705
|
+
}
|
|
6706
|
+
/** Renderer-owned controls, or undefined when disabled at construction or after disposal. */
|
|
6707
|
+
get controls() {
|
|
6708
|
+
return this._controls;
|
|
6709
|
+
}
|
|
6710
|
+
///
|
|
6467
6711
|
};
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6712
|
+
|
|
6713
|
+
// src/skin/Skins.ts
|
|
6714
|
+
var Skins = class {
|
|
6715
|
+
//<editor-fold desc="Skins">
|
|
6716
|
+
static async fromUuidOrUsername(uuidOrUsername) {
|
|
6717
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6718
|
+
return this.fromUuid(uuidOrUsername);
|
|
6719
|
+
}
|
|
6720
|
+
return this.fromUsername(uuidOrUsername);
|
|
6721
|
+
}
|
|
6722
|
+
static async fromUuid(uuid) {
|
|
6723
|
+
return this.getMcProxySkinUrl(uuid);
|
|
6724
|
+
}
|
|
6725
|
+
static async fromUsername(username) {
|
|
6726
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6727
|
+
if (uuid) {
|
|
6728
|
+
return this.fromUuid(uuid);
|
|
6729
|
+
}
|
|
6730
|
+
return void 0;
|
|
6731
|
+
});
|
|
6732
|
+
}
|
|
6733
|
+
static async fromMineSkin(mineskinId) {
|
|
6734
|
+
return this.getMineSkin(mineskinId).then((mineskin) => {
|
|
6735
|
+
if (mineskin) {
|
|
6736
|
+
return mineskin["data"]["texture"]["value"]["urls"]["skins"];
|
|
6737
|
+
}
|
|
6738
|
+
return void 0;
|
|
6739
|
+
});
|
|
6740
|
+
}
|
|
6741
|
+
//</editor-fold>
|
|
6742
|
+
//<editor-fold desc="Capes">
|
|
6743
|
+
static async capeFromUuidOrUsername(uuidOrUsername) {
|
|
6744
|
+
if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
|
|
6745
|
+
return this.capeFromUuid(uuidOrUsername);
|
|
6746
|
+
}
|
|
6747
|
+
return this.capeFromUsername(uuidOrUsername);
|
|
6748
|
+
}
|
|
6749
|
+
static async capeFromUuid(uuid) {
|
|
6750
|
+
return this.getMcProxyCapeUrl(uuid);
|
|
6751
|
+
}
|
|
6752
|
+
static async capeFromUsername(username) {
|
|
6753
|
+
return this.usernameToUuid(username).then((uuid) => {
|
|
6754
|
+
if (uuid) {
|
|
6755
|
+
return this.capeFromUuid(uuid);
|
|
6756
|
+
}
|
|
6757
|
+
return void 0;
|
|
6758
|
+
});
|
|
6759
|
+
}
|
|
6760
|
+
static async capeFromCapesDev(uuid, capeType = "minecraft") {
|
|
6761
|
+
return this.getCapesDev(uuid, capeType).then((cape) => {
|
|
6762
|
+
if (cape) {
|
|
6763
|
+
return cape?.stillImageUrl;
|
|
6764
|
+
}
|
|
6765
|
+
return void 0;
|
|
6766
|
+
});
|
|
6767
|
+
}
|
|
6768
|
+
//</editor-fold>
|
|
6769
|
+
//<editor-fold desc="Helpers">
|
|
6770
|
+
static async usernameToUuid(username) {
|
|
6771
|
+
return this.usernameToUuidMcProxy(username);
|
|
6772
|
+
}
|
|
6773
|
+
static async usernameToUuidMcProxy(username) {
|
|
6774
|
+
return Requests.genericRequest({
|
|
6775
|
+
baseURL: "https://mcproxy.dev",
|
|
6776
|
+
url: "/uuid/" + username
|
|
6777
|
+
}).then((res) => {
|
|
6778
|
+
if (res.status === 200) {
|
|
6779
|
+
return res.data["data"]["id"];
|
|
6780
|
+
}
|
|
6781
|
+
return void 0;
|
|
6782
|
+
}).catch((err) => {
|
|
6783
|
+
console.warn(err);
|
|
6784
|
+
return void 0;
|
|
6785
|
+
});
|
|
6786
|
+
}
|
|
6787
|
+
/** @deprecated **/
|
|
6788
|
+
static async usernameToUuidSkinProxy(username) {
|
|
6789
|
+
return Requests.genericRequest({
|
|
6790
|
+
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
6791
|
+
url: "/uuid/" + username
|
|
6792
|
+
}).then((res) => {
|
|
6793
|
+
if (res.status === 200) {
|
|
6794
|
+
return res.data["id"];
|
|
6795
|
+
}
|
|
6796
|
+
return void 0;
|
|
6797
|
+
}).catch((err) => {
|
|
6798
|
+
console.warn(err);
|
|
6799
|
+
return void 0;
|
|
6800
|
+
});
|
|
6801
|
+
}
|
|
6802
|
+
static async usernameToUuidMineTools(username) {
|
|
6803
|
+
return Requests.genericRequest({
|
|
6804
|
+
baseURL: "https://api.minetools.eu",
|
|
6805
|
+
url: "/uuid/" + username
|
|
6806
|
+
}).then((res) => {
|
|
6807
|
+
if (res.status === 200) {
|
|
6808
|
+
return res.data["id"];
|
|
6809
|
+
}
|
|
6810
|
+
return void 0;
|
|
6811
|
+
}).catch((err) => {
|
|
6812
|
+
console.warn(err);
|
|
6813
|
+
return void 0;
|
|
6814
|
+
});
|
|
6815
|
+
}
|
|
6816
|
+
static async getProfileFromMinetools(uuid) {
|
|
6817
|
+
return Requests.genericRequest({
|
|
6818
|
+
baseURL: "https://api.minetools.eu",
|
|
6819
|
+
url: "/profile/" + uuid
|
|
6820
|
+
}).then((res) => {
|
|
6821
|
+
if (res.status === 200) {
|
|
6822
|
+
return res.data;
|
|
6823
|
+
}
|
|
6824
|
+
});
|
|
6825
|
+
}
|
|
6826
|
+
static async getMineSkin(mineskinId) {
|
|
6827
|
+
return Requests.genericRequest({
|
|
6828
|
+
baseURL: "https://api.mineskin.org",
|
|
6829
|
+
url: "/get/uuid/" + mineskinId
|
|
6830
|
+
}).then((res) => {
|
|
6831
|
+
if (res.status === 200) {
|
|
6832
|
+
return res.data;
|
|
6833
|
+
}
|
|
6834
|
+
return void 0;
|
|
6835
|
+
}).catch((err) => {
|
|
6836
|
+
console.warn(err);
|
|
6837
|
+
return void 0;
|
|
6838
|
+
});
|
|
6839
|
+
}
|
|
6840
|
+
static async getCapesDev(uuid, type = "all") {
|
|
6841
|
+
return Requests.genericRequest({
|
|
6842
|
+
baseURL: "https://api.capes.dev",
|
|
6843
|
+
url: "/load/" + uuid + "/" + type
|
|
6844
|
+
}).then((res) => {
|
|
6845
|
+
if (res.status === 200) {
|
|
6846
|
+
return res.data;
|
|
6847
|
+
}
|
|
6848
|
+
return void 0;
|
|
6849
|
+
}).catch((err) => {
|
|
6850
|
+
console.warn(err);
|
|
6851
|
+
return void 0;
|
|
6852
|
+
});
|
|
6853
|
+
}
|
|
6854
|
+
static getCrafatarSkinUrl(uuid) {
|
|
6855
|
+
return "https://crafatar.com/skins/" + uuid;
|
|
6856
|
+
}
|
|
6857
|
+
static getCrafatarCapeUrl(uuid) {
|
|
6858
|
+
return "https://crafatar.com/capes/" + uuid;
|
|
6859
|
+
}
|
|
6860
|
+
static getMcHeadsSkinUrl(uuid) {
|
|
6861
|
+
return "https://mc-heads.net/skin/" + uuid;
|
|
6862
|
+
}
|
|
6863
|
+
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6864
|
+
return "https://mineskin.org/skin/player/" + uuid;
|
|
6865
|
+
}
|
|
6866
|
+
/** @deprecated **/
|
|
6867
|
+
static getSkinProxySkinUrl(uuid) {
|
|
6868
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6869
|
+
}
|
|
6870
|
+
/** @deprecated **/
|
|
6871
|
+
static getSkinProxyCapeUrl(uuid) {
|
|
6872
|
+
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6873
|
+
}
|
|
6874
|
+
static getMcProxySkinUrl(uuid) {
|
|
6875
|
+
return "https://mcproxy.dev/skin/" + uuid;
|
|
6476
6876
|
}
|
|
6877
|
+
static getMcProxyCapeUrl(uuid) {
|
|
6878
|
+
return "https://mcproxy.dev/cape/" + uuid;
|
|
6879
|
+
}
|
|
6880
|
+
//</editor-fold>
|
|
6477
6881
|
};
|
|
6478
6882
|
|
|
6479
6883
|
// src/world/Chunk.ts
|
|
6480
|
-
import { Box3 as Box32, Object3D as Object3D6, Vector3 as
|
|
6884
|
+
import { Box3 as Box32, Object3D as Object3D6, Vector3 as Vector311 } from "three";
|
|
6481
6885
|
|
|
6482
6886
|
// src/world/MineRenderWorld.ts
|
|
6483
|
-
import { Vector3 as
|
|
6887
|
+
import { Vector3 as Vector310 } from "three";
|
|
6484
6888
|
var MineRenderWorld = class {
|
|
6485
6889
|
constructor(scene) {
|
|
6486
6890
|
this._size = 4;
|
|
@@ -6491,10 +6895,10 @@ var MineRenderWorld = class {
|
|
|
6491
6895
|
}
|
|
6492
6896
|
getBlockAt(posOrX, y, z) {
|
|
6493
6897
|
if (typeof posOrX == "number") {
|
|
6494
|
-
return this.getBlockAt(new
|
|
6898
|
+
return this.getBlockAt(new Vector310(posOrX, y, z));
|
|
6495
6899
|
}
|
|
6496
6900
|
if (isTripleArray(posOrX)) {
|
|
6497
|
-
return this.getBlockAt(new
|
|
6901
|
+
return this.getBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]));
|
|
6498
6902
|
}
|
|
6499
6903
|
const chunk = this.getChunkAt(posOrX);
|
|
6500
6904
|
if (typeof chunk === "undefined") {
|
|
@@ -6505,10 +6909,10 @@ var MineRenderWorld = class {
|
|
|
6505
6909
|
}
|
|
6506
6910
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
6507
6911
|
if (typeof posOrX == "number") {
|
|
6508
|
-
return this.setBlockAt(new
|
|
6912
|
+
return this.setBlockAt(new Vector310(posOrX, yOrBlock, z), block);
|
|
6509
6913
|
}
|
|
6510
6914
|
if (isTripleArray(posOrX)) {
|
|
6511
|
-
return this.setBlockAt(new
|
|
6915
|
+
return this.setBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
6512
6916
|
}
|
|
6513
6917
|
this.validatePosBounds(posOrX);
|
|
6514
6918
|
const chunk = this.getOrCreateChunkAt(posOrX);
|
|
@@ -6536,7 +6940,7 @@ var MineRenderWorld = class {
|
|
|
6536
6940
|
console.log("CHUNKS", this._chunks);
|
|
6537
6941
|
for (let chunk of this._chunks.values()) {
|
|
6538
6942
|
console.log("dispose chunk", chunk);
|
|
6539
|
-
await
|
|
6943
|
+
await chunk?.dispose();
|
|
6540
6944
|
}
|
|
6541
6945
|
this._chunks.clear();
|
|
6542
6946
|
}
|
|
@@ -6554,14 +6958,14 @@ var MineRenderWorld = class {
|
|
|
6554
6958
|
return this._chunks[index];
|
|
6555
6959
|
}
|
|
6556
6960
|
static worldToScenePosition(pos) {
|
|
6557
|
-
return new
|
|
6961
|
+
return new Vector310(
|
|
6558
6962
|
pos.x * 16,
|
|
6559
6963
|
pos.y * 16,
|
|
6560
6964
|
pos.z * 16
|
|
6561
6965
|
);
|
|
6562
6966
|
}
|
|
6563
6967
|
static sceneToWorldPosition(pos) {
|
|
6564
|
-
return new
|
|
6968
|
+
return new Vector310(
|
|
6565
6969
|
pos.x / 16,
|
|
6566
6970
|
pos.y / 16,
|
|
6567
6971
|
pos.z / 16
|
|
@@ -6590,7 +6994,7 @@ var MineRenderWorld = class {
|
|
|
6590
6994
|
};
|
|
6591
6995
|
|
|
6592
6996
|
// src/world/Chunk.ts
|
|
6593
|
-
var
|
|
6997
|
+
var p11 = prefix("Chunk");
|
|
6594
6998
|
var Chunk = class _Chunk {
|
|
6595
6999
|
constructor(scene, x, y, z) {
|
|
6596
7000
|
this._blocks = [];
|
|
@@ -6603,7 +7007,7 @@ var Chunk = class _Chunk {
|
|
|
6603
7007
|
scene.add(anchor);
|
|
6604
7008
|
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
6605
7009
|
addBox3WireframeToObject(
|
|
6606
|
-
new Box32(new
|
|
7010
|
+
new Box32(new Vector311(0, 0, 0), new Vector311(256, 256, 256)),
|
|
6607
7011
|
anchor,
|
|
6608
7012
|
16776960,
|
|
6609
7013
|
4
|
|
@@ -6611,10 +7015,10 @@ var Chunk = class _Chunk {
|
|
|
6611
7015
|
}
|
|
6612
7016
|
getBlockAt(posOrX, y, z) {
|
|
6613
7017
|
if (typeof posOrX == "number") {
|
|
6614
|
-
return this.getBlockAt(new
|
|
7018
|
+
return this.getBlockAt(new Vector311(posOrX, y, z));
|
|
6615
7019
|
}
|
|
6616
7020
|
if (isTripleArray(posOrX)) {
|
|
6617
|
-
return this.getBlockAt(new
|
|
7021
|
+
return this.getBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]));
|
|
6618
7022
|
}
|
|
6619
7023
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
6620
7024
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
@@ -6622,10 +7026,10 @@ var Chunk = class _Chunk {
|
|
|
6622
7026
|
}
|
|
6623
7027
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
6624
7028
|
if (typeof posOrX == "number") {
|
|
6625
|
-
return this.setBlockAt(new
|
|
7029
|
+
return this.setBlockAt(new Vector311(posOrX, yOrBlock, z), block);
|
|
6626
7030
|
}
|
|
6627
7031
|
if (isTripleArray(posOrX)) {
|
|
6628
|
-
return this.setBlockAt(new
|
|
7032
|
+
return this.setBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
6629
7033
|
}
|
|
6630
7034
|
const worldPos = posOrX;
|
|
6631
7035
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -6642,7 +7046,7 @@ var Chunk = class _Chunk {
|
|
|
6642
7046
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
6643
7047
|
const current = this._blocks[index];
|
|
6644
7048
|
if (typeof current !== "undefined") {
|
|
6645
|
-
console.debug(
|
|
7049
|
+
console.debug(p11, "deleting existing block at", pos, worldPos, index);
|
|
6646
7050
|
current.object.removeFromScene();
|
|
6647
7051
|
delete this._blocks[index];
|
|
6648
7052
|
}
|
|
@@ -6671,7 +7075,7 @@ var Chunk = class _Chunk {
|
|
|
6671
7075
|
}
|
|
6672
7076
|
async clear() {
|
|
6673
7077
|
let promises = [];
|
|
6674
|
-
let pos = new
|
|
7078
|
+
let pos = new Vector311();
|
|
6675
7079
|
for (let x = 0; x < 16; x++) {
|
|
6676
7080
|
for (let z = 0; z < 16; z++) {
|
|
6677
7081
|
for (let y = 0; y < 16; y++) {
|
|
@@ -6690,14 +7094,14 @@ var Chunk = class _Chunk {
|
|
|
6690
7094
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
6691
7095
|
}
|
|
6692
7096
|
worldPosToChunkPos(pos) {
|
|
6693
|
-
return new
|
|
7097
|
+
return new Vector311(
|
|
6694
7098
|
pos.x - this.x * 16,
|
|
6695
7099
|
pos.y - this.y * 16,
|
|
6696
7100
|
pos.z - this.z * 16
|
|
6697
7101
|
);
|
|
6698
7102
|
}
|
|
6699
7103
|
chunkPosToWorldPos(pos) {
|
|
6700
|
-
return new
|
|
7104
|
+
return new Vector311(
|
|
6701
7105
|
this.x * 16 + pos.x,
|
|
6702
7106
|
this.y * 16 + pos.y,
|
|
6703
7107
|
this.z * 16 + pos.z
|
|
@@ -6708,6 +7112,7 @@ export {
|
|
|
6708
7112
|
AXES,
|
|
6709
7113
|
ArchiveAssetSource,
|
|
6710
7114
|
AssetKey,
|
|
7115
|
+
AssetLoadError,
|
|
6711
7116
|
AssetLoader,
|
|
6712
7117
|
AssetParser,
|
|
6713
7118
|
AssetSource,
|
|
@@ -6720,6 +7125,7 @@ export {
|
|
|
6720
7125
|
BlockEntityModels,
|
|
6721
7126
|
BlockObject,
|
|
6722
7127
|
BlockStates,
|
|
7128
|
+
BlockTints,
|
|
6723
7129
|
BrowserArchiveProxy,
|
|
6724
7130
|
CUBE_FACES,
|
|
6725
7131
|
Caching,
|
|
@@ -6765,6 +7171,7 @@ export {
|
|
|
6765
7171
|
OrbitControls,
|
|
6766
7172
|
PersistentCache,
|
|
6767
7173
|
Renderer,
|
|
7174
|
+
RequestError,
|
|
6768
7175
|
Requests,
|
|
6769
7176
|
SKIN_PARTS,
|
|
6770
7177
|
SceneInspector,
|