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

meshmodifier.h

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep 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     Sheep 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 Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef SHEEP_MESHIO_MESHMODIFIER_H
00024 #define SHEEP_MESHIO_MESHMODIFIER_H
00025 
00026 #include "common/math/point3.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector2.h"
00029 #include "common/math/vector3.h"
00030 #include "imeshbuilder.h"
00031 
00032 #include <string>
00033 #include <vector>
00034 
00035 namespace sheep {
00036 
00037     class MeshModifier :
00038         public IMeshBuilder,
00039         public IMeshBuilder::IGeometryBuilder,
00040         public IMeshBuilder::IMaterialBuilder
00041     {
00042     public:
00043         MeshModifier(IMeshBuilder &builder);
00044         virtual ~MeshModifier();
00045 
00046         //! 'smoothing_threshold' is expressed in radians.
00047         void ComputeSmoothedVertexNormals(sheep::Real smoothing_threshold_angle);
00048 
00049         //! 'vertex_welding_threshold' is expressed in distance units.
00050         //! 'normal_welding_threshold' is expressed in radians.
00051         void OptimizeMesh(
00052             sheep::Real vertex_welding_threshold_dist,
00053             sheep::Real normal_welding_threshold_angle
00054         );
00055 
00056         // IMeshBuilder interface.
00057 
00058         virtual IGeometryBuilder *GeometryBuilder();
00059         virtual IMaterialBuilder *MaterialBuilder();
00060 
00061         // IGeometryBuilder interface.
00062 
00063         virtual void BeginSubMesh(const std::string &name);
00064         virtual void EndSubMesh();
00065 
00066         virtual FeatureId AppendVertex(const Vector3 &v);
00067         virtual FeatureId AppendNormal(const Vector3 &vn);
00068         virtual FeatureId AppendTexCoord(const Vector2 &vt);
00069         virtual FeatureId AppendFace(int n, const FeatureId *v);
00070 
00071         virtual void SetFaceNormals(FeatureId face, int n, const FeatureId *vn);
00072         virtual void SetFaceTexCoords(FeatureId face, int n, const FeatureId *vt);
00073 
00074         virtual void SetMaterial(FeatureId material);
00075 
00076         // IMaterialBuilder interface.
00077 
00078         virtual FeatureId BeginMaterial(const std::string &name);
00079         virtual void EndMaterial();
00080 
00081         virtual void SetAmbientColor(Real r, Real g, Real b);
00082         virtual void SetDiffuseColor(Real r, Real g, Real b);
00083         virtual void SetSpecularColor(Real r, Real g, Real b);
00084 
00085         virtual void SetTexture(int w, int h, const unsigned char *texels); //!< 24-bit RGB format.
00086 
00087     private:
00088         struct sub_mesh {
00089             struct face {
00090                 FeatureId m_v0, m_v1, m_v2;
00091                 FeatureId m_n0, m_n1, m_n2;
00092                 FeatureId m_t0, m_t1, m_t2;
00093             };
00094 
00095             std::string m_name;
00096             FeatureId m_material;
00097 
00098             std::vector<sheep::Point3> m_vertices;
00099             std::vector<sheep::Vector3> m_normals;
00100             std::vector<sheep::Vector2> m_texcoords;
00101             std::vector<face> m_faces;
00102 
00103             void ComputeSmoothedVertexNormals(sheep::Real smoothing_threshold_angle);
00104             void OptimizeVertices(sheep::Real welding_threshold_dist);
00105             void OptimizeNormals(sheep::Real welding_threshold_angle);
00106             void OptimizeFaces();
00107         };
00108 
00109         sub_mesh *m_sub_mesh;   //!< Current sub mesh being defined.
00110 
00111         IMeshBuilder &m_builder;
00112 
00113         //! Vertex normals smoothing settings.
00114         bool m_compute_smoothed_vn;
00115         sheep::Real m_smoothing_threshold_angle;    //!< Expressed in radians.
00116 
00117         //! Mesh optimization settings.
00118         bool m_optimize_mesh;
00119         sheep::Real m_vertex_welding_threshold_dist;    //!< Expressed in distance units.
00120         sheep::Real m_normal_welding_threshold_angle;   //!< Expressed in radians.
00121     };
00122 
00123 #include "meshmodifier.inl"
00124 
00125 }
00126 
00127 #endif  // !SHEEP_MESHIO_MESHMODIFIER_H

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