minerender 2.1.0-alpha.23 → 2.1.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.mts +44 -48
- package/dist/browser/index.d.ts +44 -48
- package/dist/browser/index.js +133 -142
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +182 -191
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +137 -148
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +44 -48
- package/dist/node/index.d.ts +44 -48
- package/dist/node/index.js +134 -145
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +183 -191
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -405,7 +405,10 @@ var Caching = class _Caching {
|
|
|
405
405
|
this.blockTintCache = _Caching.createAssetCache();
|
|
406
406
|
}
|
|
407
407
|
static {
|
|
408
|
-
this.
|
|
408
|
+
this.entityModelCache = _Caching.createAssetCache();
|
|
409
|
+
}
|
|
410
|
+
static {
|
|
411
|
+
this.entityTextureCache = _Caching.createAssetCache();
|
|
409
412
|
}
|
|
410
413
|
static createAssetCache() {
|
|
411
414
|
return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
|
|
@@ -430,7 +433,8 @@ var Caching = class _Caching {
|
|
|
430
433
|
this.listAssetCache,
|
|
431
434
|
this.defaultBlockStatesCache,
|
|
432
435
|
this.blockTintCache,
|
|
433
|
-
this.
|
|
436
|
+
this.entityModelCache,
|
|
437
|
+
this.entityTextureCache
|
|
434
438
|
];
|
|
435
439
|
}
|
|
436
440
|
static clear() {
|
|
@@ -1540,14 +1544,6 @@ function applyElementRotation(rotation, geometry) {
|
|
|
1540
1544
|
}
|
|
1541
1545
|
geometry.translate(origin.x, origin.y, origin.z);
|
|
1542
1546
|
}
|
|
1543
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
1544
|
-
const origin = new Vector33(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1545
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1546
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1547
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1548
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1549
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
1550
|
-
}
|
|
1551
1547
|
function applyGenericRotation(axis, rotation, obj) {
|
|
1552
1548
|
switch (axis) {
|
|
1553
1549
|
case "x" /* X */:
|
|
@@ -2604,18 +2600,18 @@ var MinecraftCubeTexture = class {
|
|
|
2604
2600
|
}
|
|
2605
2601
|
getUvEast(w, h, l) {
|
|
2606
2602
|
return [
|
|
2607
|
-
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2608
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2609
|
-
[this.mapW(this.u), this.mapH(this.v + l)],
|
|
2610
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2603
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2604
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2605
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2606
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2611
2607
|
];
|
|
2612
2608
|
}
|
|
2613
2609
|
getUvWest(w, h, l) {
|
|
2614
2610
|
return [
|
|
2615
|
-
[this.mapW(this.u + l
|
|
2616
|
-
[this.mapW(this.u
|
|
2617
|
-
[this.mapW(this.u + l
|
|
2618
|
-
[this.mapW(this.u
|
|
2611
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2612
|
+
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2613
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2614
|
+
[this.mapW(this.u), this.mapH(this.v + l)]
|
|
2619
2615
|
];
|
|
2620
2616
|
}
|
|
2621
2617
|
getUvUp(w, h, l) {
|
|
@@ -2628,26 +2624,26 @@ var MinecraftCubeTexture = class {
|
|
|
2628
2624
|
}
|
|
2629
2625
|
getUvDown(w, h, l) {
|
|
2630
2626
|
return [
|
|
2631
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2632
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2633
2627
|
[this.mapW(this.u + l), this.mapH(this.v)],
|
|
2634
|
-
[this.mapW(this.u + l + w), this.mapH(this.v)]
|
|
2628
|
+
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
2629
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2630
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2635
2631
|
];
|
|
2636
2632
|
}
|
|
2637
2633
|
getUvSouth(w, h, l) {
|
|
2638
2634
|
return [
|
|
2639
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2640
2635
|
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l + h)],
|
|
2641
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2642
|
-
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)]
|
|
2636
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2637
|
+
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)],
|
|
2638
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)]
|
|
2643
2639
|
];
|
|
2644
2640
|
}
|
|
2645
2641
|
getUvNorth(w, h, l) {
|
|
2646
2642
|
return [
|
|
2647
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2648
2643
|
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2649
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2650
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2644
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2645
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2646
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2651
2647
|
];
|
|
2652
2648
|
}
|
|
2653
2649
|
getFaceUv(face, w, h, l) {
|
|
@@ -2666,10 +2662,12 @@ var MinecraftCubeTexture = class {
|
|
|
2666
2662
|
return this.getUvNorth(w, h, l);
|
|
2667
2663
|
}
|
|
2668
2664
|
}
|
|
2669
|
-
toUvArray(w, h, l) {
|
|
2665
|
+
toUvArray(w, h, l, mirror = false) {
|
|
2670
2666
|
const uv = [];
|
|
2671
2667
|
for (let i = 0; i < CUBE_FACES.length; i++) {
|
|
2672
|
-
|
|
2668
|
+
const face = mirror && i < 2 ? CUBE_FACES[1 - i] : CUBE_FACES[i];
|
|
2669
|
+
const corners = this.getFaceUv(face, w, h, l);
|
|
2670
|
+
UVMapper.setFaceUvInArray(uv, i * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
|
|
2673
2671
|
}
|
|
2674
2672
|
return uv;
|
|
2675
2673
|
}
|
|
@@ -2699,69 +2697,79 @@ function shutdown() {
|
|
|
2699
2697
|
Caching.end();
|
|
2700
2698
|
}
|
|
2701
2699
|
|
|
2702
|
-
// src/
|
|
2703
|
-
var
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2708
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2709
|
-
});
|
|
2710
|
-
}
|
|
2711
|
-
static async getEntityModels() {
|
|
2712
|
-
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2713
|
-
console.log(key);
|
|
2714
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2715
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2716
|
-
});
|
|
2700
|
+
// src/error/MineRenderError.ts
|
|
2701
|
+
var MineRenderError = class _MineRenderError extends Error {
|
|
2702
|
+
constructor(msg) {
|
|
2703
|
+
super(msg);
|
|
2704
|
+
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2717
2705
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
const models = await this.getBlockEntityModels();
|
|
2721
|
-
if (!models) {
|
|
2722
|
-
return [];
|
|
2723
|
-
}
|
|
2724
|
-
return Object.keys(models);
|
|
2706
|
+
get name() {
|
|
2707
|
+
return "MineRenderError";
|
|
2725
2708
|
}
|
|
2709
|
+
};
|
|
2710
|
+
|
|
2711
|
+
// src/assets/Entities.ts
|
|
2712
|
+
var Entities = class {
|
|
2726
2713
|
static async getEntityList() {
|
|
2727
|
-
const
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
if (!models) {
|
|
2736
|
-
return void 0;
|
|
2737
|
-
}
|
|
2738
|
-
if (!textureKey) {
|
|
2739
|
-
textureKey = modelKey;
|
|
2740
|
-
}
|
|
2741
|
-
const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
|
|
2742
|
-
return {
|
|
2743
|
-
key: textureKey,
|
|
2744
|
-
parts: models[baseKey.toNamespacedString()]
|
|
2714
|
+
const collect = async (path) => {
|
|
2715
|
+
const prefix2 = path ? `${path}/` : "";
|
|
2716
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
|
|
2717
|
+
const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
2718
|
+
if (!list) return [];
|
|
2719
|
+
const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
|
|
2720
|
+
const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
2721
|
+
return [...files, ...children.flat()];
|
|
2745
2722
|
};
|
|
2723
|
+
return collect("");
|
|
2724
|
+
}
|
|
2725
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
2726
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2727
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2728
|
+
const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
2729
|
+
if (!model) return void 0;
|
|
2730
|
+
const layerName = options?.layer ?? "main";
|
|
2731
|
+
const layer = model.layers[layerName];
|
|
2732
|
+
if (!layer) {
|
|
2733
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
2734
|
+
}
|
|
2735
|
+
let texture;
|
|
2736
|
+
if (textureKey) {
|
|
2737
|
+
const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
|
|
2738
|
+
texture = isAssetKey(textureKey) && textureKey.assetType === "textures" && path2.startsWith("entity/") ? textureKey : new AssetKey(textureKey.namespace, path2, "textures", "entity", "assets", ".png", isAssetKey(textureKey) ? textureKey.root : void 0);
|
|
2739
|
+
} else {
|
|
2740
|
+
texture = await this.resolveTexture(modelKey);
|
|
2741
|
+
}
|
|
2742
|
+
return { key: textureKey ?? modelKey, texture, layer, id: model.id };
|
|
2743
|
+
}
|
|
2744
|
+
static async resolveTexture(modelKey) {
|
|
2745
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2746
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2747
|
+
return Caching.entityTextureCache.get(key.serialize(), async () => {
|
|
2748
|
+
const name = path.split("/").pop();
|
|
2749
|
+
for (const candidate of [path, `${path}/${name}`]) {
|
|
2750
|
+
const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
|
|
2751
|
+
if (await ModelTextures.get(texture)) return texture;
|
|
2752
|
+
}
|
|
2753
|
+
const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
|
|
2754
|
+
const list = await AssetLoader.get(listKey, "list" /* LIST */);
|
|
2755
|
+
const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
|
|
2756
|
+
const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
|
|
2757
|
+
if (!file) return void 0;
|
|
2758
|
+
const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
|
|
2759
|
+
const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
|
|
2760
|
+
const assets = variant?.assets;
|
|
2761
|
+
const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
|
|
2762
|
+
return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
|
|
2763
|
+
});
|
|
2746
2764
|
}
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
}
|
|
2755
|
-
const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
|
|
2756
|
-
return {
|
|
2757
|
-
key: textureKey,
|
|
2758
|
-
parts: models[baseKey.toNamespacedString()]
|
|
2759
|
-
};
|
|
2765
|
+
/** @deprecated Use getEntityList(); block entities share the entity dataset. */
|
|
2766
|
+
static getBlockList() {
|
|
2767
|
+
return this.getEntityList();
|
|
2768
|
+
}
|
|
2769
|
+
/** @deprecated Use getEntity(); block entities share the entity dataset. */
|
|
2770
|
+
static getBlock(modelKey, textureKey, options) {
|
|
2771
|
+
return this.getEntity(modelKey, textureKey, options);
|
|
2760
2772
|
}
|
|
2761
|
-
};
|
|
2762
|
-
var EntityModels = class {
|
|
2763
|
-
};
|
|
2764
|
-
var BlockEntityModels = class {
|
|
2765
2773
|
};
|
|
2766
2774
|
|
|
2767
2775
|
// src/renderer/SceneObject.ts
|
|
@@ -2810,17 +2818,6 @@ function isInstanceReference(obj) {
|
|
|
2810
2818
|
return obj.isInstanceReference;
|
|
2811
2819
|
}
|
|
2812
2820
|
|
|
2813
|
-
// src/error/MineRenderError.ts
|
|
2814
|
-
var MineRenderError = class _MineRenderError extends Error {
|
|
2815
|
-
constructor(msg) {
|
|
2816
|
-
super(msg);
|
|
2817
|
-
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2818
|
-
}
|
|
2819
|
-
get name() {
|
|
2820
|
-
return "MineRenderError";
|
|
2821
|
-
}
|
|
2822
|
-
};
|
|
2823
|
-
|
|
2824
2821
|
// src/renderer/SceneObject.ts
|
|
2825
2822
|
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2826
2823
|
var p6 = prefix("SceneObject");
|
|
@@ -2954,15 +2951,8 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2954
2951
|
return this.toggleObjectVisibility(this.getMeshByName(name), visible);
|
|
2955
2952
|
}
|
|
2956
2953
|
iterateAllMeshes(cb) {
|
|
2957
|
-
this.
|
|
2958
|
-
if (obj
|
|
2959
|
-
cb(obj);
|
|
2960
|
-
}
|
|
2961
|
-
obj.children.forEach((obj1) => {
|
|
2962
|
-
if (obj1.isMesh) {
|
|
2963
|
-
cb(obj1);
|
|
2964
|
-
}
|
|
2965
|
-
});
|
|
2954
|
+
this.traverse((obj) => {
|
|
2955
|
+
if (isMesh(obj)) cb(obj);
|
|
2966
2956
|
});
|
|
2967
2957
|
}
|
|
2968
2958
|
//</editor-fold>
|
|
@@ -3200,17 +3190,16 @@ function isSceneObject(obj) {
|
|
|
3200
3190
|
// src/entity/scene/EntityObject.ts
|
|
3201
3191
|
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
3202
3192
|
import { Object3D as Object3D3 } from "three";
|
|
3203
|
-
|
|
3204
|
-
var EntityObject = class extends SceneObject {
|
|
3193
|
+
var EntityObject = class _EntityObject extends SceneObject {
|
|
3205
3194
|
constructor(entity, options) {
|
|
3206
3195
|
super();
|
|
3207
3196
|
this.entity = entity;
|
|
3208
3197
|
this.isEntityObject = true;
|
|
3209
3198
|
this.meshesCreated = false;
|
|
3210
|
-
this.options = (0, import_ts_deepmerge4.default)({},
|
|
3199
|
+
this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
|
|
3211
3200
|
}
|
|
3212
3201
|
static {
|
|
3213
|
-
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
3202
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
|
|
3214
3203
|
}
|
|
3215
3204
|
async init() {
|
|
3216
3205
|
this.createMeshes();
|
|
@@ -3220,10 +3209,11 @@ var EntityObject = class extends SceneObject {
|
|
|
3220
3209
|
super.dispose();
|
|
3221
3210
|
}
|
|
3222
3211
|
get textureKey() {
|
|
3212
|
+
if (this.entity.texture) return this.entity.texture;
|
|
3213
|
+
const key = this.entity.key;
|
|
3223
3214
|
return new AssetKey(
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
3215
|
+
key.namespace,
|
|
3216
|
+
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
3227
3217
|
"textures",
|
|
3228
3218
|
"entity",
|
|
3229
3219
|
"assets",
|
|
@@ -3233,36 +3223,41 @@ var EntityObject = class extends SceneObject {
|
|
|
3233
3223
|
async loadTextures() {
|
|
3234
3224
|
this.imageData = await ModelTextures.get(this.textureKey);
|
|
3235
3225
|
}
|
|
3236
|
-
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
3237
3226
|
createMeshes(force = false) {
|
|
3238
3227
|
if (this.meshesCreated && !force) return;
|
|
3239
|
-
const
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
const partAnchor = new Object3D3();
|
|
3244
|
-
partAnchor.position.x = part.pivotX;
|
|
3245
|
-
partAnchor.position.y = part.pivotY;
|
|
3246
|
-
partAnchor.position.z = part.pivotZ;
|
|
3247
|
-
for (let cube of part.cubes) {
|
|
3248
|
-
const w = cube.maxX - cube.minX;
|
|
3249
|
-
const h = cube.maxY - cube.minY;
|
|
3250
|
-
const l = cube.maxZ - cube.minZ;
|
|
3251
|
-
const uv = texture.toUvArray(w, h, l);
|
|
3252
|
-
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
3253
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3254
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
3255
|
-
applyModelPartRotation(part, cubeGeo);
|
|
3256
|
-
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
3257
|
-
partAnchor.add(mesh);
|
|
3258
|
-
if (this.options.wireframe) {
|
|
3259
|
-
addWireframeToMesh(cubeGeo, mesh);
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
this.add(partAnchor);
|
|
3263
|
-
}
|
|
3228
|
+
const modelRoot = new Object3D3();
|
|
3229
|
+
if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
|
|
3230
|
+
this.add(modelRoot);
|
|
3231
|
+
this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
|
|
3264
3232
|
this.meshesCreated = true;
|
|
3265
3233
|
}
|
|
3234
|
+
createPart(name, part, parent, textureSize, material) {
|
|
3235
|
+
const anchor = this.createGroup(name);
|
|
3236
|
+
anchor.position.fromArray(part.pose.offset);
|
|
3237
|
+
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
3238
|
+
anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
|
|
3239
|
+
parent.add(anchor);
|
|
3240
|
+
const size = part.texture ?? textureSize;
|
|
3241
|
+
for (const cube of part.cubes) {
|
|
3242
|
+
const [width, height, depth] = cube.size;
|
|
3243
|
+
const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
|
|
3244
|
+
const texture = new MinecraftCubeTexture(...cube.uv, ...size);
|
|
3245
|
+
const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
|
|
3246
|
+
const geometry = this._getBoxGeometryForDimensionsAndUv(
|
|
3247
|
+
width + growX * 2,
|
|
3248
|
+
height + growY * 2,
|
|
3249
|
+
depth + growZ * 2,
|
|
3250
|
+
uv
|
|
3251
|
+
).clone();
|
|
3252
|
+
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
3253
|
+
const mesh = this.createMesh(name, geometry, material);
|
|
3254
|
+
anchor.add(mesh);
|
|
3255
|
+
if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
|
|
3256
|
+
}
|
|
3257
|
+
for (const [childName, child] of Object.entries(part.children)) {
|
|
3258
|
+
this.createPart(childName, child, anchor, size, material);
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3266
3261
|
async applyTextures() {
|
|
3267
3262
|
const assetKeyStr = this.textureKey.serialize();
|
|
3268
3263
|
const keyStr = `entity:${assetKeyStr}`;
|
|
@@ -3813,7 +3808,7 @@ var BlockTints = class {
|
|
|
3813
3808
|
};
|
|
3814
3809
|
|
|
3815
3810
|
// src/model/scene/ModelObject.ts
|
|
3816
|
-
import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as
|
|
3811
|
+
import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix44 } from "three";
|
|
3817
3812
|
|
|
3818
3813
|
// src/three/BufferGeometryUtils.js
|
|
3819
3814
|
import {
|
|
@@ -3825,7 +3820,7 @@ import {
|
|
|
3825
3820
|
TriangleFanDrawMode,
|
|
3826
3821
|
TriangleStripDrawMode,
|
|
3827
3822
|
TrianglesDrawMode,
|
|
3828
|
-
Vector3 as
|
|
3823
|
+
Vector3 as Vector36
|
|
3829
3824
|
} from "three";
|
|
3830
3825
|
function computeTangents(geometry) {
|
|
3831
3826
|
geometry.computeTangents();
|
|
@@ -4144,15 +4139,15 @@ function computeMorphedAttributes(object) {
|
|
|
4144
4139
|
console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
|
|
4145
4140
|
return null;
|
|
4146
4141
|
}
|
|
4147
|
-
const _vA = new
|
|
4148
|
-
const _vB = new
|
|
4149
|
-
const _vC = new
|
|
4150
|
-
const _tempA = new
|
|
4151
|
-
const _tempB = new
|
|
4152
|
-
const _tempC = new
|
|
4153
|
-
const _morphA = new
|
|
4154
|
-
const _morphB = new
|
|
4155
|
-
const _morphC = new
|
|
4142
|
+
const _vA = new Vector36();
|
|
4143
|
+
const _vB = new Vector36();
|
|
4144
|
+
const _vC = new Vector36();
|
|
4145
|
+
const _tempA = new Vector36();
|
|
4146
|
+
const _tempB = new Vector36();
|
|
4147
|
+
const _tempC = new Vector36();
|
|
4148
|
+
const _morphA = new Vector36();
|
|
4149
|
+
const _morphB = new Vector36();
|
|
4150
|
+
const _morphC = new Vector36();
|
|
4156
4151
|
function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
|
|
4157
4152
|
_vA.fromBufferAttribute(attribute, a2);
|
|
4158
4153
|
_vB.fromBufferAttribute(attribute, b2);
|
|
@@ -4399,7 +4394,7 @@ var ModelObject = class _ModelObject extends SceneObject {
|
|
|
4399
4394
|
this.atlas.model.elements?.forEach((el) => {
|
|
4400
4395
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4401
4396
|
if (this.options.uvLockRotation) {
|
|
4402
|
-
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new
|
|
4397
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler4(...this.options.uvLockRotation));
|
|
4403
4398
|
}
|
|
4404
4399
|
if (this.options.tints) {
|
|
4405
4400
|
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
@@ -4415,12 +4410,12 @@ var ModelObject = class _ModelObject extends SceneObject {
|
|
|
4415
4410
|
}
|
|
4416
4411
|
elGeo.setAttribute("color", new BufferAttribute4(colors, 3));
|
|
4417
4412
|
}
|
|
4418
|
-
elGeo.applyMatrix4(new
|
|
4419
|
-
elGeo.applyMatrix4(new
|
|
4413
|
+
elGeo.applyMatrix4(new Matrix44().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
|
|
4414
|
+
elGeo.applyMatrix4(new Matrix44().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
4420
4415
|
if (el.rotation) {
|
|
4421
4416
|
applyElementRotation(el.rotation, elGeo);
|
|
4422
4417
|
}
|
|
4423
|
-
elGeo.applyMatrix4(new
|
|
4418
|
+
elGeo.applyMatrix4(new Matrix44().makeTranslation(-8, -8, -8));
|
|
4424
4419
|
if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
|
|
4425
4420
|
if (this.options.mergeMeshes) {
|
|
4426
4421
|
allGeos.push(elGeo);
|
|
@@ -4495,7 +4490,7 @@ function isModelObject(obj) {
|
|
|
4495
4490
|
|
|
4496
4491
|
// src/model/block/scene/BlockObject.ts
|
|
4497
4492
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4498
|
-
import { Euler as
|
|
4493
|
+
import { Euler as Euler5, Matrix4 as Matrix45, Vector3 as Vector37 } from "three";
|
|
4499
4494
|
var p10 = prefix("BlockObject");
|
|
4500
4495
|
function matchesCondition(condition, state) {
|
|
4501
4496
|
return Object.entries(condition).every(([key, value]) => {
|
|
@@ -4557,7 +4552,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4557
4552
|
if (isModelObject(model)) {
|
|
4558
4553
|
model.removeFromScene();
|
|
4559
4554
|
} else if (isInstanceReference(model)) {
|
|
4560
|
-
model.setScale(new
|
|
4555
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4561
4556
|
}
|
|
4562
4557
|
}
|
|
4563
4558
|
super.removeFromScene();
|
|
@@ -4618,7 +4613,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4618
4613
|
}
|
|
4619
4614
|
for (let model of this._models) {
|
|
4620
4615
|
if (isInstanceReference(model)) {
|
|
4621
|
-
model.setScale(new
|
|
4616
|
+
model.setScale(new Vector37(0, 0, 0));
|
|
4622
4617
|
} else {
|
|
4623
4618
|
model.dispose();
|
|
4624
4619
|
}
|
|
@@ -4655,7 +4650,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4655
4650
|
await this.createVariant(variant);
|
|
4656
4651
|
}
|
|
4657
4652
|
async createVariant(variant) {
|
|
4658
|
-
const rotation = new
|
|
4653
|
+
const rotation = new Euler5();
|
|
4659
4654
|
if (typeof variant.x !== "undefined") {
|
|
4660
4655
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4661
4656
|
}
|
|
@@ -4742,7 +4737,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4742
4737
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
4743
4738
|
super.setPositionRotationScaleAt(index, position, rotation, scale);
|
|
4744
4739
|
}
|
|
4745
|
-
getMatrixAt(index, matrix = new
|
|
4740
|
+
getMatrixAt(index, matrix = new Matrix45()) {
|
|
4746
4741
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
4747
4742
|
const child = this._models[0];
|
|
4748
4743
|
if (child && isModelObject(child)) {
|
|
@@ -5785,7 +5780,7 @@ function isMineRenderScene(obj) {
|
|
|
5785
5780
|
}
|
|
5786
5781
|
|
|
5787
5782
|
// src/renderer/Renderer.ts
|
|
5788
|
-
import { AxesHelper as
|
|
5783
|
+
import { AxesHelper as AxesHelper2, GridHelper, OrthographicCamera, PCFSoftShadowMap, PerspectiveCamera, SRGBColorSpace as SRGBColorSpace3, Vector3 as Vector39, WebGLRenderer } from "three";
|
|
5789
5784
|
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
5790
5785
|
import Stats from "stats.js";
|
|
5791
5786
|
import { EffectComposer, RenderPass } from "postprocessing";
|
|
@@ -5798,7 +5793,7 @@ import {
|
|
|
5798
5793
|
Spherical,
|
|
5799
5794
|
TOUCH,
|
|
5800
5795
|
Vector2 as Vector23,
|
|
5801
|
-
Vector3 as
|
|
5796
|
+
Vector3 as Vector38
|
|
5802
5797
|
} from "three";
|
|
5803
5798
|
var _changeEvent = { type: "change" };
|
|
5804
5799
|
var _startEvent = { type: "start" };
|
|
@@ -5812,7 +5807,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
5812
5807
|
this.domElement = domElement;
|
|
5813
5808
|
this.domElement.style.touchAction = "none";
|
|
5814
5809
|
this.enabled = true;
|
|
5815
|
-
this.target = new
|
|
5810
|
+
this.target = new Vector38();
|
|
5816
5811
|
this.minDistance = 0;
|
|
5817
5812
|
this.maxDistance = Infinity;
|
|
5818
5813
|
this.minZoom = 0;
|
|
@@ -5864,10 +5859,10 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
5864
5859
|
state = STATE.NONE;
|
|
5865
5860
|
};
|
|
5866
5861
|
this.update = function() {
|
|
5867
|
-
const offset = new
|
|
5868
|
-
const quat = new Quaternion4().setFromUnitVectors(object.up, new
|
|
5862
|
+
const offset = new Vector38();
|
|
5863
|
+
const quat = new Quaternion4().setFromUnitVectors(object.up, new Vector38(0, 1, 0));
|
|
5869
5864
|
const quatInverse = quat.clone().invert();
|
|
5870
|
-
const lastPosition = new
|
|
5865
|
+
const lastPosition = new Vector38();
|
|
5871
5866
|
const lastQuaternion = new Quaternion4();
|
|
5872
5867
|
const twoPI = 2 * Math.PI;
|
|
5873
5868
|
return function update() {
|
|
@@ -5957,7 +5952,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
5957
5952
|
const spherical = new Spherical();
|
|
5958
5953
|
const sphericalDelta = new Spherical();
|
|
5959
5954
|
let scale = 1;
|
|
5960
|
-
const panOffset = new
|
|
5955
|
+
const panOffset = new Vector38();
|
|
5961
5956
|
let zoomChanged = false;
|
|
5962
5957
|
const rotateStart = new Vector23();
|
|
5963
5958
|
const rotateEnd = new Vector23();
|
|
@@ -5983,7 +5978,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
5983
5978
|
sphericalDelta.phi -= angle;
|
|
5984
5979
|
}
|
|
5985
5980
|
const panLeft = function() {
|
|
5986
|
-
const v = new
|
|
5981
|
+
const v = new Vector38();
|
|
5987
5982
|
return function panLeft2(distance, objectMatrix) {
|
|
5988
5983
|
v.setFromMatrixColumn(objectMatrix, 0);
|
|
5989
5984
|
v.multiplyScalar(-distance);
|
|
@@ -5991,7 +5986,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
5991
5986
|
};
|
|
5992
5987
|
}();
|
|
5993
5988
|
const panUp = function() {
|
|
5994
|
-
const v = new
|
|
5989
|
+
const v = new Vector38();
|
|
5995
5990
|
return function panUp2(distance, objectMatrix) {
|
|
5996
5991
|
if (scope.screenSpacePanning === true) {
|
|
5997
5992
|
v.setFromMatrixColumn(objectMatrix, 1);
|
|
@@ -6004,7 +5999,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
6004
5999
|
};
|
|
6005
6000
|
}();
|
|
6006
6001
|
const pan = function() {
|
|
6007
|
-
const offset = new
|
|
6002
|
+
const offset = new Vector38();
|
|
6008
6003
|
return function pan2(deltaX, deltaY) {
|
|
6009
6004
|
const element = scope.domElement;
|
|
6010
6005
|
if (scope.object.isPerspectiveCamera) {
|
|
@@ -6481,8 +6476,8 @@ var Renderer = class _Renderer {
|
|
|
6481
6476
|
top: void 0,
|
|
6482
6477
|
bottom: void 0
|
|
6483
6478
|
},
|
|
6484
|
-
position: new
|
|
6485
|
-
lookingAt: new
|
|
6479
|
+
position: new Vector39(50, 50, 50),
|
|
6480
|
+
lookingAt: new Vector39(0, 0, 0)
|
|
6486
6481
|
},
|
|
6487
6482
|
render: {
|
|
6488
6483
|
fpsLimit: 60,
|
|
@@ -6586,7 +6581,7 @@ var Renderer = class _Renderer {
|
|
|
6586
6581
|
this.scene.add(gridHelper3);
|
|
6587
6582
|
}
|
|
6588
6583
|
if (this.options.debug.axes) {
|
|
6589
|
-
const axesHelper = new
|
|
6584
|
+
const axesHelper = new AxesHelper2(64);
|
|
6590
6585
|
this._debugHelpers.push(axesHelper);
|
|
6591
6586
|
this.scene.add(axesHelper);
|
|
6592
6587
|
}
|
|
@@ -6947,10 +6942,10 @@ var Skins = class {
|
|
|
6947
6942
|
};
|
|
6948
6943
|
|
|
6949
6944
|
// src/world/Chunk.ts
|
|
6950
|
-
import { Box3 as Box32, Object3D as Object3D6, Vector3 as
|
|
6945
|
+
import { Box3 as Box32, Object3D as Object3D6, Vector3 as Vector311 } from "three";
|
|
6951
6946
|
|
|
6952
6947
|
// src/world/MineRenderWorld.ts
|
|
6953
|
-
import { Vector3 as
|
|
6948
|
+
import { Vector3 as Vector310 } from "three";
|
|
6954
6949
|
var MineRenderWorld = class {
|
|
6955
6950
|
constructor(scene) {
|
|
6956
6951
|
this._size = 4;
|
|
@@ -6961,10 +6956,10 @@ var MineRenderWorld = class {
|
|
|
6961
6956
|
}
|
|
6962
6957
|
getBlockAt(posOrX, y, z) {
|
|
6963
6958
|
if (typeof posOrX == "number") {
|
|
6964
|
-
return this.getBlockAt(new
|
|
6959
|
+
return this.getBlockAt(new Vector310(posOrX, y, z));
|
|
6965
6960
|
}
|
|
6966
6961
|
if (isTripleArray(posOrX)) {
|
|
6967
|
-
return this.getBlockAt(new
|
|
6962
|
+
return this.getBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]));
|
|
6968
6963
|
}
|
|
6969
6964
|
const chunk = this.getChunkAt(posOrX);
|
|
6970
6965
|
if (typeof chunk === "undefined") {
|
|
@@ -6975,10 +6970,10 @@ var MineRenderWorld = class {
|
|
|
6975
6970
|
}
|
|
6976
6971
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
6977
6972
|
if (typeof posOrX == "number") {
|
|
6978
|
-
return this.setBlockAt(new
|
|
6973
|
+
return this.setBlockAt(new Vector310(posOrX, yOrBlock, z), block);
|
|
6979
6974
|
}
|
|
6980
6975
|
if (isTripleArray(posOrX)) {
|
|
6981
|
-
return this.setBlockAt(new
|
|
6976
|
+
return this.setBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
6982
6977
|
}
|
|
6983
6978
|
this.validatePosBounds(posOrX);
|
|
6984
6979
|
const chunk = this.getOrCreateChunkAt(posOrX);
|
|
@@ -7024,14 +7019,14 @@ var MineRenderWorld = class {
|
|
|
7024
7019
|
return this._chunks[index];
|
|
7025
7020
|
}
|
|
7026
7021
|
static worldToScenePosition(pos) {
|
|
7027
|
-
return new
|
|
7022
|
+
return new Vector310(
|
|
7028
7023
|
pos.x * 16,
|
|
7029
7024
|
pos.y * 16,
|
|
7030
7025
|
pos.z * 16
|
|
7031
7026
|
);
|
|
7032
7027
|
}
|
|
7033
7028
|
static sceneToWorldPosition(pos) {
|
|
7034
|
-
return new
|
|
7029
|
+
return new Vector310(
|
|
7035
7030
|
pos.x / 16,
|
|
7036
7031
|
pos.y / 16,
|
|
7037
7032
|
pos.z / 16
|
|
@@ -7073,7 +7068,7 @@ var Chunk = class _Chunk {
|
|
|
7073
7068
|
scene.add(anchor);
|
|
7074
7069
|
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
7075
7070
|
addBox3WireframeToObject(
|
|
7076
|
-
new Box32(new
|
|
7071
|
+
new Box32(new Vector311(0, 0, 0), new Vector311(256, 256, 256)),
|
|
7077
7072
|
anchor,
|
|
7078
7073
|
16776960,
|
|
7079
7074
|
4
|
|
@@ -7081,10 +7076,10 @@ var Chunk = class _Chunk {
|
|
|
7081
7076
|
}
|
|
7082
7077
|
getBlockAt(posOrX, y, z) {
|
|
7083
7078
|
if (typeof posOrX == "number") {
|
|
7084
|
-
return this.getBlockAt(new
|
|
7079
|
+
return this.getBlockAt(new Vector311(posOrX, y, z));
|
|
7085
7080
|
}
|
|
7086
7081
|
if (isTripleArray(posOrX)) {
|
|
7087
|
-
return this.getBlockAt(new
|
|
7082
|
+
return this.getBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]));
|
|
7088
7083
|
}
|
|
7089
7084
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
7090
7085
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
@@ -7092,10 +7087,10 @@ var Chunk = class _Chunk {
|
|
|
7092
7087
|
}
|
|
7093
7088
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
7094
7089
|
if (typeof posOrX == "number") {
|
|
7095
|
-
return this.setBlockAt(new
|
|
7090
|
+
return this.setBlockAt(new Vector311(posOrX, yOrBlock, z), block);
|
|
7096
7091
|
}
|
|
7097
7092
|
if (isTripleArray(posOrX)) {
|
|
7098
|
-
return this.setBlockAt(new
|
|
7093
|
+
return this.setBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
7099
7094
|
}
|
|
7100
7095
|
const worldPos = posOrX;
|
|
7101
7096
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -7141,7 +7136,7 @@ var Chunk = class _Chunk {
|
|
|
7141
7136
|
}
|
|
7142
7137
|
async clear() {
|
|
7143
7138
|
let promises = [];
|
|
7144
|
-
let pos = new
|
|
7139
|
+
let pos = new Vector311();
|
|
7145
7140
|
for (let x = 0; x < 16; x++) {
|
|
7146
7141
|
for (let z = 0; z < 16; z++) {
|
|
7147
7142
|
for (let y = 0; y < 16; y++) {
|
|
@@ -7160,14 +7155,14 @@ var Chunk = class _Chunk {
|
|
|
7160
7155
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
7161
7156
|
}
|
|
7162
7157
|
worldPosToChunkPos(pos) {
|
|
7163
|
-
return new
|
|
7158
|
+
return new Vector311(
|
|
7164
7159
|
pos.x - this.x * 16,
|
|
7165
7160
|
pos.y - this.y * 16,
|
|
7166
7161
|
pos.z - this.z * 16
|
|
7167
7162
|
);
|
|
7168
7163
|
}
|
|
7169
7164
|
chunkPosToWorldPos(pos) {
|
|
7170
|
-
return new
|
|
7165
|
+
return new Vector311(
|
|
7171
7166
|
this.x * 16 + pos.x,
|
|
7172
7167
|
this.y * 16 + pos.y,
|
|
7173
7168
|
this.z * 16 + pos.z
|
|
@@ -7188,7 +7183,6 @@ export {
|
|
|
7188
7183
|
BUILTIN_GENERATED,
|
|
7189
7184
|
BasicAssetKey,
|
|
7190
7185
|
BatchedExecutor,
|
|
7191
|
-
BlockEntityModels,
|
|
7192
7186
|
BlockObject,
|
|
7193
7187
|
BlockStates,
|
|
7194
7188
|
BlockTints,
|
|
@@ -7208,7 +7202,6 @@ export {
|
|
|
7208
7202
|
DisplayPosition,
|
|
7209
7203
|
DisplayTransforms,
|
|
7210
7204
|
Entities,
|
|
7211
|
-
EntityModels,
|
|
7212
7205
|
EntityObject,
|
|
7213
7206
|
Env,
|
|
7214
7207
|
Geometries,
|
|
@@ -7262,7 +7255,6 @@ export {
|
|
|
7262
7255
|
addWireframeToObject,
|
|
7263
7256
|
applyElementRotation,
|
|
7264
7257
|
applyGenericRotation,
|
|
7265
|
-
applyModelPartRotation,
|
|
7266
7258
|
axisToVec3,
|
|
7267
7259
|
base64decode,
|
|
7268
7260
|
base64encode,
|