Improving travel retractions rendering

This commit is contained in:
Lars Brubaker 2021-09-10 17:51:46 -07:00
parent 54fdca9a07
commit 83e083fcd6
4 changed files with 30 additions and 8 deletions

View file

@ -55,6 +55,7 @@ namespace MatterHackers.GCodeVisualizer
public static double ExtruderWidth { get; set; } = .4;
public static Color TravelColor = Color.Green;
public static Color RetractionColor = Color.FireEngineRed;
internal class Layer
{
@ -149,6 +150,9 @@ namespace MatterHackers.GCodeVisualizer
}
else
{
var extrusionAmount = currentInstruction.EPosition - previousInstruction.EPosition;
var filamentDiameterMm = gCodeFileToDraw.GetFilamentDiameter();
if (gCodeFileToDraw.IsExtruding(instructionIndex))
{
double layerThickness = gCodeFileToDraw.GetLayerHeight(layerToCreate);
@ -161,21 +165,32 @@ namespace MatterHackers.GCodeVisualizer
currentInstruction.Position,
currentInstruction.ToolIndex,
currentInstruction.FeedRate,
currentInstruction.EPosition - previousInstruction.EPosition,
gCodeFileToDraw.GetFilamentDiameter(),
extrusionAmount,
filamentDiameterMm,
layerThickness,
extrusionColor,
this.Gray));
}
else
{
if (extrusionAmount < 0)
{
double moveLength = (currentInstruction.Position - previousInstruction.Position).Length;
double filamentRadius = filamentDiameterMm / 2;
double areaSquareMm = (filamentRadius * filamentRadius) * Math.PI;
var extrusionVolumeMm3 = (float)(areaSquareMm * extrusionAmount);
var area = extrusionVolumeMm3 / moveLength;
}
renderFeaturesForLayer.Add(
new RenderFeatureTravel(
instructionIndex,
previousInstruction.Position,
currentInstruction.Position,
currentInstruction.ToolIndex,
currentInstruction.FeedRate));
currentInstruction.FeedRate,
extrusionAmount < 0));
}
}
}

View file

@ -43,7 +43,7 @@ namespace MatterHackers.GCodeVisualizer
private Color gray;
public RenderFeatureExtrusion(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed, double totalExtrusionMm, double filamentDiameterMm, double layerHeight, Color color, Color gray)
: base(instructionIndex, start, end, toolIndex, travelSpeed)
: base(instructionIndex, start, end, toolIndex, travelSpeed, false)
{
this.color = color;
this.gray = gray;

View file

@ -111,7 +111,7 @@ namespace MatterHackers.GCodeVisualizer
else if (extrusionAmount > 0)
{
// unretraction
retractionColor = new Color(Color.Blue, 200);
retractionColor = Color.Blue.WithAlpha(120);
}
if (graphics2D is Graphics2DOpenGL graphics2DGl)

View file

@ -40,25 +40,27 @@ namespace MatterHackers.GCodeVisualizer
protected Vector3Float end;
protected float travelSpeed;
private bool retractionTravel;
public Vector3Float Start => start;
public Vector3Float End => end;
public RenderFeatureTravel(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed)
public RenderFeatureTravel(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed, bool retractionTravel)
: base(instructionIndex, toolIndex)
{
this.toolIndex = toolIndex;
this.start = new Vector3Float(start);
this.end = new Vector3Float(end);
this.travelSpeed = (float)travelSpeed;
this.retractionTravel = retractionTravel;
}
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo)
{
if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
{
CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2);
CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, retractionTravel ? GCodeRenderer.RetractionColor : GCodeRenderer.TravelColor, .2);
}
}
@ -84,9 +86,14 @@ namespace MatterHackers.GCodeVisualizer
var endPoint = new Vector2(end.X, end.Y);
renderInfo.Transform.transform(ref endPoint);
if (retractionTravel)
{
movementColor = GCodeRenderer.RetractionColor;
}
if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
{
movementColor = new Color(movementColor, 200);
movementColor = movementColor.WithAlpha(120);
}
graphics2DGl.DrawAALineRounded(startPoint, endPoint, movementLineWidth, movementColor);