/// <summary>
        /// Update the hovered point.
        /// </summary>
        private void UpdateHoveredPoint()
        {
            var pickRay = m_application.RPickRay.GetRay();

            var hitInfo = new RaycastHit();
            hitInfo.distance = float.NaN;

            GameObject pickedGO = null;

            foreach (var layer in m_application.GetLayers())
            {
                UtilUnity.PickRecursively(
                    layer.Model,
                    pickRay,
                    layer.Model,
                    ref pickedGO,
                    ref hitInfo);
            }

            m_application.RPickRay.HitDistance = hitInfo.distance;

            if (pickedGO != null)
            {
                _hitInfo = hitInfo;
            }
            else
            {
                _hitInfo = null;
            }
        }
        /// <summary>
        /// <see cref="ApplicationState{T}.Update"/> implementation.
        /// </summary>
        public override void Update()
        {
            UpdateControllerUI();

            m_application.Fly();
            m_application.UpdateTrackingSpace();

            var controllerState = m_application.m_controllerInput.m_controllerState;

            // Setting lights as the active object type is done by:
            // - Pressing 'L' on the keyboard.
            if (Input.GetKeyDown(KeyCode.L))
            {
                StartCreateLight();
            }

            // Setting props as the active object type is done by:
            // - Pressing 'F' on the keyboard.
            if (Input.GetKeyDown(KeyCode.F))
            {
                StartCreateProp();
            }

            // Setting POI as the active object type is done by:
            // - Pressing 'P' on the keyboard.
            if (Input.GetKeyDown(KeyCode.P))
            {
                StartCreatePOI();
            }

            // Delete selected lights is performed by:
            //  - Pressing the controller 'B' button.
            var delete = controllerState.bButtonDown;

            if (delete)
            {
                Delete();
            }

            // Additive selection is enabled while:
            // - keeping R controller hand trigger pressed.
            _addToSelection = controllerState.rHandTriggerPressed;

            // Exiting edit mode is done by:
            // - Pressing left controller index trigger.
            var returnToParentState = controllerState.lIndexTriggerDown;

            if (returnToParentState)
            {
                if (!m_application.PropertiesMenuPanel.gameObject.activeSelf)
                {
                    m_application.PopApplicationState();
                }
                else
                {
                    CloseProperties();
                }
                return;
            }

            #region Update hovered object

            GameObject hoveredObject = null;

            var pickRay = m_application.RPickRay.GetRay();

            foreach (var editData in m_application.EditDatas)
            {
                foreach (var gameObject in editData.GameObjects)
                {
                    var hitInfo = new RaycastHit();
                    hitInfo.distance = float.NaN;

                    GameObject pickedGO = null;

                    UtilUnity.PickRecursively(
                        gameObject,
                        pickRay,
                        gameObject,
                        ref pickedGO,
                        ref hitInfo);

                    if (null != pickedGO)
                    {
                        hoveredObject = gameObject;
                        break;
                    }
                }
            }

            OnHover(hoveredObject);

            #endregion Update hovered object

            if (m_application.m_controllerInput.m_controllerState.rIndexTriggerDown)
            {
                if (!m_application.PropertiesMenuPanel.gameObject.activeSelf) // Do not select/unselect objects while properties menu is open.
                {
                    OnSelect(_hoveredObject);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// <see cref="ApplicationState{T}.Update()"/> implementation.
        /// </summary>
        public override void Update()
        {
            //WM.Logger.Debug("ApplicationStateScaleModel.Update()");

            UpdateControllerUI();

            if (m_application.ToggleActiveProject())
            {
                return;
            }

            //if (m_application.ToggleImmersionModeIfInputAndNetworkModeAllows())
            //{
            //    return;
            //}

            // Clients cannot toggle model layer visibility!
            if (m_application.NetworkMode != WM.Net.NetworkMode.Client)
            {
                // Toggle model layer visibility using picking.
                if (m_application.m_controllerInput.m_controllerState.rIndexTriggerDown)
                {
                    if (pickedLayer != null)
                    {
                        m_application.SetModelLayerVisible(pickedLayerIndex, !pickedLayer.activeSelf);
                    }
                    else
                    {
                        m_application.UnhideAllModelLayers();
                    }
                }
            }

            // Show name of picked model layer in right control text.
            m_application.m_rightControllerText.text = (pickedLayer == null) ? "" : pickedLayer.name;

            m_application.Fly();

            #region Maquette manipulation.

            // Clients cannot manipulate model!
            if (m_application.NetworkMode != WM.Net.NetworkMode.Client)
            {
                var cs = m_application.m_controllerInput.m_controllerState;

                float magnitudeRotateMaquette    = cs.lThumbStick.x;
                float magnitudeTranslateMaquette = cs.lThumbStick.y;

                #region Update MaquetteManipulationMode

                bool manipulating = (Mathf.Abs(magnitudeRotateMaquette) > 0.1f) || (Mathf.Abs(magnitudeTranslateMaquette) > 0.1f);

                if (maquetteManipulationMode == ModelManipulationMode.None)
                {
                    if (manipulating)
                    {
                        maquetteManipulationMode = (Mathf.Abs(magnitudeRotateMaquette) > Mathf.Abs(magnitudeTranslateMaquette))
                            ? ModelManipulationMode.Rotate
                            : ModelManipulationMode.Translate;
                    }
                    else
                    {
                        maquetteManipulationMode = ModelManipulationMode.None;
                    }
                }
                else
                {
                    if (!manipulating)
                    {
                        maquetteManipulationMode = ModelManipulationMode.None;
                    }
                }

                #endregion

                float positionOffset = _modelOffset;
                float rotationOffset = _modelRotation;

                switch (maquetteManipulationMode)
                {
                case ModelManipulationMode.Translate:
                {
                    positionOffset = Mathf.Clamp(_modelOffset + magnitudeTranslateMaquette * _modelMoveSpeed * Time.deltaTime, -1.0f, 0.6f);
                }
                break;

                case ModelManipulationMode.Rotate:
                {
                    rotationOffset += magnitudeRotateMaquette * _modelRotateSpeed * Time.deltaTime;
                }
                break;
                }

                if (maquetteManipulationMode != ModelManipulationMode.None)
                {
                    var command = new SetModelLocationCommand(positionOffset, rotationOffset);

                    if (m_application.NetworkMode == NetworkMode.Server)
                    {
                        m_application.Server.BroadcastCommand(command);
                    }
                    else
                    {
                        command.Execute(m_application);
                    }
                }
            }

            #endregion

            #region Updated picked model layer

            // Clients cannot pick model layers!
            if (m_application.NetworkMode != NetworkMode.Client)
            {
                var pickRay = m_application.RPickRay.GetRay();

                var hitInfo = new RaycastHit();
                hitInfo.distance = float.NaN;

                pickedLayer = null;

                foreach (var layer in m_application.GetLayers())
                {
                    UtilUnity.PickRecursively(
                        layer.Model,
                        pickRay,
                        layer.Model,
                        ref pickedLayer,
                        ref hitInfo);
                }

                if (pickedLayer == null)
                {
                    pickedLayerIndex = -1;
                }
                else
                {
                    int layerIndex = 0;
                    foreach (var layer in m_application.GetLayers())
                    {
                        if (pickedLayer == layer.Model)
                        {
                            pickedLayerIndex = layerIndex;
                            break;
                        }
                        ++layerIndex;
                    }
                    Debug.Assert(pickedLayerIndex != -1);
                }

                m_application.RPickRay.HitDistance = hitInfo.distance;
            }

            #endregion

            var controllerState = m_application.m_controllerInput.m_controllerState;

            // Pressing 'BackSpace' on the keyboard is a shortcut for returning to the default state.
            var returnToDefaultState = controllerState.lIndexTriggerDown || Input.GetKeyDown(KeyCode.Backspace);

            if (returnToDefaultState)
            {
                m_application.PopApplicationState();
            }
        }