コード例 #1
0
        public void DepthFirst(ref Node node, Vector3 position, Vector3 size, IDensityFunction densityFunction, int maxLevel, int level = 0)
        {
            for (var i = 0; i < 8; i++)
            {
                var childSize = NodeOffsets[i];
                childSize.Scale(size / 2);
                var childPosition = position + childSize;

                var overlap = CheckOverlap(childPosition, childPosition + size / 2, densityFunction.Minimum, densityFunction.Maximum);
                node.SetChildMask(i, overlap);
            }

            AddChildren(ref node);

            if (level >= maxLevel)
            {
                return;
            }

            var count = node.GetChildrenCount();

            for (var i = 0; i < count; i++)
            {
                ref var child         = ref GetNChild(node, i);
                var     childIndex    = node.GetNChildIndex(i);
                var     childPosition = NodeOffsets[childIndex];
                childPosition.Scale(size / 2);
                DepthFirst(ref child, position + childPosition, size / 2, densityFunction, maxLevel, level + 1);
            }
コード例 #2
0
 public Vector3 GetNormal(IDensityFunction densityFunction, int x, int y, int z)
 {
     return(new Vector3(
                Get(x + 1, y, z).Density - Get(x - 1, y, z).Density,
                Get(x, y + 1, z).Density - Get(x, y - 1, z).Density,
                Get(x, y, z + 1).Density - Get(x, y, z - 1).Density
                ).normalized);
 }
コード例 #3
0
 public StochasticMeshOperator(
     int numOfMesh,
     IUnderlyings underlying,
     IDensityFunction densityFunction)
 {
     NumOfMesh = numOfMesh > underlying.GetPathNum()
         ? numOfMesh : underlying.GetPathNum();
     DensityFunction = densityFunction;
     Underlying      = underlying;
 }
コード例 #4
0
        public void Intersect(IDensityFunction densityFunction)
        {
            var xmin = Mathf.Max(0, Mathf.FloorToInt(densityFunction.Minimum.x));
            var xmax = Mathf.Min(Width - 1, Mathf.CeilToInt(densityFunction.Maximum.x));
            var ymin = Mathf.Max(0, Mathf.FloorToInt(densityFunction.Minimum.y));
            var ymax = Mathf.Min(Height - 1, Mathf.CeilToInt(densityFunction.Maximum.y));
            var zmin = Mathf.Max(0, Mathf.FloorToInt(densityFunction.Minimum.z));
            var zmax = Mathf.Min(Length - 1, Mathf.CeilToInt(densityFunction.Maximum.z));

            for (var x = xmin; x < xmax; x++)
            {
                for (var y = ymin; y < ymax; y++)
                {
                    for (var z = zmin; z < zmax; z++)
                    {
                        _data[GetIndex(x, y, z)].Density = Mathf.Max(densityFunction.Value(new Vector3(x, y, z)), _data[GetIndex(x, y, z)].Density);
                        _data[GetIndex(x, y, z)].Normal  = GetNormal(densityFunction, x, y, z);
                    }
                }
            }
        }
コード例 #5
0
 public DensityChunkGenerator(IDensityFunction densityFunction)
 {
     _densityFunction = densityFunction;
 }