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/node/index.js
CHANGED
|
@@ -137,7 +137,6 @@ __export(index_node_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,
|
|
@@ -157,7 +156,6 @@ __export(index_node_exports, {
|
|
|
157
156
|
DisplayPosition: () => DisplayPosition,
|
|
158
157
|
DisplayTransforms: () => DisplayTransforms,
|
|
159
158
|
Entities: () => Entities,
|
|
160
|
-
EntityModels: () => EntityModels,
|
|
161
159
|
EntityObject: () => EntityObject,
|
|
162
160
|
Env: () => Env,
|
|
163
161
|
Geometries: () => Geometries,
|
|
@@ -211,7 +209,6 @@ __export(index_node_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,
|
|
@@ -562,7 +559,7 @@ var Caching = class _Caching {
|
|
|
562
559
|
this.blockTintCache = _Caching.createAssetCache();
|
|
563
560
|
}
|
|
564
561
|
static {
|
|
565
|
-
this.
|
|
562
|
+
this.entityModelCache = _Caching.createAssetCache();
|
|
566
563
|
}
|
|
567
564
|
static createAssetCache() {
|
|
568
565
|
return import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
|
|
@@ -587,7 +584,7 @@ var Caching = class _Caching {
|
|
|
587
584
|
this.listAssetCache,
|
|
588
585
|
this.defaultBlockStatesCache,
|
|
589
586
|
this.blockTintCache,
|
|
590
|
-
this.
|
|
587
|
+
this.entityModelCache
|
|
591
588
|
];
|
|
592
589
|
}
|
|
593
590
|
static clear() {
|
|
@@ -1562,7 +1559,7 @@ var BlockStates = class {
|
|
|
1562
1559
|
void 0,
|
|
1563
1560
|
"assets",
|
|
1564
1561
|
".json",
|
|
1565
|
-
|
|
1562
|
+
AssetLoader.ROOT
|
|
1566
1563
|
);
|
|
1567
1564
|
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1568
1565
|
return AssetLoader.get(key, "list" /* LIST */);
|
|
@@ -1697,14 +1694,6 @@ function applyElementRotation(rotation, geometry) {
|
|
|
1697
1694
|
}
|
|
1698
1695
|
geometry.translate(origin.x, origin.y, origin.z);
|
|
1699
1696
|
}
|
|
1700
|
-
function applyModelPartRotation(modelPart, geometry) {
|
|
1701
|
-
const origin = new import_three8.Vector3(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
|
|
1702
|
-
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1703
|
-
geometry.rotateX(toRadians(modelPart.pitch));
|
|
1704
|
-
geometry.rotateY(toRadians(modelPart.yaw));
|
|
1705
|
-
geometry.rotateZ(toRadians(modelPart.roll));
|
|
1706
|
-
geometry.translate(origin.x, origin.y, origin.z);
|
|
1707
|
-
}
|
|
1708
1697
|
function applyGenericRotation(axis, rotation, obj) {
|
|
1709
1698
|
switch (axis) {
|
|
1710
1699
|
case "x" /* X */:
|
|
@@ -1879,17 +1868,17 @@ var HostedAssetSource = class _HostedAssetSource extends AssetSource {
|
|
|
1879
1868
|
if (typeof namespaced !== "undefined") {
|
|
1880
1869
|
return namespaced;
|
|
1881
1870
|
}
|
|
1882
|
-
if (typeof key.root !== "undefined" && key.root !==
|
|
1871
|
+
if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
|
|
1883
1872
|
console.info(p3, "Retrying", key, "with default root+namespace");
|
|
1884
|
-
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension,
|
|
1873
|
+
const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
|
|
1885
1874
|
const namespacedRooted = await this.load(namespacedRootedKey, parser);
|
|
1886
1875
|
if (typeof namespacedRooted !== "undefined") {
|
|
1887
1876
|
return namespacedRooted;
|
|
1888
1877
|
}
|
|
1889
1878
|
}
|
|
1890
|
-
} else if (typeof key.root !== "undefined" && key.root !==
|
|
1879
|
+
} else if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
|
|
1891
1880
|
console.info(p3, "Retrying", key, "with default root");
|
|
1892
|
-
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension,
|
|
1881
|
+
const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
|
|
1893
1882
|
const rooted = await this.load(rootKey, parser);
|
|
1894
1883
|
if (typeof rooted !== "undefined") {
|
|
1895
1884
|
return rooted;
|
|
@@ -2023,6 +2012,20 @@ var AssetLoader = class {
|
|
|
2023
2012
|
static {
|
|
2024
2013
|
this._SOURCES = [];
|
|
2025
2014
|
}
|
|
2015
|
+
static get version() {
|
|
2016
|
+
return this.ROOT.substring(this.ROOT.lastIndexOf("/") + 1);
|
|
2017
|
+
}
|
|
2018
|
+
static setVersion(version) {
|
|
2019
|
+
this.ROOT = `https://assets.mcasset.cloud/${version}`;
|
|
2020
|
+
const source = new HostedAssetSource(this.ROOT, { retryDefaults: false });
|
|
2021
|
+
const index = this._SOURCES.findIndex((s) => s.key === "mcassets");
|
|
2022
|
+
if (index !== -1) {
|
|
2023
|
+
this._SOURCES[index] = { key: "mcassets", source };
|
|
2024
|
+
} else {
|
|
2025
|
+
this.addSource("mcassets", source);
|
|
2026
|
+
}
|
|
2027
|
+
Caching.clear();
|
|
2028
|
+
}
|
|
2026
2029
|
static addSource(key, source, override = true) {
|
|
2027
2030
|
if (override) {
|
|
2028
2031
|
const existing = this.removeSource(key);
|
|
@@ -2045,7 +2048,7 @@ var AssetLoader = class {
|
|
|
2045
2048
|
}
|
|
2046
2049
|
static {
|
|
2047
2050
|
this.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
|
|
2048
|
-
this.addSource("mcassets", new HostedAssetSource(
|
|
2051
|
+
this.addSource("mcassets", new HostedAssetSource(this.ROOT, { retryDefaults: false }));
|
|
2049
2052
|
}
|
|
2050
2053
|
static async getAll(key, parser) {
|
|
2051
2054
|
let promises = [];
|
|
@@ -2747,18 +2750,18 @@ var MinecraftCubeTexture = class {
|
|
|
2747
2750
|
}
|
|
2748
2751
|
getUvEast(w, h, l) {
|
|
2749
2752
|
return [
|
|
2750
|
-
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2751
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2752
|
-
[this.mapW(this.u), this.mapH(this.v + l)],
|
|
2753
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2753
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2754
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2755
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2756
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2754
2757
|
];
|
|
2755
2758
|
}
|
|
2756
2759
|
getUvWest(w, h, l) {
|
|
2757
2760
|
return [
|
|
2758
|
-
[this.mapW(this.u + l
|
|
2759
|
-
[this.mapW(this.u
|
|
2760
|
-
[this.mapW(this.u + l
|
|
2761
|
-
[this.mapW(this.u
|
|
2761
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2762
|
+
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
2763
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2764
|
+
[this.mapW(this.u), this.mapH(this.v + l)]
|
|
2762
2765
|
];
|
|
2763
2766
|
}
|
|
2764
2767
|
getUvUp(w, h, l) {
|
|
@@ -2771,26 +2774,26 @@ var MinecraftCubeTexture = class {
|
|
|
2771
2774
|
}
|
|
2772
2775
|
getUvDown(w, h, l) {
|
|
2773
2776
|
return [
|
|
2774
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2775
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2776
2777
|
[this.mapW(this.u + l), this.mapH(this.v)],
|
|
2777
|
-
[this.mapW(this.u + l + w), this.mapH(this.v)]
|
|
2778
|
+
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
2779
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2780
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2778
2781
|
];
|
|
2779
2782
|
}
|
|
2780
2783
|
getUvSouth(w, h, l) {
|
|
2781
2784
|
return [
|
|
2782
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2783
2785
|
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l + h)],
|
|
2784
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
2785
|
-
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)]
|
|
2786
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
2787
|
+
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)],
|
|
2788
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)]
|
|
2786
2789
|
];
|
|
2787
2790
|
}
|
|
2788
2791
|
getUvNorth(w, h, l) {
|
|
2789
2792
|
return [
|
|
2790
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2791
2793
|
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
2792
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
2793
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
2794
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
2795
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
2796
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
2794
2797
|
];
|
|
2795
2798
|
}
|
|
2796
2799
|
getFaceUv(face, w, h, l) {
|
|
@@ -2809,10 +2812,12 @@ var MinecraftCubeTexture = class {
|
|
|
2809
2812
|
return this.getUvNorth(w, h, l);
|
|
2810
2813
|
}
|
|
2811
2814
|
}
|
|
2812
|
-
toUvArray(w, h, l) {
|
|
2815
|
+
toUvArray(w, h, l, mirror = false) {
|
|
2813
2816
|
const uv = [];
|
|
2814
2817
|
for (let i = 0; i < CUBE_FACES.length; i++) {
|
|
2815
|
-
|
|
2818
|
+
const face = mirror && i < 2 ? CUBE_FACES[1 - i] : CUBE_FACES[i];
|
|
2819
|
+
const corners = this.getFaceUv(face, w, h, l);
|
|
2820
|
+
UVMapper.setFaceUvInArray(uv, i * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
|
|
2816
2821
|
}
|
|
2817
2822
|
return uv;
|
|
2818
2823
|
}
|
|
@@ -2842,69 +2847,51 @@ function shutdown() {
|
|
|
2842
2847
|
Caching.end();
|
|
2843
2848
|
}
|
|
2844
2849
|
|
|
2845
|
-
// src/
|
|
2846
|
-
var
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2851
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2852
|
-
});
|
|
2853
|
-
}
|
|
2854
|
-
static async getEntityModels() {
|
|
2855
|
-
const key = AssetKey.parse("models", "minerender:entityModels");
|
|
2856
|
-
console.log(key);
|
|
2857
|
-
return Caching.entityModelsCache.get(key.serialize(), () => {
|
|
2858
|
-
return AssetLoader.get(key, "json" /* JSON */);
|
|
2859
|
-
});
|
|
2850
|
+
// src/error/MineRenderError.ts
|
|
2851
|
+
var MineRenderError = class _MineRenderError extends Error {
|
|
2852
|
+
constructor(msg) {
|
|
2853
|
+
super(msg);
|
|
2854
|
+
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2860
2855
|
}
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
const models = await this.getBlockEntityModels();
|
|
2864
|
-
if (!models) {
|
|
2865
|
-
return [];
|
|
2866
|
-
}
|
|
2867
|
-
return Object.keys(models);
|
|
2856
|
+
get name() {
|
|
2857
|
+
return "MineRenderError";
|
|
2868
2858
|
}
|
|
2859
|
+
};
|
|
2860
|
+
|
|
2861
|
+
// src/assets/Entities.ts
|
|
2862
|
+
var Entities = class {
|
|
2869
2863
|
static async getEntityList() {
|
|
2870
|
-
const
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
if (!models) {
|
|
2879
|
-
return void 0;
|
|
2880
|
-
}
|
|
2881
|
-
if (!textureKey) {
|
|
2882
|
-
textureKey = modelKey;
|
|
2883
|
-
}
|
|
2884
|
-
const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
|
|
2885
|
-
return {
|
|
2886
|
-
key: textureKey,
|
|
2887
|
-
parts: models[baseKey.toNamespacedString()]
|
|
2864
|
+
const collect = async (path) => {
|
|
2865
|
+
const prefix2 = path ? `${path}/` : "";
|
|
2866
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
|
|
2867
|
+
const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
2868
|
+
if (!list) return [];
|
|
2869
|
+
const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
|
|
2870
|
+
const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
2871
|
+
return [...files, ...children.flat()];
|
|
2888
2872
|
};
|
|
2873
|
+
return collect("");
|
|
2889
2874
|
}
|
|
2890
|
-
static async getEntity(modelKey, textureKey) {
|
|
2891
|
-
const
|
|
2892
|
-
|
|
2893
|
-
|
|
2875
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
2876
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2877
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2878
|
+
const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
2879
|
+
if (!model) return void 0;
|
|
2880
|
+
const layerName = options?.layer ?? "main";
|
|
2881
|
+
const layer = model.layers[layerName];
|
|
2882
|
+
if (!layer) {
|
|
2883
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
2894
2884
|
}
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
return
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2885
|
+
return { key: textureKey ?? modelKey, layer, id: model.id };
|
|
2886
|
+
}
|
|
2887
|
+
/** @deprecated Use getEntityList(); block entities share the entity dataset. */
|
|
2888
|
+
static getBlockList() {
|
|
2889
|
+
return this.getEntityList();
|
|
2890
|
+
}
|
|
2891
|
+
/** @deprecated Use getEntity(); block entities share the entity dataset. */
|
|
2892
|
+
static getBlock(modelKey, textureKey, options) {
|
|
2893
|
+
return this.getEntity(modelKey, textureKey, options);
|
|
2903
2894
|
}
|
|
2904
|
-
};
|
|
2905
|
-
var EntityModels = class {
|
|
2906
|
-
};
|
|
2907
|
-
var BlockEntityModels = class {
|
|
2908
2895
|
};
|
|
2909
2896
|
|
|
2910
2897
|
// src/renderer/SceneObject.ts
|
|
@@ -2953,17 +2940,6 @@ function isInstanceReference(obj) {
|
|
|
2953
2940
|
return obj.isInstanceReference;
|
|
2954
2941
|
}
|
|
2955
2942
|
|
|
2956
|
-
// src/error/MineRenderError.ts
|
|
2957
|
-
var MineRenderError = class _MineRenderError extends Error {
|
|
2958
|
-
constructor(msg) {
|
|
2959
|
-
super(msg);
|
|
2960
|
-
Object.setPrototypeOf(this, _MineRenderError.prototype);
|
|
2961
|
-
}
|
|
2962
|
-
get name() {
|
|
2963
|
-
return "MineRenderError";
|
|
2964
|
-
}
|
|
2965
|
-
};
|
|
2966
|
-
|
|
2967
2943
|
// src/renderer/SceneObject.ts
|
|
2968
2944
|
var import_ts_deepmerge3 = __toESM(require_dist());
|
|
2969
2945
|
var p6 = prefix("SceneObject");
|
|
@@ -3097,15 +3073,8 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
|
|
|
3097
3073
|
return this.toggleObjectVisibility(this.getMeshByName(name), visible);
|
|
3098
3074
|
}
|
|
3099
3075
|
iterateAllMeshes(cb) {
|
|
3100
|
-
this.
|
|
3101
|
-
if (obj
|
|
3102
|
-
cb(obj);
|
|
3103
|
-
}
|
|
3104
|
-
obj.children.forEach((obj1) => {
|
|
3105
|
-
if (obj1.isMesh) {
|
|
3106
|
-
cb(obj1);
|
|
3107
|
-
}
|
|
3108
|
-
});
|
|
3076
|
+
this.traverse((obj) => {
|
|
3077
|
+
if (isMesh(obj)) cb(obj);
|
|
3109
3078
|
});
|
|
3110
3079
|
}
|
|
3111
3080
|
//</editor-fold>
|
|
@@ -3343,17 +3312,16 @@ function isSceneObject(obj) {
|
|
|
3343
3312
|
// src/entity/scene/EntityObject.ts
|
|
3344
3313
|
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
3345
3314
|
var import_three12 = require("three");
|
|
3346
|
-
var
|
|
3347
|
-
var EntityObject = class extends SceneObject {
|
|
3315
|
+
var EntityObject = class _EntityObject extends SceneObject {
|
|
3348
3316
|
constructor(entity, options) {
|
|
3349
3317
|
super();
|
|
3350
3318
|
this.entity = entity;
|
|
3351
3319
|
this.isEntityObject = true;
|
|
3352
3320
|
this.meshesCreated = false;
|
|
3353
|
-
this.options = (0, import_ts_deepmerge4.default)({},
|
|
3321
|
+
this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
|
|
3354
3322
|
}
|
|
3355
3323
|
static {
|
|
3356
|
-
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
|
|
3324
|
+
this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
|
|
3357
3325
|
}
|
|
3358
3326
|
async init() {
|
|
3359
3327
|
this.createMeshes();
|
|
@@ -3363,10 +3331,10 @@ var EntityObject = class extends SceneObject {
|
|
|
3363
3331
|
super.dispose();
|
|
3364
3332
|
}
|
|
3365
3333
|
get textureKey() {
|
|
3334
|
+
const key = this.entity.key;
|
|
3366
3335
|
return new AssetKey(
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
//TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
|
|
3336
|
+
key.namespace,
|
|
3337
|
+
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
3370
3338
|
"textures",
|
|
3371
3339
|
"entity",
|
|
3372
3340
|
"assets",
|
|
@@ -3376,36 +3344,41 @@ var EntityObject = class extends SceneObject {
|
|
|
3376
3344
|
async loadTextures() {
|
|
3377
3345
|
this.imageData = await ModelTextures.get(this.textureKey);
|
|
3378
3346
|
}
|
|
3379
|
-
//TODO: abstract this, since extracted model data can be used for entities, blocks, players
|
|
3380
3347
|
createMeshes(force = false) {
|
|
3381
3348
|
if (this.meshesCreated && !force) return;
|
|
3382
|
-
const
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
const partAnchor = new import_three12.Object3D();
|
|
3387
|
-
partAnchor.position.x = part.pivotX;
|
|
3388
|
-
partAnchor.position.y = part.pivotY;
|
|
3389
|
-
partAnchor.position.z = part.pivotZ;
|
|
3390
|
-
for (let cube of part.cubes) {
|
|
3391
|
-
const w = cube.maxX - cube.minX;
|
|
3392
|
-
const h = cube.maxY - cube.minY;
|
|
3393
|
-
const l = cube.maxZ - cube.minZ;
|
|
3394
|
-
const uv = texture.toUvArray(w, h, l);
|
|
3395
|
-
const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w, h, l, uv).clone();
|
|
3396
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(w / 2, h / 2, l / 2));
|
|
3397
|
-
cubeGeo.applyMatrix4(new THREE3.Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
|
|
3398
|
-
applyModelPartRotation(part, cubeGeo);
|
|
3399
|
-
const mesh = this.createMesh(partName, cubeGeo, mat);
|
|
3400
|
-
partAnchor.add(mesh);
|
|
3401
|
-
if (this.options.wireframe) {
|
|
3402
|
-
addWireframeToMesh(cubeGeo, mesh);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
this.add(partAnchor);
|
|
3406
|
-
}
|
|
3349
|
+
const modelRoot = new import_three12.Object3D();
|
|
3350
|
+
if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
|
|
3351
|
+
this.add(modelRoot);
|
|
3352
|
+
this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
|
|
3407
3353
|
this.meshesCreated = true;
|
|
3408
3354
|
}
|
|
3355
|
+
createPart(name, part, parent, textureSize, material) {
|
|
3356
|
+
const anchor = this.createGroup(name);
|
|
3357
|
+
anchor.position.fromArray(part.pose.offset);
|
|
3358
|
+
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
3359
|
+
anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
|
|
3360
|
+
parent.add(anchor);
|
|
3361
|
+
const size = part.texture ?? textureSize;
|
|
3362
|
+
for (const cube of part.cubes) {
|
|
3363
|
+
const [width, height, depth] = cube.size;
|
|
3364
|
+
const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
|
|
3365
|
+
const texture = new MinecraftCubeTexture(...cube.uv, ...size);
|
|
3366
|
+
const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
|
|
3367
|
+
const geometry = this._getBoxGeometryForDimensionsAndUv(
|
|
3368
|
+
width + growX * 2,
|
|
3369
|
+
height + growY * 2,
|
|
3370
|
+
depth + growZ * 2,
|
|
3371
|
+
uv
|
|
3372
|
+
).clone();
|
|
3373
|
+
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
3374
|
+
const mesh = this.createMesh(name, geometry, material);
|
|
3375
|
+
anchor.add(mesh);
|
|
3376
|
+
if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
|
|
3377
|
+
}
|
|
3378
|
+
for (const [childName, child] of Object.entries(part.children)) {
|
|
3379
|
+
this.createPart(childName, child, anchor, size, material);
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3409
3382
|
async applyTextures() {
|
|
3410
3383
|
const assetKeyStr = this.textureKey.serialize();
|
|
3411
3384
|
const keyStr = `entity:${assetKeyStr}`;
|
|
@@ -7314,7 +7287,6 @@ var Chunk = class _Chunk {
|
|
|
7314
7287
|
BUILTIN_GENERATED,
|
|
7315
7288
|
BasicAssetKey,
|
|
7316
7289
|
BatchedExecutor,
|
|
7317
|
-
BlockEntityModels,
|
|
7318
7290
|
BlockObject,
|
|
7319
7291
|
BlockStates,
|
|
7320
7292
|
BlockTints,
|
|
@@ -7334,7 +7306,6 @@ var Chunk = class _Chunk {
|
|
|
7334
7306
|
DisplayPosition,
|
|
7335
7307
|
DisplayTransforms,
|
|
7336
7308
|
Entities,
|
|
7337
|
-
EntityModels,
|
|
7338
7309
|
EntityObject,
|
|
7339
7310
|
Env,
|
|
7340
7311
|
Geometries,
|
|
@@ -7388,7 +7359,6 @@ var Chunk = class _Chunk {
|
|
|
7388
7359
|
addWireframeToObject,
|
|
7389
7360
|
applyElementRotation,
|
|
7390
7361
|
applyGenericRotation,
|
|
7391
|
-
applyModelPartRotation,
|
|
7392
7362
|
axisToVec3,
|
|
7393
7363
|
base64decode,
|
|
7394
7364
|
base64encode,
|