00001 #ifndef SCENEBUILDER_H
00002 #define SCENEBUILDER_H
00003
00004
00005 #include <string>
00006 #include <sstream>
00007 #include <exception>
00008 #include <map>
00009
00010
00011 class Scene;
00012 class Camera;
00013 class Light;
00014 class Texture;
00015 class Shader;
00016 class Object;
00017 class CameraFactory;
00018 class LightFactory;
00019 class ShaderFactory;
00020 class ObjectFactory;
00021 class Transformator;
00022 class AnimatorParser;
00023
00024
00030 class SceneBuilder
00031 {
00032 public:
00035 SceneBuilder();
00036
00039 ~SceneBuilder();
00040
00051 void load( Scene & scene,
00052 Camera *& camera,
00053 const std::string & fileName,
00054 bool parseScene = true );
00055
00056
00061 class SceneParseException : public std::exception
00062 {
00063 public:
00070 SceneParseException(const std::string & filename, int line, const std::string & msg) throw()
00071 : mFileName(filename),
00072 mLine(line),
00073 mMsg(msg)
00074 {
00075 }
00076
00079 virtual ~SceneParseException() throw()
00080 {
00081 }
00082
00085 const char* what() const throw()
00086 {
00087 std::stringstream error;
00088 error << "Parse error in file \"" << mFileName << "\" line " << mLine << ":\n";
00089 error << mMsg;
00090 static std::string outerror;
00091 outerror = error.str();
00092 return outerror.c_str();
00093 }
00094
00095 private:
00097 const std::string mFileName;
00098
00100 int mLine;
00101
00103 const std::string mMsg;
00104 };
00105 private:
00107 std::string mFileName;
00108
00110 std::stringstream mLine;
00111
00113 int mLineNr;
00114
00116 std::map<std::string, Light *> mLights;
00117
00119 std::map<std::string, Texture *> mTextures;
00120
00122 std::map<std::string, Shader *> mShaders;
00123
00125 std::map<std::string, Object *> mObjects;
00126
00128 std::vector<CameraFactory *> mCameraParsers;
00129
00131 std::vector<LightFactory *> mLightParsers;
00132
00134 std::vector<ShaderFactory *> mShaderParsers;
00135
00137 std::vector<ObjectFactory *> mObjectParsers;
00138
00140 std::vector<Transformator *> mTransformators;
00141
00143 std::vector<AnimatorParser * > mPhysicsParsers;
00144
00145
00152 std::string nextOperator(std::istream & ifile);
00153
00159 void makeScene(Scene & scene);
00160
00166 Camera * makeCamera(const std::string & type);
00167
00174 void addLight(Scene & scene, const std::string & type);
00175
00182 void addTexture(Scene & scene, const std::string & type);
00183
00190 void addShader(Scene & scene, const std::string & type);
00191
00198 void addObject(Scene & scene, const std::string & type);
00199
00205 void doInit(const std::string & type);
00206
00213 void addPhysicsStep(Scene & scene, const std::string & type);
00214
00215
00216
00217 void clear();
00218 };
00219
00220
00221 #endif
00222