Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Garments: no automatic placement (patent design-around): analyzeBody, slots, placePattern and garment_place removed; flatRest for the solver's rest shape; docs/design/garments.md "Do not build (patents)"

islandmeddc1e248e702d
diff --git a/changes/feat-garment-patterns.md b/changes/feat-garment-patterns.md
index cd9f6cd8..dc25933c 100644
--- a/changes/feat-garment-patterns.md
+++ b/changes/feat-garment-patterns.md
@@ -2,10 +2,9 @@
added: **Garments, part 1** (scripting and the AI assistant for now; the Pattern window follows): pattern panels at
real size (millimetres, curves, notches, grain line, seam allowance) saved in the project, a T-shirt template
(front, back, two sleeves, sewn), seams with length and direction checks, even triangulation at a chosen particle
- distance with seams matched point for point, placement around the body (front, back, sides, arms found from its
- shape), export as a real-size SVG for printing and sewing (with a 50 mm scale square) or DXF for cutters, and
- SVG panels read back in. Commands: garment_new, garment_info, garment_add_panel, garment_sew, garment_place,
- garment_export, garment_import and more.
+ distance with seams matched point for point, export as a real-size SVG for printing and sewing (with a 50 mm
+ scale square) or DXF for cutters, and SVG panels read back in. Commands: garment_new, garment_info,
+ garment_add_panel, garment_sew, garment_export, garment_import and more.
testers:
- Any OS: `sculptforge-cli -c "garment_new; garment_export path=shirt.svg"`; open the SVG in a
browser or print it at 100%: the square is 50 mm, the front is 52 cm wide.
diff --git a/docs/design/garments.md b/docs/design/garments.md
new file mode 100644
index 00000000..a6471920
--- /dev/null
+++ b/docs/design/garments.md
@@ -0,0 +1,36 @@
+# Garments: design notes
+
+Pattern panels drawn flat at real size (millimetres), sewn edge to edge, draped on a body by the cloth solver
+(docs/design/cloth.md, core/Cloth.h) and turned into a Part whose UVs are the flat layout. The code is
+src/core/Garment.h (the model, its notes in the header), GarmentMesh.cpp (even triangulation, in-house constrained
+Delaunay), GarmentFiles.cpp (SVG / DXF), GarmentCommands.cpp (garment_*) and src/app/PanelGarments.cpp (the
+Pattern window).
+
+## Placement
+
+The user places each panel: a click on the body says where it goes (part 3). There is no automatic body analysis,
+no body-part slots, bounding volumes or arrangement points, and no initial position computed from the body's
+shape. (Removed from part 1 on 11-06 before it shipped; see "Do not build".)
+
+## Sewing
+
+The user picks both edges of every seam. A seam joins whole edges (or ranges along them the user chose); the
+window shows both lengths, green when they match, red when one side is eased in. Nothing snaps a seam's ends to
+make the lengths equal.
+
+## Do not build (patents)
+
+Active patents read on these (search: ~/Work/.sf/reports/garment-patents.md, 2026-11-06; not legal advice).
+None of them may be added, in any form, without Tony's explicit OK:
+
+- Automatic placement from the body: feature points, per-body-part bounding volumes, arrangement points, initial
+ pattern positions computed from the avatar.
+- Automatic sewing from placement (sewing what ends up near each other).
+- Seam suggestions by 3D distance or orientation.
+- Auto-grading from avatar-to-avatar strain.
+- Matching patterns against a database of pattern blocks and sewing from it.
+- 3D duplicate (or mirror) of a panel that adds its seams automatically. Duplicate and Mirror Copy stay 2D with no
+ seams added.
+- A measuring tape across several pieces.
+- A shirring tool.
+- Snapping a seam's end points so the two lengths come out equal.
diff --git a/src/core/Garment.cpp b/src/core/Garment.cpp
index 61c2455e..1f192bd4 100644
--- a/src/core/Garment.cpp
+++ b/src/core/Garment.cpp
@@ -1,7 +1,7 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
-// Garments: pattern panels, their edits, seams, the body arrangement, the Part made after the simulation, the
+// Garments: pattern panels, their edits, seams, the flat rest shape, the Part made after the simulation, the
// T-shirt template and the project JSON (core/Garment.h). Triangulation is in GarmentMesh.cpp, files in
// GarmentFiles.cpp.
#include "core/Garment.h"
@@ -121,43 +121,12 @@ void fixPanels(std::vector<Seam>& seams, uint32_t removed) {
}
}
-Slot mirroredSlot(Slot s) {
- switch (s) {
- case Slot::Left: return Slot::Right;
- case Slot::Right: return Slot::Left;
- case Slot::LeftArm: return Slot::RightArm;
- case Slot::RightArm: return Slot::LeftArm;
- default: return s;
- }
-}
-
bool overlaps(const SeamSide& x, const SeamSide& y) {
return x.panel == y.panel && x.edge == y.edge && x.t0 < y.t1 - 1e-4f && y.t0 < x.t1 - 1e-4f;
}
} // namespace
-// ---------------------------------------------------------------------------
-// Slots
-// ---------------------------------------------------------------------------
-
-const char* slotId(Slot s) {
- static const char* ids[] = {"front", "back", "left", "right", "left_arm", "right_arm", "free"};
- return s < Slot::Count ? ids[int(s)] : "free";
-}
-const char* slotLabel(Slot s) {
- static const char* labels[] = {"Front", "Back", "Left side", "Right side", "Left arm", "Right arm", "Free"};
- return s < Slot::Count ? labels[int(s)] : "Free";
-}
-bool slotFromId(const std::string& id, Slot& out) {
- for (int i = 0; i < int(Slot::Count); ++i)
- if (id == slotId(Slot(i))) {
- out = Slot(i);
- return true;
- }
- return false;
-}
-
// ---------------------------------------------------------------------------
// Panel geometry
// ---------------------------------------------------------------------------
@@ -403,8 +372,6 @@ uint32_t mirroredCopy(Pattern& pat, uint32_t i, const std::string& name) {
one.panels.push_back(pat.panels[j]);
mirrorPanel(one, 0);
pat.panels[j] = std::move(one.panels[0]);
- pat.panels[j].place.slot = mirroredSlot(pat.panels[j].place.slot);
- pat.panels[j].place.offset.x = -pat.panels[j].place.offset.x;
return j;
}
@@ -632,262 +599,12 @@ std::vector<std::string> patternProblems(const Pattern& pat) {
}
// ---------------------------------------------------------------------------
-// Arrangement
+// Rest shape
// ---------------------------------------------------------------------------
-BodyFrame defaultBody() {
- BodyFrame b;
- b.bounds.min = {-0.85f, 0.0f, -0.13f};
- b.bounds.max = {0.85f, 1.75f, 0.13f};
- b.shoulderY = 1.45f;
- b.torsoHalfWidth = 0.17f;
- b.torsoFrontZ = 0.11f;
- b.torsoBackZ = -0.11f;
- b.arms = true;
- b.leftShoulder = {0.17f, 1.40f, 0.0f};
- b.rightShoulder = {-0.17f, 1.40f, 0.0f};
- b.armRadius = 0.05f;
- return b;
-}
-
-BodyFrame analyzeBody(const Mesh& body) {
- BodyFrame f;
- if (body.positions.empty()) return defaultBody();
- for (const glm::vec3& p : body.positions) f.bounds.expand(p);
- const float h = f.bounds.extent().y;
- const float y0 = f.bounds.min.y;
- f.centerX = f.bounds.center().x;
- f.centerZ = f.bounds.center().z;
- if (!(h > 1e-6f)) return defaultBody();
- // Torso width: x coverage of the chest band by triangles (not vertices: a coarse mesh has gaps between
- // them), from the middle out to the first empty gap (arms held away).
- const float binW = h / 175.0f; // 1 cm on a 1.75 m figure
- const int bins = 400;
- std::vector<int> occ(bins, 0);
- const float bandLo = y0 + 0.58f * h, bandHi = y0 + 0.70f * h;
- auto cover = [&](float xa, float xb) {
- // Both sides of the middle fold onto |x - centre|.
- const float lo = xa - f.centerX, hi = xb - f.centerX;
- const float a = (lo <= 0.0f && hi >= 0.0f) ? 0.0f : std::min(std::abs(lo), std::abs(hi));
- const float b = std::max(std::abs(lo), std::abs(hi));
- for (int k = int(a / binW); k <= int(b / binW) && k < bins; ++k) ++occ[size_t(k)];
- };
- for (const glm::uvec3& t : body.triangles) {
- if (t.x >= body.positions.size() || t.y >= body.positions.size() || t.z >= body.positions.size()) continue;
- const glm::vec3 a = body.positions[t.x], b = body.positions[t.y], c = body.positions[t.z];
- const float ylo = std::min({a.y, b.y, c.y}), yhi = std::max({a.y, b.y, c.y});
- if (yhi < bandLo || ylo > bandHi) continue;
- const float xlo = std::min({a.x, b.x, c.x}), xhi = std::max({a.x, b.x, c.x});
- if (xlo < f.centerX && xhi > f.centerX) {
- cover(xlo, f.centerX);
- cover(f.centerX, xhi);
- } else {
- cover(xlo, xhi);
- }
- }
- if (body.triangles.empty())
- for (const glm::vec3& p : body.positions)
- if (p.y >= bandLo && p.y <= bandHi) cover(p.x, p.x);
- int edge = 0;
- for (int k = 0; k < bins; ++k) {
- if (occ[size_t(k)]) edge = k;
- else if (edge > 0 || k > 2) break;
- }
- f.torsoHalfWidth = std::max(binW, (float(edge) + 1.0f) * binW);
- // Depth: the front and back of the chest band near the middle.
- float front = f.centerZ, back = f.centerZ;
- bool any = false;
- for (const glm::vec3& p : body.positions)
- if (p.y >= bandLo && p.y <= bandHi && std::abs(p.x - f.centerX) < 0.5f * f.torsoHalfWidth) {
- front = any ? std::max(front, p.z) : p.z;
- back = any ? std::min(back, p.z) : p.z;
- any = true;
- }
- f.torsoFrontZ = front;
- f.torsoBackZ = back;
- if (any) f.centerZ = 0.5f * (front + back);
- // Shoulders: the highest point over the outer half of the torso's width (the neck and head are narrower,
- // arms held out are further out), below the top of the head.
- f.shoulderY = y0 + 0.83f * h;
- float top = -std::numeric_limits<float>::max();
- for (const glm::vec3& p : body.positions) {
- const float dx = std::abs(p.x - f.centerX);
- if (dx >= 0.5f * f.torsoHalfWidth && dx <= f.torsoHalfWidth && p.y > bandLo && p.y < y0 + 0.95f * h) top = std::max(top, p.y);
- }
- if (top > bandLo) f.shoulderY = top;
- // Arms: vertices well outside the torso above the waist, one slab near the shoulder and one further out.
- f.armRadius = 0.03f * h;
- for (int side = 0; side < 2; ++side) {
- const float s = side == 0 ? 1.0f : -1.0f;
- const float x1 = 1.4f * f.torsoHalfWidth, x2 = x1 + 0.15f * h, slab = 0.08f * h;
- glm::dvec3 m1(0.0), m2(0.0);
- size_t n1 = 0, n2 = 0;
- for (const glm::vec3& p : body.positions) {
- if (p.y < y0 + 0.5f * h) continue;
- const float dx = s * (p.x - f.centerX);
- if (dx >= x1 && dx < x1 + slab) {
- m1 += glm::dvec3(p);
- ++n1;
- } else if (dx >= x2 && dx < x2 + slab) {
- m2 += glm::dvec3(p);
- ++n2;
- }
- }
- if (n1 < 8) continue;
- const glm::vec3 p1 = glm::vec3(m1 / double(n1));
- glm::vec3 dir(s, 0.0f, 0.0f);
- if (n2 >= 8) dir = glm::normalize(glm::vec3(m2 / double(n2)) - p1);
- if (dir.x * s < 0.3f) continue; // not an arm held out
- // Radius: the mean distance of the near slab's vertices from the arm's line.
- double r = 0.0;
- for (const glm::vec3& p : body.positions) {
- if (p.y < y0 + 0.5f * h) continue;
- const float dx = s * (p.x - f.centerX);
- if (dx >= x1 && dx < x1 + slab) {
- const glm::vec3 d = p - p1;
- r += double(glm::length(d - glm::dot(d, dir) * dir));
- }
- }
- const float radius = float(r / double(n1));
- // The shoulder: back along the arm to the torso's side.
- const float back = (s * (p1.x - f.centerX) - f.torsoHalfWidth) / std::max(0.3f, std::abs(dir.x));
- const glm::vec3 shoulder = p1 - dir * back;
- f.arms = true;
- f.armRadius = side == 0 ? radius : 0.5f * (f.armRadius + radius);
- (side == 0 ? f.leftShoulder : f.rightShoulder) = shoulder;
- (side == 0 ? f.leftArmDir : f.rightArmDir) = dir;
- }
- if (!f.arms) { // arms down or none: sleeves start at the shoulders, pointing out and down
- f.leftShoulder = {f.centerX + f.torsoHalfWidth, f.shoulderY - 0.03f * h, f.centerZ};
- f.rightShoulder = {f.centerX - f.torsoHalfWidth, f.shoulderY - 0.03f * h, f.centerZ};
- f.leftArmDir = glm::normalize(glm::vec3(0.3f, -1.0f, 0.0f));
- f.rightArmDir = glm::normalize(glm::vec3(-0.3f, -1.0f, 0.0f));
- }
- return f;
-}
-
-void autoSlots(Pattern& pat) {
- auto has = [](std::string s, const char* w) {
- std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return char(std::tolower(c)); });
- return s.find(w) != std::string::npos;
- };
- int sleeves = 0;
- for (Panel& p : pat.panels) {
- if (p.place.slot != Slot::Front) continue; // chosen already
- if (has(p.name, "back")) p.place.slot = Slot::Back;
- else if (has(p.name, "sleeve") || has(p.name, "arm")) {
- const bool right = has(p.name, "right") || (!has(p.name, "left") && sleeves % 2 == 1);
- p.place.slot = right ? Slot::RightArm : Slot::LeftArm;
- ++sleeves;
- } else if (has(p.name, "side")) {
- p.place.slot = has(p.name, "right") ? Slot::Right : Slot::Left;
- }
- }
-}
-
-namespace {
-
-// Arc length of an ellipse quarter from angle 0, tabulated, so a panel's x (arc length) maps to an angle.
-struct EllipseArc {
- float a, b; // semi-axes along S and R0
- std::vector<float> len; // at angles i / N * pi
- static constexpr int N = 128;
- EllipseArc(float aa, float bb) : a(aa), b(bb), len(N + 1) {
- float l = 0.0f;
- glm::vec2 prev(0.0f, b);
- for (int i = 0; i <= N; ++i) {
- const float th = float(i) / float(N) * kPi;
- const glm::vec2 q(a * std::sin(th), b * std::cos(th));
- if (i) l += glm::length(q - prev);
- prev = q;
- len[size_t(i)] = l;
- }
- }
- // (along S, along R0) at arc length x from the front point (x < 0 goes the other way; past half: straight on).
- glm::vec2 at(float x) const {
- const float s = x < 0 ? -1.0f : 1.0f;
- const float want = std::abs(x);
- if (want >= len.back()) return {s * 0.0f, -b - (want - len.back())}; // (never this far in practice)
- const auto it = std::lower_bound(len.begin(), len.end(), want);
- const size_t i = size_t(std::max<ptrdiff_t>(1, it - len.begin()));
- const float f = len[i] > len[i - 1] ? (want - len[i - 1]) / (len[i] - len[i - 1]) : 0.0f;
- const float th = (float(i - 1) + f) / float(N) * kPi;
- return {s * a * std::sin(th), b * std::cos(th)};
- }
-};
-
-struct SlotFrame {
- glm::vec3 c, axis, out, side; // panel top centre on the axis; +y of the panel; facing; +x of the panel
- float across = 0.1f, depth = 0.1f; // ellipse semi-axes (side, out)
-};
-
-SlotFrame slotFrame(const Panel& p, const BodyFrame& b, float gap) {
- SlotFrame f;
- const glm::vec3 up(0.0f, 1.0f, 0.0f);
- const float frontD = std::max(0.02f, b.torsoFrontZ - b.centerZ), backD = std::max(0.02f, b.centerZ - b.torsoBackZ);
- const glm::vec3 torso(b.centerX, b.shoulderY, b.centerZ);
- switch (p.place.slot) {
- case Slot::Front: f = {torso, up, {0, 0, 1}, {}, b.torsoHalfWidth, frontD}; break;
- case Slot::Back: f = {torso, up, {0, 0, -1}, {}, b.torsoHalfWidth, backD}; break;
- case Slot::Left: f = {torso, up, {1, 0, 0}, {}, std::max(frontD, backD), b.torsoHalfWidth}; break;
- case Slot::Right: f = {torso, up, {-1, 0, 0}, {}, std::max(frontD, backD), b.torsoHalfWidth}; break;
- case Slot::LeftArm:
- case Slot::RightArm: {
- const bool left = p.place.slot == Slot::LeftArm;
- const glm::vec3 dir = glm::normalize(left ? b.leftArmDir : b.rightArmDir);
- f.c = left ? b.leftShoulder : b.rightShoulder;
- f.axis = -dir; // the sleeve's top (cap) points back to the shoulder
- glm::vec3 o = up - glm::dot(up, f.axis) * f.axis;
- if (glm::length(o) < 1e-3f) o = glm::vec3(0, 0, 1) - glm::dot(glm::vec3(0, 0, 1), f.axis) * f.axis;
- f.out = glm::normalize(o);
- f.across = f.depth = b.armRadius;
- break;
- }
- default: f = {torso + glm::vec3(0, 0, b.torsoFrontZ - b.centerZ + 0.25f), up, {0, 0, 1}, {}, 0, 0}; break;
- }
- f.side = glm::cross(f.axis, f.out); // so that (side x axis) faces out: counter-clockwise panels face away
- f.across += gap + p.place.offset.z;
- f.depth += gap + p.place.offset.z;
- return f;
-}
-
-} // namespace
-
-glm::vec3 placePoint(const Panel& p, glm::vec2 flat, const BodyFrame& body, float gap) {
- const glm::vec2 lo = panelMin(p), hi = panelMax(p);
- const float x = (flat.x - 0.5f * (lo.x + hi.x)) * 0.001f + p.place.offset.x;
- const float y = (flat.y - hi.y) * 0.001f + p.place.offset.y;
- const SlotFrame f = slotFrame(p, body, gap);
- if (!p.place.wrap || p.place.slot == Slot::Free) return f.c + f.axis * y + f.out * f.depth + f.side * x;
- const EllipseArc arc(f.across, f.depth);
- const glm::vec2 q = arc.at(x);
- return f.c + f.axis * y + f.side * q.x + f.out * q.y;
-}
-
-void placePattern(const Pattern& pat, const GarmentMesh& m, const BodyFrame& body, std::vector<glm::vec3>& placed,
- std::vector<glm::vec3>& rest, float gap) {
- placed.resize(m.flat.size());
+void flatRest(const GarmentMesh& m, std::vector<glm::vec3>& rest) {
rest.resize(m.flat.size());
- // One frame and arc table per panel (placePoint would rebuild them per vertex).
- for (size_t pi = 0; pi + 1 < m.panelFirstVertex.size() && pi < pat.panels.size(); ++pi) {
- const Panel& p = pat.panels[pi];
- const glm::vec2 lo = panelMin(p), hi = panelMax(p);
- const SlotFrame f = slotFrame(p, body, gap);
- const EllipseArc arc(f.across, f.depth);
- const bool wrap = p.place.wrap && p.place.slot != Slot::Free;
- for (uint32_t v = m.panelFirstVertex[pi]; v < m.panelFirstVertex[pi + 1]; ++v) {
- const glm::vec2 q = m.flat[v];
- const float x = (q.x - 0.5f * (lo.x + hi.x)) * 0.001f + p.place.offset.x;
- const float y = (q.y - hi.y) * 0.001f + p.place.offset.y;
- if (wrap) {
- const glm::vec2 e = arc.at(x);
- placed[v] = f.c + f.axis * y + f.side * e.x + f.out * e.y;
- } else {
- placed[v] = f.c + f.axis * y + f.out * f.depth + f.side * x;
- }
- rest[v] = glm::vec3(q * 0.001f, 0.0f);
- }
- }
+ for (size_t v = 0; v < m.flat.size(); ++v) rest[v] = glm::vec3(m.flat[v] * 0.001f, 0.0f);
}
// ---------------------------------------------------------------------------
@@ -1058,14 +775,11 @@ Pattern tshirtPattern(float chestMm, float lengthMm) {
const float length = std::clamp(lengthMm, 300.0f, 1500.0f);
pat.panels.push_back(bodyPanel("Front", 0.0f, half, length, 90.0f));
pat.panels.push_back(bodyPanel("Back", 2.0f * half + 60.0f, half, length, 20.0f));
- pat.panels[1].place.slot = Slot::Back;
// Each armhole (front + back) is the cap's length, plus 2% ease.
const float armhole = edgeLength(pat.panels[0], 2) + edgeLength(pat.panels[1], 6);
const float sx = 3.0f * half + 120.0f + 190.0f; // 60 mm right of the back
pat.panels.push_back(sleevePanel("Left sleeve", sx, armhole * 1.02f));
pat.panels.push_back(sleevePanel("Right sleeve", sx + 440.0f, armhole * 1.02f));
- pat.panels[2].place.slot = Slot::LeftArm;
- pat.panels[3].place.slot = Slot::RightArm;
std::string error;
auto sew = [&](uint32_t pa, uint32_t ea, float a0, float a1, uint32_t pb, uint32_t eb, float b0, float b1) {
addSeam(pat, {{pa, ea, a0, a1}, {pb, eb, b0, b1}, false}, error);
@@ -1151,11 +865,6 @@ Json patternToJson(const Pattern& pat) {
pj.set("notches", std::move(notches));
pj.set("grain", num(p.grainDegrees));
pj.set("allowance_mm", num(p.seamAllowance));
- pj.set("slot", slotId(p.place.slot));
- Json off = Json::array();
- for (int k = 0; k < 3; ++k) off.push(num(p.place.offset[k]));
- pj.set("offset", std::move(off));
- pj.set("wrap", p.place.wrap);
panels.push(std::move(pj));
}
j.set("panels", std::move(panels));
@@ -1210,11 +919,6 @@ bool patternFromJson(const Json& j, Pattern& out, std::string& error) {
p.notches.push_back({uint32_t(nj[0].asNumber(0)), fnum(nj[1], 0.5f)});
p.grainDegrees = fnum(pj["grain"], 90.0f);
p.seamAllowance = std::clamp(fnum(pj["allowance_mm"], 10.0f), 0.0f, 200.0f);
- Slot s;
- if (pj["slot"].isString() && slotFromId(pj["slot"].asString(), s)) p.place.slot = s;
- if (pj["offset"].isArray() && pj["offset"].size() == 3)
- for (int k = 0; k < 3; ++k) p.place.offset[k] = std::clamp(fnum(pj["offset"][size_t(k)], 0.0f), -10.0f, 10.0f);
- p.place.wrap = pj["wrap"].asBool(true);
normalizePanel(p);
std::string why;
if (!validPanel(p, why, &outlineBudget)) {
diff --git a/src/core/Garment.h b/src/core/Garment.h
index 382c4b1e..ee9e61c4 100644
--- a/src/core/Garment.h
+++ b/src/core/Garment.h
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Garments (docs/design/cloth.md): clothing made the way it is sewn. Pattern panels are flat pieces of fabric drawn
-// at real size (millimetres); seams say which edges are sewn together; each panel is placed around the body; the
+// at real size (millimetres); seams say which edges are sewn together; the user places each panel at the body; the
// cloth solver (core/Cloth.h, Drape) pulls the seams closed and lets the garment settle; the result becomes a Part
// whose UVs are the flat panel layout.
//
@@ -18,8 +18,7 @@
// distance (a lattice along the grain, a constrained Delaunay triangulation of it with the outline as
// constraints, then smoothing); both sides of a seam get the same number of points, so the seam's particles pair
// one to one and weld cleanly after the simulation.
-// - Arrangement (analyzeBody, placePattern): slots around the body (front, back, sides, arms) found from its
-// shape, each panel wrapped around the torso or an arm so the seams start close.
+// - No automatic placement, sewing or seam suggestions: see docs/design/garments.md, "Do not build (patents)".
//
// The pattern is saved in the project (Document::projectSettings["garment"]); SVG export writes the panels at real
// size (with seam allowance, notches, grain lines) for printing and sewing, DXF the outlines for cutters.
@@ -56,19 +55,6 @@ struct Notch {
float t = 0.5f;
};
-// Where a panel goes around the body (placePattern).
-enum class Slot : uint8_t { Front, Back, Left, Right, LeftArm, RightArm, Free, Count };
-const char* slotId(Slot s); // "front", "back", "left", "right", "left_arm", "right_arm", "free"
-const char* slotLabel(Slot s); // "Front", ...
-bool slotFromId(const std::string& id, Slot& out);
-
-struct Placement {
- Slot slot = Slot::Front;
- // Metres in the slot's frame: x across the panel (around the body), y along it (+ up), z away from the body.
- glm::vec3 offset{0.0f};
- bool wrap = true; // bent around the torso or the arm (false: flat, facing out of the slot)
-};
-
struct Panel {
std::string name = "Panel";
std::vector<glm::vec2> points; // mm, the sewing line, counter-clockwise from the right side
@@ -76,7 +62,6 @@ struct Panel {
std::vector<Notch> notches;
float grainDegrees = 90.0f; // warp direction, degrees from +x (90 = up the panel)
float seamAllowance = 10.0f; // mm
- Placement place;
};
struct SeamSide {
@@ -128,8 +113,8 @@ std::vector<glm::vec2> offsetOutline(const Panel& p, float distance);
void mirrorPanel(Pattern& pat, uint32_t panel);
// A copy of the panel `offsetMm` to the right, named "<name> 2" (or `name`); returns its index.
uint32_t duplicatePanel(Pattern& pat, uint32_t panel, glm::vec2 offsetMm, const std::string& name = {});
-// A mirrored copy (the other sleeve, the other half): mirrored about its centre and moved beside it; its slot is
-// the mirrored one (left arm <-> right arm, left <-> right). Returns its index.
+// A mirrored copy (the other sleeve, the other half): mirrored about its centre and moved beside it, in 2D
+// only (no seams are added). Returns its index.
uint32_t mirroredCopy(Pattern& pat, uint32_t panel, const std::string& name = {});
// Unfolds a panel drawn as a half about straight edge `edge` (the fold line): the panel becomes the whole shape,
// the fold edge disappears. False when the edge is curved.
@@ -183,32 +168,10 @@ struct MeshQuality {
};
MeshQuality meshQuality(const GarmentMesh& m, float particleDistance);
-// --- Arrangement ---
-
-// What placePattern needs to know about the body, found from its vertices (Y up, facing +Z, metres).
-struct BodyFrame {
- AABB bounds;
- float centerX = 0.0f, centerZ = 0.0f;
- float shoulderY = 0.0f; // the top of the torso panels
- float torsoHalfWidth = 0.15f; // x
- float torsoFrontZ = 0.1f, torsoBackZ = -0.1f;
- bool arms = false; // arms held out (T or A pose) were found
- glm::vec3 leftShoulder{0.0f}, rightShoulder{0.0f}; // where each arm starts (character's left = +X)
- glm::vec3 leftArmDir{1.0f, 0.0f, 0.0f}, rightArmDir{-1.0f, 0.0f, 0.0f};
- float armRadius = 0.05f;
-};
-BodyFrame analyzeBody(const Mesh& body);
-// A body frame for no body: a 1.75 m figure standing at the origin.
-BodyFrame defaultBody();
-
-// Gives panels without a chosen slot one from their names (front, back, sleeve/arm with left/right, side).
-void autoSlots(Pattern& pat);
-// The 3D position (metres) of pattern point `flat` (mm) of panel `p` placed on `body`; `gap` metres off it.
-glm::vec3 placePoint(const Panel& p, glm::vec2 flat, const BodyFrame& body, float gap = 0.03f);
-// Every vertex of `m` placed around the body (placed) and the flat rest shape in 3D (rest: sheet x, y, z = 0, in
-// metres): what the cloth solver starts from.
-void placePattern(const Pattern& pat, const GarmentMesh& m, const BodyFrame& body, std::vector<glm::vec3>& placed,
- std::vector<glm::vec3>& rest, float gap = 0.03f);
+// --- Rest shape ---
+
+// The flat pattern in 3D (sheet x, y, z = 0, metres): the cloth solver's rest shape.
+void flatRest(const GarmentMesh& m, std::vector<glm::vec3>& rest);
// --- After the simulation ---
@@ -219,7 +182,7 @@ Mesh garmentToMesh(const GarmentMesh& m, const std::vector<glm::vec3>& positions
// --- Templates ---
-// A T-shirt pattern (front, back, two sleeves, all seams sewn, slots set): `chestMm` the body's chest girth,
+// A T-shirt pattern (front, back, two sleeves, all seams sewn): `chestMm` the body's chest girth,
// `lengthMm` the body length from the shoulder.
Pattern tshirtPattern(float chestMm = 960.0f, float lengthMm = 700.0f);
// A simple rectangle panel (`w` x `h` mm, lower-left corner at `at`).
diff --git a/src/core/GarmentCommands.cpp b/src/core/GarmentCommands.cpp
index 48da577e..2762aabe 100644
--- a/src/core/GarmentCommands.cpp
+++ b/src/core/GarmentCommands.cpp
@@ -1,8 +1,8 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
-// garment_* commands (core/Garment.h): make and edit the scene's garment pattern, sew it, place it around the
-// body, write and read pattern files. The pattern lives in the project (Document::projectSettings["garment"]).
+// garment_* commands (core/Garment.h): make and edit the scene's garment pattern, sew it, write and read
+// pattern files. The pattern lives in the project (Document::projectSettings["garment"]).
#include "core/Commands.h"
#include "core/Garment.h"
@@ -129,8 +129,8 @@ void registerGarmentCommands(CommandRegistry& reg) {
const Panel& p = pat.panels[i];
const glm::vec2 size = panelMax(p) - panelMin(p);
char buf[200];
- std::snprintf(buf, sizeof buf, "\n%zu. %s: %.0f x %.0f mm, %zu edges, %s", i + 1, p.name.c_str(),
- double(size.x), double(size.y), p.points.size(), slotLabel(p.place.slot));
+ std::snprintf(buf, sizeof buf, "\n%zu. %s: %.0f x %.0f mm, %zu edges", i + 1, p.name.c_str(),
+ double(size.x), double(size.y), p.points.size());
s << buf;
}
for (const Seam& sm : pat.seams) s << "\nSeam " << checkSeam(pat, sm).text;
@@ -140,11 +140,10 @@ void registerGarmentCommands(CommandRegistry& reg) {
reg.add({"garment_add_panel",
"Garments: add a pattern panel from its outline: points as JSON [x0, y0, x1, y1, ...] in mm (y up), "
"or a rectangle from width_mm and height_mm.",
- {{"name", T::String, "Panel name (front, back, sleeve... also picks its place around the body)", false},
+ {{"name", T::String, "Panel name", false},
{"points", T::String, "Outline as JSON [x0, y0, x1, y1, ...] in mm, 3 points or more", false},
{"width_mm", T::Number, "Rectangle width (when no points)", false},
- {"height_mm", T::Number, "Rectangle height (when no points)", false},
- {"slot", T::String, "front, back, left, right, left_arm, right_arm or free (default: from the name)", false}},
+ {"height_mm", T::Number, "Rectangle height (when no points)", false}},
[](Document& doc, const Args& a) -> CommandResult {
Pattern pat;
documentPattern(doc, pat);
@@ -170,20 +169,9 @@ void registerGarmentCommands(CommandRegistry& reg) {
normalizePanel(p);
std::string error;
if (!validPanel(p, error)) return {false, error};
- Slot slot;
- if (const std::string s = argString(a, "slot"); !s.empty()) {
- if (!slotFromId(lower(s), slot)) return {false, "Unknown slot \"" + s + "\""};
- p.place.slot = slot;
- pat.panels.push_back(std::move(p));
- } else {
- pat.panels.push_back(std::move(p));
- Pattern one;
- one.panels.push_back(pat.panels.back());
- autoSlots(one);
- pat.panels.back().place.slot = one.panels[0].place.slot;
- }
+ pat.panels.push_back(std::move(p));
setDocumentPattern(doc, pat);
- return {true, "Added " + pat.panels.back().name + " (" + slotLabel(pat.panels.back().place.slot) + "): " + summary(pat)};
+ return {true, "Added " + pat.panels.back().name + ": " + summary(pat)};
}});
reg.add({"garment_remove_panel", "Garments: remove a panel (and its seams).",
{{"panel", T::String, "Panel name or number", true}},
@@ -211,7 +199,7 @@ void registerGarmentCommands(CommandRegistry& reg) {
if (!findPanel(pat, argString(a, "panel"), i, error)) return {false, error};
const uint32_t j = mirroredCopy(pat, i, argString(a, "name"));
setDocumentPattern(doc, pat);
- return {true, "Added " + pat.panels[j].name + " (" + slotLabel(pat.panels[j].place.slot) + ")"};
+ return {true, "Added " + pat.panels[j].name};
}});
reg.add({"garment_sew",
"Garments: sew an edge range of one panel to an edge range of another (or the same) panel. Edges are "
@@ -256,30 +244,6 @@ void registerGarmentCommands(CommandRegistry& reg) {
setDocumentPattern(doc, pat);
return {true, "Garment: " + summary(pat) + ", " + pat.fabric};
}});
- reg.add({"garment_place", "Garments: where a panel goes around the body.",
- {{"panel", T::String, "Panel name or number", true},
- {"slot", T::String, "front, back, left, right, left_arm, right_arm or free", false},
- {"x", T::Number, "Offset across (around) the body, metres", false},
- {"y", T::Number, "Offset up, metres", false},
- {"z", T::Number, "Offset away from the body, metres", false},
- {"wrap", T::Bool, "Bend around the torso or arm (default true)", false}},
- [](Document& doc, const Args& a) -> CommandResult {
- CommandResult r;
- Pattern pat;
- if (!loadOrFail(doc, pat, r)) return r;
- uint32_t i;
- std::string error;
- if (!findPanel(pat, argString(a, "panel"), i, error)) return {false, error};
- Placement& pl = pat.panels[i].place;
- if (const std::string s = argString(a, "slot"); !s.empty() && !slotFromId(lower(s), pl.slot))
- return {false, "Unknown slot \"" + s + "\""};
- pl.offset.x = float(std::clamp(argNumber(a, "x", pl.offset.x), -10.0, 10.0));
- pl.offset.y = float(std::clamp(argNumber(a, "y", pl.offset.y), -10.0, 10.0));
- pl.offset.z = float(std::clamp(argNumber(a, "z", pl.offset.z), -10.0, 10.0));
- pl.wrap = argBool(a, "wrap", pl.wrap);
- setDocumentPattern(doc, pat);
- return {true, pat.panels[i].name + ": " + slotLabel(pl.slot)};
- }});
reg.add({"garment_export",
"Garments: write the pattern at real size for sewing: svg (sewing and cutting lines, notches, grain "
"lines, names, a 50 mm scale square; print at 100%) or dxf (outlines in mm).",
@@ -330,12 +294,7 @@ void registerGarmentCommands(CommandRegistry& reg) {
c.c2 += shift;
}
}
- const size_t first = pat.panels.size();
pat.panels.insert(pat.panels.end(), panels.begin(), panels.end());
- Pattern added;
- added.panels.assign(pat.panels.begin() + long(first), pat.panels.end());
- autoSlots(added);
- std::copy(added.panels.begin(), added.panels.end(), pat.panels.begin() + long(first));
setDocumentPattern(doc, pat);
return {true, "Imported " + std::to_string(n) + " panels" + (error.empty() ? "" : " (" + error + ")")};
}});
diff --git a/tests/test_garment.cpp b/tests/test_garment.cpp
index d7f77ac7..bfbf45f1 100644
--- a/tests/test_garment.cpp
+++ b/tests/test_garment.cpp
@@ -3,7 +3,7 @@
//
// Garments (core/Garment.h): pattern panels, even triangulation, seams that weld into one consistently oriented
// garment (a T-shirt sewn from its template is a single surface with exactly four openings: hem, neck, two
-// sleeves), the arrangement around a body, project and file round trips (SVG, DXF), the SVG reader against
+// sleeves), the flat rest shape, project and file round trips (SVG, DXF), the SVG reader against
// hostile input, and the garment_* commands.
#include "TestHarness.h"
@@ -74,16 +74,6 @@ Topology topology(const Mesh& m) {
return r;
}
-// A w x h x d box centred on the origin (finely divided, so the body analysis has vertices to read).
-Mesh makeBox(float w, float h, float d) {
- Mesh m = makeCube(12, 2.0f);
- AABB b;
- for (const glm::vec3& p : m.positions) b.expand(p);
- for (glm::vec3& p : m.positions) p = (p - b.center()) / b.extent() * glm::vec3(w, h, d);
- m.rebuildTopology();
- return m;
-}
-
std::string readAll(const std::string& path) {
std::ifstream f(path, std::ios::binary);
std::stringstream s;
@@ -147,9 +137,10 @@ TEST(garment_sewn_tshirt_welds_into_one_oriented_surface) {
CHECK(triangulatePattern(pat, m, error));
// One link per point along each seam, both sides the same count.
CHECK(!m.links.empty());
- std::vector<glm::vec3> placed, rest;
- placePattern(pat, m, defaultBody(), placed, rest);
- const Mesh flat = garmentToMesh(m, placed, 0.0f);
+ std::vector<glm::vec3> rest;
+ flatRest(m, rest);
+ CHECK(rest.size() == m.vertexCount() && std::abs(rest[0].x - m.flat[0].x * 0.001f) < 1e-6f && rest[0].z == 0.0f);
+ const Mesh flat = garmentToMesh(m, rest, 0.0f);
CHECK(flat.triangleCount() == m.triangles.size());
const Topology t = topology(flat);
CHECK(t.manifold);
@@ -162,7 +153,7 @@ TEST(garment_sewn_tshirt_welds_into_one_oriented_surface) {
std::set<uint32_t> groups(flat.facegroups.begin(), flat.facegroups.end());
CHECK(groups == std::set<uint32_t>({1, 2, 3, 4}));
// Thickened: closed (no border at all) and still consistently oriented.
- const Mesh thick = garmentToMesh(m, placed, 2.0f);
+ const Mesh thick = garmentToMesh(m, rest, 2.0f);
const Topology tt = topology(thick);
CHECK(tt.manifold && tt.consistent && tt.borderLoops == 0);
CHECK(thick.vertexCount() == 2 * flat.vertexCount());
@@ -176,79 +167,15 @@ TEST(garment_flipped_seam_is_reported_and_twists) {
GarmentMesh m;
std::string error;
CHECK(triangulatePattern(pat, m, error));
- std::vector<glm::vec3> placed, rest;
- placePattern(pat, m, defaultBody(), placed, rest);
- CHECK(!topology(garmentToMesh(m, placed, 0.0f)).consistent);
-}
-
-TEST(garment_panels_are_placed_around_the_body_facing_out) {
- const Pattern pat = tshirtPattern();
- GarmentMesh m;
- std::string error;
- CHECK(triangulatePattern(pat, m, error));
- // A capsule-ish body: a tall box torso with arms out (T pose), 1.75 m.
- Mesh body = makeBox(0.34f, 0.6f, 0.22f);
- for (glm::vec3& p : body.positions) p += glm::vec3(0, 1.1f, 0);
- Mesh arms = makeBox(1.4f, 0.1f, 0.1f);
- const size_t base = body.positions.size();
- for (glm::vec3 p : arms.positions) body.positions.push_back(p + glm::vec3(0, 1.36f, 0));
- for (glm::uvec3 t : arms.triangles) body.triangles.push_back(t + glm::uvec3(uint32_t(base)));
- Mesh legs = makeBox(0.3f, 0.8f, 0.2f);
- const size_t base2 = body.positions.size();
- for (glm::vec3 p : legs.positions) body.positions.push_back(p + glm::vec3(0, 0.4f, 0));
- for (glm::uvec3 t : legs.triangles) body.triangles.push_back(t + glm::uvec3(uint32_t(base2)));
- body.rebuildTopology();
- const BodyFrame f = analyzeBody(body);
- CHECK(f.arms);
- CHECK(std::abs(f.torsoHalfWidth - 0.17f) < 0.03f);
- CHECK(f.torsoFrontZ > 0.09f && f.torsoBackZ < -0.09f);
- CHECK(f.leftArmDir.x > 0.9f && f.rightArmDir.x < -0.9f);
- std::vector<glm::vec3> placed, rest;
- placePattern(pat, m, f, placed, rest);
- CHECK(placed.size() == m.vertexCount() && rest.size() == m.vertexCount());
- // Front in front of the chest, back behind it, sleeves out along the arms.
- auto mean = [&](uint32_t panel) {
- glm::dvec3 s(0.0);
- for (uint32_t v = m.panelFirstVertex[panel]; v < m.panelFirstVertex[panel + 1]; ++v) s += glm::dvec3(placed[v]);
- return glm::vec3(s / double(m.panelFirstVertex[panel + 1] - m.panelFirstVertex[panel]));
- };
- // (wrapped half-way round, so their middles are off the chest and back, their sides beside the torso)
- auto extremeZ = [&](uint32_t panel, bool front) {
- float z = front ? -1e9f : 1e9f;
- for (uint32_t v = m.panelFirstVertex[panel]; v < m.panelFirstVertex[panel + 1]; ++v)
- z = front ? std::max(z, placed[v].z) : std::min(z, placed[v].z);
- return z;
- };
- CHECK(mean(0).z > f.centerZ && extremeZ(0, true) > f.torsoFrontZ + 0.02f);
- CHECK(mean(1).z < f.centerZ && extremeZ(1, false) < f.torsoBackZ - 0.02f);
- CHECK(mean(2).x > f.torsoHalfWidth && mean(3).x < -f.torsoHalfWidth);
- // Triangles face away from the body: outward from the torso axis or the arm's axis.
- int out = 0, total = 0;
- for (uint32_t t = 0; t < m.triangles.size(); ++t) {
- const glm::uvec3 tri = m.triangles[t];
- const glm::vec3 a = placed[tri.x], b = placed[tri.y], c = placed[tri.z];
- const glm::vec3 n = glm::cross(b - a, c - a), ctr = (a + b + c) / 3.0f;
- const uint32_t panel = m.panelOf[tri.x];
- glm::vec3 radial;
- if (panel < 2) radial = glm::vec3(ctr.x - f.centerX, 0, ctr.z - f.centerZ);
- else {
- const glm::vec3 s = panel == 2 ? f.leftShoulder : f.rightShoulder;
- const glm::vec3 d = panel == 2 ? f.leftArmDir : f.rightArmDir;
- radial = (ctr - s) - glm::dot(ctr - s, d) * d;
- }
- out += glm::dot(n, radial) > 0.0f;
- ++total;
- }
- CHECK(out > total * 95 / 100);
- // The rest shape is the flat pattern, metres.
- CHECK(std::abs(rest[0].x - m.flat[0].x * 0.001f) < 1e-6f && rest[0].z == 0.0f);
+ std::vector<glm::vec3> rest;
+ flatRest(m, rest);
+ CHECK(!topology(garmentToMesh(m, rest, 0.0f)).consistent);
}
TEST(garment_pattern_round_trips_json_and_project) {
Pattern pat = tshirtPattern(1000.0f, 650.0f);
pat.particleDistance = 12.0f;
pat.fabric = "denim";
- pat.panels[2].place.offset = {0.01f, -0.02f, 0.005f};
pat.seams[3].flipped = true;
Pattern back;
std::string error;
@@ -455,7 +382,7 @@ TEST(garment_edits_keep_seams_and_shapes) {
// Mirrored copy: the other arm.
Pattern t = tshirtPattern();
const uint32_t c = mirroredCopy(t, 2, "Extra");
- CHECK(t.panels[c].place.slot == Slot::RightArm && t.panels[c].name == "Extra");
+ CHECK(t.panels[c].name == "Extra" && t.seams.size() == tshirtPattern().seams.size()); // (no seams added)
}
TEST(garment_triangulates_quickly) {
@@ -486,7 +413,6 @@ TEST(garment_commands_make_sew_and_export) {
CHECK(r.ok); // the front hem is free
CHECK(reg.execute(doc, "garment_set", {{"particle_mm", 20.0}, {"fabric", std::string("silk")}}).ok);
CHECK(!reg.execute(doc, "garment_set", {{"fabric", std::string("tweed")}}).ok);
- CHECK(reg.execute(doc, "garment_place", {{"panel", std::string("Pocket")}, {"slot", std::string("front")}, {"z", 0.01}}).ok);
const std::string svg = tempPath("garment_cmd.svg"), dxf = tempPath("garment_cmd.dxf");
CHECK(reg.execute(doc, "garment_export", {{"path", svg}}).ok);
CHECK(reg.execute(doc, "garment_export", {{"path", dxf}}).ok);
@@ -497,8 +423,6 @@ TEST(garment_commands_make_sew_and_export) {
CHECK(r.ok && r.message.find("Imported 5 panels") != std::string::npos);
Pattern got;
CHECK(documentPattern(doc, got) && got.panels.size() == 5);
- CHECK(got.panels[1].place.slot == Slot::Back && got.panels[2].place.slot == Slot::LeftArm &&
- got.panels[3].place.slot == Slot::RightArm);
CHECK(reg.execute(doc, "garment_clear").ok && !documentPattern(doc, got));
std::remove(svg.c_str());
std::remove(dxf.c_str());