-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_obj.rs
32 lines (28 loc) · 979 Bytes
/
load_obj.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Sorry, but I'm most comfortable in Rust :p.
fn main() {
let arg = std::env::args().skip(1).next().unwrap();
let obj = std::fs::read_to_string(arg).unwrap();
let mut faces = vec![];
let mut vertices = vec![];
for line in obj.lines() {
let split = line.split(' ').collect::<Vec<_>>();
if split[0] == "v" {
vertices.push([
split[1].parse::<f32>().unwrap(),
split[2].parse::<f32>().unwrap(),
split[3].parse::<f32>().unwrap(),
]);
} else if split[0] == "f" {
faces.push([
split[1].parse::<usize>().unwrap(),
split[2].parse::<usize>().unwrap(),
split[3].parse::<usize>().unwrap(),
]);
}
}
let mut out = vec![];
for face in faces.into_iter().flatten() {
out.push(vertices[face - 1]);
}
eprintln!("{:?}", out.into_iter().flatten().collect::<Vec<_>>());
}