Example #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <DMesh3_goo> goo = new List <DMesh3_goo>();
            int numCells          = 64;

            DA.GetDataList(0, goo);
            DA.GetData(1, ref numCells);

            ImplicitNaryIntersection3d diff2 = new ImplicitNaryIntersection3d();

            diff2.Children = goo.Select(x => g3ghUtil.MeshToImplicit(x.Value, numCells, 0.2f)).ToList();

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = diff2;
            c.RootMode      = g3.MarchingCubes.RootfindingModes.Bisection;
            c.RootModeSteps = 5;
            c.Bounds        = diff2.Bounds();
            c.CubeSize      = c.Bounds.MaxDim / numCells;
            c.Bounds.Expand(3 * c.CubeSize);
            c.Generate();

            MeshNormals.QuickCompute(c.Mesh);

            DA.SetData(0, c.Mesh);
        }
        protected virtual DMesh3 compute_wrap()
        {
            cache_input_sdfs();
            if (is_invalidated())
            {
                return(null);
            }

            BoundedImplicitFunction3d iso = null;

            if (op_type == OpTypes.Union)
            {
                iso = new ImplicitNaryUnion3d()
                {
                    Children = new List <BoundedImplicitFunction3d>(cached_isos)
                };
            }
            else if (op_type == OpTypes.Intersection)
            {
                iso = new ImplicitNaryIntersection3d()
                {
                    Children = new List <BoundedImplicitFunction3d>(cached_isos)
                };
            }
            else if (op_type == OpTypes.Difference)
            {
                iso = new ImplicitNaryDifference3d()
                {
                    A    = cached_isos[0],
                    BSet = new List <BoundedImplicitFunction3d>(cached_isos.Skip(1))
                };
            }

            MarchingCubes c = new MarchingCubes();

            c.Implicit = iso;
            c.IsoValue = 0;
            c.Bounds   = iso.Bounds();
            c.CubeSize = mesh_cell_size;
            c.Bounds.Expand(3 * c.CubeSize);
            c.RootMode      = MarchingCubes.RootfindingModes.Bisection;
            c.RootModeSteps = 5;

            c.CancelF = is_invalidated;
            c.Generate();
            if (is_invalidated())
            {
                return(null);
            }

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

            return(c.Mesh);
        }