Use log / stderrlog
This commit is contained in:
parent
e040ef14ff
commit
bb6bc07906
|
@ -4,13 +4,14 @@ version = "0.1.0"
|
||||||
authors = ["Thomas Forgione <thomas@tforgione.fr>"]
|
authors = ["Thomas Forgione <thomas@tforgione.fr>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
log = "0.4"
|
||||||
|
stderrlog = "0.4.1"
|
||||||
num = "0.1.42"
|
num = "0.1.42"
|
||||||
glium = "0.22.0"
|
glium = "0.22.0"
|
||||||
image = "0.19.0"
|
image = "0.19.0"
|
||||||
byteorder = "1.2.3"
|
byteorder = "1.2.3"
|
||||||
clap = "2.31.2"
|
clap = "2.31.2"
|
||||||
nalgebra = "0.15.3"
|
nalgebra = "0.15.3"
|
||||||
verbose-log = { git = "https://gitea.tforgione.fr/dash-3d/verbose-log" }
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "3d-viewer"
|
name = "3d-viewer"
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
extern crate stderrlog;
|
||||||
|
|
||||||
extern crate num;
|
extern crate num;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
extern crate nalgebra;
|
extern crate nalgebra;
|
||||||
|
|
||||||
#[macro_use] extern crate verbose_log;
|
|
||||||
#[macro_use] extern crate glium;
|
#[macro_use] extern crate glium;
|
||||||
|
|
||||||
pub mod math;
|
pub mod math;
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl Model {
|
||||||
for (name, material) in &other.materials {
|
for (name, material) in &other.materials {
|
||||||
let entry = self.materials.entry(name.clone());
|
let entry = self.materials.entry(name.clone());
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: materials merged but sharing the same name");
|
warn!("Materials merged but sharing the same name");
|
||||||
// Return error
|
// Return error
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(material.clone());
|
entry.or_insert(material.clone());
|
||||||
|
@ -156,7 +156,7 @@ impl Model {
|
||||||
for (name, texture) in &other.textures {
|
for (name, texture) in &other.textures {
|
||||||
let entry = self.textures.entry(name.clone());
|
let entry = self.textures.entry(name.clone());
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: textures merged but sharing the same name");
|
warn!("Textures merged but sharing the same name");
|
||||||
// return Error;
|
// return Error;
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(texture.clone());
|
entry.or_insert(texture.clone());
|
||||||
|
@ -172,7 +172,7 @@ impl Model {
|
||||||
for (name, material) in other.materials {
|
for (name, material) in other.materials {
|
||||||
let entry = self.materials.entry(name);
|
let entry = self.materials.entry(name);
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: materials merged but sharing the same name");
|
warn!("Materials merged but sharing the same name");
|
||||||
// Return error
|
// Return error
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(material);
|
entry.or_insert(material);
|
||||||
|
@ -183,7 +183,7 @@ impl Model {
|
||||||
for (name, texture) in other.textures {
|
for (name, texture) in other.textures {
|
||||||
let entry = self.textures.entry(name);
|
let entry = self.textures.entry(name);
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: textures merged but sharing the same name");
|
warn!("Textures merged but sharing the same name");
|
||||||
// return Error;
|
// return Error;
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(texture);
|
entry.or_insert(texture);
|
||||||
|
@ -235,7 +235,7 @@ impl Model {
|
||||||
for (name, material) in other.materials {
|
for (name, material) in other.materials {
|
||||||
let entry = self.materials.entry(name);
|
let entry = self.materials.entry(name);
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: materials merged but sharing the same name");
|
warn!("Materials merged but sharing the same name");
|
||||||
// Return error
|
// Return error
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(material);
|
entry.or_insert(material);
|
||||||
|
@ -246,7 +246,7 @@ impl Model {
|
||||||
for (name, texture) in other.textures {
|
for (name, texture) in other.textures {
|
||||||
let entry = self.textures.entry(name);
|
let entry = self.textures.entry(name);
|
||||||
if let Entry::Occupied(_) = entry {
|
if let Entry::Occupied(_) = entry {
|
||||||
eprintln!("Warning: textures merged but sharing the same name");
|
warn!("Textures merged but sharing the same name");
|
||||||
// return Error;
|
// return Error;
|
||||||
} else {
|
} else {
|
||||||
entry.or_insert(texture);
|
entry.or_insert(texture);
|
||||||
|
|
|
@ -204,7 +204,7 @@ pub trait Parser {
|
||||||
|
|
||||||
/// Parses a file and adds its content to an already existing model.
|
/// Parses a file and adds its content to an already existing model.
|
||||||
fn parse_into_model<R: Read>(&mut self, model: &mut Model, reader: R, path: &str) -> Result<(), ParserError> {
|
fn parse_into_model<R: Read>(&mut self, model: &mut Model, reader: R, path: &str) -> Result<(), ParserError> {
|
||||||
logln!("Parsing {}...", path);
|
info!("Parsing {}...", path);
|
||||||
self.priv_parse_into_model(model, reader, path)
|
self.priv_parse_into_model(model, reader, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl ObjParser {
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
let values = parse_values(line_number, line, path, 3)?;
|
let values = parse_values(line_number, line, path, 3)?;
|
||||||
logln!("Warning: expected 2 coordinates, but received 3, ignoring the last one...");
|
warn!("Warning: expected 2 coordinates, but received 3, ignoring the last one...");
|
||||||
Ok(Element::TextureCoordinate(Vector2::<f64>::new(
|
Ok(Element::TextureCoordinate(Vector2::<f64>::new(
|
||||||
values[0],
|
values[0],
|
||||||
values[1],
|
values[1],
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
extern crate stderrlog;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate glium;
|
extern crate glium;
|
||||||
#[macro_use]
|
|
||||||
extern crate verbose_log;
|
|
||||||
extern crate model_converter;
|
extern crate model_converter;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
@ -52,11 +53,16 @@ fn main() {
|
||||||
.arg(Arg::with_name("verbose")
|
.arg(Arg::with_name("verbose")
|
||||||
.short("v")
|
.short("v")
|
||||||
.long("verbose")
|
.long("verbose")
|
||||||
|
.multiple(true)
|
||||||
.help("Shows logs during the parsing of the model"))
|
.help("Shows logs during the parsing of the model"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// Set verbose flag
|
// Set verbose flag
|
||||||
verbose_log::set(matches.occurrences_of("verbose") > 0);
|
stderrlog::new()
|
||||||
|
.module(module_path!())
|
||||||
|
.verbosity(matches.occurrences_of("verbose") as usize)
|
||||||
|
.init()
|
||||||
|
.expect("Couldn't initialize logger");
|
||||||
|
|
||||||
let mut capture_count = 0;
|
let mut capture_count = 0;
|
||||||
|
|
||||||
|
@ -69,6 +75,9 @@ fn main() {
|
||||||
let mut models = vec![];
|
let mut models = vec![];
|
||||||
|
|
||||||
for input in matches.values_of("input").unwrap() {
|
for input in matches.values_of("input").unwrap() {
|
||||||
|
|
||||||
|
info!("Parsing model {}", input);
|
||||||
|
|
||||||
match parse_file(&input) {
|
match parse_file(&input) {
|
||||||
Ok(model) => {
|
Ok(model) => {
|
||||||
if model.vertices.len() > 0 {
|
if model.vertices.len() > 0 {
|
||||||
|
@ -77,7 +86,7 @@ fn main() {
|
||||||
models.push((input.to_owned(), model))
|
models.push((input.to_owned(), model))
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error while parsing file: {}", e);
|
error!("Error while parsing file: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -95,24 +104,25 @@ fn main() {
|
||||||
let mut duration;
|
let mut duration;
|
||||||
|
|
||||||
for (name, mut model) in models {
|
for (name, mut model) in models {
|
||||||
log!("Scaling model {}...", name);
|
info!("Scaling model {}...", name);
|
||||||
model.center_and_scale_from_box(&bbox);
|
model.center_and_scale_from_box(&bbox);
|
||||||
|
|
||||||
log!("\nBuilding textures for model {}...", name);
|
info!("Building textures for model {}...", name);
|
||||||
|
|
||||||
before = Instant::now();
|
before = Instant::now();
|
||||||
model.build_textures(&renderer);
|
model.build_textures(&renderer);
|
||||||
duration = Instant::now().duration_since(before);
|
duration = Instant::now().duration_since(before);
|
||||||
|
|
||||||
log!(" done in {}ms.\nBuilding vertex buffers for model {}...",
|
info!("Done in {}ms.", as_millis(duration));
|
||||||
as_millis(duration) ,name);
|
info!("Building vertex buffers for model {}...", name);
|
||||||
|
|
||||||
before = Instant::now();
|
before = Instant::now();
|
||||||
model.build_vertex_buffers(&renderer);
|
model.build_vertex_buffers(&renderer);
|
||||||
duration = Instant::now().duration_since(before);
|
duration = Instant::now().duration_since(before);
|
||||||
|
|
||||||
scene.emplace(model);
|
scene.emplace(model);
|
||||||
logln!(" done in {}ms.\nFinished", as_millis(duration));
|
info!("Done in {}ms.", as_millis(duration));
|
||||||
|
info!("Finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut closed = false;
|
let mut closed = false;
|
||||||
|
@ -174,13 +184,13 @@ fn main() {
|
||||||
}, ..
|
}, ..
|
||||||
}, ..
|
}, ..
|
||||||
} => {
|
} => {
|
||||||
println!("Camera:");
|
trace!("Camera:");
|
||||||
|
|
||||||
println!("\tPosition: ({}, {}, {})",
|
trace!("\tPosition: ({}, {}, {})",
|
||||||
camera.position.x(), camera.position.y(), camera.position.z());
|
camera.position.x(), camera.position.y(), camera.position.z());
|
||||||
println!("\tTarget: ({}, {}, {})",
|
trace!("\tTarget: ({}, {}, {})",
|
||||||
camera.target.x(), camera.target.y(), camera.target.z());
|
camera.target.x(), camera.target.y(), camera.target.z());
|
||||||
println!("\tUp: ({}, {}, {})",
|
trace!("\tUp: ({}, {}, {})",
|
||||||
camera.up.x(), camera.up.y(), camera.up.z());
|
camera.up.x(), camera.up.y(), camera.up.z());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue