Skip to content

Add UV maps to the built-in primitives - #659

Open
Micheus wants to merge 7 commits into
dgud:masterfrom
Micheus:mv/add-uv-to-primitives
Open

Micheus wants to merge 7 commits into
dgud:masterfrom
Micheus:mv/add-uv-to-primitives

Conversation

@Micheus

@Micheus Micheus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Changed the primitive creation code to generate ready-to-use UV coordinates.

UV generation can be disabled per primitive or globally through the new
"Create UV Coordinates for New Primitives" option available under
Preferences -> Advanced. It can also be disabled from the primitive creation
dialog by unchecking the "Create UV Coordinates" option.

The following primitives now generate UV layouts by default: plane, cube,
n-gon, cylinder, tube, gear, pie, oblong, sphere, cone, torus, knot,
spiral, spring, thread, grid, tetrahedron, octahedron, octotoad,
dodecahedron, icosahedron, geodome, and text.

To group the helper functions, a new shared module, wings_shapes_uv, was
created:

  • Layout helpers shared by the core and the plugins: strip unfolding of wall
    grids, cap projection, unfolding of flat polyhedra with coplanar faces merged,
    azimuthal pieces for spherized geodomes and row packing of islands;
  • create_uv_dlg/0 returns the dialog item used by every primitive.

The code adjust the UV data in case the object can be rounded, like the Cube.

NOTE:

  • Added UV coordinates generation to the primitives creation, which can be
    disabled in Preferences -> Advanced or in each primitive dialog. Thanks to RV3.

- Added UV coordinates to Various Planes: bottom and sides unfolded
  like an opened box, top as a separate island;
- Added UV coordinates to Torus, proportional to the real lengths of
  the ring and of the tube section;
- Added UV coordinates to Torus Knot, Spiral and Spring, proportional
  to the real lengths, with the body cut near the middle into two
  stacked strips;
- Added UV coordinates to Thread: sides as a strip, end caps as polygons;
- Scaled the end caps of Spiral, Spring and Thread by their area to
  follow the texture scale of the body;
- Added prm_uv_unfold, a support module shared by the primitives:
  layout/3 unfolds grid walls into strips with the real lengths and
  projects caps and flat parts, lengths/4 measures a grid, cap_radius/2
  and cap_face/3 draw a cap with the real area, cross_scale/1 and
  cross/4 unfold a box as a cross;
- Added UV coordinates to Cylinder, Tube, Gear and Pie: walls unfolded
  face by face (cones and frustums keep their shape), caps projected;
- Added UV coordinates to Oblong: bevel faces hang from the wall column
  by column; the columns of the inner contour of a void oblong that
  would overlap are cut as islands of their own;
- Added UV coordinates to Cube (opened box cross with the real
  proportions; six separate sides when spherized) and to N-Gon;
- Changed Various Planes to the same opened box cross, with the top in
  the middle and the sides with the real thickness;
- Changed Torus, Torus Knot, Spiral, Spring and Thread to use the shared
  helpers; tolerances standardized on ?EPSILON;
- Added the primitive_uv preference (Advanced tab) with the default
  state of the Create UV coordinates option of the primitive dialogs;
- Added the Create UV coordinates option to the dialogs of Cylinder,
  Oblong, Cube, N-Gon, Various Planes, Torus, Torus Knot, Spiral,
  Spring and Thread;
- Moved the UV support module of the primitives to the core as the new
  wings_shapes_uv, used by wings_shapes and by the primitive plugins.
  It was also added island/2, pack/2 and fan/2;
- Added UV coordinates to Sphere (one strip from pole to pole with the
  real distances between the rings), Cone (sides unfolded as a sector,
  base projected) and Grid (opened box cross), with the Create UV
  coordinates option in their dialogs;
- Added wings_shapes_uv:unfold/2, which unfolds a mesh of flat faces
  through their edges, breadth first, leaving a face that would overlap
  for another neighbor or for a new island;
- Added UV coordinates to Tetrahedron, Octahedron, Octotoad,
  Dodecahedron and Icosahedron, each one unfolded as a single net, with
  the Create UV coordinates option in their dialogs;
- Added wings_shapes_uv:azimuthal/2 (the azimuthal equidistant
  projection of a patch of a sphere around its center) and the packing
  of the islands in rows (pack/2);
- Added UV coordinates to GeoDome, with the Create UV coordinates
  option in its dialog: a spherized one is cut along the edges of the
  base polyhedron, its faces in pairs across their most horizontal edge
  when the pair fits in a hemisphere; a flat one is unfolded like the
  polyhedron, its coplanar faces grouped as one piece; the inside of a
  half-dome makes islands of its own;
- Added the "Create UV coordinates" option to the Text dialog,
  initialized from the primitive_uv preference;
- Projected top and bottom faces of each glyph as islands at real size;
- Unfolded the side walls of each outline into strips with real edge
  lengths, cut at the sharpest corners when longer than the text;
- Packed all islands in rows inside the 0..1 UV space;
- Returned the UV table in #e3d_mesh.tx and the per-face indices in
  #e3d_face.tx; the mesh is unchanged when the option is off;
@Micheus

Micheus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author
Primitives-uv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant