예제 #1
0
        public void Build(VoxelCache cache, Biome biome)
        {
            // Check if neighbors are loaded for next time
            if (state == ChunkState.VoxelsLoaded && NeighborsLoaded())
            {
                state = ChunkState.NeighborsLoaded;
            }

            // Next, build the mesh
            if (state == ChunkState.NeighborsLoaded)
            {
                if (!isEmpty && !isCompletelySolid)
                {
                    // Second pass: Add visible voxels
                    FindVisible(cache, biome);

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

                state = ChunkState.Meshed;

                // Remove data from cache and reset
                cache.voxels.Remove(offset);
                cache.ResetData();

                // Set matrix transformation
                transformMatrix = Matrix.CreateTranslation(offset.X, offset.Y, offset.Z);
            }
        }
예제 #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();
        }
예제 #3
0
        /// <summary>
        /// Generate a world chunk
        /// </summary>
        public void Setup(VoxelCache cache, Biome biome)
        {
            // Create lightweight voxel array. At 2 bits/voxel, Y axis shares 16 voxels per int
            voxels = new uint[cache.SizeX, cache.SizeZ, cache.SizeY / 16];

            cache.voxels.Remove(previousOffset);
            cache.voxels.Add(offset,
                             new byte[cache.SizeX + 2, cache.SizeZ + 2, cache.SizeY + 2]);

            // First generate the height map and dense voxel data
            BuildVoxels(cache, biome);
            state = ChunkState.VoxelsLoaded;

            // Remove voxels from cache if chunk doesn't need a mesh
            if (isEmpty || isCompletelySolid)
            {
                cache.voxels.Remove(offset);
            }

            // Reset cache
            cache.ResetData();
        }