minerender 2.1.0-alpha.60 → 2.1.0-alpha.61
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 +29 -2
- package/dist/browser/index.d.ts +29 -2
- package/dist/browser/index.js +94 -20
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +94 -20
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +100 -20
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +29 -2
- package/dist/node/index.d.ts +29 -2
- package/dist/node/index.js +96 -20
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +94 -20
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -1451,7 +1451,7 @@ var init_Models = __esm({
|
|
|
1451
1451
|
}
|
|
1452
1452
|
static async getItemModel(key) {
|
|
1453
1453
|
const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
|
|
1454
|
-
const model = await this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(itemKey.serialize())
|
|
1454
|
+
const model = await this.PERSISTENT_CACHE.getOrLoad(`item-v2:${AssetLoader.persistentKey(itemKey.serialize())}`, async () => {
|
|
1455
1455
|
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1456
1456
|
if (!result) return void 0;
|
|
1457
1457
|
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
@@ -1460,7 +1460,7 @@ var init_Models = __esm({
|
|
|
1460
1460
|
modelKey.root = key.root;
|
|
1461
1461
|
const model2 = await this.getRaw(modelKey);
|
|
1462
1462
|
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
|
|
1463
|
-
return selected.special
|
|
1463
|
+
return { ...model2, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
|
|
1464
1464
|
});
|
|
1465
1465
|
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1466
1466
|
}
|
|
@@ -1471,7 +1471,7 @@ var init_Models = __esm({
|
|
|
1471
1471
|
}
|
|
1472
1472
|
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1473
1473
|
case "model":
|
|
1474
|
-
if (typeof node.model === "string" && node.model) return { model: node.model };
|
|
1474
|
+
if (typeof node.model === "string" && node.model) return { model: node.model, tints: node.tints };
|
|
1475
1475
|
break;
|
|
1476
1476
|
case "special": {
|
|
1477
1477
|
if (!node.base || !node.model || typeof node.model !== "object") break;
|
|
@@ -4837,6 +4837,87 @@ var init_GuiLight = __esm({
|
|
|
4837
4837
|
}
|
|
4838
4838
|
});
|
|
4839
4839
|
|
|
4840
|
+
// src/texture/Colormaps.ts
|
|
4841
|
+
var Colormaps;
|
|
4842
|
+
var init_Colormaps = __esm({
|
|
4843
|
+
"src/texture/Colormaps.ts"() {
|
|
4844
|
+
init_AssetKey();
|
|
4845
|
+
init_ModelTextures();
|
|
4846
|
+
init_Caching();
|
|
4847
|
+
init_MineRenderError();
|
|
4848
|
+
Colormaps = class {
|
|
4849
|
+
/** Samples the selected resource pack's grass colormap using Minecraft's climate coordinates. */
|
|
4850
|
+
static async grassColor(origin, temperature = 0.5, downfall = 1) {
|
|
4851
|
+
const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
|
|
4852
|
+
const temp = Math.fround(temperature);
|
|
4853
|
+
const rain = Math.fround(downfall) * temp;
|
|
4854
|
+
const x = Math.floor((1 - temp) * 255), y = Math.floor((1 - rain) * 255);
|
|
4855
|
+
return await Caching.blockTintCache.get(`${key.serialize()}|${x},${y}`, async () => {
|
|
4856
|
+
const image = await ModelTextures.get(key);
|
|
4857
|
+
if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
|
|
4858
|
+
if (image.width !== 256 || image.height !== 256) {
|
|
4859
|
+
throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
|
|
4860
|
+
}
|
|
4861
|
+
const [red, green, blue] = image.data.getImageData(x, y, 1, 1).data;
|
|
4862
|
+
return red << 16 | green << 8 | blue;
|
|
4863
|
+
});
|
|
4864
|
+
}
|
|
4865
|
+
};
|
|
4866
|
+
}
|
|
4867
|
+
});
|
|
4868
|
+
|
|
4869
|
+
// src/model/ItemTints.ts
|
|
4870
|
+
var ItemTints;
|
|
4871
|
+
var init_ItemTints = __esm({
|
|
4872
|
+
"src/model/ItemTints.ts"() {
|
|
4873
|
+
init_MineRenderError();
|
|
4874
|
+
init_Colormaps();
|
|
4875
|
+
ItemTints = class {
|
|
4876
|
+
/** Resolves preview colors from item definitions; explicit per-index colors take precedence. */
|
|
4877
|
+
static async get(model, tints) {
|
|
4878
|
+
const sources = model.tints;
|
|
4879
|
+
if (!sources?.length) return tints;
|
|
4880
|
+
const colors = { ...tints };
|
|
4881
|
+
await Promise.all(sources.map(async (source, index) => {
|
|
4882
|
+
if (colors[index] !== void 0) return;
|
|
4883
|
+
switch (source.type) {
|
|
4884
|
+
case "constant":
|
|
4885
|
+
case "minecraft:constant":
|
|
4886
|
+
colors[index] = this.rgb(source.value);
|
|
4887
|
+
break;
|
|
4888
|
+
case "grass":
|
|
4889
|
+
case "minecraft:grass":
|
|
4890
|
+
colors[index] = await Colormaps.grassColor(model.key, source.temperature, source.downfall);
|
|
4891
|
+
break;
|
|
4892
|
+
case "dye":
|
|
4893
|
+
case "minecraft:dye":
|
|
4894
|
+
case "potion":
|
|
4895
|
+
case "minecraft:potion":
|
|
4896
|
+
case "map_color":
|
|
4897
|
+
case "minecraft:map_color":
|
|
4898
|
+
case "firework":
|
|
4899
|
+
case "minecraft:firework":
|
|
4900
|
+
case "team":
|
|
4901
|
+
case "minecraft:team":
|
|
4902
|
+
case "custom_model_data":
|
|
4903
|
+
case "minecraft:custom_model_data":
|
|
4904
|
+
colors[index] = this.rgb(source.default);
|
|
4905
|
+
break;
|
|
4906
|
+
default:
|
|
4907
|
+
throw new MineRenderError(`Unsupported item tint source ${source.type}`);
|
|
4908
|
+
}
|
|
4909
|
+
}));
|
|
4910
|
+
return colors;
|
|
4911
|
+
}
|
|
4912
|
+
static rgb(color) {
|
|
4913
|
+
if (!Array.isArray(color)) return color & 16777215;
|
|
4914
|
+
const [red, green, blue] = color.map((channel) => Math.floor(Math.fround(Math.fround(channel) * 255)));
|
|
4915
|
+
return red << 16 | green << 8 | blue;
|
|
4916
|
+
}
|
|
4917
|
+
};
|
|
4918
|
+
}
|
|
4919
|
+
});
|
|
4920
|
+
|
|
4840
4921
|
// src/model/scene/ModelObject.ts
|
|
4841
4922
|
import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color8, Euler as Euler6, Matrix4 as Matrix49 } from "three";
|
|
4842
4923
|
function isModelObject(obj) {
|
|
@@ -4859,6 +4940,7 @@ var init_ModelObject = __esm({
|
|
|
4859
4940
|
init_SpecialItems();
|
|
4860
4941
|
init_EntityObject();
|
|
4861
4942
|
init_GuiLight();
|
|
4943
|
+
init_ItemTints();
|
|
4862
4944
|
p7 = prefix("ModelObject");
|
|
4863
4945
|
_ModelObject = class _ModelObject extends SceneObject {
|
|
4864
4946
|
constructor(originalModel, options) {
|
|
@@ -4874,6 +4956,7 @@ var init_ModelObject = __esm({
|
|
|
4874
4956
|
this.addEventListener("removed", () => this.updateAnimationSubscription());
|
|
4875
4957
|
}
|
|
4876
4958
|
async init() {
|
|
4959
|
+
this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
|
|
4877
4960
|
const special = this.originalModel.special;
|
|
4878
4961
|
if (special) {
|
|
4879
4962
|
const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
|
|
@@ -8761,6 +8844,7 @@ function isInstanceable(obj) {
|
|
|
8761
8844
|
init_DisplayPosition();
|
|
8762
8845
|
init_DisplayTransforms();
|
|
8763
8846
|
init_GuiLight();
|
|
8847
|
+
init_ItemTints();
|
|
8764
8848
|
init_Model();
|
|
8765
8849
|
init_ModelCulling();
|
|
8766
8850
|
init_ModelGenerator();
|
|
@@ -8858,10 +8942,7 @@ var BlockStateResolver = class {
|
|
|
8858
8942
|
};
|
|
8859
8943
|
|
|
8860
8944
|
// src/model/block/BlockTints.ts
|
|
8861
|
-
|
|
8862
|
-
init_ModelTextures();
|
|
8863
|
-
init_Caching();
|
|
8864
|
-
init_MineRenderError();
|
|
8945
|
+
init_Colormaps();
|
|
8865
8946
|
|
|
8866
8947
|
// src/model/block/blockTints.json
|
|
8867
8948
|
var blockTints_default = {
|
|
@@ -8916,7 +8997,7 @@ var BlockTints = class {
|
|
|
8916
8997
|
color = rule.color;
|
|
8917
8998
|
break;
|
|
8918
8999
|
case "grass":
|
|
8919
|
-
color = await
|
|
9000
|
+
color = await Colormaps.grassColor(key);
|
|
8920
9001
|
break;
|
|
8921
9002
|
case "redstone": {
|
|
8922
9003
|
const power = Number(state.power ?? 0) / 15;
|
|
@@ -8934,18 +9015,6 @@ var BlockTints = class {
|
|
|
8934
9015
|
}
|
|
8935
9016
|
return { ...Object.fromEntries([...indices].map((index) => [index, color])), ...tints };
|
|
8936
9017
|
}
|
|
8937
|
-
static async grassColor(origin) {
|
|
8938
|
-
const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
|
|
8939
|
-
return await Caching.blockTintCache.get(key.serialize(), async () => {
|
|
8940
|
-
const image = await ModelTextures.get(key);
|
|
8941
|
-
if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
|
|
8942
|
-
if (image.width !== 256 || image.height !== 256) {
|
|
8943
|
-
throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
|
|
8944
|
-
}
|
|
8945
|
-
const [red, green, blue] = image.data.getImageData(127, 127, 1, 1).data;
|
|
8946
|
-
return red << 16 | green << 8 | blue;
|
|
8947
|
-
});
|
|
8948
|
-
}
|
|
8949
9018
|
};
|
|
8950
9019
|
|
|
8951
9020
|
// src/model/block/scene/BlockObject.ts
|
|
@@ -12200,6 +12269,7 @@ var SkinObject = class extends SceneObject {
|
|
|
12200
12269
|
|
|
12201
12270
|
// src/renderer/MineRenderScene.ts
|
|
12202
12271
|
init_EntityObject();
|
|
12272
|
+
init_ItemTints();
|
|
12203
12273
|
var _MineRenderScene = class _MineRenderScene extends Scene5 {
|
|
12204
12274
|
constructor(options) {
|
|
12205
12275
|
super();
|
|
@@ -12292,6 +12362,7 @@ var _MineRenderScene = class _MineRenderScene extends Scene5 {
|
|
|
12292
12362
|
}
|
|
12293
12363
|
}
|
|
12294
12364
|
async addModel(model, options, parent = this) {
|
|
12365
|
+
options = { ...options, tints: await ItemTints.get(model, options?.tints) };
|
|
12295
12366
|
return this.addSceneObject(model, () => new ModelObject(model, options), options, parent);
|
|
12296
12367
|
}
|
|
12297
12368
|
async addBlock(blockState, options, parent = this) {
|
|
@@ -13563,6 +13634,7 @@ var Skins = class {
|
|
|
13563
13634
|
};
|
|
13564
13635
|
|
|
13565
13636
|
// src/texture/index.ts
|
|
13637
|
+
init_Colormaps();
|
|
13566
13638
|
init_TextureAtlas();
|
|
13567
13639
|
init_TextureLoader();
|
|
13568
13640
|
init_Textures();
|
|
@@ -14449,6 +14521,7 @@ export {
|
|
|
14449
14521
|
CanvasImage,
|
|
14450
14522
|
Chunk,
|
|
14451
14523
|
ChunkData,
|
|
14524
|
+
Colormaps,
|
|
14452
14525
|
CubeFace,
|
|
14453
14526
|
CubeFaceIndex,
|
|
14454
14527
|
DEFAULT_ELEMENTS,
|
|
@@ -14474,6 +14547,7 @@ export {
|
|
|
14474
14547
|
ImageLoader,
|
|
14475
14548
|
InstanceManager,
|
|
14476
14549
|
InstanceReference,
|
|
14550
|
+
ItemTints,
|
|
14477
14551
|
MapControls,
|
|
14478
14552
|
Materials,
|
|
14479
14553
|
Meshes,
|