Ejemplo n.º 1
0
        public Mesh Metaball(double iso)
        {
            this.use_iso = iso;
            Plane plane = new Plane();
            Plane.FitPlaneToPoints(use_charges, out plane);
            plane.Origin = use_charges[0];
            Interval xSize = new Interval(-use_radii[0], use_radii[0]);
            Box box = new Box(plane, xSize, xSize, xSize);
            int num27 = use_charges.Count - 1;
            for (int i = 1; i <= num27; i++)
            {
                plane.Origin = use_charges[i];
                box.Union(plane.PointAt(-use_radii[i], -use_radii[i], -use_radii[i]));
                box.Union(plane.PointAt(use_radii[i], use_radii[i], use_radii[i]));
            }
            box.Inflate(res);
            int xSet = (int)Math.Round((double)(box.X.Length / res));
            int ySet = (int)Math.Round((double)(box.Y.Length / res));
            int zSet = (int)Math.Round((double)(box.Z.Length / res));
            double xLength = box.X.Length / ((double)xSet);
            double yLength = box.Y.Length / ((double)ySet);
            double zLength = box.Z.Length / ((double)zSet);
            double xBase = xLength / 2.0;
            double yBase = yLength / 2.0;
            double zBase = zLength / 2.0;
            plane.Origin = box.GetCorners()[0];
            List<Point3d> list = new List<Point3d>();
            Mesh mesh = new Mesh();

            for (int j = 0; j <= xSet - 1; j++)
            {
                for (int m = 0; m <= ySet - 1; m++)
                {
                    for (int n = 0; n <= zSet - 1; n++)
                    {
                        Point3d item = plane.PointAt(xBase + (xLength * j), yBase + (yLength * m), zBase + (zLength * n));
                        int xSet1 = use_charges.Count - 1;
                        for (int k = 0; k <= xSet1; k++)
                        {
                            if (item.DistanceTo(use_charges[k]) < (use_radii[k] + res))
                            {
                                Plane pl = plane;
                                pl.Origin = item;
                                Mesh other = this.local_tet(pl, xBase, yBase, zBase);
                                mesh.Append(other);
                                list.Add(item);
                                break;
                            }
                        }
                    }
                }
            }
            mesh.Vertices.CombineIdentical(true, true);
            mesh.UnifyNormals();
            return mesh;
        }