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); } } }
public FallingConstruction Create(int chunksCapacity) { var fallingConstructionView = GetFallingConstruction(); var fallingChunkViews = new VolumeChunk[chunksCapacity]; for (var i = 0; i < chunksCapacity; i++) { var fallingChunkView = GetFallingChunk(i); fallingChunkView.SetParent(fallingConstructionView.transform); fallingChunkViews[i] = fallingChunkView; } fallingConstructionView.chunks = fallingChunkViews; return(fallingConstructionView); }