Esempio n. 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);

            ImplicitNaryUnion3d diff2 = new ImplicitNaryUnion3d();

            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);
        }
Esempio n. 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = modes.ToString() + " : " + steps.ToString() + " Steps";

            Grid3f_goo goo = null;
            double     val = 0;
            double     exp = 0;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref val);
            DA.GetData(2, ref exp);

            var iso = goo.Value;

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = iso;
            c.Bounds        = iso.Bounds();
            c.RootMode      = modes;
            c.RootModeSteps = steps;
            c.CubeSize      = iso.CellSize;
            c.Bounds.Expand(3 * c.CubeSize);
            c.IsoValue = val;
            c.Generate();


            DMesh3 outputMesh = c.Mesh;
            bool   isValid    = outputMesh.CheckValidity();

            if (!isValid)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh seems to be corrupted. Please check...");
            }

            DA.SetData(0, outputMesh);
        }
Esempio n. 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo        gooA = null;
            List <DMesh3_goo> gooB = new List <DMesh3_goo>();
            int numCells           = 64;

            DA.GetData(0, ref gooA);
            DA.GetDataList(1, gooB);
            DA.GetData(2, ref numCells);

            DMesh3        A = new DMesh3(gooA.Value);
            List <DMesh3> B = gooB.Select(x => x.Value).ToList();

            ImplicitNaryDifference3d diff2 = new ImplicitNaryDifference3d();

            diff2.A    = g3ghUtil.MeshToImplicit(A, numCells, 0.2f);
            diff2.BSet = B.Select(x => g3ghUtil.MeshToImplicit(x, 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);
        }
        void generate_mesh(DenseGrid3f supportGrid, DenseGridTrilinearImplicit distanceField)
        {
            DenseGridTrilinearImplicit volume = new DenseGridTrilinearImplicit(
                supportGrid, GridOrigin, CellSize);
            BoundedImplicitFunction3d inputF = volume;

            if (SubtractMesh)
            {
                BoundedImplicitFunction3d sub = distanceField;
                if (SubtractMeshOffset > 0)
                {
                    sub = new ImplicitOffset3d()
                    {
                        A = distanceField, Offset = SubtractMeshOffset
                    }
                }
                ;
                ImplicitDifference3d subtract = new ImplicitDifference3d()
                {
                    A = volume, B = sub
                };
                inputF = subtract;
            }

            ImplicitHalfSpace3d cutPlane = new ImplicitHalfSpace3d()
            {
                Origin = Vector3d.Zero, Normal = Vector3d.AxisY
            };
            ImplicitDifference3d cut = new ImplicitDifference3d()
            {
                A = inputF, B = cutPlane
            };

            MarchingCubes mc = new MarchingCubes()
            {
                Implicit = cut, Bounds = grid_bounds, CubeSize = CellSize
            };

            mc.Bounds.Min.y  = -2 * mc.CubeSize;
            mc.Bounds.Min.x -= 2 * mc.CubeSize; mc.Bounds.Min.z -= 2 * mc.CubeSize;
            mc.Bounds.Max.x += 2 * mc.CubeSize; mc.Bounds.Max.z += 2 * mc.CubeSize;
            mc.Generate();

            SupportMesh = mc.Mesh;
        }
    }
Esempio n. 5
0
        public virtual void Generate()
        {
            AxisAlignedBox3d graphBox = Graph.CachedBounds;

            graphBox.Expand(2 * PostRadius);

            double cellSize = (SamplerCellSizeHint == 0) ? (PostRadius / 5) : SamplerCellSizeHint;
            ImplicitFieldSampler3d sampler = new ImplicitFieldSampler3d(graphBox, cellSize);

            ActualCellSize = cellSize;

            // sample segments into graph
            ImplicitLine3d line = new ImplicitLine3d()
            {
                Radius = PostRadius
            };

            foreach (int eid in Graph.EdgeIndices())
            {
                Index2i  ev = Graph.GetEdgeV(eid);
                Vector3d v0 = Graph.GetVertex(ev.a);
                Vector3d v1 = Graph.GetVertex(ev.b);
                double   r  = PostRadius;

                int upper_vid = (v0.y > v1.y) ? ev.a : ev.b;
                if (TipVertices.Contains(upper_vid))
                {
                    r = TipRadius;
                }

                line.Segment = new Segment3d(v0, v1);
                line.Radius  = r;
                sampler.Sample(line, line.Radius / 2);
            }

            foreach (int vid in GroundVertices)
            {
                Vector3d v = Graph.GetVertex(vid);
                sampler.Sample(new ImplicitSphere3d()
                {
                    Origin = v - (PostRadius / 2) * Vector3d.AxisY, Radius = GroundRadius
                });
            }


            ImplicitHalfSpace3d cutPlane = new ImplicitHalfSpace3d()
            {
                Origin = Vector3d.Zero, Normal = Vector3d.AxisY
            };
            ImplicitDifference3d cut = new ImplicitDifference3d()
            {
                A = sampler.ToImplicit(), B = cutPlane
            };

            MarchingCubes mc = new MarchingCubes()
            {
                Implicit = cut, Bounds = graphBox, CubeSize = PostRadius / 3
            };

            mc.Bounds.Min.y  = -2 * mc.CubeSize;
            mc.Bounds.Min.x -= 2 * mc.CubeSize; mc.Bounds.Min.z -= 2 * mc.CubeSize;
            mc.Bounds.Max.x += 2 * mc.CubeSize; mc.Bounds.Max.z += 2 * mc.CubeSize;
            mc.CancelF       = this.Cancelled;
            mc.Generate();

            ResultMesh = mc.Mesh;
        }
Esempio n. 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo             = null;
            double     lattice_radius  = 0.05;
            double     lattice_spacing = 0.4;
            double     shell_thickness = 0.05;
            int        mesh_resolution = 64;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref lattice_radius);
            DA.GetData(2, ref lattice_spacing);
            DA.GetData(3, ref shell_thickness);
            DA.GetData(4, ref mesh_resolution);

            DMesh3 mesh = new DMesh3(goo.Value);

            var              shellMeshImplicit = g3ghUtil.MeshToImplicit(mesh, 128, shell_thickness);
            double           max_dim           = mesh.CachedBounds.MaxDim;
            AxisAlignedBox3d bounds            = new AxisAlignedBox3d(mesh.CachedBounds.Center, max_dim / 2);

            bounds.Expand(2 * lattice_spacing);
            AxisAlignedBox2d element   = new AxisAlignedBox2d(lattice_spacing);
            AxisAlignedBox2d bounds_xy = new AxisAlignedBox2d(bounds.Min.xy, bounds.Max.xy);
            AxisAlignedBox2d bounds_xz = new AxisAlignedBox2d(bounds.Min.xz, bounds.Max.xz);
            AxisAlignedBox2d bounds_yz = new AxisAlignedBox2d(bounds.Min.yz, bounds.Max.yz);

            List <BoundedImplicitFunction3d> Tiling = new List <BoundedImplicitFunction3d>();

            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_xy, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(uv.x, uv.y, bounds.Min.z), new g3.Vector3d(uv.x, uv.y, bounds.Max.z));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }
            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_xz, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(uv.x, bounds.Min.y, uv.y), new g3.Vector3d(uv.x, bounds.Max.y, uv.y));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }
            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_yz, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(bounds.Min.x, uv.x, uv.y), new g3.Vector3d(bounds.Max.x, uv.x, uv.y));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }

            ImplicitNaryUnion3d lattice = new ImplicitNaryUnion3d()
            {
                Children = Tiling
            };
            ImplicitIntersection3d lattice_clipped = new ImplicitIntersection3d()
            {
                A = lattice, B = shellMeshImplicit
            };

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = lattice_clipped;
            c.RootMode      = g3.MarchingCubes.RootfindingModes.LerpSteps;
            c.RootModeSteps = 5;
            c.Bounds        = lattice_clipped.Bounds();
            c.CubeSize      = c.Bounds.MaxDim / mesh_resolution;
            c.Bounds.Expand(3 * c.CubeSize);
            c.Generate();
            MeshNormals.QuickCompute(c.Mesh);


            DA.SetData(0, c.Mesh);
        }