Esempio n. 1
0
        public void GenerateOutput(List <Index2> outputCull, out List <Vector3> vertices, out List <int> indices)
        {
            var newVertices          = new List <Vector3>((int)mesh.PointCount);
            var newIndices           = new List <int>((int)mesh.PointCount * 3);
            var vertexArrayPositions = new int[heightMap.Width, heightMap.Height];

            vertexArrayPositions.Fill(-1);

            mesh.OverFaces((tri, obj) =>
            {
                var triVertices = new[]
                {
                    tri.Point1,
                    tri.Point2,
                    tri.Point3
                };

                foreach (var holeMarker in outputCull)
                {
                    var count = 0;
                    foreach (var vertex in triVertices)
                    {
                        var idx = new Index2
                        {
                            X = (int)vertex.X,
                            Y = (int)vertex.Y
                        };

                        // The triangle abuts one of the hole markers
                        if (holeMarker == idx)
                        {
                            return;
                        }

                        // The triangle is within the hole markers neighborhood
                        if (Index2.Abs(idx - holeMarker) <= Index2.One)
                        {
                            count++;
                        }
                    }
                    if (count > 2)
                    {
                        return;
                    }
                }

                if (GeometryHelpers.IsCounterClockwise(triVertices[0], triVertices[1], triVertices[2]))
                {
                    var temp       = triVertices[1];
                    triVertices[1] = triVertices[2];
                    triVertices[2] = temp;
                }

                foreach (var vertex in triVertices)
                {
                    if (vertexArrayPositions[(int)vertex.X, (int)vertex.Y] == -1)
                    {
                        vertexArrayPositions[(int)vertex.X, (int)vertex.Y] = newVertices.Count;
                        newVertices.Add(new Vector3(vertex, heightMap.Eval(vertex.X, vertex.Y)));
                    }

                    newIndices.Add(vertexArrayPositions[(int)vertex.X, (int)vertex.Y]);
                }
            });

            vertices = newVertices;
            indices  = newIndices;
        }