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';
@@ -1424,6 +1424,12 @@ declare class DisplayTransforms {
1424
1424
  static withHandFallbacks(display: Model["display"]): Model["display"];
1425
1425
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1426
1426
  static getMatrix(display: Model["display"], position: DisplayPosition): Matrix4;
1427
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1428
+ static getTransform(display: Model["display"], position: DisplayPosition): {
1429
+ position: Vector3;
1430
+ quaternion: Quaternion;
1431
+ scale: Vector3;
1432
+ };
1427
1433
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1428
1434
  static apply(geometry: BufferGeometry, matrix: Matrix4): void;
1429
1435
  }
@@ -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';
@@ -1424,6 +1424,12 @@ declare class DisplayTransforms {
1424
1424
  static withHandFallbacks(display: Model["display"]): Model["display"];
1425
1425
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1426
1426
  static getMatrix(display: Model["display"], position: DisplayPosition): Matrix4;
1427
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1428
+ static getTransform(display: Model["display"], position: DisplayPosition): {
1429
+ position: Vector3;
1430
+ quaternion: Quaternion;
1431
+ scale: Vector3;
1432
+ };
1427
1433
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1428
1434
  static apply(geometry: BufferGeometry, matrix: Matrix4): void;
1429
1435
  }
@@ -1535,6 +1535,11 @@ var init_DisplayTransforms = __esm({
1535
1535
  }
1536
1536
  /** Build a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1537
1537
  static getMatrix(display, position) {
1538
+ const transform = this.getTransform(display, position);
1539
+ return new import_three7.Matrix4().compose(transform.position, transform.quaternion, transform.scale);
1540
+ }
1541
+ /** Position, rotation, and scale of a display pose for geometry already centered at the model's [8, 8, 8] pivot. */
1542
+ static getTransform(display, position) {
1538
1543
  const transform = this.withHandFallbacks(display)?.[position] ?? {};
1539
1544
  const left = position === "firstperson_lefthand" /* FIRSTPERSON_LEFTHAND */ || position === "thirdperson_lefthand" /* THIRDPERSON_LEFTHAND */;
1540
1545
  const sign = left ? -1 : 1;
@@ -1543,7 +1548,7 @@ var init_DisplayTransforms = __esm({
1543
1548
  const translation = new import_three7.Vector3(...transform.translation ?? [0, 0, 0]).clampScalar(-80, 80);
1544
1549
  translation.x *= sign;
1545
1550
  const scale = new import_three7.Vector3(...transform.scale ?? [1, 1, 1]).clampScalar(-4, 4);
1546
- return new import_three7.Matrix4().compose(translation, rotation, scale);
1551
+ return { position: translation, quaternion: rotation, scale };
1547
1552
  }
1548
1553
  /** Transforms geometry in place and reverses triangle winding when the matrix reflects it. */
1549
1554
  static apply(geometry, matrix) {
@@ -7109,16 +7114,21 @@ var init_ModelObject = __esm({
7109
7114
  const special = this.originalModel.special;
7110
7115
  if (special) {
7111
7116
  const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
7112
- const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three27.Matrix4();
7113
- transform.multiply(new import_three27.Matrix4().makeTranslation(-8, -8, -8));
7117
+ const display = new SceneObject();
7118
+ if (this.options.displayPosition) {
7119
+ const transform = DisplayTransforms.getTransform(this.originalModel.display, this.options.displayPosition);
7120
+ display.position.copy(transform.position);
7121
+ display.quaternion.copy(transform.quaternion);
7122
+ display.scale.copy(transform.scale);
7123
+ }
7124
+ this.add(display);
7125
+ const offset = new import_three27.Matrix4().makeTranslation(-8, -8, -8);
7114
7126
  try {
7115
7127
  const targets = [];
7116
7128
  for (const part of parts2) {
7117
7129
  const object4 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints, faces: part.faces });
7118
- object4.matrix.copy(transform).multiply(part.transform);
7119
- object4.matrixWorldNeedsUpdate = true;
7120
- object4.matrixAutoUpdate = false;
7121
- this.add(object4);
7130
+ object4.matrix.multiplyMatrices(offset, part.transform).decompose(object4.position, object4.quaternion, object4.scale);
7131
+ display.add(object4);
7122
7132
  await object4.init(part.material);
7123
7133
  object4.iterateAllMeshes((mesh) => {
7124
7134
  const source = mesh.material;