Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"name": "shapeitup",
"description": "CAD scripting toolkit: create/modify .shape.ts files, validate geometry, check collisions, export STEP/STL/3MF via Replicad + OpenCascade. Runs headless; live 3D preview available if the ShapeItUp VS Code extension is installed.",
"version": "1.30.1",
"version": "1.30.2",
"author": {
"name": "Asbjorn Rorvik",
"email": "rorvik.asbjorn@gmail.com"
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ Releases 1.17.0–1.24.0 are described only in their
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the
project follows semantic versioning at the extension level.

## [1.30.2] - 2026-10-22

Extension `1.30.2` / mcp-server `1.30.2` — a centre of mass is only reported
when it was measured.

### Fixed
- **The bounding-box centre was reported as the centre of mass.** Without a
declared material, renders skip OCCT measurement, and core then filled
each part's `centerOfMass` with its bounding-box centre. `create_shape` and
`get_render_status` printed that as `CoM=`: an L-bracket showed
`CoM=(0.00, 0.00, 17.50)` against a true `(0, -7.5, 10)`, so an agent
working out tipping or balance got a wrong answer that looked measured.
`centerOfMass` is now only set when the part was measured (a declared
`material`, or `partStats: "full"`). Otherwise the per-part row reads
`bbox centre=(…)`, and the viewer's parts panel shows "Bounds center" from
`boundsCenter`. The assembly centre of mass is unchanged. It is weighted
by measured volume, so it never included the estimate.

## [1.30.1] - 2026-10-12

Extension `1.30.1` / mcp-server `1.30.1` — Codex setup docs and three fixes.
Expand Down
33 changes: 14 additions & 19 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ export interface Core {
meshQuality?: MeshQuality;
/**
* Issue #6: how much per-part measurement to do. Default is `"bbox"` —
* fast CoM from the AABB centre, volume / surfaceArea omitted. Pass
* no measurement, so volume / surfaceArea / centerOfMass are omitted
* (the AABB centre is always on `boundsCenter`). Pass
* `"full"` only when the caller actually needs the OCCT-measured
* numbers (e.g. an aggregator computing total mass / CoM).
*/
Expand Down Expand Up @@ -1344,9 +1345,9 @@ export async function initCore(
(shouldAutoDegrade ? "preview" : "final");
// Issue #6: gate per-part B-Rep measurement. On a 14-part assembly the
// two measureShape*Properties calls together spent ~2.5 s on the hot
// path. Default `"bbox"` skips both and derives centerOfMass from the
// AABB centre — that's still a useful approximation for assembly
// aggregation, and per-part volume/surfaceArea rarely gets consumed.
// path. Default `"bbox"` skips both, so volume / surfaceArea /
// centerOfMass stay unmeasured — per-part volume/surfaceArea rarely gets
// consumed, and a guessed centre of mass is worse than none.
// A declared material — script-level `export const material` OR a per-part
// `material` on any returned part — is an explicit opt-in to mass
// reporting, and mass needs the OCCT-measured volume that only "full"
Expand Down Expand Up @@ -1423,22 +1424,16 @@ export async function initCore(
if (effectiveMaterial && typeof t.volume === "number") {
t.mass = (effectiveMaterial.density * t.volume) / 1000;
}
} else if (partStats === "bbox") {
// Cheap CoM: use the shape's AABB centre (O(1), no OCCT measure).
// volume / surfaceArea / mass stay omitted — callers who need
// exact numbers pass partStats: "full". Fall through silently if
// the shape has no usable bbox (MeshShape duck-type, test mocks).
const bounds = readBoundsSafe(shape);
if (bounds) {
t.centerOfMass = [
(bounds[0][0] + bounds[1][0]) / 2,
(bounds[0][1] + bounds[1][1]) / 2,
(bounds[0][2] + bounds[1][2]) / 2,
];
}
}
// partStats === "none": nothing to do. volume/surfaceArea/mass/CoM
// all stay undefined on the emitted part.
// partStats "bbox" / "none": nothing to measure. volume/surfaceArea/
// mass/centerOfMass all stay undefined on the emitted part.
//
// "bbox" used to fill centerOfMass with the AABB centre. That is not a
// centre of mass for anything asymmetric (an L-bracket's reads
// (0, 0, 17.5) against a true (0, -7.5, 10)), and every consumer
// printed it as one, so an agent reasoning about tipping got a wrong
// answer with no hint that it was a guess. The bbox centre is still on
// the part as `boundsCenter`, which tessellatePart sets at every level.

// Face descriptors for viewer picking. Deliberately NOT gated on
// partStats: that knob trades measurement cost against BOM numbers,
Expand Down
24 changes: 16 additions & 8 deletions packages/core/src/tessellate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,19 @@ export interface TessellatedPart {
edgeGroups?: Uint32Array;
volume?: number;
surfaceArea?: number;
/**
* The measured centroid — only set at `partStats: "full"` (OCCT's volume
* properties, or tetrahedron integration of the mesh for a MeshShape).
* Never an estimate: when nothing was measured this is undefined, and the
* bounding-box centre is on {@link boundsCenter} instead.
*/
centerOfMass?: [number, number, number];
/**
* The centre of the OCCT bounding box — exactly what `shape.boundingBox.center`
* evaluates to in a user's script.
* evaluates to in a user's script. Set at every `partStats` level.
*
* Distinct from `centerOfMass`, which is the true centroid when the part was
* measured in full and only falls back to this. The viewer's Rotate command
* Distinct from `centerOfMass`, which is the true centroid and is only there
* when the part was measured in full. The viewer's Rotate command
* needs the value the FILE will compute, not the one that is geometrically
* nicer, because the pivot it writes is that expression.
*/
Expand Down Expand Up @@ -420,10 +426,12 @@ export interface FaceInfo {
* from the emitted part. Cheapest; use when the caller only needs geometry
* for rendering.
*
* `"bbox"` (default) — still skip the two OCCT measurement calls, but derive
* a centerOfMass from the shape's bounding-box centre so assemblies get a
* usable aggregate CoM without paying the ~200 ms/part B-Rep cost. volume /
* surfaceArea stay omitted.
* `"bbox"` (default) — skip the two OCCT measurement calls; volume /
* surfaceArea / centerOfMass stay omitted. The bounding-box centre is still
* reported, as `boundsCenter` (every level gets it), and never as a
* centerOfMass: on an L-bracket the two are 10.6 mm apart. Today
* this measures exactly as little as `"none"`; the name is kept because
* callers pass it.
*
* `"full"` — pre-partStats behaviour: call both measurement functions and
* populate volume / surfaceArea / centerOfMass (plus mass if a material is
Expand Down Expand Up @@ -462,7 +470,7 @@ export interface TessellateOptions {
* `tessellatePart` itself (which never calls measureShape*Properties) —
* co-located here so callers configure all tess-time policy in one place.
* Default is `"bbox"` (issue #6: skip 2.5 s of B-Rep measurement on a
* 14-part assembly; derive CoM from the AABB centre instead).
* 14-part assembly; volume / CoM are then simply not reported).
*/
partStats?: PartStatsLevel;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "shapeitup-vscode",
"displayName": "ShapeItUp",
"description": "Scripted CAD for VS Code — write TypeScript, see 3D, export STEP/STL/3MF (Bambu Studio & OrcaSlicer ready). AI-powered with Claude Code MCP integration.",
"version": "1.30.1",
"version": "1.30.2",
"publisher": "shapeitup",
"license": "MIT",
"icon": "icon.png",
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeitup/mcp-server",
"version": "1.30.1",
"version": "1.30.2",
"description": "ShapeItUp MCP server — scripted CAD tools (Replicad/OpenCascade) for Claude Code, Codex, Cursor, Claude Desktop, and other MCP clients.",
"type": "module",
"bin": {
Expand Down
5 changes: 5 additions & 0 deletions packages/mcp-server/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ export interface ShapeProperties {
name: string;
volume?: number;
surfaceArea?: number;
/**
* Measured centroid. Present only when core measured the part
* (`partStats: "full"`, which a declared material implies) — never the
* bounding-box centre, which is `boundingBox.min`/`max`'s midpoint.
*/
centerOfMass?: [number, number, number];
/**
* Per-part bounding box. `x`/`y`/`z` remain the SIZE along each axis (back
Expand Down
67 changes: 66 additions & 1 deletion packages/mcp-server/src/tools.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { describe, it, expect } from "vitest";
import { validateSyntaxPure, detectPathDoubling, detectPathDoublingInfo, extractSignatures, safeHandler, computePartsLine, computeEffectiveMeshQuality, formatCollisionPairs, formatSweepCollisions, formatLastScreenshotLine, registerTools, getVersionTag, getViewerStatus, formatViewerBlock, partExtendsBelowBed, formatStatusText, workspaceMismatchWarning, type CollisionEntry, type SweepCollisionEntry } from "./tools.js";
import type { EngineStatus } from "./engine.js";
import { executeShapeFile, type EngineStatus } from "./engine.js";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

// ---------------------------------------------------------------------------
// Bug #6 — validate_syntax must trust .method() calls whose receiver was
Expand Down Expand Up @@ -1502,6 +1505,68 @@ describe("formatStatusText — geometry warning dedup", () => {
});
});

// An L-bracket's bounding-box centre is (0, 0, 17.5); its centre of mass is
// (0, -7.5, 10). The default render used to print the first as `CoM=`, which
// sends an agent reasoning about tipping or balance the wrong way. The second
// part is only there because per-part rows print for assemblies.
describe("formatStatusText — a centre of mass is only claimed when measured", () => {
const BRACKET = [
`import { drawRectangle, drawCircle } from "replicad";`,
`export default function main() {`,
` const base = drawRectangle(60, 40).sketchOnPlane("XY").extrude(5);`,
` const wall = drawRectangle(60, 5).sketchOnPlane("XY").extrude(35).translate(0, -17.5, 0);`,
` const pin = drawCircle(2).sketchOnPlane("XY").extrude(10).translate(0, 10, 5);`,
` return [`,
` { shape: base.fuse(wall), name: "bracket" },`,
` { shape: pin, name: "pin" },`,
` ];`,
`}`,
].join("\n");

const run = async (partStats?: "full") => {
const workdir = mkdtempSync(join(tmpdir(), "siu-com-"));
const storage = mkdtempSync(join(tmpdir(), "siu-com-storage-"));
try {
const entry = join(workdir, "bracket.shape.ts");
writeFileSync(entry, BRACKET);
const { status } = await executeShapeFile(entry, storage, undefined, partStats ? { partStats } : undefined);
expect(status.success).toBe(true);
return { status, text: formatStatusText(status) };
} finally {
rmSync(workdir, { recursive: true, force: true });
rmSync(storage, { recursive: true, force: true });
}
};

it("labels the bounding-box centre as such in a default render", async () => {
const { status, text } = await run();
const bracket = status.properties!.parts!.find((p) => p.name === "bracket")!;
expect(bracket.centerOfMass).toBeUndefined();
expect(status.properties!.centerOfMass).toBeUndefined();
expect(text).not.toContain("CoM=");
expect(text).not.toContain("center of mass");
expect(text).toMatch(/- bracket: .*bbox centre=\(0\.00, 0\.00, 17\.50\)/);
}, 60_000);

it("still reports the measured centre of mass, per part and aggregated, at partStats full", async () => {
const { status, text } = await run("full");
const bracket = status.properties!.parts!.find((p) => p.name === "bracket")!;
const [x, y, z] = bracket.centerOfMass!;
expect(x).toBeCloseTo(0, 3);
expect(y).toBeCloseTo(-7.5, 3);
expect(z).toBeCloseTo(10, 3);
// OCCT's x comes back as a hair below zero, so it prints "-0.00".
expect(text).toMatch(/- bracket: .*CoM=\(-?0\.00, -7\.50, 10\.00\)/);
expect(text).not.toContain("bbox centre");

// Volume-weighted over both bodies: 21000 mm³ at y = -7.5, a 2 mm pin at y = 10.
const pinVolume = Math.PI * 2 * 2 * 10;
const aggregate = status.properties!.centerOfMass!;
expect(aggregate[1]).toBeCloseTo((21000 * -7.5 + pinVolume * 10) / (21000 + pinVolume), 3);
expect(text).toContain("center of mass:");
}, 60_000);
});

describe("workspaceMismatchWarning — relative-dir routed to wrong workspace", () => {
const base = {
directory: "examples/wall-organizer",
Expand Down
9 changes: 8 additions & 1 deletion packages/mcp-server/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5287,7 +5287,7 @@ export function registerTools(server: McpServer) {

server.tool(
"get_render_status",
"Get the result of the last shape render — whether it succeeded or failed, with stats, geometric properties (volume, area, center of mass, mass when material is exported), and bounding box. Reads the shared status file, which both MCP-driven and VSCode-driven renders write to. Includes currentParams — the resolved values of every exported param, so you don't need to re-read the file to inspect parameter state. For multi-part assemblies, returns per-part stats (name, volume, surface area, center of mass, bounding box, mass) — no separate list_parts tool needed.",
"Get the result of the last shape render — whether it succeeded or failed, with stats, geometric properties, and bounding box. Volume, area, center of mass and mass are measured only when the script exports a material; without one they are omitted, never estimated. Reads the shared status file, which both MCP-driven and VSCode-driven renders write to. Includes currentParams — the resolved values of every exported param, so you don't need to re-read the file to inspect parameter state. For multi-part assemblies, returns per-part stats (name, volume, surface area, center of mass, bounding box, mass; the bounding-box centre when no center of mass was measured) — no separate list_parts tool needed.",
{},
safeHandler("get_render_status", async () => {
const statusFile = join(GLOBAL_STORAGE, "shapeitup-status.json");
Expand Down Expand Up @@ -7305,6 +7305,13 @@ function formatProperties(
if (typeof p.mass === "number") bits.push(`mass=${fmt(p.mass)}g`);
if (p.centerOfMass) bits.push(`CoM=${fmtPt(p.centerOfMass)}`);
if (p.boundingBox) bits.push(`bbox=${fmt(p.boundingBox.x)}x${fmt(p.boundingBox.y)}x${fmt(p.boundingBox.z)}`);
// Where the part sits, for when nothing was measured. Named for what it
// is: on an L-bracket it is 10.6 mm from the real centre of mass, and it
// used to be printed as `CoM=`.
const { min, max } = p.boundingBox ?? {};
if (!p.centerOfMass && min && max) {
bits.push(`bbox centre=${fmtPt([(min[0] + max[0]) / 2, (min[1] + max[1]) / 2, (min[2] + max[2]) / 2])}`);
}
if (bits.length) lines.push(` - ${p.name}: ${bits.join(", ")}`);
// Printability: only surface the section when there's actually a
// concern — clean parts (manifold + feature ≥ nozzle) stay silent so
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ export interface TessellatedPart {
*/
boundsCenter?: [number, number, number];
// Geometric properties computed from the original OCCT shape (not the mesh).
// Optional because measurement can fail on degenerate geometry.
// Only present when the core measured the part (`partStats: "full"`, which a
// declared material implies), and even then measurement can fail on
// degenerate geometry. centerOfMass is never a bounding-box estimate — that
// is `boundsCenter`.
volume?: number;
surfaceArea?: number;
centerOfMass?: [number, number, number];
Expand Down
23 changes: 14 additions & 9 deletions packages/viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ interface PartInfo {
* the point the written expression will.
*/
boundsCenter?: [number, number, number];
/** Measured on the OCCT shape, not the mesh. Absent on degenerate geometry. */
/**
* Measured on the OCCT shape, not the mesh. Absent unless the core measured
* the part (a declared material), or when measurement failed.
*/
volume?: number;
surfaceArea?: number;
centerOfMass?: [number, number, number];
Expand Down Expand Up @@ -3180,7 +3183,8 @@ function updatePartsList() {
const hasStats =
part.volume !== undefined ||
part.surfaceArea !== undefined ||
part.centerOfMass !== undefined;
part.centerOfMass !== undefined ||
part.boundsCenter !== undefined;

const row = document.createElement("div");
const armed =
Expand Down Expand Up @@ -3234,14 +3238,15 @@ function updatePartsList() {
};
if (part.volume !== undefined) addProp("Volume", formatVolume(part.volume));
if (part.surfaceArea !== undefined) addProp("Surface", formatArea(part.surfaceArea));
if (part.centerOfMass) {
// Which centre this is depends on how the part was measured. Without
// volume the core took the cheap path and this is the bounding-box
// centre, which is NOT the centre of mass for anything asymmetric.
// Labelling both "Center" would quietly overstate one of them.
// The core only sets centerOfMass when it measured one; otherwise the
// nearest thing it has is the bounding-box centre, which is NOT the centre
// of mass for anything asymmetric. Labelling both "Center" would quietly
// overstate one of them.
const centre = part.centerOfMass ?? part.boundsCenter;
if (centre) {
addProp(
part.volume === undefined ? "Bounds center" : "Center of mass",
part.centerOfMass.map((n) => formatNum(n, 1)).join(", "),
part.centerOfMass ? "Center of mass" : "Bounds center",
centre.map((n) => formatNum(n, 1)).join(", "),
true,
);
}
Expand Down
2 changes: 1 addition & 1 deletion skills/shapeitup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ return [
];
```

Each part gets its own color in the viewer and becomes a named component in STEP files. Per-part stats (volume, surface area, CoM, bbox, mass) are returned by `get_render_status`.
Each part gets its own color in the viewer and becomes a named component in STEP files. Per-part stats (volume, surface area, CoM, bbox, mass) are returned by `get_render_status`. Volume, area, CoM and mass are measured only when the file exports a `material`; without one a part reports just its bbox and `bbox centre`, which is not its centre of mass.

Mark mockup / reference parts with `analyze: false` to suppress printability and minFeature warnings for geometry you won't fabricate (motors, pre-bought tubes, collision-check stand-ins):

Expand Down