Exemple #1
0
        void SelectObjectsHirarchy(ISceneNode root, Ray ray, ref ISelectable output_selectedNode, ref float bestDistance)
        {
            if (root.IsVisible)
            {
                if (root is ISelectable selectableNode && selectableNode.IsSelectable)
                {
                    var distance = GeometryIntersection.IntersectObject(ray, selectableNode.Geometry, selectableNode.ModelMatrix);
                    if (distance != null)
                    {
                        if (distance < bestDistance)
                        {
                            bestDistance        = distance.Value;
                            output_selectedNode = selectableNode;
                        }
                    }
                }

                bool isUnselectableGroup = root is GroupNode groupNode && groupNode.IsLockable == true && groupNode.IsSelectable == false;
                if (!isUnselectableGroup)
                {
                    foreach (var child in root.Children)
                    {
                        SelectObjectsHirarchy(child, ray, ref output_selectedNode, ref bestDistance);
                    }
                }
            }
        }
        void SelectFromRectangle(Rectangle screenRect, bool isSelectionModification, bool removeSelection)
        {
            var unprojectedSelectionRect = _camera.UnprojectRectangle(screenRect);

            var currentState = _selectionManager.GetState();

            if (currentState.Mode == GeometrySelectionMode.Face && currentState is FaceSelectionState faceState)
            {
                if (GeometryIntersection.IntersectFaces(unprojectedSelectionRect, faceState.RenderObject.Geometry, faceState.RenderObject.ModelMatrix, out var faces))
                {
                    var faceSelectionCommand = new FaceSelectionCommand(faces, isSelectionModification, removeSelection);
                    _commandManager.ExecuteCommand(faceSelectionCommand);
                    return;
                }
            }
            else if (currentState.Mode == GeometrySelectionMode.Vertex && currentState is VertexSelectionState vertexState)
            {
                if (GeometryIntersection.IntersectVertices(unprojectedSelectionRect, vertexState.RenderObject.Geometry, vertexState.RenderObject.ModelMatrix, out var vertices))
                {
                    var vertexSelectionCommand = new VertexSelectionCommand(vertices, isSelectionModification, removeSelection);
                    _commandManager.ExecuteCommand(vertexSelectionCommand);
                    return;
                }
            }

            var selectedObjects = _sceneManger.SelectObjects(unprojectedSelectionRect);

            if (selectedObjects.Count() == 0 && isSelectionModification == false)
            {
                // Only clear selection if we are not in geometry mode and the selection count is not empty
                if (currentState.Mode != GeometrySelectionMode.Object || currentState.SelectionCount() != 0)
                {
                    var selectionCommand = new ObjectSelectionCommand(new List <ISelectable>(), false, false);
                    _commandManager.ExecuteCommand(selectionCommand);
                }
            }
            else if (selectedObjects != null)
            {
                var selectionCommand = new ObjectSelectionCommand(selectedObjects, isSelectionModification, removeSelection);
                _commandManager.ExecuteCommand(selectionCommand);
            }
        }
Exemple #3
0
        void SelectObjectsHirarchy(ISceneNode root, BoundingFrustum frustrum, List <ISelectable> output_selectedNodes)
        {
            if (root.IsVisible)
            {
                if (root is ISelectable selectableNode && selectableNode.IsSelectable)
                {
                    if (GeometryIntersection.IntersectObject(frustrum, selectableNode.Geometry, selectableNode.ModelMatrix))
                    {
                        output_selectedNodes.Add(selectableNode);
                    }
                }

                bool isUnselectableGroup = root is GroupNode groupNode && groupNode.IsLockable == true && groupNode.IsSelectable == false;
                if (!isUnselectableGroup)
                {
                    foreach (var child in root.Children)
                    {
                        SelectObjectsHirarchy(child, frustrum, output_selectedNodes);
                    }
                }
            }
        }
        void SelectFromPoint(Vector2 mousePosition, bool isSelectionModification, bool removeSelection)
        {
            var ray          = _camera.CreateCameraRay(mousePosition);
            var currentState = _selectionManager.GetState();

            if (currentState.Mode == GeometrySelectionMode.Face)
            {
                if (currentState.Mode == GeometrySelectionMode.Face)
                {
                    var faceState = currentState as FaceSelectionState;

                    if (GeometryIntersection.IntersectFace(ray, faceState.RenderObject.Geometry, faceState.RenderObject.ModelMatrix, out var selectedFace) != null)
                    {
                        FaceSelectionCommand faceSelectionCommand = new FaceSelectionCommand(selectedFace.Value, isSelectionModification, removeSelection);
                        _commandManager.ExecuteCommand(faceSelectionCommand);
                        return;
                    }
                }
            }

            // Pick object
            var selectedObject = _sceneManger.SelectObject(ray);

            if (selectedObject == null && isSelectionModification == false)
            {
                // Only clear selection if we are not in geometry mode and the selection count is not empty
                if (currentState.Mode != GeometrySelectionMode.Object || currentState.SelectionCount() != 0)
                {
                    var selectionCommand = new ObjectSelectionCommand(new List <ISelectable>(), false, false);
                    _commandManager.ExecuteCommand(selectionCommand);
                }
            }
            else if (selectedObject != null)
            {
                var selectionCommand = new ObjectSelectionCommand(selectedObject, isSelectionModification, removeSelection);
                _commandManager.ExecuteCommand(selectionCommand);
            }
        }