Moving slice layer to polygon mesh
This commit is contained in:
parent
9ea198686a
commit
d88564441e
5 changed files with 36 additions and 109 deletions
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2015, Lars Brubaker
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.VectorMath;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.MatterControl.Slicing
|
||||
{
|
||||
public class SliceLayer
|
||||
{
|
||||
public struct Segment
|
||||
{
|
||||
internal Vector2 start;
|
||||
|
||||
public Vector2 Start { get { return start; } }
|
||||
|
||||
internal Vector2 end;
|
||||
|
||||
public Vector2 End { get { return end; } }
|
||||
|
||||
internal Segment(Vector2 start, Vector2 end)
|
||||
{
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
}
|
||||
|
||||
private double zHeight;
|
||||
|
||||
public double ZHeight { get { return zHeight; } }
|
||||
|
||||
private List<Segment> unorderedSegments = new List<Segment>();
|
||||
|
||||
public List<Segment> UnorderedSegments { get { return unorderedSegments; } }
|
||||
|
||||
private List<VertexStorage> perimeters;
|
||||
|
||||
public List<VertexStorage> Perimeters { get { return perimeters; } }
|
||||
|
||||
public SliceLayer(double zHeight)
|
||||
{
|
||||
this.zHeight = zHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.PolygonMesh.Csg;
|
||||
using MatterHackers.VectorMath;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -38,14 +39,36 @@ namespace MatterHackers.MatterControl.Slicing
|
|||
{
|
||||
public class SliceLayers
|
||||
{
|
||||
private List<SliceLayer> allLayers = new List<SliceLayer>();
|
||||
|
||||
public List<SliceLayer> AllLayers { get { return allLayers; } }
|
||||
|
||||
public SliceLayers()
|
||||
{
|
||||
}
|
||||
|
||||
public List<SliceLayer> AllLayers { get; } = new List<SliceLayer>();
|
||||
|
||||
public void DumpSegmentsToGcode(string filename)
|
||||
{
|
||||
StreamWriter stream = new StreamWriter(filename);
|
||||
stream.Write("; some gcode to look at the layer segments");
|
||||
int extrudeAmount = 0;
|
||||
for (int layerIndex = 0; layerIndex < AllLayers.Count; layerIndex++)
|
||||
{
|
||||
stream.Write("; LAYER:{0}\n".FormatWith(layerIndex));
|
||||
List<Segment> unorderedSegments = AllLayers[layerIndex].UnorderedSegments;
|
||||
for (int segmentIndex = 0; segmentIndex < unorderedSegments.Count; segmentIndex++)
|
||||
{
|
||||
Segment segment = unorderedSegments[segmentIndex];
|
||||
stream.Write("G1 X{0}Y{1}\n", segment.Start.X, segment.Start.Y);
|
||||
stream.Write("G1 X{0}Y{1}E{2}\n", segment.End.X, segment.End.Y, extrudeAmount++);
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
public SliceLayer GetPerimetersAtHeight(Mesh meshToSlice, double zHeight)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void GetPerimetersForAllLayers(Mesh meshToSlice, double firstLayerHeight, double otherLayerHeights)
|
||||
{
|
||||
AllLayers.Clear();
|
||||
|
|
@ -61,7 +84,7 @@ namespace MatterHackers.MatterControl.Slicing
|
|||
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
{
|
||||
allLayers.Add(new SliceLayer(currentZ));
|
||||
AllLayers.Add(new SliceLayer(new Plane(Vector3.UnitZ, i)));
|
||||
currentZ += otherLayerHeights;
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +100,8 @@ namespace MatterHackers.MatterControl.Slicing
|
|||
|
||||
for (int layerIndex = 0; layerIndex < layerCount; layerIndex++)
|
||||
{
|
||||
SliceLayer layer = allLayers[layerIndex];
|
||||
double zHeight = layer.ZHeight;
|
||||
SliceLayer layer = AllLayers[layerIndex];
|
||||
double zHeight = layer.SlicePlane.DistanceToPlaneFromOrigin;
|
||||
if (zHeight < minZ)
|
||||
{
|
||||
// not up to the start of the face yet
|
||||
|
|
@ -91,38 +114,14 @@ namespace MatterHackers.MatterControl.Slicing
|
|||
}
|
||||
Plane cutPlane = new Plane(Vector3.UnitZ, zHeight);
|
||||
|
||||
Vector3 start;
|
||||
Vector3 end;
|
||||
if (face.GetCutLine(cutPlane, out start, out end))
|
||||
var start = Vector3.Zero;
|
||||
var end = Vector3.Zero;
|
||||
if (face.GetCutLine(cutPlane, ref start, ref end))
|
||||
{
|
||||
layer.UnorderedSegments.Add(new SliceLayer.Segment(new Vector2(start.X, start.Y), new Vector2(end.X, end.Y)));
|
||||
layer.UnorderedSegments.Add(new Segment(new Vector2(start.X, start.Y), new Vector2(end.X, end.Y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SliceLayer GetPerimetersAtHeight(Mesh meshToSlice, double zHeight)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DumpSegmentsToGcode(string filename)
|
||||
{
|
||||
StreamWriter stream = new StreamWriter(filename);
|
||||
stream.Write("; some gcode to look at the layer segments");
|
||||
int extrudeAmount = 0;
|
||||
for (int layerIndex = 0; layerIndex < allLayers.Count; layerIndex++)
|
||||
{
|
||||
stream.Write("; LAYER:{0}\n".FormatWith(layerIndex));
|
||||
List<SliceLayer.Segment> unorderedSegments = allLayers[layerIndex].UnorderedSegments;
|
||||
for (int segmentIndex = 0; segmentIndex < unorderedSegments.Count; segmentIndex++)
|
||||
{
|
||||
SliceLayer.Segment segment = unorderedSegments[segmentIndex];
|
||||
stream.Write("G1 X{0}Y{1}\n", segment.start.X, segment.start.Y);
|
||||
stream.Write("G1 X{0}Y{1}E{2}\n", segment.end.X, segment.end.Y, extrudeAmount++);
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue