minerender 2.1.0-alpha.12 → 2.1.0-alpha.14
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 +9 -2
- package/dist/browser/index.d.ts +9 -2
- package/dist/browser/index.js +78 -31
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +78 -31
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +78 -31
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +9 -2
- package/dist/node/index.d.ts +9 -2
- package/dist/node/index.js +78 -31
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +78 -31
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -278,7 +278,7 @@ registerBrowserEnv();
|
|
|
278
278
|
// src/Axis.ts
|
|
279
279
|
import { Vector3 } from "three";
|
|
280
280
|
var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
281
|
-
Axis3["X"] = "
|
|
281
|
+
Axis3["X"] = "x";
|
|
282
282
|
Axis3["Y"] = "y";
|
|
283
283
|
Axis3["Z"] = "z";
|
|
284
284
|
return Axis3;
|
|
@@ -286,7 +286,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
|
286
286
|
var AXES = Object.values(Axis);
|
|
287
287
|
function axisToVec3(axis) {
|
|
288
288
|
switch (axis) {
|
|
289
|
-
case "
|
|
289
|
+
case "x" /* X */:
|
|
290
290
|
return new Vector3(1, 0, 0);
|
|
291
291
|
case "y" /* Y */:
|
|
292
292
|
return new Vector3(0, 1, 0);
|
|
@@ -1139,7 +1139,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1139
1139
|
}
|
|
1140
1140
|
toString() {
|
|
1141
1141
|
let a = [
|
|
1142
|
-
|
|
1142
|
+
this.root ?? AssetLoader.ROOT,
|
|
1143
1143
|
this.rootType ?? "__rootType__",
|
|
1144
1144
|
this.assetType ?? "__assetType__",
|
|
1145
1145
|
this.type ?? "__type__",
|
|
@@ -1176,9 +1176,9 @@ var ModelMerger = class {
|
|
|
1176
1176
|
const models = await this.collectAllParents(model);
|
|
1177
1177
|
let merged = {};
|
|
1178
1178
|
for (let parentModel of models) {
|
|
1179
|
-
merged =
|
|
1179
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
|
|
1180
1180
|
}
|
|
1181
|
-
merged =
|
|
1181
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
|
|
1182
1182
|
merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
|
|
1183
1183
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1184
1184
|
return merged;
|
|
@@ -1189,6 +1189,7 @@ var ModelMerger = class {
|
|
|
1189
1189
|
}
|
|
1190
1190
|
const models = [];
|
|
1191
1191
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1192
|
+
parentKey.root = model.key?.root;
|
|
1192
1193
|
const parentModel = await Models.getRaw(parentKey);
|
|
1193
1194
|
if (parentModel) {
|
|
1194
1195
|
models.unshift(parentModel);
|
|
@@ -1218,26 +1219,58 @@ var Models = class _Models {
|
|
|
1218
1219
|
return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
|
|
1219
1220
|
}
|
|
1220
1221
|
static async getItemList() {
|
|
1221
|
-
const key = new AssetKey(
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
"
|
|
1225
|
-
"item",
|
|
1226
|
-
"assets",
|
|
1227
|
-
".json",
|
|
1228
|
-
DEFAULT_ROOT
|
|
1229
|
-
);
|
|
1230
|
-
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1231
|
-
return AssetLoader.get(key, "list" /* LIST */);
|
|
1222
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1223
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1224
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1225
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1232
1226
|
}).then((r) => r?.files ?? []);
|
|
1233
1227
|
}
|
|
1234
1228
|
static async loadAndMerge(key) {
|
|
1235
|
-
const model = await this.getRaw(key);
|
|
1229
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1236
1230
|
if (!model) {
|
|
1237
1231
|
return void 0;
|
|
1238
1232
|
}
|
|
1239
1233
|
return ModelMerger.mergeWithParents(model);
|
|
1240
1234
|
}
|
|
1235
|
+
static async getItemModel(key) {
|
|
1236
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1237
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1238
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1239
|
+
if (!result) return void 0;
|
|
1240
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1241
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1242
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1243
|
+
modelKey.root = key.root;
|
|
1244
|
+
const model2 = await this.getRaw(modelKey);
|
|
1245
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1246
|
+
return model2;
|
|
1247
|
+
});
|
|
1248
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1249
|
+
}
|
|
1250
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1251
|
+
static defaultItemModel(node, key) {
|
|
1252
|
+
if (!node || typeof node.type !== "string") {
|
|
1253
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1254
|
+
}
|
|
1255
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1256
|
+
case "model":
|
|
1257
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1258
|
+
break;
|
|
1259
|
+
case "condition":
|
|
1260
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1261
|
+
case "select": {
|
|
1262
|
+
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;
|
|
1263
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1264
|
+
}
|
|
1265
|
+
case "range_dispatch": {
|
|
1266
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1267
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1268
|
+
}, void 0);
|
|
1269
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1273
|
+
}
|
|
1241
1274
|
static async getRaw(key) {
|
|
1242
1275
|
if (!key.assetType) {
|
|
1243
1276
|
key.assetType = "models";
|
|
@@ -1344,7 +1377,7 @@ var DefaultBlockStates = class {
|
|
|
1344
1377
|
};
|
|
1345
1378
|
|
|
1346
1379
|
// src/assets/Assets.ts
|
|
1347
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1380
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1348
1381
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1349
1382
|
var Assets = class {
|
|
1350
1383
|
/**
|
|
@@ -1405,7 +1438,7 @@ function applyElementRotation(rotation, geometry) {
|
|
|
1405
1438
|
const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1406
1439
|
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1407
1440
|
switch (rotation.axis) {
|
|
1408
|
-
case "
|
|
1441
|
+
case "x" /* X */:
|
|
1409
1442
|
geometry.rotateX(toRadians(rotation.angle));
|
|
1410
1443
|
break;
|
|
1411
1444
|
case "y" /* Y */:
|
|
@@ -1436,7 +1469,7 @@ function applyModelPartRotation(modelPart, geometry) {
|
|
|
1436
1469
|
}
|
|
1437
1470
|
function applyGenericRotation(axis, rotation, obj) {
|
|
1438
1471
|
switch (axis) {
|
|
1439
|
-
case "
|
|
1472
|
+
case "x" /* X */:
|
|
1440
1473
|
obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
|
|
1441
1474
|
break;
|
|
1442
1475
|
case "y" /* Y */:
|
|
@@ -1762,11 +1795,29 @@ var _AssetLoader = class _AssetLoader {
|
|
|
1762
1795
|
}
|
|
1763
1796
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1764
1797
|
static async get(key, parser) {
|
|
1798
|
+
const keys = [key];
|
|
1799
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1800
|
+
keys.push(new AssetKey(
|
|
1801
|
+
key.namespace,
|
|
1802
|
+
key.path,
|
|
1803
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1804
|
+
key.type,
|
|
1805
|
+
key.rootType,
|
|
1806
|
+
key.extension,
|
|
1807
|
+
key.root
|
|
1808
|
+
));
|
|
1809
|
+
}
|
|
1810
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1811
|
+
}
|
|
1812
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1813
|
+
static async getFirst(keys, parser) {
|
|
1765
1814
|
const sources = [...this._SOURCES];
|
|
1766
1815
|
for (const source of sources) {
|
|
1767
|
-
const
|
|
1768
|
-
|
|
1769
|
-
|
|
1816
|
+
for (const key of keys) {
|
|
1817
|
+
const result = await source.source.get(key, parser);
|
|
1818
|
+
if (result !== void 0) {
|
|
1819
|
+
return { key, asset: result };
|
|
1820
|
+
}
|
|
1770
1821
|
}
|
|
1771
1822
|
}
|
|
1772
1823
|
return void 0;
|
|
@@ -2296,17 +2347,13 @@ var UVMapper = class {
|
|
|
2296
2347
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2297
2348
|
continue;
|
|
2298
2349
|
}
|
|
2350
|
+
if (!face.texture) continue;
|
|
2299
2351
|
if (!face.uv) {
|
|
2300
2352
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2301
2353
|
}
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
if (faceTexture) {
|
|
2306
|
-
faceTexture = faceTexture.substr(1);
|
|
2307
|
-
texPosition = positions[faceTexture] || [0, 0];
|
|
2308
|
-
texSize = sizes[faceTexture] || [16, 16];
|
|
2309
|
-
}
|
|
2354
|
+
const faceTexture = face.texture.substr(1);
|
|
2355
|
+
const texPosition = positions[faceTexture] || [0, 0];
|
|
2356
|
+
const texSize = sizes[faceTexture] || [16, 16];
|
|
2310
2357
|
let texPosV = new Vector2(texPosition[0], texPosition[1]);
|
|
2311
2358
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2312
2359
|
tl.add(texPosV);
|