Пример #1
0
    public void OnValidate()
    {
        Debug.Log("Group OnValidate");

        if (opts == null)
        {
            Debug.Log("making new options");
            opts = new ChunkGroupOpt(2, 2, 1f, 1f);
        }

        if (noise_options == null)
        {
            noise_options = new NoiseOptions(0.4f, 40, 1);
        }

        if (generators == null)
        {
            generators = new TerrainGenerator[] { new SmoothGeometric(0.2f, 5f, 6), new GeomRidgeGen(2f, 2f, 1f, 0.5f, 3, true) };
        }

        if (chunks == null)
        {
            Debug.Log("making chunk arr");
            chunks = new Chunk[opts.length * opts.width];

            makeAllChunks();
        }
    }
Пример #2
0
    override public void generateTerrain(NoiseOptions options)
    {
        base.generateTerrain(options);

        NoiseOptions o = new NoiseOptions(options);

        o.amplitude = 1f;
        o.scale     = getGenOpts().scale;

        float[,] new_noise = new float[o.res, o.res];

        /*
         * for(int i = 0; i < o.res; i++) {
         * for(int j = 0; j < o.res; j++) {
         *  noise_grid[i,j] = 0;
         * }
         * }
         */


        for (int k = 0; k < getGenOpts().num_octaves; k++)
        {
            new_noise = NoiseGrid.genNoise(o);

            //make ridges
            for (int i = 0; i < o.res; i++)
            {
                for (int j = 0; j < o.res; j++)
                {
                    //noise_grid[i,j] = 0.5f + 0.5f*Mathf.Pow(1f - 2f *o.amplitude* Mathf.Abs(0.5f*o.amplitude - noise_grid[i,j]), getGenOpts().power);

                    //noise_grid[i,j] +=  Mathf.Abs(noise_grid[i,j] - 0.5f * o.amplitude);

                    noise_store.setAdd(i, j, Mathf.Pow(o.amplitude - Mathf.Abs(new_noise[i, j] - 0.5f * o.amplitude), getGenOpts().power));
                    //noise_grid[i,j] += Mathf.Pow(o.amplitude - Mathf.Abs(new_noise[i,j] - 0.5f * o.amplitude), getGenOpts().power);
                }
            }
            o.scale += getGenOpts().scale_ratio; o.amplitude *= getGenOpts().amplitude_ratio;
        }


        float max = noise_store.getMax();
        float min = noise_store.getMin();

        for (int i = 0; i < o.res; i++)
        {
            for (int j = 0; j < o.res; j++)
            {
                noise_store.set(i, j, (noise_store.get(i, j) - min) / max + 1f);
                //noise_grid[i,j] = (noise_grid[i,j] - min) / max + 1f;
            }
        }

        /*
         * Debug.Log("Max: " + noise_store.getMax());
         * Debug.Log("Min: " + noise_store.getMin());
         */
    }
Пример #3
0
    public override void generateTerrain(NoiseOptions no)
    {
        base.generateTerrain(no);

        if (opt.enabled)
        {
            noise_store.setAdd2D(NoiseGrid.genNoise(no, opt.scale_x, opt.scale_y));
        }
    }
Пример #4
0
 public static int GetNoise1D(Vector3 point, NoiseOptions options, NoiseType method)
 {
     return(Mathf.FloorToInt(
                (NoiseGenerator.Sum(
                     NoiseGenerator.noiseMethods[(int)method][0],
                     new Vector3(point.x, 0, 0),
                     options.frequency.value,
                     options.octaves,
                     options.lacunarity,
                     options.persistance) + 1f).value * (options.scale / 2f)));
 }
    /// <summary>
    /// 创建噪点绘画工具。
    /// </summary>
    /// <param name="noise">给定的 <see cref="NoiseOptions"/>。</param>
    /// <param name="color">给定的字体颜色。</param>
    /// <returns>返回 <see cref="SKPaint"/>。</returns>
    public static SKPaint CreatePaint(this NoiseOptions noise, string color)
    {
        var paint = new SKPaint();

        paint.IsAntialias = true;
        paint.Color       = color.AsColor();
        paint.StrokeCap   = SKStrokeCap.Square;
        paint.StrokeWidth = noise.Width;

        return(paint);
    }
Пример #6
0
    public static float[,] genNoise(NoiseOptions no, float stretch_x, float stretch_y)
    {
        float[,] noise_grid = new float[no.res, no.res];

        for (int i = 0; i < no.res; i++)
        {
            for (int j = 0; j < no.res; j++)
            {
                noise_grid[i, j] = no.amplitude * (Mathf.PerlinNoise(i * stretch_x * no.scale / no.res, j * stretch_y * no.scale / no.res));
            }
        }

        return(noise_grid);
    }
Пример #7
0
    public Chunk(int x, int y, int res, Transform t)
    {
        Debug.Log("constructor");
        this.x = x;
        this.y = y;
        initMesh(t);
        noise_options = new NoiseOptions(0.7f, 50, 1f);

        original_noise_grid = new float[noise_options.res * noise_options.res];

        resetNoiseGrid();
        generators    = new TerrainGenerator[] { new SmoothGeometric(2f, 0.5f, 3) };
        noise_options = new NoiseOptions(0.5f, res, 1f);

        generateTerrainIfNotReady();
        applyTerrain();
        constructMesh();
    }
    /// <summary>
    /// 创建噪点数组。
    /// </summary>
    /// <param name="noise">给定的 <see cref="NoiseOptions"/>。</param>
    /// <param name="imageSize">给定的图像 <see cref="Size"/>。</param>
    /// <returns>返回 <see cref="SKPoint"/> 数组。</returns>
    public static SKPoint[] CreatePoints(this NoiseOptions noise, Size imageSize)
    {
        var points = new List <SKPoint>();

        var offset = noise.Width;
        var xCount = imageSize.Width / noise.Space.X + offset;
        var yCount = imageSize.Height / noise.Space.Y + offset;

        for (var i = 0; i < xCount; i++)
        {
            for (var j = 0; j < yCount; j++)
            {
                var point = new SKPoint(i * noise.Space.X, j * noise.Space.Y);
                points.Add(point);
            }
        }

        return(points.ToArray());
    }
Пример #9
0
    public void init(Vector3 pos, NoiseOptions noise_options, TerrainGenerator[] tgs)
    {
        Debug.Log("chunk init");
        this.transform.position = pos;

        this.noise_options = noise_options;

        if (this.generators == null)
        {
            this.generators = tgs;
        }

        Debug.Log("chunk init2");
        original_noise_grid = new float[noise_options.res * noise_options.res];
        Debug.Log("chunk init3");
        generateTerrain();
        applyTerrain();
        constructMesh();
    }
Пример #10
0
    public override void generateTerrain(NoiseOptions no)
    {
        base.generateTerrain(no);

        if (opt.enabled)
        {
            noise_store.copyFrom2D(NoiseGrid.genNoise(no, opt.scale_x, opt.scale_y));
            //noise_grid = NoiseGrid.genNoise(o);

            //make ridges
            for (int i = 0; i < no.res; i++)
            {
                for (int j = 0; j < no.res; j++)
                {
                    noise_store.set(i, j, Mathf.Pow(0.5f - Mathf.Abs(0.5f - noise_store.get(i, j)), opt.power));
                    //noise_grid[i,j] = Mathf.Pow(0.5f - Mathf.Abs(0.5f - noise_grid[i,j]), getGenOpts().power);
                }
            }
        }
    }
Пример #11
0
    public override void generateTerrain(NoiseOptions options)
    {
        Debug.Log("override gen ter");

        base.generateTerrain(options);

        Debug.Log("making noise");
        if (getGenOpts().enabled)
        {
            NoiseOptions o = new NoiseOptions(options);

            for (int i = 0; i < getGenOpts().num_octaves; i++)
            {
                noise_store.setAdd2D(NoiseGrid.genNoise(o));
                //noise_grid = add2DArr(noise_grid, NoiseGrid.genNoise(o));
                o.scale     *= getGenOpts().scale_ratio;
                o.amplitude *= getGenOpts().amplitude_ratio;
            }
        }
    }
Пример #12
0
    override public void generateTerrain(NoiseOptions options)
    {
        base.generateTerrain(options);

        if (getGenOpts().enabled)
        {
            NoiseOptions o = new NoiseOptions(options);
            o.amplitude = 1f;
            o.scale     = getGenOpts().scale;

            noise_store.copyFrom2D(NoiseGrid.genNoise(o));
            //noise_grid = NoiseGrid.genNoise(o);

            //make ridges
            for (int i = 0; i < o.res; i++)
            {
                for (int j = 0; j < o.res; j++)
                {
                    noise_store.set(i, j, Mathf.Pow(0.5f - Mathf.Abs(0.5f - noise_store.get(i, j)), getGenOpts().power));
                    //noise_grid[i,j] = Mathf.Pow(0.5f - Mathf.Abs(0.5f - noise_grid[i,j]), getGenOpts().power);
                }
            }
        }
    }
Пример #13
0
    void OnValidate()
    {
        Debug.Log("on validate");

        if (mesh_obj == null || mesh_filter == null)
        {
            if (mesh_obj == null)
            {
                Debug.Log("mesh_obj is null");
            }

            if (mesh_filter == null)
            {
                Debug.Log("mesh_filter is null");
            }

            Debug.Log("call init");
            initMesh(transform);
        }

        if (noise_options == null)
        {
            noise_options = new NoiseOptions(0.7f, 50, 1f);
        }

        if (generators == null || generators.Length == 0)
        {
            Debug.Log("making generators from tgopts");

            generators = new TerrainGenerator[tgopt.options.Length];

            for (int i = 0; i < tgopt.options.Length; i++)
            {
                generators[i] = GeneratorCaster.makeTG(tgopt.options[i], tgopt.types[i]);
            }
        }
        else
        {
            //todo later: make this better so it doesn't always re create the generators

            generators = new TerrainGenerator[tgopt.options.Length];
            for (int i = 0; i < tgopt.options.Length; i++)
            {
                generators[i] = GeneratorCaster.makeTG(tgopt.options[i], tgopt.types[i]);
            }

            /*
             * for(int i = 0; i < generators.Length; i++) {
             * generators[i] = GeneratorCaster.castTG(generators[i]);
             * }
             */
        }

        col_gen = new ColourGenerator(col_set);


        //Debug.Log("vert length : " + mesh_filter.sharedMesh.triangles.Length);

        if (mesh_filter.sharedMesh.vertices.Length == 0)
        {
            Debug.Log("mesh null");
        }


        Debug.Log("doing something");
        original_noise_grid = new float[noise_options.res * noise_options.res];
        generateTerrainIfNotReady();
        applyTerrain();
        terrain_mm = new MinMax();
        terrain_mm.addValues(noise_grid);
        terrain_mm.log();
        constructMesh();
    }
Пример #14
0
        public void Initialize(Language language)
        {
            // tools
            DodgeBurnOptions = new DodgeBurnOptions();
            DarkenLightenOptions = new DarkenLightenOptions();
            PencilOptions = new PencilOptions();
            FloodFillOptions = new FloodFillOptions();
            NoiseOptions = new NoiseOptions();
            EraserOptions = new EraserOptions();
            StampOptions = new StampOptions();

            _tools.Add(new ToolIndex(new CameraTool(), null, "T_TOOL_CAMERA", Resources.eye__1_, Keys.C));
            _tools.Add(new ToolIndex(new PencilTool(), PencilOptions, "T_TOOL_PENCIL", Resources.pen, Keys.P));
            _tools.Add(new ToolIndex(new EraserTool(), EraserOptions, "T_TOOL_ERASER", Resources.erase, Keys.E));
            _tools.Add(new ToolIndex(new DropperTool(), null, "T_TOOL_DROPPER", Resources.pipette, Keys.D));
            _tools.Add(new ToolIndex(new DodgeBurnTool(), DodgeBurnOptions, "T_TOOL_DODGEBURN", Resources.dodge, Keys.B));
            _tools.Add(new ToolIndex(new DarkenLightenTool(), DarkenLightenOptions, "T_TOOL_DARKENLIGHTEN", Resources.darkenlighten, Keys.L));
            _tools.Add(new ToolIndex(new FloodFillTool(), FloodFillOptions, "T_TOOL_BUCKET", Resources.fill_bucket, Keys.F));
            _tools.Add(new ToolIndex(new NoiseTool(), NoiseOptions, "T_TOOL_NOISE", Resources.noise, Keys.N));
            _tools.Add(new ToolIndex(new StampTool(), StampOptions, "T_TOOL_STAMP", Resources.stamp_pattern, Keys.M));

            for (int i = _tools.Count - 1; i >= 0; --i)
            {
                toolToolStripMenuItem.DropDownItems.Insert(0, _tools[i].MenuItem);
                _tools[i].MenuItem.Click += ToolMenuItemClicked;
                toolStrip1.Items.Insert(toolStrip1.Items.IndexOf(toolStripSeparator1) + 1, _tools[i].Button);
                _tools[i].Button.Click += ToolMenuItemClicked;

                languageProvider1.SetPropertyNames(_tools[i].MenuItem, "Text");
                languageProvider1.SetPropertyNames(_tools[i].Button, "Text");
            }

            // Shortcuts
            InitShortcuts();
            LoadShortcutKeys(GlobalSettings.ShortcutKeys);
            _shortcutEditor.ShortcutExists += _shortcutEditor_ShortcutExists;

            Editor.CurrentLanguage = language;
            SetSelectedTool(_tools[0]);

            Brushes.LoadBrushes();

            foreach (string x in GlobalSettings.SkinDirectories)
                Directory.CreateDirectory(MacroHandler.ReplaceMacros(x));

            // set up the GL control
            var mode = new GraphicsMode();

            reset:

            Renderer =
                new GLControl(new GraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, GlobalSettings.Multisamples));

            if (Renderer.Context == null)
            {
                mode = new GraphicsMode();
                goto reset;
            }

            Renderer.BackColor = Color.Black;
            Renderer.Dock = DockStyle.Fill;
            Renderer.Location = new Point(0, 25);
            Renderer.Name = "rendererControl";
            Renderer.Size = new Size(641, 580);
            Renderer.TabIndex = 4;

            splitContainer4.Panel2.Controls.Add(Renderer);
            Renderer.BringToFront();

            GLVendor = GL.GetString(StringName.Vendor);
            GLVersion = GL.GetString(StringName.Version);
            GLRenderer = GL.GetString(StringName.Renderer);
            GLExtensions = GL.GetString(StringName.Extensions);

            InitGL();

            Renderer.Paint += rendererControl_Paint;
            Renderer.MouseDown += rendererControl_MouseDown;
            Renderer.MouseMove += rendererControl_MouseMove;
            Renderer.MouseUp += rendererControl_MouseUp;
            Renderer.MouseLeave += rendererControl_MouseLeave;
            Renderer.Resize += rendererControl_Resize;
            Renderer.MouseWheel += rendererControl_MouseWheel;
            Renderer.MouseEnter += rendererControl_MouseEnter;

            #if NO
            if (!GlobalSettings.Loaded)
                MessageBox.Show(this, GetLanguageString("C_SETTINGSFAILED"));
            #endif

            _undoListBox = new UndoRedoPanel();
            _undoListBox.ActionString = "L_UNDOACTIONS";
            languageProvider1.SetPropertyNames(_undoListBox, "ActionString");

            _undoListBox.ListBox.MouseClick += UndoListBox_MouseClick;

            undoToolStripButton.DropDown = new Popup(_undoListBox);
            undoToolStripButton.DropDownOpening += undoToolStripButton_DropDownOpening;

            _redoListBox = new UndoRedoPanel();
            _redoListBox.ActionString = "L_REDOACTIONS";
            languageProvider1.SetPropertyNames(_redoListBox, "ActionString");

            _redoListBox.ListBox.MouseClick += RedoListBox_MouseClick;

            redoToolStripButton.DropDown = new Popup(_redoListBox);
            redoToolStripButton.DropDownOpening += redoToolStripButton_DropDownOpening;

            undoToolStripButton.DropDown.AutoClose = redoToolStripButton.DropDown.AutoClose = true;

            CreatePartList();
            Renderer.Invalidate();
        }
Пример #15
0
 override public void generateTerrain(NoiseOptions options)
 {
     //do nothing to avoid creating a noise_store
     this.height = options.res;
     this.width  = options.res;
 }
Пример #16
0
 public NoiseOptions(NoiseOptions o)
 {
     this.scale     = o.scale;
     this.res       = o.res;
     this.amplitude = o.amplitude;
 }
Пример #17
0
    IEnumerator MapExpand(SampleRegion i)
    {
        // Wait for the sampling coroutine to complete.
        for (;;)
        {
            if (!i.sampled)
            {
                yield return(null);
            }
            else
            {
                break;
            }
        }

        Stopwatch stopwatch = new Stopwatch();

        stopwatch.Start();

        NoiseOptions options = NoiseConfig.options[i.options];

        if (i.interpolates == null)
        {
            i.interpolates = new int[
                (i.region.sizeX / i.sampleRate) * i.sampleRate,
                (i.region.sizeY / i.sampleRate) * i.sampleRate,
                (i.region.sizeZ / i.sampleRate) * i.sampleRate
                             ];
        }

        int sampleX = i.region.sizeX / (i.sampleRate * 2) + 1;
        int sampleY = i.region.sizeY / i.sampleRate + 1;
        int sampleZ = i.region.sizeZ / (i.sampleRate * 2) + 1;

        for (int z = 0; z < sampleZ - 1; z++)
        {
            for (int y = 0; y < sampleY - 1; y++)
            {
                for (int x = 0; x < sampleX - 1; x++)
                {
                    float v000 = i.samples[x, y, z];
                    float v100 = i.samples[x + 1, y, z];
                    float v010 = i.samples[x, y + 1, z];
                    float v110 = i.samples[x + 1, y + 1, z];
                    float v001 = i.samples[x, y, z + 1];
                    float v101 = i.samples[x + 1, y, z + 1];
                    float v011 = i.samples[x, y + 1, z + 1];
                    float v111 = i.samples[x + 1, y + 1, z + 1];

                    for (int zi = 0; zi < i.sampleRate * 2; ++zi)
                    {
                        for (int yi = 0; yi < i.sampleRate; ++yi)
                        {
                            for (int xi = 0; xi < i.sampleRate * 2; ++xi)
                            {
                                float tx = (float)xi / (i.sampleRate * 2);
                                float ty = (float)yi / i.sampleRate;
                                float tz = (float)zi / (i.sampleRate * 2);

                                i.interpolates[x * (i.sampleRate * 2) + xi, y *i.sampleRate + yi, z *(i.sampleRate * 2) + zi]
                                    = Mathf.FloorToInt(((
                                                            GameUtils.TriLerp(v000, v100, v010, v110, v001, v101, v011, v111, tx, ty, tz)
                                                            + 1f) * (options.scale / 2f)));

                                if (stopwatch.ElapsedTicks > Config.CoroutineTiming)
                                {
                                    yield return(null);

                                    stopwatch.Reset();
                                    stopwatch.Start();
                                }
                            }
                        }
                    }
                }
            }
        }

        i.complete = true;

        yield return(null);
    }
Пример #18
0
 public static float[,] genNoise(NoiseOptions no)
 {
     //Debug.Log("NoiseOptions| a: " + no.amplitude + " s: " + no.scale);
     return(genNoise(no.res, no.amplitude, no.scale));
 }
Пример #19
0
    IEnumerator GetSamplesAsync(SampleRegion i)
    {
        NoiseOptions options = NoiseConfig.options[i.options];
        NoiseOptions drift   = new NoiseOptions();

        if (options.driftMapId != -1)
        {
            drift = NoiseConfig.options[options.driftMapId];
        }

        int h_rate = 2;

        if (Config.Interpolation == InterpolationLevel.Off)
        {
            h_rate = 1;
        }
        int sampleX = (i.region.sizeX / (i.sampleRate * h_rate)) + 1;
        int sampleY = (i.region.sizeY / i.sampleRate) + 1;
        int sampleZ = (i.region.sizeZ / (i.sampleRate * h_rate)) + 1;

        if (i.samples == null || i.samples.Length != sampleX * sampleY * sampleZ)
        {
            i.samples = new float[sampleX, sampleY, sampleZ];
        }

        for (int z = 0; z < sampleZ; z++)
        {
            for (int x = 0; x < sampleX; x++)
            {
                Vector2 location = new Vector2
                                   (
                    (x * i.sampleRate + (i.region.min.x / 2f)) * i.zoom.x,
                    (z * i.sampleRate + (i.region.min.z / 2f)) * i.zoom.z
                                   );

                float driftMap = 0f;
                if (options.driftMapId != -1)
                {
                    driftMap = NoiseGenerator.Sum
                               (
                        NoiseConfig.driftMapMethod,
                        location,
                        drift.frequency.value,
                        drift.octaves,
                        drift.lacunarity,
                        drift.persistance
                               );
                }

                for (int y = 0; y < sampleY; y++)
                {
                    // x and z are calculated above
                    Vector3 position = new Vector3
                                       (
                        location.x,
                        (y * i.sampleRate + i.region.min.y) * i.zoom.y,
                        location.y
                                       );

                    // with drift
                    i.samples[x, y, z] = NoiseGenerator.Sum(
                        i.method,
                        position,
                        options.drift != 0f
                                                        ? Mathf.Lerp(
                            options.frequency.value,
                            driftMap > 0f
                                                                        ? options.frequency.max * options.driftScale
                                                                        : options.frequency.min,
                            Mathf.Abs(driftMap))
                                                        : options.frequency.value,
                        options.octaves,
                        options.lacunarity,
                        options.persistance
                        );
                }
            }
        }

        i.sampled = true;

        yield return(null);
    }
Пример #20
0
 public override void generateTerrain(NoiseOptions o)
 {
     //do nothing to avoid creating a noise store
 }
Пример #21
0
    //protected float[,] noise_grid;

    public virtual void generateTerrain(NoiseOptions options)
    {
        Debug.Log("making noise store");
        noise_store = new NoiseStore(options.res, options.res);
    }