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_RENDERER_MESHBUILDER_H
00024 #define TOXIC_RENDERER_MESHBUILDER_H
00025
00026 #include "common/math/matrix4.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector2.h"
00029 #include "common/math/vector3.h"
00030 #include "common/meshio/imeshbuilder.h"
00031 #include "globals.h"
00032 #include "mesh.h"
00033
00034 #include <memory>
00035 #include <string>
00036 #include <vector>
00037
00038 namespace toxic {
00039
00040 class ISurfaceShader;
00041 class Map2;
00042 class Scene;
00043
00044 class MeshBuilder :
00045 public sheep::IMeshBuilder,
00046 public sheep::IMeshBuilder::IGeometryBuilder,
00047 public sheep::IMeshBuilder::IMaterialBuilder
00048 {
00049 public:
00050
00051
00052
00053
00054 MeshBuilder(
00055 const sheep::Matrix4 &m,
00056 const ISurfaceShader *surface_shader,
00057 IObject::IntersectionMask intersection_mask = IObject::INTERSECT_ALL_RAYS);
00058
00059 virtual ~MeshBuilder();
00060
00061
00062
00063 typedef Mesh MeshType;
00064 typedef std::vector<Mesh *> MeshVector;
00065
00066 virtual IMeshBuilder::IGeometryBuilder *GeometryBuilder();
00067 virtual IMeshBuilder::IMaterialBuilder *MaterialBuilder();
00068
00069 MeshVector GetMeshes() const;
00070
00071
00072
00073 virtual void BeginSubMesh(const std::string &name);
00074 virtual void EndSubMesh();
00075
00076 virtual FeatureId AppendVertex(const sheep::Vector3 &v);
00077 virtual FeatureId AppendNormal(const sheep::Vector3 &vn);
00078 virtual FeatureId AppendTexCoord(const sheep::Vector2 &vt);
00079 virtual FeatureId AppendFace(int n, const FeatureId *v);
00080
00081 virtual void SetFaceNormals(FeatureId face, int n, const FeatureId *vn);
00082 virtual void SetFaceTexCoords(FeatureId face, int n, const FeatureId *vt);
00083
00084 virtual void SetMaterial(FeatureId material);
00085
00086
00087
00088 virtual FeatureId BeginMaterial(const std::string &name);
00089 virtual void EndMaterial();
00090
00091 virtual void SetAmbientColor(sheep::Real r, sheep::Real g, sheep::Real b);
00092 virtual void SetDiffuseColor(sheep::Real r, sheep::Real g, sheep::Real b);
00093 virtual void SetSpecularColor(sheep::Real r, sheep::Real g, sheep::Real b);
00094
00095 virtual void SetTexture(int w, int h, const unsigned char *texels);
00096
00097 private:
00098 sheep::Matrix4 m_m;
00099 const ISurfaceShader *m_surface_shader;
00100 IObject::IntersectionMask m_intersection_mask;
00101
00102 MeshVector m_meshes;
00103
00104 std::vector<const ISurfaceShader *> m_surface_shaders;
00105 Color3 m_diffuse_color;
00106 const Map2 *m_texture_map;
00107 };
00108
00109 #include "meshbuilder.inl"
00110
00111 }
00112
00113 #endif // !TOXIC_RENDERER_MESHBUILDER_H