示例#1
0
        private void UpdateChunkForVoxel(int x, int y, int z, Vector3Int chunkSize, Vector3Int volumeSize)
        {
            var chunkSizeDecreased = new Vector3Int(chunkSize.x - 1, chunkSize.y - 1, chunkSize.z - 1);

            var chunkPosition = VoxelChunkUtility.GetChunkPositionByVoxelPosition(x, y, z, chunkSize);

            var xxx = x - chunkSize.x * chunkPosition.x;
            var yyy = y - chunkSize.y * chunkPosition.y;
            var zzz = z - chunkSize.z * chunkPosition.z;

            TryAddChunk(chunkPosition, chunkSize, volumeSize);

            if (xxx == chunkSizeDecreased.x && chunkPosition.x != volumeSize.x / chunkSizeDecreased.x)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.x += 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }
            if (xxx == 0 && chunkPosition.x != 0)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.x -= 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }

            if (yyy == chunkSizeDecreased.y && chunkPosition.y != volumeSize.y / chunkSizeDecreased.y)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.y += 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }
            if (yyy == 0 && chunkPosition.y != 0)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.y -= 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }

            if (zzz == chunkSizeDecreased.z && chunkPosition.z != volumeSize.z / chunkSizeDecreased.z)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.z += 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }
            if (zzz == 0 && chunkPosition.z != 0)
            {
                var chunkPositionCopy = chunkPosition;
                chunkPositionCopy.z -= 1;

                TryAddChunk(chunkPositionCopy, chunkSize, volumeSize);
            }
        }
示例#2
0
        private void TryAddChunk(Vector3Int chunkPosition, Vector3Int chunkSize, Vector3Int volumeSize)
        {
            var chunkIndex = VoxelChunkUtility.GetChunkIndex(chunkPosition, chunkSize, volumeSize);

            if (!UpdatedChunks.Contains(chunkIndex))
            {
                UpdatedChunks.Add(chunkIndex);
            }
        }
示例#3
0
        public VoxelGeometryChunkResponse Execute(VoxelGeometryVolumeRequest geometryVolumeRequest)
        {
            _currentGeometryChunkCommand.geometryVolumeRequest = geometryVolumeRequest;

            _currentGeometryChunkCommand.Execute();

            var elementLengths = _currentGeometryChunkCommand.elementLengths;
            var verticesLength = elementLengths[0];
            var indicesLength  = elementLengths[1];

            var vertices = new Vector3[verticesLength];
            var colors   = new Color32[verticesLength];
            var indices  = new int[indicesLength];

            Array.Copy(_vertices, vertices, verticesLength);
            Array.Copy(_colors, colors, verticesLength);
            Array.Copy(_indices, indices, indicesLength);

            var command = _currentGeometryChunkCommand.geometryVolumeRequest;

            var chunkIndex = VoxelChunkUtility.GetIndex(command.chunkPosition);

            return(new VoxelGeometryChunkResponse(chunkIndex, vertices, indices, colors));
        }