private void OnGUI()
        {
            _noiseType = (NoiseType)EditorGUILayout.EnumPopup("NoiseType", _noiseType);

            if (_texOutputOptions == null)
            {
                _texOutputOptions = new NoiseTextureOutputOptions();
            }

            _texOutputOptions.OnGUI();

            if (!_noiseOptions.ContainsKey(_noiseType))
            {
                _noiseOptions.Add(_noiseType, NoiseEditorUtil.CreateNoiseOptionsByType(_noiseType));
            }

            _noiseOptions[_noiseType].OnGUI();


            if (GUILayout.Button("Generate"))
            {
                var      noiseOptions = _noiseOptions[_noiseType];
                INoise2D noise        = noiseOptions.CreateNoise(_texOutputOptions);
                _generatedTexture = _texOutputOptions.ExportNoiseTo(noise);
            }

            if (_generatedTexture != null)
            {
                var rect = EditorGUILayout.GetControlRect(GUILayout.Width(256), GUILayout.Height(256));
                GUI.DrawTexture(rect, _generatedTexture);
            }
        }
        public INoise2D CreateNoise(NoiseTextureOutputOptions texOptions)
        {
            var options = new WorleyNoise2D.Options();

            options.distanceAlgorithm = distanceAlgorithm;
            options.maxPointsInCell   = maxPointsInCell;
            if (loop)
            {
                options.loopSize = new Vector2Int(Mathf.FloorToInt(texOptions.imageSize.x / texOptions.cellSize)
                                                  , Mathf.FloorToInt(texOptions.imageSize.y / texOptions.cellSize));
            }
            return(new WorleyNoise2D(options));
        }
        public INoise2D CreateNoise(NoiseTextureOutputOptions texOptions)
        {
            var options  = new ValueNoise2D.Options();
            var loopSize = new Vector2Int(0, 0);

            if (loop)
            {
                loopSize.x = Mathf.FloorToInt(texOptions.imageSize.x / texOptions.cellSize);
                loopSize.y = Mathf.FloorToInt(texOptions.imageSize.y / texOptions.cellSize);
            }
            options.loopSize = loopSize;
            return(new ValueNoise2D(options));
        }
        public INoise2D CreateNoise(NoiseTextureOutputOptions texOptions)
        {
            var loopSize = new Vector2Int(0, 0);

            if (loop)
            {
                loopSize.x = Mathf.FloorToInt(texOptions.imageSize.x / texOptions.cellSize);
                loopSize.y = Mathf.FloorToInt(texOptions.imageSize.y / texOptions.cellSize);
            }
            return(new PerlinNoise2D(new PerlinNoise2D.Options()
            {
                loopSize = loopSize
            }));
        }
Exemple #5
0
        private void OnGUI()
        {
            if (_octaves == null)
            {
                _octaves = new List <IBaseNoiseGenerateOptions>();
            }

            for (var i = 0; i < _octaves.Count; i++)
            {
                var oc = _octaves[i];
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Octave " + i);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("-", EditorStyles.miniButtonRight))
                {
                    _octaves.RemoveAt(i);
                    break;
                }
                EditorGUILayout.EndHorizontal();
                var type = (NoiseType)EditorGUILayout.EnumPopup("BaseNoiseType", oc.type);
                if (type != oc.type)
                {
                    _octaves.RemoveAt(i);
                    oc = NoiseEditorUtil.CreateNoiseOptionsByType(type);
                    _octaves.Insert(i, oc);
                }
                oc.OnGUI();
                EditorGUILayout.EndVertical();
            }

            if (GUILayout.Button("Add Octave"))
            {
                _octaves.Add(new ValueNoiseOptions());
            }

            if (_texOutputOptions == null)
            {
                _texOutputOptions = new NoiseTextureOutputOptions();
            }

            _texOutputOptions.OnGUI();


            if (GUILayout.Button("Generate"))
            {
                List <INoise2D> octaves = new List <INoise2D>();
                foreach (var o in _octaves)
                {
                    octaves.Add(o.CreateNoise(_texOutputOptions));
                }
                var noise = new FractalNoise2D(octaves.ToArray());
                _generatedNoiseTexture = _texOutputOptions.ExportNoiseTo(noise);
            }

            if (_generatedNoiseTexture)
            {
                var rect = EditorGUILayout.GetControlRect(GUILayout.Width(256), GUILayout.Height(256));
                GUI.DrawTexture(rect, _generatedNoiseTexture);
            }
        }
 public INoise2D CreateNoise(NoiseTextureOutputOptions texOptions)
 {
     return(new WhiteNoise2D());
 }