Configuration of the triangulation computation.
Inheritance: ConvexHullComputationConfig
Ejemplo n.º 1
0
        Create(IList <double[]> data, TriangulationComputationConfig config = null)
        {
            var points = data.Select(p => new DefaultVertex {
                Position = p.ToArray()
            }).ToList();

            return(VoronoiMesh <DefaultVertex, DefaultTriangulationCell <DefaultVertex>, VoronoiEdge <DefaultVertex, DefaultTriangulationCell <DefaultVertex> > > .Create(points, config));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Remove the upper faces from the hull.
 /// Remove empty boundary cells if shifting was used.
 /// </summary>
 /// <param name="config"></param>
 void PostProcessTriangulation(TriangulationComputationConfig config)
 {
     RemoveUpperFaces();
     if (config.PointTranslationType == PointTranslationType.TranslateInternal)
     {
         RemoveEmptyBoundaryCells(config.ZeroCellVolumeTolerance);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create the voronoi mesh.
 /// </summary>
 /// <typeparam name="TVertex"></typeparam>
 /// <typeparam name="TCell"></typeparam>
 /// <param name="data"></param>
 /// <param name="config">If null, default TriangulationComputationConfig is used.</param>
 /// <returns></returns>
 public static VoronoiMesh <TVertex, TCell, VoronoiEdge <TVertex, TCell> > Create <TVertex, TCell>(IList <TVertex> data, TriangulationComputationConfig config = null)
     where TVertex : IVertex
     where TCell : TriangulationCell <TVertex, TCell>, new()
 {
     return(VoronoiMesh <TVertex, TCell, VoronoiEdge <TVertex, TCell> > .Create(data, config));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create the voronoi mesh.
 /// </summary>
 /// <typeparam name="TVertex"></typeparam>
 /// <param name="data"></param>
 /// <param name="config">If null, default TriangulationComputationConfig is used.</param>
 /// <returns></returns>
 public static VoronoiMesh <TVertex, DefaultTriangulationCell <TVertex>, VoronoiEdge <TVertex, DefaultTriangulationCell <TVertex> > > Create <TVertex>(IList <TVertex> data, TriangulationComputationConfig config = null)
     where TVertex : IVertex
 {
     return(VoronoiMesh <TVertex, DefaultTriangulationCell <TVertex>, VoronoiEdge <TVertex, DefaultTriangulationCell <TVertex> > > .Create(data, config));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the Delaunay triangulation of the input data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="config">If null, default ConvexHullComputationConfig is used.</param>
        /// <returns></returns>
        public static DelaunayTriangulation <TVertex, TCell> Create(IList <TVertex> data, TriangulationComputationConfig config)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (data.Count == 0)
            {
                return new DelaunayTriangulation <TVertex, TCell> {
                           Cells = new TCell[0]
                }
            }
            ;

            config = config ?? new TriangulationComputationConfig();
            var cells = ConvexHullInternal.GetDelaunayTriangulation <TVertex, TCell>(data, config);

            return(new DelaunayTriangulation <TVertex, TCell> {
                Cells = cells
            });
        }
Ejemplo n.º 6
0
        public void GenerateMapData(int startZ, int rows)
        {
            InitGenerators();
              //set scalling factors
              scaleX = (float)WorldWidth / ((float)WidthSegments - 1);
              scaleZ = (float)WorldHeight / ((float)HeightSegments - 1);

              for (int z = startZ; z < rows; z++)
              {
            Vector3[] dataRow = new Vector3[WidthSegments];
            float worldZ = z * scaleZ;

            //build basic terrain data row
            for (int x = 0; x < WidthSegments; x++)
            {
              float worldX = (x - WidthSegments / 2) * scaleX;
              float worldY = (float)terrainScaledModule.GetValue(worldX * WorldScale, 0, worldZ * WorldScale) / WorldScale + 1.1f;
              Vector3 vertex = new Vector3(worldX, worldY, worldZ);
              dataRow[x] = vertex;
            }
            //carve river shape
            CarveRiverChannel(dataRow, scaleX, worldZ);
            //collect modified points and add to vertices array
            for (int x = 0; x < WidthSegments; x++)
            {
              Vertices.Add(new Vertex { Position3D = dataRow[x], Id = vertexIndex++ });
            }
            //build heightmaps
            //for (int x = 0; x < widthSegments; x++)
            //{
            //  uvs.Add(new Vector2(x * scaleX / (float)widthSegments, z * scaleZ / (float)heightSegments));
            //}
              }

              var config = new TriangulationComputationConfig();
              Triangles = Triangulation.CreateDelaunay<Vertex, Triangle<Vertex>>(Vertices, config).Cells.ToList();
              for (int i = Triangles.Count - 1; i >= 0; i--)
              {
            Triangles[i].ComputeNormal();
            SetBiome(Triangles[i], biomesPerlin);
              }
              foreach (Triangle<Vertex> triangle in Triangles)
              {
            SplitTriangles(triangle);
              }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates the Delaunay triangulation of the input data.
 /// </summary>
 /// <typeparam name="TVertex"></typeparam>
 /// <typeparam name="TFace"></typeparam>
 /// <param name="data"></param>
 /// <param name="config">If null, default TriangulationComputationConfig is used.</param>
 /// <returns></returns>
 public static ITriangulation <TVertex, TFace> CreateDelaunay <TVertex, TFace>(IList <TVertex> data, TriangulationComputationConfig config = null)
     where TVertex : IVertex
     where TFace : TriangulationCell <TVertex, TFace>, new()
 {
     return(DelaunayTriangulation <TVertex, TFace> .Create(data, config));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates the Delaunay triangulation of the input data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="config">If null, default TriangulationComputationConfig is used.</param>
        /// <returns></returns>
        public static ITriangulation <DefaultVertex, DefaultTriangulationCell <DefaultVertex> > CreateDelaunay(IList <double[]> data, TriangulationComputationConfig config = null)
        {
            var points = data.Select(p => new DefaultVertex {
                Position = p.ToArray()
            }).ToList();

            return(DelaunayTriangulation <DefaultVertex, DefaultTriangulationCell <DefaultVertex> > .Create(points, config));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates the Delaunay triangulation of the input data.
 /// </summary>
 /// <typeparam name="TVertex"></typeparam>
 /// <param name="data"></param>
 /// <param name="config">If null, default TriangulationComputationConfig is used.</param>
 /// <returns></returns>
 public static ITriangulation <TVertex, DefaultTriangulationCell <TVertex> > CreateDelaunay <TVertex>(IList <TVertex> data, TriangulationComputationConfig config = null)
     where TVertex : IVertex
 {
     return(DelaunayTriangulation <TVertex, DefaultTriangulationCell <TVertex> > .Create(data, config));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Computes the Delaunay triangulation.
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TCell"></typeparam>
        /// <param name="data"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        internal static TCell[] GetDelaunayTriangulation <TVertex, TCell>(IList <TVertex> data, TriangulationComputationConfig config)
            where TCell : TriangulationCell <TVertex, TCell>, new()
            where TVertex : IVertex
        {
            config = config ?? new TriangulationComputationConfig();

            var vertices = new IVertex[data.Count];

            for (int i = 0; i < data.Count; i++)
            {
                vertices[i] = data[i];
            }
            ConvexHullInternal ch = new ConvexHullInternal(vertices, true, config);

            ch.FindConvexHull();
            ch.PostProcessTriangulation(config);

            return(ch.GetConvexFaces <TVertex, TCell>());
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Use Delauney triangulation to retrieve the triangles for this mesh
    /// </summary>
    /// <returns></returns>
    private Mesh ComputeMesh()
    {
        if (m_currentVertexList.Count < 3)
        {
            Debug.LogWarning("Not creating Zone (need >= 3 vertices)");
            return null;
        }

        Mesh mesh = new Mesh();
        // Drop the y-coordinate in order to triangulate in two dimensions.
        // We don't require the ability to triangulate in 3+ dimensions, although the MIConvexHull lib is capable of doing so.
        Vertex[] vertices = m_currentVertexList.ConvertAll(vert3 => new Vertex(vert3.x, vert3.z)).ToArray();

        // Triangulate the mesh
        var config = new TriangulationComputationConfig
        {
            PointTranslationType = PointTranslationType.TranslateInternal,
            PlaneDistanceTolerance = 0.00001,
            // the translation radius should be lower than PlaneDistanceTolerance / 2
            PointTranslationGenerator = TriangulationComputationConfig.RandomShiftByRadius(0.000001, 0)
        };

        List<Vector3> meshVerts = new List<Vector3>();
        List<int> indices = new List<int>();

        try
        {
            VoronoiMesh<Vertex, Cell, VoronoiEdge<Vertex, Cell>> voronoiMesh;
            voronoiMesh = VoronoiMesh.Create<Vertex, Cell>(vertices, config);

            foreach (var cell in voronoiMesh.Vertices)
            {
                for (int vertNum = 0; vertNum < 3; vertNum++)
                {
                    Vector3 vert = new Vector3((float)cell.Vertices[vertNum].Position[0], 0.0f, (float)cell.Vertices[vertNum].Position[1]);
                    int idx;
                    if (meshVerts.Contains(vert))
                    {
                        idx = meshVerts.IndexOf(vert);
                    }
                    else
                    {
                        meshVerts.Add(vert);
                        idx = meshVerts.Count - 1;
                    }
                    indices.Add(idx);
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message);
        }

        mesh.vertices = meshVerts.ToArray();
        mesh.triangles = indices.ToArray();

        mesh.RecalculateBounds();
        mesh.RecalculateNormals();

        m_createdZone = true;
        return mesh;
    }