private void RemoveHidden(VoxelData data)
 {
     for (int x = 0; x < data.width; x++)
     {
         for (int y = 0; y < data.height; y++)
         {
             for (int z = 0; z < data.depth; z++)
             {
                 if (!data.IsVisible(x, y, z))
                 {
                     data.SetVoxel(x, y, z, 0);
                 }
             }
         }
     }
 }
        private VoxelData MergedModels()
        {
            Vector3Int min = new Vector3Int(4096, 4096, 4096);
            Vector3Int max = new Vector3Int(-4096, -4096, -4096);

            for (int i = 0; i < importer.models.Count; i++)
            {
                Vector3Int s = importer.Size(i);
                Vector3Int c = importer.modelOffsets[i];//centers

                int xmin = c.x - (s.x / 2);
                int xmax = c.x + (s.x / 2);
                if (min.x > xmin)
                {
                    min.x = xmin;
                }
                if (max.x < xmax)
                {
                    max.x = xmax;
                }

                int ymin = c.y - (s.y / 2);
                int ymax = c.y + (s.y / 2);
                if (min.y > ymin)
                {
                    min.y = ymin;
                }
                if (max.y < ymax)
                {
                    max.y = ymax;
                }

                int zmin = c.z - (s.z / 2);
                int zmax = c.z + (s.z / 2);
                if (min.z > zmin)
                {
                    min.z = zmin;
                }
                if (max.z < zmax)
                {
                    max.z = zmax;
                }
            }

            //Debug.Log(min.ToString());
            //Debug.Log(max.ToString());

            int w = Mathf.Abs(max.x - min.x) + 1;
            int h = Mathf.Abs(max.y - min.y) + 1;
            int d = Mathf.Abs(max.z - min.z) + 1;
            //Debug.Log(w + "," + h + "," + d);

            VoxelData data = new VoxelData(w, h, d, importer.palette, importer.materials);

            //Merge all models...
            for (int i = 0; i < importer.models.Count; i++)
            {
                Vector3Int s = importer.Size(i);
                Vector3Int o = importer.modelOffsets[i];
                o.x -= min.x;
                o.y -= min.y;
                o.z -= min.z;

                o.x -= s.x / 2;
                o.y -= s.y / 2;
                o.z -= s.z / 2;

                for (int x = 0; x < s.x; x++)
                {
                    for (int y = 0; y < s.y; y++)
                    {
                        for (int z = 0; z < s.z; z++)
                        {
                            if (importer.models[i][x, y, z] > 0)
                            {
                                data.SetVoxel(x + o.x, y + o.y, z + o.z, importer.models[i][x, y, z]);
                            }
                        }
                    }
                }
            }

            return(data);
        }