00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TOXIC_DRIVER_SCENEBUILDER_H
00024 #define TOXIC_DRIVER_SCENEBUILDER_H
00025
00026 #include "common/math/matrix4.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector3.h"
00029 #include "common/misc/consoleprogressmonitor.h"
00030 #include "common/misc/stringutils.h"
00031 #include "objectrepository.h"
00032 #include "renderer/color3.h"
00033 #include "renderer/globals.h"
00034 #include "renderer/imagetexture.h"
00035 #include "renderer/iobject.h"
00036 #include "renderer/meshbuilder.h"
00037 #include "surfaceshaderrepository.h"
00038
00039 #include <xercesc/dom/DOM.hpp>
00040
00041 #include <memory>
00042 #include <string>
00043
00044 namespace toxic {
00045
00046 class Collection;
00047 class Color3;
00048 class ConstantTexture;
00049 class Context;
00050 class Framebuffer;
00051 class IBDF;
00052 class IEDF;
00053
00054 class ISurfaceShader;
00055 class ITexture;
00056 class Octree;
00057 class ParameterMap;
00058 class Scene;
00059
00060
00061 class PinholeCamera;
00062 class ThinLensCamera;
00063
00064
00065 class PointLight;
00066
00067
00068 class Cube;
00069 class Mesh;
00070 class Plane;
00071 class Ring;
00072 class Sphere;
00073 class Square;
00074
00075 class SceneBuilder {
00076 public:
00077
00078 struct LoadErrorException {
00079 LoadErrorException(const std::string &message) :
00080 m_message(message) {}
00081
00082 std::string m_message;
00083 };
00084
00085
00086
00087
00088 struct ParseErrorException : public LoadErrorException {
00089 ParseErrorException(const std::string &message) :
00090 LoadErrorException(message) {}
00091 };
00092
00093 struct MultipleDefinitionException : public LoadErrorException {
00094 MultipleDefinitionException(const std::string &element) :
00095 LoadErrorException("Multiple definition of '" + element + "'.") {}
00096 };
00097
00098 SceneBuilder(
00099 const Context &context,
00100 const Framebuffer *framebuffer,
00101 const std::string &filename,
00102 const std::string &home_path,
00103 sheep::ConsoleProgressMonitor *progmon);
00104
00105 ~SceneBuilder();
00106
00107 std::auto_ptr<Scene> GetScene();
00108 std::auto_ptr<ICamera> GetCamera();
00109
00110 private:
00111 const Context &m_context;
00112 const Framebuffer *m_framebuffer;
00113 const std::string m_path;
00114 sheep::ConsoleProgressMonitor *m_progmon;
00115
00116 SurfaceShaderRepository m_surface_shaders;
00117 ObjectRepository m_objects;
00118
00119 Collection *m_root;
00120 Octree *m_octree;
00121
00122 std::auto_ptr<Scene> m_scene;
00123 std::auto_ptr<ICamera> m_camera;
00124
00125 sheep::Vector3 parse_vector3(const std::string &s) const;
00126 Color3 parse_color3(const std::string &s) const;
00127
00128 void parse_parameter(
00129 const xercesc::DOMNode *node,
00130 std::string *name,
00131 std::string *value
00132 ) const;
00133
00134 void store_parameter(
00135 const std::string &name,
00136 const std::string &value,
00137 ParameterMap *params
00138 ) const;
00139
00140 void parse_file(const std::string &filename, const std::string &home_path);
00141 void parse_root(const xercesc::DOMNode *noden);
00142 void parse_frame(const xercesc::DOMNode *node);
00143
00144 const IBDF *bdf_builder(const xercesc::DOMNode *node) const;
00145 const ConstantTexture *constant_texture_builder(const xercesc::DOMNode *node) const;
00146 const IEDF *edf_builder(const xercesc::DOMNode *node) const;
00147 const ImageTexture *image_texture_builder(const xercesc::DOMNode *node) const;
00148 sheep::Matrix4 matrix_builder(const xercesc::DOMNode *node) const;
00149 void object_builder(const xercesc::DOMNode *node);
00150 Color3 radiant_exitance_builder(const xercesc::DOMNode *node) const;
00151 const ITexture *reflectance_builder(const xercesc::DOMNode *node) const;
00152 sheep::Matrix4 rotation_builder(const xercesc::DOMNode *node) const;
00153 sheep::Matrix4 scale_builder(const xercesc::DOMNode *node) const;
00154 void surface_shader_builder(const xercesc::DOMNode *node);
00155 sheep::Matrix4 transform_builder(const xercesc::DOMNode *node) const;
00156 sheep::Matrix4 translation_builder(const xercesc::DOMNode *node) const;
00157
00158 void insert_into_repository(const std::string &key, const IObject *object);
00159 void insert_into_scene(IBoundedObject *object);
00160 void insert_into_scene(Plane *plane);
00161
00162
00163
00164 PinholeCamera *pinholecamera_builder(
00165 const sheep::Matrix4 &transform,
00166 const ParameterMap ¶ms
00167 ) const;
00168
00169 ThinLensCamera *thinlenscamera_builder(
00170 const sheep::Matrix4 &transform,
00171 const ParameterMap ¶ms
00172 ) const;
00173
00174
00175
00176 PointLight *pointlight_builder(
00177 const sheep::Matrix4 &transform,
00178 const ParameterMap ¶ms
00179 ) const;
00180
00181
00182
00183 Cube *cube_builder(
00184 const sheep::Matrix4 &transform,
00185 IObject::IntersectionMask intersection_mask,
00186 const ParameterMap ¶ms
00187 ) const;
00188
00189 MeshBuilder::MeshVector mesh_builder(
00190 const sheep::Matrix4 &transform,
00191 IObject::IntersectionMask intersection_mask,
00192 const ParameterMap ¶ms
00193 ) const;
00194
00195 Plane *plane_builder(
00196 const sheep::Matrix4 &transform,
00197 IObject::IntersectionMask intersection_mask,
00198 const ParameterMap ¶ms
00199 ) const;
00200
00201 Ring *ring_builder(
00202 const sheep::Matrix4 &transform,
00203 IObject::IntersectionMask intersection_mask,
00204 const ParameterMap ¶ms
00205 ) const;
00206
00207 Sphere *sphere_builder(
00208 const sheep::Matrix4 &transform,
00209 IObject::IntersectionMask intersection_mask,
00210 const ParameterMap ¶ms
00211 ) const;
00212
00213 Square *square_builder(
00214 const sheep::Matrix4 &transform,
00215 IObject::IntersectionMask intersection_mask,
00216 const ParameterMap ¶ms
00217 ) const;
00218 };
00219
00220 #include "scenebuilder.inl"
00221
00222 }
00223
00224 #endif // !TOXIC_DRIVER_SCENEBUILDER_H