Ejemplo n.º 1
0
        public static Signal <V, float> WorleyNoise <V> (WorleyNoiseKind kind, Func <V, V, float> distance,
                                                         IEnumerable <V> controlPoints) where V : struct, IVec <V, float>
        {
            var i    = 0;
            var tree = new KdTree <V, int> (controlPoints.Select(cp =>
                                                                 new KeyValuePair <V, int> (cp, i++)));

            switch (kind)
            {
            case WorleyNoiseKind.F1:
                return(vec => distance(vec, Neighbours(tree, vec, 1, distance)[0]));

            case WorleyNoiseKind.F2:
                return(vec => distance(vec, Neighbours(tree, vec, 2, distance)[1]));

            case WorleyNoiseKind.F3:
                return(vec => distance(vec, Neighbours(tree, vec, 3, distance)[2]));

            default:
                return(vec =>
                {
                    var neigbours = Neighbours(tree, vec, 2, distance);
                    return distance(vec, neigbours[1]) - distance(vec, neigbours[0]);
                });
            }
        }
Ejemplo n.º 2
0
 public UniformWorleyArgs(Vec2 scale, float jitter, DistanceKind distKind, WorleyNoiseKind noiseKind)
 {
     Scale        = Value(scale);
     Jitter       = Value(jitter);
     DistanceKind = Value((int)distKind);
     NoiseKind    = Value((int)noiseKind);
 }
Ejemplo n.º 3
0
 public WorleyArgs(DistanceKind distKind, WorleyNoiseKind noiseKind, params Vec2[] controlPoints)
 {
     DistanceKind  = Value((int)distKind);
     NoiseKind     = Value((int)noiseKind);
     ControlPoints = ReadBuffer(controlPoints);
     Count         = Value(controlPoints.Length);
 }
Ejemplo n.º 4
0
 protected override void Load(XElement xelem)
 {
     NoiseKind         = xelem.AttrEnum <WorleyNoiseKind> (nameof(NoiseKind));
     ControlPoints     = xelem.AttrEnum <ControlPointKind> (nameof(ControlPoints));
     DistanceKind      = xelem.AttrEnum <DistanceKind> (nameof(DistanceKind));
     ControlPointCount = xelem.AttrInt(nameof(ControlPointCount));
     Seed     = xelem.AttrInt(nameof(Seed));
     Jitter   = xelem.AttrFloat(nameof(Jitter));
     Periodic = xelem.AttrBool(nameof(Periodic));
 }
Ejemplo n.º 5
0
        protected override Control CreateControl()
        {
            var changed  = Changed.Adapt <int, AnySignalEditor> (this);
            var changedf = Changed.Adapt <float, AnySignalEditor> (this);

            return(FoldableContainer.WithLabel(Name, true, HAlign.Left,
                                               Container.LabelAndControl("Type: ",
                                                                         new Picker((int)NoiseKind,
                                                                                    React.By((int i) => NoiseKind = (WorleyNoiseKind)i).And(changed),
                                                                                    Enum.GetNames(typeof(WorleyNoiseKind))), true),
                                               Container.LabelAndControl("Seed: ",
                                                                         new NumericEdit(Seed, true, 1,
                                                                                         React.By((float i) => Seed = (int)i).And(changedf)), true),
                                               Container.LabelAndControl("CP Type: ",
                                                                         new Picker((int)ControlPoints,
                                                                                    React.By((int i) => ControlPoints = (ControlPointKind)i).And(changed),
                                                                                    Enum.GetNames(typeof(ControlPointKind))), true),
                                               Container.LabelAndControl("CP Count: ",
                                                                         new NumericEdit(ControlPointCount, true, 1,
                                                                                         React.By((float i) => ControlPointCount = (int)i).And(changedf).Filter(i => i > 2)), true),
                                               Container.LabelAndControl("Distance: ",
                                                                         new Picker((int)DistanceKind,
                                                                                    React.By((int i) => DistanceKind = (DistanceKind)i).And(changed),
                                                                                    Enum.GetNames(typeof(DistanceKind))), true),
                                               Container.LabelAndControl("Jitter: ",
                                                                         new NumericEdit(Jitter, false, 0.1f,
                                                                                         React.By((float x) => Jitter = x).And(changedf)), true),
                                               Container.LabelAndControl("Periodic: ",
                                                                         new Picker(Periodic ? 1 : 0,
                                                                                    React.By((int i) => Periodic = i != 0).And(changed),
                                                                                    "No", "Yes"), true)));
        }