Example #1
0
        public void Execute()
        {
            int nVoxels = Voxels.Length(0) * Voxels.Length(1) * Voxels.Length(2);
            int nCells  = (Voxels.Length(0) - 1) * (Voxels.Length(1) - 1) * (Voxels.Length(2) - 1);

            var MemoryCache = new NativeMemoryCache(Allocator.Temp);
            var DedupeCache = new VoxelMeshTessellation.NativeDeduplicationCache(Allocator.Temp);

            var Components = new NativeList <VoxelMeshComponent>(Allocator.Temp);
            var Indices    = new NativeList <PackedIndex>(Allocator.Temp);
            var Vertices   = new NativeList <VoxelMeshComponentVertex>(Allocator.Temp);

            var Materials     = new NativeArray <int>(8, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            var Intersections = new NativeArray <float>(12, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            var Normals       = new NativeArray <float3>(12, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            var solver = new SvdQefSolver <RawArrayVoxelCell>
            {
                Clamp = false
            };
            var polygonizer = new CMSVoxelPolygonizer <RawArrayVoxelCell, CMSProperties.DataStruct, SvdQefSolver <RawArrayVoxelCell>, IntersectionSharpFeatureSolver <RawArrayVoxelCell> >(PolygonizationProperties, solver, new IntersectionSharpFeatureSolver <RawArrayVoxelCell>(), MemoryCache);

            int xSize = Voxels.Length(0);
            int ySize = Voxels.Length(1);
            int zSize = Voxels.Length(2);

            TIndexer indexer = Voxels.Indexer;

            for (int index = 0; index < nVoxels; ++index)
            {
                int x = 0, y = 0, z = 0;
                indexer.FromIndex(index, ref x, ref y, ref z);

                if (x < xSize - 1 && y < ySize - 1 && z < zSize - 1 && FillCell(Voxels, x, y, z, 0, Materials, Intersections, Normals))
                {
                    //TODO Directly operate on voxel array
                    RawArrayVoxelCell cell = new RawArrayVoxelCell(0, new float3(x, y, z), Materials, Intersections, Normals);

                    polygonizer.Polygonize(cell, Components, Indices, Vertices);
                }
            }

            VoxelMeshTessellation.Tessellate(Components, Indices, Vertices, Matrix4x4.identity, MeshVertices, MeshTriangles, MeshNormals, MeshMaterials, new MaterialColors(), MeshColors, DedupeCache);

            MemoryCache.Dispose();
            DedupeCache.Dispose();

            Materials.Dispose();
            Intersections.Dispose();
            Normals.Dispose();

            Components.Dispose();
            Indices.Dispose();
            Vertices.Dispose();

            //Cells.Dispose();
        }
    public void Execute()
    {
        var solver = new SvdQefSolver <RawArrayVoxelCell>();

        solver.Clamp = false;
        var polygonizer = new CMSVoxelPolygonizer <RawArrayVoxelCell, CMSStandardProperties, SvdQefSolver <RawArrayVoxelCell>, IntersectionSharpFeatureSolver <RawArrayVoxelCell> >(new CMSStandardProperties(), solver, new IntersectionSharpFeatureSolver <RawArrayVoxelCell>(), MemoryCache);

        for (int i = 0; i < Cells.Length; i++)
        {
            RawArrayVoxelCell cell = new RawArrayVoxelCell(i, Cells[i], Materials, Intersections, Normals);

            polygonizer.Polygonize(cell, Components, Indices, Vertices);
        }

        VoxelMeshTessellation.Tessellate(Components, Indices, Vertices, Matrix4x4.identity, MeshVertices, MeshTriangles, MeshNormals, MeshMaterials, new MaterialColors(), MeshColors, DedupeCache);
    }