Beispiel #1
0
        /// <summary>
        /// Returns 3 dimensional simplex noise of the specified size and with the given parameters. See documentation for more information
        /// on parameters and recommended values.
        /// </summary>
        /// <param name="width">The width of the noise</param>
        /// <param name="height">The height of the noise</param>
        /// <param name="depth">The depth of the noise</param>
        /// <param name="frequency">The frequency of the noise function.A high frequency will make the noise look more random
        /// while a low frequency will make the noise look more flat and bland.
        /// Default : 1</param>
        /// <param name="persistence">The rate at which the frequency decreases for each octave. Increasing this value will make the noise
        /// rougher, while decreasing it will make it smoother.
        /// Default : 0.5 , Min : 0</param>
        /// <param name="octaveCount">The octave count determines how many noise functions are combined. Increasing this value will make
        /// the noise look more fractal, decreasing it will make the noise look more simple and stylized.
        /// Increasing this value will significantly increase computation time.
        /// Default : 6 , Min : 1 , Max : 32</param>
        /// <param name="amplitude">The highest value any point in the noise can have. Default : 1</param>
        public static float[, ,] RandSimplexNoise3(int width, int height, int depth, float frequency, float persistence, int octaveCount, float amplitude)
        {
            if (width <= 0 || width > MAX_PERLIN_SIZE || height <= 0 || height > MAX_PERLIN_SIZE || depth > MAX_PERLIN_SIZE)
            {
                throw new ArgumentException(string.Format("Noise width and height must be between 1 and {0}", MAX_PERLIN_SIZE));
            }
            if (frequency < 0)
            {
                throw new ArgumentException("Frequency must be greater than zero");
            }
            if (persistence < 0)
            {
                throw new ArgumentException("Persistence must be greater than zero");
            }
            if (octaveCount <= 0 || octaveCount > MAX_OCTAVE_COUNT)
            {
                throw new ArgumentException(string.Format("Octave count must be between 1 and {0}", MAX_OCTAVE_COUNT));
            }
            if (amplitude < 0)
            {
                throw new ArgumentException("Amplitude can't be less than zero");
            }

            SimplexGenerator generator = new SimplexGenerator(frequency, persistence, octaveCount, amplitude);

            return(generator.GetSimplexNoise(width, height, depth, 0, 0, 0));
        }
Beispiel #2
0
    void Start()
    {
        objects = new Transform[1];

        var chunkPrefab = SafeLoad <Transform>(chunk, "TerrainChunk");

        objects[0] = Instantiate(chunkPrefab, Vector3.zero, Quaternion.identity);
        objects[0].gameObject.SetActive(false);

        var mchunk = objects[0].GetComponent <MeshChunk>();

        if (mchunk != null)
        {
            mchunk.terrainGenerator = this;
        }


        generator = GetComponent <SimplexGenerator>();
        if (generator == null)
        {
            generator = gameObject.AddComponent <SimplexGenerator>();
        }

        //objectNoise.perms = SimplexNoise.NewPermutation(objectSeed);
        //heightmapNoise.perms = SimplexNoise.NewPermutation(heightmapSeed);
        //splatmapNoise.perms = SimplexNoise.NewPermutation(splatmapSeed);
        UpdateGenerator();
    }
Beispiel #3
0
    void Start()
    {
        objects = new Transform[1];

        var chunkPrefab = SafeLoad <Transform>(chunkName, "Chunk3D");

        objects[0] = Instantiate(chunkPrefab, Vector3.zero, Quaternion.identity);
        objects[0].gameObject.SetActive(false);

        var mc3d = objects[0].GetComponent <MeshChunk3D>();

        if (mc3d != null)
        {
            mc3d.generator = this;
        }

        generator = GetComponent <SimplexGenerator>();
        if (generator == null)
        {
            generator = gameObject.AddComponent <SimplexGenerator>();
        }

        UpdateGenerator();
    }