예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     w        = 1;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref w);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value, true);

            LaplacianMeshDeformer deformer = new LaplacianMeshDeformer(dMsh_copy);

            foreach (int vid in dMsh_copy.VertexIndices())
            {
                if (deformer.IsConstrained(vid) == false)
                {
                    deformer.SetConstraint(vid, dMsh_copy.GetVertex(vid), w);
                }
            }

            bool success = deformer.SolveAndUpdateMesh();
            bool isValid = dMsh_copy.CheckValidity();

            if (!success)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Laplacian deform seems to have failed. Please check...");
            }

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

            DA.SetData(0, dMsh_copy);
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            List <Point3d>  vertices = new List <Point3d>();
            List <MeshFace> faces    = new List <MeshFace>();
            List <Color>    cols     = new List <Color>();

            List <int> v_i = new List <int>();
            List <int> f_i = new List <int>();

            foreach (var ind in mesh.VertexIndices())
            {
                v_i.Add(ind);
                vertices.Add(mesh.GetVertex(ind).ToRhinoPt());
                var col = mesh.GetVertexColor(ind);
                cols.Add(Color.FromArgb((int)(col.x * 255), (int)(col.y * 255), (int)(col.z * 255)));
            }
            foreach (var ind in mesh.TriangleIndices())
            {
                f_i.Add(ind);
                var tri = mesh.GetTriangle(ind);
                faces.Add(new MeshFace(tri.a, tri.b, tri.c));
            }

            DA.SetDataList(0, v_i);
            DA.SetDataList(1, vertices);
            DA.SetDataList(2, f_i);
            DA.SetDataList(3, faces);
            DA.SetDataList(4, cols);
        }
예제 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            if (RemoveDupTris)
            {
                gs.RemoveDuplicateTriangles removeDuplicate = new gs.RemoveDuplicateTriangles(mesh);
                removeDuplicate.Apply();
                mesh = removeDuplicate.Mesh;
            }

            if (RemoveOcclTris)
            {
                gs.RemoveOccludedTriangles removeOccluded = new gs.RemoveOccludedTriangles(mesh);
                removeOccluded.Apply();
                mesh = removeOccluded.Mesh;
            }

            if (RemoveUnusedVerts)
            {
                MeshEditor.RemoveUnusedVertices(mesh);
            }

            if (RemoveFinTris)
            {
                MeshEditor.RemoveFinTriangles(mesh);
            }

            DA.SetData(0, mesh);
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;
            DMesh3_goo cut = null;
            bool       cap = false;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref cut);
            DA.GetData(2, ref cap);

            DMesh3 ms = new DMesh3(goo.Value);

            g3.MeshMeshCut cutter = new g3.MeshMeshCut();

            cutter.Target  = new DMesh3(goo.Value);
            cutter.CutMesh = new DMesh3(cut.Value);

            cutter.Compute();

            if (cap)
            {
                cutter.RemoveContained();
            }

            DA.SetData(0, cutter.CutMesh);
        }
예제 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = type.ToString();

            DMesh3_goo goo  = null;
            double     eLen = 1;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref eLen);

            DMesh3 msh = new DMesh3(goo.Value);

            DMesh3            outMesh = msh;
            MeshBoundaryLoops loops   = new MeshBoundaryLoops(outMesh, true);

            var lps = loops.Loops;

            bool hasLoops = (lps.Count > 0);
            int  iter     = 0;

            while (hasLoops)
            {
                EdgeLoop loop = lps[0];

                switch (type)
                {
                case HoleFillerType.Planar:
                    outMesh = HoleFillMethods.PlanarFill(outMesh, loop, eLen);
                    break;

                case HoleFillerType.Smooth:
                    outMesh = HoleFillMethods.SmoothFill(outMesh, loop, eLen);
                    break;

                case HoleFillerType.Minimal:
                    outMesh = HoleFillMethods.MinimalFill(outMesh, loop, eLen);
                    break;

                default:
                    outMesh = HoleFillMethods.PlanarFill(outMesh, loop, eLen);
                    break;
                }

                loops = new MeshBoundaryLoops(outMesh, true);
                lps   = loops.Loops;

                hasLoops = (lps.Count > 0);

                iter++;
                if (iter > 500)
                {
                    break;
                }
            }

            this.Message += "\n" + iter.ToString() + " holes filled.";

            DA.SetData(0, outMesh);
        }
예제 #7
0
파일: CompactMesh.cs 프로젝트: joelhi/g3-gh
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DA.SetData(0, new DMesh3(goo.Value, true));
        }
예제 #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dM3_goo = null;

            DA.GetData(0, ref dM3_goo);

            var dM3 = dM3_goo.Value;

            DA.SetData(0, dM3.ToRhino());
        }
예제 #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            MeshBoundaryLoops bounds = new MeshBoundaryLoops(mesh, true);

            DA.SetDataList(0, bounds.Loops);
        }
예제 #10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 msh = new DMesh3(goo.Value);

            var volArea = MeshMeasurements.VolumeArea(msh, msh.TriangleIndices(), msh.GetVertex);

            DA.SetData(0, volArea[1]);
            DA.SetData(1, volArea[0]);
        }
예제 #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            MeshQueries.EdgeLengthStats(mesh, out double min, out double max, out double avg);

            DA.SetData(0, max);
            DA.SetData(1, min);
            DA.SetData(2, avg);
        }
예제 #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);


            gs.MeshAutoRepair repair = new gs.MeshAutoRepair(mesh);
            repair.Apply();


            DA.SetData(0, repair.Mesh);
        }
예제 #13
0
파일: MoveDMesh3.cs 프로젝트: joelhi/g3-gh
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;

            Rhino.Geometry.Vector3d vec = new Rhino.Geometry.Vector3d(0, 0, 0);

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref vec);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            MeshTransforms.Translate(dMsh_copy, vec.ToVec3d());

            DA.SetData(0, dMsh_copy);
        }
예제 #14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     targetL  = 0;
            int        numI     = 0;
            bool       fixB     = false;
            bool       projBack = false;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref targetL);
            DA.GetData(2, ref numI);
            DA.GetData(3, ref fixB);
            DA.GetData(4, ref projBack);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            Remesher r = new Remesher(dMsh_copy);

            r.PreventNormalFlips = true;
            r.SetTargetEdgeLength(targetL);
            r.SmoothSpeedT = 0.5;

            if (fixB)
            {
                MeshConstraintUtil.FixAllBoundaryEdges(r);
            }

            if (projBack)
            {
                r.SetProjectionTarget(MeshProjectionTarget.Auto(dMsh_goo.Value));
            }

            for (int k = 0; k < numI; ++k)
            {
                r.BasicRemeshPass();
            }

            bool isValid = dMsh_copy.CheckValidity();

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

            DA.SetData(0, dMsh_copy);
        }
예제 #15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            List <Rhino.Geometry.Vector3d> vecs = new List <Rhino.Geometry.Vector3d>();

            foreach (var ind in mesh.TriangleIndices())
            {
                vecs.Add(mesh.GetTriNormal(ind).ToRhinoVec());
            }

            DA.SetDataList(0, vecs);
        }
예제 #16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     rot      = 0;
            Plane      plane    = Plane.WorldXY;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref rot);
            DA.GetData(2, ref plane);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            Quaterniond quat = new Quaterniond(plane.ZAxis.ToVec3d(), rot);

            MeshTransforms.Rotate(dMsh_copy, plane.Origin.ToVec3d(), quat);

            DA.SetData(0, dMsh_copy);
        }
예제 #17
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;

            Rhino.Geometry.Vector3d sFact = new Rhino.Geometry.Vector3d(1, 1, 1);
            Point3d origin = new Point3d(0, 0, 0);

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref sFact);
            DA.GetData(2, ref origin);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            MeshTransforms.Scale(dMsh_copy, sFact.ToVec3d(), origin.ToVec3d());



            DA.SetData(0, dMsh_copy);
        }
예제 #18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int        num_cells = 128;
            DMesh3_goo dMsh_goo  = null;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref num_cells);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);
            double cell_size = dMsh_copy.CachedBounds.MaxDim / num_cells;

            MeshSignedDistanceGrid sdf = new MeshSignedDistanceGrid(dMsh_copy, cell_size);

            sdf.Compute();

            var        iso = new DenseGridTrilinearImplicit(sdf.Grid, sdf.GridOrigin, sdf.CellSize);
            Grid3f_goo goo = iso;

            DA.SetData(0, goo);
        }
예제 #19
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = "." + type.ToString();

            DMesh3_goo goo  = null;
            string     path = "";
            string     file = "";

            DA.GetData(0, ref goo);
            DA.GetData(1, ref path);
            DA.GetData(2, ref file);
            DMesh3 mesh = new DMesh3(goo.Value);


            IOWriteResult result = StandardMeshWriter.WriteFile(Path.Combine(path, file) + "." + type.ToString(), new List <WriteMesh>()
            {
                new WriteMesh(mesh)
            }, WriteOptions.Defaults);

            DA.SetData(0, Path.Combine(path, file) + "." + type.ToString());
        }
예제 #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo   = null;
            double     angle = 30;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref angle);

            DMesh3 mesh = new DMesh3(goo.Value);

            MeshTopology topology = new MeshTopology(mesh);

            topology.CreaseAngle = angle;

            topology.Compute();

            var e = topology.CreaseEdges;

            DA.SetDataList(0, topology.Spans);
            DA.SetDataList(1, topology.Loops);
        }
예제 #21
0
파일: Voxelize.cs 프로젝트: joelhi/g3-gh
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int        num_cells = 128;
            DMesh3_goo dMsh_goo  = null;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref num_cells);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);
            double cell_size = dMsh_copy.CachedBounds.MaxDim / num_cells;

            DMeshAABBTree3 spatial = new DMeshAABBTree3(dMsh_copy, autoBuild: true);

            AxisAlignedBox3d  bounds   = dMsh_copy.CachedBounds;
            double            cellsize = bounds.MaxDim / num_cells;
            ShiftGridIndexer3 indexer  = new ShiftGridIndexer3(bounds.Min, cellsize);

            Bitmap3 bmp = new Bitmap3(new Vector3i(num_cells, num_cells, num_cells));

            foreach (Vector3i idx in bmp.Indices())
            {
                g3.Vector3d v = indexer.FromGrid(idx);
                bmp.Set(idx, spatial.IsInside(v));
            }

            VoxelSurfaceGenerator voxGen = new VoxelSurfaceGenerator();

            voxGen.Voxels = bmp;
            voxGen.Generate();
            DMesh3 voxMesh = voxGen.Meshes[0];

            var vecSize = dMsh_copy.CachedBounds.Extents;
            var box     = dMsh_copy.GetBounds();

            // Scale voxel mesh
            //MeshTransforms.Scale(voxMesh,)

            DA.SetData(0, voxMesh);
        }
예제 #22
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo   = null;
            Plane      plane = new Plane();
            bool       cap   = false;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref plane);
            DA.GetData(2, ref cap);

            DMesh3 ms = new DMesh3(goo.Value);

            g3.MeshPlaneCut cutter = new g3.MeshPlaneCut(ms, plane.Origin.ToVec3d(), plane.ZAxis.ToVec3d());
            cutter.Cut();

            if (cap)
            {
                cutter.FillHoles();
            }

            DA.SetData(0, cutter.Mesh);
        }
예제 #23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = Type.ToString();

            DMesh3_goo   goo      = null;
            EdgeLoop_goo loop_goo = null;
            double       eLen     = 1;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref loop_goo);
            DA.GetData(2, ref eLen);

            DMesh3   msh  = new DMesh3(goo.Value);
            EdgeLoop loop = new EdgeLoop(loop_goo.Value);

            DMesh3 outMesh;

            switch (Type)
            {
            case HoleFillerType.Planar:
                outMesh = HoleFillMethods.PlanarFill(msh, loop, eLen);
                break;

            case HoleFillerType.Smooth:
                outMesh = HoleFillMethods.SmoothFill(msh, loop, eLen);
                break;

            case HoleFillerType.Minimal:
                outMesh = HoleFillMethods.MinimalFill(msh, loop, eLen);
                break;

            default:
                outMesh = HoleFillMethods.PlanarFill(msh, loop, eLen);
                break;
            }

            DA.SetData(0, outMesh);
        }
예제 #24
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            int        numF     = 0;
            bool       fixB     = false;
            bool       projBack = false;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref numF);
            DA.GetData(2, ref fixB);
            DA.GetData(3, ref projBack);

            DMesh3  dMsh_copy = new DMesh3(dMsh_goo.Value);
            Reducer r         = new Reducer(dMsh_copy);

            if (fixB)
            {
                r.SetExternalConstraints(new MeshConstraints());
                MeshConstraintUtil.PreserveBoundaryLoops(r.Constraints, dMsh_copy);
            }
            if (projBack)
            {
                DMeshAABBTree3 tree = new DMeshAABBTree3(new DMesh3(dMsh_copy));
                tree.Build();
                MeshProjectionTarget target = new MeshProjectionTarget(tree.Mesh, tree);
                r.SetProjectionTarget(target);
            }

            r.ReduceToTriangleCount(numF);
            bool isValid = dMsh_copy.CheckValidity();

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

            DA.SetData(0, dMsh_copy);
        }
예제 #25
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo = null;

            DA.GetData(0, ref goo);

            DMesh3 mesh = new DMesh3(goo.Value);

            List <Rhino.Geometry.Vector3d> vecs = new List <Rhino.Geometry.Vector3d>();

            if (!mesh.HasVertexNormals)
            {
                var normals = new MeshNormals(mesh);
                normals.Compute();
            }

            foreach (var ind in mesh.VertexIndices())
            {
                vecs.Add(mesh.GetVertexNormal(ind).ToRhinoVec());
            }

            DA.SetDataList(0, vecs);
        }
예제 #26
0
파일: ExtrudeMesh.cs 프로젝트: joelhi/g3-gh
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo  = null;
            double     dist = 1;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref dist);

            DMesh3 mesh = new DMesh3(goo.Value);

            MeshExtrudeMesh extruder = new MeshExtrudeMesh(mesh);

            extruder.ExtrudedPositionF = (pos, normal, idx) => { return(pos + normal.Multiply(dist)); };

            if (dist < 0)
            {
                extruder.IsPositiveOffset = false;
            }

            extruder.Extrude();

            DA.SetData(0, extruder.Mesh);
        }
예제 #27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo   goo  = null;
            List <Color> cols = new List <Color>();

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

            DMesh3 msh = new DMesh3(goo.Value);

            msh.EnableVertexColors(new g3.Vector3f(0.5, 0.5, 0.5));

            var indices = msh.VertexIndices();

            if (cols.Count == msh.VertexCount)
            {
                int counter = 0;
                foreach (int i in indices)
                {
                    msh.SetVertexColor(i, new g3.Vector3f((float)cols[counter].R / 255, (float)cols[counter].G / 255, (float)cols[counter].B / 255));
                    counter++;
                }
            }
            else if (cols.Count == 1)
            {
                foreach (int i in indices)
                {
                    msh.SetVertexColor(i, new g3.Vector3f((float)cols[0].R / 255, (float)cols[0].G / 255, (float)cols[0].B / 255));
                }
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of colours either need to be that same amount as number of vertices in mesh, or a single one");
            }

            DA.SetData(0, msh);
        }
예제 #28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     targetL  = 0;
            bool       fixB     = false;
            bool       projBack = false;
            bool       run      = false;
            bool       reset    = false;
            int        maxIter  = 0;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref targetL);
            DA.GetData(3, ref fixB);
            DA.GetData(4, ref projBack);
            DA.GetData(2, ref maxIter);
            DA.GetData(5, ref run);
            DA.GetData(6, ref reset);

            if (passes >= maxIter)
            {
                run = false;
            }


            if (r is null || reset)
            {
                dMsh_copy = new DMesh3(dMsh_goo.Value);

                r = new Remesher(dMsh_copy);
                r.PreventNormalFlips = true;
                r.SetTargetEdgeLength(targetL);
                r.SmoothSpeedT = 0.5;

                passes = 0;

                if (fixB)
                {
                    MeshConstraintUtil.FixAllBoundaryEdges(r);
                }

                if (projBack)
                {
                    r.SetProjectionTarget(MeshProjectionTarget.Auto(dMsh_goo.Value));
                }
            }

            if (run && !reset)
            {
                r.BasicRemeshPass();
                passes++;
                Update();
            }

            bool isValid = dMsh_copy.CheckValidity();

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

            this.Message = "Pass: " + passes.ToString();

            DA.SetData(0, dMsh_copy);
        }
예제 #29
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);
        }
예제 #30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo     dMsh_goo = null;
            List <Point3d> points   = new List <Point3d>();
            double         targetL  = 0;
            int            numI     = 0;
            int            fixB     = 0;
            bool           projBack = false;
            double         smooth   = 0;

            DA.GetData(0, ref dMsh_goo);
            DA.GetDataList(2, points);
            DA.GetData(1, ref targetL);
            DA.GetData(6, ref numI);
            DA.GetData(3, ref fixB);
            DA.GetData(5, ref projBack);
            DA.GetData(7, ref smooth);

            List <EdgeConstraint_goo> edgeC = new List <EdgeConstraint_goo>();

            DA.GetDataList(4, edgeC);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            Remesher r = new Remesher(dMsh_copy);

            r.PreventNormalFlips = true;
            r.SetTargetEdgeLength(targetL);
            r.SmoothSpeedT = smooth;


            if (fixB == 2)
            {
                MeshConstraintUtil.FixAllBoundaryEdges(r);
            }
            else if (fixB == 1)
            {
                MeshConstraintUtil.PreserveBoundaryLoops(r);
            }
            else
            {
                r.SetExternalConstraints(new MeshConstraints());
            }

            if (edgeC.Count > 0)
            {
                for (int i = 0; i < edgeC.Count; i++)
                {
                    var tempEC = edgeC[i];

                    IProjectionTarget target = new DCurveProjectionTarget(tempEC.crv);

                    for (int j = 0; j < tempEC.edges.Length; j++)
                    {
                        tempEC.constraint.Target = target;
                        r.Constraints.SetOrUpdateEdgeConstraint(tempEC.edges[j], tempEC.constraint);
                    }

                    for (int j = 0; j < tempEC.vertices.Length; j++)
                    {
                        if (tempEC.PinVerts)
                        {
                            r.Constraints.SetOrUpdateVertexConstraint(tempEC.vertices[j], VertexConstraint.Pinned);
                        }
                        else
                        {
                            r.Constraints.SetOrUpdateVertexConstraint(tempEC.vertices[j], new VertexConstraint(target));
                        }
                    }
                }
            }

            if (points.Count > 0)
            {
                DMeshAABBTree3 mshAABB = new DMeshAABBTree3(dMsh_copy, true);

                var v3pts = points.Select(pt => pt.ToVec3d());

                foreach (var p in v3pts)
                {
                    int id = mshAABB.FindNearestVertex(p, 0.1);

                    if (id != -1)
                    {
                        r.Constraints.SetOrUpdateVertexConstraint(id, VertexConstraint.Pinned);
                    }
                }
            }

            if (projBack)
            {
                r.SetProjectionTarget(MeshProjectionTarget.Auto(dMsh_goo.Value));
            }


            for (int k = 0; k < numI; ++k)
            {
                r.BasicRemeshPass();
            }

            bool isValid = dMsh_copy.CheckValidity();

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

            DA.SetData(0, dMsh_copy);
        }