GarmentCode: Programming Parametric Sewing Patterns

Garment modeling is an essential task of the global apparel industry and a core part of digital human modeling. Realistic representation of garments with valid sewing patterns is key to their accurate digital simulation and eventual fabrication. However, little-to-no computational tools provide support for bridging the gap between high-level construction goals and low-level editing of pattern geometry, e.g., combining or switching garment elements, semantic editing, or design exploration that maintains the validity of a sewing pattern. We suggest the first DSL for garment modeling -- GarmentCode -- that applies principles of object-oriented programming to garment construction and allows designing sewing patterns in a hierarchical, component-oriented manner. The programming-based paradigm naturally provides unique advantages of component abstraction, algorithmic manipulation, and free-form design parametrization. We additionally support the construction process by automating typical low-level tasks like placing a dart at a desired location. In our prototype garment configurator, users can manipulate meaningful design parameters and body measurements, while the construction of pattern geometry is handled by garment programs implemented with GarmentCode. Our configurator enables the free exploration of rich design spaces and the creation of garments using interchangeable, parameterized components. We showcase our approach by producing a variety of garment designs and retargeting them to different body shapes using our configurator. Project page: https://igl.ethz.ch/projects/garmentcode/


INTRODUCTION
"Instead of making people want what we made, we will make what they want".This motto is one of the motivations behind product configurators and other services that aim to create fashion products tailored to the needs of individual customers.In stark contrast, the fast-fashion industry focuses on mass-production of a variety of designs in standard sizes, relying on trends and statistics of body shapes.The customers are left to choose from available designs and standardized sizes, which often do not fit their body shape.This results in customer dissatisfaction, as well as the production of dead stock, which intensifies the negative impact of the garment industry on the climate [Bick et al. 2018].Unfortunately, the creation of custom-made garments is an expensive, labor-intensive process, unattainable for most people.Recent years saw launches of services for made-to-order clothes of popular garment types, such as Amazon t-shirts [Amazon 2023] and Unspun jeans [Unspun 2023], offering a middle ground between the two extremes mentioned above.These services allow making some limited adjustments to pre-defined designs and producing garments on demand according to the customer's individual body shape.However, extending such services to general garment designs remains a challenge.Current production-grade tools are oriented towards creating single designs: tools like Clo3D [CLO Virtual Fashion 2022] do not support creating parametric garments.Existing research works on alternative garment modeling tools either do not take sewing patterns into consideration or do not come close to supporting the required complexity, see Tab. 1.
Table 1.Comparison of GarmetCode with baseline systems.Here, "Definition" means the ability to specify a single sewing pattern, "Tools" refer to instruments supporting pattern construction, "Modular construction" enables specifying garment parts as independent modules and constructing new designs by part combinations, "Continuous" and "Categorical" are parameters with corresponding value types, while a "Dependent" parameter's value depends on other parameters, allowing for complex parameterization and resolution of parameter value conflicts.Commercial CAD tools like Clo3D [2022] do not support true parameterization while existing parametric garment systems [Korosteleva and Lee 2021] support only limited types of parameterization and do not provide any modeling tools; neither of them fully supports modularity.*Limited support.

Garment modeling
Industry-grade tools for garment modeling, such as Clo3D [2022], rely on artists manually drawing and adjusting sewing pattern shapes.Such tools enable the creation of complex garments, but the design process is often tedious.Support for semantic parameterization is very limited: Clo3D provides only one pattern parameterized by body measurements -a bodice, and it is non-extensible with a fixed parameter set.The modular configurator is akin to categorical parameterization for component combination, but it offers a fixed set of component types (upper body, sleeve, collar, cuff) and has only one hierarchy level, and no other parameterizations are supported (Tab.1).Alternative methods for garment modeling are a subject of ongoing research: for example, editing a garment model in 3D, and automatically readjusting [Bartle et al. 2016] or inferring a sewing pattern [Liu et al. 2018;Meng et al. 2012;Pietroni et al. 2022;Wang et al. 2009;Wolff et al. 2023] corresponding to the 3D garment design.Another inspiring line of work aims to maximally reduce the modeling effort by computing 3D garment models from designs sketches [Chowdhury et al. 2022;Fondevilla et al. 2021;Li et al. 2018;Wang et al. 2018], reconstruct sewing patterns from images [Jeong et al. 2015;Yang et al. 2018], or 3D capture [Bang et al. 2021;Chen et al. 2015;Hasler et al. 2007;Korosteleva and Lee 2022].However, all these methods focus on producing a single garment.
GarmentCode offers an alternative perspective on garment modeling, offering a design toolkit for parametric sewing patterns, which allow for fast and convenient exploration of a created design space.Moreover, it offers capabilities to explicitly condition the design on body measurements.Working in the space of sewing patterns ensures controllable and fabrication-plausible garment designs at each stage of the construction process.

Garment modeling at scale
The rise of deep learning sparked an interest in data-driven techniques in many domains, including various tasks related to garments, such as virtual try-on, modeling, and neural simulation, hence creating a unique demand to generate garment designs at scale to be used in synthetic datasets for training.Some of the works in the area [Bertiche et al. 2020;Chen et al. 2015] rely on the combinatorial effect of constructing designs from a set of sub-components, such as multiple options for sleeves, upper body, and lower body garments.In these works, the combinations are performed on 3D geometry, which may result in physically implausible 3D models.These approaches do not provide corresponding sewing patterns.
Other works [Jiang et al. 2020;Korosteleva and Lee 2021;Wang et al. 2018] rely on sampling designs from a set of custom parametric sewing pattern templates, varying the continuous style parameters like length and width of garment elements.Korosteleva and Lee [2021] provide a framework for describing garment templates, but do not allow defining discrete parameters, or parameter dependencies, nor support for base sewing pattern description, as indicated in Tab. 1, rendering it hard to use for complex designs.GarmentCode combines continuous and discrete approaches to design variation into one framework, allowing creating garment design templates with interchangeable components and flexible parameterizations of style and body shape.Different helper operators (Sec.3.6) support the construction process to reduce the workload.

Garment retargeting
The process of retargeting a garment from one body shape to another is usually performed manually, with leading industry tools like Clo3D [CLO Virtual Fashion 2022] providing support in storing (arbitrary) displacements, specified by designers for each vertex of garment panels individually, for each size.However, a number of research works have been exploring automatic solutions to this problem.Optimization-based approaches [Ait Mouhou et al. 2022;Brouet et al. 2012;Fondevilla et al. 2021;Lee and Ko 2018;Lee et al. 2013;Wang 2018] transform the garment geometry to reproduce design parameters such as fit, proportionality and overall design shape on a new body model, offering impressive results.In recent years, data-driven approaches for transferring garments across different shapes [Bertiche et al. 2020;Shi et al. 2021;Tiwari et al. 2020], or both shapes and poses [Corona et al. 2021;Lal Bhatnagar et al. 2019;Ma et al. 2020;Santesteban et al. 2021] have gained popularity.Most of these works represent garments as a displacement map over a body model, which helps disentangle design from body shapes, while [Corona et al. 2021] utilizes an implicit function as a more general approach to describe various garment styles.Unlike the approaches mentioned above, GarmentCode embeds the retargeting capability already at the sewing pattern modeling stage, which both reduces the need for manual editing and allows for controllable results reflecting the intention of the designer, which is not offered by the automatic methods mentioned above.The work of Wang et al. [2003] provides control over the design transfer optimization process by allowing to relate design and body feature points in 3D.Some recent works [Jin et al. 2023;Wang et al. 2022] present case studies of one or two garment templates implemented with body shape parametrizations.Although they do not propose DSL-like tools to support the implementation of a general garment, these works demonstrate an interest in the fashion field in programmable sewing patterns.Works like [Umetani et al. 2011;Vidaurre et al. 2020;Wang et al. 2018;Yang et al. 2018] build their methods around parameterized base garments.Our work contributes towards a unified framework for creating such designs.

Procedural modeling and CAD DSL
Coding shapes like programs is not a novel idea.There are a number of programming languages developed for traditional solid CAD (Featurescript [Onshape 2023], OpenSCAD [Kintel, Marius and Wolf, Claire 2023]) with rich toolkits supporting shape definition (e.g., collections of standard shapes), editing (e.g., extrusion, boolean operations), and parameterization.Procedural modeling methods for buildings [Haegler et al. 2010;Müller et al. 2006;Schwarz and Müller 2015], city landscapes [Birsak et al. 2022;Parish and Muller 2001] and plants [Aono and Kunii 1984;Lane and Prusinkiewicz 2002;Lindenmayer 1968;Makowski et al. 2019;Oppenheimer 1986] provide tools (e.g., shape grammars) to code highly parametric generative models of the target objects in a variety of styles, with built-in editing options (e.g., varying the number of floors and windows in a building).Similar approaches emerge for furniture [Jones et al. 2020;Pearl et al. 2022], providing an interesting new angle on reconstruction problems.Due to the unique coupling of the 2D base representation with highly deformable behavior in 3D, garment engineering presents its own challenges and requires targeted modeling tools, but the research in this direction is limited.In addition to works on synthetic garment datasets described above, research on procedurally generated knitting instructions [Jones et al. 2022] computes machine-knittable patterns of given garment models.GarmentCode aims to fill the gap in the procedural generation of sewing pattern designs.We "translate" some of the tools of traditional CAD DSL to the garment domain, e.g., our edge loop definition for panels mirrors the structure of parametric boundary representations, and component copy operations are akin to linear and circular patterning in CAD.At the same time, we introduce component abstraction, tools for component stitching, and 2D-3D coupling, unique to garments.

ARCHITECTURE 3.1 Overview
Approaching sewing pattern modeling with a programming-based paradigm, especially when built upon the basis of existing generalpurpose programming languages like Python, immediately provides a number of benefits, such as performing auxiliary computations (examples in Sec.3.6.3and Appendix A), free-form parametrization of geometry, and leveraging existing libraries built by the community.None of these benefits are available in existing design representations, be it visual [CLO Virtual Fashion 2022] or text-based parametric approaches [Korosteleva and Lee 2021].However, specifying pattern geometry as a program without the support of structures and tools designed to handle garment-specific properties is tedious and   inefficient, akin to the dictionary-based specification of the existing text-based approach [Korosteleva and Lee 2021], requiring explicit definitions of each panel vertex and cross-referencing individual edges for stitch specification ("flat pattern representation"), with no support for element reuse beyond basic language capabilities.Hence, the goal of GarmentCode is to provide a domain-specific language for specifying parametric sewing patterns and allowing easy reuse of defined garment elements to compose new garments as modular programs, enabling programming efficiency and complexity management.Specifically, we are bringing the principles of encapsulation and abstraction from the object-oriented programming (OOP) paradigm to garment construction.OOP has proven to be extremely efficient when it comes to building large complex systems across application areas, and we would like to leverage that efficiency when representing the complexity of garment design spaces.A panel, a stitched combination of panels, or a higher-level combination of components all define a garment component object, which encapsulates its particular geometry and only exposes an abstract semantic interface, implemented as a subset of edges of panels that comprise the component.Interfaces of two individual components can be connected together (abstract stitch) to form a higher-level component, and any components that implement the same set of interfaces (in our implementation, interfaces identified by the same names) can be used interchangeably regardless of the differences in their encapsulated geometry, enabling modular construction.
To summarize, the GarmentCode architecture allows pattern description through the following basic types: Edge, EdgeSequence, Component, Panel (as a special type of Component), and Interface, as illustrated in Fig. 3. Supporting the process, a variety of tools are implemented: a factory for typical edge sequences (e.g., dart shape), specification of curved edges with target properties, projecting an open edge sequence on a corner or an edge, copy operators, normal evaluation for automatic right/wrong side definition, placing stitched components next to each other.To support downstream processing, GarmentCode also implements unfolding the abstract stitch definition into a flat pattern representation and serialization of patterns into files.
Below we describe the elements that comprise our architectural approach in detail.

Component.
A component is an abstract class providing a framework to describe a compound garment or a garment element and holds some component processing methods (serialization, rotation, translation, mirroring, etc.).Any component should contain the following attributes: • A set of subcomponents; • Stitches -a list of stitching rules describing how the subcomponents should be connected (see Sec. 3.3).• A set of interface objects that describe how other components can connect to this one (see Sec. 3.3.1).
Apart from specifying these attributes, a component construction process may contain instructions for modifying subcomponents, e.g., projecting an interface -a selection of edges from subcomponent's panels -of one component onto another, or smart copies, as demonstrated in Fig. 2.

Panel.
A panel is a "leaf" component with special structure, so that it can act as a subcomponent, but also specify the panel geometry.Following the work of Korosteleva and Lee [2021], Gar-mentCode defines a panel as a closed piecewise smooth curve represented as a sequence of directed edges organized in a loop, as well as 6D placement parameters (rotation and translation).The latter is needed to correctly place the panel around the body but defaults to zero translation and rotation, and can be left to be set by higherlevel components.These attributes define a panel component, in addition to the standard component attributes, namely interfaces and stitches.Note that a panel may contain stitches between its own edges, e.g., if the panel contains darts, as in the fitted bodice panel in Fig. 2.

3.2.3
Edges.An edge is an elementary building block of panels in a sewing pattern.Every edge describes an oriented curve segment.Specifically, GarmentCode supports straight line segments, circular arcs, and quadratic and cubic Bézier splines as edges.This set is flexible and representative enough to model a variety of panel geometries, while ensuring smoothness and computational feasibility.
Edges are represented by their start and end vertices as attributes (the vertex coordinates are defined in 2D).Bézier curves additionally hold the coordinates of the their control points, while circular arcs store the signed distance of the midpoint of the arc to the straight line connecting the start and end vertices.Building upon the ideas of [Korosteleva and Lee 2021], all controls are specified in a local coordinate system of an edge: the straight segment connecting the edge endpoints is used as the unit horizontal axis, and the left perpendicular is the vertical axis.Such relative representation is invariant to edge translation and rotation, and preserves the curvature with uniform scaling, allowing to perform these operations on all types of edges only though vertex manipulation.
Working with edges is supported by a variety of routines.For simplicity of use, GarmentCode supports conversion of internal representations from and to standard ones: absolute control point coordinates for Bézier curves, and for circular arcs, the standard three-point representation or the desired radius with flags indicating one of the four arc options.

Edge sequences.
An edge sequence specifies an ordered list of edges.An edge sequence used in panel definition must have all its edges chained one after another and into a loop, but other types of edge sequences might be used in other contexts, for example, in interfaces edges may not be chained together nor form a loop.To manipulate edge sequences conveniently, GarmentCode implements them as a variation of Python list type and thus supports indexing and slicing, appending, removals, and insertions, as well as domain-specific geometry manipulation methods: translation, rotation, scaling, and reflection around an arbitrary axis.

Stitches
The GarmentCode approach to stitch representation is one of the key elements that enable modular component construction.We aim to keep the stitching abstracted from the internal structure of individual components and rather reflect a semantic connection between high-level components.This allows substituting one component in the connection by another with the same semantic meaning despite differences in underlying geometry -enabling the interchangeability property.This behavior is realized by defining an abstract stitch as a connection between component-defined interfaces instead of a connection between panels' edges, as in flat sewing pattern representations.For example, in composite garments, the bottom of a bodice connects to the top of an under-waist garment.The same abstract stitch would describe a connection of a fitted bodice to a flared skirt, as in a 1950s dress, or a basic straight bodice to pants in a jumpsuit (see Fig. 7 for patterns of these examples).

3.3.1
Interface.An interface describes how and where a particular component can be connected with.An interface contains a collection of edges of panels that can connect to another component in an abstract stitch.An interface can be constructed directly as a subset of panel edges (usually in panel components), or from reusing or combining interfaces of subcomponents.Thus, a single interface can contain multiple edges from multiple different panels (in contrast to 1-1 edge stitches in [Korosteleva and Lee 2021]).One component may have several interfaces.
In addition to stitches, interfaces may be useful for other purposes.For example, in sleeves, an interface specifies a projecting shape for correct modification of the bodice panel, which differs from the shape of the sleeve panel edges themselves.In Fig. 4, an Armhole is part of a Sleeve and defines the projecting shape, and Fig. 5 shows the differences and the projection result up close.
3.3.2Stitching rule.In our implementation, an abstract stitch is specified simply as a pair of interfaces, wrapped in a stitching rule object.The wrapper encapsulates the processing of the stitch flattening (see below), performed at stitch declaration time.
3.3.3Flattening stitch representation.While abstract stitches are convenient for modeling, downstream processing tasks like simulation usually require a flat representation of stitches as edge-to-edge connection instructions.Unpacking the hierarchy of interfaces is straightforward, however, oftentimes one or both interfaces participating in a stitch contain multiple edges.Breaking such a stitch down to edge-to-edge instructions requires additional processing.To perform this conversion, GarmentCode automatically generates additional vertices on the underlying panels to match the number of edges in the two connecting interfaces.Once the subdivision is completed, the set of resulting one-to-one stitches can then be used as a flattened representation.At the current stage of development, we use a simplifying assumption that each edge participates in no more than one stitch.
The process of generating the needed vertices is as follows.First, we note that the total length of edges in the interfaces on either side may not match, e.g., in stitches with gather, as in the Regency dress in Fig. 1.To accommodate for non-matching lengths of interfaces, the edge lengths are represented as fractions of the total lengths of an interface instead of being used directly.The fractions from one of the interfaces are projected onto another interface to generate additional vertices whenever the projections fall outside of existing ones with some tolerance, and then the process is repeated in the other direction.The edge sequences in the interfaces are assumed to be aligned in the expected connection order.
Our stitch flattening algorithm is rather straightforward, and similar algorithms are likely to be behind many-to-many stitch features in commercial visual CAD like CLO3D [CLO Virtual Fashion 2022].

Parameterization format
While the opportunity for defining parameters emerges naturally from using a programming-based paradigm, GarementCode provides configuration formats to support this feature further.In Gar-mentCode, we propose separating body and style parameters into two sets, with body parameters containing the measurements of the current avatar, and style parameters specifying not only the particular values but also the possible value ranges and type (numerical, boolean, or categorical) for each parameter, to allow for design sampling.
Since some of the useful body measurements can be derived from others, GarmentCode provides an abstract class for loading body configuration files, with a separate method for the specification of formulas for derived parameters, which can be implemented in the application through a subclass.For example, in our prototype garment configurator, we use the waist level from the ground for positioning the garments, which is calculated from the body height, height of the head, and the usual waistline measurement from the nape of the neck to the waist.The calculation of derived design parameters, as well as the handling of parameter value conflicts, are usually component-specific and hence should be defined by the creators at the appropriate level.

Helpers
We propose severalroutines designed to simplify the construction of sewing patterns.It is worth noting that the presented algorithms, when needed, were chosen for their simplicity while providing reasonable quality, however, better or more efficient solutions are likely to exist.All calculations are performed at evaluation time.3.6.1Typical edge sequences.We implement shortcuts to create typical edge sequences, which include creating a loop of straight edges from a set of vertices, edge subdivision for all edge types (adding vertices inside an existing edge specified by relative distances), and creating a triangular dart shape, specified by desired dart width and depth.3.6.2Defining curve edges.In practice, curved edge design is often driven by certain requirements, rather than by the placement of control points.GarmentCode implements two optimization-based routines to specify Bézier curves: • Specifying a quadratic Bézier curve with the highest point at a particular location, used e.g. in pencil skirts and pants to correctly hug the hips in a manner transferable across different bodies; • Smoothly adjusting a cubic Bézier curve to match the desired tangent directions at the edge ends while preserving the curve lengths, used in defining inverted sleeve opening shapes for curve-based sleeves.
The second routine is described in Appendix A as part of the sleeve inversion algorithm.

Projection operators.
Oftentimes when there is a need to connect two panels together, we wish the interface on one panel to be in stylistic or functional correspondence with the geometry of the other, e.g. when connecting a sleeve panel with a bodice panel.Describing and maintaining such correspondence across independent panels and components would break the encapsulation principle, so instead GarmentCode offers projection operators to transfer the shape defined in a one-panel component onto another panel.The transferred shape may be part of a panel geometry, or be a construction geometry defined specifically for use in projection, implemented as an interface.Such a solution ensures that either of the panels can be easily modified or substituted, without the need to manually accommodate the changes in the second panel, supporting our target plug-and-play garment construction style.An example use of projections is demonstrated in Fig. 2. GarmentCode supports projection on an edge (injection) and projection on a corner for an arbitrary open chained edge sequence as projection shape, and edge or pair of chained edges, correspondingly, as target shapes.Both types support the use of curves in projection shapes, as well as in the target edges, and hence are formulated as optimization problems.
In both cases, the goal is to find the points on the target that align with the "opening" (the first and the last vertices in the edge sequence) of projection shapes.The target edges are then split at the found points, and the projection shape is injected in between the found points into the target edge sequence, while the leftover "cuts" are removed.What differs between the two projection types is the process of finding the injection points.Projection on a corner relies on finding the points in the curve parameterization space (for straight edges and circular arcs we use arc length parameterization) whose 2D positions correspond to the projection shape opening: where  1 ,  2 are the edges of the target corner,  1 ,  2 are values in curve parameterization space, and proj_vec = proj.end− proj.start is the vector describing the projecting shape opening.
Projection on edges also acts in curve parameterization space and finds two points that accommodate the projecting shape and are equidistant from the target point of injection  (): where  is the target edge,  is the requested placement of the projecting shape  1 ,  2 are the shifts, all specified in respective curve parameterizations, and proj_vec = proj.end− proj.start is the vector describing projecting shape opening.
In case of projection on an edge, the projecting shape is automatically rotated such that proj_vec aligns with the estimated insertion vector ( ( +  1 ) −  ( −  2 )), following the edge direction.The inserted shape may be reflected over the insertion vector following a user-specified parameter to appear on the other side.Rotation alignment in projection on the corner is left to be specified externally to ensure design flexibility: within certain limits, different rotations of the same shape projected on a corner would produce different but equally valid results.
3.6.4Smart copy.The garment designs often exhibit reflection symmetry w.r.t. the sagittal plane (left-right symmetry), so describing only one of the halves often suffices.To support such a design shortcut, GarmentCode provides a mirroring operator, which reflects a component over a vertical line, including its shape and the location (used in our upper garment components, showcased throughout the paper).For other types of repetitive designs, GarmentCode provides a distribution of components copied along a line or a circle, an example use of which is demonstrated in Fig. 11.
3.6.5Panel normal.The notion of the right and wrong sides of a fabric is represented as the direction of the panel normal (positive orientation corresponding to the "right", usually outwards-facing side).The normal direction is defined by the counterclockwise traversal of edges.GarmentCode can automatically update the edge loop traversal such that the right side of the fabric points outside of the body, under the assumption that a body model is aligned with the axes in the coordinate basis in which the panel's 6D placement is specified.To do so, we evaluate the position of the panel center-ofmass (COM), and for each edge determine whether it traverses the COM on the right or on the left using the cross product of the edge vector from its end to start vertex with the vector from COM to the edge start vertex.The normal is then the prevalent direction of those cross products among the panel edges.If the normal is not oriented outwards of the center of the body, the edge loop is reversed to flip the normal.Large curvature arcs in curve edges may interfere with this process, so we use their linear approximation.We find the extremal points of the curve (furthest away from the straight line of an edge) and use them as new panel vertices, connecting them by straight edges.
In our implementation, the panel normal is adjusted upon every update to the panel's placement, ensuring correct normals throughout.However, updating the normals of all involved panels at the time of component serialization may also suffice.3.6.6Placement support.GarmentCode simplifies the task of correctly manipulating the component placement.First, all placement modifications performed at component level are automatically propagated to subcomponents while preserving their relative placement (that was set on the lower levels of the hierarchy).Second, Garment-Code provides a helper to adjust the translation of one component so that its chosen interface is aligned with another component's interface in 3D, which can be used to align components by their stitches.The helper simply evaluates the 3D centers-of-mass of the edge sequences described by the interfaces, and the modified component's translation is updated by the location difference on the two COMs.The modified component may additionally be shifted outward of the component COM to create a gap between two interfaces.

APPLICATION: GARMENT CONFIGURATOR
We apply the GarmentCode architecture described in Sec. 3 to build a garment configurator.The configurator allows selecting and assembling various high-level components and interactively manipulating their parameters, displaying the resulting sewing pattern.We design a collection of parametric garment components: various styles of skirts, such as flare, godet, pencil, gather, and compound, with the flare skirt implemented with two different topologies; bodice (i.e., components covering the torso, which can be fitted or loose), pants, sleeves (with optional cuffs), and different collar shapes.See Fig. 4.  5. Connecting a sleeve to a bodice.The edges on the sleeve side should create a concave shape compared to the sleeve opening shape on the bodice, so that the sleeve curves away from the body when stitched (see details in Appendix A).Our sleeve component defines a bodice opening shape as an additional interface for correct projection and connection.Fig. 6.Sleeve styles created from the same sleeve component by varying sleeve length, cuff length, and gather parameters Many of these components can represent garments on their own, but an additional meta-component enables combining those elements into complex dresses (Fig. 1) and jumpsuits (Fig. 7).Components are parameterized w.r.t.body measurements (bust size, waist length, etc.), and style features (like lengths of elements).Most of the style parameters are defined to depend on body measurements or each other (e.g., collar width is bound between neck width and shoulder size), which additionally enables body retargeting and ensures pattern validity.
A selection of garments sampled from our parametric template is presented in Fig. 10.An example garment program is provided in Fig. 11.Flexible implementation of our GUI allows any garment programs with the recommended parameterization format to be loaded as GUI with little-to-no tweaks.

Example construction process
Here we describe an example process of constructing a dress in a 1950s style with GarmentCode.This dress requires a definition of a flare skirt, fitted bodice, collars, and sleeves.The process is illustrated in Fig. 2.
A fitted bodice is created to accommodate the natural body curvature and accentuate the waistline; darts are employed to create this effect.Since we assume that the body is left-right symmetric, we start building this piece by defining two quadrilateral panels representing one half of the front and the back of the bodice, following the body measurements (Fig. 2, a).The front panel is wider and longer to accommodate the extra curvature on the chest.We add darts (Fig. 2, b) by projecting a triangular shape onto the side of the front panel, such that the side with a dart is the same length as the back side, and the bottom of the front and back panel, and removing some length from the side as well.The bottom length of both pieces equals half of the body waist measurement.
We combine the bodice component with other components to create an upper garment.First, we define a collar shape and project it onto the inner corners of the front and back panels.Secondly, we take a sleeve component and project a corresponding opening shape onto the outside corners of the front and back panels (Fig. 2, c; Fig. 5).Applying the projection operator makes the bodice design agnostic to the types of sleeves and collars used in this step, hence these components are easily replaceable with other designs.The next step is simply to mirror the upper garment component created so far, as described in Sec.3.6.4.The bottom edges of the final four panels are designated as the interface of this upper component (Fig. 2, d).
We approximate a 1950s-style flare skirt with trapezoid panels replicated multiple times and distributed around the body (Fig. 2, e).The same shape can be achieved with two or even one panel -a section of a circle, but we show a more complex option to demonstrate the capabilities of GarmentCode.The tops of the panels should follow the body waist size, and the bottoms are wider, creating a flare effect.The sequence of the top edges of the skirt panels is designated to be a skirt interface.The final step is to connect the bottom of the upper garment with the top of the skirt, which is done automatically (see Sec. 3.3).

EVALUATION 5.1 Element parameterization
The power of parameterization in garment design can be well demonstrated on a sleeve example Fig. 6.The same building block can produce various sleeve silhouettes, from modern streetwear style to a vintage balloon sleeve, merely by varying a few parameters.The GarmentCode representation and parameterization open up an easy way for experimenting with designs based on human-readable parameters, rather than editing sewing patterns at the low level.

Handling complexity
The convenience of manipulating garments through hierarchical component structure is well-demonstrated through an example of a compound skirt (Fig. 8).Having the base skirts (pencil, flare, gather) and their corresponding parameter spaces defined, creating a compound skirt that uses existing components as layers is trivial: it requires an initialization of the base skirt (hugging the hips), and multiple copies of the skirt type used for the different levels, initializing their size based the bottom size of the one above, connecting their tops to bottoms of previous ones, and using the placing helper for correct alignment.With the base skirts implemented, extending our component library with the compound skirt component takes just 50 lines of code (see skirt_levels.py in supplementary code).Thanks to the component abstraction, it seamlessly integrates into the library: it can be used in place of other skirts or pants by simply adding its class name to the list of supported components in the meta-component parameter range for bottoms types.

Body retargeting
Our garment components are parameterized by body measurements, which makes it easy to fit a garment design on a different body.The parameterizations are introduced in the areas of garments that tightly hug the body, e.g., the waist of flare skirts and pants.The fitted bodice component is fully specified by body measurements (waist and bust circumferences, bust line, waistline, and back width) since its purpose is to accentuate the body curves.Some style parameters are made dependent on the body measurements, e.g., the length of a flare skirt is specified as a fraction of leg length and varies according to the wearer's height.
To demonstrate body retargeting, we take several body shape samples from SMPL [Loper et al. 2015] and manually acquire their body measurements.Fig. 7 shows the retargeting results.A 1950sstyle dress recognizable hourglass silhouette relies on a proper fit of the tailored bodice component.The correct fit of the dress is fully preserved across large body shape variations thanks to the semantic encoding of GarmentCode components.The skirt length varies with the leg length, hence leaving approximately the same part of the leg uncovered in different body shapes.The tight-fitting pants in the jumpsuit and the pencil skirt in the strapless dress successfully adapt to different body shapes and proportions.The bottom of the pencil skirt is parameterized relative to the hip size, enabling the preservation of the defining upside-down triangular silhouette across all body models.

Reproducing a real-world pattern
To evaluate the patterns created with GarmentCode, we reproduce one of the professional garment patterns from Mood Fabrics [2020] by adjusting the parameters of the demo configurator, see Fig. 9.We observe that the overall 3D shape and design intention are well reproduced.However, a number of details vary.Our panel definition excludes inner loops such as diamond darts, resulting in an excessive stitch in the waist area.Without the support for fold lines (both in our system and in the downstream simulator), the sleeve panel needs to be defined as two.Since we currently do not support stitching multiple layers of fabric, we can only model one-sided cuff and turtle neck components, whereas in the original pattern these are double-sided, with half of the panel folded inside.
Other differences are not dictated by the architectural limitations, but simply by the choices made when designing our example garment components.Our sleeve element uses smoother curves compared to the original pattern, resulting in a mismatch.The difference in lengths between the waist and the hip is distributed between the darts and the skirt sides differently, resulting in misaligned darts.Remaining variations (e.g.side dart width) are simply due to differences in body sizes between our body model and the standard sizing used in the original pattern.The showcased limitations provide inspiration for further development of the GarmentCode system.

DISCUSSION
We introduced a new framework for representing and designing parameterized garments.Our architecture encourages composing garments as hierarchical structures with interchangeable parametric components akin to configurable puzzle pieces.This approach enables exponential growth of design possibilities whenever a new component is added to the collection, expanding the design space, which can be easily explored through semantic parameters with little manual overhead, or sampled when constructing design datasets.
We demonstrated how our framework can be employed to create parametric garment design templates suitable for product configurators or in design samplers for synthetic garment datasets.Our templates offer extended design spaces, garment transfer across different body shapes, and produce valid sewing patterns for each instance, which can be passed on to a physics-based simulator or adapted for fabrication.
Our presented system changes the paradigm of garment construction to programming-based, which does not follow the traditional design workflow, and presents other challenges like the need for explicit specification of vertex coordinates in panels, which may be an obstacle for industry adoption.However, the successful cases of embracing programming in the creative domains, such as solid modeling CAD/DSL systems [Kintel, Marius and Wolf, Claire 2023;Onshape 2023], procedural tools for plans [Makowski et al. 2019], buildings [Müller et al. 2006], or city landscapes [Parish and Muller 2001], and even such widespread fields as web design, give us reason to believe that fashion creators might be willing to acquire the needed programming skills to access unique features GarmenCode provides.Pairing programming-based parametric construction with a visual tool for specifying panel and edge geometry could be an interesting avenue for future work.
Creating a new design tool for garment construction is an ambitious and complex goal.GarmentCode aims to demonstrate the potential of our idea and provides a solid proof-of-concept implementation, but it is not all-encompassing.GarmentCode could be expanded with additional helpers to improve the toolkit: readjusting the edge shape after dart insertion for a smooth connection, adding a curved dart calculator, adding rotation alignment to the placement by stitches, etc.On the architecture level, the simplified definition of a panel does not allow specification of internal loops, hence Gar-mentCode cannot seamlessly represent panels with holes (Fig. 9).The architecture could also be extended to incorporate elements that are sewn on top of a fabric piece, such as pockets and flounces.Likewise, GarmentCode currently has limited support for sharp folds, and more tools are needed to efficiently specify and assemble pleats and smocking patterns.We also wish to further accommodate the differences between sewing patterns for garment fabrication vs. simulation: for example, merging excessively fragmented panels in the final pattern to reduce the number of stitches needed (e.g., removing the central stitch for front and back panels).Representing different stitch appearances in the spirit of [Rodríguez and Cirio 2022] is also an interesting direction to explore.
Finally, there is a considerable variation in sewing pattern geometry even within the basic garment elements, which is not fully represented in our implemented garment components, making it difficult to reproduce real garment designs merely by varying the semantic parameters of the demo configurator (Fig. 9).An additional engineering effort is required to accommodate such variations of real-world patterns.
GarmentCode achieves several considerable advancements through a simple architecture.It is evident that the problem of garment construction is under-explored, and we hope our work will inspire further research on computational support of this important engineering problem.

A CONSTRUCTING CURVED ELEMENTS
One of the advantages of the programming-based paradigm of garment modeling is the ability to utilize computational tools for defining garment elements that are difficult to specify correctly by hand, e.g., when it comes to manipulating smooth curves.Here we elaborate on one such example to complement the experiments presented in the paper.

A.1 Inverting sleeve opening
As shown in Fig. 5, the connection between the sleeve and a chosen bodice block is non-trivial, requiring the shape of the sleeve to be an "inverse" of the shape of the sleeve opening on the bodice in order to correctly wrap around the arm.In addition to these constraints, the shape of the inverse connection on the sleeve defines the rest angle of the sleeve in 3D: the arm angle at which there are neither folds nor tensions in the garment fabric.Smaller angles allow putting arms up more easily and are thus good for activewear, while bigger angles create fewer folds in the armpit zone when the arms are down, hence more suitable for officewear, as shown in Fig. 12.
For sleeve openings based on curves, defining sleeve edges correctly is especially challenging, since the inversion should preserve the length of the edge while following the desired rest angle and maintaining smoothness of connection of sleeve panels.Garment-Code helps with this task.
Our process assumes that the projecting shape for a bodice is defined as a cubic Bézier curve with both control points on one side of the edge.The first step is then to create an initial guess for the inverted sleeve shape: the control point towards the end of the edge is flipped to the other side (flipping the -coordinate in its relative representation), and the edge direction is aligned with an axis perpendicular to zero angle sleeve rest shape.In our implementation, the -axis corresponds to a fully horizontal sleeve, and the perpendicular is the vertical direction.The edge is then rotated by a desired rest angle  .
The second step is an optimization process, in which the edge extension and new positions of curvature control points are optimized s.t. the length of the curve is preserved, while the curve tangents at the endpoints are aligned with the downward direction at the top and the desired sleeve angle at the bottom.The first condition ensures a smooth connection at the top between the front and back sleeve panels, while the second one enables the inversion effect and supports the chosen rest angle.The function to minimize is as follows: where  1 ,  2 are the cubic Bézier control points,  start ,  end are initial edge endpoints,  ( start ,  1 ,  2 ,  end ) is a curved edge with given endpoints and control points,  is the scaling factor of the edge vector  =  end − start , the  0 (•),  1 (•) functions evaluate the curve tangent at the start and the end point of the edge curve, with * 0 ,  * 1 being the target tangent values as described above.Finally,  max (•) evaluates the maximum curvature of the edge and is used to regularize the curve smoothness.
The given process produces a correct sleeve inversion for sleeve openings of arbitrary size and for a desired sleeve rest angle, allowing us to define both as garment style parameters, as is done on our prototype garment configurator.The optimization process is included in the core GarmentCode as an operator.

Fig. 2 .
Fig. 2. Construction of a fitted bodice component and a skirt for 1950s dress style pattern.Dashed arrows denote projection operators; gray arrows show some of the body-related and stylistic parameters of presented components; thick lines on d) and e) show the interfaces of upper garment and skirt components.

Fig. 3 .
Fig. 3. Overview of the elements of a GarmentCode architecture.Highlighted edges on panels correspond to chosen interfaces.The body model serves as a positioning reference.Here and in the figures below we use SMPL female average body model [Loper et al. 2015], unless otherwise specified.
Serialization denotes a conversion of a GarmentCode hierarchical component into a flat sewing pattern representation that can then be passed on to downstream tasks such as cloth simulation.The process is fairly straightforward: GarmentCode recursively converts all panels involved in component construction into a text representation and then gathers them into one file, together with flattened stitching instructions.In this work, we serialize component instances into the open-source JSON file format introduced in [Korosteleva andLee 2021], compatible with their draping pipeline.ACM Trans.Graph., Vol.42, No. 6, Article 197.Publication date: December 2023.197:6 • Korosteleva and Sorkine-Hornung

Fig. 4 .
Fig. 4. Samples of garment components that we design using GarmentCode (stitches are not depicted for clarity).Each component's appearance is conditioned on style parameters and body measurements, some of which are illustrated with gray arrows.*Cuffs for sleeves and pants are the same component, shown twice to demonstrate potential use in both cases.

Fig.
Fig.5.Connecting a sleeve to a bodice.The edges on the sleeve side should create a concave shape compared to the sleeve opening shape on the bodice, so that the sleeve curves away from the body when stitched (see details in Appendix A).Our sleeve component defines a bodice opening shape as an additional interface for correct projection and connection.

Fig. 8 .
Fig. 8. Two design samples from a compound skirt component.With trivial implementation, this component allows combinations of existing skirts and their parametrizations, resulting in complex garment styles.

Fig. 9 .
Fig. 9. Reproducing a production sewing pattern "Birch dress" of MoodFabrics [2020].The MoodFabrics pattern is in grey (top) with the final garment on the right (photo provided by MoodFabrics), and ours is in pink (bottom) with the final garment on the left.Some discrepancies occur simply due to different design decisions and body sizes, while others highlight the limitations of the base GarmentCode architecture, as discussed in Sec.5.4.

Fig. 10
Fig. 10.A selection of design samples from our parametric garment template.The segmentation corresponds to panels and stitches in the respective sewing patterns.

Fig. 11 .
Fig. 11.Example of a garment program written with GarmentCode, showcasing a skirt used in our 1950s dress example.The ThinSkirtPanel class defines a single trapezoid-shaped panel.SkirtManyPanels creates an instance of the panel according to style parameters (desired length, number of panels, and flare, where 1 sun = full circle skirt), and body measurements (waist to condition the top opening, and hips height to condition the length).The panel is then placed, and its copies are distributed on a circle around the body (using distribute_Y() operator) and stitched.The top edges of all panels constitute the interface of a final skirt.

Fig. 12
Fig. 12. T-shirts designed with different rest angles of sleeves (denoted  ) draped in the same pose.Note the differences in how well the fabric follows the arm angle.