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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: reject self-crossing extrude outlines and holes (#3350)
[._.]/ Adam Eivy237d1d67ddd6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 1da9ed6c2c..2815649d68 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 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.+- **[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 or crosses itself, 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.mdindex a0c64870f3..51dd4cc36d 100644--- a/docs/THREEJS_MODELS.md+++ b/docs/THREEJS_MODELS.md@@ -36,8 +36,10 @@ and the bounded `custom` triangle mesh, the schema carries two constructiveforms 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; each- hole must lie strictly inside the outline (point-in-polygon on every vertex+ swept to `depth` with optional bevel. Every ring must enclose real area and+ be simple (a self-crossing ring has no defined interior, and its lobes partly+ cancel so the area test alone does not catch it); each hole must lie strictly+ inside the outline (point-in-polygon on every vertexplus an edge sweep, since a concave outline's bounding box covers empty spaceits notch does not); and holes may not touch, cross, or nest. Each of thosecases triangulates into an empty face, a disjoint face, or solid materialdiff --git a/server/lib/threejsModel.js b/server/lib/threejsModel.jsindex 8a056e1f99..1642ef3421 100644--- a/server/lib/threejsModel.js+++ b/server/lib/threejsModel.js@@ -113,6 +113,21 @@ const ringsCross = (outer, inner) => {return false;};+// A ring that crosses itself has no defined interior — the shoelace area stays+// non-zero (the lobes partly cancel) but the triangulator picks an arbitrary+// filling, so require a simple polygon: no two non-adjacent edges may meet.+const isSimpleRing = (ring) => {+ for (let i = 0; i < ring.length; i += 1) {+ for (let j = i + 1; j < ring.length; j += 1) {+ const adjacent = j === i + 1 || (i === 0 && j === ring.length - 1);+ if (!adjacent && segmentsCross(ring[i], ring[(i + 1) % ring.length], ring[j], ring[(j + 1) % ring.length])) {+ return false;+ }+ }+ }+ return true;+};+// Vertex containment alone is not enough: a concave outline can hold every hole// vertex while an edge between two of them leaves through the notch. Bounded by// the ring caps (160 outline points × 12 holes × 160 hole points), so the O(n·m)@@ -127,7 +142,8 @@ const ringsOverlap = (a, b) => ringsCross(a, b)|| 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');+ .refine((ring) => ringArea(ring) > MIN_RING_AREA, 'outline must enclose a non-zero area')+ .refine(isSimpleRing, 'outline must not cross itself');const extrudeGeometrySchema = z.object({type: z.literal('extrude'),diff --git a/server/lib/threejsModel.test.js b/server/lib/threejsModel.test.jsindex 4726861990..a7e19a1888 100644--- a/server/lib/threejsModel.test.js+++ b/server/lib/threejsModel.test.js@@ -125,6 +125,15 @@ describe('threejsGeometrySchema extrude/tube validation', () => {expect(threejsGeometrySchema.safeParse({ ...validExtrude(), holes: [collinear] }).success).toBe(false);});+ it('rejects a self-crossing outline or hole', () => {+ // Non-zero shoelace area, but the lobes cross so the interior is undefined.+ const crossing = [[0, 0], [2, 4], [4, 0], [0, 3], [4, 3]];+ const result = threejsGeometrySchema.safeParse({ ...validExtrude(), outline: crossing });+ expect(result.success).toBe(false);+ expect(result.error.issues.some((issue) => issue.message.includes('must not cross itself'))).toBe(true);+ expect(threejsGeometrySchema.safeParse({ ...validExtrude(), holes: [crossing] }).success).toBe(false);+ });+it('rejects an outline with fewer than three points', () => {expect(threejsGeometrySchema.safeParse({ ...validExtrude(), outline: [[0, 0], [1, 1]] }).success).toBe(false);});diff --git a/server/services/threejsModels/prompt.js b/server/services/threejsModels/prompt.jsindex dbb384597e..d0bf1e2f49 100644--- a/server/services/threejsModels/prompt.js+++ b/server/services/threejsModels/prompt.js@@ -14,7 +14,7 @@ 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, every hole must lie strictly inside the outline, and holes must not touch, overlap, or nest inside each other.)+- {"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 must not cross itself, 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)