Example #1
0
    private void HandleSlice()
    {
        if (Input.GetMouseButtonDown(0))
        {
            lineRenderer = new LineRendererManipulate(transform);
            Ray ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            oldRay = ray;
            SliceMethods.SetIntersectedValue("first", ray);
            EventManager.Instance.Events.InvokeModeManipulate("StopAll");
        }
        else if (Input.GetMouseButtonUp(0))
        {
            EventManager.Instance.Events.InvokeModeManipulate("EndAll");
            Ray ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            SliceMethods.SetIntersectedValue("second", ray);

            GameObject[] SliceResult = SliceMethods.Slicing();

            for (int i = 0; i < Size; i++)
            {
                LeftHeart[i]  = SliceResult[SliceResultIndex++];
                RightHeart[i] = SliceResult[SliceResultIndex++];
            }

            mode = "select";
            Destroy(lineRenderer.lineObject);
        }
        else if (Input.GetMouseButton(0))
        {
            Ray ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            lineRenderer.SetFixedLineRenderer(oldRay.origin + oldRay.direction * 100f, ray.origin + ray.direction * 100f);
        }
    }
    void Update()
    {
        // 패치 방법부터 바꿔야됨.
        Ray cameraRay = MeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);

        if (isLastPatch)
        {
            Destroy(lineRenderer.lineObject);
            patchManager.GenerateMeshForMeasure();
            isLastPatch = false;
            Destroy(this);
        }
        else if (Input.GetMouseButtonDown(0))
        {
            Ray ray = MeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.GetIntersectedValues();
            if (intersectedValues.Intersected)
            {
                firstRay      = ray;
                oldRay        = ray;
                firstPosition = intersectedValues.IntersectedPosition;
                oldPosition   = intersectedValues.IntersectedPosition;
                EventManager.Instance.Events.InvokeModeManipulate("StopAll");
                AdjacencyList.Instance.ListUpdate();
                patchManager.Generate();
                patchManager.AddVertex(intersectedValues.IntersectedPosition);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (oldPosition == Vector3.zero)
            {
                return;
            }
            EventManager.Instance.Events.InvokeModeManipulate("EndAll");
            lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100, firstRay.origin + firstRay.direction * 100);
            isLastPatch = true;
        }
        else if (Input.GetMouseButton(0))
        {
            if (oldPosition == Vector3.zero)
            {
                return;
            }
            Ray ray = MeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.GetIntersectedValues();

            if (intersectedValues.Intersected)
            {
                //first position이 저장되어 있어야함.
                if (patchCount > 10 && Vector3.Distance(firstPosition, intersectedValues.IntersectedPosition) < 1.0f * MeshManager.Instance.pivotTransform.lossyScale.z)
                {
                    EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                    isLastPatch = true;
                    return;
                }

                if (patchCount != 0)
                {
                    lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100, ray.origin + ray.direction * 100);
                }
                else
                {
                    lineRenderer.SetFixedLineRenderer(oldRay.origin + oldRay.direction * 100, ray.origin + ray.direction * 100);
                }

                if (Vector3.Distance(firstPosition, intersectedValues.IntersectedPosition) > 1.5f * MeshManager.Instance.pivotTransform.lossyScale.z)
                {
                    patchManager.AddVertex(intersectedValues.IntersectedPosition);

                    patchCount++;
                    oldPosition = intersectedValues.IntersectedPosition;
                    oldRay      = ray;
                    return;
                }
            }
            else
            {
                if (patchCount == 0)
                {
                    return;
                }
                Destroy(lineRenderer.lineObject);
                patchManager.RemovePatchVariables();
                ChatManager.Instance.GenerateMessage(" 패치 라인이 심장을 벗어났습니다.");
                FirstSet();
            }
        }
        return;
    }
    private void handleIncision()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit FirstHit;

            if (Physics.Raycast(ray, out FirstHit, 1000f))
            {
                FirstHitObject = FirstHit.collider.gameObject;
            }
            else
            {
                return;
            }

            for (int i = 0; i < Size; i++)
            {
                if (FirstHitObject.name == GameObject.Find("PartialModel").transform.GetChild(i).name)
                {
                    HitOBJIndex = i;
                    MultiMeshManager.Instance.MeshIndex = HitOBJIndex;
                }
            }

            GameObject.Find("Main").GetComponent <CHD>().MeshIndex = HitOBJIndex;
        }

        IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(HitOBJIndex);
        bool checkInside = intersectedValues.Intersected;

        if (Input.GetMouseButtonDown(0) && checkInside)
        {
            EventManager.Instance.Events.InvokeModeManipulate("StopAll");

            firstIncision = true;
            incisionDistance.SetActive(true);
            oldPosition = intersectedValues.IntersectedPosition;

            IncisionManager.IncisionUpdate();
            IncisionManager.SetStartVerticesDF(HitOBJIndex);

            MultiMeshAdjacencyList.Instance.ListUpdate();
        }
        else if (Input.GetMouseButton(0))
        {
            if (!firstIncision)
            {
                return;
            }

            if (!checkInside)
            {
                ChatManager.Instance.GenerateMessage(" 심장을 벗어났습니다.");
                EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                Destroy(lineRenderer.lineObject);
                Destroy(incisionDistance);
                Destroy(this);
            }

            Vector3 currentPosition = intersectedValues.IntersectedPosition;
            Vector3 curPos          = currentPosition;
            Vector3 oldPos          = oldPosition;

            Vector2 newRectPos;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(rectCanvas.transform as RectTransform, Input.mousePosition, rectCanvas.worldCamera, out newRectPos);
            incisionDistance.GetComponent <RectTransform>().localPosition = newRectPos;
            incisionDistance.GetComponent <Text>().text = (Vector3.Distance(oldPos, curPos) / MultiMeshManager.Instance.PivotTransform.localScale.z).ToString("N3") + " mm";

            lineRenderer.SetFixedLineRenderer(oldPos, curPos);
        }
        else if (Input.GetMouseButtonUp(0) && firstIncision)
        {
            if (checkInside)
            {
                Vector3 currentPosition = intersectedValues.IntersectedPosition;

                if (Vector3.Distance(oldPosition, currentPosition) < 2.5f * MultiMeshManager.Instance.PivotTransform.lossyScale.z)
                {
                    EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                    ChatManager.Instance.GenerateMessage(" incision 거리가 너무 짧습니다.");
                    IncisionManager.IncisionUpdate();
                    firstIncision = false;
                    Destroy(incisionDistance);
                    Destroy(lineRenderer.lineObject);
                    return;
                }
            }

            Destroy(lineRenderer.lineObject);
            bool checkEdge = false;

            IncisionManager.SetEndVerticesDF(HitOBJIndex);
            IncisionManager.SetDividingListDF(ref checkEdge, HitOBJIndex);

            if (checkEdge)
            {
                IncisionManager.leftSide.RemoveAt(IncisionManager.currentIndex);
                IncisionManager.rightSide.RemoveAt(IncisionManager.currentIndex);
                IncisionManager.IncisionUpdate();
                EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                Destroy(incisionDistance);
                Destroy(this);
                return;
            }

            // 위에서 잘못되면 끊어야됨.
            IncisionManager.ExecuteDividing(HitOBJIndex);
            MultiMeshAdjacencyList.Instance.ListUpdate();
            IncisionManager.GenerateIncisionList(HitOBJIndex);
            IncisionManager.currentIndex++;

            MultiMeshManager.Instance.Meshes[HitOBJIndex].RecalculateNormals();
            Destroy(incisionDistance);
            mode = "extand";
            MultiMeshManager.Instance.IncisionOk = true;

            EventManager.Instance.Events.InvokeModeManipulate("EndWithoutScaling");
            ChatManager.Instance.GenerateMessage(" 절개하였습니다. 확장이 가능합니다.");
        }
    }
Example #4
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (once == true)
            {
                Ray        ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
                RaycastHit FirstHit;

                if (Physics.Raycast(ray, out FirstHit, 1000f))
                {
                    FirstHitObject = FirstHit.collider.gameObject;
                }
                else
                {
                    return;
                }

                for (int i = 0; i < MultiMeshManager.Instance.Size; i++)
                {
                    if (FirstHitObject.name == GameObject.Find("PartialModel").transform.GetChild(i).name)
                    {
                        HitOBJIndex = i;
                    }
                }

                once = false;
            }
        }

        Ray cameraRay = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);

        if (isLastPatch)
        {
            Destroy(lineRenderer.lineObject);
            patchManager.GenerateMesh();
            isPatchUpdate = true;
            isLastPatch   = false;
            MultiMeshManager.Instance.PatchOk = true;
        }
        else if (isPatchUpdate)
        {
            patchManager.UpdateCurve(MultiMeshManager.Instance.PatchList.Count - 1);
        }
        else if (Input.GetMouseButtonDown(0))
        {
            Ray ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(HitOBJIndex);

            if (intersectedValues.Intersected)
            {
                firstRay      = ray;
                oldRay        = ray;
                firstPosition = intersectedValues.IntersectedPosition;
                oldPosition   = intersectedValues.IntersectedPosition;

                EventManager.Instance.Events.InvokeModeManipulate("StopAll");
                MultiMeshAdjacencyList.Instance.Initialize();

                patchManager.Generate();
                patchManager.AddVertex(intersectedValues.IntersectedPosition);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (oldPosition == Vector3.zero)
            {
                return;
            }

            EventManager.Instance.Events.InvokeModeManipulate("EndAll");
            lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100, firstRay.origin + firstRay.direction * 100);
            isLastPatch = true;
        }
        else if (Input.GetMouseButton(0))
        {
            if (oldPosition == Vector3.zero)
            {
                return;
            }

            Ray ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(HitOBJIndex);

            if (intersectedValues.Intersected)
            {
                if (patchCount > 10 && Vector3.Distance(firstPosition, intersectedValues.IntersectedPosition) < 1.0f * MultiMeshManager.Instance.PivotTransform.lossyScale.z)
                {
                    EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                    isLastPatch = true;
                    return;
                }

                if (patchCount != 0)
                {
                    lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100, ray.origin + ray.direction * 100);
                }
                else
                {
                    lineRenderer.SetFixedLineRenderer(oldRay.origin + oldRay.direction * 100, ray.origin + ray.direction * 100);
                }

                if (Vector3.Distance(firstPosition, intersectedValues.IntersectedPosition) > 1.5f * MultiMeshManager.Instance.PivotTransform.lossyScale.z)
                {
                    patchManager.AddVertex(intersectedValues.IntersectedPosition);
                    oldPosition = intersectedValues.IntersectedPosition;
                    patchCount++;
                    oldRay = ray;
                    return;
                }
            }
            else
            {
                if (patchCount == 0)
                {
                    return;
                }

                Destroy(lineRenderer.lineObject);
                patchManager.RemovePatchVariables();
                ChatManager.Instance.GenerateMessage(" 패치 라인이 심장을 벗어났습니다.");
                FirstSet();
            }
        }
        return;
    }
Example #5
0
    void Update()
    {
        if (isFirst)
        {
            Debug.Log("Boundary cut 실행");
            MeshManager.Instance.SaveCurrentMesh();
            AdjacencyList.Instance.ListUpdate();
            isFirst       = false;
            boundaryCount = 0;
            return;
        }
        else if (isLast)
        {
            CGALCut();
            AdjacencyList.Instance.ListUpdate();
            EventManager.Instance.Events.InvokeModeManipulate("EndAll");
            //EventManager.Instance.Events.InvokeModeChanged("ResetButton");
            Destroy(lineRenderer.lineObject);
            Destroy(this);
        }
        else if (Input.GetMouseButtonDown(0))
        {
            EventManager.Instance.Events.InvokeModeManipulate("StopAll");
            Ray ray = MeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.GetIntersectedValues();

            rayList.Add(ray);
            oldRay   = ray;
            firstRay = ray;
            boundaryCount++;

            if (intersectedValues.Intersected)
            {
                intersectedVerticesPos.Add(intersectedValues.IntersectedPosition);
            }
            else
            {
                isIntersected = false;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            Ray ray = MeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            IntersectedValues intersectedValues = Intersections.GetIntersectedValues();

            lineRenderer.SetFixedLineRenderer(oldRay.origin + oldRay.direction * 100f, ray.origin + ray.direction * 100f);
            if (boundaryCount > 8 && Vector3.Distance(firstRay.origin, ray.origin) < 0.01f)
            {
                lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, firstRay.origin + firstRay.direction * 100f);
                isLast = true;
            }
            else if (Vector3.Distance(oldRay.origin, ray.origin) > 0.005f)
            {
                boundaryCount++;
                lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, ray.origin + ray.direction * 100f);
                oldRay = ray;
                rayList.Add(ray);
                if (intersectedValues.Intersected)
                {
                    intersectedVerticesPos.Add(intersectedValues.IntersectedPosition);
                }
                else
                {
                    isIntersected = false;
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, firstRay.origin + firstRay.direction * 100f);
            isLast = true;
        }
    }
Example #6
0
    private void handleIncision()
    {
        IntersectedValues intersectedValues = Intersections.GetIntersectedValues();
        bool checkInside = intersectedValues.Intersected;

        if (Input.GetMouseButtonDown(0) && checkInside)
        {
            EventManager.Instance.Events.InvokeModeManipulate("StopAll");
            firstIncision = true;
            incisionDistance.SetActive(true);
            oldPosition = intersectedValues.IntersectedPosition;
            IncisionManager.IncisionUpdate();
            AdjacencyList.Instance.ListUpdate();
            IncisionManager.SetStartVerticesDF();
        }
        else if (Input.GetMouseButton(0))
        {
            if (!firstIncision)
            {
                return;
            }

            if (!checkInside)
            {
                Destroy(lineRenderer.lineObject);
                ChatManager.Instance.GenerateMessage(" 심장을 벗어났습니다.");
                EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                Destroy(incisionDistance);
                Destroy(this);
            }
            Vector3 currentPosition = intersectedValues.IntersectedPosition;
            Vector3 curPos          = currentPosition;
            Vector3 oldPos          = oldPosition;

            Vector2 newRectPos;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(rectCanvas.transform as RectTransform, Input.mousePosition, rectCanvas.worldCamera, out newRectPos);
            incisionDistance.GetComponent <RectTransform>().localPosition = newRectPos;

            incisionDistance.GetComponent <Text>().text = (Vector3.Distance(oldPos, curPos) / MeshManager.Instance.pivotTransform.localScale.z).ToString("N3") + " mm";

            lineRenderer.SetFixedLineRenderer(oldPos, curPos);
        }
        else if (Input.GetMouseButtonUp(0) && firstIncision)
        {
            if (checkInside)
            {
                Vector3 currentPosition = intersectedValues.IntersectedPosition;
                if (Vector3.Distance(oldPosition, currentPosition) < 2.5f * MeshManager.Instance.pivotTransform.lossyScale.z)
                {
                    Destroy(incisionDistance);
                    Destroy(lineRenderer.lineObject);
                    EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                    ChatManager.Instance.GenerateMessage(" incision 거리가 너무 짧습니다.");
                    IncisionManager.IncisionUpdate();
                    firstIncision = false;
                    return;
                }
            }
            Destroy(lineRenderer.lineObject);
            bool checkEdge = false;
            IncisionManager.SetEndVerticesDF();
            IncisionManager.SetDividingListDF(ref checkEdge);
            if (checkEdge)
            {
                IncisionManager.leftSide.RemoveAt(IncisionManager.currentIndex);
                IncisionManager.rightSide.RemoveAt(IncisionManager.currentIndex);
                //incisionCount--;
                IncisionManager.IncisionUpdate();
                EventManager.Instance.Events.InvokeModeManipulate("EndAll");
                Destroy(incisionDistance);
                Destroy(this);
                return;
            }

            // 위에서 잘못되면 끊어야됨.
            Debug.Log(MeshManager.Instance.mesh.vertexCount);
            IncisionManager.ExecuteDividing();
            AdjacencyList.Instance.ListUpdate();
            IncisionManager.GenerateIncisionList();
            MakeDoubleFaceMesh.Instance.MeshUpdateInnerFaceVertices();
            //MeshManager.Instance.SaveCurrentMesh();
            IncisionManager.currentIndex++;
            MeshManager.Instance.mesh.RecalculateNormals();
            // chatmanager 대신 popup manager에서 팝업 호출하기.
            ChatManager.Instance.GenerateMessage(" 절개하였습니다. 확장이 가능합니다.");
            Destroy(incisionDistance);
            mode = "extand";
            EventManager.Instance.Events.InvokeModeManipulate("EndWithoutScaling");
        }
    }
    void Update()
    {
        if (isFirst)
        {
            Debug.Log("Boundary cut 실행");
            MultiMeshAdjacencyList.Instance.Initialize();
            isFirst       = false;
            boundaryCount = 0;
            return;
        }
        else if (isLast)
        {
            CGALCut();
            MultiMeshAdjacencyList.Instance.Initialize();
            GameObject.Find("Undo Button").GetComponent <MultiMeshUndoRedo>().MeshList[HitOBJIndex].Add(Instantiate(MultiMeshManager.Instance.Meshes[HitOBJIndex]));
            //GameObject.Find("Undo Button").GetComponent<MultiMeshUndoRedo>().MeshList[HitOBJIndex].Add(Instantiate(GameObject.Find("PartialModel").transform.GetChild(HitOBJIndex).transform.GetChild(0).GetComponent<MeshFilter>().mesh));
            GameObject.Find("Undo Button").GetComponent <MultiMeshUndoRedo>().IBSave(GameObject.Find("Main").GetComponent <CHD>().MeshIndex);
            EventManager.Instance.Events.InvokeModeManipulate("EndAll");
            EventManager.Instance.Events.InvokeModeChanged("ResetButton");
            GameObject.Find("Main").GetComponent <CHD>().AllButtonInteractable();
            Destroy(lineRenderer.lineObject);
            Destroy(this);
        }
        else if (Input.GetMouseButtonDown(0))
        {
            EventManager.Instance.Events.InvokeModeManipulate("StopAll");

            RaycastHit FirstHit;
            Ray        ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out FirstHit, 1000f))
            {
                FirstHitObject = FirstHit.collider.gameObject;
            }
            else
            {
                return;
            }

            for (int i = 0; i < Size; i++)
            {
                if (FirstHitObject.name == GameObject.Find("PartialModel").transform.GetChild(i).name)
                {
                    HitOBJIndex = i;
                }
            }

            GameObject.Find("Main").GetComponent <CHD>().MeshIndex = HitOBJIndex;
            IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(HitOBJIndex);

            rayList.Add(ray);
            oldRay   = ray;
            firstRay = ray;
            boundaryCount++;

            if (intersectedValues.Intersected)
            {
                intersectedVerticesPos.Add(intersectedValues.IntersectedPosition);
            }
            else
            {
                isIntersected = false;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            Ray        ray = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit SecondHit;

            if (Physics.Raycast(ray, out SecondHit, 1000f))
            {
                SecondHitObject = SecondHit.collider.gameObject;
            }
            else
            {
                Debug.Log("영역을 이탈했습니다.");
                Destroy(lineRenderer.lineObject);
                Destroy(this);
                return;
            }

            if (SecondHitObject.name != FirstHitObject.name)
            {
                Debug.Log("영역을 이탈했습니다.");
                Destroy(lineRenderer.lineObject);
                Destroy(this);
                return;
            }

            IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(HitOBJIndex);
            lineRenderer.SetFixedLineRenderer(oldRay.origin + oldRay.direction * 100f, ray.origin + ray.direction * 100f);

            if (boundaryCount > 8 && Vector3.Distance(firstRay.origin, ray.origin) < 0.01f)
            {
                lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, firstRay.origin + firstRay.direction * 100f);
                isLast = true;
            }
            else if (Vector3.Distance(oldRay.origin, ray.origin) > 0.005f)
            {
                boundaryCount++;
                lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, ray.origin + ray.direction * 100f);
                oldRay = ray;
                rayList.Add(ray);

                if (intersectedValues.Intersected)
                {
                    Debug.Log("intersectedVerticesPosCount : " + intersectedVerticesPos.Count);
                    intersectedVerticesPos.Add(intersectedValues.IntersectedPosition);
                }
                else
                {
                    isIntersected = false;
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lineRenderer.SetLineRenderer(oldRay.origin + oldRay.direction * 100f, firstRay.origin + firstRay.direction * 100f);
            isLast = true;
        }
    }