Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: reject overlapping extrude holes and closed tube paths that cannot enclose a loop (#3350)

[._.]/ Adam Eivy37fa4e4a394d
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 09abfc1117..1da9ed6c2c 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -160,4 +160,4 @@
## Three.js Models
-- **[issue-3350] Silhouettes with cutouts, bent details, and glass/cloth finishes no longer have to degrade into a coarse triangle mesh.** The scene schema could express primitives, a lathe, and a bounded custom mesh, so anything with a keyhole, a vent, a cable, or a bent handle either got flattened into a box stack or spent its budget on hand-authored triangles. Two schema-backed forms now cover that gap: `extrude` sweeps a closed 2D outline — with optional hole rings — to a depth with optional bevel, and `tube` sweeps a round profile along a Catmull-Rom path. Both are validated on the way in rather than trusted: a ring that encloses no area, a hole that falls outside its outline, a path that repeats a point consecutively, or a closed path that repeats its first point at the end are all rejected, because each renders as an empty face, a stray disjoint face, or NaN geometry rather than an error. `physical` materials also gained bounded `ior`, `transmission`, `thickness`, `sheen`, `iridescence`, and `anisotropy`, so glass, gems, velvet, oil-slick, and brushed metal are material choices instead of approximations — parsed for every material type so a spec round-trips unchanged, but only handed to Three.js for physical ones. The generation prompt now says which form fits which subject and that custom triangles are the last resort, and the preview builds the new geometry through the same construction the downloaded standalone factory emits.
+- **[issue-3350] Silhouettes with cutouts, bent details, and glass/cloth finishes no longer have to degrade into a coarse triangle mesh.** The scene schema could express primitives, a lathe, and a bounded custom mesh, so anything with a keyhole, a vent, a cable, or a bent handle either got flattened into a box stack or spent its budget on hand-authored triangles. Two schema-backed forms now cover that gap: `extrude` sweeps a closed 2D outline — with optional hole rings — to a depth with optional bevel, and `tube` sweeps a round profile along a Catmull-Rom path. Both are validated on the way in rather than trusted: a ring that encloses no area, a hole that falls outside its outline or overlaps another hole, a path that repeats a point consecutively, and a closed path that repeats its seam or cannot enclose a loop are all rejected, because each renders as an empty face, a stray disjoint face, or NaN geometry rather than an error. `physical` materials also gained bounded `ior`, `transmission`, `thickness`, `sheen`, `iridescence`, and `anisotropy`, so glass, gems, velvet, oil-slick, and brushed metal are material choices instead of approximations — parsed for every material type so a spec round-trips unchanged, but only handed to Three.js for physical ones. The generation prompt now says which form fits which subject and that custom triangles are the last resort, and the preview builds the new geometry through the same construction the downloaded standalone factory emits.
diff --git a/docs/THREEJS_MODELS.md b/docs/THREEJS_MODELS.md
index 980cf364fa..a0c64870f3 100644
--- a/docs/THREEJS_MODELS.md
+++ b/docs/THREEJS_MODELS.md
@@ -36,13 +36,18 @@ and the bounded `custom` triangle mesh, the schema carries two constructive
forms so silhouette-defining shapes don't have to degrade into a coarse mesh:
- `extrude` — a closed 2D outline (3–160 points) with optional hole rings,
- swept to `depth` with optional bevel. Every ring must enclose real area and
- each hole must lie inside the outline, so a degenerate or stray ring is
- rejected instead of rendering as an empty or disjoint face.
+ swept to `depth` with optional bevel. Every ring must enclose real area; each
+ hole must lie strictly inside the outline (point-in-polygon on every vertex
+ plus an edge sweep, since a concave outline's bounding box covers empty space
+ its notch does not); and holes may not touch, cross, or nest. Each of those
+ cases triangulates into an empty face, a disjoint face, or solid material
+ inside a requested cutout rather than failing, so they are rejected up front.
- `tube` — a round profile of `radius` swept along a 2–96 point Catmull-Rom
path. Consecutive points must differ and a `closed` path must not repeat its
first point, because either produces NaN frames in the centripetal/chordal
- parameterizations.
+ parameterizations. A `closed` path also needs three non-collinear points —
+ fewer, or a straight line, closes into a curve that runs out and retraces
+ itself, overlapping the tube with its own surface.
`type: "physical"` materials additionally carry bounded `ior`, `transmission`,
`thickness`, `sheen`, `iridescence`, and `anisotropy` for glass, cloth,
diff --git a/server/lib/threejsModel.js b/server/lib/threejsModel.js
index b97f01c07f..8a056e1f99 100644
--- a/server/lib/threejsModel.js
+++ b/server/lib/threejsModel.js
@@ -120,6 +120,12 @@ const ringsCross = (outer, inner) => {
const ringContainsRing = (outer, inner) =>
inner.every((point) => pointInRing(outer, point)) && !ringsCross(outer, inner);
+// Two holes that touch, cross, or nest are one cutout described twice; the
+// triangulator resolves the doubled winding by leaving material inside them.
+const ringsOverlap = (a, b) => ringsCross(a, b)
+ || b.every((point) => pointInRing(a, point))
+ || a.every((point) => pointInRing(b, point));
+
const outlineRingSchema = z.array(z.tuple([finite, finite])).min(3).max(160)
.refine((ring) => ringArea(ring) > MIN_RING_AREA, 'outline must enclose a non-zero area');
@@ -141,9 +147,32 @@ const extrudeGeometrySchema = z.object({
if (!ringContainsRing(definition.outline, hole)) {
ctx.addIssue({ code: 'custom', message: `extrude hole ${index} falls outside the outline`, path: ['holes', index] });
}
+ for (let other = 0; other < index; other += 1) {
+ if (ringsOverlap(definition.holes[other], hole)) {
+ ctx.addIssue({ code: 'custom', message: `extrude hole ${index} overlaps hole ${other}`, path: ['holes', index] });
+ }
+ }
});
});
+// Exact collinearity only — the epsilon guards float noise, never near-straight
+// paths, which sweep a perfectly good tube.
+const isCollinearPath = (points) => {
+ const [origin] = points;
+ const spread = points.find((point) => point.some((value, axis) => value !== origin[axis]));
+ if (!spread) return true;
+ const direction = spread.map((value, axis) => value - origin[axis]);
+ return points.every((point) => {
+ const offset = point.map((value, axis) => value - origin[axis]);
+ const cross = [
+ (direction[1] * offset[2]) - (direction[2] * offset[1]),
+ (direction[2] * offset[0]) - (direction[0] * offset[2]),
+ (direction[0] * offset[1]) - (direction[1] * offset[0]),
+ ];
+ return cross.every((component) => Math.abs(component) < 1e-9);
+ });
+};
+
const tubeGeometrySchema = z.object({
type: z.literal('tube'),
path: z.array(vec3Schema).min(2).max(96)
@@ -158,13 +187,19 @@ const tubeGeometrySchema = z.object({
curveType: z.enum(['centripetal', 'chordal', 'catmullrom']).default('centripetal'),
tension: z.number().finite().min(0).max(1).default(0.5),
}).superRefine((definition, ctx) => {
+ if (!definition.closed) return;
const first = definition.path[0];
const last = definition.path[definition.path.length - 1];
// A closed curve already joins the endpoints; repeating the seam point yields a
// zero-length segment and NaN frames in the centripetal/chordal parameterizations.
- if (definition.closed && first.every((value, axis) => value === last[axis])) {
+ if (first.every((value, axis) => value === last[axis])) {
ctx.addIssue({ code: 'custom', message: 'a closed tube path must not repeat its first point at the end', path: ['path'] });
}
+ // Fewer than three points — or any number of collinear ones — closes into a
+ // curve that runs out and retraces itself, so the tube overlaps its own surface.
+ if (definition.path.length < 3 || isCollinearPath(definition.path)) {
+ ctx.addIssue({ code: 'custom', message: 'a closed tube path needs at least three non-collinear points', path: ['path'] });
+ }
});
const customGeometrySchema = z.object({
diff --git a/server/lib/threejsModel.test.js b/server/lib/threejsModel.test.js
index 118b5bcc6e..4726861990 100644
--- a/server/lib/threejsModel.test.js
+++ b/server/lib/threejsModel.test.js
@@ -162,6 +162,58 @@ describe('threejsGeometrySchema extrude/tube validation', () => {
expect(result.error.issues.some((issue) => issue.message.includes('falls outside the outline'))).toBe(true);
});
+ it('rejects overlapping and nested holes', () => {
+ const overlapping = threejsGeometrySchema.safeParse({
+ ...validExtrude(),
+ holes: [
+ [[-0.6, -0.4], [0.1, -0.4], [0.1, 0.4], [-0.6, 0.4]],
+ [[-0.1, -0.4], [0.6, -0.4], [0.6, 0.4], [-0.1, 0.4]],
+ ],
+ });
+ expect(overlapping.success).toBe(false);
+ expect(overlapping.error.issues.some((issue) => issue.message.includes('overlaps hole 0'))).toBe(true);
+
+ const nested = threejsGeometrySchema.safeParse({
+ ...validExtrude(),
+ holes: [
+ [[-0.6, -0.6], [0.6, -0.6], [0.6, 0.6], [-0.6, 0.6]],
+ [[-0.2, -0.2], [0.2, -0.2], [0.2, 0.2], [-0.2, 0.2]],
+ ],
+ });
+ expect(nested.success).toBe(false);
+ expect(nested.error.issues.some((issue) => issue.message.includes('overlaps hole 0'))).toBe(true);
+ });
+
+ it('accepts disjoint holes inside the outline', () => {
+ expect(threejsGeometrySchema.safeParse({
+ ...validExtrude(),
+ holes: [
+ [[-0.7, -0.3], [-0.3, -0.3], [-0.3, 0.3], [-0.7, 0.3]],
+ [[0.3, -0.3], [0.7, -0.3], [0.7, 0.3], [0.3, 0.3]],
+ ],
+ }).success).toBe(true);
+ });
+
+ it('rejects a closed tube that cannot enclose a loop', () => {
+ const twoPoint = threejsGeometrySchema.safeParse({
+ type: 'tube', radius: 0.1, closed: true, path: [[0, 0, 0], [1, 0, 0]],
+ });
+ expect(twoPoint.success).toBe(false);
+ expect(twoPoint.error.issues.some((issue) => issue.message.includes('three non-collinear points'))).toBe(true);
+
+ const collinear = threejsGeometrySchema.safeParse({
+ type: 'tube', radius: 0.1, closed: true, path: [[0, 0, 0], [1, 1, 1], [3, 3, 3]],
+ });
+ expect(collinear.success).toBe(false);
+ expect(collinear.error.issues.some((issue) => issue.message.includes('three non-collinear points'))).toBe(true);
+ });
+
+ it('accepts a two-point open tube path', () => {
+ expect(threejsGeometrySchema.safeParse({
+ type: 'tube', radius: 0.1, path: [[0, 0, 0], [1, 0, 0]],
+ }).success).toBe(true);
+ });
+
it('accepts a hole fully inside a concave outline', () => {
const result = threejsGeometrySchema.safeParse({
...validExtrude(),
diff --git a/server/services/threejsModels/prompt.js b/server/services/threejsModels/prompt.js
index c3857ba482..dbb384597e 100644
--- a/server/services/threejsModels/prompt.js
+++ b/server/services/threejsModels/prompt.js
@@ -14,8 +14,8 @@ Allowed geometry definitions:
- {"type":"torus","radius":n,"tube":n,"radialSegments":3..64,"tubularSegments":6..128,"arcDegrees":1..360}
- {"type":"capsule","radius":n,"length":n,"capSegments":2..32,"radialSegments":3..64}
- {"type":"lathe","points":[[x,y],...],"segments":3..96}
-- {"type":"extrude","outline":[[x,y],...],"holes":[[[x,y],...],...],"depth":n,"bevelEnabled":false,"bevelThickness":n,"bevelSize":n,"bevelSegments":0..8,"curveSegments":1..24,"steps":1..32} (a closed 2D outline of 3..160 points swept along +Z; \`holes\` are closed rings cut out of it. Every ring must enclose real area and every hole must lie inside the outline.)
-- {"type":"tube","path":[[x,y,z],...],"radius":n,"tubularSegments":2..256,"radialSegments":3..32,"closed":false,"curveType":"centripetal"|"chordal"|"catmullrom","tension":0..1} (a round profile swept along a smooth 2..96 point curve. Consecutive path points must differ, and a closed path must not repeat its first point at the end.)
+- {"type":"extrude","outline":[[x,y],...],"holes":[[[x,y],...],...],"depth":n,"bevelEnabled":false,"bevelThickness":n,"bevelSize":n,"bevelSegments":0..8,"curveSegments":1..24,"steps":1..32} (a closed 2D outline of 3..160 points swept along +Z; \`holes\` are closed rings cut out of it. Every ring must enclose real area, every hole must lie strictly inside the outline, and holes must not touch, overlap, or nest inside each other.)
+- {"type":"tube","path":[[x,y,z],...],"radius":n,"tubularSegments":2..256,"radialSegments":3..32,"closed":false,"curveType":"centripetal"|"chordal"|"catmullrom","tension":0..1} (a round profile swept along a smooth 2..96 point curve. Consecutive path points must differ; a closed path must not repeat its first point at the end and needs at least three non-collinear points.)
- {"type":"custom","vertices":[x,y,z,...],"indices":[a,b,c,...]} (triangle mesh; use only when primitives cannot express an identity-defining silhouette)
Choosing between them:
@@ -104,7 +104,7 @@ WORKFLOW:
6. Use physically coherent PBR material channels. Reach for "physical" with ior/transmission/thickness for glass, gems, liquid, and clear plastic, sheen for cloth and velvet, iridescence for oil-slick/soap-film/pearlescent finishes, and anisotropy for brushed metal or spun discs. Do not use textures, external meshes, URLs, downloaded assets, or JavaScript.
7. Center the subject near the origin, keep dimensions internally consistent, and choose a camera that frames the whole model.
8. Be honest about unseen sides in limitations. Infer conservatively; never claim exact hidden geometry.
-9. Ensure every detailInventory item points to real part ids, every material reference exists, every socket parent exists, all ids are unique, custom indices are in range, extrude rings enclose real area with holes inside the outline, and tube paths never repeat a point.
+9. Ensure every detailInventory item points to real part ids, every material reference exists, every socket parent exists, all ids are unique, custom indices are in range, extrude rings enclose real area with non-overlapping holes inside the outline, and tube paths never repeat a point.
QUALITY GATE:
- A compound subject must not collapse into one primitive.