mirror of https://github.com/Leinnan/doppler.git
Multiple objects
This commit is contained in:
parent
7047300ca8
commit
8bfaaa5d56
|
|
@ -8,7 +8,7 @@ use cgmath::{perspective, vec3, Deg, Matrix4, Point3};
|
|||
use imgui_glfw_rs::glfw;
|
||||
|
||||
pub struct ExampleClient {
|
||||
model: ModelComponent,
|
||||
models: Vec<ModelComponent>,
|
||||
camera: Camera,
|
||||
shader: shader::Shader,
|
||||
show_object_info: bool,
|
||||
|
|
@ -17,14 +17,42 @@ pub struct ExampleClient {
|
|||
|
||||
impl ExampleClient {
|
||||
pub fn create() -> ExampleClient {
|
||||
let model = ModelComponent {
|
||||
let tree = ModelComponent {
|
||||
transform: Transform{ position: vec3(10.0,0.0,26.0),
|
||||
scale: vec3(2.5, 2.5, 2.5),
|
||||
..Transform::default()},
|
||||
model: model::Model::new_ext("resources/objects/tree/tree_6_d.obj",
|
||||
Some("tree_e.png")),
|
||||
};
|
||||
let tree2 = ModelComponent {
|
||||
transform: Transform{ position: vec3(-9.0,0.0,-15.0),
|
||||
scale: vec3(2.5, 2.5, 2.5),
|
||||
..Transform::default()},
|
||||
model: model::Model::new_ext("resources/objects/tree/tree_6_c.obj",
|
||||
Some("tree_e.png")),
|
||||
};
|
||||
let tree3 = ModelComponent {
|
||||
transform: Transform{ position: vec3(15.0,0.0,-7.0),
|
||||
scale: vec3(2.5, 2.5, 2.5),
|
||||
..Transform::default()},
|
||||
model: model::Model::new_ext("resources/objects/tree/tree_6_c.obj",
|
||||
Some("tree_e.png")),
|
||||
};
|
||||
let ground = ModelComponent {
|
||||
transform: Transform {
|
||||
scale: vec3(0.5, 0.5, 0.5),
|
||||
..Transform::default()
|
||||
},
|
||||
model: model::Model::new("resources/objects/ground/ground.obj"),
|
||||
};
|
||||
let robot = ModelComponent {
|
||||
transform: Transform::default(),
|
||||
model: model::Model::new("resources/objects/robot/robot.obj"),
|
||||
};
|
||||
ExampleClient {
|
||||
show_camera_info: true,
|
||||
show_object_info: false,
|
||||
model: model,
|
||||
models: vec!(tree,tree2,tree3,ground, robot),
|
||||
camera: Camera {
|
||||
position: Point3::new(0.0, 8.0, 13.0),
|
||||
front: vec3(0.0, -0.4, -1.0),
|
||||
|
|
@ -57,7 +85,9 @@ impl Client for ExampleClient {
|
|||
self.shader.set_mat4(c_str!("projection"), &projection);
|
||||
self.shader.set_mat4(c_str!("view"), &view);
|
||||
|
||||
self.model.draw(&self.shader);
|
||||
for model in self.models.iter() {
|
||||
model.draw(&self.shader);
|
||||
}
|
||||
}
|
||||
fn update(&mut self, _engine: &mut Engine) {}
|
||||
|
||||
|
|
@ -79,7 +109,7 @@ impl Client for ExampleClient {
|
|||
self.camera
|
||||
.enable_mouse_movement(window.get_key(Key::LeftControl) != Action::Press);
|
||||
if window.get_key(Key::O) == Action::Press {
|
||||
println!("{:?}",self.camera);
|
||||
println!("{:?}", self.camera);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,20 +155,21 @@ impl Client for ExampleClient {
|
|||
menu_bar.end(ui);
|
||||
}
|
||||
if self.show_camera_info {
|
||||
let text = format!("{:?}", self.camera).replace("{","{\n").replace("}","\n}").replace("],","],\n");
|
||||
let text = format!("{:?}", self.camera)
|
||||
.replace("{", "{\n")
|
||||
.replace("}", "\n}")
|
||||
.replace("],", "],\n");
|
||||
Window::new(im_str!("CameraInfo"))
|
||||
.size([300.0,300.0], Condition::Always)
|
||||
.position(
|
||||
[50.0, 50.0],
|
||||
Condition::Always,
|
||||
).title_bar(false)
|
||||
.scroll_bar(false)
|
||||
.collapsible(false)
|
||||
.build(&ui, || {
|
||||
ui.text(im_str!("Camera info"));
|
||||
ui.separator();
|
||||
ui.text(text);
|
||||
});
|
||||
.size([300.0, 300.0], Condition::Always)
|
||||
.position([50.0, 50.0], Condition::Always)
|
||||
.title_bar(false)
|
||||
.scroll_bar(false)
|
||||
.collapsible(false)
|
||||
.build(&ui, || {
|
||||
ui.text(im_str!("Camera info"));
|
||||
ui.separator();
|
||||
ui.text(text);
|
||||
});
|
||||
}
|
||||
if self.show_object_info {
|
||||
let mut show_window = self.show_object_info;
|
||||
|
|
@ -146,7 +177,7 @@ impl Client for ExampleClient {
|
|||
.size([250.0, 250.0], Condition::FirstUseEver)
|
||||
.opened(&mut show_window)
|
||||
.build(&ui, || {
|
||||
let mut selected_mut = vec![&mut self.model.transform];
|
||||
let mut selected_mut = vec![&mut self.models[0].transform];
|
||||
<Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut(
|
||||
&mut selected_mut,
|
||||
"Object info",
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const SPEED: f32 = 2.5;
|
|||
const SENSITIVTY: f32 = 0.1;
|
||||
const ZOOM: f32 = 45.0;
|
||||
|
||||
#[derive(Debug,Clone,Copy)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Camera {
|
||||
// Camera Attributes
|
||||
pub position: Point3,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::gaia::model::Model;
|
||||
use crate::gaia::shader::Shader;
|
||||
use cgmath::{vec3, Matrix4, Vector3, Rad};
|
||||
use cgmath::{vec3, Matrix4, Rad, Vector3};
|
||||
use imgui_glfw_rs::imgui;
|
||||
use imgui_inspect::InspectArgsDefault;
|
||||
use imgui_inspect::InspectRenderDefault;
|
||||
|
|
@ -89,7 +89,7 @@ pub struct ModelComponent {
|
|||
}
|
||||
|
||||
impl ModelComponent {
|
||||
pub unsafe fn draw(&mut self, shader: &Shader) {
|
||||
pub unsafe fn draw(&self, shader: &Shader) {
|
||||
let matrix = self.transform.get_matrix();
|
||||
|
||||
shader.set_mat4(c_str!("model"), &matrix);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,10 @@ impl Engine {
|
|||
Window::new(im_str!("EngineInfo"))
|
||||
.size(size, Condition::Always)
|
||||
.position(
|
||||
[self.window_size.0 - size[0] - offset, self.window_size.1 - size[1] - offset],
|
||||
[
|
||||
self.window_size.0 - size[0] - offset,
|
||||
self.window_size.1 - size[1] - offset,
|
||||
],
|
||||
Condition::Always,
|
||||
)
|
||||
.no_decoration()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct Model {
|
|||
|
||||
impl Model {
|
||||
/// constructor, expects a filepath to a 3D model.
|
||||
pub fn new(path: &str) -> Model {
|
||||
pub fn new_ext(path: &str, diff_texture: Option<&str>) -> Model {
|
||||
let pathObj = Path::new(path);
|
||||
let mut model = Model {
|
||||
meshes: Vec::<Mesh>::new(),
|
||||
|
|
@ -30,10 +30,14 @@ impl Model {
|
|||
.unwrap()
|
||||
.into(),
|
||||
};
|
||||
model.load_model(path);
|
||||
model.load_model(path, diff_texture);
|
||||
model
|
||||
}
|
||||
|
||||
pub fn new(path: &str) -> Model {
|
||||
Model::new_ext(path, None)
|
||||
}
|
||||
|
||||
pub fn Draw(&self, shader: &Shader) {
|
||||
for mesh in &self.meshes {
|
||||
unsafe {
|
||||
|
|
@ -43,7 +47,7 @@ impl Model {
|
|||
}
|
||||
|
||||
// loads a model from file and stores the resulting meshes in the meshes vector.
|
||||
fn load_model(&mut self, path: &str) {
|
||||
fn load_model(&mut self, path: &str, diffuse_path: Option<&str>) {
|
||||
let path = Path::new(path);
|
||||
println!("Started loading model from path: {}", path.display());
|
||||
|
||||
|
|
@ -98,7 +102,17 @@ impl Model {
|
|||
self.load_material_texture(&material.normal_texture, "texture_normal");
|
||||
textures.push(texture);
|
||||
}
|
||||
// NOTE: no height maps
|
||||
// NOTE: no height maps
|
||||
} else if diffuse_path.is_some() {
|
||||
println!("Loading {}", &diffuse_path.unwrap());
|
||||
let texture = self.load_material_texture(&diffuse_path.unwrap(), "texture_diffuse");
|
||||
textures.push(texture);
|
||||
} else {
|
||||
println!(
|
||||
"There are no materials with id {} for: {}",
|
||||
mesh.material_id.unwrap_or(404usize),
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
|
||||
self.meshes.push(Mesh::new(vertices, indices, textures));
|
||||
|
|
|
|||
Loading…
Reference in New Issue