void synchronize_meshes(BackgroundThreadData d) { // filter out any ignored/invalid meshes List <PrintMeshSO> printMeshes = CC.Objects.PrintMeshes; List <PrintMeshSO> useMeshes = new List <PrintMeshSO>(); foreach (PrintMeshSO printMesh in printMeshes) { if (printMesh.Settings.ObjectType != PrintMeshSettings.ObjectTypes.Ignored) { useMeshes.Add(printMesh); } } // this has to run in main thread int N = useMeshes.Count; d.meshToScene = new Frame3f[N]; d.localScale = new Vector3f[N]; d.meshCopies = new DMesh3[N]; d.meshSettings = new PrintMeshSettings[N]; for (int k = 0; k < N; ++k) { PrintMeshSO so = useMeshes[k]; d.meshCopies[k] = new DMesh3(so.Mesh); d.meshToScene[k] = SceneTransforms.ObjectToScene(so, Frame3f.Identity); d.localScale[k] = so.GetLocalScale(); d.meshSettings[k] = so.Settings.Clone(); } }
private void ObjSettings_OnSettingModified(ObjectSettings settings) { PrintMeshSO so = settings.SourceSO as PrintMeshSO; update_mesh_material(so); // set dirty flag on scene CCActions.SetCurrentSceneModified(); }
public void RemovePrintMesh(PrintMeshSO mesh) { mesh.OnMeshModified -= Mesh_OnMeshModified; mesh.OnTransformModified -= Mesh_OnTransformModified; PrintMeshes.Remove(mesh); CC.MeshAnalysis.RemoveMesh(mesh); CC.Slicer.InvalidateSlicing(); }
public static void OnApply_PurgeSpiralTool(PurgeSpiralTool tool, DMeshSO previewSO) { if (previewSO.Mesh.TriangleCount == 0) { return; } PrintMeshSO printSO = convert_to_print_mesh(previewSO); printSO.Name = UniqueNames.GetNext(previewSO.Name); CC.ActiveScene.History.PushInteractionCheckpoint(); }
public static void RemovePrintMesh(PrintMeshSO removeSO) { DeleteSOChange change = new DeleteSOChange() { scene = CC.ActiveScene, so = removeSO, OnAddedF = (so) => { CC.Objects.AddPrintMesh(so as PrintMeshSO); }, OnRemovedF = (so) => { CC.Objects.RemovePrintMesh(so as PrintMeshSO); } }; CC.ActiveScene.History.PushChange(change, false); }
public static bool Emit(SceneSerializer s, IOutputStream o, SceneObject gso) { PrintMeshSO so = gso as PrintMeshSO; o.AddAttribute(IOStrings.ASOType, so.Type.identifier); o.AddAttribute(AttrSourceFilePath, so.SourceFilePath); EmitPrintMeshSettings(s, o, so.Settings); SceneSerializerEmitTypesExt.EmitDMeshSO(s, o, so as DMeshSO); return(true); }
public void AddPrintMesh(PrintMeshSO mesh) { PrintMeshes.Add(mesh); mesh.OnMeshModified += Mesh_OnMeshModified; mesh.OnTransformModified += Mesh_OnTransformModified; CC.MeshAnalysis.AddMesh(mesh); update_mesh_material(mesh); CC.Slicer.InvalidateSlicing(); }
public static void OnApply_PlaneCutTool(PlaneCutTool tool, Dictionary <DMeshSO, DMeshSO> result) { standard_multi_so_tool_handler(result, true); if (tool.KeepBothSides) { foreach (var pair in tool.OtherSideMeshes) { PrintMeshSO newSO = emit_new_print_mesh(pair.Value, pair.Key); newSO.Name = UniqueNames.GetNext(pair.Key.Name); } } CC.ActiveScene.History.PushInteractionCheckpoint(); }
/// <summary> /// convert preview SO to print mesh, discard preview /// TODO: be able to swap/transfer preview into print /// </summary> static PrintMeshSO convert_to_print_mesh(DMeshSO previewSO) { previewSO.EnableSpatial = true; PrintMeshSO printMeshSO = previewSO.DuplicateSubtype <PrintMeshSO>(); printMeshSO.Name = previewSO.Name; printMeshSO.AssignSOMaterial(CCMaterials.PrintMeshMaterial); CC.ActiveScene.RemoveSceneObject(previewSO, true); CCActions.AddNewPrintMesh(printMeshSO); return(printMeshSO); }
public void AddMesh(PrintMeshSO sourceSO) { if (!File.Exists(sourceSO.SourceFilePath)) { return; } lock (TrackedMeshes) { if (TrackedMeshes.Contains(sourceSO) == false) { TrackedMeshes.Add(sourceSO); } } }
protected override void duplicate_to(DMeshSO copy) { base.duplicate_to(copy); PrintMeshSO pcopy = copy as PrintMeshSO; if (pcopy != null) { pcopy.Settings = this.Settings.Clone(); pcopy.UpDirection = this.UpDirection; pcopy.SourceFilePath = this.SourceFilePath; pcopy.LastReadFileTimestamp = this.LastReadFileTimestamp; pcopy.AutoUpdateOnSourceFileChange = this.AutoUpdateOnSourceFileChange; } }
public static void AddNewPrintMesh(PrintMeshSO printMeshSO) { AddSOChange addChange = new AddSOChange() { scene = CC.ActiveScene, so = printMeshSO, OnAddedF = (so) => { CC.Objects.AddPrintMesh(so as PrintMeshSO); }, OnRemovedF = (so) => { CC.Objects.RemovePrintMesh(so as PrintMeshSO); } }; CC.ActiveScene.History.PushChange(addChange, false); }
public static void SetFileMonitoringEnabled(PrintMeshSO so, bool bEnabled) { if (so.CanAutoUpdateFromSource() == false || so.AutoUpdateOnSourceFileChange == bEnabled) { return; } if (bEnabled) { so.AutoUpdateOnSourceFileChange = true; CC.FileMonitor.AddMesh(so); } else { so.AutoUpdateOnSourceFileChange = false; CC.FileMonitor.RemoveMesh(so); } }
static PrintMeshSO emit_new_print_mesh(DMesh3 mesh, DMeshSO fromParent) { PrintMeshSO newSO = new PrintMeshSO(); newSO.Create(mesh, CCMaterials.PrintMeshMaterial); CCActions.AddNewPrintMesh(newSO); if (fromParent != null) { newSO.SetLocalScale(fromParent.GetLocalScale()); newSO.SetLocalFrame(fromParent.GetLocalFrame(CoordSpace.SceneCoords), CoordSpace.SceneCoords); } else { throw new NotImplementedException("have not implemented this path yet..."); // estimate frame?? } return(newSO); }
public static void OnApply_GenerateGraphSupportsTool(GenerateGraphSupportsTool tool, DMeshSO previewSO) { if (previewSO.Mesh.TriangleCount == 0) { return; } if (tool.Targets.Count() == CC.Objects.PrintMeshes.Count) { CC.Settings.GenerateSupport = false; } PrintMeshSO printSO = convert_to_print_mesh(previewSO); printSO.Name = UniqueNames.GetNext("Tree Support"); printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Support; printSO.AssignSOMaterial(CCMaterials.SupportMeshMaterial); CC.ActiveScene.History.PushInteractionCheckpoint(); }
private void ActiveScene_ChangedEvent(object sender, SceneObject so, SceneChangeType type) { if (so is PrintMeshSO == false) { return; } PrintMeshSO printSO = so as PrintMeshSO; if (type == SceneChangeType.Removed) { RemoveMesh(printSO); } else if (type == SceneChangeType.Added && printSO.CanAutoUpdateFromSource() && printSO.AutoUpdateOnSourceFileChange) { // this should only happen on undo of delete, right? AddMesh(printSO); } }
public static void OnApply_AddHoleTool(AddHoleTool tool) { if (tool.HoleType == AddHoleTool.HoleTypes.CavityObject) { PrintMeshSO printSO = convert_to_print_mesh(tool.GetOutputSO()); printSO.Name = UniqueNames.GetNext("Hole"); printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Cavity; printSO.AssignSOMaterial(CCMaterials.CavityMeshMaterial); } else { bool replace_input = tool.Parameters.GetValueBool("replace_input"); DMeshSO previewSO = tool.GetOutputSO(); previewSO.EnableSpatial = true; // required because preview has no spatial DS standard_mesh_tool_handler(new List <DMeshSO>() { tool.TargetSO as DMeshSO }, previewSO, replace_input); } CC.ActiveScene.History.PushInteractionCheckpoint(); }
public void UpdateFromSettings(PrintMeshSO printSO) { if (printSO == null) { return; } ActiveSO = printSO; Active = printSO.Settings; // Note!! have to use internal variables here, if we use accessors then we // will spawn toolpath invalidations when objects change object_type = Active.ObjectType; no_voids = Active.NoVoids; shell_only = Active.OuterShellOnly; open_mode = Active.OpenMeshMode; clearance = Active.Clearance; offset_xy = Active.OffsetXY; bValueModified = false; OnNewSettings?.Invoke(this); }
public static SceneObject Build(SOFactory factory, FScene scene, TypedAttribSet attributes) { PrintMeshSO so = new PrintMeshSO(); factory.RestoreDMeshSO(scene, attributes, so); if (attributes.ContainsKey(AttrSourceFilePath)) { so.SourceFilePath = attributes[AttrSourceFilePath] as string; } PrintMeshSettings settings = null; try { settings = RestorePrintMeshSettings(factory, attributes); } catch { } if (settings != null) { so.Settings = settings; } return(so); }
public static void DuplicateSelectedObjects(bool bInteractive) { List <SceneObject> duplicate = new List <SceneObject>(CC.ActiveScene.Selected); foreach (var existingSO in duplicate) { if (existingSO is PrintMeshSO == false) { throw new NotSupportedException("CCActions.DuplicateSelectedObjects: currently can only delete print meshes?"); } PrintMeshSO dupeSO = (existingSO as PrintMeshSO).DuplicateSubtype <PrintMeshSO>(); dupeSO.Name = UniqueNames.GetNext(existingSO.Name); AddNewPrintMesh(dupeSO); // If we have multi-select, then we duplicated relative to a transient group that will // go away. So, update position using scene coords if (existingSO.Parent is FScene == false) { var sceneF = existingSO.GetLocalFrame(CoordSpace.SceneCoords); dupeSO.SetLocalFrame(sceneF, CoordSpace.SceneCoords); Vector3f scaleL = existingSO.GetLocalScale(); Vector3f scaleS = SceneTransforms.ObjectToSceneV(existingSO, scaleL); float scale = scaleS.Length / scaleL.Length; dupeSO.SetLocalScale(scale * Vector3f.One); } if (dupeSO.CanAutoUpdateFromSource() && dupeSO.AutoUpdateOnSourceFileChange == true) { CC.FileMonitor.AddMesh(dupeSO); } } if (bInteractive) { CC.ActiveScene.History.PushInteractionCheckpoint(); } }
protected void update_mesh_material(PrintMeshSO so) { bool enable_shadow = true; if (so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.Support) { so.AssignSOMaterial(CCMaterials.SupportMeshMaterial); } else if (so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.Cavity) { so.AssignSOMaterial(CCMaterials.CavityMeshMaterial); } else if (so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.CropRegion) { so.AssignSOMaterial(CCMaterials.CropRegionMeshMaterial); enable_shadow = false; } else if (so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.Ignored) { so.AssignSOMaterial(CCMaterials.IgnoreMeshMaterial); enable_shadow = false; } else if (so.Mesh.CachedIsClosed == false) { so.AssignSOMaterial(CCMaterials.OpenPrintMeshMaterial); } else { so.AssignSOMaterial(CCMaterials.PrintMeshMaterial); } if (enable_shadow != so.ShadowsEnabled) { so.SetShadowsEnabled(enable_shadow); } }
/// <summary> /// called on scene & selection changes, to update the global current PrintSettings object /// (which currently can only be applied to a single object at a time) /// </summary> public static void UpdateObjectSettings() { if (CC.ObjSettings.IsActive) { CC.ObjSettings.WriteToCurrentSettings(); } List <PrintMeshSO> meshes = CC.ActiveScene.FindSceneObjectsOfType <PrintMeshSO>(); List <PrintMeshSO> selected = CC.ActiveScene.FindSceneObjectsOfType <PrintMeshSO>(true); // invalid scene/selection, clear settings and hide panel if (meshes.Count == 0 || (meshes.Count > 1 && selected.Count != 1)) { CC.ObjSettings.ClearCurrentSettings(); } else { // upate for current object PrintMeshSO so = (meshes.Count == 1) ? meshes[0] : selected[0]; CC.ObjSettings.UpdateFromSettings(so); } ObjectsTabbedPanelSetup.UpdateVisibilityFromSelection(); }
async Task complete_import(string sFilename, DMesh3Builder builder, Action <string> onCompletedF) { AxisAlignedBox3d bounds = AxisAlignedBox3d.Empty; foreach (DMesh3 mesh in builder.Meshes) { bounds.Contain(mesh.CachedBounds); } Vector3d centerPt = bounds.Center; Vector3d basePt = centerPt - bounds.Height * 0.5f * Vector3d.AxisY; Vector3d vTranslate = basePt; await Task.Run(() => { foreach (DMesh3 mesh in builder.Meshes) { MeshTransforms.Translate(mesh, -vTranslate); } }); bool bFirst = (CC.Objects.PrintMeshes.Count == 0); Vector3d postTranslate = Vector3d.Zero; switch (CCPreferences.ImportTransformMode) { case CCPreferences.ImportTransformModes.AutoCenterAll: break; case CCPreferences.ImportTransformModes.AutoCenterFirst: if (bFirst) { CCState.SceneImportTransform = vTranslate; } postTranslate = vTranslate - CCState.SceneImportTransform; break; case CCPreferences.ImportTransformModes.NoAutoCenter: postTranslate = vTranslate; break; } // compact input meshes await Task.Run(() => { gParallel.ForEach(builder.Meshes, (mesh) => { MeshEditor.RemoveUnusedVertices(mesh); }); gParallel.ForEach(Interval1i.Range(builder.Meshes.Count), (k) => { if (builder.Meshes[k].IsCompact == false) { builder.Meshes[k] = new DMesh3(builder.Meshes[k], true); } }); }); string sBaseName = Path.GetFileNameWithoutExtension(sFilename); foreach (DMesh3 mesh in builder.Meshes) { PrintMeshSO meshSO = new PrintMeshSO(); meshSO.Create(mesh, CCMaterials.PrintMeshMaterial); meshSO.UpDirection = UpDirection.ZUp; Frame3f f = meshSO.GetLocalFrame(CoordSpace.ObjectCoords); f.Origin = f.Origin + (Vector3f)postTranslate; meshSO.SetLocalFrame(f, CoordSpace.ObjectCoords); // if only one mesh, we can keep a reference if (builder.Meshes.Count == 1) { meshSO.SourceFilePath = sFilename; meshSO.LastReadFileTimestamp = File.GetLastWriteTime(SourceFilePath).Ticks; } meshSO.Name = UniqueNames.GetNext(sBaseName); CCActions.AddNewPrintMesh(meshSO); } if (onCompletedF != null) { onCompletedF(sFilename); } }
public bool ImportAutoUpdate(PrintMeshSO so) { SourceFilePath = so.SourceFilePath; if (!File.Exists(SourceFilePath)) { ErrorMessage = "MeshImporter.ImportAutoUpdate: file does not exist"; return(false); } DMesh3Builder builder = new DMesh3Builder(); StandardMeshReader reader = new StandardMeshReader() { MeshBuilder = builder }; long timestamp = File.GetLastWriteTime(SourceFilePath).Ticks; IOReadResult result = reader.Read(SourceFilePath, ReadOptions.Defaults); if (result.code != IOCode.Ok) { ErrorMessage = "MeshImporter.ImportAutoUpdate: failed with message " + result.message; return(false); } if (builder.Meshes.Count == 0) { ErrorMessage = "MeshImporter.ImportAutoUpdate: no meshes in file!"; return(false); } if (builder.Meshes.Count != 1) { ErrorMessage = "MeshImporter.ImportAutoUpdate: can only auto-update from file with single mesh!"; return(false); } DMesh3 mesh = builder.Meshes[0]; // unity xforms MeshTransforms.ConvertZUpToYUp(mesh); MeshTransforms.FlipLeftRightCoordSystems(mesh); // wait for any active tools to finish // [TODO] do we need to do this? while (CC.ActiveContext.ToolManager.HasActiveTool()) { Thread.Sleep(1000); } if (CC.ActiveScene.SceneObjects.Contains(so) == false) { ErrorMessage = "MeshImporter.ImportAutoUpdate: SO no longer exists"; return(false); } // change event?? so.LastReadFileTimestamp = timestamp; ThreadMailbox.PostToMainThread(() => { so.ReplaceMesh(mesh, true); }); return(true); }
public void RemoveMesh(PrintMeshSO so) { lock (TrackedMeshes) { TrackedMeshes.Remove(so); } }
public void ClearCurrentSettings() { Active = null; ActiveSO = null; }