voxel_engine/mesh/chunk.py

28 lines
790 B
Python
Raw Permalink Normal View History

2023-10-19 12:59:58 +02:00
#!/usr/bin/python3
from mesh.base import BaseMesh
from mesh.chunk_builder import build_chunk_mesh
class ChunkMesh(BaseMesh):
def __init__(self, chunk):
super().__init__()
self.app = chunk.app
self.chunk = chunk
self.ctx = self.app.ctx
self.program = self.app.shader_program.chunk
2023-10-19 16:13:27 +02:00
self.vbo_format = "1u4"
2023-10-19 12:59:58 +02:00
self.format_size = sum(int(fmt[:1]) for fmt in self.vbo_format.split())
2023-10-19 16:13:27 +02:00
self.attributes = ("packed_data",)
2023-10-19 12:59:58 +02:00
self.vao = self.get_vao()
def get_vertex_data(self):
mesh = build_chunk_mesh(
chunk_voxels=self.chunk.voxels,
format_size=self.format_size,
chunk_pos=self.chunk.position,
world_voxels=self.chunk.world.voxels
)
return mesh