Exemple #1
0
        public void DefaultQueueSortTest()
        {
            var geometryRequestsQueue = new VoxelGeometryChunkRequestQueue();
            var playerPosition        = new Vector3(0, 0, 0);
            var pullCount             = 4;

            geometryRequestsQueue.Push(new VoxelGeometryVolumeRequest
            {
                chunkPosition = new Vector3Int(23, 32, 32)
            });

            geometryRequestsQueue.Push(new VoxelGeometryVolumeRequest
            {
                chunkPosition = new Vector3Int(16, 16, 16)
            });

            geometryRequestsQueue.Push(new VoxelGeometryVolumeRequest
            {
                chunkPosition = new Vector3Int(1, 1, 1)
            });

            var pull = geometryRequestsQueue.Pull(pullCount, playerPosition);

            foreach (var re in pull)
            {
                Debug.Log(re.chunkPosition);
            }
        }
Exemple #2
0
        private void LateUpdate()
        {
            if (_chunkRequestQueue.Count > 0)
            {
                var geometryRequests  = _chunkRequestQueue.Pull(_pullCount, _camera.Position);
                var geometryResponses = _voxelGeometryController.Execute(geometryRequests);

                foreach (var geometryResponse in geometryResponses)
                {
                    /*
                     * var chunk = _chunks[geometryResponse.ChunkIndex];
                     * chunk.SetMesh(geometryResponse);*/
                }
            }

            if (_fallingRequestQueue.Count > 0)
            {
                var geometryRequests  = _fallingRequestQueue.Pull(_pullCount, _camera.Position);
                var geometryResponses = _voxelGeometryController.Execute(geometryRequests);

                foreach (var geometryResponse in geometryResponses)
                {
                    /*
                     * var fallingConstructionController = _fallingConstructionControllers[geometryResponse.ConstructionIndex];
                     * fallingConstructionController.SetMesh(geometryResponse);*/
                }
            }
        }
Exemple #3
0
    private void LateUpdate()
    {
        _chunkRenderer.Execute();

        if (_chunkRequestQueue.Count > 0)
        {
            var geometryRequests  = _chunkRequestQueue.Pull(4, _cameraTransform.position);
            var geometryResponses = _voxelGeometryController.Execute(geometryRequests);

            var length = geometryResponses.Length;

            if (length > 0)
            {
                var bakeChunks = new VolumeChunk[geometryResponses.Length];

                for (var i = 0; i < length; i++)
                {
                    var geometryResponse = geometryResponses[i];

                    var chunk = _chunks[geometryResponse.ChunkIndex];
                    chunk.SetMesh(geometryResponse);

                    bakeChunks[i] = chunk;
                }

                var tasks = new Task[length];

                for (var i = 0; i < length; i++)
                {
                    var bakeId = bakeChunks[i].MeshId;
                    tasks[i] = Task.Run(() => Physics.BakeMesh(bakeId, false));
                }

                Task.WaitAll(tasks);

                for (var i = 0; i < length; i++)
                {
                    bakeChunks[i].UpdateColliderMesh();
                }
            }
        }

        if (_fallingRequestQueue.Count > 0)
        {
            var geometryRequests  = _fallingRequestQueue.Pull(4, _cameraTransform.position);
            var geometryResponses = _voxelGeometryController.Execute(geometryRequests);

            foreach (var geometryResponse in geometryResponses)
            {
                var fallingConstruction = _fallingConstructions[geometryResponse.ConstructionIndex];
                fallingConstruction.SetMesh(geometryResponse);
            }
        }
    }