Ready to implement multiple structures
This commit is contained in:
+29
-7
@@ -4,6 +4,7 @@ extern crate glium;
|
||||
#[macro_use]
|
||||
extern crate load_file;
|
||||
|
||||
use std::fs;
|
||||
use glium::texture::SrgbTexture2d;
|
||||
use phf::phf_map;
|
||||
use std::io::Cursor;
|
||||
@@ -29,7 +30,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [
|
||||
"wallStone.jpg",
|
||||
"cargoWhite.jpg",
|
||||
"b_ficusc2d_f.png",
|
||||
"basketball court.jpg",
|
||||
"basketball_court.jpg",
|
||||
"zinc.jpg",
|
||||
"solarPowerPlant.png",
|
||||
"cargoSand.jpg",
|
||||
@@ -70,7 +71,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [
|
||||
"wallBlue.jpg",
|
||||
"stop.jpg",
|
||||
"wallGreyATM.jpg",
|
||||
"iron bars.png",
|
||||
"iron_bars.png",
|
||||
"tile.jpg",
|
||||
"horizontalBrick.jpg",
|
||||
"steel.jpg",
|
||||
@@ -112,7 +113,7 @@ static STRUCTURES_TEXTURES_REVERSED: phf::Map<&'static str, u32> = phf_map! {
|
||||
"wallStone" => 3,
|
||||
"cargoWhite" => 4,
|
||||
"b_ficusc2d_f" => 5,
|
||||
"basketball court" => 6,
|
||||
"basketball_court" => 6,
|
||||
"zinc" => 7,
|
||||
"solarPowerPlant" => 8,
|
||||
"cargoSand" => 9,
|
||||
@@ -153,7 +154,7 @@ static STRUCTURES_TEXTURES_REVERSED: phf::Map<&'static str, u32> = phf_map! {
|
||||
"wallBlue" => 44,
|
||||
"stop" => 45,
|
||||
"wallGreyATM" => 46,
|
||||
"iron bars" => 47,
|
||||
"iron_bars" => 47,
|
||||
"tile" => 48,
|
||||
"horizontalBrick" => 49,
|
||||
"steel" => 50,
|
||||
@@ -418,9 +419,29 @@ fn main() {
|
||||
|
||||
let mut camera = support::camera::CameraState::new();
|
||||
|
||||
let vertex_buffer = support::load_wavefront(
|
||||
let structures_folder = "Extensions/LemnosLife/Map/Common/Structures/";
|
||||
let paths = fs::read_dir(structures_folder).unwrap();
|
||||
let mut structures_vertex_buffer = vec![];
|
||||
|
||||
for path in paths {
|
||||
let path = path
|
||||
.unwrap()
|
||||
.path();
|
||||
let file_path = path
|
||||
.to_str()
|
||||
.unwrap();
|
||||
if file_path.ends_with(".obj") {
|
||||
print!("path: {:?}", file_path);
|
||||
structures_vertex_buffer.push(support::load_wavefront(
|
||||
&display,
|
||||
load_bytes!(&format!("../{}", file_path)),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
let structures_vertex_buffer = support::load_wavefront(
|
||||
&display,
|
||||
load_bytes!("../Extensions/LemnosLife/Map/Common/Structures/24.obj"),
|
||||
load_bytes!(&format!("../{}/24.obj", structures_folder)),
|
||||
);
|
||||
|
||||
let structures_program = program!(&display,
|
||||
@@ -491,6 +512,7 @@ fn main() {
|
||||
tex18: &ground_textures[18],
|
||||
};
|
||||
|
||||
// That way we *load* far too many textures per structure but until haven't treated http://gitea.lemnoslife.com:3006/Benjamin_Loison/LemnosLife_Rust/issues/6#issuecomment-240, can't do better.
|
||||
let structures_uniforms = uniform! {
|
||||
persp_matrix: camera.get_perspective(),
|
||||
view_matrix: camera.get_view(),
|
||||
@@ -608,7 +630,7 @@ fn main() {
|
||||
|
||||
target
|
||||
.draw(
|
||||
(&vertex_buffer, per_instance_buffer.per_instance().unwrap()),
|
||||
(&structures_vertex_buffer, per_instance_buffer.per_instance().unwrap()),
|
||||
&glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||
&structures_program,
|
||||
&structures_uniforms,
|
||||
|
||||
Reference in New Issue
Block a user