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.
@@ -174,6 +174,7 @@ declare class AssetKey extends BasicAssetKey {
174
174
  rootType: "assets" | "data" | string;
175
175
  extension: ".json" | ".png" | string;
176
176
  root?: string | undefined;
177
+ readonly isAssetKey: true;
177
178
  constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
178
179
  static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
179
180
  toString(): string;
@@ -554,6 +555,7 @@ declare class UVMapper {
554
555
  static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
555
556
  static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
556
557
  static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
558
+ static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
557
559
  static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
558
560
  static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
559
561
  [k: string]: T;
@@ -847,6 +849,8 @@ declare class ModelObject extends SceneObject {
847
849
  protected applyTextures(): void;
848
850
  }
849
851
  interface ModelObjectOptions extends SceneObjectOptions {
852
+ /** Quarter-turn block rotation in radians to compensate when locking UVs. */
853
+ uvLockRotation?: TripleArray;
850
854
  }
851
855
  declare function isModelObject(obj: any): obj is ModelObject;
852
856
 
@@ -1538,6 +1542,8 @@ declare class Skins {
1538
1542
  static capeFromUsername(username: string): Promise<Maybe<string>>;
1539
1543
  static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
1540
1544
  private static usernameToUuid;
1545
+ private static usernameToUuidMcProxy;
1546
+ /** @deprecated **/
1541
1547
  private static usernameToUuidSkinProxy;
1542
1548
  private static usernameToUuidMineTools;
1543
1549
  private static getProfileFromMinetools;
@@ -1547,8 +1553,12 @@ declare class Skins {
1547
1553
  private static getCrafatarCapeUrl;
1548
1554
  private static getMcHeadsSkinUrl;
1549
1555
  private static getMineSkinPlayerSkinUrl;
1556
+ /** @deprecated **/
1550
1557
  private static getSkinProxySkinUrl;
1558
+ /** @deprecated **/
1551
1559
  private static getSkinProxyCapeUrl;
1560
+ private static getMcProxySkinUrl;
1561
+ private static getMcProxyCapeUrl;
1552
1562
  }
1553
1563
 
1554
1564
  declare class TextureLoader {
@@ -174,6 +174,7 @@ declare class AssetKey extends BasicAssetKey {
174
174
  rootType: "assets" | "data" | string;
175
175
  extension: ".json" | ".png" | string;
176
176
  root?: string | undefined;
177
+ readonly isAssetKey: true;
177
178
  constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
178
179
  static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
179
180
  toString(): string;
@@ -554,6 +555,7 @@ declare class UVMapper {
554
555
  static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
555
556
  static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
556
557
  static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
558
+ static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
557
559
  static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
558
560
  static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
559
561
  [k: string]: T;
@@ -847,6 +849,8 @@ declare class ModelObject extends SceneObject {
847
849
  protected applyTextures(): void;
848
850
  }
849
851
  interface ModelObjectOptions extends SceneObjectOptions {
852
+ /** Quarter-turn block rotation in radians to compensate when locking UVs. */
853
+ uvLockRotation?: TripleArray;
850
854
  }
851
855
  declare function isModelObject(obj: any): obj is ModelObject;
852
856
 
@@ -1538,6 +1542,8 @@ declare class Skins {
1538
1542
  static capeFromUsername(username: string): Promise<Maybe<string>>;
1539
1543
  static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
1540
1544
  private static usernameToUuid;
1545
+ private static usernameToUuidMcProxy;
1546
+ /** @deprecated **/
1541
1547
  private static usernameToUuidSkinProxy;
1542
1548
  private static usernameToUuidMineTools;
1543
1549
  private static getProfileFromMinetools;
@@ -1547,8 +1553,12 @@ declare class Skins {
1547
1553
  private static getCrafatarCapeUrl;
1548
1554
  private static getMcHeadsSkinUrl;
1549
1555
  private static getMineSkinPlayerSkinUrl;
1556
+ /** @deprecated **/
1550
1557
  private static getSkinProxySkinUrl;
1558
+ /** @deprecated **/
1551
1559
  private static getSkinProxyCapeUrl;
1560
+ private static getMcProxySkinUrl;
1561
+ private static getMcProxyCapeUrl;
1552
1562
  }
1553
1563
 
1554
1564
  declare class TextureLoader {
@@ -1281,6 +1281,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
1281
1281
  this.rootType = rootType;
1282
1282
  this.extension = extension;
1283
1283
  this.root = root;
1284
+ this.isAssetKey = true;
1284
1285
  }
1285
1286
  static parse(assetType, str, origin) {
1286
1287
  let namespace = origin?.namespace || DEFAULT_NAMESPACE;
@@ -1296,7 +1297,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
1296
1297
  split.shift();
1297
1298
  }
1298
1299
  let path = split.join("/");
1299
- let extension = assetType === "textures" ? ".png" : origin?.assetType || ".json";
1300
+ const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
1301
+ if (extension && path.endsWith(extension)) {
1302
+ path = path.slice(0, -extension.length);
1303
+ }
1300
1304
  return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
1301
1305
  }
1302
1306
  toString() {
@@ -1326,10 +1330,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
1326
1330
  }
1327
1331
  };
1328
1332
  function isBasicAssetKey(obj) {
1329
- return "namespace" in obj && "path" in obj;
1333
+ return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
1330
1334
  }
1331
1335
  function isAssetKey(obj) {
1332
- return isBasicAssetKey(obj) && "parse" in obj;
1336
+ return isBasicAssetKey(obj) && obj.isAssetKey === true;
1333
1337
  }
1334
1338
 
1335
1339
  // src/model/ModelMerger.ts
@@ -2242,6 +2246,14 @@ var DEFAULT_UV = [0, 0, 16, 16];
2242
2246
  var X = 0;
2243
2247
  var Y = 1;
2244
2248
  var Z = 2;
2249
+ var FACE_UV_AXES = {
2250
+ east: [new import_three8.Vector3(0, 0, -1), new import_three8.Vector3(0, -1, 0)],
2251
+ west: [new import_three8.Vector3(0, 0, 1), new import_three8.Vector3(0, -1, 0)],
2252
+ up: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, 1)],
2253
+ down: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, -1)],
2254
+ south: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, -1, 0)],
2255
+ north: [new import_three8.Vector3(-1, 0, 0), new import_three8.Vector3(0, -1, 0)]
2256
+ };
2245
2257
  var UVMapper = class {
2246
2258
  static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
2247
2259
  if (uvCoord === 0) return 0;
@@ -2339,6 +2351,42 @@ var UVMapper = class {
2339
2351
  static facesToUv(faces, originalTextureSize, actualTextureSize) {
2340
2352
  return new import_three8.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
2341
2353
  }
2354
+ static lockUvs(geometry, faces, atlas, rotation) {
2355
+ const uv = geometry.getAttribute("uv");
2356
+ for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
2357
+ const faceName = CUBE_FACES[faceIndex];
2358
+ const texture = faces[faceName]?.texture?.substring(1);
2359
+ const position = texture && atlas.positions[texture];
2360
+ const size = texture && atlas.sizes[texture];
2361
+ if (!position || !size) continue;
2362
+ const [sourceU, sourceV] = FACE_UV_AXES[faceName];
2363
+ const uAxis = sourceU.clone().applyEuler(rotation);
2364
+ const vAxis = sourceV.clone().applyEuler(rotation);
2365
+ const normal = vAxis.clone().cross(uAxis);
2366
+ const targetFace = CUBE_FACES.find((name) => {
2367
+ const [u, v] = FACE_UV_AXES[name];
2368
+ return v.clone().cross(u).dot(normal) > 0.5;
2369
+ });
2370
+ const [targetU, targetV] = FACE_UV_AXES[targetFace];
2371
+ const uu = Math.round(targetU.dot(uAxis));
2372
+ const uvCross = Math.round(targetU.dot(vAxis));
2373
+ const vu = Math.round(targetV.dot(uAxis));
2374
+ const vv = Math.round(targetV.dot(vAxis));
2375
+ for (let corner = 0; corner < 4; corner++) {
2376
+ const index = faceIndex * 4 + corner;
2377
+ const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
2378
+ const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
2379
+ const lockedU = uu * u + uvCross * v + 0.5;
2380
+ const lockedV = vu * u + vv * v + 0.5;
2381
+ uv.setXY(
2382
+ index,
2383
+ (position[0] + lockedU * size[0]) / atlas.image.width,
2384
+ 1 - (position[1] + lockedV * size[1]) / atlas.image.height
2385
+ );
2386
+ }
2387
+ }
2388
+ uv.needsUpdate = true;
2389
+ }
2342
2390
  static async getAtlas(model) {
2343
2391
  const keyStr = model.key.serialize();
2344
2392
  return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
@@ -2953,6 +3001,7 @@ var SceneObject = class _SceneObject extends import_three9.Object3D {
2953
3001
  }
2954
3002
  createInstancedMesh(name, geometry, material, count) {
2955
3003
  const mesh = new import_three9.InstancedMesh(geometry, material, count);
3004
+ mesh.count = 0;
2956
3005
  if (name) {
2957
3006
  mesh.name = `mesh:${name}`;
2958
3007
  }
@@ -3030,6 +3079,10 @@ var SceneObject = class _SceneObject extends import_three9.Object3D {
3030
3079
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
3031
3080
  const i = this._instanceCounter++;
3032
3081
  this.setMatrixAt(i, new import_three9.Matrix4());
3082
+ const mesh = this.children[0];
3083
+ if (mesh && isInstancedMesh(mesh)) {
3084
+ mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
3085
+ }
3033
3086
  console.debug(p6, "nextInstance " + i);
3034
3087
  if (i === this.options.maxInstanceCount) {
3035
3088
  console.warn(p6, "Max instance count reached for " + this);
@@ -4330,6 +4383,9 @@ var ModelObject = class _ModelObject extends SceneObject {
4330
4383
  if (this.atlas.model.elements) {
4331
4384
  this.atlas.model.elements?.forEach((el) => {
4332
4385
  const elGeo = this._getBoxGeometryFromElement(el).clone();
4386
+ if (this.options.uvLockRotation) {
4387
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
4388
+ }
4333
4389
  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));
4334
4390
  elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4335
4391
  if (el.rotation) {
@@ -4567,25 +4623,24 @@ var BlockObject = class _BlockObject extends SceneObject {
4567
4623
  await this.createVariant(variant);
4568
4624
  }
4569
4625
  async createVariant(variant) {
4570
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4571
- const obj = await this.scene.addModel(model, this.options);
4572
- if (isInstanceReference(obj) || obj.isInstanced) {
4573
- this._isInstanced = true;
4574
- this._instanceCounter = 1;
4575
- }
4576
- let rotation = new import_three16.Euler(0, 0, 0);
4626
+ const rotation = new import_three16.Euler();
4577
4627
  if (typeof variant.x !== "undefined") {
4578
4628
  rotation.x = toRadians(clampRotationDegrees(variant.x));
4579
4629
  }
4580
4630
  if (typeof variant.y !== "undefined") {
4581
- if (typeof variant.x !== "undefined") {
4582
- rotation.y = toRadians(clampRotationDegrees(variant.y));
4583
- } else {
4584
- rotation.y = toRadians(clampRotationDegrees(360 - variant.y));
4585
- }
4631
+ rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
4632
+ }
4633
+ const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4634
+ const options = {
4635
+ ...this.options,
4636
+ uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
4637
+ };
4638
+ const obj = await this.scene.addModel(model, options);
4639
+ if (isInstanceReference(obj) || obj.isInstanced) {
4640
+ this._isInstanced = true;
4641
+ this._instanceCounter = 1;
4586
4642
  }
4587
4643
  obj.setRotation(rotation);
4588
- console.log(obj);
4589
4644
  return obj;
4590
4645
  }
4591
4646
  async resetState() {
@@ -5647,7 +5702,8 @@ var MineRenderScene = class _MineRenderScene extends import_three17.Scene {
5647
5702
  const obj = await objectSupplier();
5648
5703
  if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
5649
5704
  console.log("instanceMeshes + key");
5650
- const key = asset.key.serialize();
5705
+ const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
5706
+ const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
5651
5707
  return this.instanceManager.getOrCreate(key, async () => {
5652
5708
  obj.scene = this;
5653
5709
  await obj.init();
@@ -6683,7 +6739,7 @@ var Skins = class {
6683
6739
  return this.fromUsername(uuidOrUsername);
6684
6740
  }
6685
6741
  static async fromUuid(uuid) {
6686
- return this.getSkinProxySkinUrl(uuid);
6742
+ return this.getMcProxySkinUrl(uuid);
6687
6743
  }
6688
6744
  static async fromUsername(username) {
6689
6745
  return this.usernameToUuid(username).then((uuid) => {
@@ -6710,7 +6766,7 @@ var Skins = class {
6710
6766
  return this.capeFromUsername(uuidOrUsername);
6711
6767
  }
6712
6768
  static async capeFromUuid(uuid) {
6713
- return this.getSkinProxyCapeUrl(uuid);
6769
+ return this.getMcProxyCapeUrl(uuid);
6714
6770
  }
6715
6771
  static async capeFromUsername(username) {
6716
6772
  return this.usernameToUuid(username).then((uuid) => {
@@ -6731,8 +6787,23 @@ var Skins = class {
6731
6787
  //</editor-fold>
6732
6788
  //<editor-fold desc="Helpers">
6733
6789
  static async usernameToUuid(username) {
6734
- return this.usernameToUuidSkinProxy(username);
6790
+ return this.usernameToUuidMcProxy(username);
6791
+ }
6792
+ static async usernameToUuidMcProxy(username) {
6793
+ return Requests.genericRequest({
6794
+ baseURL: "https://mcproxy.dev",
6795
+ url: "/uuid/" + username
6796
+ }).then((res) => {
6797
+ if (res.status === 200) {
6798
+ return res.data["data"]["id"];
6799
+ }
6800
+ return void 0;
6801
+ }).catch((err) => {
6802
+ console.warn(err);
6803
+ return void 0;
6804
+ });
6735
6805
  }
6806
+ /** @deprecated **/
6736
6807
  static async usernameToUuidSkinProxy(username) {
6737
6808
  return Requests.genericRequest({
6738
6809
  baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
@@ -6811,12 +6882,20 @@ var Skins = class {
6811
6882
  static getMineSkinPlayerSkinUrl(uuid) {
6812
6883
  return "https://mineskin.org/skin/player/" + uuid;
6813
6884
  }
6885
+ /** @deprecated **/
6814
6886
  static getSkinProxySkinUrl(uuid) {
6815
6887
  return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
6816
6888
  }
6889
+ /** @deprecated **/
6817
6890
  static getSkinProxyCapeUrl(uuid) {
6818
6891
  return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
6819
6892
  }
6893
+ static getMcProxySkinUrl(uuid) {
6894
+ return "https://mcproxy.dev/skin/" + uuid;
6895
+ }
6896
+ static getMcProxyCapeUrl(uuid) {
6897
+ return "https://mcproxy.dev/cape/" + uuid;
6898
+ }
6820
6899
  //</editor-fold>
6821
6900
  };
6822
6901