Exemplo n.º 1
0
        public void CallBack(PulsarMessage message)
        {
            if (message != null)
            {
                switch (message.Type)
                {
                case PulsarMessage.MessageType.MouseWheelZoomIn:
                    _zoom = Zoom.In;
                    AdjustZoom();
                    break;

                case PulsarMessage.MessageType.MouseWheelZoomOut:
                    _zoom = Zoom.Out;
                    AdjustZoom();
                    break;

                case PulsarMessage.MessageType.MouseButtonLeftDownRotate:
                    RotateCamera(message);
                    break;

                case PulsarMessage.MessageType.MouseButtonRightDownPan:
                    PanCamera(message);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void Main_Resize(object sender, EventArgs e)
        {
            var renderSceneWidth         = (int)(0.67252 * Width);
            var sceneTreeWidth           = (int)(0.12345 * Width);
            var propertiesInspectorWidth = (int)(0.19059 * Width);

            PulsarMessage message = new PulsarMessage()
            {
                Type       = PulsarMessage.MessageType.AdjustRenderFormWidth,
                Iterations = 1
            };

            message.Properties.Add("width", renderSceneWidth);
            _application.MessageQueue.PushMessage(message);

            message = new PulsarMessage()
            {
                Type       = PulsarMessage.MessageType.AdjustSceneTreeFormWidth,
                Iterations = 1
            };
            message.Properties.Add("width", sceneTreeWidth);
            _application.MessageQueue.PushMessage(message);

            message = new PulsarMessage()
            {
                Type       = PulsarMessage.MessageType.AdjustPropertiesFormWidth,
                Iterations = 1
            };
            message.Properties.Add("width", propertiesInspectorWidth);
            _application.MessageQueue.PushMessage(message);
        }
Exemplo n.º 3
0
 private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //Find the selected object in the scene
     if (_scene != null)
     {
         if (_scene.SelectedSceneObjects.SelectedObjectCount > 0)
         {
             foreach (SelectedObject selectedObject in _scene.SelectedSceneObjects.ObjectList)
             {
                 if (!selectedObject.SelectedNode.IsDeleted)
                 {
                     selectedObject.MarkForDelete   = true;
                     selectedObject.RemoveFromScene = true;
                     //scene tree to be updated
                     DisplaySceneInTree();
                     //Reset the properties window
                     PulsarMessage pulsarMessage = new PulsarMessage
                     {
                         Type       = PulsarMessage.MessageType.ResetPropertiesWindow,
                         Iterations = 1
                     };
                     _application.MessageQueue.PushMessage(pulsarMessage);
                 }
             }
             //Remove selected items
             PulsarMessage message = new PulsarMessage
             {
                 Type       = PulsarMessage.MessageType.ClearSelectedObjects,
                 Iterations = 1
             };
             _application.MessageQueue.PushMessage(message);
         }
     }
 }
Exemplo n.º 4
0
        private void RotateCamera(PulsarMessage message)
        {
            PulsarCamera camera = null;

            if (_renderSurface.InvokeRequired)
            {
                var delegateCameraRotate = new ThreadSafeCameraRotate(RotateCamera);
                _renderSurface.Invoke(delegateCameraRotate, new object[] { message });
            }
            else
            {
                //get the mouseDelta property from the message
                message.Properties.TryGetValue("mouseDelta", out object mouseDelta);
                if (mouseDelta != null)
                {
                    IntVector2 delta = (IntVector2)mouseDelta;
                    if (delta != null)
                    {
                        camera = _mainApplication.DisplayScene.SceneCamera;
                        if (camera != null)
                        {
                            //remove any Z component computed as a result of a previous 'Rotate' call
                            //fixes Z axis rotation to zero thus preventing camera roll
                            var cameraRotation = camera.Node.Rotation.ToEulerAngles();
                            cameraRotation.Z     = 0;
                            camera.Node.Rotation = new Quaternion(cameraRotation.X, cameraRotation.Y, cameraRotation.Z);
                            //do the desired rotation
                            camera.Node.Rotate(new Quaternion(delta.Y, delta.X, 0));
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void InformMainToChangeProperties(string treeNodeName)
        {
            //send a reset properties view message
            if (_mainApplication != null)
            {
                PulsarMessage pulsarMessage = new PulsarMessage
                {
                    Type       = PulsarMessage.MessageType.ResetPropertiesWindow,
                    Iterations = 1
                };
                _mainApplication.MessageQueue.PushMessage(pulsarMessage);
            }

            switch (treeNodeName)
            {
            case var light when(light?.Contains("MainDirectionalLight") == true):
                SendShowObjectPropertiesMessage(SceneObjectType.Light, _currentScene.GetChild(treeNodeName));

                break;

            case var camera when(camera?.ToLower().Contains("camera") == true):
                SendShowObjectPropertiesMessage(SceneObjectType.Camera, _currentScene.GetChild(treeNodeName));

                break;

            default:
                SendShowObjectPropertiesMessage(SceneObjectType.Node, _currentScene.GetChild(treeNodeName));
                break;
            }
        }
Exemplo n.º 6
0
 public void CallBack(PulsarMessage message)
 {
     if (message != null)
     {
         _receivedMessage = message;
         Application.InvokeOnMain(ProcessMessageMainThread);
     }
 }
Exemplo n.º 7
0
        private void PanCamera(PulsarMessage message)
        {
            PulsarCamera camera = null;

            if (_renderSurface.InvokeRequired)
            {
                var delegateCameraRotate = new ThreadSafeCameraPan(PanCamera);
                _renderSurface.Invoke(delegateCameraRotate, new object[] { message });
            }
            else
            {
                string keyPressed = "";
                //check if any constraint key is present
                message.Properties.TryGetValue("constrainKeyDown", out object constrainKeyPressed);
                bool keyDownFound = (constrainKeyPressed != null);
                if (keyDownFound)
                {
                    keyPressed = (string)constrainKeyPressed;
                }
                //get the mouseDelta property from the message
                message.Properties.TryGetValue("mouseDelta", out object mouseDelta);
                if (mouseDelta != null)
                {
                    IntVector2 delta = (IntVector2)mouseDelta;
                    if (delta != null)
                    {
                        camera = _mainApplication.DisplayScene.SceneCamera;
                        if (camera != null)
                        {
                            //only pan horizontally if there is no vertical constraint
                            if (!keyDownFound || keyPressed != "shift")
                            {
                                if (delta.X > 0)
                                {
                                    camera.Node.Translate(Vector3.Right * 3);
                                }
                                else if (delta.X < 0)
                                {
                                    camera.Node.Translate(Vector3.Left * 3);
                                }
                            }
                            //only pan vertically if there is no horizontal constraint
                            if (!keyDownFound || keyPressed != "ctrl")
                            {
                                if (delta.Y > 0)
                                {
                                    camera.Node.Translate(Vector3.Down * 3);
                                }
                                else if (delta.Y < 0)
                                {
                                    camera.Node.Translate(Vector3.Up * 3);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void CallBack(PulsarMessage message)
        {
            if (message != null)
            {
                message.Properties.TryGetValue("sceneObject", out object sceneObject);
                message.Properties.TryGetValue("externallySet", out object externallySet);

                switch (message.Type)
                {
                case PulsarMessage.MessageType.ResetPropertiesWindow:
                    var delegateReset = new ThreadSafeResetPropertiesGrid(ResetPropertiesWindow);
                    propertyGrid.Invoke(delegateReset, Array.Empty <object>());
                    break;

                case PulsarMessage.MessageType.ShowObjectProperties:
                    var delegateShowObjectProperties = new ThreadSafeShowObjectProperties(SetProperties);
                    if (sceneObject != null)
                    {
                        message.Properties.TryGetValue("sceneObjectType", out object sceneObjectType);
                        if (sceneObjectType != null && externallySet != null)
                        {
                            propertyGrid.Invoke(delegateShowObjectProperties, new object[] { (SceneObjectType)sceneObjectType, sceneObject, (bool)externallySet });
                        }
                    }
                    break;

                case PulsarMessage.MessageType.NodeTranslationChange:
                    var delegateTranslationChange = new ThreadSafeNodeTranslationChange(TranslationChange);
                    if (sceneObject != null && externallySet != null)
                    {
                        propertyGrid.Invoke(delegateTranslationChange, new object[] { ((Node)sceneObject).Position, (bool)externallySet });
                    }
                    break;

                case PulsarMessage.MessageType.NodeRotationChange:
                    var delegateRotationChange = new ThreadSafeNodeRotationChange(RotationChange);
                    if (sceneObject != null && externallySet != null)
                    {
                        propertyGrid.Invoke(delegateRotationChange, new object[] { ((Node)sceneObject).Rotation, (bool)externallySet });
                    }
                    break;

                case PulsarMessage.MessageType.NodeScaleChange:
                    var delegateScaleChange = new ThreadSafeNodeScaleChange(ScaleChange);
                    if (sceneObject != null && externallySet != null)
                    {
                        propertyGrid.Invoke(delegateScaleChange, new object[] { ((Node)sceneObject).Scale, (bool)externallySet });
                    }
                    break;

                case PulsarMessage.MessageType.AdjustPropertiesFormWidth:
                    AdjustFormWidth(message);
                    break;
                }
            }
        }
Exemplo n.º 9
0
        private void SendDraggingStoppedMessage()
        {
            PulsarMessage pulsarMessage = new PulsarMessage
            {
                Type       = PulsarMessage.MessageType.DraggingStopped,
                Iterations = 1
            };

            MessageQueue.PushMessage(pulsarMessage);
        }
Exemplo n.º 10
0
        private void ProcessMouseRotation(IntVector2 mouseMovingDelta)
        {
            PulsarMessage pulsarMessage = new PulsarMessage
            {
                Type       = PulsarMessage.MessageType.MouseButtonLeftDownRotate,
                Iterations = 1
            };

            pulsarMessage.Properties.Add("mouseDelta", mouseMovingDelta);

            MessageQueue.PushMessage(pulsarMessage);
        }
Exemplo n.º 11
0
 public void CallBack(PulsarMessage message)
 {
     if (message != null)
     {
         switch (message.Type)
         {
         case PulsarMessage.MessageType.ClearSelectedObjects:
             _scene.SelectedSceneObjects.Clear();
             break;
         }
     }
 }
Exemplo n.º 12
0
        private void SendResetPropertiesWindowMessage()
        {
            PulsarMessage message = new PulsarMessage()
            {
                Type       = PulsarMessage.MessageType.ResetPropertiesWindow,
                Iterations = 1
            };

            if (message != null)
            {
                MessageQueue.PushMessage(message);
            }
        }
Exemplo n.º 13
0
        public void Update(float timeStep)
        {
            //Actions are not part of the scene and, so, we cannot set ReceiveSceneUpdates in the constructor
            //In this case the BaseEntity is set to ReceiveSceneUpdates and then calls this method
            //if there are any actions so that updates can be performed

            //make sure that if there are any actions being performed we update the gizmo pos/rot
            if (_actions.Count() > 0)
            {
                //if any actions are running then update
                if (ActionsAreRunning())
                {
                    if (BaseEntity != null)
                    {
                        //get the gizmo
                        Gizmo gizmo = BaseEntity.GetGizmo();
                        if (gizmo != null)
                        {
                            gizmo.Node.Position = Node.Position;
                            gizmo.Node.Rotation = Node.Rotation;

                            //now we need to create messages so the properties of this actions node
                            //get updated whilst the actions run
                            PulsarMessage message = new PulsarMessage
                            {
                                Type       = PulsarMessage.MessageType.NodeTranslationChange,
                                Iterations = 1
                            };
                            message.Properties.Add("nodeName", Node.Name);
                            message.Properties.Add("changeType", PulsarMessage.MessageType.NodeTranslationChange);
                            message.Properties.Add("sceneObject", Node);
                            message.Properties.Add("externallySet", true);
                            BaseEntity.PulsarScene.GetApplication().MessageQueue.PushMessage(message);

                            message = new PulsarMessage
                            {
                                Type       = PulsarMessage.MessageType.NodeRotationChange,
                                Iterations = 1
                            };
                            message.Properties.Add("nodeName", Node.Name);
                            message.Properties.Add("changeType", PulsarMessage.MessageType.NodeRotationChange);
                            message.Properties.Add("sceneObject", Node);
                            message.Properties.Add("externallySet", true);
                            BaseEntity.PulsarScene.GetApplication().MessageQueue.PushMessage(message);
                        }
                    }
                }

                RemoveCompletedActions();
            }
        }
Exemplo n.º 14
0
 void IRegisterMessage.CallBack(PulsarMessage message)
 {
     if (message != null)
     {
         switch (message.Type)
         {
         case PulsarMessage.MessageType.NodeNameChanged:
         case PulsarMessage.MessageType.RefreshTreeView:
             var displaySceneElements = new ThreadSafeDisplaySceneElements(DisplaySceneElements);
             _sceneTreeView.Invoke(displaySceneElements, Array.Empty <object>());
             break;
         }
     }
 }
Exemplo n.º 15
0
        private void ProcessMousePan(IntVector2 mouseDeltaPan, bool constrainKeyDown)
        {
            PulsarMessage pulsarMessage = new PulsarMessage
            {
                Type       = PulsarMessage.MessageType.MouseButtonRightDownPan,
                Iterations = 1
            };

            pulsarMessage.Properties.Add("mouseDelta", mouseDeltaPan);
            if (constrainKeyDown)
            {
                string keyPressed = _input.GetKeyDown(Key.LeftShift) ? "shift" : "ctrl";
                pulsarMessage.Properties.Add("constrainKeyDown", keyPressed);
            }
            MessageQueue.PushMessage(pulsarMessage);
        }
Exemplo n.º 16
0
 private void AdjustFormWidth(PulsarMessage message)
 {
     if (InvokeRequired)
     {
         var delegateFormResize = new ThreadSafeFormResize(AdjustFormWidth);
         Invoke(delegateFormResize, new object[] { message });
     }
     else
     {
         if (message.Properties.Count > 0)
         {
             message.Properties.TryGetValue("width", out object widthProperty);
             if (widthProperty != null)
             {
                 Width = (int)widthProperty;
             }
         }
     }
 }
Exemplo n.º 17
0
        private void SendShowObjectPropertiesMessage(SceneObjectType objectType, object sceneObject)
        {
            if (_mainApplication != null)
            {
                PulsarMessage message = new PulsarMessage
                {
                    Type       = PulsarMessage.MessageType.ShowObjectProperties,
                    Iterations = 1
                };

                message.Properties.Add("sceneObjectType", objectType);
                message.Properties.Add("sceneObject", sceneObject);
                message.Properties.Add("externallySet", false);

                if (message != null)
                {
                    _mainApplication.MessageQueue.PushMessage(message);
                }
            }
        }
Exemplo n.º 18
0
 public void CallBack(PulsarMessage message)
 {
     if (message != null)
     {
         //Debug.Print("NodeProperties.CallBack - Received message...");
         switch (message.Type)
         {
         case PulsarMessage.MessageType.DraggingStopped:
             //Debug.Print("NodeProperties.CallBack - Message is type 'DraggingStopped'");
             if (_container != null)
             {
                 //Debug.Print("NodeProperties.CallBack - Container is set, externallySet flag changed to false");
                 //reset the 'externallySet' flag on the control itself
                 _container.ExternallySet = false;
                 _externallySet           = false;
             }
             break;
         }
     }
 }
Exemplo n.º 19
0
        private void SendScaleChangeMessage(Node sceneObject)
        {
            if (_pulsarApplication != null)
            {
                PulsarMessage message = new PulsarMessage()
                {
                    Type       = PulsarMessage.MessageType.NodeScaleChange,
                    Iterations = 1
                };
                message.Properties.Add("nodeName", sceneObject.Name);
                message.Properties.Add("changeType", PulsarMessage.MessageType.NodeScaleChange);
                message.Properties.Add("sceneObject", sceneObject);
                message.Properties.Add("externallySet", true);

                if (message != null)
                {
                    _pulsarApplication.MessageQueue.PushMessage(message);
                }
            }
        }
Exemplo n.º 20
0
        public void CallBack(PulsarMessage message)
        {
            if (message != null)
            {
                switch (message.Type)
                {
                case PulsarMessage.MessageType.AdjustRenderFormWidth:
                    AdjustFormWidth(message);
                    break;

                case PulsarMessage.MessageType.MouseWheelZoomIn:
                    _zoom = Zoom.In;
                    AdjustZoom();
                    break;

                case PulsarMessage.MessageType.MouseWheelZoomOut:
                    _zoom = Zoom.Out;
                    AdjustZoom();
                    break;
                }
            }
        }
Exemplo n.º 21
0
 private void ProcessMouseWheel(int mouseWheelDelta)
 {
     if (mouseWheelDelta > 0)
     {
         // zooming in
         PulsarMessage pulsarMessage = new PulsarMessage
         {
             Type       = PulsarMessage.MessageType.MouseWheelZoomIn,
             Iterations = 1
         };
         MessageQueue.PushMessage(pulsarMessage);
     }
     else if (mouseWheelDelta < 0)
     {
         // zooming out
         PulsarMessage pulsarMessage = new PulsarMessage
         {
             Type       = PulsarMessage.MessageType.MouseWheelZoomOut,
             Iterations = 1
         };
         MessageQueue.PushMessage(pulsarMessage);
     }
 }
Exemplo n.º 22
0
 private void ProcessMouseEvents()
 {
     //zoom
     //start by getting the main camera
     if (DisplayScene != null)
     {
         var camera = DisplayScene.GetMainCameraNode();
         if (camera != null)
         {
             if (_input != null)
             {
                 var mouseDelta = _input.MouseMoveWheel;
                 if (mouseDelta > 0)
                 {
                     // zooming in
                     PulsarMessage pulsarMessage = new PulsarMessage
                     {
                         Type       = PulsarMessage.MessageType.MouseWheelZoomIn,
                         Iterations = 1
                     };
                     MessageQueue.PushMessage(pulsarMessage);
                 }
                 else
                 {
                     // zooming out
                     PulsarMessage pulsarMessage = new PulsarMessage
                     {
                         Type       = PulsarMessage.MessageType.MouseWheelZoomOut,
                         Iterations = 1
                     };
                     MessageQueue.PushMessage(pulsarMessage);
                 }
             }
         }
     }
 }
Exemplo n.º 23
0
        private void SendScaleChangeMessage(Node sceneObject)
        {
            PulsarMessage message;

            if (Application != null)
            {
                try
                {
                    message = new PulsarMessage()
                    {
                        Type       = PulsarMessage.MessageType.NodeScaleChange,
                        Iterations = 1
                    };
                }
                catch (PulsarMessageException createMessageException)
                {
                    createMessageException.Source   = "[Dragger:SendScaleChangeMessage]";
                    createMessageException.Message += " - Unable to create PulsarMessage for message type NodeScaleChange";
                    throw createMessageException;
                }

                if (message != null && sceneObject != null)
                {
                    try
                    {
                        message.Properties.Add("nodeName", sceneObject.Name);
                    }
                    catch (PulsarMessageException nodeNameException)
                    {
                        nodeNameException.Source   = "[Dragger:SendScaleChangeMessage]";
                        nodeNameException.Message += " - Unable to add message property 'nodeName'";
                        throw nodeNameException;
                    }

                    try
                    {
                        message.Properties.Add("changeType", PulsarMessage.MessageType.NodeScaleChange);
                    }
                    catch (PulsarMessageException changeTypeException)
                    {
                        changeTypeException.Source   = "[Dragger:SendScaleChangeMessage]";
                        changeTypeException.Message += " - Unable to add message property 'changeType'";
                        throw changeTypeException;
                    }

                    try
                    {
                        message.Properties.Add("sceneObject", sceneObject);
                    }
                    catch (PulsarMessageException sceneObjectException)
                    {
                        sceneObjectException.Source   = "[Dragger:SendScaleChangeMessage]";
                        sceneObjectException.Message += " - Unable to add message property 'sceneObject'";
                        throw sceneObjectException;
                    }

                    try
                    {
                        message.Properties.Add("externallySet", true);
                    }
                    catch (PulsarMessageException externallySetException)
                    {
                        externallySetException.Source   = "[Dragger:SendScaleChangeMessage]";
                        externallySetException.Message += " - Unable to add message property 'externallySet'";
                        throw externallySetException;
                    }

                    if (Application.MessageQueue != null)
                    {
                        try
                        {
                            Application.MessageQueue.PushMessage(message);
                        }
                        catch (PulsarMessageException pushMessageException)
                        {
                            pushMessageException.Source   = "[Dragger:SendScaleChangeMessage]";
                            pushMessageException.Message += " - Unable to add message to application message queue";
                            throw pushMessageException;
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
        public void CheckForSelection(Node hitNode, Drawable hitDrawable, bool treeViewSelection = false)
        {
            bool multipleSelect = true;

            BaseEntity baseEntity = null;

            if (Input.GetMouseButtonPress(MouseButton.Left))
            {
                _treeviewNodeClicked = false;
                //if the node is null, we should remove all items from the list

                if (hitNode != null)
                {
                    if (!hitNode.Name.Contains("wirePlane"))
                    {
                        if (hitNode.Components.Count > 0)
                        {
                            if (!hitNode.Name.ToLower().Contains("gizmo"))
                            {
                                //baseEntity from component
                                baseEntity = hitNode.GetComponent <BaseEntity>();
                                if (baseEntity == null)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                //baseEntity from gizmo (parent/parent/baseentity)
                                var parent1 = hitNode.Parent;
                                if (parent1 != null)
                                {
                                    var parent2 = parent1.Parent;
                                    if (parent2 != null)
                                    {
                                        if (parent2.Components.Count > 0)
                                        {
                                            var parent2Gizmo = parent2.GetComponent <Gizmo>();
                                            if (parent2Gizmo != null)
                                            {
                                                baseEntity = parent2Gizmo.BaseEntity;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return;
                        }

                        if (baseEntity != null)
                        {
                            if (!baseEntity.IsSelected)
                            {
                                //if the user has pressed Shift button, then we need to add to the selected object list, otherwise
                                //we should clear the list first
                                if (!Input.GetKeyDown(Key.Shift))
                                {
                                    multipleSelect = false;
                                    DisplayScene.SelectedSceneObjects.ResetGizmosAndMaterials();
                                    DisplayScene.SelectedSceneObjects.Clear();
                                    SendResetPropertiesWindowMessage();
                                }

                                if (!hitNode.Name.Contains("wirePlane"))
                                {
                                    SelectedObject selectedObject = new SelectedObject
                                    {
                                        SelectedNode = hitNode,
                                        Drawable     = hitDrawable
                                    };

                                    if (baseEntity != null)
                                    {
                                        baseEntity.SetAsSelected();
                                        //send a message to show the object properties
                                        PulsarMessage message = new PulsarMessage()
                                        {
                                            Type       = PulsarMessage.MessageType.ShowObjectProperties,
                                            Iterations = 1
                                        };
                                        message.Properties.Add("sceneObjectType", GetSceneObjectType(hitNode));
                                        message.Properties.Add("sceneObject", hitNode);
                                        message.Properties.Add("externallySet", false);
                                        if (message != null)
                                        {
                                            MessageQueue.PushMessage(message);
                                        }
                                    }

                                    SceneNodeClicked?.Invoke(SceneObjectType.Node, hitNode, multipleSelect);

                                    DisplayScene.SelectedSceneObjects.AddSelectedObject(selectedObject);
                                }
                            }
                        }
                    }
                    else
                    {
                        DisplayScene.SelectedSceneObjects.ResetGizmosAndMaterials();
                        DisplayScene.SelectedSceneObjects.Clear();
                        //Using this event and passing null to inform the scenetree form that any previously selected node should be cleared (as wirePanel was hit and we've reset all gizmos and materials)
                        SceneNodeClicked?.Invoke(SceneObjectType.Node, null, false);
                        //Send message to properties window to clear its display
                        SendResetPropertiesWindowMessage();
                    }
                }
                else
                {
                    DisplayScene.SelectedSceneObjects.ResetGizmosAndMaterials();
                    DisplayScene.SelectedSceneObjects.Clear();
                    //Using this event and passing null to inform the scenetree form that any previously selected node should be cleared (as nothing was hit and we've reset all gizmos and materials)
                    SceneNodeClicked?.Invoke(SceneObjectType.Node, null, false);
                    SendResetPropertiesWindowMessage();
                }
            }
        }
Exemplo n.º 25
0
        protected override void OnUpdate(float timeStep)
        {
            base.OnUpdate(timeStep);

            var markedForDelete = DisplayScene.SelectedSceneObjects.ObjectList.Find(node => node.MarkForDelete == true);

            if (markedForDelete != null)
            {
                if (!markedForDelete.SelectedNode.IsDeleted)
                {
                    //is this an ACTUAL deletion from the scene
                    if (markedForDelete.RemoveFromScene)
                    {
                        var node = markedForDelete.SelectedNode;
                        if (node != null)
                        {
                            var gizmo = DisplayScene.GetChild(node.Name + "_gizmo");
                            try
                            {
                                if (gizmo != null)
                                {
                                    DisplayScene.RemoveChild(gizmo);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.Print("An access violation occurred here attempting to remove '" + node.Name + "_gizmo'\n" + ex.Message);
                            }

                            DisplayScene.RemoveChild(node);

                            PulsarMessage pulsarMessage = new PulsarMessage
                            {
                                Type       = PulsarMessage.MessageType.RefreshTreeView,
                                Iterations = 1
                            };
                            MessageQueue.PushMessage(pulsarMessage);
                        }
                    }
                    else
                    {
                        PulsarModel pulsarModel = markedForDelete.SelectedNode?.GetComponent <PulsarModel>();
                        if (pulsarModel != null)
                        {
                            BaseEntity baseEntity = pulsarModel.GetBaseEntity();
                            if (baseEntity != null)
                            {
                                baseEntity.UnSelect();
                                DisplayScene.SelectedSceneObjects.ObjectList.Remove(markedForDelete);
                            }
                        }
                    }
                }
            }

            //TEST INPUT TO MOVE CAMERA AROUND

            Input input = Input;

            //get the camera to look at the box
            PulsarCamera camera  = DisplayScene.SceneCamera;
            Node         boxNode = DisplayScene.BoxNode;

            //camera.Camera.Node.LookAt(Vector3.Zero, Vector3.Up);

            if (_hudText == null)
            {
                _hudText = new Text();
                _hudText.SetColor(Color.Black);
                _hudText.SetFont(ResourceCache.GetFont("Fonts/arial.ttf", false), 24);

                UI.Root.AddChild(_hudText);
            }

            Node hitNode = null;


            if (Raycast(1000.0f, camera.Camera, out Vector3 hitPos, out Drawable hitDrawable))
            {
                if (hitDrawable != null)
                {
                    hitNode = hitDrawable.Node;
                    if (hitNode != null)
                    {
                        //exclude the wireFrame
                        if (!hitNode.Name.Contains("wirePlane"))
                        {
                            _hudText.Value = "Hit - " + hitNode.Name;
                            BoundingBox bounds = hitDrawable.WorldBoundingBox;
                            DisplayScene.SceneDebugRenderer.AddBoundingBox(bounds, Color.Red);
                        }
                    }
                }
            }

            // Movement speed as world units per second
            const float moveSpeed = 10.0f;
            // Read WASD keys and move the camera scene node to the
            // corresponding direction if they are pressed
            Node cameraNode = camera.Camera.Node;

            if (cameraNode != null)
            {
                if (input.GetKeyDown(Key.S))
                {
                    cameraNode.Translate(Vector3.UnitY * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.W))
                {
                    cameraNode.Translate(new Vector3(0.0f, -1.0f, 0.0f) * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.D))
                {
                    cameraNode.Translate(new Vector3(-1.0f, 0.0f, 0.0f) * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.A))
                {
                    cameraNode.Translate(Vector3.UnitX * moveSpeed * timeStep, TransformSpace.Local);
                }

                camera.BaseEntity.Position = cameraNode.Position;
                camera.BaseEntity.Rotation = cameraNode.Rotation.ToEulerAngles();
            }

            ProcessMouseEvents();

            CheckForSelection(hitNode, hitDrawable, _treeviewNodeClicked);

            DrawSelectedObjects();

            if (_dragger.IsDragging)
            {
                DoGizmoTransform(null);
            }
            else if (hitNode != null)
            {
                if (hitNode.Name.Contains("GizmoNode"))
                {
                    DoGizmoTransform(hitNode);
                }
            }
        }
Exemplo n.º 26
0
        public void CheckForSelection(Node hitNode, Drawable hitDrawable, bool treeViewSelection = false)
        {
            bool multipleSelect = true;

            BaseEntity baseEntity = null;

            if (Input.GetMouseButtonPress(MouseButton.Left))
            {
                _treeviewNodeClicked = false;
                //if the node is null, we should remove all items from the list
                if (hitNode != null)
                {
                    if (!hitNode.Name.Contains("wirePlane"))
                    {
                        if (hitNode.Components.Count > 0)
                        {
                            if (!hitNode.Name.ToLower().Contains("gizmo"))
                            {
                                //baseEntity from component
                                baseEntity = hitNode.GetComponent <BaseEntity>();
                                if (baseEntity == null)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                //baseEntity from gizmo (parent/parent/baseentity)
                                var parent1 = hitNode.Parent;
                                if (parent1 != null)
                                {
                                    var parent2 = parent1.Parent;
                                    if (parent2 != null)
                                    {
                                        if (parent2.Components.Count > 0)
                                        {
                                            var parent2Gizmo = parent2.GetComponent <Gizmo>();
                                            if (parent2Gizmo != null)
                                            {
                                                baseEntity = parent2Gizmo.BaseEntity;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Debug.Print("CheckForSelection - Calling ClearSelectedObjectsAndGizmos because hitNode.Components.Count is zero...");
                            ClearSelectedObjectsAndGizmos();
                            return;
                        }

                        if (baseEntity != null)
                        {
                            if (!baseEntity.HasGizmo)
                            {
                                baseEntity.CreateGizmo();
                            }
                            if (!baseEntity.IsSelected)
                            {
                                //if the user has pressed Shift button, then we need to add to the selected object list, otherwise
                                //we should clear the list first
                                if (!Input.GetKeyDown(Key.Shift))
                                {
                                    multipleSelect = false;
                                    DisplayScene.SelectedSceneObjects.ResetGizmosAndMaterials();
                                    DisplayScene.SelectedSceneObjects.Clear();
                                    SendResetPropertiesWindowMessage();
                                }

                                if (!hitNode.Name.Contains("wirePlane"))
                                {
                                    SelectedObject selectedObject = new SelectedObject
                                    {
                                        SelectedNode = hitNode,
                                        Drawable     = hitDrawable
                                    };

                                    if (baseEntity != null)
                                    {
                                        baseEntity.SetAsSelected();
                                        //send a message to show the object properties
                                        PulsarMessage message = new PulsarMessage()
                                        {
                                            Type       = PulsarMessage.MessageType.ShowObjectProperties,
                                            Iterations = 1
                                        };
                                        message.Properties.Add("sceneObjectType", GetSceneObjectType(hitNode));
                                        message.Properties.Add("sceneObject", hitNode);
                                        message.Properties.Add("externallySet", false);
                                        if (message != null)
                                        {
                                            MessageQueue.PushMessage(message);
                                        }
                                    }

                                    SceneNodeClicked?.Invoke(SceneObjectType.Node, hitNode, multipleSelect);

                                    DisplayScene.SelectedSceneObjects.AddSelectedObject(selectedObject);
                                }
                            }
                        }
                        else
                        {
                            Debug.Print("CheckForSelection - baseEntity was NULL!");
                        }
                    }
                    else
                    {
                        Debug.Print("CheckForSelection - Calling ClearSelectedObjectsAndGizmos because hitNode was the wirePlane...");
                        ClearSelectedObjectsAndGizmos();
                    }
                }
                else
                {
                    Debug.Print("CheckForSelection - Calling ClearSelectedObjectsAndGizmos because hitNode was null...");
                    ClearSelectedObjectsAndGizmos();
                }
            }
        }