Beispiel #1
0
        /// <summary>
        /// count 6-nbrs of each voxel, discard if count <= minNbrs
        /// </summary>
        public void Filter(int nMinNbrs)
        {
            AxisAlignedBox3i bounds = GridBounds;

            bounds.Max -= Vector3i.One;

            for (int i = 0; i < Bits.Length; ++i)
            {
                if (Bits[i] == false)
                {
                    continue;
                }
                Vector3i idx = ToIndex(i);
                int      nc  = 0;
                for (int k = 0; k < 6 && nc <= nMinNbrs; ++k)
                {
                    Vector3i nbr = idx + gIndices.GridOffsets6[k];
                    if (bounds.Contains(nbr) == false)
                    {
                        continue;
                    }
                    if (Get(nbr))
                    {
                        nc++;
                    }
                }
                if (nc <= nMinNbrs)
                {
                    Bits[i] = false;
                }
            }
        }
        public void Generate()
        {
            append_mesh();

            AxisAlignedBox3i bounds = Voxels.GridBounds;

            bounds.Max -= Vector3i.One;

            int[] vertices = new int[4];

            foreach (Vector3i nz in Voxels.NonZeros())
            {
                check_counts_or_append(6, 2);

                Box3d cube = Box3d.UnitZeroCentered;
                cube.Center = (Vector3d)nz;

                for (int fi = 0; fi < 6; ++fi)
                {
                    // checks dependent on neighbours
                    Index3i nbr = nz + gIndices.GridOffsets6[fi];
                    if (bounds.Contains(nbr))
                    {
                        if (SkipInteriorFaces && Voxels.Get(nbr))
                        {
                            continue;
                        }
                    }
                    else if (CapAtBoundary == false)
                    {
                        continue;
                    }


                    int           ni = gIndices.BoxFaceNormals[fi];
                    Vector3f      n  = (Vector3f)(Math.Sign(ni) * cube.Axis(Math.Abs(ni) - 1));
                    NewVertexInfo vi = new NewVertexInfo(Vector3d.Zero, n);
                    if (ColorSourceF != null)
                    {
                        vi.c      = ColorSourceF(nz);
                        vi.bHaveC = true;
                    }
                    for (int j = 0; j < 4; ++j)
                    {
                        vi.v        = cube.Corner(gIndices.BoxFaces[fi, j]);
                        vertices[j] = cur_mesh.AppendVertex(vi);
                    }

                    Index3i t0 = new Index3i(vertices[0], vertices[1], vertices[2], Clockwise);
                    Index3i t1 = new Index3i(vertices[0], vertices[2], vertices[3], Clockwise);
                    cur_mesh.AppendTriangle(t0);
                    cur_mesh.AppendTriangle(t1);
                }
            }
        }