1
1
use crossterm:: { cursor, Crossterm , InputEvent , KeyEvent , RawScreen } ;
2
2
use std:: error:: Error ;
3
3
use std:: f32;
4
- use std:: fs:: OpenOptions ;
5
4
use std:: io:: { stdout, Write } ;
6
- use std:: path:: Path ;
7
5
use std:: time:: Instant ;
8
6
9
7
use nalgebra:: Rotation3 ;
@@ -22,37 +20,8 @@ pub use inputs::*;
22
20
23
21
fn main ( ) -> Result < ( ) , Box < Error > > {
24
22
let matches = cli_matches ( ) ; // Read command line arguments
25
- let mut mesh_queue: Vec < SimpleMesh > = vec ! [ ] ; // A list of meshes to render
26
- for slice in matches. value_of ( "INPUT FILENAME" ) . unwrap ( ) . split ( ' ' ) {
27
- let error = |s : & str , e : & str | -> Vec < SimpleMesh > {
28
- println ! ( "filename: [{}] couldn't load, {}. {}" , slice, s, e) ;
29
- vec ! [ ]
30
- } ;
31
- // Fill list with file inputs (Splits for spaces -> multiple files)
32
- let path = Path :: new ( slice) ;
33
- let mut meshes = match path. extension ( ) {
34
- None => error ( "couldn't determine filename extension" , "" ) ,
35
- Some ( ext) => match ext. to_str ( ) {
36
- None => error ( "couldn't parse filename extension" , "" ) ,
37
- Some ( extstr) => match & * extstr. to_lowercase ( ) {
38
- "obj" => match tobj:: load_obj ( & path) {
39
- Err ( e) => error ( "tobj couldnt load/parse OBJ" , & e. to_string ( ) ) ,
40
- Ok ( present) => to_meshes ( present. 0 , present. 1 ) ,
41
- } ,
42
- "stl" => match OpenOptions :: new ( ) . read ( true ) . open ( & path) {
43
- Err ( e) => error ( "STL load failed" , & e. to_string ( ) ) ,
44
- Ok ( mut file) => match stl_io:: read_stl ( & mut file) {
45
- Err ( e) => error ( "stl_io couldnt parse STL" , & e. to_string ( ) ) ,
46
- Ok ( stlio_mesh) => vec ! [ stlio_mesh. to_simple_mesh( ) ] ,
47
- } ,
48
- } ,
49
- _ => error ( "unknown filename extension" , "" ) ,
50
- } ,
51
- } ,
52
- } ;
53
- mesh_queue. append ( & mut meshes) ;
54
- }
55
23
24
+ let mesh_queue: Vec < SimpleMesh > = match_meshes ( & matches) ?; // A list of meshes to render
56
25
let mut turntable = match_turntable ( & matches) ?;
57
26
let crossterm = Crossterm :: new ( ) ;
58
27
let input = crossterm. input ( ) ;
@@ -88,17 +57,21 @@ fn main() -> Result<(), Box<Error>> {
88
57
let mut last_time; // Used in the variable time step
89
58
loop {
90
59
last_time = Instant :: now ( ) ;
91
- if let Some ( b) = stdin. next ( ) {
92
- match b {
93
- InputEvent :: Keyboard ( event) => match event {
94
- KeyEvent :: Char ( 'q' ) => break ,
60
+ if !context. image {
61
+ if let Some ( b) = stdin. next ( ) {
62
+ match b {
63
+ InputEvent :: Keyboard ( event) => match event {
64
+ KeyEvent :: Char ( 'q' ) => {
65
+ cursor. show ( ) ?;
66
+ break ;
67
+ } ,
68
+ _ => { }
69
+ } ,
95
70
_ => { }
96
- } ,
97
- _ => { }
71
+ }
98
72
}
99
73
}
100
- let rot =
101
- Rotation3 :: from_euler_angles ( turntable. 0 , turntable. 1 , turntable. 2 ) . to_homogeneous ( ) ;
74
+ let rot = Rotation3 :: from_euler_angles ( turntable. 0 , turntable. 1 , turntable. 2 ) . to_homogeneous ( ) ;
102
75
context. update ( size, & mesh_queue) ?; // This checks for if there needs to be a context update
103
76
context. clear ( ) ; // This clears the z and frame buffer
104
77
for mesh in & mesh_queue {
@@ -134,6 +107,5 @@ fn main() -> Result<(), Box<Error>> {
134
107
}
135
108
}
136
109
137
- cursor. show ( ) ?;
138
110
Ok ( ( ) )
139
111
}
0 commit comments