Skip to content

Commit c37f6cf

Browse files
committed
Add new order-2 operator "Valetta"
1 parent 21c165b commit c37f6cf

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

Packages/Polyhydra/com.ixxy.polyhydra/Core/Runtime/PolyMesh.ConwayOps.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,96 @@ public PolyMesh Stake(OpParams o, bool join = false)
21302130
return new PolyMesh(vertexPoints, faceIndices, faceRoles, vertexRoles, newFaceTags);
21312131
}
21322132

2133+
public PolyMesh Valletta(OpParams o)
2134+
{
2135+
var newFaceTags = new List<HashSet<string>>();
2136+
2137+
var faceIndices = new List<int[]>();
2138+
var vertexPoints = new List<Vector3>();
2139+
var existingVertices = new Dictionary<Vector3, int>();
2140+
var newInnerVertices = new Dictionary<(Guid, Guid)?, int>();
2141+
2142+
var faceRoles = new List<Roles>();
2143+
var vertexRoles = new List<Roles>();
2144+
2145+
for (var i = 0; i < Vertices.Count; i++)
2146+
{
2147+
vertexPoints.Add(Vertices[i].Position);
2148+
vertexRoles.Add(Roles.Existing);
2149+
existingVertices[vertexPoints[i]] = i;
2150+
}
2151+
2152+
int vertexIndex = vertexPoints.Count;
2153+
2154+
for (var faceIndex = 0; faceIndex < Faces.Count; faceIndex++)
2155+
{
2156+
float ratio = o.GetValueA(this, faceIndex);
2157+
var prevFaceTagSet = FaceTags[faceIndex];
2158+
var face = Faces[faceIndex];
2159+
var edge = face.Halfedge;
2160+
var centroid = face.Centroid;
2161+
2162+
// Generate the quads and triangles on this face
2163+
for (int i = 0; i < face.Sides; i++)
2164+
{
2165+
var newVertex = Vector3.LerpUnclamped(
2166+
edge.Midpoint,
2167+
centroid,
2168+
ratio
2169+
);
2170+
2171+
vertexPoints.Add(newVertex);
2172+
vertexRoles.Add(Roles.NewAlt);
2173+
newInnerVertices[edge.Name] = vertexIndex++;
2174+
edge = edge.Next;
2175+
}
2176+
2177+
if (face.Sides > 2)
2178+
{
2179+
var innerFace = new int[face.Sides * 2];
2180+
edge = face.Halfedge;
2181+
for (int i = 0; i < face.Sides; i++)
2182+
{
2183+
innerFace[i * 2] = newInnerVertices[edge.Name];
2184+
innerFace[i * 2 + 1] = existingVertices[edge.Vertex.Position];
2185+
edge = edge.Next;
2186+
}
2187+
2188+
faceIndices.Add(innerFace);
2189+
faceRoles.Add(Roles.Existing);
2190+
newFaceTags.Add(prevFaceTagSet);
2191+
}
2192+
}
2193+
2194+
var edgeFlags = new HashSet<(Guid, Guid)?>();
2195+
foreach (var edge in Halfedges)
2196+
{
2197+
if (edge.Pair == null) continue;
2198+
2199+
if (!edgeFlags.Contains(edge.PairedName))
2200+
{
2201+
var quad = new[]
2202+
{
2203+
existingVertices[edge.Vertex.Position],
2204+
newInnerVertices[edge.Name],
2205+
existingVertices[edge.Pair.Vertex.Position],
2206+
newInnerVertices[edge.Pair.Name],
2207+
};
2208+
faceIndices.Add(quad);
2209+
faceRoles.Add(Roles.New);
2210+
edgeFlags.Add(edge.PairedName);
2211+
2212+
var newFaceTagSet = new HashSet<string>();
2213+
newFaceTagSet.UnionWith(FaceTags[Faces.IndexOf(edge.Face)]);
2214+
newFaceTagSet.UnionWith(FaceTags[Faces.IndexOf(edge.Pair.Face)]);
2215+
newFaceTags.Add(newFaceTagSet);
2216+
}
2217+
}
2218+
2219+
return new PolyMesh(vertexPoints, faceIndices, faceRoles, vertexRoles, newFaceTags);
2220+
}
2221+
2222+
21332223
public PolyMesh JoinKisKis(OpParams o)
21342224
{
21352225
var newFaceTags = new List<HashSet<string>>();

Packages/Polyhydra/com.ixxy.polyhydra/Core/Runtime/PolyMesh.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ public enum Operation
12941294
Ortho3 = 97,
12951295
Zellige = 114,
12961296
Girih = 110,
1297+
Valletta = 115,
12971298
StraightSkeleton = 105,
12981299
FaceTessellate = 106,
12991300
Tessellate = 107,
@@ -1494,7 +1495,10 @@ public PolyMesh AppyOperation(Operation op, OpParams p)
14941495
polyMesh = polyMesh.Stake(p);
14951496
break;
14961497
case Operation.JoinStake:
1497-
polyMesh = polyMesh.Stake(p, @join: true);
1498+
polyMesh = polyMesh.Stake(p, join: true);
1499+
break;
1500+
case Operation.Valletta:
1501+
polyMesh = polyMesh.Valletta(p);
14981502
break;
14991503
case Operation.Medial:
15001504
polyMesh = polyMesh.Medial(p);

0 commit comments

Comments
 (0)