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/node/index.d.mts
CHANGED
|
@@ -15,7 +15,7 @@ interface AnimatorFunction {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
declare enum Axis {
|
|
18
|
-
X = "
|
|
18
|
+
X = "x",
|
|
19
19
|
Y = "y",
|
|
20
20
|
Z = "z"
|
|
21
21
|
}
|
|
@@ -671,6 +671,11 @@ declare class AssetLoader {
|
|
|
671
671
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
672
672
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
673
673
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
674
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
675
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
676
|
+
key: AssetKey;
|
|
677
|
+
asset: T;
|
|
678
|
+
}>>;
|
|
674
679
|
}
|
|
675
680
|
|
|
676
681
|
interface BlockState extends MinecraftAsset {
|
|
@@ -696,7 +701,7 @@ interface MultipartCondition {
|
|
|
696
701
|
[key: string]: string;
|
|
697
702
|
}
|
|
698
703
|
|
|
699
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
704
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
700
705
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
701
706
|
declare class Assets {
|
|
702
707
|
/**
|
|
@@ -761,6 +766,8 @@ declare class Models {
|
|
|
761
766
|
private static get PERSISTENT_CACHE();
|
|
762
767
|
static getItemList(): Promise<string[]>;
|
|
763
768
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
769
|
+
private static getItemModel;
|
|
770
|
+
private static defaultItemModel;
|
|
764
771
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
766
773
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/node/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ interface AnimatorFunction {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
declare enum Axis {
|
|
18
|
-
X = "
|
|
18
|
+
X = "x",
|
|
19
19
|
Y = "y",
|
|
20
20
|
Z = "z"
|
|
21
21
|
}
|
|
@@ -671,6 +671,11 @@ declare class AssetLoader {
|
|
|
671
671
|
static getAll<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<T[]>;
|
|
672
672
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
673
673
|
static get<T extends MinecraftAsset>(key: AssetKey, parser: AssetParser | string): Promise<Maybe<T>>;
|
|
674
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
675
|
+
static getFirst<T extends MinecraftAsset>(keys: readonly AssetKey[], parser: AssetParser | string): Promise<Maybe<{
|
|
676
|
+
key: AssetKey;
|
|
677
|
+
asset: T;
|
|
678
|
+
}>>;
|
|
674
679
|
}
|
|
675
680
|
|
|
676
681
|
interface BlockState extends MinecraftAsset {
|
|
@@ -696,7 +701,7 @@ interface MultipartCondition {
|
|
|
696
701
|
[key: string]: string;
|
|
697
702
|
}
|
|
698
703
|
|
|
699
|
-
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
704
|
+
declare const DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
700
705
|
declare const DEFAULT_NAMESPACE = "minecraft";
|
|
701
706
|
declare class Assets {
|
|
702
707
|
/**
|
|
@@ -761,6 +766,8 @@ declare class Models {
|
|
|
761
766
|
private static get PERSISTENT_CACHE();
|
|
762
767
|
static getItemList(): Promise<string[]>;
|
|
763
768
|
static loadAndMerge(key: AssetKey): Promise<Maybe<Model>>;
|
|
769
|
+
private static getItemModel;
|
|
770
|
+
private static defaultItemModel;
|
|
764
771
|
static getRaw(key: AssetKey): Promise<Maybe<Model>>;
|
|
765
772
|
static getMerged(key: AssetKey): Promise<Maybe<Model>>;
|
|
766
773
|
static get(key: AssetKey): Promise<Maybe<Model>>;
|
package/dist/node/index.js
CHANGED
|
@@ -396,7 +396,7 @@ registerNodeEnv();
|
|
|
396
396
|
// src/Axis.ts
|
|
397
397
|
var import_three = require("three");
|
|
398
398
|
var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
399
|
-
Axis3["X"] = "
|
|
399
|
+
Axis3["X"] = "x";
|
|
400
400
|
Axis3["Y"] = "y";
|
|
401
401
|
Axis3["Z"] = "z";
|
|
402
402
|
return Axis3;
|
|
@@ -404,7 +404,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
|
|
|
404
404
|
var AXES = Object.values(Axis);
|
|
405
405
|
function axisToVec3(axis) {
|
|
406
406
|
switch (axis) {
|
|
407
|
-
case "
|
|
407
|
+
case "x" /* X */:
|
|
408
408
|
return new import_three.Vector3(1, 0, 0);
|
|
409
409
|
case "y" /* Y */:
|
|
410
410
|
return new import_three.Vector3(0, 1, 0);
|
|
@@ -1297,7 +1297,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1297
1297
|
}
|
|
1298
1298
|
toString() {
|
|
1299
1299
|
let a = [
|
|
1300
|
-
|
|
1300
|
+
this.root ?? AssetLoader.ROOT,
|
|
1301
1301
|
this.rootType ?? "__rootType__",
|
|
1302
1302
|
this.assetType ?? "__assetType__",
|
|
1303
1303
|
this.type ?? "__type__",
|
|
@@ -1334,9 +1334,9 @@ var ModelMerger = class {
|
|
|
1334
1334
|
const models = await this.collectAllParents(model);
|
|
1335
1335
|
let merged = {};
|
|
1336
1336
|
for (let parentModel of models) {
|
|
1337
|
-
merged =
|
|
1337
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
|
|
1338
1338
|
}
|
|
1339
|
-
merged =
|
|
1339
|
+
merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
|
|
1340
1340
|
merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
|
|
1341
1341
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1342
1342
|
return merged;
|
|
@@ -1347,6 +1347,7 @@ var ModelMerger = class {
|
|
|
1347
1347
|
}
|
|
1348
1348
|
const models = [];
|
|
1349
1349
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1350
|
+
parentKey.root = model.key?.root;
|
|
1350
1351
|
const parentModel = await Models.getRaw(parentKey);
|
|
1351
1352
|
if (parentModel) {
|
|
1352
1353
|
models.unshift(parentModel);
|
|
@@ -1376,26 +1377,58 @@ var Models = class _Models {
|
|
|
1376
1377
|
return this._persistentCache ??= PersistentCache.open("minerender-models");
|
|
1377
1378
|
}
|
|
1378
1379
|
static async getItemList() {
|
|
1379
|
-
const key = new AssetKey(
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
"
|
|
1383
|
-
"item",
|
|
1384
|
-
"assets",
|
|
1385
|
-
".json",
|
|
1386
|
-
DEFAULT_ROOT
|
|
1387
|
-
);
|
|
1388
|
-
return Caching.listAssetCache.get(key.serialize(), () => {
|
|
1389
|
-
return AssetLoader.get(key, "list" /* LIST */);
|
|
1380
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
|
|
1381
|
+
const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
|
|
1382
|
+
return Caching.listAssetCache.get(key.serialize(), async () => {
|
|
1383
|
+
return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
|
|
1390
1384
|
}).then((r) => r?.files ?? []);
|
|
1391
1385
|
}
|
|
1392
1386
|
static async loadAndMerge(key) {
|
|
1393
|
-
const model = await this.getRaw(key);
|
|
1387
|
+
const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
|
|
1394
1388
|
if (!model) {
|
|
1395
1389
|
return void 0;
|
|
1396
1390
|
}
|
|
1397
1391
|
return ModelMerger.mergeWithParents(model);
|
|
1398
1392
|
}
|
|
1393
|
+
static async getItemModel(key) {
|
|
1394
|
+
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1395
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
|
|
1396
|
+
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1397
|
+
if (!result) return void 0;
|
|
1398
|
+
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1399
|
+
const reference = this.defaultItemModel(result.asset.model, key);
|
|
1400
|
+
const modelKey = AssetKey.parse("models", reference);
|
|
1401
|
+
modelKey.root = key.root;
|
|
1402
|
+
const model2 = await this.getRaw(modelKey);
|
|
1403
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
|
|
1404
|
+
return model2;
|
|
1405
|
+
});
|
|
1406
|
+
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1407
|
+
}
|
|
1408
|
+
// Item previews use the GUI context, false conditions, and zero numeric properties.
|
|
1409
|
+
static defaultItemModel(node, key) {
|
|
1410
|
+
if (!node || typeof node.type !== "string") {
|
|
1411
|
+
throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
|
|
1412
|
+
}
|
|
1413
|
+
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1414
|
+
case "model":
|
|
1415
|
+
if (typeof node.model === "string" && node.model) return node.model;
|
|
1416
|
+
break;
|
|
1417
|
+
case "condition":
|
|
1418
|
+
return this.defaultItemModel(node.on_false, key);
|
|
1419
|
+
case "select": {
|
|
1420
|
+
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;
|
|
1421
|
+
return this.defaultItemModel(selected ?? node.fallback, key);
|
|
1422
|
+
}
|
|
1423
|
+
case "range_dispatch": {
|
|
1424
|
+
const selected = node.entries?.reduce((match, entry) => {
|
|
1425
|
+
return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
|
|
1426
|
+
}, void 0);
|
|
1427
|
+
return this.defaultItemModel(selected?.model ?? node.fallback, key);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
|
|
1431
|
+
}
|
|
1399
1432
|
static async getRaw(key) {
|
|
1400
1433
|
if (!key.assetType) {
|
|
1401
1434
|
key.assetType = "models";
|
|
@@ -1502,7 +1535,7 @@ var DefaultBlockStates = class {
|
|
|
1502
1535
|
};
|
|
1503
1536
|
|
|
1504
1537
|
// src/assets/Assets.ts
|
|
1505
|
-
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.
|
|
1538
|
+
var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
|
|
1506
1539
|
var DEFAULT_NAMESPACE = "minecraft";
|
|
1507
1540
|
var Assets = class {
|
|
1508
1541
|
/**
|
|
@@ -1563,7 +1596,7 @@ function applyElementRotation(rotation, geometry) {
|
|
|
1563
1596
|
const origin = new import_three7.Vector3(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
|
|
1564
1597
|
geometry.translate(-origin.x, -origin.y, -origin.z);
|
|
1565
1598
|
switch (rotation.axis) {
|
|
1566
|
-
case "
|
|
1599
|
+
case "x" /* X */:
|
|
1567
1600
|
geometry.rotateX(toRadians(rotation.angle));
|
|
1568
1601
|
break;
|
|
1569
1602
|
case "y" /* Y */:
|
|
@@ -1594,7 +1627,7 @@ function applyModelPartRotation(modelPart, geometry) {
|
|
|
1594
1627
|
}
|
|
1595
1628
|
function applyGenericRotation(axis, rotation, obj) {
|
|
1596
1629
|
switch (axis) {
|
|
1597
|
-
case "
|
|
1630
|
+
case "x" /* X */:
|
|
1598
1631
|
obj.rotateOnAxis(new import_three7.Vector3(1, 0, 0), toRadians(rotation));
|
|
1599
1632
|
break;
|
|
1600
1633
|
case "y" /* Y */:
|
|
@@ -1945,11 +1978,29 @@ var AssetLoader = class {
|
|
|
1945
1978
|
}
|
|
1946
1979
|
/** Returns the first defined result in source-priority order, without merging assets. */
|
|
1947
1980
|
static async get(key, parser) {
|
|
1981
|
+
const keys = [key];
|
|
1982
|
+
if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
|
|
1983
|
+
keys.push(new AssetKey(
|
|
1984
|
+
key.namespace,
|
|
1985
|
+
key.path,
|
|
1986
|
+
key.assetType === "structure" ? "structures" : "structure",
|
|
1987
|
+
key.type,
|
|
1988
|
+
key.rootType,
|
|
1989
|
+
key.extension,
|
|
1990
|
+
key.root
|
|
1991
|
+
));
|
|
1992
|
+
}
|
|
1993
|
+
return (await this.getFirst(keys, parser))?.asset;
|
|
1994
|
+
}
|
|
1995
|
+
/** Tries each path within a source before considering lower-priority sources. */
|
|
1996
|
+
static async getFirst(keys, parser) {
|
|
1948
1997
|
const sources = [...this._SOURCES];
|
|
1949
1998
|
for (const source of sources) {
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
|
|
1999
|
+
for (const key of keys) {
|
|
2000
|
+
const result = await source.source.get(key, parser);
|
|
2001
|
+
if (result !== void 0) {
|
|
2002
|
+
return { key, asset: result };
|
|
2003
|
+
}
|
|
1953
2004
|
}
|
|
1954
2005
|
}
|
|
1955
2006
|
return void 0;
|
|
@@ -2489,17 +2540,13 @@ var UVMapper = class {
|
|
|
2489
2540
|
this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
|
|
2490
2541
|
continue;
|
|
2491
2542
|
}
|
|
2543
|
+
if (!face.texture) continue;
|
|
2492
2544
|
if (!face.uv) {
|
|
2493
2545
|
face.uv = this.getFallbackUv(element, faceName);
|
|
2494
2546
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
if (faceTexture) {
|
|
2499
|
-
faceTexture = faceTexture.substr(1);
|
|
2500
|
-
texPosition = positions[faceTexture] || [0, 0];
|
|
2501
|
-
texSize = sizes[faceTexture] || [16, 16];
|
|
2502
|
-
}
|
|
2547
|
+
const faceTexture = face.texture.substr(1);
|
|
2548
|
+
const texPosition = positions[faceTexture] || [0, 0];
|
|
2549
|
+
const texSize = sizes[faceTexture] || [16, 16];
|
|
2503
2550
|
let texPosV = new import_three8.Vector2(texPosition[0], texPosition[1]);
|
|
2504
2551
|
const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
|
|
2505
2552
|
tl.add(texPosV);
|