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;
    }
Example #2
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 #3
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;
    }
    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;
        }
    }