Exemplo n.º 1
0
    private void CGALCut()
    {
        if (isIntersected)
        {
            Debug.Log("intersected true");
            MultiMeshAdjacencyList.Instance.Initialize();

            IntPtr HeartPart = CGAL.CreateMeshObject();
            IntPtr stamp     = CGAL.CreateMeshObject();

            float[] verticesCoordinate = CGAL.ConvertToFloatArray(MultiMeshAdjacencyList.Instance.WorldPositionVertices[HitOBJIndex].ToArray());

            if (CGAL.BuildPolyhedron(HeartPart,
                                     verticesCoordinate,
                                     verticesCoordinate.Length / 3,
                                     MultiMeshManager.Instance.Meshes[HitOBJIndex].triangles,
                                     MultiMeshManager.Instance.Meshes[HitOBJIndex].triangles.Length / 3) == -1)
            {
                Debug.Log(" 만들어지지 않음");
                return;
            }

            Vector3[] newVertices  = new Vector3[rayList.Count * 2];
            int[]     newTriangles = new int[rayList.Count * 6];
            CGAL.MultiMeshGenerateStampWithHeart(intersectedVerticesPos, rayList, ref newVertices, ref newTriangles, HitOBJIndex);
            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(HeartPart, stamp) == -1)
            {
                Debug.Log("Clip error");
                return;
            }

            MultiMeshManager.Instance.SetNewObject(CGAL.GenerateNewObject(HeartPart, heartMaterial, HitOBJIndex), HitOBJIndex);
            MultiMeshManager.Instance.ReInitialize();
        }
        else
        {
            IntPtr  HeartPart          = CGAL.CreateMeshObject();
            IntPtr  stamp              = CGAL.CreateMeshObject();
            float[] verticesCoordinate = CGAL.ConvertToFloatArray(MultiMeshAdjacencyList.Instance.WorldPositionVertices[HitOBJIndex].ToArray());

            if (CGAL.BuildPolyhedron(HeartPart,
                                     verticesCoordinate,
                                     verticesCoordinate.Length / 3,
                                     MultiMeshManager.Instance.Meshes[HitOBJIndex].triangles,
                                     MultiMeshManager.Instance.Meshes[HitOBJIndex].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(HeartPart, stamp) == -1)
            {
                Debug.Log("Clip error");
                return;
            }
            MultiMeshManager.Instance.SetNewObject(CGAL.GenerateNewObject(HeartPart, heartMaterial, HitOBJIndex), HitOBJIndex);
            MultiMeshManager.Instance.ReInitialize();
        }
    }