minerender 2.1.0-alpha.19 → 2.1.0-alpha.20

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.
@@ -850,6 +850,8 @@ declare class ModelObject extends SceneObject {
850
850
  interface ModelObjectOptions extends SceneObjectOptions {
851
851
  /** Quarter-turn block rotation in radians to compensate when locking UVs. */
852
852
  uvLockRotation?: TripleArray;
853
+ /** sRGB 0xRRGGBB colors by face tint index; omitted indices stay white. */
854
+ tints?: Record<number, number>;
853
855
  }
854
856
  declare function isModelObject(obj: any): obj is ModelObject;
855
857
 
@@ -850,6 +850,8 @@ declare class ModelObject extends SceneObject {
850
850
  interface ModelObjectOptions extends SceneObjectOptions {
851
851
  /** Quarter-turn block rotation in radians to compensate when locking UVs. */
852
852
  uvLockRotation?: TripleArray;
853
+ /** sRGB 0xRRGGBB colors by face tint index; omitted indices stay white. */
854
+ tints?: Record<number, number>;
853
855
  }
854
856
  declare function isModelObject(obj: any): obj is ModelObject;
855
857
 
@@ -1096,6 +1096,7 @@ var _Materials = class _Materials {
1096
1096
  uniform bool SHADE;
1097
1097
 
1098
1098
  varying vec2 vUv;
1099
+ varying vec3 vTint;
1099
1100
  varying float light;
1100
1101
  varying float lift;
1101
1102
 
@@ -1130,6 +1131,7 @@ var _Materials = class _Materials {
1130
1131
  }
1131
1132
 
1132
1133
  vUv = uv;
1134
+ vTint = color;
1133
1135
 
1134
1136
  #ifdef USE_INSTANCING
1135
1137
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
@@ -1151,12 +1153,14 @@ var _Materials = class _Materials {
1151
1153
  uniform float BRIGHTNESS;
1152
1154
 
1153
1155
  varying vec2 vUv;
1156
+ varying vec3 vTint;
1154
1157
  varying float light;
1155
1158
  varying float lift;
1156
1159
 
1157
1160
  void main(void)
1158
1161
  {
1159
1162
  vec4 color = texture2D(map, vUv);
1163
+ color.rgb *= vTint;
1160
1164
 
1161
1165
  if (color.a < 0.01) discard;
1162
1166
 
@@ -2183,17 +2187,20 @@ var TextureAtlas = class {
2183
2187
  // src/model/ModelGenerator.ts
2184
2188
  var ModelGenerator = class {
2185
2189
  static generateItemModel(imageData, layer) {
2190
+ const tintindex = this.ITEM_LAYERS.indexOf(layer);
2186
2191
  const mainElement = {
2187
2192
  from: [0, 0, 7.5],
2188
2193
  to: [16, 16, 8.5],
2189
2194
  faces: {
2190
2195
  "south": {
2191
2196
  uv: [0, 0, 16, 16],
2192
- texture: `#${layer}`
2197
+ texture: `#${layer}`,
2198
+ tintindex
2193
2199
  },
2194
2200
  "north": {
2195
2201
  uv: [16, 0, 0, 16],
2196
- texture: `#${layer}`
2202
+ texture: `#${layer}`,
2203
+ tintindex
2197
2204
  }
2198
2205
  },
2199
2206
  shade: true
@@ -4314,6 +4321,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
4314
4321
  this.isModelObject = true;
4315
4322
  this.meshesCreated = false;
4316
4323
  this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
4324
+ if (this.options.tints) this.options.tints = { ...this.options.tints };
4317
4325
  console.log("ModelObject options", this.options);
4318
4326
  }
4319
4327
  async init() {
@@ -4343,6 +4351,20 @@ var _ModelObject = class _ModelObject extends SceneObject {
4343
4351
  if (this.options.uvLockRotation) {
4344
4352
  UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
4345
4353
  }
4354
+ if (this.options.tints) {
4355
+ const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
4356
+ for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
4357
+ const tintIndex = el.faces[faceName]?.tintindex;
4358
+ if (tintIndex === void 0 || tintIndex < 0) continue;
4359
+ const tint = this.options.tints[tintIndex];
4360
+ if (tint === void 0) continue;
4361
+ const color = new import_three15.Color(tint);
4362
+ for (let vertex = 0; vertex < 4; vertex++) {
4363
+ color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4364
+ }
4365
+ }
4366
+ elGeo.setAttribute("color", new import_three15.BufferAttribute(colors, 3));
4367
+ }
4346
4368
  elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4347
4369
  elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4348
4370
  if (el.rotation) {
@@ -4399,6 +4421,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
4399
4421
  /*TODO: get this from render options*/
4400
4422
  );
4401
4423
  this.iterateAllMeshes((mesh) => {
4424
+ if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
4402
4425
  mesh.material = mat;
4403
4426
  });
4404
4427
  if (this.atlas.hasAnimation) {
@@ -5657,8 +5680,13 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
5657
5680
  const obj = await objectSupplier();
5658
5681
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5659
5682
  console.log("instanceMeshes + key");
5660
- const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5661
- const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5683
+ let key = asset.key.serialize();
5684
+ if (isModelObject(obj)) {
5685
+ const { uvLockRotation, tints } = obj.options;
5686
+ if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
5687
+ const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
5688
+ if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
5689
+ }
5662
5690
  return this.instanceManager.getOrCreate(key, async () => {
5663
5691
  obj.scene = this;
5664
5692
  await obj.init();