コード例 #1
0
    private void OnDrawGizmos()
    {
        if (triangulatedMesh != null)
        {
            //Display the triangles with a random color
            TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(triangulatedMesh, seed);

            //Display the points
            TestAlgorithmsHelpMethods.DisplayPoints(points, 0.1f, Color.black);

            //Display the points on the hull
            if (pointsOnHull != null && pointsOnHull.Count > 0)
            {
                HashSet <Vector3> pointsOnHull_3d = new HashSet <Vector3>();

                foreach (MyVector2 p in pointsOnHull)
                {
                    pointsOnHull_3d.Add(p.ToVector3());
                }

                TestAlgorithmsHelpMethods.DisplayPoints(pointsOnHull_3d, 0.3f, Color.black);
            }
        }

        if (testTriangles != null)
        {
            List <Triangle2> test = new List <Triangle2>(testTriangles);

            testTriangleNumber = Mathf.Clamp(testTriangleNumber, 0, testTriangles.Count - 1);

            Triangle2 t = test[testTriangleNumber];

            TestAlgorithmsHelpMethods.DisplayTriangle(t.p1.ToVector3(), t.p2.ToVector3(), t.p3.ToVector3(), Color.white);
        }
    }
コード例 #2
0
    private void OnDrawGizmos()
    {
        //
        // Generate the random sites
        //
        HashSet <Vector3> randomSites = new HashSet <Vector3>();

        //Generate random numbers with a seed
        Random.InitState(seed);

        float max = halfMapSize;
        float min = -halfMapSize;

        for (int i = 0; i < numberOfPoints; i++)
        {
            float randomX = Random.Range(min, max);
            float randomZ = Random.Range(min, max);

            randomSites.Add(new Vector3(randomX, 0f, randomZ));
        }


        //Points outside of the screen for voronoi which has some cells that are infinite
        float bigSize = halfMapSize * 5f;

        //Star shape which will give a better result when a cell is infinite large
        //When using other shapes, some of the infinite cells misses triangles
        randomSites.Add(new Vector3(0f, 0f, bigSize));
        randomSites.Add(new Vector3(0f, 0f, -bigSize));
        randomSites.Add(new Vector3(bigSize, 0f, 0f));
        randomSites.Add(new Vector3(-bigSize, 0f, 0f));

        //3d to 2d
        HashSet <MyVector2> randomSites_2d = new HashSet <MyVector2>();

        foreach (Vector3 v in randomSites)
        {
            randomSites_2d.Add(v.ToMyVector2());
        }


        //Generate the voronoi
        List <VoronoiCell2> voronoiCells = _Voronoi.DelaunyToVoronoi(randomSites_2d);

        //Display the voronoi diagram
        DisplayVoronoiCells(voronoiCells);

        //Display the sites
        TestAlgorithmsHelpMethods.DisplayPoints(randomSites, 0.1f, Color.black);


        //Generate delaunay for comparisons
        GenerateDelaunay(randomSites_2d);
    }
コード例 #3
0
    private void OnDrawGizmos()
    {
        //
        // Init the sites
        //

        //HashSet<Vector3> sites_3d = GetRandomSites();
        //HashSet<Vector3> sites_3d = GetCustomSites();
        HashSet <Vector3> sites_3d = GetCustomSites2();

        //3d to 2d
        HashSet <MyVector2> sites_2d = new HashSet <MyVector2>();

        foreach (Vector3 v in sites_3d)
        {
            sites_2d.Add(v.ToMyVector2());
        }


        //Normalize
        AABB2 normalizingBox = new AABB2(new List <MyVector2>(sites_2d));

        float dMax = HelpMethods.CalculateDMax(normalizingBox);

        HashSet <MyVector2> randomSites_2d_normalized = HelpMethods.Normalize(sites_2d, normalizingBox, dMax);


        //Generate the voronoi
        List <VoronoiCell2> voronoiCells = _Voronoi.DelaunyToVoronoi(randomSites_2d_normalized);


        //Unnormalize
        voronoiCells = HelpMethods.UnNormalize(voronoiCells, normalizingBox, dMax);


        //Display the voronoi diagram
        DisplayVoronoiCells(voronoiCells);

        //Display the sites
        TestAlgorithmsHelpMethods.DisplayPoints(sites_3d, 0.5f, Color.black);

        //Generate delaunay for comparisons
        GenerateDelaunay(sites_2d);
    }
コード例 #4
0
    private void OnDrawGizmos()
    {
        if (triangulatedMesh != null)
        {
            //Display the triangles with a random color
            TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(triangulatedMesh, seed);

            //Display the points
            TestAlgorithmsHelpMethods.DisplayPoints(points, 0.1f, Color.black);

            //Display the points on the hull
            if (pointsOnHull != null && pointsOnHull.Count > 0)
            {
                HashSet <Vector3> pointsOnHull_3d = new HashSet <Vector3>();

                foreach (MyVector2 p in pointsOnHull)
                {
                    pointsOnHull_3d.Add(p.ToVector3());
                }

                TestAlgorithmsHelpMethods.DisplayPoints(pointsOnHull_3d, 0.3f, Color.black);
            }
        }
    }