public void GrowSelection(FaceSelectionState faceSelectionState) { var selectedFaceIndecies = new List <ushort>(); var indexBuffer = faceSelectionState.RenderObject.Geometry.GetIndexBuffer(); foreach (var face in faceSelectionState.SelectedFaces) { selectedFaceIndecies.Add(indexBuffer[face]); selectedFaceIndecies.Add(indexBuffer[face + 1]); selectedFaceIndecies.Add(indexBuffer[face + 2]); } var meshService = new MeshSplitterService(); var newSelection = meshService.GrowSelection(faceSelectionState.RenderObject.Geometry, selectedFaceIndecies); var selectCmd = new FaceSelectionCommand(newSelection); _commandManager.ExecuteCommand(selectCmd); }
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); } }
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); } }