diff -r 062b1c4143f7 -r 907929fa9b59 src/serialize.cc --- a/src/serialize.cc Wed Apr 23 14:39:33 2008 +0200 +++ b/src/serialize.cc Wed Apr 23 19:35:03 2008 +0200 @@ -25,15 +25,18 @@ */ #include "serialize.h" +#include #include #include Indexer vertex_index, shape_index; +vector vertices; void resetSerializer() { vertex_index.reset(); shape_index.reset(); + vertices.clear(); } bool Indexer::get(void *o, int &retidx) @@ -53,32 +56,78 @@ } } -Shape *loadShape(istream &st) +Shape *loadShape(istream &st, Material *mat) { string s; istringstream is; - getline(st, s, ','); - trim(s); - if (s.compare("(box") == 0) + for (;;) { - Vector3 L,H; - st >> L; getline(st, s, ','); - st >> H; - getline(st, s, ')'); - return new Box(L, H, new Material(Colour(1,1,1))); + trim(s); + + // Vertex + if (s.compare("(v") == 0) + { + Vector3 P; + st >> P; + getline(st, s, ')'); + vertices.push_back(new Vertex(P)); + getline(st, s, ','); + continue; + } + + // NormalVertex + if (s.compare("(vn") == 0) + { + Vector3 P,N; + st >> P; + getline(st, s, ','); + st >> N; + getline(st, s, ')'); + vertices.push_back(new NormalVertex(P,N)); + getline(st, s, ','); + continue; + } + + // Triangle + if (s.compare("(t") == 0) + { + int a,b,c; + st >> a; + getline(st, s, ','); + st >> b; + getline(st, s, ','); + st >> c; + getline(st, s, ')'); + return new Triangle(vertices[a], vertices[b], vertices[c], mat); + } + + // box + if (s.compare("(box") == 0) + { + Vector3 L,H; + st >> L; + getline(st, s, ','); + st >> H; + getline(st, s, ')'); + return new Box(L, H, mat); + } + + // Sphere + if (s.compare("(sphere") == 0) + { + Vector3 center; + Float radius; + st >> center; + getline(st, s, ','); + st >> radius; + getline(st, s, ')'); + return new Sphere(center, radius, mat); + } + + // else... + return NULL; } - if (s.compare("(sphere") == 0) - { - Vector3 center; - Float radius; - st >> center; - getline(st, s, ','); - st >> radius; - getline(st, s, ')'); - return new Sphere(center, radius, new Material(Colour(1,1,1))); - } - return NULL; } ostream & operator<<(ostream &st, Shape &o)