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