Skip to content

Instantly share code, notes, and snippets.

@Dan-Piker
Created November 7, 2023 10:43
Show Gist options
  • Save Dan-Piker/bde58460a971bddce5be78f6fb6c7ec3 to your computer and use it in GitHub Desktop.
Save Dan-Piker/bde58460a971bddce5be78f6fb6c7ec3 to your computer and use it in GitHub Desktop.
Coons patch
Mesh m = new Mesh();
int uc = pa.Count;
int vc = pb.Count;
for(int u = 0;u < uc;u++)
{
for(int v = 0;v < vc;v++)
{
Point3d p0 = pa[u] * v / (vc - 1) + pc[uc - 1 - u] * (vc - 1 - v) / (vc - 1);
Point3d p1 = pd[v] * (uc - 1 - u) / (uc - 1) + pb[vc - 1 - v] * u / (uc - 1);
Point3d p2 =
((pa[0] * (uc - 1 - u) / (uc - 1)) + (pb[0] * u / (uc - 1))) * v / (vc - 1) +
((pd[0] * (uc - 1 - u) / (uc - 1)) + (pc[0] * u / (uc - 1))) * (vc - 1 - v) / (vc - 1);
Point3d p3 = p0 + p1 + (-1 * p2);
m.Vertices.Add(p3);
}
}
for(int u = 0;u < uc - 1;u++)
{
for(int v = 0;v < vc - 1;v++)
{
m.Faces.AddFace(u * vc + v,
(u + 1) * vc + v,
(u + 1) * vc + v + 1,
u * vc + v + 1);
}
}
m.Normals.ComputeNormals();
return m;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment