Base class for noise modules.
Inheritance: IDisposable
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="width">The width of the noise map.</param>
 /// <param name="height">The height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int width, int height, ModuleBase generator)
 {
     this.m_generator = generator;
     this.m_width = width;
     this.m_height = height;
     this.m_data = new float[width, height];
 }
 public LoadedModule(string id, ModuleBase module, Point location)
 {
     this.ID = id;
     this.Module = module;
     this.Location = location;
     Links = new List<string>();
 }
 public LoadedModule(string id, ModuleBase module, Point location, List<string> links)
 {
     this.ID = id;
     this.Module = module;
     this.Location = location;
     this.Links = links;
 }
	void RenderAndSetImage(ModuleBase generator)
	{
		var heightMapBuilder = new Noise2D(256, 256, generator);
		heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom);
		var image = heightMapBuilder.GetTexture(_gradient);
		renderer.material.mainTexture = image;
	}
        /// <summary>
        /// Generates a cylindrical projection of a point in the noise map.
        /// </summary>
        /// <param name="angle">The angle of the point.</param>
        /// <param name="height">The height of the point.</param>
        /// <returns>The corresponding noise map value.</returns>
        public static double GenerateCylindricalPoint(ModuleBase module, double angle, double height, int scale)
        {
            double x = System.Math.Cos(angle * Utils.DegreesToRadians());
            double y = height;
            double z = System.Math.Sin(angle * Utils.DegreesToRadians());

            return module.GetValue(x, y, z, scale);
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of Turbulence.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Turbulence(ModuleBase input)
     : base(1)
 {
     _xDistort = new Generator.Perlin();
     _yDistort = new Generator.Perlin();
     _zDistort = new Generator.Perlin();
     Modules[0] = input;
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of Turbulence.
 /// </summary>
 /// <param name="x">The perlin noise to apply on the x-axis.</param>
 /// <param name="y">The perlin noise to apply on the y-axis.</param>
 /// <param name="z">The perlin noise to apply on the z-axis.</param>
 /// <param name="power">The power of the turbulence.</param>
 /// <param name="input">The input module.</param>
 public Turbulence( Generator.Perlin x, Generator.Perlin y, Generator.Perlin z, double power, ModuleBase input)
     : base(1)
 {
     _xDistort = x;
     _yDistort = y;
     _zDistort = z;
     Modules[0] = input;
     Power = power;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="width">The width of the noise map.</param>
 /// <param name="height">The height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int width, int height, ModuleBase generator = null)
 {
     _generator = generator;
     _width = width;
     _height = height;
     _data = new float[width, height];
     _ucWidth = width + _ucBorder * 2;
     _ucHeight = height + _ucBorder * 2;
     _ucData = new float[width + _ucBorder * 2, height + _ucBorder * 2];
 }
    void NoiseSelector()
    {
        // Requires LibNoise in your project
        // https://github.com/ricardojmendez/LibNoise.Unity

        switch (noiseType)
        {
            case NoiseMode.Billow:
                var billow = new Billow();
                billow.Seed = seed;
                billow.Quality = quality;
                billow.OctaveCount = _octaveCount;
                billow.Frequency = _frecuency * 0.1;
                billow.Lacunarity = _lacunarity;
                billow.Persistence = _persistence;
                generate = billow;
                break;
            case NoiseMode.Perlin:
                var perlin = new Perlin();
                perlin.Seed = seed;
                perlin.Quality = quality;
                perlin.OctaveCount = _octaveCount;
                perlin.Frequency = _frecuency * 0.1;
                perlin.Lacunarity = _lacunarity;
                perlin.Persistence = _persistence;
                generate = perlin;
                break;
            case NoiseMode.RidgedMultifractal:
                var multiFractal = new RidgedMultifractal();
                multiFractal.Seed = seed;
                multiFractal.Quality = quality;
                multiFractal.OctaveCount = _octaveCount;
                multiFractal.Frequency = _frecuency * 0.1;
                multiFractal.Lacunarity = _lacunarity;
                generate = multiFractal;
                break;
            case NoiseMode.Voronoi:
                var voroni = new Voronoi();
                voroni.Seed = seed;
                voroni.Frequency = _frecuency;
                voroni.Displacement = _displacement;
                generate = voroni;
                break;
            default:
                break;
        }
    }
Exemple #10
0
    /// <summary>
    /// Don't touch any data in the job class after initialization until IsDone is true.	/// </summary>
    /// <param name="_startX"> x start position.</param>
    /// <param name="_startY"> y start position.</param>
    /// <param name="_xStepSize"> step width.</param>
    /// <param name="_yStepSize"> step height.</param>
    /// <param name="_mapX"> map width.</param>
    /// <param name="_mapY"> map height.</param>
    /// <param name="_perlinScale">_noise scale.</param>
    /// <param name="_mult">multiplies output height.</param>
    /// <param name="libNoiseModual">lib Noise Modual</param>
    public LibNoiseJob(int _startX, int _startY, int _xStepSize, int _yStepSize, int _mapX, int _mapY, float _perlinScale, float _mult, LibNoise.ModuleBase libNoiseModual) : base()
    {
        OutData          = new float[(_mapX * _mapY)];
        heightData       = new float[((_mapX + 2) * (_mapY + 2))];
        OutNormals       = new UnityEngine.Vector3[(_mapX * _mapY)];
        this.mapX        = _mapX;
        this.mapY        = _mapY;
        this.xStepSize   = _xStepSize;
        this.yStepSize   = _yStepSize;
        this.startX      = _startX;
        this.startY      = _startY;
        this.perlinScale = _perlinScale;
        this.mult        = _mult;

        generator = libNoiseModual;
        StartJob();
    }
    /// <summary>
    /// Don't touch any data in the job class after initialization until IsDone is true.	/// </summary>
    /// <param name="_startX"> x start position.</param>
    /// <param name="_startY"> y start position.</param>
    /// <param name="_xStepSize"> step width.</param>
    /// <param name="_yStepSize"> step height.</param>
    /// <param name="_mapX"> map width.</param>
    /// <param name="_mapY"> map height.</param>
    /// <param name="_perlinScale">_noise scale.</param>
    /// <param name="_mult">multiplies output height.</param>
    /// <param name="libNoiseModual">lib Noise Modual</param>
    public LibNoiseJob(int _startX, int _startY, int _xStepSize, int _yStepSize, int _mapX, int _mapY, float _perlinScale, float _mult, LibNoise.ModuleBase libNoiseModual)
        : base()
    {
        OutData = new float[(_mapX * _mapY)];
        heightData = new float[((_mapX+2) * (_mapY+2))];
        OutNormals = new UnityEngine.Vector3[(_mapX * _mapY)];
        this.mapX = _mapX;
        this.mapY = _mapY;
        this.xStepSize = _xStepSize;
        this.yStepSize = _yStepSize;
        this.startX = _startX;
        this.startY = _startY;
        this.perlinScale = _perlinScale;
        this.mult = _mult;

        generator = libNoiseModual;
        StartJob();
    }
        /// <summary>
        /// Generates a cylindrical projection of the noise map. Result will be buffered with extra data
        /// </summary>
        /// <param name="angleMin">The maximum angle of the clip region.</param>
        /// <param name="angleMax">The minimum angle of the clip region.</param>
        /// <param name="heightMin">The minimum height of the clip region.</param>
        /// <param name="heightMax">The maximum height of the clip region.</param>
        public static double[,] GenerateCylindrical(ModuleBase module, int width, int height, double angleMin, double angleMax, double heightMin, double heightMax, bool isNormalized = true, int scale = 0)
        {
            int ucWidth = width + UC_BORDER * 2;
            int ucHeight = height + UC_BORDER * 2;
            double[,] data = new double[ucWidth, ucHeight];

            if (angleMax <= angleMin || heightMax <= heightMin) throw new ArgumentException("Invalid angle or height parameters");
            if (module == null) throw new ArgumentNullException("Generator is null");

            double ae = angleMax - angleMin;
            double he = heightMax - heightMin;
            double xd = ae / ((double)(width - UC_BORDER));
            double yd = he / ((double)(height - UC_BORDER));
            double ca = angleMin;

            List<ParallelProcessHelper> processValues = new List<ParallelProcessHelper>();

            for (int x = 0; x < ucWidth; x++)
            {
                double ch = heightMin;
                for (int y = 0; y < ucHeight; y++)
                {
                    processValues.Add(new ParallelProcessHelper(x, y, ca, ch));
                    ch += yd;
                }
                ca += xd;
            }

            var rangePartitioner = Partitioner.Create(0, processValues.Count);
            Parallel.ForEach(rangePartitioner, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, range =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    ParallelProcessHelper processHelper = processValues[i];
                    double sample = GenerateCylindricalPoint(module, processHelper.innerValue, processHelper.outerValue, scale);
                    if (isNormalized) sample = (sample + 1) / 2;

                    data[processHelper.x, processHelper.y] = sample;
                }
            });

            return data;
        }
        public PreviewWindow(ImpObservableCollection<object> nodes)
        {
            InitializeComponent();

            // clone the module by generating a new module via serialization
            // this is not the nicest way of doing this, so we'll improve it later with a proper clone mechanism
            // for now though, it works quite well
            XmlDocument doc = LibnoiseFileUtils.DiagramToXML(nodes);
            ModuleBase module = LibnoiseFileUtils.LoadLibnoiseXml(doc);
            SetSeeds(module, 0);

            this.nodes = nodes;
            this.module = module;

            imageWidth = 512;
            imageHeight = 512;

            selectedNoiseStyle = NoiseStyles.Planar;
            selectedColorStyle = ColourStyles.Greyscale;

            GeneratePreview();
        }
    public void Heights(Terrain terrain, LibNoise.ModuleBase _noise)
    {
        float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
        for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
        {
            for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
            {
                var   point = new Vector3(i, k, 0f) / 100;
                float value = (float)_noise.GetValue(point);

                if (Island == true)
                {
                    value = (float)(value + a - b * Mathf.Pow((float)d, (float)c));
                }

                value = Mathf.Clamp01((value + 1) / 2f);

                heights[i, k] = value / 10f;
            }
        }


        terrain.terrainData.SetHeights(0, 0, heights);
    }
 /// <summary>
 /// Generates a planar projection of a point in the noise map.
 /// </summary>
 /// <param name="x">The position on the x-axis.</param>
 /// <param name="y">The position on the y-axis.</param>
 /// <returns>The corresponding noise map value.</returns>
 public static double GeneratePlanarPoint(ModuleBase module, double x, double y, int scale = 0)
 {
     return module.GetValue(x, 0.0, y, scale);
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of Turbulence.
 /// </summary>
 public Turbulence(double power, ModuleBase input)
     : this(new Generator.Perlin(), new Generator.Perlin(), new Generator.Perlin(), power, input)
 {
 }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="size">The width and height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int size, ModuleBase generator)
     : this(size, size, generator)
 {
 }
 public LoadedModule(string id, ModuleBase module)
 {
     this.ID = id;
     this.Module = module;
     Links = new List<string>();
 }
 public CaveLayer()
 {
     noise = new LibNoise.Generator.RidgedMultifractal (0.06, 2.0, 6, (int) (Random.value * 100000), LibNoise.QualityMode.Medium);
 }
 public LibnoiseNode(ModuleBase sourceModule)
 {
     LibnoiseModule = sourceModule;
     ID = Guid.NewGuid().ToString();
     Inputs = new LibnoiseNode[5];
 }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="size">The width and height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int size, ModuleBase generator)
     : this(size, size, generator)
 {
 }
 public LibnoiseNode(ModuleBase sourceModule, string ID)
 {
     LibnoiseModule = sourceModule;
     this.ID = ID;
 }
        /// <summary>
        /// Generates a non-seamless planar projection of the noise map. Result will be buffered with extra data
        /// </summary>
        /// <param name="left">The clip region to the left.</param>
        /// <param name="right">The clip region to the right.</param>
        /// <param name="top">The clip region to the top.</param>
        /// <param name="bottom">The clip region to the bottom.</param>
        /// <param name="isSeamless">Indicates whether the resulting noise map should be seamless.</param>
        public static double[,] GeneratePlanar(ModuleBase module, int width, int height, double left, double right, double top, double bottom, bool isSeamless = true, bool isNormalized = true, int scale = 0)
        {
            int ucWidth = width + UC_BORDER * 2;
            int ucHeight = height + UC_BORDER * 2;
            double[,] data = new double[ucWidth, ucHeight];

            if (right <= left || bottom <= top) throw new ArgumentException("Invalid right/left or bottom/top combination");
            if (module == null) throw new ArgumentNullException("Base Module is null");

            double xe = right - left;
            double ze = bottom - top;
            double xd = xe / ((double)width - UC_BORDER);
            double zd = ze / ((double)height - UC_BORDER);
            double xc = left;

            for (var x = 0; x < ucWidth; x++)
            {
                double zc = top;
                for (var y = 0; y < ucHeight; y++)
                {
                    double fv;

                    if (isSeamless) fv = GeneratePlanarPoint(module, xc, zc, scale);
                    else
                    {
                        double swv = GeneratePlanarPoint(module, xc, zc, scale);
                        double sev = GeneratePlanarPoint(module, xc + xe, zc, scale);
                        double nwv = GeneratePlanarPoint(module, xc, zc + ze, scale);
                        double nev = GeneratePlanarPoint(module, xc + xe, zc + ze, scale);

                        double xb = 1.0 - ((xc - left) / xe);
                        double zb = 1.0 - ((zc - top) / ze);

                        double z0 = Utils.InterpolateLinear(swv, sev, xb);
                        double z1 = Utils.InterpolateLinear(nwv, nev, xb);

                        fv = Utils.InterpolateLinear(z0, z1, zb);
                    }

                    if (isNormalized) fv = (fv + 1) / 2;

                    data[x, y] = fv;
                    zc += zd;
                }
                xc += xd;
            }

            return data;
        }
        private void PreviewButton_Click(object sender, RoutedEventArgs e)
        {
            // validate the height/width first
            bool widthValid = Int32.TryParse(WidthBox.Text, out imageWidth);
            bool heightValid = Int32.TryParse(HeightBox.Text, out imageHeight);
            bool seedValid = Int32.TryParse(SeedBox.Text, out seed);

            if (!widthValid) WidthBox.BorderBrush = System.Windows.Media.Brushes.Red;
            else WidthBox.BorderBrush = System.Windows.Media.Brushes.CornflowerBlue;

            if (!heightValid) HeightBox.BorderBrush = System.Windows.Media.Brushes.Red;
            else HeightBox.BorderBrush = System.Windows.Media.Brushes.CornflowerBlue;

            if (!seedValid) SeedBox.BorderBrush = System.Windows.Media.Brushes.Red;
            else SeedBox.BorderBrush = System.Windows.Media.Brushes.CornflowerBlue;

            string noiseStyle = ((ComboBoxItem)NoiseStyle.SelectedItem).Content.ToString();
            string colorStyle = ((ComboBoxItem)ColourStyle.SelectedItem).Content.ToString();

            if (noiseStyle.Equals("Planar")) selectedNoiseStyle = NoiseStyles.Planar;
            else if (noiseStyle.Equals("Cylindrical")) selectedNoiseStyle = NoiseStyles.Cylindrical;
            else selectedNoiseStyle = NoiseStyles.Spherical;

            if (colorStyle.Equals("Grayscale")) selectedColorStyle = ColourStyles.Greyscale;
            else if (colorStyle.Equals("Blue/Red")) selectedColorStyle = ColourStyles.RedBlue;
            else selectedColorStyle = ColourStyles.World;

            if (seedValid)
            {
                // clone the module by generating a new module via serialization
                // this is not the nicest way of doing this, so we'll improve it later with a proper clone mechanism
                // for now though, it works quite well
                XmlDocument doc = LibnoiseFileUtils.DiagramToXML(nodes);
                ModuleBase module = LibnoiseFileUtils.LoadLibnoiseXml(doc);
                SetSeeds(module, seed);
                this.module = module;
            }

            if (widthValid && heightValid && seedValid) GeneratePreview();
        }
 /// <summary>
 /// Generates a spherical projection of a point in the noise map.
 /// </summary>
 /// <param name="lat">The latitude of the point.</param>
 /// <param name="lon">The longitude of the point.</param>
 /// <returns>The corresponding noise map value.</returns>
 public static double GenerateSphericalPoint(ModuleBase module, double lat, double lon, int scale)
 {
     double r = System.Math.Cos(Utils.DegreesToRadians() * lat);
     return module.GetValue(r * System.Math.Cos(Utils.DegreesToRadians() * lon), System.Math.Sin(Utils.DegreesToRadians() * lat), r * System.Math.Sin(Utils.DegreesToRadians() * lon), scale);
 }
        /// <summary>
        /// Generates a spherical projection of the noise map.
        /// </summary>
        /// <param name="south">The clip region to the south.</param>
        /// <param name="north">The clip region to the north.</param>
        /// <param name="west">The clip region to the west.</param>
        /// <param name="east">The clip region to the east.</param>
        public static double[,] GenerateSpherical(ModuleBase module, int width, int height, double south, double north, double west, double east, bool isNormalized = true, int scale = 0)
        {
            int ucWidth = width + UC_BORDER * 2;
            int ucHeight = height + UC_BORDER * 2;
            double[,] data = new double[ucWidth, ucHeight];

            if (east <= west || north <= south) throw new ArgumentException("Invalid east/west or north/south combination");
            if (module == null) throw new ArgumentNullException("Generator is null");

            double loe = east - west;
            double lae = north - south;
            double xd = loe / ((double)(width - UC_BORDER));
            double yd = lae / ((double)(height - UC_BORDER));
            double clo = west;

            List<ParallelProcessHelper> processValues = new List<ParallelProcessHelper>();

            // Create parallel process helpers with the values for each sample
            for (int x = 0; x < ucWidth; x++)
            {
                double cla = south;
                for (int y = 0; y < ucHeight; y++)
                {
                    processValues.Add(new ParallelProcessHelper(x, y, cla, clo));
                    cla += yd;
                }
                clo += xd;
            }

            // now that we have each sample calculated, run through and fetch the noise
            // Parallelism should be set somwhere from 1 to Processor Count / 2.
            var rangePartitioner = Partitioner.Create(0, processValues.Count);
            Parallel.ForEach(rangePartitioner, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, range =>
            {
                for (int i = range.Item1; i < range .Item2; i++)
                {
                    ParallelProcessHelper processHelper = processValues[i];
                    double sample = GenerateSphericalPoint(module, processHelper.innerValue, processHelper.outerValue, scale);
                    if (isNormalized) sample = (sample + 1) / 2;

                    data[processHelper.x, processHelper.y] = sample;
                }
            });

            return data;
        }
 // Creates a new node in the network at the current mouse location.
 private void CreateNode(ModuleBase module)
 {
     //var newNodePosition = Mouse.GetPosition(networkControl);
     NodeViewModel nvw = this.ViewModel.CreateNode(module, contextMenuPosition, true);
 }
        // simple recursive call to cycle through a selected module
        // and their connected children and set the seed value to the
        // seed selected by the user. If a seed value already exists,
        // then leave it alone... or maybe add it together?
        private void SetSeeds(ModuleBase module, int seed)
        {
            switch (module.GetType().Name)
            {
                case "Billow":
                    if (((Billow)module).Seed == 0) ((Billow)module).Seed = seed;
                    break;
                case "Perlin":
                    if (((Perlin)module).Seed == 0) ((Perlin)module).Seed = seed;
                    break;
                case "RidgedMultifractal":
                    if (((RidgedMultifractal)module).Seed == 0) ((RidgedMultifractal)module).Seed = seed;
                    break;
                case "Voronoi":
                    if (((Voronoi)module).Seed == 0) ((Voronoi)module).Seed = seed;
                    break;
                case "Turbulence":
                    if (((Turbulence)module).Seed == 0) ((Turbulence)module).Seed = seed;
                    break;
                default:
                    break;
            }

            if (module.Modules != null && module.Modules.Count() > 0)
            {
                foreach (ModuleBase mb in module.Modules)
                {
                    SetSeeds(mb, seed);
                }
            }
        }
        /// <summary>
        /// Create a node and add it to the view-model.
        /// </summary>
        public NodeViewModel CreateNode(ModuleBase moduleBase, Point nodeLocation, bool centerNode)
        {
            System.Windows.Media.Brush generatorBrush = new LinearGradientBrush(Colors.White, Colors.Orange, 90.0);
            System.Windows.Media.Brush operatorBrush = new LinearGradientBrush(Colors.White, Colors.PowderBlue, 90.0);
            System.Windows.Media.Brush finalBrush = new LinearGradientBrush(Colors.White, Colors.YellowGreen, 90.0);

            NodeViewModel node = new NodeViewModel(new LibnoiseNode(moduleBase));
            node.Module.ID = moduleBase.GetType().Name + "_" + (Network.Nodes.Count(n => n.Module.ModuleType.Equals(moduleBase.GetType().Name)) + 1);
            node.X = nodeLocation.X;
            node.Y = nodeLocation.Y;

            node.StrokeBrush = System.Windows.Media.Brushes.Black;

            // this can be simplified, for sure, but I left in the giant ugly switch
            // in the event I want to do something unique by type, such as any additional
            // colouring or whatever. It's a little gross to look at, but it does the job
            switch (moduleBase.GetType().Name)
            {
                    // Generators should not have any input values
                case "Billow":
                    node.FillBrush = generatorBrush;
                    break;
                case "Checker":
                    node.FillBrush = generatorBrush;
                    break;
                case "Const":
                    node.FillBrush = generatorBrush;
                    break;
                case "Cylinders":
                    node.FillBrush = generatorBrush;
                    break;
                case "Perlin":
                    node.FillBrush = generatorBrush;
                    break;
                case "RidgedMultifractal":
                    node.FillBrush = generatorBrush;
                    break;
                case "Spheres":
                    node.FillBrush = generatorBrush;
                    break;
                case "Voronoi":
                    node.FillBrush = generatorBrush;
                    break;
                case "Abs":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Add":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Blend":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    node.InputConnectors.Add(new ConnectorViewModel("Operator"));
                    break;
                case "Cache":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Clamp":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Curve":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Displace":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Primary"));
                    node.InputConnectors.Add(new ConnectorViewModel("X"));
                    node.InputConnectors.Add(new ConnectorViewModel("Y"));
                    node.InputConnectors.Add(new ConnectorViewModel("Z"));
                    break;
                case "Exponent":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Invert":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Max":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Min":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Multiply":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Power":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Rotate":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Scale":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "ScaleBias":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Select":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Primary"));
                    node.InputConnectors.Add(new ConnectorViewModel("Secondary"));
                    node.InputConnectors.Add(new ConnectorViewModel("Controller"));
                    break;
                case "Subtract":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Left"));
                    node.InputConnectors.Add(new ConnectorViewModel("Right"));
                    break;
                case "Terrace":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Translate":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Turbulence":
                    node.FillBrush = operatorBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                case "Final":
                    node.FillBrush = finalBrush;
                    node.InputConnectors.Add(new ConnectorViewModel("Input"));
                    break;
                default:
                    break;
            }

            // for the 'Final' node, don't add any outputs.
            if (!moduleBase.GetType().Name.Equals("Final"))
            {
                node.OutputConnectors.Add(new ConnectorViewModel("Output"));
            }

            if (centerNode)
            {
                //
                // We want to center the node.
                //
                // For this to happen we need to wait until the UI has determined the
                // size based on the node's data-template.
                //
                // So we define an anonymous method to handle the SizeChanged event for a node.
                //
                // Note: If you don't declare sizeChangedEventHandler before initializing it you will get
                //       an error when you try and unsubscribe the event from within the event handler.
                //
                EventHandler<EventArgs> sizeChangedEventHandler = null;
                sizeChangedEventHandler =
                    delegate(object sender, EventArgs e)
                    {
                        //
                        // This event handler will be called after the size of the node has been determined.
                        // So we can now use the size of the node to modify its position.
                        //
                        node.X -= node.Size.Width / 2;
                        node.Y -= node.Size.Height / 2;

                        //
                        // Don't forget to unhook the event, after the initial centering of the node
                        // we don't need to be notified again of any size changes.
                        //
                        node.SizeChanged -= sizeChangedEventHandler;
                    };

                //
                // Now we hook the SizeChanged event so the anonymous method is called later
                // when the size of the node has actually been determined.
                //
                node.SizeChanged += sizeChangedEventHandler;
            }

            //
            // Add the node to the view-model.
            //
            this.Network.Nodes.Add(node);

            return node;
        }
Exemple #30
0
		public static void generateHeightmap(GameObject terrObject, ModuleBase modbase, float alphaAmount, float noiseAmp){
			Vector3 gopos = terrObject.transform.position;
	        float cwidth = terrObject.GetComponent<Terrain>().terrainData.size.x;
	        int resolution = terrObject.GetComponent<Terrain>().terrainData.heightmapResolution;
			float[,] hmap = new float[resolution,resolution];
	        double yoffset = 0 - (gopos.x / cwidth);
	        double xoffset = (gopos.z / cwidth);
	        Noise2D tmpNoiseMap = new Noise2D(resolution, resolution, modbase);
	        tmpNoiseMap.GeneratePlanar(xoffset, (xoffset) + (1f / resolution) * (resolution + 1), -yoffset, (-yoffset) + (1f / resolution) * (resolution + 1));
	        if (alphaAmount == 1.0f)
	        {
	            for (int hY = 0; hY < resolution; hY++)
	            {
	                for (int hX = 0; hX < resolution; hX++)
	                {
	                    hmap[hX, hY] = ((tmpNoiseMap[hX, hY]*0.5f) + 0.5f) * noiseAmp;
	                }
	            }
	        }
	        else
	        {
	            hmap = terrObject.GetComponent<Terrain>().terrainData.GetHeights(0, 0, resolution, resolution);
	            for (int hY = 0; hY < resolution; hY++)
	            {
	                for (int hX = 0; hX < resolution; hX++)
	                {
	                    hmap[hX, hY] = ((1.0f - alphaAmount) * hmap[hX, hY]) + (alphaAmount * (((tmpNoiseMap[hX, hY]*0.5f) + 0.5f) * noiseAmp));
	                }
	            }
	        }
	        terrObject.GetComponent<Terrain>().terrainData.SetHeights(0, 0, hmap);
	    }