Esempio n. 1
0
        void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                double[,] data = NoiseFactory.GeneratePlanar((ModuleBase)e.Argument, previewWidth, previewHeight, -1, 1, -1, 1, true, true, 0);

                Bitmap bm = new Bitmap(previewWidth, previewHeight);

                for (int x = 0; x < previewWidth; x++)
                {
                    for (int y = 0; y < previewHeight; y++)
                    {
                        double val = data[x, y];

                        val = val > 1.0 ? 1.0 : val;
                        val = val < 0 ? 0 : val;

                        // typically, I'd rather do image work with lockbits, but for something so small the
                        // slow setpixels method should work fine.
                        int colorValue = Convert.ToInt32(Math.Round((255.0f * val), 0, MidpointRounding.ToEven));
                        bm.SetPixel(x, y, System.Drawing.Color.FromArgb(colorValue, colorValue, colorValue));
                    }
                }

                PreviewImageBitmap = bm;
            }
            catch (Exception ex)
            {
                // can't prepare the preview image. just toss back an empty one for now
                // it's most likely that the diagram is invalid
                PreviewImageBitmap = new Bitmap(previewWidth, previewHeight);
            }
        }
        public static StreamingStageMeshFactory CreateSkyIsland()
        {
            var stageIdentity = new StageIdentity("Test Stage");
            var multiNoise    = new NoiseFactory(seed: 0);

            // maps
            var mapChunkConfig = new SkyIslandMapChunkConfig(VoxelChunkConfig.TreeDepth);
            var stageBounds    = new StageBounds(new ChunkKey(0, 0, 0), new Index3D(1, 8, 1));
            var mapConfig      = SkyIslandMapGenerationConfigService.CreatePreconfigured(stageBounds, mapChunkConfig).Build();

            var mapChunkPopulator = new AsyncChunkPopulator <ISkyIslandMapChunk>(
                new SkyIslandMapChunkPopulator(mapConfig, stageBounds, multiNoise));

            var mapChunkCacheBuilder = new SkyIslandMapChunkCacheBuilder(mapChunkConfig, mapChunkPopulator);
            var mapCacheOptions      = new ChunkCacheBuilderOptions <SkyIslandMapChunkResources>()
            {
                StashCapacityMultiplier = 2,
                EagerFillPool           = true,
            };

            mapChunkCacheBuilder.CreateAndAssignStandardResourceStash(CacheSizeInBytes / 10, mapCacheOptions);
            var mapChunkCache = mapChunkCacheBuilder.Build();

            // voxels
            var voxelChunkPopulator = new SkyIslandVoxelGridChunkPopulator(
                SkyIslandVoxelGridGenerationConfigService.CreatePreconfigured().Build(),
                mapChunkCache.AsReadOnly,
                multiNoise);

            return(CreateMeshFactory(multiNoise, voxelChunkPopulator, mapChunkCache));
        }
Esempio n. 3
0
 public void UpdateSettings(ColorSettings settings)
 {
     this.settings = settings;
     if (texture == null || texture.height != settings.biomeColorSettings.biomes.Length)
     {
         texture = new Texture2D(textureResolution, settings.biomeColorSettings.biomes.Length, TextureFormat.RGBA32, false);
     }
     biomeNoiseFilter = NoiseFactory.createNoiseFilter(settings.biomeColorSettings.noise);
 }
Esempio n. 4
0
 public NastyBiome(string baseDirectory, int size, NoiseFactory noiseFactory)
     : base(
         Path.Combine(baseDirectory, nameof(NastyBiome)),
         Biome.BurntForestColor, size, noiseFactory)
 {
     _featureNoise          = noiseFactory.GetFeatureRockNoise((float)0.06, (float)0.1);
     _generalLandscapeNoise = noiseFactory.GetCellularNoiseForLandscapeAddition((float)0.015);
     _mazeNoise             = noiseFactory.GetCellularNoiseForMaze();
 }
Esempio n. 5
0
        public TestBiome(string baseDirectory, int size, NoiseFactory noiseFactory)
            : base(Path.Combine(baseDirectory, nameof(TestBiome)),
                   Biome.DesertColor, size, noiseFactory)
        {
            _generalRollingBaseNoise = noiseFactory.GetRollingBaseLandscape((float)0.002);
            _featureRockNoise        = noiseFactory.GetFeatureRockNoise((float)0.06, (float)0.1);

            _generalLandscapeNoise = noiseFactory.GetPerlinFractalBillow((float)0.004);
            _cellNoise             = noiseFactory.GetRollingBaseLandscape((float)0.05); //noiseFactory.GetCellularNoiseForLandscapeAddition((float)0.015);
        }
        public static StreamingStageMeshFactory CreateCubes()
        {
            var stageIdentity = new StageIdentity("Test Stage");
            var multiNoise    = new NoiseFactory(seed: 0);

            var voxelChunkPopulator = new CubeVoxelGridChunkPopulator(
                new TerrainVoxel(TerrainMaterial.Stone, byte.MaxValue));

            return(CreateMeshFactory(multiNoise, voxelChunkPopulator.WrapWithAsync()));
        }
 public SettingsViewModel(NoiseFactory.NoiseParameters defaults)
 {
     SettingsChanged += () => { };
     _amplitude = defaults.Amplitude;
     _octaves = defaults.Octaves;
     _frequency = defaults.Frequency;
     _lacunarity = defaults.Lacunarity;
     _h = defaults.H;
     _offset = defaults.Offset;
     _gain = defaults.Gain;
 }
        public static StreamingStageMeshFactory CreateNoise()
        {
            var stageIdentity = new StageIdentity("Test Stage");
            var multiNoise    = new NoiseFactory(seed: 0);

            var voxelChunkPopulator = new NoiseWorldVoxelGridChunkPopulator(
                multiNoise.Create(0),
                noiseScaling: .05,
                numberOfOctaves: 2,
                material: TerrainMaterial.Grass);

            return(CreateMeshFactory(multiNoise, voxelChunkPopulator.WrapWithAsync()));
        }
 protected BiomeBase(
     string baseDirectory,
     Color baseColor,
     int size,
     NoiseFactory noiseFactory)
 {
     BaseDirectory = baseDirectory;
     _baseColor    = baseColor;
     _noiseFactory = noiseFactory;
     Size          = size;
     BaseLevel     = (ushort)7650;
     SeaLevel      = BaseLevel - (ushort.MaxValue / 255);
     if (!Directory.Exists(BaseDirectory))
     {
         Directory.CreateDirectory(BaseDirectory);
     }
 }
Esempio n. 10
0
    public ShapeGenerator(ShapeSettings settings, Interactor interaction, CraterGenerator craterGenerator)
    {
        this.settings = settings;
        noiseFilters  = new NoiseInterface[settings.noiseLayers.Length];

        this.interaction = interaction;
        this.masks       = new List <Dictionary <string, float> >();
        //this.masks.Add(DataChanger.arraysToDict(maskKeys, maskValues));

        this.maskKeys   = new List <string>();
        this.maskValues = new List <float>();

        for (int i = 0; i < noiseFilters.Length; i++)
        {
            masks.Add(new Dictionary <string, float>());
            noiseFilters[i] = NoiseFactory.createNoiseFilter(settings.noiseLayers[i].noiseSettings);
        }

        elevationMinMax         = new MinMax();
        this.craterGenerator    = craterGenerator;
        settings.zeroLvlIsOcean = true;
    }
        private static StreamingStageMeshFactory CreateMeshFactory(
            NoiseFactory noise, IAsyncChunkPopulator <IVoxelGridChunk> populator, IAsyncCompletable additional = null)
        {
            Contracts.Requires.That(noise != null);
            Contracts.Requires.That(populator != null);

            var voxelCache = CreateVoxelChunkCache(populator);
            var meshPool   = CreateMeshBuilderPool();

            var meshFactory = new ContourMeshFactory <TerrainSurfaceData>(
                VoxelChunkConfig,
                voxelCache.AsReadOnly,
                meshPool,
                new TerrainDualContourer <TerrainSurfaceData>(noise));

            var completable = new AggregateAsyncCompletable(voxelCache, new DisposableAsyncCompletable(meshPool));

            if (additional != null)
            {
                completable = new AggregateAsyncCompletable(additional, completable);
            }

            return(new StreamingStageMeshFactory(meshFactory, completable));
        }
Esempio n. 12
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                double[,] noise = null;

                //depending on the style selected, create some default noise values
                if (selectedNoiseStyle.Equals(NoiseStyles.Planar))
                {
                    noise = NoiseFactory.GeneratePlanar(module, imageWidth, imageHeight, -1, 1, -1, 1, true, true, 0);
                }
                if (selectedNoiseStyle.Equals(NoiseStyles.Cylindrical))
                {
                    noise = NoiseFactory.GenerateCylindrical(module, imageWidth, imageHeight, -1, 180, -1, 1, true, 0);
                }
                else
                {
                    noise = NoiseFactory.GenerateSpherical(module, imageWidth, imageHeight, worldSouth, worldNorth, worldWest, worldEast, true, 0);
                }

                // Generate the image from the nosie values

                System.Drawing.Rectangle areaToPaint = new System.Drawing.Rectangle(0, 0, imageWidth, imageHeight);
                Bitmap     bmp    = new Bitmap(imageWidth, imageHeight);
                BitmapData bmData = bmp.LockBits(areaToPaint, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                //Generate a second image to overlay "Hillshading" for the world style
                Bitmap     hillshadeBmp = new Bitmap(imageWidth, imageHeight);
                BitmapData hsbmData     = hillshadeBmp.LockBits(areaToPaint, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                int stride = imageWidth * 4;

                unsafe
                {
                    byte *ptr   = (byte *)bmData.Scan0.ToPointer();
                    byte *hsPtr = (byte *)hsbmData.Scan0.ToPointer();

                    for (int y = areaToPaint.Top; y < areaToPaint.Height; y++)
                    {
                        for (int x = areaToPaint.Left; x < areaToPaint.Width; x++)
                        {
                            double heightValue = noise[x, y];

                            System.Drawing.Color finalColor = System.Drawing.Color.Black;

                            if (selectedColorStyle.Equals(ColourStyles.Greyscale))
                            {
                                finalColor = GetGradientColor(System.Drawing.Color.Black, System.Drawing.Color.White, (float)heightValue);
                            }
                            else if (selectedColorStyle.Equals(ColourStyles.RedBlue))
                            {
                                finalColor = GetGradientColor(System.Drawing.Color.Blue, System.Drawing.Color.Red, (float)heightValue);
                            }
                            else
                            {
                                // "World" style
                                if (heightValue <= 0.5)
                                {
                                    finalColor = System.Drawing.Color.PowderBlue;
                                }
                                else if (heightValue >= 0.9)
                                {
                                    finalColor = GetGradientColor(System.Drawing.Color.LightGray, System.Drawing.Color.Snow, (float)heightValue);
                                }
                                else
                                {
                                    finalColor = GetGradientColor(System.Drawing.Color.LightGreen, System.Drawing.Color.ForestGreen, (float)heightValue);
                                }

                                System.Drawing.Color hillshading = Hillshade(noise, imageWidth, imageHeight, x, y, 10, 45, 315, 1);

                                hsPtr[(x * 4) + y * stride]     = ((Color)hillshading).B;
                                hsPtr[(x * 4) + y * stride + 1] = ((Color)hillshading).G;
                                hsPtr[(x * 4) + y * stride + 2] = ((Color)hillshading).R;

                                byte trans = 255;

                                if (heightValue > 0.5)
                                {
                                    trans = (byte)(((Color)hillshading).A * 0.3);                    // over land set transparency to 30%
                                }
                                else
                                {
                                    trans = (byte)(((Color)hillshading).A * 0.1);  // over water transparency to 10%
                                }
                                hsPtr[(x * 4) + y * stride + 3] = trans;
                            }

                            ptr[(x * 4) + y * stride]     = finalColor.B;
                            ptr[(x * 4) + y * stride + 1] = finalColor.G;
                            ptr[(x * 4) + y * stride + 2] = finalColor.R;
                            ptr[(x * 4) + y * stride + 3] = finalColor.A;
                        }
                    }
                }
                bmp.UnlockBits(bmData);
                hillshadeBmp.UnlockBits(hsbmData);

                if (selectedColorStyle.Equals(ColourStyles.World))
                {
                    Bitmap mergedResult = new Bitmap(imageWidth, imageHeight);

                    Graphics canvas = Graphics.FromImage(mergedResult);

                    canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    canvas.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                    canvas.DrawImage(hillshadeBmp, new Rectangle(0, 0, hillshadeBmp.Width, hillshadeBmp.Height), new Rectangle(0, 0, hillshadeBmp.Width, hillshadeBmp.Height), GraphicsUnit.Pixel);
                    canvas.Save();

                    previewBmp = mergedResult;
                }
                else
                {
                    previewBmp = bmp;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occured while generating the image preview. " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }