minerender 2.1.0-alpha.17 → 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
@@ -67157,6 +67157,7 @@ return ${compiler2.callType("value", tagType)}
67157
67157
  this.rootType = rootType;
67158
67158
  this.extension = extension;
67159
67159
  this.root = root;
67160
+ this.isAssetKey = true;
67160
67161
  }
67161
67162
  static parse(assetType, str, origin) {
67162
67163
  let namespace = origin?.namespace || DEFAULT_NAMESPACE;
@@ -67172,7 +67173,10 @@ return ${compiler2.callType("value", tagType)}
67172
67173
  split.shift();
67173
67174
  }
67174
67175
  let path = split.join("/");
67175
- let extension = assetType === "textures" ? ".png" : origin?.assetType || ".json";
67176
+ const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
67177
+ if (extension && path.endsWith(extension)) {
67178
+ path = path.slice(0, -extension.length);
67179
+ }
67176
67180
  return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
67177
67181
  }
67178
67182
  toString() {
@@ -67202,10 +67206,10 @@ return ${compiler2.callType("value", tagType)}
67202
67206
  }
67203
67207
  };
67204
67208
  function isBasicAssetKey(obj) {
67205
- return "namespace" in obj && "path" in obj;
67209
+ return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
67206
67210
  }
67207
67211
  function isAssetKey(obj) {
67208
- return isBasicAssetKey(obj) && "parse" in obj;
67212
+ return isBasicAssetKey(obj) && obj.isAssetKey === true;
67209
67213
  }
67210
67214
 
67211
67215
  // src/model/ModelMerger.ts
@@ -77618,6 +77622,14 @@ return ${compiler2.callType("value", tagType)}
77618
77622
  var X3 = 0;
77619
77623
  var Y4 = 1;
77620
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
+ };
77621
77633
  var UVMapper = class {
77622
77634
  static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
77623
77635
  if (uvCoord === 0) return 0;
@@ -77715,6 +77727,42 @@ return ${compiler2.callType("value", tagType)}
77715
77727
  static facesToUv(faces, originalTextureSize, actualTextureSize) {
77716
77728
  return new Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
77717
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
+ }
77718
77766
  static async getAtlas(model) {
77719
77767
  const keyStr = model.key.serialize();
77720
77768
  return Caching.modelTextureAtlasCache.get(keyStr, (k4) => {
@@ -78414,6 +78462,7 @@ return ${compiler2.callType("value", tagType)}
78414
78462
  }
78415
78463
  createInstancedMesh(name2, geometry, material, count) {
78416
78464
  const mesh = new InstancedMesh(geometry, material, count);
78465
+ mesh.count = 0;
78417
78466
  if (name2) {
78418
78467
  mesh.name = `mesh:${name2}`;
78419
78468
  }
@@ -78491,6 +78540,10 @@ return ${compiler2.callType("value", tagType)}
78491
78540
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
78492
78541
  const i4 = this._instanceCounter++;
78493
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
+ }
78494
78547
  console.debug(p9, "nextInstance " + i4);
78495
78548
  if (i4 === this.options.maxInstanceCount) {
78496
78549
  console.warn(p9, "Max instance count reached for " + this);
@@ -79893,6 +79946,9 @@ return ${compiler2.callType("value", tagType)}
79893
79946
  if (this.atlas.model.elements) {
79894
79947
  this.atlas.model.elements?.forEach((el) => {
79895
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
+ }
79896
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));
79897
79953
  elGeo.applyMatrix4(new Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
79898
79954
  if (el.rotation) {
@@ -80126,25 +80182,24 @@ return ${compiler2.callType("value", tagType)}
80126
80182
  await this.createVariant(variant);
80127
80183
  }
80128
80184
  async createVariant(variant) {
80129
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
80130
- const obj = await this.scene.addModel(model, this.options);
80131
- if (isInstanceReference(obj) || obj.isInstanced) {
80132
- this._isInstanced = true;
80133
- this._instanceCounter = 1;
80134
- }
80135
- let rotation = new Euler(0, 0, 0);
80185
+ const rotation = new Euler();
80136
80186
  if (typeof variant.x !== "undefined") {
80137
80187
  rotation.x = toRadians(clampRotationDegrees(variant.x));
80138
80188
  }
80139
80189
  if (typeof variant.y !== "undefined") {
80140
- if (typeof variant.x !== "undefined") {
80141
- rotation.y = toRadians(clampRotationDegrees(variant.y));
80142
- } else {
80143
- rotation.y = toRadians(clampRotationDegrees(360 - variant.y));
80144
- }
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;
80145
80201
  }
80146
80202
  obj.setRotation(rotation);
80147
- console.log(obj);
80148
80203
  return obj;
80149
80204
  }
80150
80205
  async resetState() {
@@ -81249,7 +81304,8 @@ return ${compiler2.callType("value", tagType)}
81249
81304
  const obj = await objectSupplier();
81250
81305
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
81251
81306
  console.log("instanceMeshes + key");
81252
- 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(",")}` : "");
81253
81309
  return this.instanceManager.getOrCreate(key, async () => {
81254
81310
  obj.scene = this;
81255
81311
  await obj.init();
@@ -84065,7 +84121,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84065
84121
  return this.fromUsername(uuidOrUsername);
84066
84122
  }
84067
84123
  static async fromUuid(uuid) {
84068
- return this.getSkinProxySkinUrl(uuid);
84124
+ return this.getMcProxySkinUrl(uuid);
84069
84125
  }
84070
84126
  static async fromUsername(username) {
84071
84127
  return this.usernameToUuid(username).then((uuid) => {
@@ -84092,7 +84148,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84092
84148
  return this.capeFromUsername(uuidOrUsername);
84093
84149
  }
84094
84150
  static async capeFromUuid(uuid) {
84095
- return this.getSkinProxyCapeUrl(uuid);
84151
+ return this.getMcProxyCapeUrl(uuid);
84096
84152
  }
84097
84153
  static async capeFromUsername(username) {
84098
84154
  return this.usernameToUuid(username).then((uuid) => {
@@ -84113,8 +84169,23 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84113
84169
  //</editor-fold>
84114
84170
  //<editor-fold desc="Helpers">
84115
84171
  static async usernameToUuid(username) {
84116
- return this.usernameToUuidSkinProxy(username);
84172
+ return this.usernameToUuidMcProxy(username);
84117
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
+ });
84187
+ }
84188
+ /** @deprecated **/
84118
84189
  static async usernameToUuidSkinProxy(username) {
84119
84190
  return Requests.genericRequest({
84120
84191
  baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
@@ -84193,12 +84264,20 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
84193
84264
  static getMineSkinPlayerSkinUrl(uuid) {
84194
84265
  return "https://mineskin.org/skin/player/" + uuid;
84195
84266
  }
84267
+ /** @deprecated **/
84196
84268
  static getSkinProxySkinUrl(uuid) {
84197
84269
  return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
84198
84270
  }
84271
+ /** @deprecated **/
84199
84272
  static getSkinProxyCapeUrl(uuid) {
84200
84273
  return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
84201
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
+ }
84202
84281
  //</editor-fold>
84203
84282
  };
84204
84283