00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00047 void ComputeSmoothedVertexNormals(sheep::Real smoothing_threshold_angle);
00048
00049
00050
00051 void OptimizeMesh(
00052 sheep::Real vertex_welding_threshold_dist,
00053 sheep::Real normal_welding_threshold_angle
00054 );
00055
00056
00057
00058 virtual IGeometryBuilder *GeometryBuilder();
00059 virtual IMaterialBuilder *MaterialBuilder();
00060
00061
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
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);
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;
00110
00111 IMeshBuilder &m_builder;
00112
00113
00114 bool m_compute_smoothed_vn;
00115 sheep::Real m_smoothing_threshold_angle;
00116
00117
00118 bool m_optimize_mesh;
00119 sheep::Real m_vertex_welding_threshold_dist;
00120 sheep::Real m_normal_welding_threshold_angle;
00121 };
00122
00123 #include "meshmodifier.inl"
00124
00125 }
00126
00127 #endif // !SHEEP_MESHIO_MESHMODIFIER_H