コード例 #1
0
    //TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed);
    //Is adding memory each time we run it in playmode, which could maybe
    //have been solved by destroying the meshes we create each update???
    //But DrawMesh is similar
    private void OnDrawGizmos()
    {
        if (multiColoredMeshes != null)
        {
            foreach (Mesh m in multiColoredMeshes)
            {
                TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black);
            }
        }


        //This point is set to be outside if its not active
        Gizmos.color = Color.white;

        //Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f);


        //Connected points
        if (connectedPoints != null)
        {
            Gizmos.color = Color.white;

            for (int i = 0; i < connectedPoints.Count; i++)
            {
                //Show the circle
                Gizmos.DrawWireSphere(connectedPoints[i].ToVector3(), 0.2f);

                //Line to previous point
                if (i > 0)
                {
                    Gizmos.DrawLine(connectedPoints[i].ToVector3(), connectedPoints[i - 1].ToVector3());
                }
            }
        }
    }
コード例 #2
0
    private void GenerateDelaunay(HashSet <MyVector2> points_2d)
    {
        //Normalize
        AABB2 normalizingBox = new AABB2(new List <MyVector2>(points_2d));

        float dMax = HelpMethods.CalculateDMax(normalizingBox);

        HashSet <MyVector2> points_2d_normalized = HelpMethods.Normalize(points_2d, normalizingBox, dMax);


        //Generate delaunay
        //HalfEdgeData2 delaunayData = _Delaunay.FlippingEdges(points_2d_normalized, new HalfEdgeData2());
        HalfEdgeData2 delaunayData = _Delaunay.PointByPoint(points_2d_normalized, new HalfEdgeData2());


        //UnNormalize
        HalfEdgeData2 triangleData = HelpMethods.UnNormalize(delaunayData, normalizingBox, dMax);

        //From halfedge to triangle
        HashSet <Triangle2> triangles = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(triangleData);

        //Make sure they have the correct orientation
        triangles = HelpMethods.OrientTrianglesClockwise(triangles);

        //2d to 3d
        HashSet <Triangle3> triangles_3d = new HashSet <Triangle3>();


        int counter = -1;

        foreach (Triangle2 t in triangles)
        {
            counter++;

            //if (counter != 2)
            //{
            //    continue;
            //}

            triangles_3d.Add(new Triangle3(t.p1.ToMyVector3_Yis3D(), t.p2.ToMyVector3_Yis3D(), t.p3.ToMyVector3_Yis3D()));

            //Debug.Log($"p1: {t.p1.x} {t.p1.y} p2: {t.p2.x} {t.p2.y} p3: {t.p3.x} {t.p3.y}");

            //MyVector2 circleCenter = _Geometry.CalculateCircleCenter(t.p1, t.p2, t.p3);

            //Debug.Log("Circle center: " + circleCenter.x + " " + circleCenter.y);
        }

        Mesh delaunayMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d);

        //Display the delaunay triangles
        TestAlgorithmsHelpMethods.DisplayMeshEdges(delaunayMesh, Color.black);
    }
コード例 #3
0
    //TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed);
    //Is adding memory each time we run it in playmode, which could maybe
    //have been solved by destroying the meshes we create each update???
    //But DrawMesh is similar
    private void OnDrawGizmos()
    {
        if (triangleMeshes != null)
        {
            foreach (Mesh m in triangleMeshes)
            {
                TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black);
            }


            Gizmos.color = Color.white;

            Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f);
        }
    }
コード例 #4
0
    private void GenerateDelaunay(HashSet <MyVector2> points)
    {
        HalfEdgeData2 delaunayData = _Delaunay.FlippingEdges(points, new HalfEdgeData2());

        //From halfedge to triangle
        HashSet <Triangle2> triangles = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(delaunayData);

        //Make sure they have the correct orientation
        triangles = HelpMethods.OrientTrianglesClockwise(triangles);

        //2d to 3d
        HashSet <Triangle3> triangles_3d = new HashSet <Triangle3>();

        foreach (Triangle2 t in triangles)
        {
            triangles_3d.Add(new Triangle3(t.p1.ToMyVector3(), t.p2.ToMyVector3(), t.p3.ToMyVector3()));
        }

        Mesh delaunayMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d);

        //Display the delaunay triangles
        TestAlgorithmsHelpMethods.DisplayMeshEdges(delaunayMesh, Color.black);
    }
コード例 #5
0
    private void GenerateDelaunay(HashSet <MyVector2> points_2d)
    {
        //Normalize
        AABB2 normalizingBox = new AABB2(new List <MyVector2>(points_2d));

        float dMax = HelpMethods.CalculateDMax(normalizingBox);

        HashSet <MyVector2> points_2d_normalized = HelpMethods.Normalize(points_2d, normalizingBox, dMax);


        //Generate delaunay
        //HalfEdgeData2 delaunayData = _Delaunay.FlippingEdges(points_2d_normalized, new HalfEdgeData2());
        HalfEdgeData2 delaunayData = _Delaunay.PointByPoint(points_2d_normalized, new HalfEdgeData2());


        //UnNormalize
        HalfEdgeData2 triangleData = HelpMethods.UnNormalize(delaunayData, normalizingBox, dMax);

        //From halfedge to triangle
        HashSet <Triangle2> triangles = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(triangleData);

        //Make sure they have the correct orientation
        triangles = HelpMethods.OrientTrianglesClockwise(triangles);

        //2d to 3d
        HashSet <Triangle3> triangles_3d = new HashSet <Triangle3>();

        foreach (Triangle2 t in triangles)
        {
            triangles_3d.Add(new Triangle3(t.p1.ToMyVector3(), t.p2.ToMyVector3(), t.p3.ToMyVector3()));
        }

        Mesh delaunayMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d);

        //Display the delaunay triangles
        TestAlgorithmsHelpMethods.DisplayMeshEdges(delaunayMesh, Color.black);
    }