private void copyGroupBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; BackgroundWorker backgroundWorker = (BackgroundWorker)sender; PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY); MeshGroup meshGroupToCopy = asynchMeshGroups[SelectedMeshGroupIndex]; MeshGroup copyMeshGroup = new MeshGroup(); double meshCount = meshGroupToCopy.Meshes.Count; for (int i = 0; i < meshCount; i++) { Mesh mesh = asynchMeshGroups[SelectedMeshGroupIndex].Meshes[i]; copyMeshGroup.Meshes.Add(Mesh.Copy(mesh, (double progress0To1, string processingState, out bool continueProcessing) => { BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing); })); } PlatingHelper.FindPositionForGroupAndAddToPlate(copyMeshGroup, SelectedMeshGroupTransform, asynchPlatingDatas, asynchMeshGroups, asynchMeshGroupTransforms); PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, asynchMeshGroups.Count - 1, null); bool continueProcessing2; BackgroundWorker_ProgressChanged(.95, "", out continueProcessing2); }
public static List<Mesh> SplitConnectedIntoMeshes(MeshGroup meshGroupToSplit, ReportProgressRatio reportProgress) { List<Mesh> discreteMeshes = new List<Mesh>(); double ratioPerDiscreetMesh = 1.0 / meshGroupToSplit.Meshes.Count; double currentRatioDone = 0; foreach (Mesh mesh in meshGroupToSplit.Meshes) { List<Mesh> discreteVolumes = SplitVolumesIntoMeshes(mesh, (double progress0To1, string processingState, out bool continueProcessing) => { if (reportProgress != null) { double progress = (currentRatioDone + ratioPerDiscreetMesh * progress0To1); reportProgress(progress, "Split Into Meshes", out continueProcessing); } else { continueProcessing = true; } }); discreteMeshes.AddRange(discreteVolumes); currentRatioDone += ratioPerDiscreetMesh; } return discreteMeshes; }
public DeleteUndoCommand(View3DWidget view3DWidget, int deletedIndex) { this.view3DWidget = view3DWidget; this.deletedIndex = deletedIndex; meshGroupThatWasDeleted = view3DWidget.MeshGroups[deletedIndex]; deletedTransform = view3DWidget.MeshGroupTransforms[deletedIndex]; deletedPlatingData = view3DWidget.MeshGroupExtraData[deletedIndex]; }
public CopyUndoCommand(View3DWidget view3DWidget, int newItemIndex) { this.view3DWidget = view3DWidget; this.newItemIndex = newItemIndex; meshGroupThatWasDeleted = view3DWidget.MeshGroups[newItemIndex]; newItemTransform = view3DWidget.MeshGroupTransforms[newItemIndex]; newItemPlatingData = view3DWidget.MeshGroupExtraData[newItemIndex]; }
public void SetCenteringForMeshGroup(MeshGroup meshGroup) { AxisAlignedBoundingBox bounds = meshGroup.GetAxisAlignedBoundingBox(); Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2; centering = Matrix4X4.CreateTranslation(-boundsCenter); // and move the translation back so the part does not move translation *= Matrix4X4.CreateTranslation(boundsCenter); }
private void PushMeshGroupDataToAsynchLists(TraceInfoOpperation traceInfoOpperation, ReportProgressRatio reportProgress = null) { UiThread.RunOnIdle(() => { processingProgressControl.ProgressMessage = "Async Copy"; }); asynchMeshGroups.Clear(); asynchMeshGroupTransforms.Clear(); for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++) { MeshGroup meshGroup = MeshGroups[meshGroupIndex]; MeshGroup newMeshGroup = new MeshGroup(); for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++) { Mesh mesh = meshGroup.Meshes[meshIndex]; newMeshGroup.Meshes.Add(Mesh.Copy(mesh)); } asynchMeshGroups.Add(newMeshGroup); asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]); } asynchPlatingDatas.Clear(); for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++) { PlatingMeshGroupData meshData = new PlatingMeshGroupData(); meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale; MeshGroup meshGroup = MeshGroups[meshGroupIndex]; if (traceInfoOpperation == TraceInfoOpperation.DO_COPY) { meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData); } asynchPlatingDatas.Add(meshData); } UiThread.RunOnIdle(() => { processingProgressControl.ProgressMessage = ""; }); }
private static string SaveAndGetFilenameForMaterial(MeshGroup extruderMeshGroup, List<int> materialIndexsToSaveInThisSTL) { string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".stl"); string applicationUserDataPath = ApplicationDataStorage.ApplicationUserDataPath; string folderToSaveStlsTo = Path.Combine(applicationUserDataPath, "data", "temp", "amf_to_stl"); if (!Directory.Exists(folderToSaveStlsTo)) { Directory.CreateDirectory(folderToSaveStlsTo); } MeshOutputSettings settings = new MeshOutputSettings(); settings.MaterialIndexsToSave = materialIndexsToSaveInThisSTL; string extruder1StlFileToSlice = Path.Combine(folderToSaveStlsTo, fileName); MeshFileIo.Save(extruderMeshGroup, extruder1StlFileToSlice, settings); return extruder1StlFileToSlice; }
private void CreateBooleanTestGeometry(GuiWidget drawingWidget, DrawEventArgs e) { try { booleanGroup = new MeshGroup(); booleanGroup.Meshes.Add(ApplyBoolean(PolygonMesh.Csg.CsgOperations.Union, AxisAlignedBoundingBox.Union, new Vector3(100, 0, 20), "U")); booleanGroup.Meshes.Add(ApplyBoolean(PolygonMesh.Csg.CsgOperations.Subtract, null, new Vector3(100, 100, 20), "S")); booleanGroup.Meshes.Add(ApplyBoolean(PolygonMesh.Csg.CsgOperations.Intersect, AxisAlignedBoundingBox.Intersection , new Vector3(100, 200, 20), "I")); offset += direction; rotCurrent += rotChange; scaleCurrent += scaleChange; meshViewerWidget.MeshGroups.Add(booleanGroup); groupTransform = Matrix4X4.Identity; meshViewerWidget.MeshGroupTransforms.Add(groupTransform); } catch(Exception e2) { string text = e2.Message; int a = 0; } }
private void PushMeshGroupDataToAsynchLists(bool copyTraceInfo) { asynchMeshGroups.Clear(); asynchMeshGroupTransforms.Clear(); for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++) { MeshGroup meshGroup = MeshGroups[meshGroupIndex]; MeshGroup newMeshGroup = new MeshGroup(); for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++) { Mesh mesh = meshGroup.Meshes[meshIndex]; newMeshGroup.Meshes.Add(Mesh.Copy(mesh)); asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]); } asynchMeshGroups.Add(newMeshGroup); } asynchPlatingDatas.Clear(); for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++) { PlatingMeshGroupData meshData = new PlatingMeshGroupData(); meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale; MeshGroup meshGroup = MeshGroups[meshGroupIndex]; for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++) { if (copyTraceInfo) { meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData); } } asynchPlatingDatas.Add(meshData); } }
private void CreateBooleanTestGeometry(GuiWidget drawingWidget, DrawEventArgs e) { Mesh boxA = PlatonicSolids.CreateCube(40, 40, 40); //boxA.Triangulate(); boxA.Translate(centering); Mesh boxB = PlatonicSolids.CreateCube(40, 40, 40); //boxB.Triangulate(); for (int i = 0; i < 3; i++) { if (Math.Abs(direction[i] + offset[i]) > 10) { direction[i] = -direction[i]; } } offset += direction; boxB.Translate(offset + centering); booleanGroup = new MeshGroup(); booleanGroup.Meshes.Add(PolygonMesh.Csg.CsgOperations.Union(boxA, boxB)); meshViewerWidget.MeshGroups.Add(booleanGroup); groupTransform = ScaleRotateTranslate.Identity(); meshViewerWidget.MeshGroupTransforms.Add(groupTransform); }
private static bool CheckPosition(int meshGroupToMoveIndex, List<MeshGroup> allMeshGroups, List<ScaleRotateTranslate> meshTransforms, MeshGroup meshGroupToMove, AxisAlignedBoundingBox meshToMoveBounds, int yStep, int xStep, ref Matrix4X4 transform) { double xStepAmount = 5; double yStepAmount = 5; Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0); Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform); transform = Matrix4X4.CreateTranslation(newPosition); AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform); bool foundHit = false; for (int i = 0; i < meshGroupToMoveIndex; i++) { MeshGroup meshToTest = allMeshGroups[i]; if (meshToTest != meshGroupToMove) { AxisAlignedBoundingBox existingMeshBounds = GetAxisAlignedBoundingBox(meshToTest, meshTransforms[i].TotalTransform); AxisAlignedBoundingBox intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds); if (intersection.XSize > 0 && intersection.YSize > 0) { foundHit = true; break; } } } if (!foundHit) { return true; } return false; }
static AxisAlignedBoundingBox GetAxisAlignedBoundingBox(MeshGroup meshGroup, Matrix4X4 transform) { return meshGroup.GetAxisAlignedBoundingBox(transform); }
public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, ScaleRotateTranslate meshTransform, List<PlatingMeshGroupData> perMeshInfo, List<MeshGroup> meshesGroupsToAvoid, List<ScaleRotateTranslate> meshTransforms) { if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1) { return; } // first find the bounds of what is already here. AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[0], meshTransforms[0].TotalTransform); for (int i = 1; i < meshesGroupsToAvoid.Count; i++) { AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[i], meshTransforms[i].TotalTransform); allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds); } meshesGroupsToAvoid.Add(meshGroupToAdd); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); perMeshInfo.Add(newMeshInfo); meshTransform.SetCenteringForMeshGroup(meshGroupToAdd); meshTransforms.Add(meshTransform); int meshGroupIndex = meshesGroupsToAvoid.Count - 1; // move the part to the total bounds lower left side MeshGroup meshGroup = meshesGroupsToAvoid[meshGroupIndex]; Vector3 meshLowerLeft = GetAxisAlignedBoundingBox(meshGroup, meshTransforms[meshGroupIndex].TotalTransform).minXYZ; ScaleRotateTranslate atLowerLeft = meshTransforms[meshGroupIndex]; atLowerLeft.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ); meshTransforms[meshGroupIndex] = atLowerLeft; MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms); PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex); }