示例#1
0
        private void Compile(ref CompiledChunk compiledChunk)
        {
            Profiler.BeginSample("Compile");
            if (_chunkRenderCache != null)
            {
                var startPos = Chunk.Position;
                var endPos   = startPos + new Vector3Int(16, 16, 16);

                var blockTessellator = compiledChunk.BlockTessellator;


                for (int x = startPos.x; x < endPos.x; x++)
                {
                    for (int z = startPos.z; z < endPos.z; z++)
                    {
                        for (int y = startPos.y; y < endPos.y; y++)
                        {
                            var tile = _chunkRenderCache.Value.GetTile(x, y, z);

                            if (tile != Tile.Air)
                            {
                                blockTessellator.RenderModelSmooth(_chunkRenderCache, tile, new Vector3Int(x, y, z));
                            }
                        }
                    }
                }
            }
            Profiler.EndSample();
        }
示例#2
0
        public override Task <ChunkTaskResult> Execute()
        {
            if (_chunkRenderCache == null)
            {
                return(Task.FromResult(ChunkTaskResult.CANCELLED));
            }

            if (Finished == 1)
            {
                return(Task.FromResult(ChunkTaskResult.CANCELLED));
            }

            var compiledChunk = new CompiledChunk();

            Compile(ref compiledChunk);

            if (Finished == 1)
            {
                return(Task.FromResult(ChunkTaskResult.CANCELLED));
            }

            var ret = new TaskCompletionSource <bool>();

            Dispatcher.UploadTasks.Enqueue(() =>
            {
                var tessellator = compiledChunk.BlockTessellator.Tessellator;

                var mesh      = Chunk.Mesh;
                mesh.vertices = tessellator.Vertices.ToArray();
                mesh.colors32 = tessellator.Colors.ToArray();
                mesh.uv       = tessellator.Coords.ToArray();

                mesh.subMeshCount = 1;
                mesh.SetTriangles(tessellator.Indices, 0);
                mesh.RecalculateNormals();
                // mesh.RecalculateTangents();

                ret.SetResult(true);
            });
            ret.Task.Wait();

            if (Finished == 1)
            {
                return(Task.FromResult(ChunkTaskResult.CANCELLED));
            }

            Chunk._compiledChunk = compiledChunk;
            return(Task.FromResult(ChunkTaskResult.SUCCESSFUL));
        }
示例#3
0
 private void StopCompileTask()
 {
     StopTasks();
     _compiledChunk = null;
     _needsUpdate   = true;
 }
示例#4
0
 public ExecutionQueueEntity(CompiledChunk chunk, ChunkInstance instance)
 {
     Chunk    = chunk;
     Instance = instance;
 }