示例#1
0
        /// <summary>
        /// Create a non existing chunk
        /// </summary>
        /// <param name="pos">The Chunks position</param>
        /// <param name="trength">The chunks 4th dimension position</param>
        /// <param name="size">The size of the chunk</param>
        /// <param name="compute">ComputeShader used by the gpu visualizor</param>
        /// <param name="generator">The monobehaviour that called this function</param>
        /// <param name="visualizer">What visualizor to use</param>
        public Chunk(Vector3Int pos, float trength, long seed, float threshold, ComputeShader compute, MonoBehaviour generator, MeshGenModel.Visualizer visualizer, int size = 16, float noiseScale = 1f)
        {
            switch (visualizer)
            {
            case MeshGenModel.Visualizer.VOXEL:
                mv = new VoxelVisualisor(threshold);
                break;

            case MeshGenModel.Visualizer.MARCHING:
                mv = new MarchingVisualiser(threshold);
                break;

            case MeshGenModel.Visualizer.GPU_MARCHING:
                mv = new MarchingComputeVisualiser(threshold, compute, generator);
                break;

            default:
                break;
            }

            this.seed    = seed;
            position     = pos;
            this.trength = trength;
            this.size    = size;
            if (noiseScale <= 0)
            {
                throw new ArgumentException("noiseScale is out of bounds, it is less then or equal to 0");
            }
            this.noiseScale = noiseScale;

            this.threshold = threshold;
        }
示例#2
0
        /// <summary>
        /// Attempt to load this chunk from a file
        /// </summary>
        public static Chunk TryLoadFromFile(Vector3Int pos, float trength, long seed, float threshold, ComputeShader compute, MonoBehaviour generator, MeshGenModel.Visualizer visualizer, int size = 16, float noiseScale = 1f)
        {
            if (!Directory.Exists(@"save\"))
            {
                Directory.CreateDirectory(@"save\");
            }

            string filename = InfoToFileName(pos, trength, seed, threshold, size, noiseScale);

            if (File.Exists(@"save\" + filename))
            {
                return(ChunkSerializer.Deserialize(File.ReadAllBytes(@"save\" + filename), compute, generator, visualizer));
            }
            else
            {
                return(new Chunk(pos, trength, seed, threshold, compute, generator, visualizer, size, noiseScale));
            }
        }