Beispiel #1
0
        private void CalculateChunkPartMesh(Chunk chunk, Vector3I direction)
        {
            Vector3I partChunkSize = Constant.ChunkSize;

            for (int i = 0; i < 3; i++)
            {
                if (direction[i] != 0)
                {
                    partChunkSize[i] = 1;
                }
            }
            Chunk partChunk = new Chunk(chunk.Position * Constant.ChunkSize - direction);

            for (int x = direction.X; x <= partChunkSize.X; x++)
            {
                for (int y = direction.Y; y <= partChunkSize.Y; y++)
                {
                    for (int z = direction.Z; z <= partChunkSize.Z; z++)
                    {
                        partChunk[x, y, z] = chunk[x - direction.X, y - direction.Y, z - direction.Z];
                    }
                }
            }

            if (_chunkPartMeshes.ContainsKey(partChunk.Position))
            {
                _chunkPartMeshes[partChunk.Position] = new ChunkMesh(partChunk, partChunkSize);
            }
            else
            {
                _chunkPartMeshes.Add(partChunk.Position, new ChunkMesh(partChunk, partChunkSize));
            }

            VoxelMesh mesh = new ChunkMesh(partChunk, partChunkSize)
                             .Transform(Matrix4x4.CreateTranslation((Vector3)partChunk.Position))
                             .Transform(Matrix4x4.CreateScale(_voxelSize));

            UpdateChunkGeometry(partChunk.Position, mesh);
            UpdateChunkDepthGeomatry(partChunk.Position, mesh);
        }
Beispiel #2
0
        private void CalculateChunkMeshes(IEnumerable <Chunk> viewModelChunks)
        {
            foreach (Chunk chunk in viewModelChunks)
            {
                if (_chunkMeshes.ContainsKey(chunk.Position))
                {
                    _chunkMeshes[chunk.Position] = new ChunkMesh(chunk);
                }
                else
                {
                    _chunkMeshes.Add(chunk.Position, new ChunkMesh(chunk));
                }

                VoxelMesh mesh = new ChunkMesh(chunk)
                                 .Transform(Matrix4x4.CreateTranslation((Vector3)(chunk.Position * Constant.ChunkSize)))
                                 .Transform(Matrix4x4.CreateScale(_voxelSize));
                UpdateChunkGeometry(chunk.Position, mesh);
                UpdateChunkDepthGeomatry(chunk.Position, mesh);

                CalculateChunkPartMeshes(chunk);
            }
        }