minerender 2.1.0-alpha.18 → 2.1.0-alpha.19

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/bundle.js CHANGED
@@ -77622,6 +77622,14 @@ return ${compiler2.callType("value", tagType)}
77622
77622
  var X3 = 0;
77623
77623
  var Y4 = 1;
77624
77624
  var Z3 = 2;
77625
+ var FACE_UV_AXES = {
77626
+ east: [new Vector3(0, 0, -1), new Vector3(0, -1, 0)],
77627
+ west: [new Vector3(0, 0, 1), new Vector3(0, -1, 0)],
77628
+ up: [new Vector3(1, 0, 0), new Vector3(0, 0, 1)],
77629
+ down: [new Vector3(1, 0, 0), new Vector3(0, 0, -1)],
77630
+ south: [new Vector3(1, 0, 0), new Vector3(0, -1, 0)],
77631
+ north: [new Vector3(-1, 0, 0), new Vector3(0, -1, 0)]
77632
+ };
77625
77633
  var UVMapper = class {
77626
77634
  static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
77627
77635
  if (uvCoord === 0) return 0;
@@ -77719,6 +77727,42 @@ return ${compiler2.callType("value", tagType)}
77719
77727
  static facesToUv(faces, originalTextureSize, actualTextureSize) {
77720
77728
  return new Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
77721
77729
  }
77730
+ static lockUvs(geometry, faces, atlas, rotation) {
77731
+ const uv = geometry.getAttribute("uv");
77732
+ for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
77733
+ const faceName = CUBE_FACES[faceIndex];
77734
+ const texture = faces[faceName]?.texture?.substring(1);
77735
+ const position = texture && atlas.positions[texture];
77736
+ const size = texture && atlas.sizes[texture];
77737
+ if (!position || !size) continue;
77738
+ const [sourceU, sourceV] = FACE_UV_AXES[faceName];
77739
+ const uAxis = sourceU.clone().applyEuler(rotation);
77740
+ const vAxis = sourceV.clone().applyEuler(rotation);
77741
+ const normal = vAxis.clone().cross(uAxis);
77742
+ const targetFace = CUBE_FACES.find((name2) => {
77743
+ const [u4, v5] = FACE_UV_AXES[name2];
77744
+ return v5.clone().cross(u4).dot(normal) > 0.5;
77745
+ });
77746
+ const [targetU, targetV] = FACE_UV_AXES[targetFace];
77747
+ const uu = Math.round(targetU.dot(uAxis));
77748
+ const uvCross = Math.round(targetU.dot(vAxis));
77749
+ const vu = Math.round(targetV.dot(uAxis));
77750
+ const vv = Math.round(targetV.dot(vAxis));
77751
+ for (let corner = 0; corner < 4; corner++) {
77752
+ const index = faceIndex * 4 + corner;
77753
+ const u4 = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
77754
+ const v5 = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
77755
+ const lockedU = uu * u4 + uvCross * v5 + 0.5;
77756
+ const lockedV = vu * u4 + vv * v5 + 0.5;
77757
+ uv.setXY(
77758
+ index,
77759
+ (position[0] + lockedU * size[0]) / atlas.image.width,
77760
+ 1 - (position[1] + lockedV * size[1]) / atlas.image.height
77761
+ );
77762
+ }
77763
+ }
77764
+ uv.needsUpdate = true;
77765
+ }
77722
77766
  static async getAtlas(model) {
77723
77767
  const keyStr = model.key.serialize();
77724
77768
  return Caching.modelTextureAtlasCache.get(keyStr, (k4) => {
@@ -78418,6 +78462,7 @@ return ${compiler2.callType("value", tagType)}
78418
78462
  }
78419
78463
  createInstancedMesh(name2, geometry, material, count) {
78420
78464
  const mesh = new InstancedMesh(geometry, material, count);
78465
+ mesh.count = 0;
78421
78466
  if (name2) {
78422
78467
  mesh.name = `mesh:${name2}`;
78423
78468
  }
@@ -78495,6 +78540,10 @@ return ${compiler2.callType("value", tagType)}
78495
78540
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
78496
78541
  const i4 = this._instanceCounter++;
78497
78542
  this.setMatrixAt(i4, new Matrix4());
78543
+ const mesh = this.children[0];
78544
+ if (mesh && isInstancedMesh(mesh)) {
78545
+ mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
78546
+ }
78498
78547
  console.debug(p9, "nextInstance " + i4);
78499
78548
  if (i4 === this.options.maxInstanceCount) {
78500
78549
  console.warn(p9, "Max instance count reached for " + this);
@@ -79897,6 +79946,9 @@ return ${compiler2.callType("value", tagType)}
79897
79946
  if (this.atlas.model.elements) {
79898
79947
  this.atlas.model.elements?.forEach((el) => {
79899
79948
  const elGeo = this._getBoxGeometryFromElement(el).clone();
79949
+ if (this.options.uvLockRotation) {
79950
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler(...this.options.uvLockRotation));
79951
+ }
79900
79952
  elGeo.applyMatrix4(new Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
79901
79953
  elGeo.applyMatrix4(new Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
79902
79954
  if (el.rotation) {
@@ -80130,25 +80182,24 @@ return ${compiler2.callType("value", tagType)}
80130
80182
  await this.createVariant(variant);
80131
80183
  }
80132
80184
  async createVariant(variant) {
80133
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
80134
- const obj = await this.scene.addModel(model, this.options);
80135
- if (isInstanceReference(obj) || obj.isInstanced) {
80136
- this._isInstanced = true;
80137
- this._instanceCounter = 1;
80138
- }
80139
- let rotation = new Euler(0, 0, 0);
80185
+ const rotation = new Euler();
80140
80186
  if (typeof variant.x !== "undefined") {
80141
80187
  rotation.x = toRadians(clampRotationDegrees(variant.x));
80142
80188
  }
80143
80189
  if (typeof variant.y !== "undefined") {
80144
- if (typeof variant.x !== "undefined") {
80145
- rotation.y = toRadians(clampRotationDegrees(variant.y));
80146
- } else {
80147
- rotation.y = toRadians(clampRotationDegrees(360 - variant.y));
80148
- }
80190
+ rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
80191
+ }
80192
+ const model = await Models.getMerged(AssetKey.parse("models", variant.model));
80193
+ const options = {
80194
+ ...this.options,
80195
+ uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
80196
+ };
80197
+ const obj = await this.scene.addModel(model, options);
80198
+ if (isInstanceReference(obj) || obj.isInstanced) {
80199
+ this._isInstanced = true;
80200
+ this._instanceCounter = 1;
80149
80201
  }
80150
80202
  obj.setRotation(rotation);
80151
- console.log(obj);
80152
80203
  return obj;
80153
80204
  }
80154
80205
  async resetState() {
@@ -81253,7 +81304,8 @@ return ${compiler2.callType("value", tagType)}
81253
81304
  const obj = await objectSupplier();
81254
81305
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
81255
81306
  console.log("instanceMeshes + key");
81256
- const key = asset.key.serialize();
81307
+ const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
81308
+ const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
81257
81309
  return this.instanceManager.getOrCreate(key, async () => {
81258
81310
  obj.scene = this;
81259
81311
  await obj.init();
@@ -84069,7 +84121,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84069
84121
  return this.fromUsername(uuidOrUsername);
84070
84122
  }
84071
84123
  static async fromUuid(uuid) {
84072
- return this.getSkinProxySkinUrl(uuid);
84124
+ return this.getMcProxySkinUrl(uuid);
84073
84125
  }
84074
84126
  static async fromUsername(username) {
84075
84127
  return this.usernameToUuid(username).then((uuid) => {
@@ -84096,7 +84148,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84096
84148
  return this.capeFromUsername(uuidOrUsername);
84097
84149
  }
84098
84150
  static async capeFromUuid(uuid) {
84099
- return this.getSkinProxyCapeUrl(uuid);
84151
+ return this.getMcProxyCapeUrl(uuid);
84100
84152
  }
84101
84153
  static async capeFromUsername(username) {
84102
84154
  return this.usernameToUuid(username).then((uuid) => {
@@ -84117,8 +84169,23 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84117
84169
  //</editor-fold>
84118
84170
  //<editor-fold desc="Helpers">
84119
84171
  static async usernameToUuid(username) {
84120
- return this.usernameToUuidSkinProxy(username);
84172
+ return this.usernameToUuidMcProxy(username);
84173
+ }
84174
+ static async usernameToUuidMcProxy(username) {
84175
+ return Requests.genericRequest({
84176
+ baseURL: "https://mcproxy.dev",
84177
+ url: "/uuid/" + username
84178
+ }).then((res) => {
84179
+ if (res.status === 200) {
84180
+ return res.data["data"]["id"];
84181
+ }
84182
+ return void 0;
84183
+ }).catch((err) => {
84184
+ console.warn(err);
84185
+ return void 0;
84186
+ });
84121
84187
  }
84188
+ /** @deprecated **/
84122
84189
  static async usernameToUuidSkinProxy(username) {
84123
84190
  return Requests.genericRequest({
84124
84191
  baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
@@ -84197,12 +84264,20 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84197
84264
  static getMineSkinPlayerSkinUrl(uuid) {
84198
84265
  return "https://mineskin.org/skin/player/" + uuid;
84199
84266
  }
84267
+ /** @deprecated **/
84200
84268
  static getSkinProxySkinUrl(uuid) {
84201
84269
  return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
84202
84270
  }
84271
+ /** @deprecated **/
84203
84272
  static getSkinProxyCapeUrl(uuid) {
84204
84273
  return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
84205
84274
  }
84275
+ static getMcProxySkinUrl(uuid) {
84276
+ return "https://mcproxy.dev/skin/" + uuid;
84277
+ }
84278
+ static getMcProxyCapeUrl(uuid) {
84279
+ return "https://mcproxy.dev/cape/" + uuid;
84280
+ }
84206
84281
  //</editor-fold>
84207
84282
  };
84208
84283