Esempio n. 1
0
 public override void Attach(LinkType type, Adapter a)
 {
     if (type == LinkType.In2) noise.SourceModule = a.Module;
       if (type == LinkType.In1) noise.XDisplaceModule = a.Module;
       if (type == LinkType.In3) noise.ZDisplaceModule = a.Module;
       if (type == LinkType.In4) noise.YDisplaceModule = a.Module;
 }
Esempio n. 2
0
 public override void Attach(LinkType type, Adapter a)
 {
     if (type != LinkType.In1) return; noise.SourceModule = a.Module;
 }
Esempio n. 3
0
 public override void Attach(LinkType type, Adapter a)
 {
     if (type == LinkType.In1) noise.SourceModule1 = a.Module;
       if (type == LinkType.In2) noise.SourceModule2 = a.Module;
       if (type == LinkType.In3) noise.WeightModule = a.Module;
 }
Esempio n. 4
0
 public virtual void Attach(LinkType type, Adapter a)
 {
 }
Esempio n. 5
0
 public override void Attach(LinkType type, Adapter a)
 {
     if (type == LinkType.In1) noise.BaseModule = a.Module;
       if (type == LinkType.In2) noise.PowerModule = a.Module;
 }
Esempio n. 6
0
        private void setModuleType(string type)
        {
            Adapter old = mNoise;

              mSkip = false;
              LinkTips.Reset();

              mNoiseType = type;
              if (mNoiseType as string == "Perlin")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Quality", Min = 1, Max = 3, Incr = 1, Value = 2, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Octaves", Min = 1, Max = 30, Incr = 1, Value = 6, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 16, Incr = 1, Value = 1, Rounding = 0 });
            a.Add(new Parameter() { Name = "Persistence", Min = 0, Max = 1, Incr = 0.01, Rounding = 2, Value = 0.5 });
            a.Add(new Parameter() { Name = "Lacunarity", Min = 1, Max = 4, Incr = 0.1, Value = 2, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterPerlin();
              }

              else if (mNoiseType as string == "Billow")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Quality", Min = 1, Max = 3, Incr = 1, Value = 2, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Octaves", Min = 1, Max = 30, Incr = 1, Value = 6, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 16, Incr = 1, Value = 1, Rounding = 0 });
            a.Add(new Parameter() { Name = "Persistence", Min = 0, Max = 1, Incr = 0.01, Rounding = 2, Value = 0.5 });
            a.Add(new Parameter() { Name = "Lacunarity", Min = 1, Max = 4, Incr = 0.1, Value = 2, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterBillow();
              }

              else if (mNoiseType as string == "Checkerboard")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterCheckerboard();
              }

              else if (mNoiseType as string == "Constant")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Value", Min = 0, Max = 1, Incr = 0.01, Value = 0, Rounding = 2 });
            Parameters = a;
            mNoise = new AdapterConstant();
              }

              else if (mNoiseType as string == "Cylinders")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterCylinders();
              }
              else if (mNoiseType as string == "Spheres")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterSpheres();
              }

              else if (mNoiseType as string == "Gradient")
              {
            xLinks.SetLinks(0);
            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Axis", Min = 1, Max = 3, Incr = 1, Value = 1, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Lower", Min = 0, Max = 1, Incr = 0.01, Value = 0, Rounding = 2 });
            a.Add(new Parameter() { Name = "Upper", Min = 0, Max = 1, Incr = 0.01, Value = 1, Rounding = 2 });
            Parameters = a;
            mNoise = new AdapterGradient();
              }
              else if (mNoiseType as string == "Ridged Multifractal")
              {
            xLinks.SetLinks(0);

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Quality", Min = 1, Max = 3, Incr = 1, Value = 2, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Octaves", Min = 1, Max = 30, Incr = 1, Value = 6, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 16, Incr = 1, Value = 1, Rounding = 0 });
            a.Add(new Parameter() { Name = "Lacunarity", Min = 1, Max = 4, Incr = 0.1, Value = 2, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterRidged();
              }
              else if (mNoiseType as string == "Voronoi")
              {
            xLinks.SetLinks(0);

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Distance", Min = 0, Max = 1, Incr = 1, Value = 0, Rounding = 0 });
            a.Add(new Parameter() { Name = "Displacement", Min = 1, Max = 30, Incr = 1, Value = 1, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Frequency", Min = 1, Max = 16, Incr = 1, Value = 1, Rounding = 0 });
            Parameters = a;
            mNoise = new AdapterVoronoi();
              }
              else if (mNoiseType as string == "Absolute")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterAbs();
              }
              else if (mNoiseType as string == "Terrace")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Invert", Min = 0, Max = 1, Incr = 1, Value = 0, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Point", Min = -5, Max = 5, Incr = 0.01, Value = 1, Rounding = 2 });
            Parameters = a;
            mNoise = new AdapterTerrace();
              }
              else if (mNoiseType as string == "Curve")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "PointX", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0 });
            a.Add(new Parameter() { Name = "PointY", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0 });
            a.Add(new Parameter() { Name = "PointX", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0.3 });
            a.Add(new Parameter() { Name = "PointY", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0.3 });
            a.Add(new Parameter() { Name = "PointX", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0.6 });
            a.Add(new Parameter() { Name = "PointY", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 0.6 });
            a.Add(new Parameter() { Name = "PointX", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 1 });
            a.Add(new Parameter() { Name = "PointY", Min = -5, Max = 5, Incr = 0.01, Rounding = 2, Value = 1 });
            Parameters = a;
            mNoise = new AdapterCurve();
              }
              else if (mNoiseType as string == "Clamp")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Lower", Min = -5, Max = 5, Incr = 0.01, Value = -1, Rounding = 2 });
            a.Add(new Parameter() { Name = "Upper", Min = -5, Max = 5, Incr = 0.01, Value = 1, Rounding = 2 });
            Parameters = a;
            mNoise = new AdapterClamp();
              }
              else if (mNoiseType as string == "Exponent")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Exponent", Min = 1, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterExponent();
              }
              else if (mNoiseType as string == "Invert")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterInvert();
              }
              else if (mNoiseType as string == "ScaleBias")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Scale", Min = 0, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            a.Add(new Parameter() { Name = "Bias", Min = -5, Max = 5, Incr = 0.1, Value = 0, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterScaleBias();
              }
              else if (mNoiseType as string == "Displace")
              {
            xLinks.SetLinks(4);
            LinkTips.In2 = "Source";
            LinkTips.In1 = "X Displace";
            LinkTips.In3 = "Z Displace";
            LinkTips.In4 = "Y Displace";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterDisplace();
              }
              else if (mNoiseType as string == "Invert Input")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterInvertInput();
              }
              else if (mNoiseType as string == "Rotate")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "X Angle", Min = 0, Max = 360, Incr = 1, Value = 0, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Y Angle", Min = 0, Max = 360, Incr = 1, Value = 0, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Z Angle", Min = 0, Max = 360, Incr = 1, Value = 0, Rounding = 0, Typeable = Visibility.Collapsed });
            Parameters = a;
            mNoise = new AdapterRotate();
              }
              else if (mNoiseType as string == "Scale")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "X", Min = -10, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            a.Add(new Parameter() { Name = "Y", Min = -10, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            a.Add(new Parameter() { Name = "Z", Min = -10, Max = 10, Incr = 0.1, Value = 1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterScale();
              }
              else if (mNoiseType as string == "Translate")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "X", Min = -10, Max = 10, Incr = 0.1, Value = 0, Rounding = 1 });
            a.Add(new Parameter() { Name = "Y", Min = -10, Max = 10, Incr = 0.1, Value = 0, Rounding = 1 });
            a.Add(new Parameter() { Name = "Z", Min = -10, Max = 10, Incr = 0.1, Value = 0, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterTranslate();
              }
              else if (mNoiseType as string == "Turbulence")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "Power", Min = 0, Max = 8, Incr = 0.1, Value = 1, Rounding = 1 });
            a.Add(new Parameter() { Name = "Roughness", Min = 1, Max = 30, Incr = 1, Value = 3, Rounding = 0, Typeable = Visibility.Collapsed });
            a.Add(new Parameter() { Name = "Frequency", Min = 0, Max = 8, Incr = 0.1, Value = 1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterTurbulence();
              }
              else if (mNoiseType as string == "Add")
              {
            xLinks.SetLinks(2);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterAdd();
              }
              else if (mNoiseType as string == "Max")
              {
            xLinks.SetLinks(2);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterMax();
              }
              else if (mNoiseType as string == "Min")
              {
            xLinks.SetLinks(2);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterMin();
              }
              else if (mNoiseType as string == "Multiply")
              {
            xLinks.SetLinks(2);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterMultiply();
              }
              else if (mNoiseType as string == "Power")
              {
            xLinks.SetLinks(2);
            LinkTips.In1 = "Base Module";
            LinkTips.In2 = "Power Module";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterPower();
              }
              else if (mNoiseType as string == "Blend")
              {
            xLinks.SetLinks(3);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";
            LinkTips.In3 = "Weight Module";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterBlend();
              }
              else if (mNoiseType as string == "Select")
              {
            xLinks.SetLinks(3);
            LinkTips.In1 = "Source A";
            LinkTips.In2 = "Source B";
            LinkTips.In3 = "Control Module";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            a.Add(new Parameter() { Name = "EdgeFalloff", Min = 0, Max = 1, Incr = 0.01, Value = 0, Rounding = 2 });
            a.Add(new Parameter() { Name = "UpperBound", Min = -5, Max = 5, Incr = 0.1, Value = 1, Rounding = 1 });
            a.Add(new Parameter() { Name = "LowerBound", Min = -5, Max = 5, Incr = 0.1, Value = -1, Rounding = 1 });
            Parameters = a;
            mNoise = new AdapterSelect();
              }
              else if (mNoiseType as string == "Cache")
              {
            xLinks.SetLinks(1);
            LinkTips.In1 = "Source";

            ObservableCollection<Parameter> a = new ObservableCollection<Parameter>();
            Parameters = a;
            mNoise = new AdapterCache();
            mSkip = true;
              }

              xLinks.DataContext = LinkTips;
              xLinks.xGrid.Height = xLinks.ActualHeight / 2;
              LinkTips.Signal();

              if (old != null)
              {
            mNoise.Attach(LinkType.In1, old.Detatch(LinkType.In1));
            mNoise.Attach(LinkType.In2, old.Detatch(LinkType.In2));
            mNoise.Attach(LinkType.In3, old.Detatch(LinkType.In3));
              }

              ShadowParams();

              mNoise.Seed();
              OnRaise();
              OnRelink();
              OnNeedApply();
        }
Esempio n. 7
0
 public void Attach(LinkType type, Adapter a)
 {
     if (mNoise != null) mNoise.Attach(type, a);
 }
Esempio n. 8
0
        public BitmapSource Render(Adapter noise, GradientDef gradient, bool redraw = false)
        {
            if (noise == null) return null;
              if (gradient == null) return null;
              if (pixelData == null) return null;

              // draw the pixels scaled to color range - we need to know min max
              double xInc = (double)Boundary.Object.W / (double)width;
              double yInc = (double)Boundary.Object.H / (double)height;
              double x = Boundary.Object.X;
              double y = Boundary.Object.Y;

              BitmapSource bitmap = null;
              System.Windows.Media.PixelFormat pf = System.Windows.Media.PixelFormats.Rgb24;
              int rawStride;
              rawStride = width * 3;

              if (!mNormal)
              {
            min = 1000000;
            max = -1000000;
              }

              Color c = new Color();

              // n is the index into noiseData
              // i,j are indexes into the bitmap data - range of the widow size
              // x,y are indexes into the noise module to get the value - range of the bounds
              int n = 0;
              for (int j = 0; j < height; ++j)
              {
            int yIndex = j * rawStride;
            for (int i = 0; i < rawStride; i += 3)
            {
              double val = 0;
              if (redraw)
            val = noiseData[n++];
              else
              {
            if (mTile)
            {
              double swValue, seValue, neValue;
              swValue = noise.GetValue(x, y);
              seValue = noise.GetValue(Boundary.Object.W - x, y);
              neValue = noise.GetValue(x, Boundary.Object.H - y);
              double mirrorx = (swValue + seValue) / 2;
              double mirrory = (swValue + neValue) / 2;
              // lerp between mirror and real
              double xloc = (x - Boundary.Object.X) / Boundary.Object.W;
              double yloc = (y - Boundary.Object.Y) / Boundary.Object.H;
              double factorx = Math.Abs(0.5 - xloc) * 2;
              double factory = Math.Abs(0.5 - yloc) * 2;
              if (Math.Abs(factorx - factory) < 0.1)
              {
                // calculate how much towards x is it
                double factor = ((factorx - factory) / 0.1 + 1) / 2;
                double valx = (mirrorx * factorx + swValue * (1 - factorx));
                double valy = (mirrory * factory + swValue * (1 - factory));
                val = (valx * factor + valy * (1 - factor));
              }
              else
              {
                if (factorx > factory)
                  val = (mirrorx * factorx + swValue * (1 - factorx));
                else
                  val = (mirrory * factory + swValue * (1 - factory));
              }
            }
            else
              val = noise.GetValue(x, y);
            noiseData[n++] = val;
              }

              if (!mNormal)
              {
            if (val < min) min = val;
            if (val > max) max = val;
              }

              if (!mShadow)
              {
            if (mNormal) val = (val - min) / (max - min);
            gradient.GetColor(val, ref c);
            pixelData[i + yIndex] = c.R;
            pixelData[i + yIndex + 1] = c.G;
            pixelData[i + yIndex + 2] = c.B;
              }

              x += xInc;
            }
            y += yInc;
            x = Boundary.Object.X;
              }

              if (!mShadow)
              {
            if (noDispatch)
              bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, pixelData, rawStride);
            else
              Application.Current.Dispatcher.Invoke((Action)(() => { bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, pixelData, rawStride); }));
              }
              else
            bitmap = Shadow(gradient);

              return bitmap;
        }
Esempio n. 9
0
 public BitmapSource Redraw(Adapter noise, GradientDef grad)
 {
     return mShadow ? Shadow(grad) : Render(noise, grad, true);
 }