fixed snapping indicators
fixing warnings fixing scaling issues
This commit is contained in:
parent
a35347df4a
commit
b1c79e88c6
8 changed files with 64 additions and 68 deletions
|
|
@ -554,7 +554,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
mouseAngle = mouseDownInfo.AngleOfHit;
|
||||
}
|
||||
|
||||
var graphics2DOpenGL = new Graphics2DOpenGL();
|
||||
var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);
|
||||
|
||||
if (mouseDownInfo != null || MouseIsOver)
|
||||
{
|
||||
|
|
@ -600,7 +600,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo)
|
||||
{
|
||||
var graphics2DOpenGL = new Graphics2DOpenGL();
|
||||
var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);
|
||||
|
||||
double snappingRadians = MathHelper.Tau / numSnapPoints;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,25 +48,25 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
public IObject3D ActiveSelectedItem { get; set; }
|
||||
|
||||
protected PlaneShape hitPlane;
|
||||
protected Vector3 initialHitPosition;
|
||||
protected Mesh minXminYMesh;
|
||||
protected AxisAlignedBoundingBox mouseDownSelectedBounds;
|
||||
protected Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
||||
protected Matrix4X4 transformAppliedByThis = Matrix4X4.Identity;
|
||||
private PlaneShape hitPlane;
|
||||
private Vector3 initialHitPosition;
|
||||
private readonly Mesh minXminYMesh;
|
||||
private AxisAlignedBoundingBox mouseDownSelectedBounds;
|
||||
private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
||||
private Matrix4X4 transformAppliedByThis = Matrix4X4.Identity;
|
||||
|
||||
private double DistToStart => 10 * GuiWidget.DeviceScale;
|
||||
|
||||
private double LineLength => 35 * GuiWidget.DeviceScale;
|
||||
|
||||
private List<Vector2> lines = new List<Vector2>();
|
||||
private readonly List<Vector2> lines = new List<Vector2>();
|
||||
private Vector3 originalPointToMove;
|
||||
private int quadrantIndex;
|
||||
private double selectCubeSize = 7 * GuiWidget.DeviceScale;
|
||||
private ThemeConfig theme;
|
||||
private InlineEditControl xValueDisplayInfo;
|
||||
private InlineEditControl yValueDisplayInfo;
|
||||
private bool HadClickOnControl;
|
||||
private readonly int quadrantIndex;
|
||||
private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale;
|
||||
private readonly ThemeConfig theme;
|
||||
private readonly InlineEditControl xValueDisplayInfo;
|
||||
private readonly InlineEditControl yValueDisplayInfo;
|
||||
private bool hadClickOnControl;
|
||||
|
||||
public ScaleCornerControl(IObject3DControlContext context, int cornerIndex)
|
||||
: base(context)
|
||||
|
|
@ -85,7 +85,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
if (!xValueDisplayInfo.Visible)
|
||||
{
|
||||
HadClickOnControl = false;
|
||||
hadClickOnControl = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
if (!yValueDisplayInfo.Visible)
|
||||
{
|
||||
HadClickOnControl = false;
|
||||
hadClickOnControl = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
&& mouseEvent3D.info != null
|
||||
&& selectedItem != null)
|
||||
{
|
||||
HadClickOnControl = true;
|
||||
hadClickOnControl = true;
|
||||
|
||||
yValueDisplayInfo.Visible = true;
|
||||
xValueDisplayInfo.Visible = true;
|
||||
|
|
@ -260,7 +260,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
xValueDisplayInfo.Visible = true;
|
||||
yValueDisplayInfo.Visible = true;
|
||||
}
|
||||
else if (!HadClickOnControl
|
||||
else if (!hadClickOnControl
|
||||
|| (selectedItem != null && selectedItem.Matrix != transformAppliedByThis))
|
||||
{
|
||||
xValueDisplayInfo.Visible = false;
|
||||
|
|
@ -335,7 +335,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
if (HadClickOnControl)
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
Object3DControlContext.Scene.AddTransformSnapshot(transformOnMouseDown);
|
||||
}
|
||||
|
|
@ -470,7 +470,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
|
||||
// if we clicked on the control
|
||||
if (HadClickOnControl)
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,8 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl;
|
||||
|
|
@ -47,22 +45,22 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
public class ScaleTopControl : Object3DControl
|
||||
{
|
||||
public IObject3D ActiveSelectedItem;
|
||||
protected PlaneShape hitPlane;
|
||||
protected Vector3 initialHitPosition;
|
||||
protected Mesh topScaleMesh;
|
||||
protected AxisAlignedBoundingBox mouseDownSelectedBounds;
|
||||
protected Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
||||
private IObject3D activeSelectedItem;
|
||||
private PlaneShape hitPlane;
|
||||
private Vector3 initialHitPosition;
|
||||
private readonly Mesh topScaleMesh;
|
||||
private AxisAlignedBoundingBox mouseDownSelectedBounds;
|
||||
private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
||||
|
||||
private double DistToStart => 5 * GuiWidget.DeviceScale;
|
||||
|
||||
private double LineLength => 55 * GuiWidget.DeviceScale;
|
||||
|
||||
private List<Vector2> lines = new List<Vector2>();
|
||||
private readonly List<Vector2> lines = new List<Vector2>();
|
||||
private Vector3 originalPointToMove;
|
||||
private double arrowSize = 7 * GuiWidget.DeviceScale;
|
||||
private ThemeConfig theme;
|
||||
private InlineEditControl zValueDisplayInfo;
|
||||
private readonly double arrowSize = 7 * GuiWidget.DeviceScale;
|
||||
private readonly ThemeConfig theme;
|
||||
private readonly InlineEditControl zValueDisplayInfo;
|
||||
private bool hadClickOnControl;
|
||||
|
||||
public ScaleTopControl(IObject3DControlContext context)
|
||||
|
|
@ -75,7 +73,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
ForceHide = () =>
|
||||
{
|
||||
// if the selection changes
|
||||
if (RootSelection != ActiveSelectedItem)
|
||||
if (RootSelection != activeSelectedItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -108,24 +106,24 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
zValueDisplayInfo.EditComplete += (s, e) =>
|
||||
{
|
||||
var selectedItem = ActiveSelectedItem;
|
||||
var selectedItem = activeSelectedItem;
|
||||
|
||||
Matrix4X4 startingTransform = selectedItem.Matrix;
|
||||
var originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
||||
Vector3 topPosition = GetTopPosition(selectedItem);
|
||||
Vector3 lockedBottom = new Vector3(topPosition.X, topPosition.Y, originalSelectedBounds.MinXYZ.Z);
|
||||
var lockedBottom = new Vector3(topPosition.X, topPosition.Y, originalSelectedBounds.MinXYZ.Z);
|
||||
|
||||
Vector3 newSize = Vector3.Zero;
|
||||
newSize.Z = zValueDisplayInfo.Value;
|
||||
Vector3 scaleAmount = ScaleCornerControl.GetScalingConsideringShiftKey(originalSelectedBounds, mouseDownSelectedBounds, newSize, Object3DControlContext.GuiSurface.ModifierKeys);
|
||||
|
||||
Matrix4X4 scale = Matrix4X4.CreateScale(scaleAmount);
|
||||
var scale = Matrix4X4.CreateScale(scaleAmount);
|
||||
|
||||
selectedItem.Matrix = selectedItem.ApplyAtBoundsCenter(scale);
|
||||
|
||||
// and keep the locked edge in place
|
||||
AxisAlignedBoundingBox scaledSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
||||
Vector3 newLockedBottom = new Vector3(topPosition.X, topPosition.Y, scaledSelectedBounds.MinXYZ.Z);
|
||||
var newLockedBottom = new Vector3(topPosition.X, topPosition.Y, scaledSelectedBounds.MinXYZ.Z);
|
||||
|
||||
selectedItem.Matrix *= Matrix4X4.CreateTranslation(lockedBottom - newLockedBottom);
|
||||
|
||||
|
|
@ -181,13 +179,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
bottomPosition.Z = originalSelectedBounds.MinXYZ.Z;
|
||||
|
||||
// render with z-buffer full black
|
||||
double distBetweenPixelsWorldSpace = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(topPosition);
|
||||
Vector3 delta = topPosition - bottomPosition;
|
||||
Vector3 centerPosition = (topPosition + bottomPosition) / 2;
|
||||
Matrix4X4 rotateTransform = Matrix4X4.CreateRotation(new Quaternion(delta, Vector3.UnitX));
|
||||
Matrix4X4 scaleTransform = Matrix4X4.CreateScale((topPosition - bottomPosition).Length, distBetweenPixelsWorldSpace, distBetweenPixelsWorldSpace);
|
||||
Matrix4X4 lineTransform = scaleTransform * rotateTransform * Matrix4X4.CreateTranslation(centerPosition);
|
||||
|
||||
Frustum clippingFrustum = Object3DControlContext.World.GetClippingFrustum();
|
||||
|
||||
if (e.ZBuffered)
|
||||
|
|
@ -216,11 +207,11 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (mouseEvent3D.info != null && Object3DControlContext.Scene.SelectedItem != null)
|
||||
{
|
||||
hadClickOnControl = true;
|
||||
ActiveSelectedItem = RootSelection;
|
||||
activeSelectedItem = RootSelection;
|
||||
|
||||
zValueDisplayInfo.Visible = true;
|
||||
|
||||
var selectedItem = ActiveSelectedItem;
|
||||
var selectedItem = activeSelectedItem;
|
||||
|
||||
double distanceToHit = Vector3Ex.Dot(mouseEvent3D.info.HitPosition, mouseEvent3D.MouseRay.directionNormal);
|
||||
hitPlane = new PlaneShape(mouseEvent3D.MouseRay.directionNormal, distanceToHit, null);
|
||||
|
|
@ -238,7 +229,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
var selectedItem = RootSelection;
|
||||
|
||||
ActiveSelectedItem = selectedItem;
|
||||
activeSelectedItem = selectedItem;
|
||||
if (MouseIsOver)
|
||||
{
|
||||
zValueDisplayInfo.Visible = true;
|
||||
|
|
@ -271,7 +262,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
|
||||
Vector3 topPosition = GetTopPosition(selectedItem);
|
||||
Vector3 lockedBottom = new Vector3(topPosition.X, topPosition.Y, originalSelectedBounds.MinXYZ.Z);
|
||||
var lockedBottom = new Vector3(topPosition.X, topPosition.Y, originalSelectedBounds.MinXYZ.Z);
|
||||
|
||||
Vector3 newSize = Vector3.Zero;
|
||||
newSize.Z = newPosition.Z - lockedBottom.Z;
|
||||
|
|
@ -279,13 +270,13 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
// scale it
|
||||
Vector3 scaleAmount = ScaleCornerControl.GetScalingConsideringShiftKey(originalSelectedBounds, mouseDownSelectedBounds, newSize, Object3DControlContext.GuiSurface.ModifierKeys);
|
||||
|
||||
Matrix4X4 scale = Matrix4X4.CreateScale(scaleAmount);
|
||||
var scale = Matrix4X4.CreateScale(scaleAmount);
|
||||
|
||||
selectedItem.Matrix = selectedItem.ApplyAtBoundsCenter(scale);
|
||||
|
||||
// and keep the locked edge in place
|
||||
AxisAlignedBoundingBox scaledSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
||||
Vector3 newLockedBottom = new Vector3(topPosition.X, topPosition.Y, scaledSelectedBounds.MinXYZ.Z);
|
||||
var newLockedBottom = new Vector3(topPosition.X, topPosition.Y, scaledSelectedBounds.MinXYZ.Z);
|
||||
|
||||
selectedItem.Matrix *= Matrix4X4.CreateTranslation(lockedBottom - newLockedBottom);
|
||||
|
||||
|
|
@ -324,13 +315,13 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
||||
|
||||
Vector3 topPosition = GetTopPosition(selectedItem);
|
||||
Vector3 bottomPosition = new Vector3(topPosition.X, topPosition.Y, selectedBounds.MinXYZ.Z);
|
||||
var bottomPosition = new Vector3(topPosition.X, topPosition.Y, selectedBounds.MinXYZ.Z);
|
||||
double distBetweenPixelsWorldSpace = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(topPosition);
|
||||
|
||||
Vector3 arrowCenter = topPosition;
|
||||
arrowCenter.Z += arrowSize / 2 * distBetweenPixelsWorldSpace;
|
||||
|
||||
Matrix4X4 centerMatrix = Matrix4X4.CreateTranslation(arrowCenter);
|
||||
var centerMatrix = Matrix4X4.CreateTranslation(arrowCenter);
|
||||
centerMatrix = Matrix4X4.CreateScale(distBetweenPixelsWorldSpace) * centerMatrix;
|
||||
TotalTransform = centerMatrix;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,12 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public List<IObject3DControl> GetObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
||||
{
|
||||
return new List<IObject3DControl> { new MoveInZControl(object3DControlsLayer) };
|
||||
return new List<IObject3DControl>
|
||||
{
|
||||
new MoveInZControl(object3DControlsLayer),
|
||||
new SelectionShadow(object3DControlsLayer),
|
||||
new SnappingIndicators(object3DControlsLayer),
|
||||
};
|
||||
}
|
||||
|
||||
private ImageBuffer LoadImage()
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private readonly Mesh upArrowMesh;
|
||||
private AxisAlignedBoundingBox mouseDownSelectedBounds;
|
||||
private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
||||
private readonly double distToStart = 5;
|
||||
private readonly double lineLength = 55;
|
||||
private readonly double distToStart = 5 * GuiWidget.DeviceScale;
|
||||
private readonly double lineLength = 55 * GuiWidget.DeviceScale;
|
||||
private readonly List<Vector2> lines = new List<Vector2>();
|
||||
private readonly double upArrowSize = 7 * GuiWidget.DeviceScale;
|
||||
private readonly InlineEditControl zHeightDisplayInfo;
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
public class SelectionShadow : Object3DControl
|
||||
{
|
||||
static Mesh normalShadowMesh;
|
||||
private static Mesh normalShadowMesh;
|
||||
|
||||
private Color shadowColor;
|
||||
|
||||
private ThemeConfig theme;
|
||||
private readonly ThemeConfig theme;
|
||||
|
||||
public SelectionShadow(IObject3DControlContext context)
|
||||
: base(context)
|
||||
|
|
@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
TotalTransform = Matrix4X4.CreateTranslation(new Vector3(boundsCenter.X, boundsCenter.Y, 0.1));
|
||||
}
|
||||
|
||||
Mesh GetNormalShadowMesh()
|
||||
private Mesh GetNormalShadowMesh()
|
||||
{
|
||||
if (normalShadowMesh == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
public class SnappingIndicators : Object3DControl
|
||||
{
|
||||
private double distToStart = 10;
|
||||
private double lineLength = 15;
|
||||
private Vector2[] lines = new Vector2[4];
|
||||
private readonly double distToStart = 10 * GuiWidget.DeviceScale;
|
||||
private readonly double lineLength = 15 * GuiWidget.DeviceScale;
|
||||
private readonly Vector2[] lines = new Vector2[4];
|
||||
|
||||
public SnappingIndicators(IObject3DControlContext context)
|
||||
: base(context)
|
||||
|
|
@ -52,7 +52,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
public override void Dispose()
|
||||
{
|
||||
// no objects need to be removed
|
||||
Object3DControlContext.GuiSurface.AfterDraw -= Object3DControl_AfterDraw;
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo meshSelectInfo)
|
||||
|
|
@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
case HitQuadrant.LB:
|
||||
{
|
||||
Vector3 cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MinXYZ.Y, 0);
|
||||
var cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MinXYZ.Y, 0);
|
||||
double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint);
|
||||
|
||||
lines[0] = world.GetScreenPosition(cornerPoint - new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0));
|
||||
|
|
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
case HitQuadrant.LT:
|
||||
{
|
||||
Vector3 cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MaxXYZ.Y, 0);
|
||||
var cornerPoint = new Vector3(selectedBounds.MinXYZ.X, selectedBounds.MaxXYZ.Y, 0);
|
||||
double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint);
|
||||
|
||||
lines[0] = world.GetScreenPosition(cornerPoint - new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0));
|
||||
|
|
@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
case HitQuadrant.RB:
|
||||
{
|
||||
Vector3 cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MinXYZ.Y, 0);
|
||||
var cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MinXYZ.Y, 0);
|
||||
double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint);
|
||||
|
||||
lines[0] = world.GetScreenPosition(cornerPoint + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0));
|
||||
|
|
@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
case HitQuadrant.RT:
|
||||
{
|
||||
Vector3 cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MaxXYZ.Y, 0);
|
||||
var cornerPoint = new Vector3(selectedBounds.MaxXYZ.X, selectedBounds.MaxXYZ.Y, 0);
|
||||
double distBetweenPixelsWorldSpace = world.GetWorldUnitsPerScreenPixelAtPosition(cornerPoint);
|
||||
|
||||
lines[0] = world.GetScreenPosition(cornerPoint + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0));
|
||||
Loading…
Add table
Add a link
Reference in a new issue