Esempio n. 1
0
    public void NoiseFunctionFoldout(ref MapGenerator _mapGen)
    {
        showNoiseFunctions = EditorGUILayout.Foldout(showNoiseFunctions, "Noise Functions");
        if (showNoiseFunctions)
        {
            if (GUILayout.Button("Open Noise Designer"))
            {
                NoiseDesigner.ShowWindow();
            }

            if (GUILayout.Button("Add New Noise Function"))
            {
                if (!(_mapGen.noiseFunctions.Length > 0))
                {
                    NoiseFunction[] tempNFunc = new NoiseFunction[1];
                }
                NoiseFunction[] placeholder = new NoiseFunction[_mapGen.noiseFunctions.Length + 1];
                for (int j = 0; j < _mapGen.noiseFunctions.Length; j++)
                {
                    placeholder[j] = _mapGen.noiseFunctions[j];
                }
                placeholder[_mapGen.noiseFunctions.Length] = new NoiseFunction();
                _mapGen.noiseFunctions = new NoiseFunction[placeholder.Length];
                for (int j = 0; j < placeholder.Length; j++)
                {
                    _mapGen.noiseFunctions[j] = placeholder[j];
                }
            }
            #region Save / Load Functions
            if (GUILayout.Button("Save This Noise Preset"))
            {
                fileName = EditorUtility.SaveFilePanel("Save a New Preset", Application.dataPath, "Noise Preset", "npr");
                _mapGen.SavePresets(_mapGen.noiseFunctions, fileName);
            }
            if (GUILayout.Button("Load Preset From File"))
            {
                fileName = EditorUtility.OpenFilePanel("Load a noise File ", null, "npr");
                Debug.Log(fileName + " loaded.");
                _mapGen.LoadPresets(fileName);
                _mapGen.GenerateMap();
            }
            #endregion
            if (_mapGen.noiseFunctions != null)
            {
                for (int i = 0; i < _mapGen.noiseFunctions.Length; i++)
                {
                    if (showNoiseFunctions)
                    {
                        GetInspectorElements(_mapGen.noiseFunctions[i], i, _mapGen);
                    }
                }
            }
        }
    }
 public float[] GenerateNoise(NoiseFunction noiseFunction)
 {
     for (int j = 0; j < height; ++j)
     {
         for (int i = 0; i < width; ++i)
         {
             // generate a float in the range [0:1]
             map[j * width + i] = noiseFunction(new Vector2D(i, j));
         }
     }
     return(map);
 }
Esempio n. 3
0
        private static float[] GenNoise(NoiseFunction f, int width, int height, float scale = 1, float offset = 0)
        {
            float[] noises = new float[width * height];

            for (int z = 0, i = 0; z < height; z++)
            {
                for (int x = 0; x < width; x++)
                {
                    noises[i] = f((float)x / width * scale + offset, (float)z / height * scale);

                    i++;
                }
            }
            return(noises);
        }
Esempio n. 4
0
        private void MinNoiseCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            bool mbValue = ((CheckBox)sender).Checked;

            if (mbValue == true)
            {
                NoiseFunction func = new NoiseFunction();
                TerrainGlobals.getEditor().mComponentMaskSettings.mMinNoiseFunction = func;
            }
            else
            {
                TerrainGlobals.getEditor().mComponentMaskSettings.mMinNoiseFunction = null;
            }

            UpdateComponentMasking();
        }
Esempio n. 5
0
        private void MaxNoiseCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            bool mbValue = ((CheckBox)sender).Checked;

            if (mbValue == true)
            {
                NoiseFunction func = new NoiseFunction();
                //NoiseGeneration.RigedMultiFractal.mFrequency = 0.05f;
                TerrainGlobals.getEditor().mComponentMaskSettings.mMaxNoiseFunction = func;
            }
            else
            {
                TerrainGlobals.getEditor().mComponentMaskSettings.mMaxNoiseFunction = null;
            }

            UpdateComponentMasking();
        }
Esempio n. 6
0
 public void LoadPresets(string filePath)  //loads map from a given string location
 {
     if (File.Exists(filePath))
     {
         BinaryFormatter bf            = new BinaryFormatter();
         FileStream      file          = File.Open(filePath, FileMode.Open);
         NoisePresets[]  loadedPresets = (NoisePresets[])bf.Deserialize(file);
         NoiseFunction[] holder        = new NoiseFunction[loadedPresets.Length];
         for (int i = 0; i < loadedPresets.Length; i++)
         {
             holder[i] = new NoiseFunction(loadedPresets[i]);
         }
         noiseFunctions = new NoiseFunction[holder.Length];
         noiseFunctions = holder;
         file.Close();
     }
 }
Esempio n. 7
0
        public override void Initialize(ModuleWaterfallFX host)
        {
            base.Initialize(host);

            if (noiseType == "perlin")
            {
                noiseFunc = new NoiseFunction(PerlinNoise);
            }
            else if (noiseType == "random")
            {
                noiseFunc = new NoiseFunction(RandomNoise);
            }
            else
            {
                noiseFunc = new NoiseFunction(RandomNoise);
            }
        }
        public override void Initialize(ModuleWaterfallFX host)
        {
            base.Initialize(host);

            if (noiseType == PerlinNoiseName)
            {
                noiseFunc = PerlinNoise;
            }
            else if (noiseType == RandomNoiseName)
            {
                noiseFunc = RandomNoise;
            }
            else
            {
                noiseFunc = RandomNoise;
            }
        }
Esempio n. 9
0
 public void AttachToBase(NoiseFunction _noiseFunc)
 {
     Attached = _noiseFunc;
 }
Esempio n. 10
0
    /// <summary>
    /// The Core Map Generation Method, in essence this method
    /// takes the stack of noise methods and processes them
    /// sequentially and generates a resultant noise map.
    /// It then calls a function to generate the Mesh (or 3D object)
    /// and applies the noise to the mesh inside of the function
    /// to draw the mesh.

    /// -RGS
    /// </summary>
    public void GenerateMap()
    {
        #region variables and setup

        //This function prevents the generation from happening if there is no noise stack to process.
        if ((noiseFunctions == null) || (noiseFunctions.Length < 1))
        {
            noiseFunctions    = new NoiseFunction[1];
            noiseFunctions[0] = new NoiseFunction();
            noiseFunctions[0].GetDefault();
        }

        //this is the base noise module that will be manipulated
        baseModule = null;

        //this is the noisemap that will be generated
        noiseMap = null;


        ///next two commands interface with multithreaded renderer
        ///to shut it down if it's running.  The bool adds a hard
        ///abort check that doesn't rely on the timestamp

        HaltThreads();
        reset = true;

        //misc Setup
        MapDisplay display = FindObjectOfType <MapDisplay>();

        #endregion

        #region Noise Map Initialization

        //Generates a random seed and passes it to the noise processor
        if (!useRandomSeed)
        {
            seedValue = seed.GetHashCode();
        }
        else
        {
            seedValue = UnityEngine.Random.Range(0, 10000000);
        }
        baseModule = NoiseProcessor.InitNoise(noiseFunctions, seedValue);


        //This clamps the module to between 1 and 0, sort of...
        //because of the way coherent noise works, it's not possible to completely
        //eliminate the possibility that a value will fall outside these ranges.
        if (clamped)
        {
            baseModule = new Clamp(0, 1, baseModule);
        }
        noiseMap = new Noise2D(mapWidth, mapHeight, baseModule);

        #endregion

        #region Planet Generator Setup
        if (mapType == MapType.Planet)
        {
            mapHeight  = mapWidth / 2;
            renderType = RenderType.Color;

            if ((oceans) && (!waterMesh.activeSelf))
            {
                waterMesh.SetActive(true);
            }
            if (waterMesh != null)
            {
                waterMesh.transform.localScale = 2 * (new Vector3(radius + seaLevelOffset, radius + seaLevelOffset, radius + seaLevelOffset));

                if (!oceans)
                {
                    waterMesh.SetActive(false);
                }
            }
        }
        #endregion

        #region Flat Terrain Generator
        //non functional

        else if (mapType == MapType.FlatTerrain)
        {
            noiseMap = new Noise2D(100, 100, baseModule);
            noiseMap.GeneratePlanar(-1, 1, -1, 1, seamless);
            display.TextureRender = FindObjectOfType <Renderer>();
            mapTexture            = GetMapTexture(renderType, noiseMap);
            display.DrawMesh(FlatMeshGenerator.GenerateTerrainMesh(noiseMap, heightMultiplier, heightAdjuster), mapTexture);
        }
        #endregion

        #region Start Multithreaded Noisemapping
        if (multithreading)
        {
            ThreadMap();
        }

        #endregion
    }
Esempio n. 11
0
    public void GetInspectorElements(NoiseFunction noiseFunc, int index, MapGenerator generator)
    {
        if (noiseFunc == null)
        {
            return;
        }
        //to autoupdate if this panel has been changed
        EditorGUI.BeginChangeCheck();

        #region Perlin Function UI
        if (noiseFunc.type == NoiseFunction.NoiseType.Perlin)
        {
            EditorGUILayout.Space();
            string name = "Perlin Noise";
            EditorGUILayout.LabelField(name);
            noiseFunc.type        = (NoiseFunction.NoiseType)EditorGUILayout.EnumPopup("Type of Noise", noiseFunc.type);
            noiseFunc.enabled     = EditorGUILayout.ToggleLeft("Enabled", noiseFunc.enabled);
            noiseFunc.frequency   = (double)EditorGUILayout.Slider("Frequency", (float)noiseFunc.frequency, -20f, 20f);
            noiseFunc.lacunarity  = (double)EditorGUILayout.Slider("Lacunarity", (float)noiseFunc.lacunarity, -2.0000000f, 2.5000000f);
            noiseFunc.persistence = (double)EditorGUILayout.Slider("Persistence", (float)noiseFunc.persistence, -1f, 1f);
            noiseFunc.octaves     = EditorGUILayout.IntSlider("Octaves", noiseFunc.octaves, 0, 18);
            noiseFunc.qualityMode = (LibNoise.QualityMode)EditorGUILayout.EnumPopup("Quality Mode", noiseFunc.qualityMode);
            noiseFunc.blendMode   = (NoiseFunction.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", noiseFunc.blendMode);
            if (GUILayout.Button("Remove"))
            {
                NoiseFunction[] placeHolder = new NoiseFunction[generator.noiseFunctions.Length - 1];
                placeHolder = generator.noiseFunctions.RemoveAt(index);
                generator.noiseFunctions = placeHolder;
            }
        }
        #endregion

        #region Billow Function UI
        else if (noiseFunc.type == NoiseFunction.NoiseType.Billow)
        {
            EditorGUILayout.Space();
            string name = "Billow Noise";
            EditorGUILayout.LabelField(name);
            noiseFunc.type        = (NoiseFunction.NoiseType)EditorGUILayout.EnumPopup("Type of Noise", noiseFunc.type);
            noiseFunc.enabled     = EditorGUILayout.ToggleLeft("Enabled", noiseFunc.enabled);
            noiseFunc.frequency   = (double)EditorGUILayout.Slider("Frequency", (float)noiseFunc.frequency, 0f, 20f);
            noiseFunc.lacunarity  = (double)EditorGUILayout.Slider("Lacunarity", (float)noiseFunc.lacunarity, 1.5000000f, 3.5000000f);
            noiseFunc.persistence = (double)EditorGUILayout.Slider("Persistence", (float)noiseFunc.persistence, 0f, 1f);
            noiseFunc.octaves     = EditorGUILayout.IntSlider("Octaves", noiseFunc.octaves, 0, 18);
            noiseFunc.qualityMode = (LibNoise.QualityMode)EditorGUILayout.EnumPopup("Quality Mode", noiseFunc.qualityMode);
            noiseFunc.blendMode   = (NoiseFunction.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", noiseFunc.blendMode);
            if (GUILayout.Button("Remove"))
            {
                NoiseFunction[] placeHolder = new NoiseFunction[generator.noiseFunctions.Length - 1];
                placeHolder = generator.noiseFunctions.RemoveAt(index);
                generator.noiseFunctions = placeHolder;
            }
        }
        #endregion

        #region Voronoi UI
        else if (noiseFunc.type == NoiseFunction.NoiseType.Voronoi)
        {
            EditorGUILayout.Space();
            string name = "Voronoi Noise";
            EditorGUILayout.LabelField(name);
            noiseFunc.type         = (NoiseFunction.NoiseType)EditorGUILayout.EnumPopup("Type of Noise", noiseFunc.type);
            noiseFunc.enabled      = EditorGUILayout.ToggleLeft("Enabled", noiseFunc.enabled);
            noiseFunc.frequency    = (double)EditorGUILayout.Slider("Frequency", (float)noiseFunc.frequency, 0f, 20f);
            noiseFunc.displacement = (double)EditorGUILayout.Slider("Displacement", (float)noiseFunc.displacement, 0f, 20f);
            noiseFunc.distance     = EditorGUILayout.ToggleLeft("Use Distance", noiseFunc.distance);
            noiseFunc.blendMode    = (NoiseFunction.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", noiseFunc.blendMode);
            if (GUILayout.Button("Remove"))
            {
                NoiseFunction[] placeHolder = new NoiseFunction[generator.noiseFunctions.Length - 1];
                placeHolder = generator.noiseFunctions.RemoveAt(index);
                generator.noiseFunctions = placeHolder;
            }
        }
        #endregion

        #region Ridged Multifractal UI
        else if (noiseFunc.type == NoiseFunction.NoiseType.RidgedMultifractal)
        {
            EditorGUILayout.Space();
            string name = "Ridged Multifractal";
            EditorGUILayout.LabelField(name);
            noiseFunc.type        = (NoiseFunction.NoiseType)EditorGUILayout.EnumPopup("Type of Noise", noiseFunc.type);
            noiseFunc.enabled     = EditorGUILayout.ToggleLeft("Enabled", noiseFunc.enabled);
            noiseFunc.frequency   = (double)EditorGUILayout.Slider("Frequency", (float)noiseFunc.frequency, 0f, 20f);
            noiseFunc.lacunarity  = (double)EditorGUILayout.Slider("Lacunarity", (float)noiseFunc.lacunarity, 1.5000000f, 3.5000000f);
            noiseFunc.octaves     = EditorGUILayout.IntSlider("Octaves", noiseFunc.octaves, 0, 18);
            noiseFunc.qualityMode = (LibNoise.QualityMode)EditorGUILayout.EnumPopup("Quality Mode", noiseFunc.qualityMode);
            noiseFunc.blendMode   = (NoiseFunction.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", noiseFunc.blendMode);
            if (GUILayout.Button("Remove"))
            {
                NoiseFunction[] placeHolder = new NoiseFunction[generator.noiseFunctions.Length - 1];
                placeHolder = generator.noiseFunctions.RemoveAt(index);
                generator.noiseFunctions = placeHolder;
            }
        }
        #endregion

        #region None UI
        else if (noiseFunc.type == NoiseFunction.NoiseType.None)
        {
            EditorGUILayout.Space();
            string name = "None";
            EditorGUILayout.LabelField(name);
            noiseFunc.type = (NoiseFunction.NoiseType)EditorGUILayout.EnumPopup("Type of Noise", noiseFunc.type);
            if (GUILayout.Button("Remove"))
            {
                NoiseFunction[] placeHolder = new NoiseFunction[generator.noiseFunctions.Length - 1];
                placeHolder = generator.noiseFunctions.RemoveAt(index);
                generator.noiseFunctions = placeHolder;
            }
            noiseFunc.enabled = false;
        }

        #endregion

        //to autoupdate if this inspector element has changed
        if (generator.autoUpdate && EditorGUI.EndChangeCheck())
        {
            generator.GenerateMap();
        }
    }