Ready to use an uniform array of textures for the biomes

This commit is contained in:
2022-10-17 02:35:05 +02:00
parent 02e28b2bc8
commit c526ebe977
3 changed files with 73 additions and 25 deletions
+42 -13
View File
@@ -55,6 +55,15 @@ where
})
}
fn get_biome(line: &str, index: usize) -> u32 {
let biome_char = line.chars().nth(index).unwrap();
return if '0' <= biome_char && biome_char <= '9' {
biome_char.to_digit(10).unwrap()
} else {
(10 + (biome_char as u8 - 'A' as u8)) as u32
}
}
/// Returns a vertex buffer that should be rendered as `TrianglesList`.
pub fn load_ground(display: &Display) -> VertexBufferAny {
#[derive(Copy, Clone)]
@@ -62,30 +71,44 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: f32,
normal: [f32; 3],
index: u32,
biome: u32,
}
implement_vertex!(Vertex, altitude, normal, index);
let mut vertex_data: Vec<Vertex> = Vec::new();
let contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height").expect("Unable to load ground file!");
// TODO: load "all" ground/biomes files
// TODO: use triangle strip
let height_contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height")
.expect("Unable to load ground file!");
let lines: Vec<&str> = contents.split('\n').collect();
let biomes_contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Biomes/13 13.biomes")
.expect("Unable to load biomes file!");
let height_lines: Vec<&str> = height_contents.split('\n').collect();
let biomes_lines: Vec<&str> = biomes_contents.split('\n').collect();
let mut index: u32 = 0;
for lines_index in 0..lines.len() - 1 {
let line = lines[lines_index];
let next_line = lines[lines_index + 1];
let columns: Vec<&str> = line.split(' ').collect();
let next_columns: Vec<&str> = next_line.split(' ').collect();
for columns_index in 0..columns.len() - 1 {
let column = columns[columns_index].parse::<f32>().unwrap();
let column_right = columns[columns_index + 1].parse::<f32>().unwrap();
let column_below = next_columns[columns_index].parse::<f32>().unwrap();
let column_below_right = next_columns[columns_index + 1].parse::<f32>().unwrap();
for lines_index in 0..height_lines.len() - 1 {
let height_line = height_lines[lines_index];
let height_next_line = height_lines[lines_index + 1];
let height_columns: Vec<&str> = height_line.split(' ').collect();
let height_next_columns: Vec<&str> = height_next_line.split(' ').collect();
// TODO: normals if necessary.
let biomes_line = biomes_lines[lines_index / 2];
for columns_index in 0..height_columns.len() - 1 {
let column = height_columns[columns_index].parse::<f32>().unwrap();
let column_right = height_columns[columns_index + 1].parse::<f32>().unwrap();
let column_below = height_next_columns[columns_index].parse::<f32>().unwrap();
let column_below_right = height_next_columns[columns_index + 1].parse::<f32>().unwrap();
let biome = get_biome(biomes_line, columns_index / 2);
// TODO: compute normals if necessary.
// First triangle.
@@ -93,6 +116,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
@@ -100,6 +124,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
@@ -107,6 +132,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
@@ -116,6 +142,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
@@ -123,6 +150,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
@@ -130,6 +158,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
altitude: column_below_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
}