public void DrawPointTriangles(MorphTriangleType Type) { GL.LineWidth(1.5f); GL.DepthMask(false); GL.Begin(PrimitiveType.Lines); GL.Color3(Color.Red); foreach (var part in HeadMesh.Parts) { for (int i = 0; i < part.PointIndices.Count; i += 3) { var p0 = part.MorphPoints[part.PointIndices[i]]; var p1 = part.MorphPoints[part.PointIndices[i + 1]]; var p2 = part.MorphPoints[part.PointIndices[i + 2]]; if (p0.TriangleType != Type || p0.Position.Z < 0.0f) { continue; } if (p1.TriangleType != Type || p1.Position.Z < 0.0f) { continue; } if (p2.TriangleType != Type || p2.Position.Z < 0.0f) { continue; } GL.Vertex3(p0.WorldPosition); GL.Vertex3(p1.WorldPosition); GL.Vertex3(p1.WorldPosition); GL.Vertex3(p2.WorldPosition); GL.Vertex3(p2.WorldPosition); GL.Vertex3(p0.WorldPosition); } } GL.End(); GL.DepthMask(true); }
public void Initialize(ProjectedDots dots, HeadMorphing headMorphing) { MorphTriangleType realType = Type; if (IsReversed) { realType = Type == MorphTriangleType.Left ? MorphTriangleType.Right : MorphTriangleType.Left; } List <Vector2> points = new List <Vector2>(); foreach (var part in ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Parts) { foreach (var point in part.MorphPoints) { if (point.TriangleType != realType || point.Position.Z < 0.0f) { continue; } if (IsReversed) { points.Add(point.ReversedWorldPosition.Xy); } else { points.Add(point.WorldPosition.Xy); } } } Convex = Triangulate.ComputeConvexHull(points, (Type == MorphTriangleType.Left) == IsReversed); LastIndex = Convex.Count - 1; float prevX = Convex[LastIndex].X; float prevY = Convex[LastIndex].Y; for (int i = LastIndex - 1; i >= 0; --i) { float y = Convex[i].Y; float x = Convex[i].X; if (x > prevX == (Type == MorphTriangleType.Left)) { continue; } if (y < prevY) { break; } prevX = x; prevY = y; FirstIndex = i; } Convex.RemoveRange(0, FirstIndex); if (Type == MorphTriangleType.Left) { Convex.Insert(0, GetPoint(dots.Points[52])); Convex.Insert(0, GetPoint(dots.Points[3])); Convex.Insert(0, GetPoint(dots.Points[58])); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[72].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[73].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[74].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[75].Xy)); } else { Convex.Insert(0, GetPoint(dots.Points[53])); Convex.Insert(0, GetPoint(dots.Points[4])); Convex.Insert(0, GetPoint(dots.Points[59])); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[70].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[77].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[76].Xy)); Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[75].Xy)); } FirstIndex = 7; LastIndex = Convex.Count - 1; var tempPoints = new List <Point>(); for (int index = 0; index < Convex.Count; ++index) { var position = Convex[index]; tempPoints.Add(new Point((uint)index, position.X, position.Y)); } Indices.Clear(); Indices.AddRange(Triangulate.Delaunay(tempPoints)); }