Esempio n. 1
0
        public override Texture2D DidRequestTextureUpdate(int size, float spread)
        {
            Texture2D      tex  = new Texture2D(size, size);
            ConstraintNode cons = ConstraintValue;

            //Fill texture with black
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    tex.SetPixel(x, y, Color.black);
                }
            }

            AbsGeneratorNode maskNode = null;
            Generator        gen      = null;

            if (cons != null)
            {
                maskNode = cons.GetMaskValue();
            }
            if (maskNode != null)
            {
                gen = maskNode.GetGenerator();
            }

            Vector2[] samples = SamplePositions(new System.Random());
            for (var i = 0; i < samples.Length; i++)
            {
                Vector2 sample = samples[i];

                if (gen != null)
                {
                    Vector2 world = MathUtil.NormalToWorld(GridPosition.Zero, sample);

                    if (gen.GetValue(world.x, world.y, 0) < cons.Tolerance)
                    {
                        continue;
                    }
                }

                int x = Mathf.Clamp((int)(sample.x * size), 0, size);
                int y = Mathf.Clamp((int)(sample.y * size), 0, size);

                tex.SetPixel(x, y, Color.white);

                if (i >= MaxObjects)
                {
                    break;
                }
            }

            tex.Apply();
            return(tex);
        }
Esempio n. 2
0
        private void SetHeightmapSampler()
        {
            if (!UseHeightmap)
            {
                return;
            }

            AbsGeneratorNode gen = GetInputValue <AbsGeneratorNode>("HeightmapGenerator");

            _heightmapSampler = gen == null ? null : new GeneratorSampler(gen.GetGenerator());
        }
Esempio n. 3
0
        private void SetMoistureSampler()
        {
            if (!UseMoisture)
            {
                return;
            }

            AbsGeneratorNode gen = GetInputValue <AbsGeneratorNode>("MoistureGenerator");

            _moistureSampler = gen == null ? null : new GeneratorSampler(gen.GetGenerator());
        }
Esempio n. 4
0
        /// <summary>
        /// Decides whether or not this object should be placed at
        /// the specified height and angle. Does not check for intersections.
        /// </summary>
        /// <param name="height">Height to evaluate at</param>
        /// <param name="angle">Angle to evaluate at (0 to 180 degrees)</param>
        /// <returns></returns>
        public bool ShouldPlaceAt(float x, float y, float height, float angle)
        {
            if (ConstrainHeight && !HeightConstraint.Fits(height))
            {
                return(false);
            }
            if (ConstrainAngle && !AngleConstraint.Fits(angle))
            {
                return(false);
            }

            //Fails constrained height or constrained angle check
            if (!EvaluateHeight(height) || !EvaluateAngle(angle))
            {
                return(false);
            }

            //Place probability check
            if (Math.Abs(PlacementProbability - 100f) > 0.01f)
            {
                int result = UnityEngine.Random.Range(0, 101);
                if (result < 100 - PlacementProbability)
                {
                    return(false);
                }
            }

            //Mask check
            if (_cachedGeneratorNode == null)
            {
                _cachedGeneratorNode = GetMaskValue();
            }

            if (_cachedGeneratorNode != null)
            {
                if (_cachedGenerator == null)
                {
                    _cachedGenerator = _cachedGeneratorNode.GetGenerator();
                }

                if (_cachedGenerator != null)
                {
                    return(_cachedGenerator.GetValue(x, y, 0) < Tolerance);
                }
            }

            return(true);
        }
Esempio n. 5
0
        private Generator GetGeneratorFromNode(string name)
        {
            AbsGeneratorNode iv = GetInputValue <AbsGeneratorNode>(name);

            return(iv == null ? null : iv.GetGenerator());
        }