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.
@@ -945,6 +945,7 @@ var Materials = class _Materials {
945
945
  uniform bool SHADE;
946
946
 
947
947
  varying vec2 vUv;
948
+ varying vec3 vTint;
948
949
  varying float light;
949
950
  varying float lift;
950
951
 
@@ -979,6 +980,7 @@ var Materials = class _Materials {
979
980
  }
980
981
 
981
982
  vUv = uv;
983
+ vTint = color;
982
984
 
983
985
  #ifdef USE_INSTANCING
984
986
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
@@ -1000,12 +1002,14 @@ var Materials = class _Materials {
1000
1002
  uniform float BRIGHTNESS;
1001
1003
 
1002
1004
  varying vec2 vUv;
1005
+ varying vec3 vTint;
1003
1006
  varying float light;
1004
1007
  varying float lift;
1005
1008
 
1006
1009
  void main(void)
1007
1010
  {
1008
1011
  vec4 color = texture2D(map, vUv);
1012
+ color.rgb *= vTint;
1009
1013
 
1010
1014
  if (color.a < 0.01) discard;
1011
1015
 
@@ -2066,17 +2070,20 @@ var ModelGenerator = class {
2066
2070
  this.ITEM_LAYERS = ["layer0", "layer1", "layer2", "layer3", "layer4"];
2067
2071
  }
2068
2072
  static generateItemModel(imageData, layer) {
2073
+ const tintindex = this.ITEM_LAYERS.indexOf(layer);
2069
2074
  const mainElement = {
2070
2075
  from: [0, 0, 7.5],
2071
2076
  to: [16, 16, 8.5],
2072
2077
  faces: {
2073
2078
  "south": {
2074
2079
  uv: [0, 0, 16, 16],
2075
- texture: `#${layer}`
2080
+ texture: `#${layer}`,
2081
+ tintindex
2076
2082
  },
2077
2083
  "north": {
2078
2084
  uv: [16, 0, 0, 16],
2079
- texture: `#${layer}`
2085
+ texture: `#${layer}`,
2086
+ tintindex
2080
2087
  }
2081
2088
  },
2082
2089
  shade: true
@@ -3655,7 +3662,7 @@ function isQuadArray(obj) {
3655
3662
  }
3656
3663
 
3657
3664
  // src/model/scene/ModelObject.ts
3658
- import { BoxGeometry as BoxGeometry5, Euler as Euler4, Matrix4 as Matrix45 } from "three";
3665
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix45 } from "three";
3659
3666
 
3660
3667
  // src/three/BufferGeometryUtils.js
3661
3668
  import {
@@ -4209,6 +4216,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4209
4216
  this.isModelObject = true;
4210
4217
  this.meshesCreated = false;
4211
4218
  this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
4219
+ if (this.options.tints) this.options.tints = { ...this.options.tints };
4212
4220
  console.log("ModelObject options", this.options);
4213
4221
  }
4214
4222
  static {
@@ -4241,6 +4249,20 @@ var ModelObject = class _ModelObject extends SceneObject {
4241
4249
  if (this.options.uvLockRotation) {
4242
4250
  UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler4(...this.options.uvLockRotation));
4243
4251
  }
4252
+ if (this.options.tints) {
4253
+ const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
4254
+ for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
4255
+ const tintIndex = el.faces[faceName]?.tintindex;
4256
+ if (tintIndex === void 0 || tintIndex < 0) continue;
4257
+ const tint = this.options.tints[tintIndex];
4258
+ if (tint === void 0) continue;
4259
+ const color = new Color3(tint);
4260
+ for (let vertex = 0; vertex < 4; vertex++) {
4261
+ color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4262
+ }
4263
+ }
4264
+ elGeo.setAttribute("color", new BufferAttribute4(colors, 3));
4265
+ }
4244
4266
  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));
4245
4267
  elGeo.applyMatrix4(new Matrix45().makeTranslation(el.from[0], el.from[1], el.from[2]));
4246
4268
  if (el.rotation) {
@@ -4297,6 +4319,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4297
4319
  /*TODO: get this from render options*/
4298
4320
  );
4299
4321
  this.iterateAllMeshes((mesh) => {
4322
+ if (mesh.geometry.hasAttribute("color")) mat.vertexColors = true;
4300
4323
  mesh.material = mat;
4301
4324
  });
4302
4325
  if (this.atlas.hasAnimation) {
@@ -5557,8 +5580,13 @@ var MineRenderScene = class _MineRenderScene extends Scene2 {
5557
5580
  const obj = await objectSupplier();
5558
5581
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5559
5582
  console.log("instanceMeshes + key");
5560
- const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5561
- const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5583
+ let key = asset.key.serialize();
5584
+ if (isModelObject(obj)) {
5585
+ const { uvLockRotation, tints } = obj.options;
5586
+ if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
5587
+ const palette = Object.entries(tints ?? {}).sort(([a], [b]) => Number(a) - Number(b));
5588
+ if (palette.length) key += `|tints:${JSON.stringify(palette)}`;
5589
+ }
5562
5590
  return this.instanceManager.getOrCreate(key, async () => {
5563
5591
  obj.scene = this;
5564
5592
  await obj.init();