bambu-printer-mcp 1.1.40 → 1.1.41

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.
@@ -1823,22 +1823,23 @@ export class STLManipulator extends EventEmitter {
1823
1823
  throw new Error("Operation cancelled");
1824
1824
  if (progressCallback)
1825
1825
  progressCallback(75, "Finding largest flat surface...");
1826
- // Find the group with the largest total area (excluding near-vertical faces)
1826
+ // Include already-horizontal faces: excluding Z-aligned normals can
1827
+ // stand a flat model on its edge, including on a repeated layFlat call.
1827
1828
  let largestArea = 0;
1828
1829
  let targetNormal = null;
1829
- const upVector = new THREE.Vector3(0, 1, 0); // Assuming Y is up for most models initially?
1830
1830
  const downVector = new THREE.Vector3(0, 0, -1); // Target normal (pointing down)
1831
+ // Faces are grouped by direction, so a part whose flat faces are all
1832
+ // horizontal has equal up- and down-facing areas. On a tie, keep the
1833
+ // face that already points down so a seated part is not flipped.
1831
1834
  for (const group of normalGroups.values()) {
1832
- // Check if the normal is reasonably horizontal (not too close to vertical Z)
1833
- // Angle threshold could be adjusted (e.g., > 5 degrees from Z axis)
1834
- if (Math.abs(group.representativeNormal.z) < 0.99 && group.totalArea > largestArea) {
1835
+ const tied = targetNormal !== null && Math.abs(group.totalArea - largestArea) <= largestArea * 1e-6;
1836
+ if (tied ? group.representativeNormal.z < targetNormal.z : group.totalArea > largestArea) {
1835
1837
  largestArea = group.totalArea;
1836
1838
  targetNormal = group.representativeNormal;
1837
1839
  }
1838
1840
  }
1839
1841
  if (!targetNormal) {
1840
- // If no suitable horizontal face found, maybe pick the lowest Z face?
1841
- // For now, throw an error or return unchanged.
1842
+ // Only a mesh without any face area reaches this.
1842
1843
  console.warn("Could not find a suitable large flat face to lay down. No changes made.");
1843
1844
  this.emit('operationComplete', { operationId, type: 'layFlat', success: true, output: stlFilePath, message: "No suitable flat face found." });
1844
1845
  return stlFilePath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -2255,24 +2255,25 @@ export class STLManipulator extends EventEmitter {
2255
2255
  if (!this.activeOperations.get(operationId)) throw new Error("Operation cancelled");
2256
2256
  if (progressCallback) progressCallback(75, "Finding largest flat surface...");
2257
2257
 
2258
- // Find the group with the largest total area (excluding near-vertical faces)
2258
+ // Include already-horizontal faces: excluding Z-aligned normals can
2259
+ // stand a flat model on its edge, including on a repeated layFlat call.
2259
2260
  let largestArea = 0;
2260
2261
  let targetNormal: THREE.Vector3 | null = null;
2261
- const upVector = new THREE.Vector3(0, 1, 0); // Assuming Y is up for most models initially?
2262
2262
  const downVector = new THREE.Vector3(0, 0, -1); // Target normal (pointing down)
2263
2263
 
2264
+ // Faces are grouped by direction, so a part whose flat faces are all
2265
+ // horizontal has equal up- and down-facing areas. On a tie, keep the
2266
+ // face that already points down so a seated part is not flipped.
2264
2267
  for (const group of normalGroups.values()) {
2265
- // Check if the normal is reasonably horizontal (not too close to vertical Z)
2266
- // Angle threshold could be adjusted (e.g., > 5 degrees from Z axis)
2267
- if (Math.abs(group.representativeNormal.z) < 0.99 && group.totalArea > largestArea) {
2268
+ const tied = targetNormal !== null && Math.abs(group.totalArea - largestArea) <= largestArea * 1e-6;
2269
+ if (tied ? group.representativeNormal.z < targetNormal!.z : group.totalArea > largestArea) {
2268
2270
  largestArea = group.totalArea;
2269
2271
  targetNormal = group.representativeNormal;
2270
2272
  }
2271
2273
  }
2272
2274
 
2273
2275
  if (!targetNormal) {
2274
- // If no suitable horizontal face found, maybe pick the lowest Z face?
2275
- // For now, throw an error or return unchanged.
2276
+ // Only a mesh without any face area reaches this.
2276
2277
  console.warn("Could not find a suitable large flat face to lay down. No changes made.");
2277
2278
  this.emit('operationComplete', { operationId, type: 'layFlat', success: true, output: stlFilePath, message: "No suitable flat face found." });
2278
2279
  return stlFilePath;