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.
@@ -940,6 +940,7 @@ var _Materials = class _Materials {
940
940
  uniform bool SHADE;
941
941
 
942
942
  varying vec2 vUv;
943
+ varying vec3 vTint;
943
944
  varying float light;
944
945
  varying float lift;
945
946
 
@@ -974,6 +975,7 @@ var _Materials = class _Materials {
974
975
  }
975
976
 
976
977
  vUv = uv;
978
+ vTint = color;
977
979
 
978
980
  #ifdef USE_INSTANCING
979
981
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
@@ -995,12 +997,14 @@ var _Materials = class _Materials {
995
997
  uniform float BRIGHTNESS;
996
998
 
997
999
  varying vec2 vUv;
1000
+ varying vec3 vTint;
998
1001
  varying float light;
999
1002
  varying float lift;
1000
1003
 
1001
1004
  void main(void)
1002
1005
  {
1003
1006
  vec4 color = texture2D(map, vUv);
1007
+ color.rgb *= vTint;
1004
1008
 
1005
1009
  if (color.a < 0.01) discard;
1006
1010
 
@@ -2027,17 +2031,20 @@ var TextureAtlas = class {
2027
2031
  // src/model/ModelGenerator.ts
2028
2032
  var ModelGenerator = class {
2029
2033
  static generateItemModel(imageData, layer) {
2034
+ const tintindex = this.ITEM_LAYERS.indexOf(layer);
2030
2035
  const mainElement = {
2031
2036
  from: [0, 0, 7.5],
2032
2037
  to: [16, 16, 8.5],
2033
2038
  faces: {
2034
2039
  "south": {
2035
2040
  uv: [0, 0, 16, 16],
2036
- texture: `#${layer}`
2041
+ texture: `#${layer}`,
2042
+ tintindex
2037
2043
  },
2038
2044
  "north": {
2039
2045
  uv: [16, 0, 0, 16],
2040
- texture: `#${layer}`
2046
+ texture: `#${layer}`,
2047
+ tintindex
2041
2048
  }
2042
2049
  },
2043
2050
  shade: true
@@ -3614,7 +3621,7 @@ function isQuadArray(obj) {
3614
3621
  }
3615
3622
 
3616
3623
  // src/model/scene/ModelObject.ts
3617
- import { BoxGeometry as BoxGeometry5, Euler as Euler4, Matrix4 as Matrix45 } from "three";
3624
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix45 } from "three";
3618
3625
 
3619
3626
  // src/three/BufferGeometryUtils.js
3620
3627
  import {
@@ -4168,6 +4175,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
4168
4175
  this.isModelObject = true;
4169
4176
  this.meshesCreated = false;
4170
4177
  this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
4178
+ if (this.options.tints) this.options.tints = { ...this.options.tints };
4171
4179
  console.log("ModelObject options", this.options);
4172
4180
  }
4173
4181
  async init() {
@@ -4197,6 +4205,20 @@ var _ModelObject = class _ModelObject extends SceneObject {
4197
4205
  if (this.options.uvLockRotation) {
4198
4206
  UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler4(...this.options.uvLockRotation));
4199
4207
  }
4208
+ if (this.options.tints) {
4209
+ const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
4210
+ for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
4211
+ const tintIndex = el.faces[faceName]?.tintindex;
4212
+ if (tintIndex === void 0 || tintIndex < 0) continue;
4213
+ const tint = this.options.tints[tintIndex];
4214
+ if (tint === void 0) continue;
4215
+ const color = new Color3(tint);
4216
+ for (let vertex = 0; vertex < 4; vertex++) {
4217
+ color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4218
+ }
4219
+ }
4220
+ elGeo.setAttribute("color", new BufferAttribute4(colors, 3));
4221
+ }
4200
4222
  elGeo.applyMatrix4(new Matrix45().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4201
4223
  elGeo.applyMatrix4(new Matrix45().makeTranslation(el.from[0], el.from[1], el.from[2]));
4202
4224
  if (el.rotation) {
@@ -4253,6 +4275,7 @@ var _ModelObject = class _ModelObject extends SceneObject {
4253
4275
  /*TODO: get this from render options*/
4254
4276
  );
4255
4277
  this.iterateAllMeshes((mesh) => {
4278
+ if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
4256
4279
  mesh.material = mat;
4257
4280
  });
4258
4281
  if (this.atlas.hasAnimation) {
@@ -5511,8 +5534,13 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
5511
5534
  const obj = await objectSupplier();
5512
5535
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5513
5536
  console.log("instanceMeshes + key");
5514
- const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5515
- const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5537
+ let key = asset.key.serialize();
5538
+ if (isModelObject(obj)) {
5539
+ const { uvLockRotation, tints } = obj.options;
5540
+ if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
5541
+ const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
5542
+ if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
5543
+ }
5516
5544
  return this.instanceManager.getOrCreate(key, async () => {
5517
5545
  obj.scene = this;
5518
5546
  await obj.init();