Created
January 5, 2025 00:24
-
-
Save twobob/6d38aacee1e37e0733015a4c21e46b79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
public static class StripUtility | |
{ | |
// 1) Remove specified vertices | |
// 2) Re-sort remaining verts by angle around the centroid | |
// Ensures a consistent winding for a triangle strip after removal | |
public static void RemoveAndReorder(ref List<Vector3> verts, List<int> indicesToRemove) | |
{ | |
// Remove unwanted verts (sort indices descending so removal won't shift) | |
indicesToRemove.Sort((a, b) => b.CompareTo(a)); | |
foreach(int i in indicesToRemove) | |
if(i >= 0 && i < verts.Count) verts.RemoveAt(i); | |
if(verts.Count < 3) return; // Nothing to reorder | |
// Compute centroid | |
Vector3 center = Vector3.zero; | |
for(int i = 0; i < verts.Count; i++) | |
center += verts[i]; | |
center /= verts.Count; | |
// Sort by angle around centroid | |
verts.Sort((v1, v2) => | |
{ | |
float a1 = Mathf.Atan2(v1.y - center.y, v1.x - center.x); | |
float a2 = Mathf.Atan2(v2.y - center.y, v2.x - center.x); | |
return a1.CompareTo(a2); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment