Ejemplo n.º 1
0
    public GameObject[] Slicing()
    {
        // left right를 각각 뒤집어 씌울 material을 만들고 색을 다르게해서 각각 잘리면 나눠서 색을 입힘. 그 다음에 유저가 선택하면 선택한 mesh만 지워지도록. 허공을 누르면 다시 오리지널 메쉬로 넘어가게.


        AdjacencyList.Instance.ListUpdate();
        IntPtr left  = CGAL.CreateMeshObject();
        IntPtr right = CGAL.CreateMeshObject();

        GameObject[] result = new GameObject[2];

        float[] verticesCoordinate = CGAL.ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray());

        middlePosition = Vector3.Lerp(firstRay.origin, secondRay.origin, 0.5f);

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

        ///left right 생성이 됨.
        ///이상태에서
        ///plane의 노말값만 바꿔서 슬라이싱함.
        CGAL.ClipPolyhedronByPlane(
            left,
            CGAL.GeneratePlane(
                middlePosition,
                firstRay.origin + firstRay.direction * 10f,
                secondRay.origin + secondRay.direction * 10f));

        CGAL.ClipPolyhedronByPlane(
            right,
            CGAL.GeneratePlane(
                middlePosition,
                secondRay.origin + secondRay.direction * 10f,
                firstRay.origin + firstRay.direction * 10f));

        GameObject leftHeart  = CGAL.GenerateNewObject(left, leftMaterial);
        GameObject rightHeart = CGAL.GenerateNewObject(right, rightMaterial);

        leftWorldPos  = new List <Vector3>();
        rightWorldPos = new List <Vector3>();
        leftWorldPos  = AdjacencyList.Instance.LocalToWorldPosition(leftHeart.GetComponent <MeshFilter>().mesh);
        rightWorldPos = AdjacencyList.Instance.LocalToWorldPosition(rightHeart.GetComponent <MeshFilter>().mesh);

        MeshManager.Instance.Heart.SetActive(false);
        // 여기까지 했고 선택하면 하나 잘리도록 하기.

        result[0] = leftHeart;
        result[1] = rightHeart;
        return(result);
    }
Ejemplo n.º 2
0
    public GameObject[] Slicing()
    {
        MultiMeshAdjacencyList.Instance.Initialize();
        verticesCoordinates = new List <float[]>();

        int ResultIndex = 0;

        for (int j = 0; j < Size; j++)
        {
            Left[j]  = CGAL.CreateMeshObject();
            Right[j] = CGAL.CreateMeshObject();
        }

        middlePosition = Vector3.Lerp(firstRay.origin, secondRay.origin, 0.5f);

        for (int j = 0; j < Size; j++)
        {
            verticesCoordinates.Add(CGAL.ConvertToFloatArray(MultiMeshAdjacencyList.Instance.WorldPositionVertices[j].ToArray()));

            if (CGAL.BuildPolyhedron(Left[j],
                                     verticesCoordinates.ElementAt(j),
                                     verticesCoordinates.ElementAt(j).Length / 3,
                                     MultiMeshManager.Instance.Meshes[j].triangles,
                                     MultiMeshManager.Instance.Meshes[j].triangles.Length / 3) == -1)
            {
                Debug.Log("만들어지지 않음");
            }

            if (CGAL.BuildPolyhedron(Right[j],
                                     verticesCoordinates.ElementAt(j),
                                     verticesCoordinates.ElementAt(j).Length / 3,
                                     MultiMeshManager.Instance.Meshes[j].triangles,
                                     MultiMeshManager.Instance.Meshes[j].triangles.Length / 3) == -1)
            {
                Debug.Log("만들어지지 않음");
            }
        }
        for (int j = 0; j < Size; j++)
        {
            if (
                CGAL.ClipPolyhedronByPlane(
                    Left[j],
                    CGAL.GeneratePlane(
                        middlePosition,
                        firstRay.origin + firstRay.direction * 10f,
                        secondRay.origin + secondRay.direction * 10f)) == -1)
            {
                Debug.Log("만들어지지 않음");
            }

            if (CGAL.ClipPolyhedronByPlane(
                    Right[j],
                    CGAL.GeneratePlane(
                        middlePosition,
                        secondRay.origin + secondRay.direction * 10f,
                        firstRay.origin + firstRay.direction * 10f)) == -1)
            {
                Debug.Log("만들어지지 않음");
            }
            LeftPart[j]  = CGAL.GenerateLeftNewObject(Left[j], leftMaterial, j);
            RightPart[j] = CGAL.GenerateRightNewObject(Right[j], rightMaterial, j);
            MultiMeshManager.Instance.Parts[j].SetActive(false);

            LeftResult[j]  = LeftPart[j];
            RightResult[j] = RightPart[j];

            TotalResult[ResultIndex++] = LeftResult[j];
            TotalResult[ResultIndex++] = RightResult[j];
        }
        return(TotalResult);
    }