internal static void CreateSimulationPrintJobAsync(Core.Slices.RenderSliceInfo sliceInfo) { SimulationPolyLines = new List <SlicePolyLine3D>(); TotalProcessedSlices = 0; TotalAmountSlices = 1; var bwPrintJobSimulatorEngine = new System.ComponentModel.BackgroundWorker(); bwPrintJobSimulatorEngine.DoWork += bwbwPrintJobSimulatorEngine_DoWork; bwPrintJobSimulatorEngine.RunWorkerAsync(sliceInfo); }
internal static void CreateSimulationPrintJob(Core.Slices.RenderSliceInfo sliceInfo) { var selectedPrinterResolutionX = PrinterManager.DefaultPrinter.ProjectorResolutionX; var selectedPrinterResolutionY = PrinterManager.DefaultPrinter.ProjectorResolutionY; try { TotalProcessedSlices = 0; //copy org vectors to undopoints foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D) { var stlModel = object3d as STLModel3D; stlModel.CreateUndoPoints(); } } //update triangles with min/max z var topPoint = 0f; foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D) { var stlModel = (STLModel3D)object3d; //if (UserProfileManager.UserProfiles[0].Settings_PrintJob_MirrorObjects) stlModel.Mirror(false, false); stlModel.UpdateTrianglesMinMaxZ(); if (stlModel.TopPoint > topPoint) { topPoint = stlModel.TopPoint; } } } foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D && !(object3d is GroundPane)) { if (object3d is Models.Defaults.TrapezoidCorrection) { var stlModel = (Models.Defaults.TrapezoidCorrection)object3d; stlModel.Scale(2.0025f, 2.0025f, 2, ScaleEventArgs.TypeAxis.ALL, false, false); //move move 1px to left for (var arrayIndex = 0; arrayIndex < stlModel.Triangles.Count; arrayIndex++) { for (var triangleIndex = 0; triangleIndex < stlModel.Triangles[arrayIndex].Count; triangleIndex++) { if (triangleIndex == 0 && arrayIndex == 0) { Console.WriteLine(stlModel.Triangles[arrayIndex][triangleIndex].Vectors[0].Position); } stlModel.Triangles[arrayIndex][triangleIndex].Vectors[0].Position -= new Vector3(0.25f, 0.1f, 0); stlModel.Triangles[arrayIndex][triangleIndex].Vectors[1].Position -= new Vector3(0.25f, 0.1f, 0); stlModel.Triangles[arrayIndex][triangleIndex].Vectors[2].Position -= new Vector3(0.25f, 0.1f, 0); } } if (stlModel.SupportBasement) { stlModel.SupportBasementStructure.CalcSliceIndexes(sliceInfo.Material); } } else { var stlModel = (STLModel3D)object3d; stlModel.PreviousScaleFactorX = stlModel.ScaleFactorX; stlModel.PreviousScaleFactorY = stlModel.ScaleFactorY; stlModel.PreviousScaleFactorZ = stlModel.ScaleFactorZ; if (stlModel.SupportBasement) { stlModel.SupportBasementStructure._scaleFactorX = 1; stlModel.SupportBasementStructure._scaleFactorY = 1; stlModel.SupportBasementStructure._scaleFactorZ = 1; stlModel.SupportBasementStructure.Scale((float)((stlModel.SupportBasementStructure.ScaleFactorX / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * sliceInfo.Material.ShrinkFactor), 0, 0, Events.ScaleEventArgs.TypeAxis.X, false, false); stlModel.SupportBasementStructure.Scale(0, (float)((stlModel.SupportBasementStructure.ScaleFactorY / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * sliceInfo.Material.ShrinkFactor), 0, Events.ScaleEventArgs.TypeAxis.Y, false, false); stlModel.SupportBasementStructure.Scale(0, 0, (float)(stlModel.SupportBasementStructure.ScaleFactorZ * sliceInfo.Material.ShrinkFactor), Events.ScaleEventArgs.TypeAxis.Z, false, false); //combine movetranslation with scaled vector // stlModel.SupportBasementStructure.MoveTranslation = stlModel.MoveTranslation; stlModel.SupportBasementStructure.CombineMoveTranslationWithVectors(new OpenTK.Vector3( (stlModel.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * (float)sliceInfo.Material.ShrinkFactor, (stlModel.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * (float)sliceInfo.Material.ShrinkFactor, stlModel.MoveTranslation.Z * (float)sliceInfo.Material.ShrinkFactor)); stlModel.SupportBasementStructure.CalcSliceIndexes(sliceInfo.Material); } stlModel.Scale((float)((stlModel.ScaleFactorX / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * sliceInfo.Material.ShrinkFactor), 0, 0, Events.ScaleEventArgs.TypeAxis.X, false, false); stlModel.Scale(0, (float)((stlModel.ScaleFactorY / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * sliceInfo.Material.ShrinkFactor), 0, Events.ScaleEventArgs.TypeAxis.Y, false, false); stlModel.Scale(0, 0, (float)(stlModel.ScaleFactorZ * sliceInfo.Material.ShrinkFactor), Events.ScaleEventArgs.TypeAxis.Z, false, false); //combine movetranslation with scaled vector stlModel.CombineMoveTranslationWithVectors(new OpenTK.Vector3( (stlModel.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * (float)sliceInfo.Material.ShrinkFactor, (stlModel.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * (float)sliceInfo.Material.ShrinkFactor, stlModel.MoveTranslation.Z * (float)sliceInfo.Material.ShrinkFactor)); foreach (var supportCone in stlModel.SupportStructure) { supportCone._scaleFactorX = 1; supportCone._scaleFactorY = 1; supportCone._scaleFactorZ = 1; supportCone.Scale((float)((supportCone.ScaleFactorX / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * sliceInfo.Material.ShrinkFactor), 0, 0, Events.ScaleEventArgs.TypeAxis.X, false, false); supportCone.Scale(0, (float)((supportCone.ScaleFactorY / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * sliceInfo.Material.ShrinkFactor), 0, Events.ScaleEventArgs.TypeAxis.Y, false, false); supportCone.Scale(0, 0, (float)(supportCone.ScaleFactorZ * sliceInfo.Material.ShrinkFactor), Events.ScaleEventArgs.TypeAxis.Z, false, false); supportCone.CombineMoveTranslationWithVectors(new OpenTK.Vector3( (supportCone.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX + stlModel.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * (float)sliceInfo.Material.ShrinkFactor, (supportCone.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY + stlModel.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * (float)sliceInfo.Material.ShrinkFactor, stlModel.MoveTranslation.Z * (float)sliceInfo.Material.ShrinkFactor)); supportCone.CalcSliceIndexes(sliceInfo.Material); } foreach (var supportCone in stlModel.Triangles.HorizontalSurfaces.SupportStructure) { supportCone._scaleFactorX = 1; supportCone._scaleFactorY = 1; supportCone._scaleFactorZ = 1; supportCone.Scale((float)((supportCone.ScaleFactorX / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * sliceInfo.Material.ShrinkFactor), 0, 0, Events.ScaleEventArgs.TypeAxis.X, false, false); supportCone.Scale(0, (float)((supportCone.ScaleFactorY / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * sliceInfo.Material.ShrinkFactor), 0, Events.ScaleEventArgs.TypeAxis.Y, false, false); supportCone.Scale(0, 0, (float)(supportCone.ScaleFactorZ * sliceInfo.Material.ShrinkFactor), Events.ScaleEventArgs.TypeAxis.Z, false, false); supportCone.CombineMoveTranslationWithVectors(new OpenTK.Vector3( (supportCone.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX + stlModel.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * (float)sliceInfo.Material.ShrinkFactor, (supportCone.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY + stlModel.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * (float)sliceInfo.Material.ShrinkFactor, stlModel.MoveTranslation.Z * (float)sliceInfo.Material.ShrinkFactor + (stlModel.SupportBasement ? stlModel.SupportBasementStructure.TopPoint : 0))); supportCone.CalcSliceIndexes(sliceInfo.Material); } foreach (var supportCone in stlModel.Triangles.FlatSurfaces.SupportStructure) { supportCone._scaleFactorX = 1; supportCone._scaleFactorY = 1; supportCone._scaleFactorZ = 1; supportCone.Scale((float)((supportCone.ScaleFactorX / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * sliceInfo.Material.ShrinkFactor), 0, 0, Events.ScaleEventArgs.TypeAxis.X, false, false); supportCone.Scale(0, (float)((supportCone.ScaleFactorY / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * sliceInfo.Material.ShrinkFactor), 0, Events.ScaleEventArgs.TypeAxis.Y, false, false); supportCone.Scale(0, 0, (float)(supportCone.ScaleFactorZ * sliceInfo.Material.ShrinkFactor), Events.ScaleEventArgs.TypeAxis.Z, false, false); //combine movetranslation with scaled vector supportCone.CombineMoveTranslationWithVectors(new OpenTK.Vector3( (supportCone.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX + stlModel.MoveTranslation.X / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorX) * (float)sliceInfo.Material.ShrinkFactor, (supportCone.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY + stlModel.MoveTranslation.Y / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionFactorY) * (float)sliceInfo.Material.ShrinkFactor, stlModel.MoveTranslation.Z * (float)sliceInfo.Material.ShrinkFactor)); supportCone.CalcSliceIndexes(sliceInfo.Material); } } } } foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D && (!(object3d is GroundPane))) { var stlModel = (STLModel3D)object3d; stlModel.CalcSliceIndexes(sliceInfo.Material); } } //var sliceIndex = 0; var sliceCount = 0; // //determine slicecount var initialLayersHeight = 0f; for (var initialLayerIndex = 1; initialLayerIndex < sliceInfo.Material.InitialLayers + 1; initialLayerIndex++) { initialLayersHeight = (float)sliceInfo.Material.LT1 * initialLayerIndex; sliceCount++; if (initialLayersHeight > topPoint) { break; } } if (initialLayersHeight < topPoint) { var remainingLayersHeight = topPoint - initialLayersHeight; var remainingLayersCount = (remainingLayersHeight / sliceInfo.Material.LT2) + 1; for (var remainingLayerIndex = 0; remainingLayerIndex < remainingLayersCount; remainingLayerIndex++) { sliceCount++; } } var highestModelIndex = 0; TotalAmountSlices = 0; foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D && (!(object3d is GroundPane))) { var stlModel = object3d as STLModel3D; if (stlModel.SliceIndexes.Count >= TotalAmountSlices) { TotalAmountSlices = stlModel.SliceIndexes.Count; highestModelIndex = stlModel.Index; } } } var currentSliceIndex = 0; if (highestModelIndex > 0 && TotalAmountSlices > 0) { SortedDictionary <float, List <TriangleConnectionInfo> > stlModelIndexes = null; foreach (var object3d in ObjectView.Objects3D) { if (object3d is STLModel3D && (!(object3d is GroundPane))) { var stlModel = object3d as STLModel3D; if (stlModel.Index == highestModelIndex) { stlModelIndexes = stlModel.SliceIndexes; break; } } } foreach (var sliceIndexKey in stlModelIndexes) { var renderSliceInfo = new Core.Slices.RenderSliceInfo(); renderSliceInfo.SliceIndex = currentSliceIndex; renderSliceInfo.SliceHeight = sliceIndexKey.Key; renderSliceInfo.SliceCount = stlModelIndexes.Count; renderSliceInfo.PrinterResolutionX = selectedPrinterResolutionX; renderSliceInfo.PrinterResolutionY = selectedPrinterResolutionY; renderSliceInfo.Material = sliceInfo.Material; if (Managers.PerformanceSettingsManager.Settings.PrintJobGenerationMultiThreading && renderSliceInfo.SliceIndex > 0) { ThreadPool.QueueUserWorkItem(new WaitCallback((_) => { RenderSliceThread(renderSliceInfo); })); } else { currentSliceIndex = RenderSliceThread(renderSliceInfo); } currentSliceIndex++; } } else { //no printjob/objects found if (SimulationPrintJobCanceled != null) { SimulationPrintJobCanceled(null, null); } } //cleanjob image } catch (Exception exc) { Console.WriteLine(exc.Message); } }