public static void test_1() { DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); int num_cells = 64; double cell_size = mesh.CachedBounds.MaxDim / num_cells; MeshSignedDistanceGrid sdf = new MeshSignedDistanceGrid(mesh, cell_size) { ExactBandWidth = 5 }; sdf.Compute(); var iso = new DenseGridTrilinearImplicit(sdf.Grid, sdf.GridOrigin, sdf.CellSize); var skel_field = new DistanceFieldToSkeletalField() { DistanceField = iso, FalloffDistance = 5 * cell_size }; var offset_field = new ImplicitOffset3d() { A = skel_field, Offset = DistanceFieldToSkeletalField.ZeroIsocontour }; MarchingCubesPro c = new MarchingCubesPro(); //c.Implicit = iso; //c.Implicit = skel_field; //c.IsoValue = DistanceFieldToSkeletalField.ZeroIsocontour; c.Implicit = offset_field; c.Bounds = mesh.CachedBounds; c.CubeSize = c.Bounds.MaxDim / 128; c.Bounds.Expand(3 * c.CubeSize); //c.RootMode = MarchingCubesPro.RootfindingModes.Bisection; c.ParallelCompute = false; c.Generate(); //c.GenerateContinuation(mesh.Vertices()); TestUtil.WriteTestOutputMesh(c.Mesh, "mcpro_output.obj"); }
public static void test_2() { DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); DMeshAABBTree3 spatial = new DMeshAABBTree3(mesh, true); int num_cells = 64; double cell_size = mesh.CachedBounds.MaxDim / num_cells; CachingMeshSDF sdf = new CachingMeshSDF(mesh, cell_size, spatial); sdf.MaxOffsetDistance = (float)(4 * cell_size); sdf.Initialize(); gParallel.ForEach(sdf.Grid.Indices(), (idx) => { sdf.GetValue(idx); }); CachingMeshSDFImplicit sdf_iso = new CachingMeshSDFImplicit(sdf); var skel_field = new DistanceFieldToSkeletalField() { DistanceField = sdf_iso, FalloffDistance = 5 * cell_size }; MarchingCubesPro c = new MarchingCubesPro(); //c.Implicit = sdf_iso; c.Implicit = skel_field; //c.IsoValue = DistanceFieldToSkeletalField.ZeroIsocontour; c.Bounds = mesh.CachedBounds; c.CubeSize = c.Bounds.MaxDim / 128; c.Bounds.Expand(3 * c.CubeSize); c.RootMode = MarchingCubesPro.RootfindingModes.Bisection; c.ParallelCompute = false; c.Generate(); //c.GenerateContinuation(mesh.Vertices()); c.Mesh.ReverseOrientation(); TestUtil.WriteTestOutputMesh(c.Mesh, "mcpro_output.obj"); }
protected virtual DMesh3 compute_blend_analytic() { bool profile = true; LocalProfiler p = null; if (profile) { p = new LocalProfiler(); p.Start("bvtree"); } compute_cache_lazy_sdfs(); if (is_invalidated()) { return(null); } if (profile) { p.Stop("bvtree"); p.Start("mc"); } List <BoundedImplicitFunction3d> inputs = new List <BoundedImplicitFunction3d>(); foreach (CachingMeshSDF sdf in cached_lazy_sdfs) { var skel_field = new DistanceFieldToSkeletalField() { DistanceField = new CachingMeshSDFImplicit(sdf), FalloffDistance = blend_falloff }; inputs.Add(skel_field); } SkeletalRicciNaryBlend3d blend = new SkeletalRicciNaryBlend3d() { Children = inputs, BlendPower = this.blend_power, FieldShift = -DistanceFieldToSkeletalField.ZeroIsocontour }; AxisAlignedBox3d use_bounds = source_bounds; source_bounds.Expand(blend_falloff); MarchingCubesPro c = lazy_mc; c.Implicit = blend; //c.IsoValue = DistanceFieldToSkeletalField.ZeroIsocontour; c.Bounds = use_bounds; c.CubeSize = mesh_cell_size; c.Bounds.Expand(3 * c.CubeSize); c.RootMode = MarchingCubesPro.RootfindingModes.LerpSteps; c.RootModeSteps = 3; //c.ParallelCompute = false; c.CancelF = is_invalidated; c.GenerateContinuation(input_mesh_seeds()); if (is_invalidated()) { return(null); } if (profile) { p.Stop("mc"); p.Start("reduce"); } c.Mesh.ReverseOrientation(); Reducer r = new Reducer(c.Mesh); r.FastCollapsePass(c.CubeSize / 2, 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); } if (profile) { p.Stop("reduce"); #if G3_USING_UNITY UnityEngine.Debug.Log("ANALYTIC BLEND TIME: " + p.AllTimes()); #endif } return(c.Mesh); }
protected virtual DMesh3 compute_blend_bounded() { bool profile = true; LocalProfiler p = null; if (profile) { p = new LocalProfiler(); p.Start("sdf"); } cache_input_sdfs_bounded(); if (is_invalidated()) { return(null); } if (profile) { p.Stop("sdf"); p.Start("mc"); } List <BoundedImplicitFunction3d> inputs = new List <BoundedImplicitFunction3d>(); foreach (var sdf in cached_bounded_sdfs) { var dist_field = new DenseGridTrilinearImplicit(sdf); var skel_field = new DistanceFieldToSkeletalField() { DistanceField = dist_field, FalloffDistance = blend_falloff }; inputs.Add(skel_field); } SkeletalRicciNaryBlend3d blend = new SkeletalRicciNaryBlend3d() { Children = inputs, BlendPower = this.blend_power }; MarchingCubesPro c = new MarchingCubesPro(); c.Implicit = blend; c.IsoValue = DistanceFieldToSkeletalField.ZeroIsocontour; c.Bounds = blend.Bounds(); c.CubeSize = mesh_cell_size; c.Bounds.Expand(3 * c.CubeSize); c.RootMode = MarchingCubesPro.RootfindingModes.LerpSteps; c.RootModeSteps = 3; c.CancelF = is_invalidated; //c.Generate(); c.GenerateContinuation(input_mesh_seeds()); if (is_invalidated()) { return(null); } if (profile) { p.Stop("mc"); p.Start("reduce"); } c.Mesh.ReverseOrientation(); Reducer r = new Reducer(c.Mesh); r.FastCollapsePass(c.CubeSize / 2, 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); } if (profile) { p.Stop("reduce"); #if G3_USING_UNITY UnityEngine.Debug.Log("BLEND TIME: " + p.AllTimes()); #endif } return(c.Mesh); }