public virtual void Update() { base.begin_update(); int start_timestamp = this.CurrentInputTimestamp; if (MeshSource == null) { throw new Exception("CombineMeshesOp: must set valid MeshSource to compute!"); } ResultMesh = null; try { DMesh3 meshIn = new DMesh3(MeshSource.GetDMeshUnsafe()); if (orient_nested_shells) { MeshConnectedComponents comp = new MeshConnectedComponents(meshIn); comp.FindConnectedT(); DSubmesh3Set subMeshes = new DSubmesh3Set(meshIn, comp); List <DMesh3> curMeshes = new List <DMesh3>(); foreach (var submesh in subMeshes) { curMeshes.Add(submesh.SubMesh); } MeshSpatialSort sort = new MeshSpatialSort(); foreach (var mesh in curMeshes) { sort.AddMesh(mesh, mesh); } sort.Sort(); ResultMesh = new DMesh3(); MeshEditor editor = new MeshEditor(ResultMesh); foreach (var solid in sort.Solids) { DMesh3 outer = solid.Outer.Mesh; if (!is_outward_oriented(outer)) { outer.ReverseOrientation(); } editor.AppendMesh(outer, ResultMesh.AllocateTriangleGroup()); foreach (var hole in solid.Cavities) { if (hole.Mesh.CachedIsClosed && is_outward_oriented(hole.Mesh) == true) { hole.Mesh.ReverseOrientation(); } editor.AppendMesh(hole.Mesh, ResultMesh.AllocateTriangleGroup()); } } } else { ResultMesh = meshIn; } base.complete_update(); } catch (Exception e) { PostOnOperatorException(e); ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe()); base.complete_update(); } }
public virtual void Update() { base.begin_update(); int start_timestamp = this.CurrentInputTimestamp; if (MeshSource == null) { throw new Exception("SeparateSolidsOp: must set valid MeshSource to compute!"); } ResultMeshes = null; try { DMesh3 meshIn = new DMesh3(MeshSource.GetDMeshUnsafe()); MeshConnectedComponents comp = new MeshConnectedComponents(meshIn); comp.FindConnectedT(); DSubmesh3Set subMeshes = new DSubmesh3Set(meshIn, comp); List <DMesh3> curMeshes = new List <DMesh3>(); foreach (var submesh in subMeshes) { curMeshes.Add(submesh.SubMesh); } if (group_nested_shells) { MeshSpatialSort sort = new MeshSpatialSort(); foreach (var mesh in curMeshes) { sort.AddMesh(mesh, mesh); } sort.Sort(); curMeshes.Clear(); foreach (var solid in sort.Solids) { DMesh3 outer = solid.Outer.Mesh; if (orient_nested_shells && is_outward_oriented(outer) == false) { outer.ReverseOrientation(); } foreach (var hole in solid.Cavities) { if (orient_nested_shells && hole.Mesh.CachedIsClosed && is_outward_oriented(hole.Mesh) == true) { hole.Mesh.ReverseOrientation(); } MeshEditor.Append(outer, hole.Mesh); } curMeshes.Add(outer); } } ResultMeshes = curMeshes; base.complete_update(); } catch (Exception) { ResultMeshes = new List <DMesh3>(); base.complete_update(); throw; } }
protected virtual DMesh3 compute_wrap() { DMesh3 meshIn = MeshSource.GetDMeshUnsafe(); double unsigned_offset = Math.Abs(distance); if (cached_sdf == null || unsigned_offset > cached_sdf_max_offset || grid_cell_size != cached_sdf.CellSize) { DMeshAABBTree3 use_spatial = input_spatial; CachingMeshSDF sdf = new CachingMeshSDF(meshIn, grid_cell_size, use_spatial); sdf.MaxOffsetDistance = 2 * (float)unsigned_offset; sdf.CancelF = is_invalidated; sdf.Initialize(); if (is_invalidated()) { return(null); } cached_sdf = sdf; cached_sdf_max_offset = unsigned_offset; cached_sdf_bounds = meshIn.CachedBounds; } var grid_iso = new CachingMeshSDFImplicit(cached_sdf); // currently MCPro-Continuation does not work w/ non-zero // isovalues, so we have to shift our target offset externally var iso = new ImplicitOffset3d() { A = grid_iso, Offset = distance }; MarchingCubesPro c = new MarchingCubesPro(); c.Implicit = iso; c.Bounds = cached_sdf_bounds; c.CubeSize = mesh_cell_size; c.Bounds.Expand(distance + 3 * c.CubeSize); c.CancelF = is_invalidated; c.GenerateContinuation(offset_seeds(meshIn, distance)); if (is_invalidated()) { return(null); } Reducer r = new Reducer(c.Mesh); r.FastCollapsePass(c.CubeSize * 0.5, 3, true); if (is_invalidated()) { return(null); } if (min_component_volume > 0) { MeshEditor.RemoveSmallComponents(c.Mesh, min_component_volume, min_component_volume); } if (is_invalidated()) { return(null); } DMesh3 offsetMesh = c.Mesh; MeshConnectedComponents comp = new MeshConnectedComponents(offsetMesh); comp.FindConnectedT(); if (is_invalidated()) { return(null); } DSubmesh3Set subMeshes = new DSubmesh3Set(offsetMesh, comp); if (is_invalidated()) { return(null); } MeshSpatialSort sort = new MeshSpatialSort(); foreach (var subMesh in subMeshes) { sort.AddMesh(subMesh.SubMesh, subMesh); } sort.Sort(); if (is_invalidated()) { return(null); } DMesh3 outerMesh = new DMesh3(); foreach (var solid in sort.Solids) { DMesh3 outer = solid.Outer.Mesh; //if (is_outward_oriented(outer) == false) // outer.ReverseOrientation(); MeshEditor.Append(outerMesh, outer); } if (is_invalidated()) { return(null); } return(compute_inset(outerMesh)); }