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_ASELOADER_H
00024 #define SHEEP_MESHIO_ASELOADER_H
00025
00026 #include "imeshbuilder.h"
00027 #include "imeshloader.h"
00028 #include "keywordtable.h"
00029
00030 #include <cassert>
00031 #include <cstdio>
00032 #include <map>
00033 #include <string>
00034 #include <vector>
00035
00036 namespace sheep {
00037
00038 class ProgressMonitor;
00039
00040 class ASELoader : public IMeshLoader {
00041 public:
00042 struct ExtendedLoadingException : public LoadingException {
00043 ExtendedLoadingException(int line) :
00044 m_line(line) {}
00045
00046 const int m_line;
00047 };
00048
00049
00050 struct ParsingException : public ExtendedLoadingException {
00051 ParsingException(int line) : ExtendedLoadingException(line) {}
00052 };
00053
00054 ASELoader();
00055
00056 virtual void Load(
00057 const std::string &filename,
00058 IMeshBuilder &builder,
00059 int option_mask = DEFAULT_CONFIGURATION_BIT,
00060 ProgressMonitor *progmon = 0
00061 ) throw(LoadingException);
00062
00063 private:
00064 enum symbol {
00065 END_OF_FILE = 256, IDENTIFIER,
00066 STRING, INTEGER, DOUBLE,
00067
00068
00069 BITMAP, GEOMOBJECT, MAP_DIFFUSE, MATERIAL, MATERIAL_AMBIENT,
00070 MATERIAL_DIFFUSE, MATERIAL_LIST, MATERIAL_NAME, MATERIAL_REF,
00071 MATERIAL_SPECULAR, MESH, MESH_FACE, MESH_FACE_LIST,
00072 MESH_FACENORMAL, MESH_MTLID, MESH_NORMALS, MESH_SMOOTHING,
00073 MESH_TFACE, MESH_TFACELIST, MESH_TVERT, MESH_TVERTLIST, MESH_VERTEX,
00074 MESH_VERTEX_LIST, MESH_VERTEXNORMAL, NODE_NAME, SUBMATERIAL,
00075 WIREFRAME_COLOR,
00076
00077
00078 UNKNOWN_KEYWORD
00079 };
00080
00081 struct look_ahead {
00082 int m_sym;
00083 struct m_val_u {
00084 std::string m_str;
00085 int m_int;
00086 double m_dbl;
00087 } m_val;
00088 };
00089
00090 KeywordTable m_keyword_table;
00091
00092 std::string m_path;
00093
00094 IMeshBuilder::IGeometryBuilder *m_geombuilder;
00095 IMeshBuilder::IMaterialBuilder *m_matbuilder;
00096
00097 int m_option_mask;
00098
00099 ProgressMonitor *m_progmon;
00100
00101 FILE *m_file;
00102 int m_line;
00103 look_ahead m_look_ahead;
00104
00105 int m_geomobject_index;
00106
00107 struct material_key {
00108 int m_material_index;
00109 int m_submaterial_index;
00110
00111 material_key(int material_index, int submaterial_index) :
00112 m_material_index(material_index),
00113 m_submaterial_index(submaterial_index) {}
00114
00115 bool operator<(const material_key &k) const {
00116 if(m_material_index < k.m_material_index)
00117 return true;
00118 if(m_material_index > k.m_material_index)
00119 return false;
00120 return m_submaterial_index < k.m_submaterial_index;
00121 }
00122 };
00123
00124
00125 std::map<material_key, IMeshBuilder::FeatureId> m_mat_key_to_mat_id;
00126
00127
00128
00129 std::map<int, int> m_submaterial_count;
00130
00131 struct mesh_data {
00132
00133 struct face {
00134 int m_vertex_index[3];
00135 int m_texcoord_index[3];
00136 int m_normal_index[3];
00137 std::vector<int> m_sg;
00138 int m_submaterial_index;
00139 };
00140
00141 std::vector<Vector3> m_vertices;
00142 std::vector<Vector2> m_texcoords;
00143 std::vector<Vector3> m_normals;
00144 std::vector<face> m_faces;
00145
00146
00147 int m_material_index;
00148
00149
00150 bool m_has_wf_color;
00151
00152
00153
00154 double m_wf_r, m_wf_g, m_wf_b;
00155
00156 mesh_data() :
00157 m_material_index(-1),
00158 m_has_wf_color(false)
00159 {
00160
00161 }
00162 };
00163
00164 typedef std::vector<mesh_data *> mesh_data_vector;
00165
00166 mesh_data_vector m_mesh_data;
00167
00168 void parse_error();
00169
00170 int read_char();
00171 void unread_char(int c);
00172 int look_ahead() const;
00173
00174 void next();
00175
00176 void accept(int token);
00177 std::string accept_string();
00178 int accept_integer();
00179 double accept_double();
00180
00181 void skip_compound();
00182 void skip_statement();
00183
00184 void parse_file();
00185
00186 void parse_geomobject();
00187 void parse_map_diffuse();
00188 void parse_material(
00189 int material_index,
00190 bool is_submaterial = false,
00191 int submaterial_index = 0);
00192 void parse_material_list();
00193 void parse_mesh();
00194 void parse_mesh_face_list();
00195 void parse_mesh_normals();
00196 void parse_mesh_tfacelist();
00197 void parse_mesh_tvertlist();
00198 void parse_mesh_vertex_list();
00199
00200 void dispatch_mesh_data();
00201 };
00202
00203 #include "aseloader.inl"
00204
00205 }
00206
00207 #endif // !SHEEP_MESHIO_ASELOADER_H