Skip to content

Commit

Permalink
Last few Laves tilings
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Feb 19, 2024
1 parent 8486f1a commit 5b639f2
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Assets/Scripts/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TestBase : MonoBehaviour
public bool debugFaces;
public bool debugEdges;
public bool debugVerts;

[NonSerialized] public PolyMesh poly;

public void Build(ColorMethods colorMethod = ColorMethods.ByRole)
Expand All @@ -48,7 +48,7 @@ public void Build(ColorMethods colorMethod = ColorMethods.ByRole)
for (int i1 = 0; i1 < Op1Iterations; i1++)
{
var op1Filter = Filter.GetFilter(Op1FilterType, Op1FilterParam, Mathf.FloorToInt(Op1FilterParam), Op1FilterFlip);

var op1Func1 = new OpFunc(_ => Mathf.Lerp(0, Op1Parameter1, (float)_random.NextDouble()));
var op1Func2 = new OpFunc(_ => Mathf.Lerp(0, Op1Parameter2, (float)_random.NextDouble()));

Expand Down Expand Up @@ -79,7 +79,7 @@ public void Build(ColorMethods colorMethod = ColorMethods.ByRole)
}
if (MergeThreshold > 0) poly.MergeCoplanarFaces(MergeThreshold);
for (int i2 = 0; i2 < Op2Iterations; i2++)
{
{
var op2Filter = Filter.GetFilter(Op2FilterType, Op2FilterParam, Mathf.FloorToInt(Op2FilterParam), Op2FilterFlip);
poly = poly.AppyOperation(op2, new OpParams(Op2Parameter1, Op2Parameter2, filter: op2Filter));
}
Expand Down Expand Up @@ -123,16 +123,16 @@ protected virtual void ModifyPostOp()
{}

public virtual void Go(){}

private void OnValidate()
{
Go();
}

private void OnDrawGizmos()
{
if (poly==null) return;

if (debugFaces)
{
for (var f = 0; f < poly.Faces.Count; f++)
Expand Down Expand Up @@ -161,7 +161,7 @@ private void OnDrawGizmos()
Vector3 pos = transform.TransformPoint(vert);
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(pos, .025f);
Handles.Label(pos + new Vector3(0, 0.03f, 0), i.ToString());
Handles.Label(pos + new Vector3(0, 0.1f, 0), i.ToString());
}
}
}
Expand Down
134 changes: 125 additions & 9 deletions Packages/Polyhydra/com.ixxy.polyhydra/Core/Runtime/Generators/Grids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum GridShapes
Sphere,
Polar,
}

public enum GridTypes
{
// Regular
Expand Down Expand Up @@ -72,7 +72,7 @@ public enum GridTypes
TriTriSquare1 = 32, // 3.3.3.3.3.3;3.3.3.4.4: A
TriTriSquare2 = 33, // 3.3.3.3.3.3;3.3.3.4.4: B
}

}

public static class Grids
Expand Down Expand Up @@ -182,7 +182,7 @@ public static TileDef BuildTileDefFromFormat(string format)
foreach (var line in lines.Skip(3))
{
parts = line.Trim().Split(' ');
if (line == "" || parts.Length < 1)
if (string.IsNullOrEmpty(line) || parts.Length < 1)
{
continue;
}
Expand Down Expand Up @@ -774,15 +774,133 @@ public static PolyMesh Build(GridEnums.GridTypes type, GridEnums.GridShapes grid
break;

case GridEnums.GridTypes.TriakisTriangular:
tile = Shapes.Polygon(6);
tile = tile.Stake(new OpParams(1f / 3));
tile = tile.SplitFaces(new OpParams(0));
xOffset = tile.Vertices[4].Position - tile.Vertices[2].Position;
yOffset = tile.Vertices[3].Position - tile.Vertices[1].Position;
roleSet = new List<List<List<Roles>>>
{
new()
{
new()
{
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
Roles.Existing,
Roles.ExistingAlt,
Roles.New,
}
}
};

break;

case GridEnums.GridTypes.DeltoidalTrihexagonal:
tile = Shapes.Polygon(6);
tile = tile.Ortho(new OpParams(0));
xOffset = tile.Vertices[4].Position - tile.Vertices[12].Position;
yOffset = tile.Vertices[4].Position - tile.Vertices[8].Position;
roleSet = new List<List<List<Roles>>>
{
new()
{
new()
{
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt
}
}
};
break;

case GridEnums.GridTypes.Kisrhombille:
tile = Shapes.Polygon(6);
tile = tile.Meta(new OpParams(0));
xOffset = tile.Vertices[5].Position - tile.Vertices[1].Position;
yOffset = tile.Vertices[3].Position - tile.Vertices[1].Position;
roleSet = new List<List<List<Roles>>>
{
new()
{
new()
{
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt
}
}
};
break;


case GridEnums.GridTypes.FloretPentagonal:
var floret = Shapes.Polygon(6);
floret.ExtendFace(0, 4, 3);
var verts = floret.Vertices.Select(v => v.Position).ToList();
verts = new List<Vector3>
{
verts[0],
verts[1],
verts[2],
verts[6],
verts[5],
};
floret = Shapes.Polygon(5);
floret.SetVertexPositions(verts.ToList());
floret.Transform(new Vector3(0, 0, -floret.Vertices[3].Position.z / 2), scale: Vector3.one / 2);

tile = floret.Duplicate();
for (int i = 1; i < 6; i++)
{
floret.Transform(Vector3.zero, new Vector3(0, 60, 0));
tile.Append(floret);
}

xOffset = tile.Vertices[25].Position - tile.Vertices[5].Position;
yOffset = tile.Vertices[0].Position - tile.Vertices[20].Position;

roleSet = new List<List<List<Roles>>>
{
new()
{
new()
{
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt,
Roles.Existing,
Roles.ExistingAlt
}
}
};
break;

case GridEnums.GridTypes.PrismaticPentagonal:
Expand All @@ -800,7 +918,6 @@ public static PolyMesh Build(GridEnums.GridTypes type, GridEnums.GridShapes grid
tile.Append(new PolyMesh(points.Select(p => new Vector3(p.x, 0, -p.z))));
xOffset = tile.Vertices[0].Position - tile.Vertices[1].Position;
yOffset = tile.Vertices[8].Position - tile.Vertices[2].Position;
tile.DebugVerts = tile.Vertices.Select(v => v.Position).ToList();
roleSet = new List<List<List<Roles>>>
{
new()
Expand Down Expand Up @@ -905,7 +1022,6 @@ public static PolyMesh Build(GridEnums.GridTypes type, GridEnums.GridShapes grid
format = @"6 0 0
12 17
15 10
0 0 4 1
0 1 4 1
0 2 4 1
Expand Down Expand Up @@ -1239,7 +1355,7 @@ 3 0 3 1

public static PolyMesh ShapeWrap(PolyMesh grid, GridEnums.GridShapes gridShape, float heightScale, float maxHeight)
{

// Cylinder
for (var i = 0; i < grid.Vertices.Count; i++)
{
Expand All @@ -1254,7 +1370,7 @@ public static PolyMesh ShapeWrap(PolyMesh grid, GridEnums.GridShapes gridShape,
}
// Weld cylinder edges.
// Other shapes might not work with welding tips etc
grid = grid.Weld(0.01f);
grid = grid.Weld(0.01f);

// Change cylinder profile for cone etc
if (gridShape != GridEnums.GridShapes.Plane)
Expand Down Expand Up @@ -1299,7 +1415,7 @@ public static PolyMesh ShapeWrap(PolyMesh grid, GridEnums.GridShapes gridShape,
return grid;
}
}





}

0 comments on commit 5b639f2

Please sign in to comment.