minerender 2.1.0-alpha.125 → 2.1.0-alpha.126

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.
@@ -1,5 +1,5 @@
1
1
  import * as three from 'three';
2
- import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, ShaderMaterial, Texture, Camera, MOUSE, TOUCH, Controls, WebGLRenderer, EventDispatcher, Raycaster, Intersection, Group, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points } from 'three';
2
+ import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Quaternion, Box2, Scene, Object3DEventMap, ShaderMaterial, Texture, Camera, MOUSE, TOUCH, Controls, WebGLRenderer, EventDispatcher, Raycaster, Intersection, Group, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points } from 'three';
3
3
  import * as nodeCanvas from 'canvas';
4
4
  import { ImageData as ImageData$1, CanvasRenderingContext2D } from 'canvas';
5
5
  import { Buffer } from 'buffer';
@@ -1422,6 +1422,12 @@ declare class DisplayTransforms {
1422
1422
  static withHandFallbacks(display: Model["display"]): Model["display"];
1423
1423
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1424
1424
  static getMatrix(display: Model["display"], position: DisplayPosition): Matrix4;
1425
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1426
+ static getTransform(display: Model["display"], position: DisplayPosition): {
1427
+ position: Vector3;
1428
+ quaternion: Quaternion;
1429
+ scale: Vector3;
1430
+ };
1425
1431
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1426
1432
  static apply(geometry: BufferGeometry, matrix: Matrix4): void;
1427
1433
  }
@@ -1,5 +1,5 @@
1
1
  import * as three from 'three';
2
- import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, ShaderMaterial, Texture, Camera, MOUSE, TOUCH, Controls, WebGLRenderer, EventDispatcher, Raycaster, Intersection, Group, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points } from 'three';
2
+ import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Quaternion, Box2, Scene, Object3DEventMap, ShaderMaterial, Texture, Camera, MOUSE, TOUCH, Controls, WebGLRenderer, EventDispatcher, Raycaster, Intersection, Group, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points } from 'three';
3
3
  import * as nodeCanvas from 'canvas';
4
4
  import { ImageData as ImageData$1, CanvasRenderingContext2D } from 'canvas';
5
5
  import { Buffer } from 'buffer';
@@ -1422,6 +1422,12 @@ declare class DisplayTransforms {
1422
1422
  static withHandFallbacks(display: Model["display"]): Model["display"];
1423
1423
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1424
1424
  static getMatrix(display: Model["display"], position: DisplayPosition): Matrix4;
1425
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1426
+ static getTransform(display: Model["display"], position: DisplayPosition): {
1427
+ position: Vector3;
1428
+ quaternion: Quaternion;
1429
+ scale: Vector3;
1430
+ };
1425
1431
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1426
1432
  static apply(geometry: BufferGeometry, matrix: Matrix4): void;
1427
1433
  }
@@ -1479,6 +1479,11 @@ var init_DisplayTransforms = __esm({
1479
1479
  }
1480
1480
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1481
1481
  static getMatrix(display, position) {
1482
+ const transform = this.getTransform(display, position);
1483
+ return new import_three7.Matrix4().compose(transform.position, transform.quaternion, transform.scale);
1484
+ }
1485
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1486
+ static getTransform(display, position) {
1482
1487
  const transform = this.withHandFallbacks(display)?.[position] ?? {};
1483
1488
  const left = position === "firstperson_lefthand" /* FIRSTPERSON_LEFTHAND */ || position === "thirdperson_lefthand" /* THIRDPERSON_LEFTHAND */;
1484
1489
  const sign = left ? -1 : 1;
@@ -1487,7 +1492,7 @@ var init_DisplayTransforms = __esm({
1487
1492
  const translation = new import_three7.Vector3(...transform.translation ?? [0, 0, 0]).clampScalar(-80, 80);
1488
1493
  translation.x *= sign;
1489
1494
  const scale = new import_three7.Vector3(...transform.scale ?? [1, 1, 1]).clampScalar(-4, 4);
1490
- return new import_three7.Matrix4().compose(translation, rotation, scale);
1495
+ return { position: translation, quaternion: rotation, scale };
1491
1496
  }
1492
1497
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1493
1498
  static apply(geometry, matrix) {
@@ -7007,16 +7012,21 @@ var init_ModelObject = __esm({
7007
7012
  const special = this.originalModel.special;
7008
7013
  if (special) {
7009
7014
  const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
7010
- const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three27.Matrix4();
7011
- transform.multiply(new import_three27.Matrix4().makeTranslation(-8, -8, -8));
7015
+ const display = new SceneObject();
7016
+ if (this.options.displayPosition) {
7017
+ const transform = DisplayTransforms.getTransform(this.originalModel.display, this.options.displayPosition);
7018
+ display.position.copy(transform.position);
7019
+ display.quaternion.copy(transform.quaternion);
7020
+ display.scale.copy(transform.scale);
7021
+ }
7022
+ this.add(display);
7023
+ const offset = new import_three27.Matrix4().makeTranslation(-8, -8, -8);
7012
7024
  try {
7013
7025
  const targets = [];
7014
7026
  for (const part of parts2) {
7015
7027
  const object4 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints, faces: part.faces });
7016
- object4.matrix.copy(transform).multiply(part.transform);
7017
- object4.matrixWorldNeedsUpdate = true;
7018
- object4.matrixAutoUpdate = false;
7019
- this.add(object4);
7028
+ object4.matrix.multiplyMatrices(offset, part.transform).decompose(object4.position, object4.quaternion, object4.scale);
7029
+ display.add(object4);
7020
7030
  await object4.init(part.material);
7021
7031
  object4.iterateAllMeshes((mesh) => {
7022
7032
  const source = mesh.material;