minerender 2.1.0-alpha.22 → 2.1.0-alpha.24
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 +43 -48
- package/dist/browser/index.d.ts +43 -48
- package/dist/browser/index.js +121 -147
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +170 -196
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +125 -153
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +43 -48
- package/dist/node/index.d.ts +43 -48
- package/dist/node/index.js +120 -150
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +169 -196
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -137,7 +137,6 @@ __export(index_browser_exports, {
|
|
|
137
137
|
BUILTIN_GENERATED: () => BUILTIN_GENERATED,
|
|
138
138
|
BasicAssetKey: () => BasicAssetKey,
|
|
139
139
|
BatchedExecutor: () => BatchedExecutor,
|
|
140
|
-
BlockEntityModels: () => BlockEntityModels,
|
|
141
140
|
BlockObject: () => BlockObject,
|
|
142
141
|
BlockStates: () => BlockStates,
|
|
143
142
|
BlockTints: () => BlockTints,
|
|
@@ -159,7 +158,6 @@ __export(index_browser_exports, {
|
|
|
159
158
|
DisplayPosition: () => DisplayPosition,
|
|
160
159
|
DisplayTransforms: () => DisplayTransforms,
|
|
161
160
|
Entities: () => Entities,
|
|
162
|
-
EntityModels: () => EntityModels,
|
|
163
161
|
EntityObject: () => EntityObject,
|
|
164
162
|
Env: () => Env,
|
|
165
163
|
Geometries: () => Geometries,
|
|
@@ -211,7 +209,6 @@ __export(index_browser_exports, {
|
|
|
211
209
|
addWireframeToObject: () => addWireframeToObject,
|
|
212
210
|
applyElementRotation: () => applyElementRotation,
|
|
213
211
|
applyGenericRotation: () => applyGenericRotation,
|
|
214
|
-
applyModelPartRotation: () => applyModelPartRotation,
|
|
215
212
|
axisToVec3: () => axisToVec3,
|
|
216
213
|
base64decode: () => base64decode,
|
|
217
214
|
base64encode: () => base64encode,
|
|
@@ -571,7 +568,7 @@ var _Caching = class _Caching {
|
|
|
571
568
|
this.listAssetCache,
|
|
572
569
|
this.defaultBlockStatesCache,
|
|
573
570
|
this.blockTintCache,
|
|
574
|
-
this.
|
|
571
|
+
this.entityModelCache
|
|
575
572
|
];
|
|
576
573
|
}
|
|
577
574
|
static clear() {
|
|
@@ -614,7 +611,7 @@ _Caching.blockStateCache = import_loading_cache.Caches.builder().expireAfterWrit
|
|
|
614
611
|
_Caching.listAssetCache = _Caching.createAssetCache();
|
|
615
612
|
_Caching.defaultBlockStatesCache = _Caching.createAssetCache();
|
|
616
613
|
_Caching.blockTintCache = _Caching.createAssetCache();
|
|
617
|
-
_Caching.
|
|
614
|
+
_Caching.entityModelCache = _Caching.createAssetCache();
|
|
618
615
|
var Caching = _Caching;
|
|
619
616
|
|
|
620
617
|
// src/Geometries.ts
|
|
@@ -1558,7 +1555,7 @@ var BlockStates = class {
|
|
|
1558
1555
|
void 0,
|
|
1559
1556
|
"assets",
|
|
1560
1557
|
".json",
|
|
1561
|
-
|
|
1558
|
+
AssetLoader.ROOT
|
|
1562
1559
|
);
|
|
1563
1560
|
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1564
1561
|
return AssetLoader.get(key, "list" /* LIST */);
|
|
@@ -1693,14 +1690,6 @@ function applyElementRotation(rotation, geometry) {
|
|
|
1693
1690
|
}
|
|
1694
1691
|
geometry.translate(origin.x, origin.y, origin.z);
|
|
1695
1692
|
}
|
|
1696
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
1697
|
-
const origin = new import_three8.Vector3(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1698
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1699
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1700
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1701
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1702
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
1703
|
-
}
|
|
1704
1693
|
function applyGenericRotation(axis, rotation, obj) {
|
|
1705
1694
|
switch (axis) {
|
|
1706
1695
|
case "x" /* X */:
|
|
@@ -1799,17 +1788,17 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1799
1788
|
if (typeof namespaced !== "undefined") {
|
|
1800
1789
|
return namespaced;
|
|
1801
1790
|
}
|
|
1802
|
-
if (typeof key.root !== "undefined" && key.root !==
|
|
1791
|
+
if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
|
|
1803
1792
|
console.info(p3, "Retrying", key, "with default root+namespace");
|
|
1804
|
-
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension,
|
|
1793
|
+
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
|
|
1805
1794
|
const namespacedRooted = await this.load(namespacedRootedKey, parser);
|
|
1806
1795
|
if (typeof namespacedRooted !== "undefined") {
|
|
1807
1796
|
return namespacedRooted;
|
|
1808
1797
|
}
|
|
1809
1798
|
}
|
|
1810
|
-
} else if (typeof key.root !== "undefined" && key.root !==
|
|
1799
|
+
} else if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
|
|
1811
1800
|
console.info(p3, "Retrying", key, "with default root");
|
|
1812
|
-
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension,
|
|
1801
|
+
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
|
|
1813
1802
|
const rooted = await this.load(rootKey, parser);
|
|
1814
1803
|
if (typeof rooted !== "undefined") {
|
|
1815
1804
|
return rooted;
|
|
@@ -1998,6 +1987,20 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
|
|
|
1998
1987
|
// src/assets/AssetLoader.ts
|
|
1999
1988
|
var p4 = prefix("AssetLoader");
|
|
2000
1989
|
var _AssetLoader = class _AssetLoader {
|
|
1990
|
+
static get version() {
|
|
1991
|
+
return this.ROOT.substring(this.ROOT.lastIndexOf("/") + 1);
|
|
1992
|
+
}
|
|
1993
|
+
static setVersion(version) {
|
|
1994
|
+
this.ROOT = `https://assets.mcasset.cloud/${version}`;
|
|
1995
|
+
const source = new HostedAssetSource(this.ROOT, { retryDefaults: false });
|
|
1996
|
+
const index = this._SOURCES.findIndex((s) => s.key === "mcassets");
|
|
1997
|
+
if (index !== -1) {
|
|
1998
|
+
this._SOURCES[index] = { key: "mcassets", source };
|
|
1999
|
+
} else {
|
|
2000
|
+
this.addSource("mcassets", source);
|
|
2001
|
+
}
|
|
2002
|
+
Caching.clear();
|
|
2003
|
+
}
|
|
2001
2004
|
static addSource(key, source, override = true) {
|
|
2002
2005
|
if (override) {
|
|
2003
2006
|
const existing = this.removeSource(key);
|
|
@@ -2060,7 +2063,7 @@ var _AssetLoader = class _AssetLoader {
|
|
|
2060
2063
|
_AssetLoader.ROOT = DEFAULT_ROOT;
|
|
2061
2064
|
_AssetLoader._SOURCES = [];
|
|
2062
2065
|
_AssetLoader.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
|
|
2063
|
-
_AssetLoader.addSource("mcassets", new HostedAssetSource(
|
|
2066
|
+
_AssetLoader.addSource("mcassets", new HostedAssetSource(_AssetLoader.ROOT, { retryDefaults: false }));
|
|
2064
2067
|
var AssetLoader = _AssetLoader;
|
|
2065
2068
|
|
|
2066
2069
|
// src/assets/ModelTextures.ts
|
|
@@ -2708,18 +2711,18 @@ var MinecraftCubeTexture = class {
|
|
|
2708
2711
|
}
|
|
2709
2712
|
getUvEast(w, h, l) {
|
|
2710
2713
|
return [
|
|
2711
|
-
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2712
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2713
|
-
[this.mapW(this.u), this.mapH(this.v + l)],
|
|
2714
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2714
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2715
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2716
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2717
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2715
2718
|
];
|
|
2716
2719
|
}
|
|
2717
2720
|
getUvWest(w, h, l) {
|
|
2718
2721
|
return [
|
|
2719
|
-
[this.mapW(this.u + l
|
|
2720
|
-
[this.mapW(this.u
|
|
2721
|
-
[this.mapW(this.u + l
|
|
2722
|
-
[this.mapW(this.u
|
|
2722
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2723
|
+
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2724
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2725
|
+
[this.mapW(this.u), this.mapH(this.v + l)]
|
|
2723
2726
|
];
|
|
2724
2727
|
}
|
|
2725
2728
|
getUvUp(w, h, l) {
|
|
@@ -2732,26 +2735,26 @@ var MinecraftCubeTexture = class {
|
|
|
2732
2735
|
}
|
|
2733
2736
|
getUvDown(w, h, l) {
|
|
2734
2737
|
return [
|
|
2735
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2736
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2737
2738
|
[this.mapW(this.u + l), this.mapH(this.v)],
|
|
2738
|
-
[this.mapW(this.u + l + w), this.mapH(this.v)]
|
|
2739
|
+
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
2740
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2741
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2739
2742
|
];
|
|
2740
2743
|
}
|
|
2741
2744
|
getUvSouth(w, h, l) {
|
|
2742
2745
|
return [
|
|
2743
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2744
2746
|
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l + h)],
|
|
2745
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2746
|
-
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)]
|
|
2747
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2748
|
+
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)],
|
|
2749
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)]
|
|
2747
2750
|
];
|
|
2748
2751
|
}
|
|
2749
2752
|
getUvNorth(w, h, l) {
|
|
2750
2753
|
return [
|
|
2751
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2752
2754
|
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2753
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2754
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2755
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2756
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2757
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2755
2758
|
];
|
|
2756
2759
|
}
|
|
2757
2760
|
getFaceUv(face, w, h, l) {
|
|
@@ -2770,10 +2773,12 @@ var MinecraftCubeTexture = class {
|
|
|
2770
2773
|
return this.getUvNorth(w, h, l);
|
|
2771
2774
|
}
|
|
2772
2775
|
}
|
|
2773
|
-
toUvArray(w, h, l) {
|
|
2776
|
+
toUvArray(w, h, l, mirror = false) {
|
|
2774
2777
|
const uv = [];
|
|
2775
2778
|
for (let i = 0; i < CUBE_FACES.length; i++) {
|
|
2776
|
-
|
|
2779
|
+
const face = mirror && i < 2 ? CUBE_FACES[1 - i] : CUBE_FACES[i];
|
|
2780
|
+
const corners = this.getFaceUv(face, w, h, l);
|
|
2781
|
+
UVMapper.setFaceUvInArray(uv, i * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
|
|
2777
2782
|
}
|
|
2778
2783
|
return uv;
|
|
2779
2784
|
}
|
|
@@ -2803,69 +2808,51 @@ function shutdown() {
|
|
|
2803
2808
|
Caching.end();
|
|
2804
2809
|
}
|
|
2805
2810
|
|
|
2806
|
-
// src/
|
|
2807
|
-
var
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2812
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2813
|
-
});
|
|
2814
|
-
}
|
|
2815
|
-
static async getEntityModels() {
|
|
2816
|
-
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2817
|
-
console.log(key);
|
|
2818
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2819
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2820
|
-
});
|
|
2811
|
+
// src/error/MineRenderError.ts
|
|
2812
|
+
var MineRenderError = class _MineRenderError extends Error {
|
|
2813
|
+
constructor(msg) {
|
|
2814
|
+
super(msg);
|
|
2815
|
+
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2821
2816
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
const models = await this.getBlockEntityModels();
|
|
2825
|
-
if (!models) {
|
|
2826
|
-
return [];
|
|
2827
|
-
}
|
|
2828
|
-
return Object.keys(models);
|
|
2817
|
+
get name() {
|
|
2818
|
+
return "MineRenderError";
|
|
2829
2819
|
}
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2822
|
+
// src/assets/Entities.ts
|
|
2823
|
+
var Entities = class {
|
|
2830
2824
|
static async getEntityList() {
|
|
2831
|
-
const
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
if (!models) {
|
|
2840
|
-
return void 0;
|
|
2841
|
-
}
|
|
2842
|
-
if (!textureKey) {
|
|
2843
|
-
textureKey = modelKey;
|
|
2844
|
-
}
|
|
2845
|
-
const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
|
|
2846
|
-
return {
|
|
2847
|
-
key: textureKey,
|
|
2848
|
-
parts: models[baseKey.toNamespacedString()]
|
|
2825
|
+
const collect = async (path) => {
|
|
2826
|
+
const prefix2 = path ? `${path}/` : "";
|
|
2827
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
|
|
2828
|
+
const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
2829
|
+
if (!list) return [];
|
|
2830
|
+
const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
|
|
2831
|
+
const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
2832
|
+
return [...files, ...children.flat()];
|
|
2849
2833
|
};
|
|
2834
|
+
return collect("");
|
|
2850
2835
|
}
|
|
2851
|
-
static async getEntity(modelKey, textureKey) {
|
|
2852
|
-
const
|
|
2853
|
-
|
|
2854
|
-
|
|
2836
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
2837
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2838
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2839
|
+
const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
2840
|
+
if (!model) return void 0;
|
|
2841
|
+
const layerName = options?.layer ?? "main";
|
|
2842
|
+
const layer = model.layers[layerName];
|
|
2843
|
+
if (!layer) {
|
|
2844
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
2855
2845
|
}
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
return
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2846
|
+
return { key: textureKey ?? modelKey, layer, id: model.id };
|
|
2847
|
+
}
|
|
2848
|
+
/** @deprecated Use getEntityList(); block entities share the entity dataset. */
|
|
2849
|
+
static getBlockList() {
|
|
2850
|
+
return this.getEntityList();
|
|
2851
|
+
}
|
|
2852
|
+
/** @deprecated Use getEntity(); block entities share the entity dataset. */
|
|
2853
|
+
static getBlock(modelKey, textureKey, options) {
|
|
2854
|
+
return this.getEntity(modelKey, textureKey, options);
|
|
2864
2855
|
}
|
|
2865
|
-
};
|
|
2866
|
-
var EntityModels = class {
|
|
2867
|
-
};
|
|
2868
|
-
var BlockEntityModels = class {
|
|
2869
2856
|
};
|
|
2870
2857
|
|
|
2871
2858
|
// src/renderer/SceneObject.ts
|
|
@@ -2914,17 +2901,6 @@ function isInstanceReference(obj) {
|
|
|
2914
2901
|
return obj.isInstanceReference;
|
|
2915
2902
|
}
|
|
2916
2903
|
|
|
2917
|
-
// src/error/MineRenderError.ts
|
|
2918
|
-
var MineRenderError = class _MineRenderError extends Error {
|
|
2919
|
-
constructor(msg) {
|
|
2920
|
-
super(msg);
|
|
2921
|
-
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2922
|
-
}
|
|
2923
|
-
get name() {
|
|
2924
|
-
return "MineRenderError";
|
|
2925
|
-
}
|
|
2926
|
-
};
|
|
2927
|
-
|
|
2928
2904
|
// src/renderer/SceneObject.ts
|
|
2929
2905
|
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2930
2906
|
var p6 = prefix("SceneObject");
|
|
@@ -3050,15 +3026,8 @@ var _SceneObject = class _SceneObject extends import_three10.Object3D {
|
|
|
3050
3026
|
return this.toggleObjectVisibility(this.getMeshByName(name), visible);
|
|
3051
3027
|
}
|
|
3052
3028
|
iterateAllMeshes(cb) {
|
|
3053
|
-
this.
|
|
3054
|
-
if (obj
|
|
3055
|
-
cb(obj);
|
|
3056
|
-
}
|
|
3057
|
-
obj.children.forEach((obj1) => {
|
|
3058
|
-
if (obj1.isMesh) {
|
|
3059
|
-
cb(obj1);
|
|
3060
|
-
}
|
|
3061
|
-
});
|
|
3029
|
+
this.traverse((obj) => {
|
|
3030
|
+
if (isMesh(obj)) cb(obj);
|
|
3062
3031
|
});
|
|
3063
3032
|
}
|
|
3064
3033
|
//</editor-fold>
|
|
@@ -3303,14 +3272,13 @@ function isSceneObject(obj) {
|
|
|
3303
3272
|
// src/entity/scene/EntityObject.ts
|
|
3304
3273
|
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
3305
3274
|
var import_three12 = require("three");
|
|
3306
|
-
var
|
|
3307
|
-
var EntityObject = class extends SceneObject {
|
|
3275
|
+
var _EntityObject = class _EntityObject extends SceneObject {
|
|
3308
3276
|
constructor(entity, options) {
|
|
3309
3277
|
super();
|
|
3310
3278
|
this.entity = entity;
|
|
3311
3279
|
this.isEntityObject = true;
|
|
3312
3280
|
this.meshesCreated = false;
|
|
3313
|
-
this.options = (0, import_ts_deepmerge4.default)({},
|
|
3281
|
+
this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
|
|
3314
3282
|
}
|
|
3315
3283
|
async init() {
|
|
3316
3284
|
this.createMeshes();
|
|
@@ -3320,10 +3288,10 @@ var EntityObject = class extends SceneObject {
|
|
|
3320
3288
|
super.dispose();
|
|
3321
3289
|
}
|
|
3322
3290
|
get textureKey() {
|
|
3291
|
+
const key = this.entity.key;
|
|
3323
3292
|
return new AssetKey(
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
3293
|
+
key.namespace,
|
|
3294
|
+
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
3327
3295
|
"textures",
|
|
3328
3296
|
"entity",
|
|
3329
3297
|
"assets",
|
|
@@ -3333,36 +3301,41 @@ var EntityObject = class extends SceneObject {
|
|
|
3333
3301
|
async loadTextures() {
|
|
3334
3302
|
this.imageData = await ModelTextures.get(this.textureKey);
|
|
3335
3303
|
}
|
|
3336
|
-
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
3337
3304
|
createMeshes(force = false) {
|
|
3338
3305
|
if (this.meshesCreated && !force) return;
|
|
3339
|
-
const
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
const partAnchor = new import_three12.Object3D();
|
|
3344
|
-
partAnchor.position.x = part.pivotX;
|
|
3345
|
-
partAnchor.position.y = part.pivotY;
|
|
3346
|
-
partAnchor.position.z = part.pivotZ;
|
|
3347
|
-
for (let cube of part.cubes) {
|
|
3348
|
-
const w = cube.maxX - cube.minX;
|
|
3349
|
-
const h = cube.maxY - cube.minY;
|
|
3350
|
-
const l = cube.maxZ - cube.minZ;
|
|
3351
|
-
const uv = texture.toUvArray(w, h, l);
|
|
3352
|
-
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
3353
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3354
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
3355
|
-
applyModelPartRotation(part, cubeGeo);
|
|
3356
|
-
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
3357
|
-
partAnchor.add(mesh);
|
|
3358
|
-
if (this.options.wireframe) {
|
|
3359
|
-
addWireframeToMesh(cubeGeo, mesh);
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
this.add(partAnchor);
|
|
3363
|
-
}
|
|
3306
|
+
const modelRoot = new import_three12.Object3D();
|
|
3307
|
+
if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
|
|
3308
|
+
this.add(modelRoot);
|
|
3309
|
+
this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
|
|
3364
3310
|
this.meshesCreated = true;
|
|
3365
3311
|
}
|
|
3312
|
+
createPart(name, part, parent, textureSize, material) {
|
|
3313
|
+
const anchor = this.createGroup(name);
|
|
3314
|
+
anchor.position.fromArray(part.pose.offset);
|
|
3315
|
+
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
3316
|
+
anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
|
|
3317
|
+
parent.add(anchor);
|
|
3318
|
+
const size = part.texture ?? textureSize;
|
|
3319
|
+
for (const cube of part.cubes) {
|
|
3320
|
+
const [width, height, depth] = cube.size;
|
|
3321
|
+
const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
|
|
3322
|
+
const texture = new MinecraftCubeTexture(...cube.uv, ...size);
|
|
3323
|
+
const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
|
|
3324
|
+
const geometry = this._getBoxGeometryForDimensionsAndUv(
|
|
3325
|
+
width + growX * 2,
|
|
3326
|
+
height + growY * 2,
|
|
3327
|
+
depth + growZ * 2,
|
|
3328
|
+
uv
|
|
3329
|
+
).clone();
|
|
3330
|
+
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
3331
|
+
const mesh = this.createMesh(name, geometry, material);
|
|
3332
|
+
anchor.add(mesh);
|
|
3333
|
+
if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
|
|
3334
|
+
}
|
|
3335
|
+
for (const [childName, child] of Object.entries(part.children)) {
|
|
3336
|
+
this.createPart(childName, child, anchor, size, material);
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3366
3339
|
async applyTextures() {
|
|
3367
3340
|
const assetKeyStr = this.textureKey.serialize();
|
|
3368
3341
|
const keyStr = `entity:${assetKeyStr}`;
|
|
@@ -3383,7 +3356,8 @@ var EntityObject = class extends SceneObject {
|
|
|
3383
3356
|
this.notifyDirty();
|
|
3384
3357
|
}
|
|
3385
3358
|
};
|
|
3386
|
-
|
|
3359
|
+
_EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
|
|
3360
|
+
var EntityObject = _EntityObject;
|
|
3387
3361
|
function isEntityObject(obj) {
|
|
3388
3362
|
return obj.isEntityObject;
|
|
3389
3363
|
}
|