private void StartPick(int i)
        {
            if (onDeactivateGizmos != null)
            {
                onDeactivateGizmos.Invoke();
            }
            pickingVertexIndex = i;
            pickingVertex      = true;
            for (int j = 0; j < vertexInfos.Length; j++)
            {
                vertexInfos[j].coordsBforeEdit = vertexInfos[j].currentCoords;
                if (j != i)
                {
                    vertexInfos[j].DisableUIElements();
                }
            }

            if (!vertexPicker)
            {
                vertexPicker = Instantiate(vertexPickerPrefab).GetComponentInChildren <CapsuleRay>();
                vertexPicker.SetCamera(CVSPUIManager.GetEditorCamera());
            }
            vertexPicker.SetActive(true);
            vertexInfos[i].oldCoords = vertexInfos[i].currentCoords;
            selectedHighlight.SetActive(true);
            Vector3 pos = selectedHighlight.transform.position;

            StopAllCoroutines();
            StartCoroutine(CVSPUIUtils.UIMovementCoroutine(selectedHighlight, 0.15f, new Vector3(pos.x, vertexInfos[i].parentObject.position.y, pos.z)));
        }
        private void PickNext()
        {
            vertexInfos[pickingVertexIndex].DisableUIElements();
            pickingVertexIndex = (pickingVertexIndex + 1) % vertexInfos.Length;
            if (pickingVertexIndex == deletedIndex)
            {
                pickingVertexIndex = (pickingVertexIndex + 1) % vertexInfos.Length;
            }
            vertexInfos[pickingVertexIndex].EnableUIElements();
            Vector3 pos = selectedHighlight.transform.position;

            StopAllCoroutines();
            StartCoroutine(CVSPUIUtils.UIMovementCoroutine(selectedHighlight, 0.15f, new Vector3(pos.x, vertexInfos[pickingVertexIndex].parentObject.position.y, pos.z)));
        }
Beispiel #3
0
        private void OnGUI()
        {
            if (null == centeredGUIStyle)
            {
                centeredGUIStyle = new GUIStyle("box");
                centeredGUIStyle.normal.textColor = Color.red;
                centeredGUIStyle.alignment        = TextAnchor.MiddleCenter;
                centeredGUIStyle.fontSize         = 16;
            }
            if (!input || !(bWrnFileExists || bWrnInvalidName))
            {
                return;
            }


            centeredGUIStyle.normal.textColor = bWrnFileExists ? Color.yellow : Color.red;
            GUI.Box(CVSPUIUtils.RectTransformToRect(input.transform as RectTransform), bWrnFileExists ? wrnFileExists : wrnInvalidName, centeredGUIStyle);
        }
 private void OnGUI()
 {
     if (showLabel && labelItem)
     {
         var style = CVSPPresetSelector.centeredGUIStyle;
         if (style == null)
         {
             return;
         }
         style.normal.textColor = Color.white;
         var r = CVSPUIUtils.RectTransformToRect(labelItem.transform as RectTransform, getARectAboveTransform: true);
         r.x               -= 40 - r.width / 2;
         r.width            = 80;
         labelRect.size     = Vector2.Lerp(labelRect.size, r.size, 0.25f);
         labelRect.position = (labelRect.position - r.position).sqrMagnitude > 40000f ? r.position : Vector2.Lerp(labelRect.position, r.position, 0.25f);
         GUI.Box(labelRect, labelInfo.name, style);
     }
 }
Beispiel #5
0
        private void Update()
        {
            if (EdgeVisualizer.Instance == null)
            {
                return;
            }
            if (editorCamera == null)
            {
                return;
            }

            #region Editor demonstration
            //RaycastHit hit;
            //if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 400, layerMask: 1 << 4))
            //    target.transform.position = hit.point;
            #endregion

            #region Rotating View

            /*
             * if (rotatingView)
             * {
             *  if (Input.GetMouseButtonUp(1))
             *      rotatingView = false;
             *  var delta = Input.mousePosition - oldMousePos;
             *  Transform camT = editorCamera.transform;
             *  camT.localRotation = Quaternion.AngleAxis(delta.x * .5f, camT.up) * camT.localRotation;
             *  camT.localRotation = Quaternion.AngleAxis(-delta.y * .5f, camT.right) * camT.localRotation;
             *  camT.LookAt(camT.position + camT.forward, Vector3.up);
             *  oldMousePos = Input.mousePosition;
             * }
             *
             * if (!rotatingView && Input.GetMouseButtonDown(1))
             * {
             *  oldMousePos = Input.mousePosition;
             *  rotatingView = true;
             * }*/
            #endregion

            #region Pan View

            /*
             * if (panView)
             * {
             *  if (Input.GetMouseButtonUp(2))
             *      panView = false;
             *  var delta = Input.mousePosition - oldMousePos;
             *  Transform camT = editorCamera.transform;
             *  camT.Translate(.0625f * delta);
             *  oldMousePos = Input.mousePosition;
             * }
             *
             * if (!panView && Input.GetMouseButtonDown(2))
             * {
             *  oldMousePos = Input.mousePosition;
             *  panView = true;
             * }*/
            #endregion

            Vector3 mouseRayDir = editorCamera.ScreenPointToRay(Input.mousePosition).direction;

            #region Update Probe Direction
            //if (!rotatingView)
            {
                mouseRay.transform.position = editorCamera.transform.position;
                mouseRay.transform.rotation = Quaternion.FromToRotation(Vector3.forward, mouseRayDir);
            }
            #endregion

            #region Move Probe along its length
            // transform.position += Input.mouseScrollDelta.y * .25f * (transform.up);
            #endregion

            #region Move Camera fwd or bkwd
            // editorCamera.transform.position += Input.mouseScrollDelta.y * .25f * editorCamera.transform.forward;
            #endregion

            #region Update snap state
            if (Input.GetKey(KeyCode.LeftControl))
            {
                snapState = SnapStates.Surfaces;
            }
            else if (Input.GetKey(KeyCode.LeftAlt))
            {
                snapState = SnapStates.Edges;
            }
            else
            {
                snapState = SnapStates.Vertices;
            }

            EdgePctSnapFineTune = Input.GetKey(KeyCode.LeftShift);
            if (Input.GetKeyDown(KeyCode.C))
            {
                UseEdgePctSnap = !UseEdgePctSnap;
            }
            #endregion

            if (closestMeshToCamera != null && closestMeshToCamera.Length > 0 && closestMeshToCamera[0])
            {
                Vector3[] meshVerts;
                int[]     meshTris;
                CVSPUIUtils.MergeMeshes(closestMeshToCamera[0].transform, closestMeshToCamera, out meshVerts, out meshTris);
                Matrix4x4 meshTransform = closestMeshToCamera[0].transform.localToWorldMatrix;
                #region Detect nearest vertex to mouse ray, and place a mark on it
                if (snapState == SnapStates.Vertices)
                {
                    closestVertexID     = CVSPUIUtils.GetNeatestVertToMouseRay(meshVerts, meshTransform, editorCamera, mouseRayDir);
                    closestVertexLclPos = meshVerts[closestVertexID];
                    closestVertexWldPos = meshTransform.MultiplyPoint3x4(closestVertexLclPos);
                    vertexMarker.rectTransform.position = editorCamera.WorldToScreenPoint(closestVertexWldPos);
                    vertexMarker.enabled = true;
                    EdgeVisualizer.Instance.VisualizeMeshEdge(closestMeshToCamera[0].mesh, meshVerts, meshTris, closestVertexWldPos, closestMeshToCamera[0].transform.localToWorldMatrix);
                }
                #endregion

                #region Detect nearest triangle to camera which is hit by mouse ray, and place a mark at hit point when SnapStates.Surfaces, or at projected position on edge when SnapStates.Edges. If none has been hit, hide marker
                else if (snapState == SnapStates.Surfaces || snapState == SnapStates.Edges)
                {
                    var result     = CVSPUIUtils.GetNeatestTriHitByMouseRay(meshVerts, meshTris, meshTransform, editorCamera, mouseRayDir);
                    int triangleID = (int)result.w;
                    if (triangleID >= 0)
                    {
                        hitTriangleID        = triangleID;
                        hitPointWldPos       = result;
                        vertexMarker.enabled = true;
                        if (snapState == SnapStates.Surfaces)
                        {
                            vertexMarker.rectTransform.position = editorCamera.WorldToScreenPoint(hitPointWldPos);
                            EdgeVisualizer.Instance.VisualizeMeshEdge(closestMeshToCamera[0].mesh, meshVerts, meshTris, hitPointWldPos, closestMeshToCamera[0].transform.localToWorldMatrix);
                        }
                        else
                        {
                            snappedEdgePointWldPos = CVSPUIUtils.SnapInnerPointToTriangleEdges(meshTransform.MultiplyPoint3x4(meshVerts[meshTris[hitTriangleID]]),
                                                                                               meshTransform.MultiplyPoint3x4(meshVerts[meshTris[hitTriangleID + 1]]),
                                                                                               meshTransform.MultiplyPoint3x4(meshVerts[meshTris[hitTriangleID + 2]]),
                                                                                               hitPointWldPos,
                                                                                               UseEdgePctSnap,
                                                                                               EdgePctSnapFineTune ? 0.125f : 0.25f);
                            vertexMarker.rectTransform.position = editorCamera.WorldToScreenPoint(snappedEdgePointWldPos);
                            EdgeVisualizer.Instance.VisualizeMeshEdge(closestMeshToCamera[0].mesh, meshVerts, meshTris, snappedEdgePointWldPos, closestMeshToCamera[0].transform.localToWorldMatrix);
                        }
                    }
                    else
                    {
                        EdgeVisualizer.Instance.Disable();
                        vertexMarker.enabled = false;
                    }
                }
                #endregion
            }
            else
            {
                EdgeVisualizer.Instance.Disable();
                vertexMarker.enabled = false;
            }
        }