Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

meshbuilder.h

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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>   // std::auto_ptr<>
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         //! 'm' is the object space to world space transformation matrix.
00051         //! If 'surface_shader' is set to 0, materials described in the mesh file
00052         //! will be used. Otherwise, the specified material will be assigned to
00053         //! every submesh.
00054         MeshBuilder(
00055             const sheep::Matrix4 &m,
00056             const ISurfaceShader *surface_shader,   //!< May be 0.
00057             IObject::IntersectionMask intersection_mask = IObject::INTERSECT_ALL_RAYS);
00058 
00059         virtual ~MeshBuilder();
00060 
00061         // IMeshBuilder interface.
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         // IGeometryBuilder interface.
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         // IMaterialBuilder interface.
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); //!< 24-bit RGB format.
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

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6