コード例 #1
0
    public void SetEndVerticesDF(int MeshIndex)
    {
        endScreenRay = MultiMeshManager.Instance.cam.ScreenPointToRay(Input.mousePosition);
        IntersectedValues intersectedValues = Intersections.MultiMeshGetIntersectedValues(MeshIndex);

        endVertexPosition     = intersectedValues.IntersectedPosition;
        endOuterTriangleIndex = intersectedValues.TriangleIndex;
    }
コード例 #2
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;
    }
コード例 #3
0
    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(" 절개하였습니다. 확장이 가능합니다.");
        }
    }
コード例 #4
0
    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;
        }
    }