1 module wavefront.obj;
2 
3 import utga;
4 import std.conv;
5 import std.stdio;
6 import std.array;
7 import std.algorithm;
8 
9 public import wavefront.geometry;
10 
11 
12 class Model
13 {
14 private:
15 
16 	Vec3f[] verts_;
17 	int[][] faces_;
18 
19 
20 public:
21 
22 	this(string filename)
23 	{
24 		auto f = File(filename, "r");
25 		foreach (line; f.byLine) {
26 			if (line.startsWith("v ")) {
27 				Vec3f v;
28 				v.raw = line[2..$].splitter.map!(to!float).array;
29 				verts_ ~= v;
30 			}
31 			else if (line.startsWith("f ")) {
32 				int[] face;
33 				int tmp;
34 				foreach (pol; line[2..$].splitter) {
35 					tmp = to!int(pol.splitter("/").array[0]) - 1;
36 					face ~= tmp;
37 				}
38 				faces_ ~= face;
39 			}
40 		}
41 		stderr.writefln("# v# %d f# %d", verts_.length, faces_.length);
42 	}
43 
44 	@property
45 	auto nverts()
46 	{
47 		return verts_.length;
48 	}
49 
50 	@property
51 	auto nfaces()
52 	{
53 		return faces_.length;
54 	}
55 
56 	auto face(int idx)
57 	{
58 		return faces_[idx];
59 	}
60 
61 	auto vert(int idx)
62 	{
63 		return verts_[idx];
64 	}
65 
66 	@property
67 	auto faces()
68 	{
69 		return faces_;
70 	}
71 }