Пример #1
0
        /// <summary>
        /// Load a MagicaVoxel .vox format file into a VoxelSprite object using a file name string.
        /// A BinaryReader file stream is created for loading.
        /// </summary>
        public static byte[] Load(String fileName)
        {
            String       voxPath   = "Content/VoxFiles/";
            BinaryReader voxStream = new BinaryReader(File.Open(voxPath + fileName + extension, FileMode.Open));

            // Load and return the file from here
            byte[] voxelData = MagicaVoxImporter.LoadFromStream(voxStream);
            return(voxelData);
        }
Пример #2
0
        /// <summary>
        /// Load voxel data and create a mesh from it
        /// </summary>
        public void Load(VoxelCache cache, String filename)
        {
            this.voxelData = MagicaVoxImporter.Load(filename);

            // Setup cache
            cache.ResetData();
            cache.voxels.Add(Vector3.One,
                             new byte[cache.SizeX + 2, cache.SizeZ + 2, cache.SizeY + 2]);

            // First generate the height map and dense voxel data
            BuildVoxels(cache);

            // Second pass: Add visible voxels
            FindVisible(cache);

            // Third pass: Build mesh out of visible voxels
            BuildMesh(cache);

            // Reset cache
            cache.voxels.Remove(Vector3.One);
            cache.ResetData();
        }