/// <summary>
        /// Can reuse the same neighbourhood if operating on positions within
        /// the same chunk, otherwise the light manager expects a neighbourhood
        /// centered on the chunk containing the modified voxel.
        /// Adjusts voxel pos to be relative to the center chunk.
        /// </summary>
        /// <param name="voxelPos"></param>
        /// <returns></returns>
        private ChunkNeighbourhood neighbourhoodFor(ref Vector3Int voxelPos)
        {
            //ChunkId is elementwise integer division by the Chunk dimensions
            var chunkId = voxelPos.ElementWise((a, b) => Mathf.FloorToInt(a / (float)b), chunkDimensions);

            var remainder = voxelPos.ElementWise((a, b) => a % b, chunkDimensions);

            //Local voxel index is the remainder, with negatives adjusted
            voxelPos = remainder.ElementWise((a, b) => a < 0 ? b + a : a, chunkDimensions);

            return(new ChunkNeighbourhood(chunkId, GetMockChunkData));
        }
Example #2
0
        public static Vector3Int ModuloChunkDimensions(Vector3Int position, Vector3Int chunkDimensions)
        {
            var remainder = position.ElementWise((a, b) => a % b, chunkDimensions);

            //Local voxel index is the remainder, with negatives adjusted
            return(remainder.ElementWise((a, b) => a < 0 ? b + a : a, chunkDimensions));
        }
Example #3
0
        bool InsideRadius(Vector3Int displacement, Vector3Int Radii)
        {
            Vector3Int absDisplacement = displacement.ElementWise(Mathf.Abs);

            //Inside if all elements of the absolute displacement are less than or equal to the radius
            return(absDisplacement.All((a, b) => a <= b, Radii));
        }
Example #4
0
        public static void AdjustForBounds(ref Vector3Int localPos, ref Vector3Int chunkId, Vector3Int chunkDimensions)
        {
            //Result is elementwise integer division by the Chunk dimensions
            var offset = localPos.ElementWise((a, b) => Mathf.FloorToInt(a / (float)b), chunkDimensions);

            chunkId += offset;

            localPos = ModuloChunkDimensions(localPos, chunkDimensions);
        }
Example #5
0
        Vector3Int WorldToChunkPos(Vector3 pos, Vector3Int ChunkDimensions)
        {
            Vector3Int floor = new Vector3Int();

            floor.x = Mathf.FloorToInt(pos.x);
            floor.y = Mathf.FloorToInt(pos.y);
            floor.z = Mathf.FloorToInt(pos.z);

            //Result is elementwise integer division by the Chunk dimensions
            Vector3Int result = floor.ElementWise((a, b) => Mathf.FloorToInt(a / (float)b), ChunkDimensions);

            return(result);
        }