예제 #1
0
        //TODO: Unbounded problem could manifest itself here
        public static VFace closestCell(float x, float y, TriangleNet.Voronoi.BoundedVoronoi voronoi)
        {
            int   startingIndex   = voronoi.Faces.Count / 2;
            VFace currentCell     = voronoi.Faces[startingIndex];
            float currentDistance = Mathf.Sqrt((float)(currentCell.generator.X - x) * (float)(currentCell.generator.X - x) + (float)(currentCell.generator.Y - y) * (float)(currentCell.generator.Y - y));

            while (true)
            {
                TriangleNet.Topology.DCEL.Face nextCell = null;
                bool foundNeighbour = false;
                foreach (TriangleNet.Topology.DCEL.HalfEdge edge in currentCell.EnumerateEdges())
                {
                    VFace nCell                 = edge.twin.face;
                    float neighbourX            = (float)nCell.generator.X;
                    float neighbourY            = (float)nCell.generator.Y;
                    float distanceFromNeighbour = Mathf.Sqrt((neighbourX - x) * (neighbourX - x) + (neighbourY - y) * (neighbourY - y));
                    if (distanceFromNeighbour < currentDistance)
                    {
                        foundNeighbour  = true;
                        currentDistance = distanceFromNeighbour;
                        nextCell        = nCell;
                    }
                }

                if (!foundNeighbour)
                {
                    break;
                }

                currentCell = nextCell;
            }

            return(currentCell);
        }
예제 #2
0
        private void Step(Mesh mesh, IVoronoiFactory factory)
        {
            var voronoi = new BoundedVoronoi(mesh, factory, predicates);

            double x, y;

            foreach (var face in voronoi.Faces)
            {
                if (face.generator.label == 0)
                {
                    Centroid(face, out x, out y);

                    face.generator.x = x;
                    face.generator.y = y;
                }
            }
        }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        TriangleNet.Configuration conf = new TriangleNet.Configuration();


        List <Vertex> vertices = OsgiViz.Helperfunctions.createPointsOnPlane(1f, 1f, 50, 50, 1f, new System.Random());
        SweepLine     sl       = new SweepLine();

        //TriangleNet.Mesh tMesh = (TriangleNet.Mesh)TriangleNet.Meshing.GenericMesher.StructuredMesh(1f, 1f, 10, 10);
        TriangleNet.Mesh tMesh = (TriangleNet.Mesh)sl.Triangulate(vertices, conf);
        TriangleNet.Voronoi.BoundedVoronoi voronoi = new TriangleNet.Voronoi.BoundedVoronoi(tMesh);

        foreach (TriangleNet.Topology.DCEL.Face vf in voronoi.Faces)
        {
            voronoiFaceToGO(vf);
        }
    }
    void generateMesh(int xOffSet, int yOffSet)
    {
        #region Triangle.Net mesh Generation and trianglation
        elevations.Clear();
        polygon = new Polygon();
        mesh    = null;
        for (int i = 0; i < randomPoints; i++)
        {
            polygon.Add(new Vertex(Random.Range(0.0f, xsize), Random.Range(0.0f, ysize)));
        }
        TriangleNet.Meshing.ConstraintOptions options =
            new TriangleNet.Meshing.ConstraintOptions()
        {
            ConformingDelaunay = true
        };
        mesh           = (TriangleNet.Mesh)polygon.Triangulate(options);
        boundedVoronoi = new TriangleNet.Voronoi.BoundedVoronoi(mesh);
        #endregion

        //setting up bounds to be used for generatating UVs
        meshBounds = new Bounds(new Vector3((float)mesh.Bounds.Left - (float)mesh.Bounds.Right,
                                            (float)mesh.Bounds.Top - (float)mesh.Bounds.Bottom), new Vector3((float)mesh.Bounds.Width, (float)mesh.Bounds.Height));

        #region defining and sampling data from images or noise
        int randomMap = Random.Range(0, typesOfImages[selectedImagePoolIndex].Count);
        int min       = 0;
        int maxW;
        int maxH;
        int maxX = 0;
        int maxY = 0;

        // setting width and height to be used for normalising the values to select the appropriate portion of the image
        if (useCustomImage)
        {
            circleGradient = customImage;
            maxW           = circleGradient.width;
            maxH           = circleGradient.height;
        }
        else
        {
            if (useImagePool)
            {
                circleGradient = typesOfImages[selectedImagePoolIndex][randomMap];
                maxW           = typesOfImages[selectedImagePoolIndex][randomMap].width;
                maxH           = typesOfImages[selectedImagePoolIndex][randomMap].height;
            }
            else
            {
                maxW = circleGradient.width;
                maxH = circleGradient.height;
            }
        }
        //sampling image/noise and defining heights
        for (int i = 0; i < mesh.vertices.Count; i++)
        {
            float sample;
            if (usePerlinNoise)
            {
                sample = Mathf.PerlinNoise((float)mesh.vertices[i].x + xOffSet, (float)mesh.vertices[i].y + yOffSet);
            }
            else
            {
                int x = Mathf.FloorToInt(HelperFunctions.normalise((float)mesh.vertices[i].x, min, xsize, min, maxW));
                int y = Mathf.FloorToInt(HelperFunctions.normalise((float)mesh.vertices[i].y, min, ysize, min, maxH));
                maxX = Mathf.Max(x, maxX);
                maxY = Mathf.Max(y, maxY);

                sample = circleGradient.GetPixel(x, y).grayscale;
            }
            sample = defineIsland(sample, mesh.vertices[i]);

            elevations.Add(sample);
        }
        #endregion

        MakeMesh(xOffSet, yOffSet);
    }