public void DeformCGAL(Vector3 direction) { Mesh mesh = MeshManager.Instance.mesh; float[] directionFloat = { direction.x, direction.y, direction.z }; CGAL.DeformMesh(heart, directionFloat); Vector3[] newVertices = CGAL.ConvertToVector(CGAL.GetVertices(heart), CGAL.GetNumberOfVertices(heart), GameObject.Find("PartialModel").transform); mesh.vertices = newVertices; }
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 void SetPreprocessCGAL(int centerIndex, float radius) { CGAL.PreprocessDeformMesh(heart, centerIndex, radius, 0.5f); IntPtr asdf = CGAL.GetRoiVertices(heart); int[] lengthTemp = new int[1]; Marshal.Copy(asdf, lengthTemp, 0, 1); int length = lengthTemp[0]; int[] verticesIndex = new int[length]; Marshal.Copy(asdf, verticesIndex, 1, length); Debug.Log(verticesIndex[0]); Debug.Log(verticesIndex.Length); }
//[DllImport("CGALtest_dll", EntryPoint = "CorefineAndIntersection", CallingConvention = CallingConvention.Cdecl)] //public static extern int CorefineAndIntersection(IntPtr value, IntPtr value2, IntPtr value3); public static void GenerateBigTriangle(Vector2 startMousePos, Vector2 endMousePos) //none { Vector2 newVec = startMousePos - endMousePos; float height = Screen.height; float width = Screen.width; float newHeight = (height - startMousePos.y) / newVec.y; float newWidth = (width - startMousePos.x) / newVec.x; float weight = Mathf.Abs(newHeight) > Mathf.Abs(newWidth) ? newWidth : newHeight; Vector2 maximumPos = startMousePos + (newVec * weight); newHeight = (0 - startMousePos.y) / newVec.y; newWidth = (0 - startMousePos.x) / newVec.x; weight = Mathf.Abs(newHeight) > Mathf.Abs(newWidth) ? newWidth : newHeight; Vector2 minimumPos = startMousePos + (newVec * weight); // 각 끝점에서 ray direction 값 가져오고 둘의 중간지점의 origin 값 가져오기. Vector3 maxPos = MeshManager.Instance.cam.ScreenPointToRay(maximumPos).direction.normalized * 1000; Vector3 minPos = MeshManager.Instance.cam.ScreenPointToRay(minimumPos).direction.normalized * 1000; Vector3 middlePos = MeshManager.Instance.cam.ScreenPointToRay(Vector2.Lerp(minimumPos, maximumPos, 0.5f)).origin; IntPtr heart = CreateMeshObject(); float[] verticesCoordinate = ConvertToFloatArray(AdjacencyList.Instance.worldPositionVertices.ToArray()); if (BuildPolyhedron(heart, verticesCoordinate, verticesCoordinate.Length / 3, MeshManager.Instance.mesh.triangles, MeshManager.Instance.mesh.triangles.Length / 3) == -1) { Debug.Log("polyhedron 형성이 안됨."); return; } IntPtr clipper = CreateMeshObject(); float[] verticesClipper = { maxPos.x, maxPos.y, maxPos.z, minPos.x, minPos.y, minPos.z, middlePos.x, middlePos.y, middlePos.z }; int[] trianglesClipper = { 0, 1, 2 }; if (BuildPolyhedron(clipper, verticesClipper, verticesClipper.Length / 3, trianglesClipper, 1) == -1) { Debug.Log("polyhedron 형성이 안됨."); return; } CorefineByMesh(heart, clipper); Debug.Log("done corefine"); // 추가되는 vtx 활용 Vector3[] newVertices = ConvertToVector(GetVertices(heart), GetNumberOfVertices(heart), GameObject.Find("PartialModel").transform); int[] newTriangles = ConvertToTriangle(GetFaces(heart), GetNumberOfFaces(heart)); //AdjacencyList.Instance.worldPositionVertices.cou Material heartMaterial = Resources.Load("Materials/Heart", typeof(Material)) as Material; MeshManager.Instance.SetNewObject(CGAL.GenerateNewObject(heart, heartMaterial)); MakeDoubleFaceMesh.Instance.Reinitialize(); }
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(); } }