minerender 2.1.0-alpha.21 → 2.1.0-alpha.23

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
@@ -45373,6 +45373,7 @@ return ${compiler2.callType("value", tagType)}
45373
45373
  DISPLAY_POSITIONS: () => DISPLAY_POSITIONS,
45374
45374
  DefaultBlockStates: () => DefaultBlockStates,
45375
45375
  DisplayPosition: () => DisplayPosition,
45376
+ DisplayTransforms: () => DisplayTransforms,
45376
45377
  Entities: () => Entities,
45377
45378
  EntityModels: () => EntityModels,
45378
45379
  EntityObject: () => EntityObject,
@@ -67219,15 +67220,82 @@ return ${compiler2.callType("value", tagType)}
67219
67220
  return isBasicAssetKey(obj) && obj.isAssetKey === true;
67220
67221
  }
67221
67222
 
67223
+ // src/model/DisplayTransforms.ts
67224
+ init_dirname();
67225
+ init_buffer2();
67226
+ init_process2();
67227
+
67228
+ // src/model/DisplayPosition.ts
67229
+ init_dirname();
67230
+ init_buffer2();
67231
+ init_process2();
67232
+ var DisplayPosition = /* @__PURE__ */ ((DisplayPosition2) => {
67233
+ DisplayPosition2["THIRDPERSON_RIGHTHAND"] = "thirdperson_righthand";
67234
+ DisplayPosition2["THIRDPERSON_LEFTHAND"] = "thirdperson_lefthand";
67235
+ DisplayPosition2["FIRSTPERSON_RIGHTHAND"] = "firstperson_righthand";
67236
+ DisplayPosition2["FIRSTPERSON_LEFTHAND"] = "firstperson_lefthand";
67237
+ DisplayPosition2["GUI"] = "gui";
67238
+ DisplayPosition2["HEAD"] = "head";
67239
+ DisplayPosition2["GROUND"] = "ground";
67240
+ DisplayPosition2["FIXED"] = "fixed";
67241
+ DisplayPosition2["ON_SHELF"] = "on_shelf";
67242
+ return DisplayPosition2;
67243
+ })(DisplayPosition || {});
67244
+ var DISPLAY_POSITIONS = Object.values(DisplayPosition);
67245
+
67246
+ // src/model/DisplayTransforms.ts
67247
+ var DisplayTransforms = class {
67248
+ /** Resolve hand fallbacks within one model, before inheriting parent display entries. */
67249
+ static withHandFallbacks(display) {
67250
+ if (!display) return void 0;
67251
+ const resolved = { ...display };
67252
+ for (const [left, right] of [
67253
+ ["thirdperson_lefthand" /* THIRDPERSON_LEFTHAND */, "thirdperson_righthand" /* THIRDPERSON_RIGHTHAND */],
67254
+ ["firstperson_lefthand" /* FIRSTPERSON_LEFTHAND */, "firstperson_righthand" /* FIRSTPERSON_RIGHTHAND */]
67255
+ ]) {
67256
+ if (resolved[left] === void 0 && resolved[right] !== void 0) resolved[left] = resolved[right];
67257
+ }
67258
+ return resolved;
67259
+ }
67260
+ /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
67261
+ static getMatrix(display, position) {
67262
+ const transform = this.withHandFallbacks(display)?.[position] ?? {};
67263
+ const left = position === "firstperson_lefthand" /* FIRSTPERSON_LEFTHAND */ || position === "thirdperson_lefthand" /* THIRDPERSON_LEFTHAND */;
67264
+ const sign = left ? -1 : 1;
67265
+ const [x4, y5, z4] = transform.rotation ?? [0, 0, 0];
67266
+ const rotation = new Quaternion().setFromEuler(new Euler(toRadians(x4), sign * toRadians(y5), sign * toRadians(z4), "XYZ"));
67267
+ const translation = new Vector3(...transform.translation ?? [0, 0, 0]).clampScalar(-80, 80);
67268
+ translation.x *= sign;
67269
+ const scale = new Vector3(...transform.scale ?? [1, 1, 1]).clampScalar(-4, 4);
67270
+ return new Matrix4().compose(translation, rotation, scale);
67271
+ }
67272
+ static apply(geometry, matrix) {
67273
+ geometry.applyMatrix4(matrix);
67274
+ if (matrix.determinant() < 0) {
67275
+ if (!geometry.index) geometry.setIndex(Array.from({ length: geometry.getAttribute("position").count }, (_4, i4) => i4));
67276
+ const index = geometry.index;
67277
+ for (let i4 = 0; i4 < index.count; i4 += 3) {
67278
+ const second = index.getX(i4 + 1);
67279
+ index.setX(i4 + 1, index.getX(i4 + 2));
67280
+ index.setX(i4 + 2, second);
67281
+ }
67282
+ index.needsUpdate = true;
67283
+ }
67284
+ }
67285
+ };
67286
+
67222
67287
  // src/model/ModelMerger.ts
67223
67288
  var ModelMerger = class {
67224
67289
  static async mergeWithParents(model) {
67225
67290
  const models = await this.collectAllParents(model);
67226
67291
  let merged = {};
67227
- for (let parentModel of models) {
67228
- merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
67292
+ for (const source of [...models, model]) {
67293
+ const inheritedDisplay = merged.display;
67294
+ merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, source);
67295
+ if (source.display) {
67296
+ merged.display = { ...inheritedDisplay, ...DisplayTransforms.withHandFallbacks(source.display) };
67297
+ }
67229
67298
  }
67230
- merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
67231
67299
  merged.hierarchy = models.map((m4) => m4.parent).filter((p15) => `${p15}`);
67232
67300
  merged.hierarchy.push(`${merged.parent}`);
67233
67301
  return merged;
@@ -67379,7 +67447,7 @@ return ${compiler2.callType("value", tagType)}
67379
67447
  void 0,
67380
67448
  "assets",
67381
67449
  ".json",
67382
- DEFAULT_ROOT
67450
+ AssetLoader.ROOT
67383
67451
  );
67384
67452
  return Caching.listAssetCache.get(key.serialize(), () => {
67385
67453
  return AssetLoader.get(key, "list" /* LIST */);
@@ -67677,17 +67745,17 @@ return ${compiler2.callType("value", tagType)}
67677
67745
  if (typeof namespaced !== "undefined") {
67678
67746
  return namespaced;
67679
67747
  }
67680
- if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
67748
+ if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
67681
67749
  console.info(p6, "Retrying", key, "with default root+namespace");
67682
- const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
67750
+ const namespacedRootedKey = new AssetKey(DEFAULT_NAMESPACE, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
67683
67751
  const namespacedRooted = await this.load(namespacedRootedKey, parser);
67684
67752
  if (typeof namespacedRooted !== "undefined") {
67685
67753
  return namespacedRooted;
67686
67754
  }
67687
67755
  }
67688
- } else if (typeof key.root !== "undefined" && key.root !== DEFAULT_ROOT || typeof this.root !== "undefined" && this.root !== DEFAULT_ROOT) {
67756
+ } else if (typeof key.root !== "undefined" && key.root !== AssetLoader.ROOT || typeof this.root !== "undefined" && this.root !== AssetLoader.ROOT) {
67689
67757
  console.info(p6, "Retrying", key, "with default root");
67690
- const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, DEFAULT_ROOT);
67758
+ const rootKey = new AssetKey(key.namespace, key.path, key.assetType, key.type, key.rootType, key.extension, AssetLoader.ROOT);
67691
67759
  const rooted = await this.load(rootKey, parser);
67692
67760
  if (typeof rooted !== "undefined") {
67693
67761
  return rooted;
@@ -77334,6 +77402,20 @@ return ${compiler2.callType("value", tagType)}
77334
77402
  // src/assets/AssetLoader.ts
77335
77403
  var p7 = prefix("AssetLoader");
77336
77404
  var _AssetLoader = class _AssetLoader {
77405
+ static get version() {
77406
+ return this.ROOT.substring(this.ROOT.lastIndexOf("/") + 1);
77407
+ }
77408
+ static setVersion(version2) {
77409
+ this.ROOT = `https://assets.mcasset.cloud/${version2}`;
77410
+ const source = new HostedAssetSource(this.ROOT, { retryDefaults: false });
77411
+ const index = this._SOURCES.findIndex((s4) => s4.key === "mcassets");
77412
+ if (index !== -1) {
77413
+ this._SOURCES[index] = { key: "mcassets", source };
77414
+ } else {
77415
+ this.addSource("mcassets", source);
77416
+ }
77417
+ Caching.clear();
77418
+ }
77337
77419
  static addSource(key, source, override = true) {
77338
77420
  if (override) {
77339
77421
  const existing = this.removeSource(key);
@@ -77396,7 +77478,7 @@ return ${compiler2.callType("value", tagType)}
77396
77478
  _AssetLoader.ROOT = DEFAULT_ROOT;
77397
77479
  _AssetLoader._SOURCES = [];
77398
77480
  _AssetLoader.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
77399
- _AssetLoader.addSource("mcassets", new HostedAssetSource(DEFAULT_ROOT, { retryDefaults: false }));
77481
+ _AssetLoader.addSource("mcassets", new HostedAssetSource(_AssetLoader.ROOT, { retryDefaults: false }));
77400
77482
  var AssetLoader = _AssetLoader;
77401
77483
 
77402
77484
  // src/assets/ModelTextures.ts
@@ -79291,23 +79373,6 @@ return ${compiler2.callType("value", tagType)}
79291
79373
  init_buffer2();
79292
79374
  init_process2();
79293
79375
 
79294
- // src/model/DisplayPosition.ts
79295
- init_dirname();
79296
- init_buffer2();
79297
- init_process2();
79298
- var DisplayPosition = /* @__PURE__ */ ((DisplayPosition2) => {
79299
- DisplayPosition2["THIRDPERSON_RIGHTHAND"] = "thirdperson_righthand";
79300
- DisplayPosition2["THIRDPERSON_LEFTHAND"] = "thirdperson_lefthand";
79301
- DisplayPosition2["FIRSTPERSON_RIGHTHAND"] = "firstperson_righthand";
79302
- DisplayPosition2["FIRSTPERSON_LEFTHAND"] = "firstperson_lefthand";
79303
- DisplayPosition2["GUI"] = "gui";
79304
- DisplayPosition2["HEAD"] = "head";
79305
- DisplayPosition2["GROUND"] = "ground";
79306
- DisplayPosition2["FIXED"] = "fixed";
79307
- return DisplayPosition2;
79308
- })(DisplayPosition || {});
79309
- var DISPLAY_POSITIONS = Object.values(DisplayPosition);
79310
-
79311
79376
  // src/model/ElementFace.ts
79312
79377
  init_dirname();
79313
79378
  init_buffer2();
@@ -80042,6 +80107,7 @@ return ${compiler2.callType("value", tagType)}
80042
80107
  createMeshes(force = false) {
80043
80108
  if (this.meshesCreated && !force) return;
80044
80109
  const mat = Materials.MISSING_TEXTURE;
80110
+ const displayTransform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : void 0;
80045
80111
  let allGeos = [];
80046
80112
  if (this.atlas) {
80047
80113
  if (this.atlas.model.elements) {
@@ -80070,6 +80136,7 @@ return ${compiler2.callType("value", tagType)}
80070
80136
  applyElementRotation(el.rotation, elGeo);
80071
80137
  }
80072
80138
  elGeo.applyMatrix4(new Matrix4().makeTranslation(-8, -8, -8));
80139
+ if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
80073
80140
  if (this.options.mergeMeshes) {
80074
80141
  allGeos.push(elGeo);
80075
80142
  } else {
@@ -80091,6 +80158,7 @@ return ${compiler2.callType("value", tagType)}
80091
80158
  combinedGeo = mergeBufferGeometries(allGeos);
80092
80159
  } else {
80093
80160
  combinedGeo = new BoxGeometry(16, 16, 16);
80161
+ if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
80094
80162
  }
80095
80163
  combinedGeo.computeBoundingBox();
80096
80164
  let mesh;
@@ -81423,7 +81491,8 @@ return ${compiler2.callType("value", tagType)}
81423
81491
  console.log("instanceMeshes + key");
81424
81492
  let key = asset.key.serialize();
81425
81493
  if (isModelObject(obj)) {
81426
- const { uvLockRotation, tints } = obj.options;
81494
+ const { displayPosition, uvLockRotation, tints } = obj.options;
81495
+ if (displayPosition) key += `|display:${displayPosition}`;
81427
81496
  if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
81428
81497
  const palette = Object.entries(tints ?? {}).sort(([a4], [b4]) => Number(a4) - Number(b4));
81429
81498
  if (palette.length) key += `|tints:${JSON.stringify(palette)}`;