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.
@@ -851,6 +851,8 @@ declare class ModelObject extends SceneObject {
851
851
  interface ModelObjectOptions extends SceneObjectOptions {
852
852
  /** Quarter-turn block rotation in radians to compensate when locking UVs. */
853
853
  uvLockRotation?: TripleArray;
854
+ /** sRGB 0xRRGGBB colors by face tint index; omitted indices stay white. */
855
+ tints?: Record<number, number>;
854
856
  }
855
857
  declare function isModelObject(obj: any): obj is ModelObject;
856
858
 
@@ -851,6 +851,8 @@ declare class ModelObject extends SceneObject {
851
851
  interface ModelObjectOptions extends SceneObjectOptions {
852
852
  /** Quarter-turn block rotation in radians to compensate when locking UVs. */
853
853
  uvLockRotation?: TripleArray;
854
+ /** sRGB 0xRRGGBB colors by face tint index; omitted indices stay white. */
855
+ tints?: Record<number, number>;
854
856
  }
855
857
  declare function isModelObject(obj: any): obj is ModelObject;
856
858
 
@@ -1100,6 +1100,7 @@ var Materials = class _Materials {
1100
1100
  uniform bool SHADE;
1101
1101
 
1102
1102
  varying vec2 vUv;
1103
+ varying vec3 vTint;
1103
1104
  varying float light;
1104
1105
  varying float lift;
1105
1106
 
@@ -1134,6 +1135,7 @@ var Materials = class _Materials {
1134
1135
  }
1135
1136
 
1136
1137
  vUv = uv;
1138
+ vTint = color;
1137
1139
 
1138
1140
  #ifdef USE_INSTANCING
1139
1141
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
@@ -1155,12 +1157,14 @@ var Materials = class _Materials {
1155
1157
  uniform float BRIGHTNESS;
1156
1158
 
1157
1159
  varying vec2 vUv;
1160
+ varying vec3 vTint;
1158
1161
  varying float light;
1159
1162
  varying float lift;
1160
1163
 
1161
1164
  void main(void)
1162
1165
  {
1163
1166
  vec4 color = texture2D(map, vUv);
1167
+ color.rgb *= vTint;
1164
1168
 
1165
1169
  if (color.a < 0.01) discard;
1166
1170
 
@@ -2221,17 +2225,20 @@ var ModelGenerator = class {
2221
2225
  this.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
2222
2226
  }
2223
2227
  static generateItemModel(imageData, layer) {
2228
+ const tintindex = this.ITEM_LAYERS.indexOf(layer);
2224
2229
  const mainElement = {
2225
2230
  from: [0, 0, 7.5],
2226
2231
  to: [16, 16, 8.5],
2227
2232
  faces: {
2228
2233
  "south": {
2229
2234
  uv: [0, 0, 16, 16],
2230
- texture: `#${layer}`
2235
+ texture: `#${layer}`,
2236
+ tintindex
2231
2237
  },
2232
2238
  "north": {
2233
2239
  uv: [16, 0, 0, 16],
2234
- texture: `#${layer}`
2240
+ texture: `#${layer}`,
2241
+ tintindex
2235
2242
  }
2236
2243
  },
2237
2244
  shade: true
@@ -4354,6 +4361,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4354
4361
  this.isModelObject = true;
4355
4362
  this.meshesCreated = false;
4356
4363
  this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
4364
+ if (this.options.tints) this.options.tints = { ...this.options.tints };
4357
4365
  console.log("ModelObject options", this.options);
4358
4366
  }
4359
4367
  static {
@@ -4386,6 +4394,20 @@ var ModelObject = class _ModelObject extends SceneObject {
4386
4394
  if (this.options.uvLockRotation) {
4387
4395
  UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
4388
4396
  }
4397
+ if (this.options.tints) {
4398
+ const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
4399
+ for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
4400
+ const tintIndex = el.faces[faceName]?.tintindex;
4401
+ if (tintIndex === void 0 || tintIndex < 0) continue;
4402
+ const tint = this.options.tints[tintIndex];
4403
+ if (tint === void 0) continue;
4404
+ const color = new import_three15.Color(tint);
4405
+ for (let vertex = 0; vertex < 4; vertex++) {
4406
+ color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4407
+ }
4408
+ }
4409
+ elGeo.setAttribute("color", new import_three15.BufferAttribute(colors, 3));
4410
+ }
4389
4411
  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));
4390
4412
  elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4391
4413
  if (el.rotation) {
@@ -4442,6 +4464,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4442
4464
  /*TODO: get this from render options*/
4443
4465
  );
4444
4466
  this.iterateAllMeshes((mesh) => {
4467
+ if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
4445
4468
  mesh.material = mat;
4446
4469
  });
4447
4470
  if (this.atlas.hasAnimation) {
@@ -5702,8 +5725,13 @@ var MineRenderScene = class _MineRenderScene extends import_three17.Scene {
5702
5725
  const obj = await objectSupplier();
5703
5726
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5704
5727
  console.log("instanceMeshes + key");
5705
- const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5706
- const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5728
+ let key = asset.key.serialize();
5729
+ if (isModelObject(obj)) {
5730
+ const { uvLockRotation, tints } = obj.options;
5731
+ if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
5732
+ const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
5733
+ if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
5734
+ }
5707
5735
  return this.instanceManager.getOrCreate(key, async () => {
5708
5736
  obj.scene = this;
5709
5737
  await obj.init();