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.
@@ -554,6 +554,7 @@ declare class UVMapper {
554
554
  static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
555
555
  static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
556
556
  static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
557
+ static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
557
558
  static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
558
559
  static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
559
560
  [k: string]: T;
@@ -847,6 +848,8 @@ declare class ModelObject extends SceneObject {
847
848
  protected applyTextures(): void;
848
849
  }
849
850
  interface ModelObjectOptions extends SceneObjectOptions {
851
+ /** Quarter-turn block rotation in radians to compensate when locking UVs. */
852
+ uvLockRotation?: TripleArray;
850
853
  }
851
854
  declare function isModelObject(obj: any): obj is ModelObject;
852
855
 
@@ -1538,6 +1541,8 @@ declare class Skins {
1538
1541
  static capeFromUsername(username: string): Promise<Maybe<string>>;
1539
1542
  static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
1540
1543
  private static usernameToUuid;
1544
+ private static usernameToUuidMcProxy;
1545
+ /** @deprecated **/
1541
1546
  private static usernameToUuidSkinProxy;
1542
1547
  private static usernameToUuidMineTools;
1543
1548
  private static getProfileFromMinetools;
@@ -1547,8 +1552,12 @@ declare class Skins {
1547
1552
  private static getCrafatarCapeUrl;
1548
1553
  private static getMcHeadsSkinUrl;
1549
1554
  private static getMineSkinPlayerSkinUrl;
1555
+ /** @deprecated **/
1550
1556
  private static getSkinProxySkinUrl;
1557
+ /** @deprecated **/
1551
1558
  private static getSkinProxyCapeUrl;
1559
+ private static getMcProxySkinUrl;
1560
+ private static getMcProxyCapeUrl;
1552
1561
  }
1553
1562
 
1554
1563
  declare class TextureLoader {
@@ -554,6 +554,7 @@ declare class UVMapper {
554
554
  static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
555
555
  static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
556
556
  static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
557
+ static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
557
558
  static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
558
559
  static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
559
560
  [k: string]: T;
@@ -847,6 +848,8 @@ declare class ModelObject extends SceneObject {
847
848
  protected applyTextures(): void;
848
849
  }
849
850
  interface ModelObjectOptions extends SceneObjectOptions {
851
+ /** Quarter-turn block rotation in radians to compensate when locking UVs. */
852
+ uvLockRotation?: TripleArray;
850
853
  }
851
854
  declare function isModelObject(obj: any): obj is ModelObject;
852
855
 
@@ -1538,6 +1541,8 @@ declare class Skins {
1538
1541
  static capeFromUsername(username: string): Promise<Maybe<string>>;
1539
1542
  static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
1540
1543
  private static usernameToUuid;
1544
+ private static usernameToUuidMcProxy;
1545
+ /** @deprecated **/
1541
1546
  private static usernameToUuidSkinProxy;
1542
1547
  private static usernameToUuidMineTools;
1543
1548
  private static getProfileFromMinetools;
@@ -1547,8 +1552,12 @@ declare class Skins {
1547
1552
  private static getCrafatarCapeUrl;
1548
1553
  private static getMcHeadsSkinUrl;
1549
1554
  private static getMineSkinPlayerSkinUrl;
1555
+ /** @deprecated **/
1550
1556
  private static getSkinProxySkinUrl;
1557
+ /** @deprecated **/
1551
1558
  private static getSkinProxyCapeUrl;
1559
+ private static getMcProxySkinUrl;
1560
+ private static getMcProxyCapeUrl;
1552
1561
  }
1553
1562
 
1554
1563
  declare class TextureLoader {
@@ -2209,6 +2209,14 @@ var DEFAULT_UV = [0, 0, 16, 16];
2209
2209
  var X = 0;
2210
2210
  var Y = 1;
2211
2211
  var Z = 2;
2212
+ var FACE_UV_AXES = {
2213
+ east: [new import_three8.Vector3(0, 0, -1), new import_three8.Vector3(0, -1, 0)],
2214
+ west: [new import_three8.Vector3(0, 0, 1), new import_three8.Vector3(0, -1, 0)],
2215
+ up: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, 1)],
2216
+ down: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, -1)],
2217
+ south: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, -1, 0)],
2218
+ north: [new import_three8.Vector3(-1, 0, 0), new import_three8.Vector3(0, -1, 0)]
2219
+ };
2212
2220
  var UVMapper = class {
2213
2221
  static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
2214
2222
  if (uvCoord === 0) return 0;
@@ -2306,6 +2314,42 @@ var UVMapper = class {
2306
2314
  static facesToUv(faces, originalTextureSize, actualTextureSize) {
2307
2315
  return new import_three8.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
2308
2316
  }
2317
+ static lockUvs(geometry, faces, atlas, rotation) {
2318
+ const uv = geometry.getAttribute("uv");
2319
+ for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
2320
+ const faceName = CUBE_FACES[faceIndex];
2321
+ const texture = faces[faceName]?.texture?.substring(1);
2322
+ const position = texture && atlas.positions[texture];
2323
+ const size = texture && atlas.sizes[texture];
2324
+ if (!position || !size) continue;
2325
+ const [sourceU, sourceV] = FACE_UV_AXES[faceName];
2326
+ const uAxis = sourceU.clone().applyEuler(rotation);
2327
+ const vAxis = sourceV.clone().applyEuler(rotation);
2328
+ const normal = vAxis.clone().cross(uAxis);
2329
+ const targetFace = CUBE_FACES.find((name) => {
2330
+ const [u, v] = FACE_UV_AXES[name];
2331
+ return v.clone().cross(u).dot(normal) > 0.5;
2332
+ });
2333
+ const [targetU, targetV] = FACE_UV_AXES[targetFace];
2334
+ const uu = Math.round(targetU.dot(uAxis));
2335
+ const uvCross = Math.round(targetU.dot(vAxis));
2336
+ const vu = Math.round(targetV.dot(uAxis));
2337
+ const vv = Math.round(targetV.dot(vAxis));
2338
+ for (let corner = 0; corner < 4; corner++) {
2339
+ const index = faceIndex * 4 + corner;
2340
+ const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
2341
+ const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
2342
+ const lockedU = uu * u + uvCross * v + 0.5;
2343
+ const lockedV = vu * u + vv * v + 0.5;
2344
+ uv.setXY(
2345
+ index,
2346
+ (position[0] + lockedU * size[0]) / atlas.image.width,
2347
+ 1 - (position[1] + lockedV * size[1]) / atlas.image.height
2348
+ );
2349
+ }
2350
+ }
2351
+ uv.needsUpdate = true;
2352
+ }
2309
2353
  static async getAtlas(model) {
2310
2354
  const keyStr = model.key.serialize();
2311
2355
  return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
@@ -2912,6 +2956,7 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
2912
2956
  }
2913
2957
  createInstancedMesh(name, geometry, material, count) {
2914
2958
  const mesh = new import_three9.InstancedMesh(geometry, material, count);
2959
+ mesh.count = 0;
2915
2960
  if (name) {
2916
2961
  mesh.name = `mesh:${name}`;
2917
2962
  }
@@ -2989,6 +3034,10 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
2989
3034
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
2990
3035
  const i = this._instanceCounter++;
2991
3036
  this.setMatrixAt(i, new import_three9.Matrix4());
3037
+ const mesh = this.children[0];
3038
+ if (mesh && isInstancedMesh(mesh)) {
3039
+ mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
3040
+ }
2992
3041
  console.debug(p6, "nextInstance " + i);
2993
3042
  if (i === this.options.maxInstanceCount) {
2994
3043
  console.warn(p6, "Max instance count reached for " + this);
@@ -4291,6 +4340,9 @@ var _ModelObject = class _ModelObject extends SceneObject {
4291
4340
  if (this.atlas.model.elements) {
4292
4341
  this.atlas.model.elements?.forEach((el) => {
4293
4342
  const elGeo = this._getBoxGeometryFromElement(el).clone();
4343
+ if (this.options.uvLockRotation) {
4344
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
4345
+ }
4294
4346
  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));
4295
4347
  elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4296
4348
  if (el.rotation) {
@@ -4525,25 +4577,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
4525
4577
  await this.createVariant(variant);
4526
4578
  }
4527
4579
  async createVariant(variant) {
4528
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4529
- const obj = await this.scene.addModel(model, this.options);
4530
- if (isInstanceReference(obj) || obj.isInstanced) {
4531
- this._isInstanced = true;
4532
- this._instanceCounter = 1;
4533
- }
4534
- let rotation = new import_three16.Euler(0, 0, 0);
4580
+ const rotation = new import_three16.Euler();
4535
4581
  if (typeof variant.x !== "undefined") {
4536
4582
  rotation.x = toRadians(clampRotationDegrees(variant.x));
4537
4583
  }
4538
4584
  if (typeof variant.y !== "undefined") {
4539
- if (typeof variant.x !== "undefined") {
4540
- rotation.y = toRadians(clampRotationDegrees(variant.y));
4541
- } else {
4542
- rotation.y = toRadians(clampRotationDegrees(360 - variant.y));
4543
- }
4585
+ rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
4586
+ }
4587
+ const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4588
+ const options = {
4589
+ ...this.options,
4590
+ uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
4591
+ };
4592
+ const obj = await this.scene.addModel(model, options);
4593
+ if (isInstanceReference(obj) || obj.isInstanced) {
4594
+ this._isInstanced = true;
4595
+ this._instanceCounter = 1;
4544
4596
  }
4545
4597
  obj.setRotation(rotation);
4546
- console.log(obj);
4547
4598
  return obj;
4548
4599
  }
4549
4600
  async resetState() {
@@ -5606,7 +5657,8 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
5606
5657
  const obj = await objectSupplier();
5607
5658
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5608
5659
  console.log("instanceMeshes + key");
5609
- const key = asset.key.serialize();
5660
+ const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5661
+ const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5610
5662
  return this.instanceManager.getOrCreate(key, async () => {
5611
5663
  obj.scene = this;
5612
5664
  await obj.init();
@@ -6643,7 +6695,7 @@ var Skins = class {
6643
6695
  return this.fromUsername(uuidOrUsername);
6644
6696
  }
6645
6697
  static async fromUuid(uuid) {
6646
- return this.getSkinProxySkinUrl(uuid);
6698
+ return this.getMcProxySkinUrl(uuid);
6647
6699
  }
6648
6700
  static async fromUsername(username) {
6649
6701
  return this.usernameToUuid(username).then((uuid) => {
@@ -6670,7 +6722,7 @@ var Skins = class {
6670
6722
  return this.capeFromUsername(uuidOrUsername);
6671
6723
  }
6672
6724
  static async capeFromUuid(uuid) {
6673
- return this.getSkinProxyCapeUrl(uuid);
6725
+ return this.getMcProxyCapeUrl(uuid);
6674
6726
  }
6675
6727
  static async capeFromUsername(username) {
6676
6728
  return this.usernameToUuid(username).then((uuid) => {
@@ -6691,8 +6743,23 @@ var Skins = class {
6691
6743
  //</editor-fold>
6692
6744
  //<editor-fold desc="Helpers">
6693
6745
  static async usernameToUuid(username) {
6694
- return this.usernameToUuidSkinProxy(username);
6746
+ return this.usernameToUuidMcProxy(username);
6695
6747
  }
6748
+ static async usernameToUuidMcProxy(username) {
6749
+ return Requests.genericRequest({
6750
+ baseURL: "https://mcproxy.dev",
6751
+ url: "/uuid/" + username
6752
+ }).then((res) => {
6753
+ if (res.status === 200) {
6754
+ return res.data["data"]["id"];
6755
+ }
6756
+ return void 0;
6757
+ }).catch((err) => {
6758
+ console.warn(err);
6759
+ return void 0;
6760
+ });
6761
+ }
6762
+ /** @deprecated **/
6696
6763
  static async usernameToUuidSkinProxy(username) {
6697
6764
  return Requests.genericRequest({
6698
6765
  baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
@@ -6771,12 +6838,20 @@ var Skins = class {
6771
6838
  static getMineSkinPlayerSkinUrl(uuid) {
6772
6839
  return "https://mineskin.org/skin/player/" + uuid;
6773
6840
  }
6841
+ /** @deprecated **/
6774
6842
  static getSkinProxySkinUrl(uuid) {
6775
6843
  return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
6776
6844
  }
6845
+ /** @deprecated **/
6777
6846
  static getSkinProxyCapeUrl(uuid) {
6778
6847
  return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
6779
6848
  }
6849
+ static getMcProxySkinUrl(uuid) {
6850
+ return "https://mcproxy.dev/skin/" + uuid;
6851
+ }
6852
+ static getMcProxyCapeUrl(uuid) {
6853
+ return "https://mcproxy.dev/cape/" + uuid;
6854
+ }
6780
6855
  //</editor-fold>
6781
6856
  };
6782
6857