From e52d963278d3b9396bb5c4873e8565d8998e0ccf Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 2 Jun 2019 22:29:54 -0700 Subject: [PATCH] Extract WorldView extension methods --- .../RotateControls/RotateCornerControl.cs | 2 +- .../ScaleControls/ScaleCornerControl.cs | 6 +- .../ScaleControls/ScaleTopControl.cs | 2 +- .../DesignTools/Obsolete/CurveObject3D.cs | 1 + .../DesignTools/Operations/CurveObject3D_2.cs | 1 + .../Operations/FitToBoundsObject3D_2.cs | 1 + .../Operations/FitToCylinderObject3D.cs | 1 + .../DesignTools/Operations/ScaleObject3D.cs | 1 + .../DesignTools/Operations/TwistObject3D.cs | 1 + .../View3D/WorldViewExtensions.cs | 111 ------------------ 10 files changed, 11 insertions(+), 116 deletions(-) diff --git a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs index bbfba8db8..c2d4b24d6 100644 --- a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs @@ -651,7 +651,7 @@ namespace MatterHackers.Plugins.EditorTools Vector3 startPosition = Vector3Ex.Transform(unitPosition * innerRadius, rotationCenterTransform); Vector3 endPosition = Vector3Ex.Transform(unitPosition * outerRadius, rotationCenterTransform); - InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(theme.TextColor, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); + InteractionContext.World.Render3DLine(startPosition, endPosition, new Color(theme.TextColor, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); } } diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs index 899ae3139..f7a686e6b 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs @@ -192,18 +192,18 @@ namespace MatterHackers.Plugins.EditorTools Vector3 endPosition = GetCornerPosition(selectedItem, (quadrantIndex + 1) % 4); - Frustum clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World); + Frustum clippingFrustum = InteractionContext.World.GetClippingFrustum(); if (clippingFrustum.ClipLine(ref startPosition, ref endPosition)) { if (e.ZBuffered) { - InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, theme.TextColor); + InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, Color.Green); } else { // render on top of everything very lightly - InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(theme.TextColor, 20), false); + InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(Color.Green, 20), false); } } diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs index 32f94d47b..ccb3c1256 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs @@ -187,7 +187,7 @@ namespace MatterHackers.Plugins.EditorTools Matrix4X4 scaleTransform = Matrix4X4.CreateScale((topPosition - bottomPosition).Length, distBetweenPixelsWorldSpace, distBetweenPixelsWorldSpace); Matrix4X4 lineTransform = scaleTransform * rotateTransform * Matrix4X4.CreateTranslation(centerPosition); - Frustum clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World); + Frustum clippingFrustum = InteractionContext.World.GetClippingFrustum(); if (e.ZBuffered) { diff --git a/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs b/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs index 357ffa152..e9b89eb3a 100644 --- a/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs @@ -48,6 +48,7 @@ using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PartPreviewWindow.View3D; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; +using MatterHackers.RenderOpenGl; using MatterHackers.RenderOpenGl.OpenGl; using MatterHackers.VectorMath; diff --git a/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs b/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs index af6dd6022..110dea770 100644 --- a/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs @@ -42,6 +42,7 @@ using MatterHackers.MatterControl.DesignTools.Operations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; +using MatterHackers.RenderOpenGl; using MatterHackers.RenderOpenGl.OpenGl; using MatterHackers.VectorMath; using Newtonsoft.Json; diff --git a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs index e23e2df25..8438087fb 100644 --- a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs @@ -34,6 +34,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; +using MatterHackers.RenderOpenGl; using MatterHackers.VectorMath; using Newtonsoft.Json; using System; diff --git a/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs b/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs index 509e691fe..3c4e9a58a 100644 --- a/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs @@ -44,6 +44,7 @@ using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; using MatterHackers.PolygonMesh.Rendering; +using MatterHackers.RenderOpenGl; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools.Operations diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs index 14c59bac5..cf55c134c 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs @@ -33,6 +33,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MeshVisualizer; +using MatterHackers.RenderOpenGl; using MatterHackers.VectorMath; using Newtonsoft.Json; using System; diff --git a/MatterControlLib/DesignTools/Operations/TwistObject3D.cs b/MatterControlLib/DesignTools/Operations/TwistObject3D.cs index eea670e46..dace4585e 100644 --- a/MatterControlLib/DesignTools/Operations/TwistObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/TwistObject3D.cs @@ -42,6 +42,7 @@ using MatterHackers.MatterControl.DesignTools.Operations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; +using MatterHackers.RenderOpenGl; using MatterHackers.RenderOpenGl.OpenGl; using MatterHackers.VectorMath; using Newtonsoft.Json; diff --git a/MatterControlLib/PartPreviewWindow/View3D/WorldViewExtensions.cs b/MatterControlLib/PartPreviewWindow/View3D/WorldViewExtensions.cs index b8dd2233b..032a03f38 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/WorldViewExtensions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/WorldViewExtensions.cs @@ -38,117 +38,6 @@ namespace MatterHackers.MeshVisualizer { public static class WorldViewExtensions { - public static void RenderCylinderOutline(this WorldView world, Matrix4X4 worldMatrix, Vector3 center, double diameter, double height, int sides, Color color, double lineWidth = 1, double extendLineLength = 0) - { - world.RenderCylinderOutline(worldMatrix, center, diameter, height, sides, color, color, lineWidth, extendLineLength); - } - - public static void RenderCylinderOutline(this WorldView world, Matrix4X4 worldMatrix, Vector3 center, double diameter, double height, int sides, Color topBottomRingColor, Color sideLinesColor, double lineWidth = 1, double extendLineLength = 0, double phase = 0) - { - GLHelper.PrepareFor3DLineRender(true); - Frustum frustum = world.GetClippingFrustum(); - - for (int i = 0; i < sides; i++) - { - var startAngle = MathHelper.Tau * i / sides + phase; - var rotatedPoint = new Vector3(Math.Cos(startAngle), Math.Sin(startAngle), 0) * diameter / 2; - var sideTop = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, height / 2), worldMatrix); - var sideBottom = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, -height / 2), worldMatrix); - var endAngle = MathHelper.Tau * (i + 1) / sides + phase; - var rotated2Point = new Vector3(Math.Cos(endAngle), Math.Sin(endAngle), 0) * diameter / 2; - var topStart = sideTop; - var topEnd = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, height / 2), worldMatrix); - var bottomStart = sideBottom; - var bottomEnd = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, -height / 2), worldMatrix); - - if (extendLineLength > 0) - { - GLHelper.ExtendLineEnds(ref sideTop, ref sideBottom, extendLineLength); - } - - if (sideLinesColor != Color.Transparent) - { - world.Render3DLineNoPrep(frustum, sideTop, sideBottom, sideLinesColor, lineWidth); - } - - if (topBottomRingColor != Color.Transparent) - { - world.Render3DLineNoPrep(frustum, topStart, topEnd, topBottomRingColor, lineWidth); - world.Render3DLineNoPrep(frustum, bottomStart, bottomEnd, topBottomRingColor, lineWidth); - } - } - - // turn the lighting back on - GL.Enable(EnableCap.Lighting); - } - - public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double width, double extendLineLength = 0) - { - GLHelper.PrepareFor3DLineRender(true); - - Frustum frustum = world.GetClippingFrustum(); - for (int i = 0; i < 4; i++) - { - Vector3 sideStartPosition = Vector3Ex.Transform(bounds.GetBottomCorner(i), matrix); - Vector3 sideEndPosition = Vector3Ex.Transform(bounds.GetTopCorner(i), matrix); - - Vector3 bottomStartPosition = sideStartPosition; - Vector3 bottomEndPosition = Vector3Ex.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix); - - Vector3 topStartPosition = sideEndPosition; - Vector3 topEndPosition = Vector3Ex.Transform(bounds.GetTopCorner((i + 1) % 4), matrix); - - if (extendLineLength > 0) - { - GLHelper.ExtendLineEnds(ref sideStartPosition, ref sideEndPosition, extendLineLength); - GLHelper.ExtendLineEnds(ref topStartPosition, ref topEndPosition, extendLineLength); - GLHelper.ExtendLineEnds(ref bottomStartPosition, ref bottomEndPosition, extendLineLength); - } - - // draw each of the edge lines (4) and their touching top and bottom lines (2 each) - world.Render3DLineNoPrep(frustum, sideStartPosition, sideEndPosition, color, width); - world.Render3DLineNoPrep(frustum, topStartPosition, topEndPosition, color, width); - world.Render3DLineNoPrep(frustum, bottomStartPosition, bottomEndPosition, color, width); - } - - GL.Enable(EnableCap.Lighting); - } - - public static void RenderAxis(this WorldView world, Vector3 position, Matrix4X4 matrix, double size, double lineWidth) - { - GLHelper.PrepareFor3DLineRender(true); - - Frustum frustum = world.GetClippingFrustum(); - Vector3 length = Vector3.One * size; - for (int i = 0; i < 3; i++) - { - var min = position; - min[i] -= length[i]; - Vector3 start = Vector3Ex.Transform(min, matrix); - - var max = position; - max[i] += length[i]; - Vector3 end = Vector3Ex.Transform(max, matrix); - - var color = Agg.Color.Red; - switch (i) - { - case 1: - color = Agg.Color.Green; - break; - - case 2: - color = Agg.Color.Blue; - break; - } - - // draw each of the edge lines (4) and their touching top and bottom lines (2 each) - world.Render3DLineNoPrep(frustum, start, end, color, lineWidth); - } - - GL.Enable(EnableCap.Lighting); - } - public static void RenderDirectionAxis(this WorldView world, DirectionAxis axis, Matrix4X4 matrix, double size) { GLHelper.PrepareFor3DLineRender(true);