Skip to content

Commit 81cf9a3

Browse files
committed
fix: solid
1 parent 5b0490b commit 81cf9a3

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/lib/3d/Solid.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ export class Solid {
198198
if (wedgePoints.length === 0) return fullCylinder;
199199

200200
// Create wedge prism (make it taller to ensure complete cut)
201-
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color })
202-
.rotate({ x: 90 })
203-
.move({ y: height * 0.75 }); // Center wedge on Y-axis
201+
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color }).move({
202+
y: height * 0.75
203+
}); // Center wedge on Y-axis
204204

205205
// Subtract wedge from cylinder to create closed partial geometry
206206
return Solid.SUBTRACT(fullCylinder, wedgeCutter);
@@ -241,9 +241,9 @@ export class Solid {
241241
if (wedgePoints.length === 0) return fullSphere;
242242

243243
// Create wedge prism tall enough to cut through entire sphere diameter
244-
const wedgeCutter = this.profilePrismFromPoints(radius * 4, wedgePoints, { color })
245-
.rotate({ x: 90 }) // Rotate to align with sphere
246-
.move({ y: radius * 2 }); // Center wedge on Y-axis
244+
const wedgeCutter = this.profilePrismFromPoints(radius * 4, wedgePoints, { color }).move({
245+
y: radius * 2
246+
}); // Center wedge on Y-axis
247247

248248
// Subtract wedge from sphere to create closed partial geometry
249249
return Solid.SUBTRACT(fullSphere, wedgeCutter);
@@ -291,9 +291,9 @@ export class Solid {
291291
if (wedgePoints.length === 0) return fullCone;
292292

293293
// Create wedge prism (make it taller to ensure complete cut)
294-
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color })
295-
.rotate({ x: 90 })
296-
.move({ y: height * 0.75 }); // Center wedge on Y-axis
294+
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color }).move({
295+
y: height * 0.75
296+
}); // Center wedge on Y-axis
297297

298298
// Subtract wedge from cone to create closed partial geometry
299299
return Solid.SUBTRACT(fullCone, wedgeCutter);
@@ -351,9 +351,9 @@ export class Solid {
351351
if (wedgePoints.length === 0) return fullPrism;
352352

353353
// Create wedge prism (make it taller to ensure complete cut)
354-
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color })
355-
.rotate({ x: 90 })
356-
.move({ y: height * 0.75 }); // Center wedge on Y-axis
354+
const wedgeCutter = this.profilePrismFromPoints(height * 1.5, wedgePoints, { color }).move({
355+
y: height * 0.75
356+
}); // Center wedge on Y-axis
357357

358358
// Subtract wedge from prism to create closed partial geometry
359359
return Solid.SUBTRACT(fullPrism, wedgeCutter);
@@ -404,7 +404,8 @@ export class Solid {
404404
steps: 1
405405
});
406406

407-
return new Solid(this.geometryToBrush(geometry), color).normalize();
407+
// Rotate so extrusion direction (Z-axis) becomes height (Y-axis)
408+
return new Solid(this.geometryToBrush(geometry), color).normalize().rotate({ x: 90 });
408409
};
409410

410411
/**
@@ -665,9 +666,9 @@ export class Solid {
665666
// Create wedge prism (make it taller to ensure complete cut through entire profile)
666667
// The wedge needs to extend through the entire height range of the profile
667668
const wedgeHeight = Math.max(profileHeight * 2, maxRadius * 4);
668-
const wedgeCutter = this.profilePrismFromPoints(wedgeHeight, wedgePoints, { color })
669-
.rotate({ x: 90 }) // Rotate to align with Y-axis (revolution axis)
670-
.move({ y: profileCenter + wedgeHeight / 2 }); // Center the wedge on the profile (rotation makes extrusion go negative, so add half height)
669+
const wedgeCutter = this.profilePrismFromPoints(wedgeHeight, wedgePoints, { color }).move({
670+
y: profileCenter + wedgeHeight / 2
671+
}); // Center the wedge on the profile
671672

672673
// Subtract wedge from full revolution to create closed partial geometry
673674
return Solid.SUBTRACT(fullRevolution, wedgeCutter);

src/lib/3d/stl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { writeFloatLE, writeInt16LE, writeInt32LE } from '$lib/buffer';
22

3-
export const getBinaryStlSizeKbFromVertices = (verticesLength: number) =>
4-
Math.round((80 + 4 + 50 * (verticesLength / 9)) / 1024);
3+
export const getBinaryStlSizeKbFromVertices = (vertices: Float32Array) =>
4+
(80 + 4 + 50 * (vertices.length / 9)) / 1024;
55

66
export const generateBinaryStlFromVertices = (vertices: Float32Array): Uint8Array => {
7+
// Validate input: vertices array cannot be empty
8+
if (vertices.length === 0) throw new Error('Vertices array cannot be empty');
9+
710
// Validate input: vertices array must contain complete triangles (9 values per triangle)
8-
if (vertices.length % 9 !== 0)
9-
throw new Error(
10-
`Invalid vertices array: length must be divisible by 9 (got ${vertices.length})`
11-
);
11+
if (vertices.length % 9 !== 0) throw new Error('Vertices length must be divisible by 9');
1212

1313
const buffer = new Uint8Array(80 + 4 + 50 * (vertices.length / 9));
1414

0 commit comments

Comments
 (0)