An old commit

This commit is contained in:
Thomas Forgione 2019-06-24 09:45:27 +02:00
parent bb6bc07906
commit 3b1370ad0b
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 79 additions and 7 deletions

View File

@ -12,6 +12,9 @@ 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"
serde = "1.0.82"
serde_json = "1.0.33"
serde_derive = "1.0.82"
[[bin]] [[bin]]
name = "3d-viewer" name = "3d-viewer"

View File

@ -2,6 +2,11 @@
#![warn(missing_docs)] #![warn(missing_docs)]
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate stderrlog; extern crate stderrlog;

View File

@ -1,3 +1,9 @@
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate stderrlog; extern crate stderrlog;
@ -5,6 +11,8 @@ extern crate clap;
extern crate glium; extern crate glium;
extern crate model_converter; extern crate model_converter;
use std::fs::File;
use std::io::Write;
use std::process::exit; use std::process::exit;
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
use std::thread::sleep; use std::thread::sleep;
@ -34,6 +42,29 @@ fn as_millis(duration: Duration) -> u64 {
duration.as_secs() * 1_000 + (duration.subsec_nanos() as u64) / 1_000_000 duration.as_secs() * 1_000 + (duration.subsec_nanos() as u64) / 1_000_000
} }
#[derive(Serialize, Deserialize)]
struct Vector {
x: f64,
y: f64,
z: f64,
}
impl From<Vector3<f64>> for Vector {
fn from(v: Vector3<f64>) -> Vector {
Vector {
x: v[0],
y: v[1],
z: v[2],
}
}
}
#[derive(Serialize, Deserialize)]
struct CameraEvent {
position: Vector,
target: Vector,
}
fn main() { fn main() {
let matches = App::new("3D Viewer") let matches = App::new("3D Viewer")
@ -65,6 +96,8 @@ fn main() {
.expect("Couldn't initialize logger"); .expect("Couldn't initialize logger");
let mut capture_count = 0; let mut capture_count = 0;
let mut path_count = 0;
let mut path = vec![];
use std::f64::{MIN, MAX}; use std::f64::{MIN, MAX};
let mut bbox = BoundingBox3::new( let mut bbox = BoundingBox3::new(
@ -125,6 +158,11 @@ fn main() {
info!("Finished"); info!("Finished");
} }
let center = (bbox.min() + bbox.max()) / 2.0;
let size = (bbox.max() - bbox.min()).norm();
let center_f64 = Vector3::new(center.x() as f64, center.y() as f64, center.z() as f64);
let size_f64 = size as f64;
let mut closed = false; let mut closed = false;
let mut camera = Camera::new( let mut camera = Camera::new(
@ -149,6 +187,7 @@ fn main() {
use model_converter::controls::Controls; use model_converter::controls::Controls;
let mut recording = false;
let mut before = Instant::now(); let mut before = Instant::now();
while !closed { while !closed {
@ -175,6 +214,27 @@ fn main() {
}, .. }, ..
} => closed = true, } => closed = true,
// R key
Event::WindowEvent {
event: WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::R),
state: ElementState::Pressed, ..
}, ..
}, ..
} => {
if ! recording {
path.clear();
recording = true;
} else {
recording = false;
let string = serde_json::to_string(&path).unwrap();
let mut file = File::create(format!("path-{}.json", path_count)).unwrap();
file.write_all(string.as_bytes()).unwrap();
path_count += 1;
}
},
// Enter key // Enter key
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::KeyboardInput { event: WindowEvent::KeyboardInput {
@ -202,13 +262,7 @@ fn main() {
}, .. }, ..
}, .. }, ..
} => { } => should_screenshot = true,
should_screenshot = true;
},
_ => (), _ => (),
} }
@ -217,6 +271,16 @@ fn main() {
controls.update(&mut camera, &renderer); controls.update(&mut camera, &renderer);
renderer.render(&scene, &camera); renderer.render(&scene, &camera);
if recording {
let position = camera.position * size_f64 + center_f64;
let target = camera.target * size_f64 + center_f64;
path.push(CameraEvent {
position: position.into(),
target: target.into(),
});
}
if should_screenshot { if should_screenshot {
// Make a screenshot // Make a screenshot
let cap = renderer.capture(); let cap = renderer.capture();