コード例 #1
0
        private void WriteModel(StreamWriter writer)
        {
            writer.WriteLine("; Model");

            float delta = Options.Slice.Step;
            int   count = (int)Math.Truncate(Model.Dimensions.Size.Z / delta) + 1;
            int   startSolidLayerIndex = Options.Fill.SolidLayerCount;
            int   endSolidLayerIndex   = count - Options.Fill.SolidLayerCount - 1;

            for (int i = 0; i < count; i++)
            {
                if (RaiseOnProgress(i * 100 / count))
                {
                    return;
                }

                if (i == 1 && Options.Printer.UseFan)
                {
                    writer.WriteLine($"M106 S{Options.Printer.FanSpeed * 255 / 100}"); // Включить вентилятор
                }
                float z = Model.Dimensions.MinPoint.Z + delta * (i + 1);
                Slice outerPerimeter = Model.GetSlice(z, Options);
                outerPerimeter.Index = i;

                if (outerPerimeter.Parts.Count > 0)
                {
                    writer.WriteLine($"; Layer {i}, Z={z.ToString(CultureInfo.InvariantCulture)}");
                    WritePerimeter(writer, outerPerimeter, delta * i);

                    Slice fillPerimeter = outerPerimeter;
                    if (Expander != null)
                    {
                        Slice innerPerimeter = outerPerimeter.Expand(Expander, -Options.Printer.ExtruderDiameter);
                        WritePerimeter(writer, innerPerimeter, 0f);

                        if (Options.Fill.FillLocation == FillLocation.InnerPerimeter)
                        {
                            fillPerimeter = innerPerimeter;
                        }
                        else if (Options.Fill.FillLocation == FillLocation.InsideInnerPerimeter)
                        {
                            fillPerimeter = outerPerimeter.Expand(Expander, -Options.Printer.ExtruderDiameter * 2);
                        }
                    }

                    FillFactory fillFactory = CreateFillFactory();
                    fillFactory.LayerByLayer = Options.Fill.LayerByLayer;
                    float fillStep = (i < startSolidLayerIndex || i >= endSolidLayerIndex) ?
                                     Options.Printer.ExtruderDiameter :                                 // Solid layer
                                     Options.Printer.ExtruderDiameter * 100f / Options.Fill.Percentage; // Regular fill
                    Fill fill = fillFactory.CreateFill(fillPerimeter, (float)(Options.Fill.AngleInDegrees * Math.PI / 180), fillStep);
                    WriteFill(writer, fill);
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: FlashyFire/VKRSlicer
        private void DrawFill(Slice slice, bool solid)
        {
            Vector3 viewScale    = GetViewScale();
            Vector3 viewPosition = GetViewPosition();

            SetupMaterial(options.View.FillLineColor, options.View.FillLineColor, 100f);
            GL.LineWidth(options.View.FillLineWidth);
            FillFactory fillFactory = CreateFillFactory();

            fillFactory.LayerByLayer = options.Fill.LayerByLayer;
            float step = options.Printer.ExtruderDiameter * 100f / (solid ? 100f : options.Fill.Percentage);
            Fill  fill = fillFactory.CreateFill(slice, (float)(options.Fill.AngleInDegrees * Math.PI / 180), step / scale.X);

            foreach (FillPart part in fill.Parts)
            {
                GL.Begin(PrimitiveType.LineStrip);
                foreach (Vector3 point in part.Points)
                {
                    GL.Vertex3(point * viewScale + viewPosition);
                }
                GL.End();
            }
        }