private void AdjustClusterSize()
        {
            var newClusterDimensions = _clusterDimensions * 2;
            var offset      = _clusterDimensions / 2;
            var newClusters = new GpuInstancingNodeCluster <T> [newClusterDimensions, newClusterDimensions];

            for (int i = 0; i < _clusterDimensions; ++i)
            {
                for (int j = 0; j < _clusterDimensions; ++j)
                {
                    newClusters[i + offset, j + offset] = _nodeClusters[i, j];
                }
            }

            _clusterDimensions = newClusterDimensions;
            _nodeClusters      = newClusters;
        }
        public void AddCluster(GpuInstancingNodeCluster <T> cluster)
        {
            while (true)
            {
                var halfSize = _clusterDimensions / 2;
                var xIndex   = Mathf.RoundToInt(cluster.MinPosition.x / _clusterSize) + halfSize;
                var zIndex   = Mathf.RoundToInt(cluster.MinPosition.z / _clusterSize) + halfSize;

                if (xIndex >= _clusterDimensions || zIndex >= _clusterDimensions)
                {
                    AdjustClusterSize();
                }
                else
                {
                    _nodeClusters[xIndex, zIndex] = cluster;

                    var clusterMaxInstanceCount = cluster.MaxInstanceCountPerRenderInUnit;
                    var count = clusterMaxInstanceCount.Length;

                    if (_maxInstanceCountPerRenderInUnit == null)
                    {
                        _maxInstanceCountPerRenderInUnit = new int[count];
                    }

                    for (int i = 0; i < count; ++i)
                    {
                        if (_maxInstanceCountPerRenderInUnit[i] < clusterMaxInstanceCount[i])
                        {
                            _newInstanceCountLimit = true;
                            _maxInstanceCountPerRenderInUnit[i] = clusterMaxInstanceCount[i];
                        }
                    }

                    break;
                }
            }
        }
 public GpuInstancingSpatialPartition()
 {
     _nodeClusters = new GpuInstancingNodeCluster <T> [_clusterDimensions, _clusterDimensions];
 }