mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Surface support for the cubic mesher.
This commit is contained in:
parent
5358c99646
commit
fc153bae06
@ -728,6 +728,28 @@ Vector3 VoxelCubePoints::get_bottom_right_point(int face) {
|
||||
return _points[P000];
|
||||
}
|
||||
|
||||
uint8_t VoxelCubePoints::get_face_type(int face) {
|
||||
if (face == VOXEL_FACE_BACK) {
|
||||
return _point_types[P111];
|
||||
}
|
||||
if (face == VOXEL_FACE_FRONT) {
|
||||
return _point_types[P110];
|
||||
}
|
||||
if (face == VOXEL_FACE_RIGHT) {
|
||||
return _point_types[P110];
|
||||
}
|
||||
if (face == VOXEL_FACE_LEFT) {
|
||||
return _point_types[P011];
|
||||
}
|
||||
if (face == VOXEL_FACE_TOP) {
|
||||
return _point_types[P110];
|
||||
}
|
||||
if (face == VOXEL_FACE_BOTTOM) {
|
||||
return _point_types[P100];
|
||||
}
|
||||
return _point_types[0];
|
||||
}
|
||||
|
||||
bool VoxelCubePoints::has_points() {
|
||||
return (_point_types[P000] != 0 && _point_types[P100] != 0 && _point_types[P010] != 0 && _point_types[P001] != 0 &&
|
||||
_point_types[P110] != 0 && _point_types[P011] != 0 && _point_types[P101] != 0 && _point_types[P111] != 0);
|
||||
@ -814,6 +836,8 @@ void VoxelCubePoints::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_bottom_left_point", "face"), &VoxelCubePoints::get_bottom_left_point);
|
||||
ClassDB::bind_method(D_METHOD("get_bottom_right_point", "face"), &VoxelCubePoints::get_bottom_right_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_face_type", "face"), &VoxelCubePoints::get_face_type);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_points"), &VoxelCubePoints::has_points);
|
||||
ClassDB::bind_method(D_METHOD("get_opposite_face", "face"), &VoxelCubePoints::get_opposite_face);
|
||||
|
||||
|
@ -147,6 +147,8 @@ public:
|
||||
Vector3 get_bottom_left_point(int face);
|
||||
Vector3 get_bottom_right_point(int face);
|
||||
|
||||
uint8_t get_face_type(int face);
|
||||
|
||||
bool has_points();
|
||||
int get_opposite_face(int face);
|
||||
|
||||
|
@ -33,8 +33,6 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
|
||||
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
chunk->generate_ao();
|
||||
|
||||
int x_size = chunk->get_size_x();
|
||||
int y_size = chunk->get_size_y();
|
||||
int z_size = chunk->get_size_z();
|
||||
@ -61,6 +59,13 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
|
||||
if (!cube_points->is_face_visible(face))
|
||||
continue;
|
||||
|
||||
uint8_t type = cube_points->get_face_type(face);
|
||||
|
||||
Ref<VoxelSurface> surface = _library->get_voxel_surface(type);
|
||||
|
||||
if (!surface.is_valid())
|
||||
continue;
|
||||
|
||||
add_indices(get_vertex_count() + 2);
|
||||
add_indices(get_vertex_count() + 1);
|
||||
add_indices(get_vertex_count() + 0);
|
||||
@ -102,8 +107,23 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
|
||||
|
||||
add_color(light);
|
||||
|
||||
add_uv((cube_points->get_point_uv_direction(face, i) + Vector2(0.5, 0.5)) * Vector2(tile_uv_size, tile_uv_size));
|
||||
add_uv2((cube_points->get_point_uv_direction(face, i) + Vector2(0.5, 0.5)) * Vector2(tile_uv_size, tile_uv_size));
|
||||
Vector2 uv = (cube_points->get_point_uv_direction(face, i) + Vector2(0.5, 0.5)) * Vector2(tile_uv_size, tile_uv_size);
|
||||
|
||||
VoxelSurface::VoxelSurfaceSides side = VoxelSurface::VOXEL_SIDE_SIDE;
|
||||
|
||||
switch (face) {
|
||||
case VoxelCubePoints::VOXEL_FACE_TOP:
|
||||
side = VoxelSurface::VOXEL_SIDE_TOP;
|
||||
break;
|
||||
case VoxelCubePoints::VOXEL_FACE_BOTTOM:
|
||||
side = VoxelSurface::VOXEL_SIDE_BOTTOM;
|
||||
break;
|
||||
}
|
||||
|
||||
uv = surface->transform_uv(side, uv);
|
||||
|
||||
add_uv(uv);
|
||||
add_uv2(uv);
|
||||
|
||||
add_vertex((vertices[i] * voxel_size + Vector3(x, y, z)) * voxel_scale);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user