Prowl.Unwrapper 0.1.0

dotnet add package Prowl.Unwrapper --version 0.1.0
                    
NuGet\Install-Package Prowl.Unwrapper -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Prowl.Unwrapper" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Prowl.Unwrapper" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Prowl.Unwrapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Prowl.Unwrapper --version 0.1.0
                    
#r "nuget: Prowl.Unwrapper, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Prowl.Unwrapper@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Prowl.Unwrapper&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Prowl.Unwrapper&version=0.1.0
                    
Install as a Cake Tool

Prowl.Unwrapper UV Unwrapper

A mesh UV unwrapper built for the Prowl Game Engine. Given an arbitrary triangle mesh, Prowl.Unwrapper produces a non-overlapping UV atlas suitable for lightmaps, AO bakes, signed-distance bakes, or any other texture-space workflow that needs a clean parametrisation.

The pipeline cleans the input mesh, segments it into roughly developable charts, flattens each chart with LSCM, and packs the charts into the unit square. All in pure C# with no native dependencies.

Performance

Tested on Sponza (262k triangles, the standard glTF sample model) on a desktop CPU:

  Cleanup + half-edge build:   1.2 s
  Chart segmentation:          7.4 s
  LinABF + LSCM solve:         9.1 s
  Atlas packing:               5.1 s
                              ------
  Total:                      22.8 s

Hot paths use SIMD via System.Numerics.Vector<double>, the linear solver is a Jacobi-preconditioned conjugate gradient over a CSC sparse matrix, and chart processing is parallelised across logical cores via Parallel.For. Hash maps for half-edge lookups use a custom open-addressing long -> int table with SplitMix64 mixing, which is roughly 5x faster than Dictionary<long, int> for this workload.

Features

  • Robust geometry preparation

    • Vertex welding with normal-aware splitting (coincident points with opposing normals stay separate)
    • Degenerate triangle removal (zero area, collinear corners)
    • Non-manifold geometry fixer using local edge cutting (Gueziec / Taubin), so dirty real-world meshes work
    • Optional per-corner material UV input used as a seam hint
  • Segmentation

    • Lloyd-style chart growth scored by 3D compactness and developability
    • Hard-edge detection from a configurable dihedral threshold
    • Distortion-aware merging: adjacent chart pairs are trial-flattened and accepted only if mean angular and area distortion stay below the configured thresholds
    • Time-budgeted merge pass for pathological inputs
  • Parametrisation

    • Linear Angle-Based Flattening (LinABF) provides the initial angle field
    • Least Squares Conformal Maps (LSCM) produces the per-chart UVs
    • Two pinned vertices selected from the chart boundary for stable rotation
    • Distortion metrics (mean and worst-case angular + area) reported per chart
  • Packing

    • Convex hull and oriented bounding box per chart for tight rotation
    • Skyline-style bin packing with a configurable border for texel safety
    • Repeated atlas growth until everything fits inside [0, 1] x [0, 1]
  • API

    • Fluent UnwrapMesh builder
    • Per-call UnwrapOptions tunable knobs
    • Optional progress sink for diagnostics
    • Per-corner UV output (3 entries per triangle), so split corners across chart seams are preserved

Usage

Basic unwrap

using Prowl.Unwrapper;
using Prowl.Vector;

Double3[] positions = ...;   // one per vertex
int[] triangles    = ...;    // flat index buffer, 3 per face

var result = new UnwrapMesh(positions, triangles).Unwrap();

// result.PerCornerUVs is laid out as [tri0.c0, tri0.c1, tri0.c2, tri1.c0, ...]
Double2[] uvs = result.PerCornerUVs;

With normals and material UV hints

Normals improve welding (coincident points with opposing normals stay split). Material UVs act as a seam hint during segmentation.

var result = new UnwrapMesh(positions, triangles)
    .WithNormals(normals)
    .WithMaterialUVs(existingUVs)
    .Unwrap();

Tuning chart quality

var options = new UnwrapOptions
{
    AngleDistortionThreshold = 0.05,   // stricter than default 0.08
    AreaDistortionThreshold  = 0.10,
    HardAngle                = 75.0,   // more aggressive crease cutting
    PackMargin               = 1.0 / 512.0,
};

var result = new UnwrapMesh(positions, triangles).Unwrap(options);

Progress reporting

var result = new UnwrapMesh(positions, triangles)
    .WithProgress(msg => Console.WriteLine(msg))
    .Unwrap();

Handling degenerate triangles

Triangles that collapse during cleanup are reported back so caller geometry can stay aligned with the input index buffer:

if (result.DegenerateTriangleIndices is { } skipped)
{
    foreach (int i in skipped)
        Console.WriteLine($"triangle {i} was degenerate and got zero UVs");
}

Limitations

  • Output UVs are per-corner, not per-vertex. Callers wanting a vertex buffer must split shared vertices along seams themselves.
  • Pure CPU. There is no GPU path.
  • The unwrapper minimises distortion, not seam length. For artist-facing UVs you may want a different tool.

License

This component is part of the Prowl Game Engine and is licensed under the MIT License. See the LICENSE file in the project root for details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 45 5/20/2026