示例#1
0
        public override bool HandleDrag(Ray ray, ref Vector3 planeIntersection)
        {
            if (state == State.Base)
            {
                VRMath.GetPointOnPlane(ray, m_Plane, out planeIntersection);
                m_EndPoint = planeIntersection;
                m_EndPoint = Snapping.Snap(m_EndPoint, m_SnapIncrement, VECTOR3_ONE);
            }
            else
            {
                planeIntersection = VRMath.CalculateNearestPointRayRay(ray.origin, ray.direction, m_BaseEndPoint, m_Plane.normal);
                Vector3 dir = planeIntersection - m_BaseEndPoint;
                dir.Normalize();
                float m        = Vector3.Dot(m_Plane.normal, dir) / 1f;
                float distance = Vector3.Distance(planeIntersection, m_BaseEndPoint) * m;
                distance   = Snapping.Snap(distance, m_SnapIncrement);
                m_EndPoint = m_BaseEndPoint + (m_Plane.normal * distance);
            }

            UpdateShape();

            // @todo sanity check ray input to prevent gigantic shapes
            return(true);
        }
        private void HandleFinish(Standard input, Action <InputControl> consumeControl)
        {
            // Ready for next object to be created
            if (input.action.wasJustReleased)
            {
                m_AudioModule.Play(m_Trigger, true);
                m_GuideModule.SetVisible(false);
                m_HighlightModule.SetFaceHighlight(m_Object, null);

                m_Dragging = false;
                m_State    = CreateState.Start;
                m_Object.ToMesh();
                m_Object.Refresh();
            }
            else
            {
                if (m_IsDirectSelect)
                {
                    m_DraggedPoint = m_DragOrigin + (Vector3.Project(rayOrigin.position - m_DragOrigin, m_DragDirection));
                }
                else if (m_VertexSnap.valid)
                {
                    m_DraggedPoint = m_DragOrigin + (Vector3.Project(m_VertexSnap.point - m_DragOrigin, m_DragDirection));
                }
                else
                {
                    m_DraggedPoint = VRMath.CalculateNearestPointRayRay(m_DragOrigin, m_DragDirection, rayOrigin.position, rayOrigin.forward);
                }

                if (!m_Dragging)
                {
                    m_Offset   = m_IsDirectSelect ? m_DraggedPoint - m_DragOrigin : Vector3.zero;
                    m_Dragging = true;
                }

                m_DraggedPoint -= m_Offset;

                Vector3 localDragOrigin   = m_Object.transform.InverseTransformPoint(m_DragOrigin);
                Vector3 localDraggedPoint = m_Object.transform.InverseTransformPoint(m_DraggedPoint);
                Vector3 vertexTranslation = localDraggedPoint - localDragOrigin;

                if (vertexTranslation.magnitude > MAX_TRANSLATE_DISTANCE)
                {
                    vertexTranslation = vertexTranslation.normalized * MAX_TRANSLATE_DISTANCE;
                }

                vertexTranslation = Snapping.Snap(vertexTranslation, m_SnapIncrement, VECTOR3_ONE);

                if (vertexTranslation != m_PreviousVertexTranslation)
                {
                    m_PreviousVertexTranslation = vertexTranslation;
                    m_AudioModule.Play(m_Drag);
                }

                foreach (int ind in m_SelectedIndices)
                {
                    m_SettingPositions[ind] = m_Positions[ind] + vertexTranslation;
                }

                m_Object.SetVertices(m_SettingPositions);
                m_Object.msh.vertices = m_SettingPositions;
                m_Object.RefreshUV();
                m_Object.msh.RecalculateBounds();
                m_HighlightModule.UpdateVertices(m_Object);
            }

            setHighlight(m_Object.gameObject, false);
            consumeControl(input.action);
        }