private void FindIntersectionPoints(List <Vector3> points, SlicePart part, float x) { if (!part.IsValid) { return; } bool closed = part.Closed; int count = part.Points.Count; int endIndex = closed ? count : count - 1; Vector3 prevPoint = part.Points[0]; bool prev_below = prevPoint.X <= x; for (int i = 1; i <= endIndex; i++) { Vector3 currentPoint = part.Points[i % count]; bool below = currentPoint.X <= x; if (prev_below != below) { Vector3 point = GetIntersectionPoint(prevPoint, currentPoint, x); points.Add(point); } else if (!closed && prevPoint.X == x) { points.Add(prevPoint); } prevPoint = currentPoint; prev_below = below; } if (!closed && prevPoint.X == x) { points.Add(prevPoint); } }
public void TryJoinToMidPoint() { part.AddSection(Vector3.Zero, Vector3.UnitX); part.AddSection(Vector3.UnitX, Vector3.UnitY); SlicePart other = new SlicePart(); other.AddSection(Vector3.UnitX, Vector3.UnitX * 3); Assert.IsFalse(part.Join(other)); }
public void TryJoinWithClosed() { part.AddSection(Vector3.Zero, Vector3.UnitX); part.AddSection(Vector3.UnitX, Vector3.UnitY); part.AddSection(Vector3.UnitY, Vector3.Zero); SlicePart other = new SlicePart(); other.AddSection(Vector3.Zero, Vector3.UnitX * 2); Assert.IsFalse(part.Join(other)); }
public void JoinToStartNotClose() { part.AddSection(Vector3.Zero, Vector3.UnitX); part.AddSection(Vector3.UnitX, Vector3.UnitY); SlicePart other = new SlicePart(); other.AddSection(Vector3.UnitY * 2, Vector3.Zero); Assert.IsTrue(part.Join(other)); Assert.AreEqual(4, part.Points.Count); Assert.AreEqual(Vector3.UnitY * 2, part.Points[0]); Assert.AreEqual(Vector3.Zero, part.Points[1]); Assert.AreEqual(Vector3.UnitX, part.Points[2]); Assert.AreEqual(Vector3.UnitY, part.Points[3]); Assert.IsFalse(part.Closed); }
public void JoinAndClose() { part.AddSection(Vector3.Zero, Vector3.UnitX, Vector3.UnitY); part.AddSection(Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ); SlicePart other = new SlicePart(); other.AddSection(Vector3.UnitY, Vector3.Zero, Vector3.One); Assert.IsTrue(part.Join(other)); Assert.AreEqual(3, part.Points.Count); Assert.AreEqual(Vector3.Zero, part.Points[0]); Assert.AreEqual(Vector3.UnitX, part.Points[1]); Assert.AreEqual(Vector3.UnitY, part.Points[2]); Assert.AreEqual(3, part.Normals.Count); Assert.AreEqual(Vector3.UnitY, part.Normals[0]); Assert.AreEqual(Vector3.UnitZ, part.Normals[1]); Assert.AreEqual(Vector3.One, part.Normals[2]); Assert.IsTrue(part.Closed); }
public static Slice GetSkirt(this Model model, float scale, SlicerOptions options) { Slice slice = new Slice(); SlicePart part = new SlicePart(); ObjectDimensions dimensions = model.Dimensions; Vector3 minPoint = dimensions.MinPoint; Vector3 maxPoint = dimensions.MaxPoint; float skirtDistance = options.Skirt.Distance / scale; float skirtZ = dimensions.MinPoint.Z + options.Printer.ExtruderDiameter / 2; part.Points.Add(new Vector3(minPoint.X - skirtDistance / 2, minPoint.Y - skirtDistance, skirtZ)); // 0 part.Normals.Add(-Vector3.UnitY); part.Points.Add(new Vector3(maxPoint.X + skirtDistance / 2, minPoint.Y - skirtDistance, skirtZ)); // 1 part.Normals.Add((Vector3.UnitX - Vector3.UnitY).Normalized()); part.Points.Add(new Vector3(maxPoint.X + skirtDistance, minPoint.Y - skirtDistance / 2, skirtZ)); // 2 part.Normals.Add(Vector3.UnitX); part.Points.Add(new Vector3(maxPoint.X + skirtDistance, maxPoint.Y + skirtDistance / 2, skirtZ)); // 3 part.Normals.Add((Vector3.UnitX + Vector3.UnitY).Normalized()); part.Points.Add(new Vector3(maxPoint.X + skirtDistance / 2, maxPoint.Y + skirtDistance, skirtZ)); // 4 part.Normals.Add(Vector3.UnitY); part.Points.Add(new Vector3(minPoint.X - skirtDistance / 2, maxPoint.Y + skirtDistance, skirtZ)); // 5 part.Normals.Add((-Vector3.UnitX + Vector3.UnitY).Normalized()); part.Points.Add(new Vector3(minPoint.X - skirtDistance, maxPoint.Y + skirtDistance / 2, skirtZ)); // 6 part.Normals.Add(-Vector3.UnitX); part.Points.Add(new Vector3(minPoint.X - skirtDistance, minPoint.Y - skirtDistance / 2, skirtZ)); // 7 part.Normals.Add((-Vector3.UnitX - Vector3.UnitY).Normalized()); part.Closed = true; slice.Parts.Add(part); return(slice); }
public void Cleanup() { part = null; }
public void Initialize() { part = new SlicePart(); }