minerender 2.1.0-alpha.21 → 2.1.0-alpha.22

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;
@@ -79291,23 +79359,6 @@ return ${compiler2.callType("value", tagType)}
79291
79359
  init_buffer2();
79292
79360
  init_process2();
79293
79361
 
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
79362
  // src/model/ElementFace.ts
79312
79363
  init_dirname();
79313
79364
  init_buffer2();
@@ -80042,6 +80093,7 @@ return ${compiler2.callType("value", tagType)}
80042
80093
  createMeshes(force = false) {
80043
80094
  if (this.meshesCreated && !force) return;
80044
80095
  const mat = Materials.MISSING_TEXTURE;
80096
+ const displayTransform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : void 0;
80045
80097
  let allGeos = [];
80046
80098
  if (this.atlas) {
80047
80099
  if (this.atlas.model.elements) {
@@ -80070,6 +80122,7 @@ return ${compiler2.callType("value", tagType)}
80070
80122
  applyElementRotation(el.rotation, elGeo);
80071
80123
  }
80072
80124
  elGeo.applyMatrix4(new Matrix4().makeTranslation(-8, -8, -8));
80125
+ if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
80073
80126
  if (this.options.mergeMeshes) {
80074
80127
  allGeos.push(elGeo);
80075
80128
  } else {
@@ -80091,6 +80144,7 @@ return ${compiler2.callType("value", tagType)}
80091
80144
  combinedGeo = mergeBufferGeometries(allGeos);
80092
80145
  } else {
80093
80146
  combinedGeo = new BoxGeometry(16, 16, 16);
80147
+ if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
80094
80148
  }
80095
80149
  combinedGeo.computeBoundingBox();
80096
80150
  let mesh;
@@ -81423,7 +81477,8 @@ return ${compiler2.callType("value", tagType)}
81423
81477
  console.log("instanceMeshes + key");
81424
81478
  let key = asset.key.serialize();
81425
81479
  if (isModelObject(obj)) {
81426
- const { uvLockRotation, tints } = obj.options;
81480
+ const { displayPosition, uvLockRotation, tints } = obj.options;
81481
+ if (displayPosition) key += `|display:${displayPosition}`;
81427
81482
  if (uvLockRotation) key += `|uvlock:${uvLockRotation.join(",")}`;
81428
81483
  const palette = Object.entries(tints ?? {}).sort(([a4], [b4]) => Number(a4) - Number(b4));
81429
81484
  if (palette.length) key += `|tints:${JSON.stringify(palette)}`;