private void DrawingCut() { IntPtr left = CGAL.CreateMeshObject(); IntPtr right = CGAL.CreateMeshObject(); IntPtr stamp = CGAL.CreateMeshObject(); float[] verticesCoordinate = CGAL.ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray()); if (CGAL.BuildPolyhedron(left, verticesCoordinate, verticesCoordinate.Length / 3, MeshManager.Instance.mesh.triangles, MeshManager.Instance.mesh.triangles.Length / 3) == -1) { Debug.Log(" 만들어지지 않음"); } if (CGAL.BuildPolyhedron(right, verticesCoordinate, verticesCoordinate.Length / 3, MeshManager.Instance.mesh.triangles, MeshManager.Instance.mesh.triangles.Length / 3) == -1) { Debug.Log(" 만들어지지 않음"); } ///left right 생성이 됨. ///이상태에서 ///plane의 노말값만 바꿔서 슬라이싱함. /// 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(" 만들어지지 않음"); } CGAL.FillHole(stamp); CGAL.ClipPolyhedronByMesh(left, stamp); // CGAL.GenerateNewObject(left, leftMaterial); // 여기에 이제 잘리고나서 작업 넣어줘야됨. 새로운 메쉬로 바꾸고 정리하는 형태가 되어야함. // 라인렌더러 넣어줘야함. MeshManager.Instance.Heart.SetActive(false); }
public void SetHeartCGAL() { AdjacencyList.Instance.ListUpdate(); heart = CGAL.CreateMeshObject(); float[] verticesCoordinate = CGAL.ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray()); CGAL.BuildPolyhedron(heart, verticesCoordinate, verticesCoordinate.Length / 3, MeshManager.Instance.mesh.triangles, MeshManager.Instance.mesh.triangles.Length / 3); }
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); }
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); } }
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); }
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(); } }