コード例 #1
0
ファイル: ExplorerView.xaml.cs プロジェクト: ext0/Flex
        private void ActiveInstancesSelectedChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            _propertyGrid.SelectedObject = e.NewValue;
            PositionedInstance positioned = e.NewValue as PositionedInstance;

            if (positioned != null && !(positioned is Camera))
            {
                Engine.QueueForRenderDispatcher(() =>
                {
                    Engine.MouseHandler.SetActiveSelectedNode(positioned.SceneNode);
                });
            }

            /*
             * foreach (PropertyItem prop in _propertyGrid)
             * {
             *  if (prop.IsExpandable)
             *  {
             *      prop.IsExpanded = true;
             *      prop.IsExpandable = false;
             *  }
             * }
             */
            /*
             * (_propertyGrid.SelectedObject as Instance).OnChanged += Tracker_Changed;
             */
        }
コード例 #2
0
        private void _panel_MouseClick(object sender, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);

            Engine.QueueForRenderDispatcher(() =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    Ray ray;
                    RaySceneQueryResult.Enumerator itr = GetRaySceneQuery(point.X, point.Y, out ray);

                    if (itr != null)
                    {
                        while (itr.MoveNext())
                        {
                            RaySceneQueryResultEntry entry = itr.Current;
                            SceneNode parentNode           = entry.movable.ParentSceneNode;

                            PositionedInstance instance = Engine.SceneNodeStore.GetInstance(parentNode);

                            if (instance != null)
                            {
                                Engine.RunOnUIThread(() =>
                                {
                                    IoC.Get <IExplorer>().SelectInstance(instance);
                                });

                                ActiveScene.SelectedInstance = instance;

                                SetActiveSelectedNode(parentNode);
                                return;
                            }
                        }
                        SceneNode node;
                        if (ExistsSelectedNode(out node))
                        {
                            PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node);
                            if (oldInstance != null)
                            {
                                SizedInstance oldSized = oldInstance as SizedInstance;
                                if (oldSized != null)
                                {
                                    oldSized.IsSelected           = false;
                                    oldSized.IsBoundingBoxEnabled = false;
                                }
                            }

                            ActiveScene.SelectedInstance = null;

                            oldInstance.RemoveGizmoVisual();

                            ClearSelectedNode();
                        }
                    }
                }
            });
        }
コード例 #3
0
ファイル: MogreRenderer.cs プロジェクト: ext0/Flex
        public SceneNode CreateSceneNode(PositionedInstance instance)
        {
            SceneNode node = _scene.CreateSceneNode();

            node.AttachObject(instance.MovableObject);
            _scene.RootSceneNode.AddChild(node);
            Engine.SceneNodeStore.AddSceneNode(node, instance);
            return(node);
        }
コード例 #4
0
        public void SetActiveSelectedNode(SceneNode newNode)
        {
            PositionedInstance instance = Engine.SceneNodeStore.GetInstance(newNode);

            if (instance == null)
            {
                return;
            }
            SceneNode node;

            if (ExistsSelectedNode(out node))
            {
                if (!newNode.Equals(node))
                {
                    PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node);
                    if (oldInstance != null)
                    {
                        SizedInstance oldSized = oldInstance as SizedInstance;
                        if (oldSized != null)
                        {
                            oldSized.IsSelected           = false;
                            oldSized.IsBoundingBoxEnabled = false;
                        }
                        oldInstance.RemoveGizmoVisual();
                        ClearSelectedNode();
                    }
                    SizedInstance sized = instance as SizedInstance;
                    if (sized != null)
                    {
                        sized.IsBoundingBoxEnabled = true;
                        sized.IsSelected           = true;
                    }
                    SetSelectedNode(newNode);

                    instance.SetGizmoVisual(new GizmoVisual(_gizmoNode));
                }
            }
            else
            {
                SizedInstance sized = instance as SizedInstance;
                if (sized != null)
                {
                    sized.IsBoundingBoxEnabled = true;
                    sized.IsSelected           = true;
                }

                SetSelectedNode(newNode);

                instance.SetGizmoVisual(new GizmoVisual(_gizmoNode));
            }
        }
コード例 #5
0
ファイル: SceneViewModel.cs プロジェクト: ext0/Flex
        Task ICommandHandler <RotatePartYCommandDefinition> .Run(Command command)
        {
            Instance selected = ActiveScene.SelectedInstance;

            if (selected != null)
            {
                PositionedInstance positioned = selected as PositionedInstance;
                if (positioned != null)
                {
                    positioned.rotation.y = (positioned.rotation.y + 90) % 360;
                }
            }
            return(TaskUtility.Completed);
        }
コード例 #6
0
ファイル: Engine.cs プロジェクト: ext0/Flex
 public static void Destroy(PositionedInstance instance)
 {
     if (MouseHandler.IsSelectedNode(instance.SceneNode))
     {
         MouseHandler.ClearSelectedNode();
     }
     if (MouseHandler.IsAlreadyHovered(instance.SceneNode))
     {
         MouseHandler.ClearHovered();
     }
     SceneNodeStore.RemoveSceneNode(instance.SceneNode);
     instance.SceneNode.RemoveAllChildren();
     _renderer.Scene.DestroySceneNode(instance.SceneNode);
 }
コード例 #7
0
        public void AddToHoverNode(SceneNode newNode)
        {
            if (!IsAlreadyHovered(newNode))
            {
                if (!IsSelectedNode(newNode))
                {
                    PositionedInstance instance = Engine.SceneNodeStore.GetInstance(newNode);
                    if (instance != null)
                    {
                        SizedInstance sized = instance as SizedInstance;
                        if (sized != null)
                        {
                            sized.IsBoundingBoxEnabled = true;
                        }

                        MarkAsHovered(newNode);
                    }
                }
            }
        }
コード例 #8
0
        private void ActiveScene_GizmoChanged(object sender, EventArgs e)
        {
            SceneNode node;

            if (ExistsSelectedNode(out node))
            {
                PositionedInstance instance = Engine.SceneNodeStore.GetInstance(node);
                if (instance != null)
                {
                    instance.RemoveGizmoVisual();
                }
            }

            switch (ActiveScene.ActiveGizmoType)
            {
            case Misc.Runtime.GizmoType.POINTER:
                _gizmoNode = _pointerNode;
                break;

            case Misc.Runtime.GizmoType.TRANSLATE:
                _gizmoNode = _translateNode;
                break;

            case Misc.Runtime.GizmoType.SCALE:
                _gizmoNode = _scaleNode;
                break;

            case Misc.Runtime.GizmoType.ROTATE:
                _gizmoNode = _rotateNode;
                break;
            }

            if (ExistsSelectedNode(out node))
            {
                PositionedInstance instance = Engine.SceneNodeStore.GetInstance(node);
                if (instance != null)
                {
                    instance.SetGizmoVisual(new GizmoVisual(_gizmoNode));
                }
            }
        }
コード例 #9
0
 public void AddSceneNode(SceneNode node, PositionedInstance instance)
 {
     _instances.Add(node, instance);
 }
コード例 #10
0
        private void _panel_MouseMove(object sender, MouseEventArgs e)
        {
            if (_oldMousePosition == null)
            {
                _oldMousePosition = new Point(e.X, e.Y);
                return;
            }
            Point point = new Point(e.X, e.Y);

            Engine.QueueForRenderDispatcher(() =>
            {
                double deltaDirectionX = point.X - _oldMousePosition.X;
                double deltaDirectionY = point.Y - _oldMousePosition.Y;

                if (e.Button.HasFlag(MouseButtons.Right))
                {
                    ActiveScene.Context.ActiveWorld.Camera.pitch(new Radian((float)-deltaDirectionY / 200f).ValueDegrees);
                    ActiveScene.Context.ActiveWorld.Camera.yaw(new Radian((float)-deltaDirectionX / 200f).ValueDegrees);
                }

                IEnumerable <SceneNode> selected = GetSelectedNode();
                SceneNode selectedNode           = null;
                if (selected != null)
                {
                    selectedNode = selected.FirstOrDefault();
                }

                if (_translateDragging != TransformDragging.NONE && ActiveScene.ActiveGizmoType == Misc.Runtime.GizmoType.TRANSLATE)
                {
                    if (selectedNode != null)
                    {
                        Plane plane = new Plane();
                        if (_translateDragging == TransformDragging.X)
                        {
                            Vector3 normal = Vector3.UNIT_Y;
                            plane          = new Plane(normal, selectedNode.Position);
                        }
                        else if (_translateDragging == TransformDragging.Y)
                        {
                            Vector3 normal = (Engine.Renderer.Camera.Position - selectedNode.Position).NormalisedCopy;
                            normal.y       = 0;
                            plane          = new Plane(normal, selectedNode.Position);
                        }
                        else if (_translateDragging == TransformDragging.Z)
                        {
                            Vector3 normal = Vector3.UNIT_Y;
                            plane          = new Plane(normal, selectedNode.Position);
                        }

                        Vector3 translateVector;
                        if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out translateVector, selectedNode))
                        {
                            PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode);

                            SizedInstance sized = instance as SizedInstance;

                            if (sized != null)
                            {
                                translateVector -= _translateDragDifference;

                                if (_translateDragging == TransformDragging.X)
                                {
                                    instance.position.x = (float)System.Math.Round(translateVector.x - (sized.size.x / 2));
                                    //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance);
                                }
                                else if (_translateDragging == TransformDragging.Y)
                                {
                                    instance.position.y = (float)System.Math.Round(translateVector.y - (sized.size.y / 2));
                                    //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance);
                                }
                                else if (_translateDragging == TransformDragging.Z)
                                {
                                    instance.position.z = (float)System.Math.Round(translateVector.z - (sized.size.z / 2));
                                    //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance);
                                }
                            }
                        }
                    }
                }
                else if (_scaleDragging != DirectionalTransformDragging.NONE && ActiveScene.ActiveGizmoType == Misc.Runtime.GizmoType.SCALE)
                {
                    if (selectedNode != null)
                    {
                        Plane plane = new Plane();
                        if (_scaleDragging == DirectionalTransformDragging.XA || _scaleDragging == DirectionalTransformDragging.XB)
                        {
                            Vector3 normal = Vector3.UNIT_Y;
                            plane          = new Plane(normal, selectedNode.Position);
                        }
                        else if (_scaleDragging == DirectionalTransformDragging.YA || _scaleDragging == DirectionalTransformDragging.YB)
                        {
                            Vector3 normal = (Engine.Renderer.Camera.Position - selectedNode.Position).NormalisedCopy;
                            normal.y       = 0;
                            plane          = new Plane(normal, selectedNode.Position);
                        }
                        else if (_scaleDragging == DirectionalTransformDragging.ZA || _scaleDragging == DirectionalTransformDragging.ZB)
                        {
                            Vector3 normal = Vector3.UNIT_Y;
                            plane          = new Plane(normal, selectedNode.Position);
                        }

                        Vector3 scaleVector;
                        if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out scaleVector, selectedNode))
                        {
                            PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode);

                            SizedInstance sized = instance as SizedInstance;

                            if (sized != null)
                            {
                                int magicOffsetA = 2;

                                if (_scaleDragging == DirectionalTransformDragging.XA)
                                {
                                    sized.size.x = System.Math.Max(1, (float)System.Math.Round(scaleVector.x - (sized.position.x) - magicOffsetA));
                                }
                                else if (_scaleDragging == DirectionalTransformDragging.YA)
                                {
                                    sized.size.y = System.Math.Max(1, (float)System.Math.Round(scaleVector.y - (sized.position.y) - magicOffsetA));
                                }
                                else if (_scaleDragging == DirectionalTransformDragging.ZA)
                                {
                                    sized.size.z = System.Math.Max(1, (float)System.Math.Round(scaleVector.z - (sized.position.z) - magicOffsetA));
                                }
                                else if (_scaleDragging == DirectionalTransformDragging.XB)
                                {
                                    //TODO: fix
                                    float newX  = scaleVector.x + (sized.size.x / 2) + _scaleDragDifference.x; //wtf?
                                    float delta = (sized.position.x - newX);

                                    float rounded = (float)System.Math.Round(delta);

                                    sized.position.x -= rounded;
                                    sized.size.x     += rounded;
                                }
                                else if (_scaleDragging == DirectionalTransformDragging.YB)
                                {
                                }
                                else if (_scaleDragging == DirectionalTransformDragging.ZB)
                                {
                                }
                            }
                        }
                    }
                }

                Cursor cursor = null;
                if (_translateFreeDragging && _scaleDragging == DirectionalTransformDragging.NONE && _translateDragging == TransformDragging.NONE)
                {
                    if (selectedNode != null)
                    {
                        Plane plane = new Plane(Vector3.UNIT_Y, Engine.Renderer.Camera.Position.y - 16);

                        Vector3 vector;
                        if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out vector, selectedNode))
                        {
                            PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode);

                            SizedInstance sized = instance as SizedInstance;

                            if (sized != null)
                            {
                                instance.position.x = (float)System.Math.Round(vector.x - (sized.size.x / 2));
                                instance.position.y = (float)System.Math.Round(vector.y - (sized.size.y / 2));
                                instance.position.z = (float)System.Math.Round(vector.z - (sized.size.z / 2));
                            }
                        }

                        cursor = Cursors.NoMove2D;
                    }
                    else
                    {
                        _translateFreeDragging = false;
                    }
                }

                Ray ray;
                RaySceneQueryResult.Enumerator itr = GetRaySceneQuery(point.X, point.Y, out ray);

                if (itr != null)
                {
                    bool nothing = true;
                    while (itr.MoveNext())
                    {
                        RaySceneQueryResultEntry entry = itr.Current;

                        if (entry.movable.QueryFlags != (uint)QueryFlags.IGNORE_ALL)
                        {
                            nothing = false;
                        }

                        if (entry.movable.QueryFlags == (uint)QueryFlags.INSTANCE_ENTITY)
                        {
                            SceneNode parentNode = entry.movable.ParentSceneNode;
                            if (selectedNode != null && selectedNode.Equals(parentNode) && e.Button.HasFlag(MouseButtons.Left) && _translateDragging == TransformDragging.NONE)
                            {
                                if (System.Math.Abs(deltaDirectionX) >= TRANSLATE_DRAG_THRESHOLD || System.Math.Abs(deltaDirectionY) >= TRANSLATE_DRAG_THRESHOLD)
                                {
                                    _translateFreeDragging = true;
                                }
                            }
                            if (!IsAlreadyHovered(parentNode))
                            {
                                IEnumerable <SceneNode> hovered = GetHoveredNodes();
                                if (hovered != null)
                                {
                                    foreach (SceneNode node in hovered)
                                    {
                                        if (!IsSelectedNode(node))
                                        {
                                            PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node);
                                            if (oldInstance != null)
                                            {
                                                SizedInstance oldSized = oldInstance as SizedInstance;
                                                if (oldSized != null)
                                                {
                                                    oldSized.IsBoundingBoxEnabled = false;
                                                }
                                            }
                                        }
                                    }
                                    ClearHovered();
                                }
                                AddToHoverNode(parentNode);
                            }
                            break;
                        }
                    }
                    if (nothing)
                    {
                        if (cursor == null)
                        {
                            cursor = Cursors.Default;
                        }
                        IEnumerable <SceneNode> hovered = GetHoveredNodes();
                        if (hovered != null)
                        {
                            foreach (SceneNode node in hovered)
                            {
                                if (!IsSelectedNode(node))
                                {
                                    PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node);
                                    if (oldInstance != null)
                                    {
                                        SizedInstance oldSized = oldInstance as SizedInstance;
                                        if (oldSized != null)
                                        {
                                            oldSized.IsBoundingBoxEnabled = false;
                                        }
                                    }
                                }
                            }
                            ClearHovered();
                        }
                    }
                    else
                    {
                        if (cursor == null)
                        {
                            cursor = Cursors.Hand;
                        }
                    }
                }
                if (cursor != null)
                {
                    System.Windows.Application.Current.Dispatcher.InvokeAsync(() => _panel.Cursor = cursor, DispatcherPriority.Background);
                }
                _oldMousePosition = point;
            });
        }