Beispiel #1
0
 public IEnumerator InvertChunksCoroutine()
 {
     foreach (var chunk in childs)
     {
         var GD = chunk.Value.GridData;
         foreach (var d in MultiDimenIterator.Range(0, _size - 1, 0, _size - 1, 0, _size - 1, 1, 1, 1))
         {
             GD[d.i, d.j, d.k] = 1 - GD[d.i, d.j, d.k];
         }
     }
     yield break;
 }
Beispiel #2
0
        public static Vector3 WeightedAverage(IList <Vector3> values, IList <float> weights)
        {
            if (values == null || weights == null || values.Count <= 0 || values.Count != weights.Count)
            {
                return(Vector3.zero);
            }
            var x = MultiDimenIterator.Range(0, values.Count - 1, 1).WeightedAverage(i => values[i].x, i => weights[i]);
            var y = MultiDimenIterator.Range(0, values.Count - 1, 1).WeightedAverage(i => values[i].y, i => weights[i]);
            var z = MultiDimenIterator.Range(0, values.Count - 1, 1).WeightedAverage(i => values[i].z, i => weights[i]);

            return(new Vector3(x, y, z));
        }
        public void Init(int Size, float defaultValue = 0)
        {
            var f = new float[Size, Size, Size];

            if (defaultValue != 0)
            {
                foreach (var d in MultiDimenIterator.Range(0, f.GetLength(0) - 1, 0, f.GetLength(1) - 1, 0, f.GetLength(2) - 1, 1, 1, 1))
                {
                    f[d.i, d.j, d.k] = defaultValue;
                }
            }
            Init(Size, f);
        }
Beispiel #4
0
        public IEnumerator ExplodeBrushCoroutine(float x, float y, float z, float size, float val = 1, bool noised = false, System.Action <float, Vector3> countCallback = null)
        {
            Vector3 center, pointPos;
            float   count = 0, newValue = 0, origValue = 0, difference;

            center = new Vector3(x, y, z);
            var positions = new List <Vector3>();
            var weights   = new List <float>();

            foreach (var d in MultiDimenIterator.Range(
                         Mathf.FloorToInt(x - size),
                         Mathf.CeilToInt(x + size),
                         Mathf.FloorToInt(y - size),
                         Mathf.CeilToInt(y + size),
                         Mathf.FloorToInt(z - size),
                         Mathf.CeilToInt(z + size), 1, 1, 1))
            {
                pointPos  = d.ToVector3();
                origValue = this[d.i, d.j, d.k];
                newValue  = Mathf.Lerp(
                    origValue, noised ? Mathf.Lerp(origValue, val, Mathf.PerlinNoise(d.i, d.j)) : val,
                    Mathf.Sqrt(Mathf.Clamp01((size - Vector3.Distance(center, pointPos)) / size)));
                this[d.i, d.j, d.k] = newValue;
                if (countCallback == null)
                {
                    continue;
                }
                difference = newValue - origValue;
                positions.Add(pointPos);
                weights.Add(difference);
                count += difference;
            }
            if (countCallback != null)
            {
                countCallback(count, transform.TransformPoint(HelperFunctions.WeightedAverage(positions, weights)));
            }
            yield break;
        }