From 4ad41f1c7066ae4278070b5672d8844c07e215b1 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 3 Aug 2017 11:59:27 -0700 Subject: [PATCH] Better selection rendering --- PartPreviewWindow/View3D/MeshViewerWidget.cs | 69 +++++++++++++++++--- PartPreviewWindow/View3D/View3DWidget.cs | 15 ----- Submodules/agg-sharp | 2 +- 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 7023a8742..1ee6456d8 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -613,7 +613,6 @@ namespace MatterHackers.MeshVisualizer public bool IsActive { get; set; } = true; - RGBA_Bytes lastDrawColor; private void DrawObject(IObject3D object3D, Matrix4X4 transform, bool parentSelected) { foreach(MeshRenderData renderData in object3D.VisibleMeshes(transform)) @@ -637,16 +636,66 @@ namespace MatterHackers.MeshVisualizer drawColor = RGBA_Floats.FromHSL(Math.Max(renderData.MaterialIndex, 0) / 4.0, .99, .49).GetAsRGBA_Bytes(); } - if (drawColor.Alpha0To1 == 0) - { - drawColor = lastDrawColor; - } - else - { - lastDrawColor = drawColor; - } - GLHelper.Render(renderData.Mesh, drawColor, renderData.Matrix, RenderType); + + if(isSelected) + { + var screenPosition = new Vector3[3]; + var frustum = World.GetClippingFrustum(); + GLHelper.PrepareFor3DLineRender(true); + + if (renderData.Mesh.Vertices.Count < 1000) + { + foreach (MeshEdge meshEdge in renderData.Mesh.MeshEdges) + { + if (meshEdge.GetNumFacesSharingEdge() == 2) + { + FaceEdge firstFaceEdge = meshEdge.firstFaceEdge; + FaceEdge nextFaceEdge = meshEdge.firstFaceEdge.radialNextFaceEdge; + // find out if one face is facing the camera and one is facing away + var vertexPosition = World.GetScreenSpace(Vector3.Transform(firstFaceEdge.FirstVertex.Position, renderData.Matrix)); + var firstNormal = World.GetScreenSpace(Vector3.Transform(firstFaceEdge.FirstVertex.Position + firstFaceEdge.ContainingFace.normal, renderData.Matrix)); + var nextNormal = World.GetScreenSpace(Vector3.Transform(firstFaceEdge.FirstVertex.Position + nextFaceEdge.ContainingFace.normal, renderData.Matrix)); + + var firstTowards = (firstNormal - vertexPosition).z < 0; + var nextTowards = (nextNormal - vertexPosition).z < 0; + + if (firstTowards != nextTowards) + { + var transformed1 = Vector3.Transform(meshEdge.VertexOnEnd[0].Position, renderData.Matrix); + var transformed2 = Vector3.Transform(meshEdge.VertexOnEnd[1].Position, renderData.Matrix); + + for (int i = 0; i < 3; i++) + { + GLHelper.Render3DLineNoPrep(frustum, World, transformed1, transformed2, ActiveTheme.Instance.PrimaryAccentColor, 15); + } + } + } + } + } + else // just render the bounding box + { + RenderAABB(frustum, renderData.Mesh.GetAxisAlignedBoundingBox(), renderData.Matrix, ActiveTheme.Instance.PrimaryAccentColor); + } + + // turn lighting back on after rendering selection outlines + GL.Enable(EnableCap.Lighting); + } + } + } + + void RenderAABB(Frustum frustum, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, RGBA_Bytes color) + { + for (int i = 0; i < 4; i++) + { + Vector3 bottomStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix); + Vector3 bottomEndPosition = Vector3.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix); + Vector3 topStartPosition = Vector3.Transform(bounds.GetTopCorner(i), matrix); + Vector3 topEndPosition = Vector3.Transform(bounds.GetTopCorner((i + 1) % 4), matrix); + + GLHelper.Render3DLineNoPrep(frustum, World, bottomStartPosition, bottomEndPosition, ActiveTheme.Instance.PrimaryAccentColor, 15); + GLHelper.Render3DLineNoPrep(frustum, World, topStartPosition, topEndPosition, ActiveTheme.Instance.PrimaryAccentColor, 15); + GLHelper.Render3DLineNoPrep(frustum, World, topStartPosition, bottomStartPosition, ActiveTheme.Instance.PrimaryAccentColor, 15); } } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index e9a4605c3..1e8a217de 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -69,7 +69,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public UndoBuffer UndoBuffer { get; } = new UndoBuffer(); public readonly int EditButtonHeight = 44; - private bool editorThatRequestedSave = false; private ExportPrintItemWindow exportingWindow = null; private ObservableCollection extruderButtons = new ObservableCollection(); private bool hasDrawn = false; @@ -664,18 +663,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow AxisAlignedBoundingBox boundsAdd = meshToAdd.GetAxisAlignedBoundingBox(); AxisAlignedBoundingBox boundsResult = aabbOpperation(boundsA, boundsB); - - if (!boundsAdd.Equals(boundsResult, .0001)) - { - int a = 0; - } - } - - int nonManifoldEdges = meshToAdd.GetNonManifoldEdges().Count; - if (nonManifoldEdges > 0) - { - // shoud be manifold - int a = 0; } return meshToAdd; @@ -1979,8 +1966,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private async Task SaveChanges() { - editorThatRequestedSave = true; - if (Scene.HasChildren) { processingProgressControl.ProcessType = "Saving".Localize() + ":"; diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index a1356399d..1e1f3e593 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit a1356399d53052875b234494dd0906d063d5d6ef +Subproject commit 1e1f3e59327106eb3f5dc3fb993306fbda00ece3