Skip to content

Commit 4443adf

Browse files
committed
Fix bounding box position
1 parent b59656a commit 4443adf

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/bounding-box.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,14 @@ export class BoundingBox {
6363
z: this.minZ + (this.maxZ - this.minZ) / 2
6464
};
6565
}
66+
67+
public get corners(): { min: { x: number; y: number; z: number }; max: { x: number; y: number; z: number } } {
68+
if (!this.isValid) {
69+
return null;
70+
}
71+
return {
72+
min: { x: this.minX, y: this.minY, z: this.minZ },
73+
max: { x: this.maxX, y: this.maxY, z: this.maxZ }
74+
};
75+
}
6676
}

src/webgl-preview.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ export class WebGLPreview {
827827
}
828828

829829
if (this.job && this.job.boundingBox.isValid && this._buildVolume) {
830-
// Added check for this._buildVolume
831830
const bb = this.job.boundingBox;
832831
const size = bb.size;
833832
const center = bb.center;
@@ -843,10 +842,11 @@ export class WebGLPreview {
843842
// Three.js X position = G-code X center - (Build Volume X / 2)
844843
// Three.js Y position = G-code Z center (since Three.js Y is up, and LineBox handles its own Y-offset)
845844
// Three.js Z position = G-code Y center - (Build Volume Y / 2)
845+
const pos = bb.corners.min;
846846
this.boundingBoxMesh.position.set(
847-
center.x - this._buildVolume.x / 2,
848-
center.z, // Three.js Y (G-code Z)
849-
-(center.y - this._buildVolume.y / 2) // Three.js Z (G-code Y)
847+
pos.x,
848+
0,
849+
-pos.y
850850
);
851851

852852
this.scene.add(this.boundingBoxMesh);

0 commit comments

Comments
 (0)