Skip to content

Commit

Permalink
Trapezohedra and new fast(?) canonocalize. Bump Unity version
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Feb 12, 2024
1 parent c6922cd commit c404312
Show file tree
Hide file tree
Showing 9 changed files with 527 additions and 22 deletions.
26 changes: 18 additions & 8 deletions Assets/Scripts/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class TestBase : MonoBehaviour
public FilterTypes Op2FilterType;
public float Op2FilterParam;
public bool Op2FilterFlip;
public float SpherizeAmount = 0;
public bool FastConicalize = true;
public int CanonicalizeIterations = 0;
public int PlanarizeIterations = 0;
[Range(.1f, 1f)] public float FaceScale = .99f;
Expand Down Expand Up @@ -82,18 +84,26 @@ public void Build(ColorMethods colorMethod = ColorMethods.ByRole)
ModifyPostOp();
// debugVerts = poly.Vertices.Select(v => v.Position).ToList();

if (FaceInset != 0)
if (SpherizeAmount > 0) poly.Spherize(new OpParams(SpherizeAmount));
if (FastConicalize)
{
Debug.Log($"Inset on {poly.Faces.Count} faces");
poly = poly.FaceInset(new OpParams(FaceInset));
if (CanonicalizeIterations > 0)
{
poly = poly.Kanonicalize(CanonicalizeIterations);
}
}

if (FaceExtrude != 0)
else
{
poly = poly.Extrude(new OpParams(FaceExtrude));
if (CanonicalizeIterations > 0 || PlanarizeIterations > 0)
{
poly = poly.Canonicalize(CanonicalizeIterations, PlanarizeIterations);
}
}
if (CanonicalizeIterations > 0 || PlanarizeIterations > 0) poly = poly.Canonicalize(CanonicalizeIterations, PlanarizeIterations);
if (FaceScale<1f) poly = poly.FaceScale(new OpParams(FaceScale));

if (FaceInset != 0) poly = poly.FaceInset(new OpParams(FaceInset));
if (FaceExtrude != 0) poly = poly.Extrude(new OpParams(FaceExtrude));
if (FaceScale < 1f) poly = poly.FaceScale(new OpParams(FaceScale));

var meshData = poly.BuildMeshData(colorMethod: colorMethod);
var mesh = poly.BuildUnityMesh(meshData);
if (poly.DebugVerts == null) poly.DebugVerts = new List<Vector3>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public static PolyMesh Antiprism(int sides)
{
return Antiprism(sides, _CalcAntiprismHeight(sides));
}

public static PolyMesh Trapezohedron(int sides)
{
var antiprism = Antiprism(sides);
var poly = antiprism.Dual();
poly.Recenter();
return poly.Kanonicalize(16); // TODO figure out the minimum iterations
}

public static PolyMesh Antiprism(int sides, float height)
{
Expand Down Expand Up @@ -603,6 +611,7 @@ public static PolyMesh Build(RadialPolyType type, int sides)
{
RadialPolyType.Prism => Prism(sides),
RadialPolyType.Antiprism => Antiprism(sides),
RadialPolyType.Trapezohedron => Trapezohedron(sides),
RadialPolyType.Pyramid => Pyramid(sides),
RadialPolyType.ElongatedPyramid => ElongatedPyramid(sides),
RadialPolyType.GyroelongatedPyramid => GyroelongatedPyramid(sides),
Expand Down Expand Up @@ -664,6 +673,7 @@ public enum RadialPolyType
GyroBicupola,
ElongatedOrthoBicupola,
ElongatedGyroBicupola,
GyroelongatedBicupola
GyroelongatedBicupola,
Trapezohedron
}
}
Loading

0 comments on commit c404312

Please sign in to comment.