Esempio n. 1
0
    private void CGALCut()
    {
        if (isIntersected)
        {
            AdjacencyList.Instance.ListUpdate();
            Debug.Log("intersected true");
            IntPtr  heart = CGAL.CreateMeshObject();
            IntPtr  stamp = CGAL.CreateMeshObject();
            float[] verticesCoordinate = CGAL.ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray());

            if (CGAL.BuildPolyhedron(heart,
                                     verticesCoordinate,
                                     verticesCoordinate.Length / 3,
                                     MeshManager.Instance.mesh.triangles,
                                     MeshManager.Instance.mesh.triangles.Length / 3) == -1)
            {
                Debug.Log(" 만들어지지 않음");
                return;
            }

            Vector3[] newVertices  = new Vector3[rayList.Count * 2];
            int[]     newTriangles = new int[rayList.Count * 6];
            CGAL.GenerateStampWithHeart(intersectedVerticesPos, rayList, ref newVertices, ref newTriangles);


            float[] newVerticesCoordinate = CGAL.ConvertToFloatArray(newVertices);
            if (CGAL.BuildPolyhedron(
                    stamp,
                    newVerticesCoordinate,
                    newVerticesCoordinate.Length / 3,
                    newTriangles,
                    newTriangles.Length / 3
                    ) == -1)
            {
                Debug.Log(" 만들어지지 않음");
                return;
            }
            if (CGAL.FillHole(stamp) == -1)
            {
                Debug.Log("fillhole error");
                return;
            }

            if (CGAL.ClipPolyhedronByMesh(heart, stamp) == -1)
            {
                Debug.Log("Clip error");
                return;
            }
            MeshManager.Instance.SetNewObject(CGAL.GenerateNewObject(heart, heartMaterial));
            MakeDoubleFaceMesh.Instance.Reinitialize();
            ////CGAL.GenerateNewObject(stamp, leftMaterial);
            //// 여기에 이제 잘리고나서 작업 넣어줘야됨. 새로운 메쉬로 바꾸고 정리하는 형태가 되어야함.
            ////MeshManager.Instance.Heart.SetActive(false);
        }
        else
        {
            IntPtr  heart = CGAL.CreateMeshObject();
            IntPtr  stamp = CGAL.CreateMeshObject();
            float[] verticesCoordinate = CGAL.ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray());

            if (CGAL.BuildPolyhedron(heart,
                                     verticesCoordinate,
                                     verticesCoordinate.Length / 3,
                                     MeshManager.Instance.mesh.triangles,
                                     MeshManager.Instance.mesh.triangles.Length / 3) == -1)
            {
                Debug.Log(" 만들어지지 않음");
                return;
            }

            Vector3[] newVertices  = new Vector3[rayList.Count * 2];
            int[]     newTriangles = new int[rayList.Count * 6];
            CGAL.GenerateStamp(rayList, ref newVertices, ref newTriangles);

            float[] newVerticesCoordinate = CGAL.ConvertToFloatArray(newVertices);
            if (CGAL.BuildPolyhedron(
                    stamp,
                    newVerticesCoordinate,
                    newVerticesCoordinate.Length / 3,
                    newTriangles,
                    newTriangles.Length / 3
                    ) == -1)
            {
                Debug.Log(" 만들어지지 않음");
                return;
            }

            if (CGAL.FillHole(stamp) == -1)
            {
                Debug.Log("fillhole error");
                return;
            }

            if (CGAL.ClipPolyhedronByMesh(heart, stamp) == -1)
            {
                Debug.Log("Clip error");
                return;
            }
            MeshManager.Instance.SetNewObject(CGAL.GenerateNewObject(heart, heartMaterial));
            MakeDoubleFaceMesh.Instance.Reinitialize();
            //// 여기에 이제 잘리고나서 작업 넣어줘야됨. 새로운 메쉬로 바꾸고 정리하는 형태가 되어야함.

            ////MeshManager.Instance.Heart.SetActive(false);
        }
    }