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 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(); } }
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); } }