31 #include "MeshException.h" 37 static const int MESH_ATTRIBUTE_NOT_PROVIDED = -1;
47 MESH_SHADING_NONE = (0),
48 MESH_SHADING_FLAT = (1 << 0),
49 MESH_SHADING_SMOOTH = (1 << 1),
50 MESH_SHADING_TEXTURE = (1 << 2),
51 MESH_SHADING_COLOR = (1 << 3),
52 MESH_SHADING_MATERIAL = (1 << 4),
53 MESH_SHADING_FLAT_SHADE = (1 << 5),
54 MESH_SHADING_SPECULAR_SHADE = (1 << 6)
73 SUTILAPI
void setToDefaultParams();
78 float diffuse_trans[4];
83 float index_of_refraction;
85 float reflectivity[4];
100 typedef std::map<std::string, int> MeshMaterialNumbersMap;
114 texture_coordinate_indices( 0 ),
115 material_indices( 0 ),
119 SUTILAPI ~MeshGroup() { }
128 int* texture_coordinate_indices;
129 int* material_indices;
134 typedef std::map<std::string, MeshGroup> MeshGroupMap;
207 template <
class Functor>
208 void forEachGroup( Functor functor )
const;
210 template <
class Functor>
211 void forEachGroup( Functor functor );
213 int getNumVertices()
const {
return m_num_vertices; }
214 int getNumNormals()
const {
return m_num_normals; }
215 int getNumColors()
const {
return m_num_colors; }
216 int getNumTextureCoordinates()
const {
return m_num_texture_coordinates; }
218 int getNumTriangles()
const {
return m_num_triangles; }
219 int getNumGroups()
const {
return (
int)m_mesh_groups.size(); }
221 float* getVertexData() {
return m_vertex_data; }
222 const float* getVertexData()
const {
return m_vertex_data; }
224 float* getNormalData() {
return m_normal_data; }
225 const float* getNormalData()
const {
return m_normal_data; }
227 unsigned char* getColorData() {
return m_color_data; }
228 const unsigned char* getColorData()
const {
return m_color_data; }
230 float* getTextureCoordinateData() {
return m_texture_coordinate_data; }
231 const float* getTextureCoordinateData()
const {
return m_texture_coordinate_data; }
233 int getVertexStride()
const {
return m_vertex_stride; }
234 int getNormalStride()
const {
return m_normal_stride; }
235 int getColorStride()
const {
return m_color_stride; }
236 int getTextureCoordinateStride()
const {
return m_texture_coordinate_stride; }
238 const float* getBBoxMin()
const {
return m_bbox_min; }
239 const float* getBBoxMax()
const {
return m_bbox_max; }
243 const std::string& getMaterialLibraryName()
const {
return m_material_library_name; }
245 MeshGroup& getMeshGroup(
const std::string& group_name) {
246 MeshGroupMap::iterator found = m_mesh_groups.find(group_name);
247 if( found != m_mesh_groups.end() ) {
248 return found->second;
251 throw MeshException(
"Could not find group named '" + group_name +
"'" );
255 const MeshGroup& getMeshGroup(
const std::string& group_name)
const {
256 MeshGroupMap::const_iterator found = m_mesh_groups.find(group_name);
257 if( found != m_mesh_groups.end() ) {
258 return found->second;
261 throw MeshException(
"Could not find group named '" + group_name +
"'" );
265 size_t getMaterialCount()
const {
return m_material_params.size(); }
268 m_material_params[i] = params;
272 return m_material_params[i];
277 return m_material_params[i];
280 void setMeshGrouping(MeshGrouping grouping) { m_grouping = grouping; }
281 MeshGrouping getMeshGrouping()
const {
return m_grouping; }
287 void loadFromObj(
const std::string& filename,
bool insertDefaultMaterial,
const MeshMaterialParams& defaultMaterial );
292 void loadMaterials(
const std::string& material_filename );
297 void loadFromPly(
const std::string& filename,
bool insertDefaultMaterial,
const MeshMaterialParams& defaultMaterial );
305 void setNormalData(
float* normal_data ) { m_normal_data = normal_data; }
306 void setColorData(
unsigned char* color_data ) { m_color_data = color_data; }
307 void setTextureCoordinateData(
float* texture_coordinate_data ) { m_texture_coordinate_data = texture_coordinate_data; }
308 void setMaterialIndices(
int* material_indices) { m_material_indices = material_indices; }
310 void setVertexStride(
int vertex_stride ) { m_vertex_stride = vertex_stride; }
311 void setNormalStride(
int normal_stride ) { m_normal_stride = normal_stride; }
312 void setColorStride(
int color_stride ) { m_color_stride = color_stride; }
313 void setTextureCoordinateStride(
int texture_coordinate_stride ) { m_texture_coordinate_stride = texture_coordinate_stride; }
315 void setVertexIndexStride(
int index_stride ) { m_vertex_index_stride = index_stride; }
316 void setNormalIndexStride(
int index_stride ) { m_normal_index_stride = index_stride; }
317 void setColorIndexStride(
int index_stride ) { m_color_index_stride = index_stride; }
318 void setTextureIndexStride(
int index_stride ) { m_texture_index_stride = index_stride; }
320 const std::string& getFilename()
const {
return m_filename; }
321 const std::string& getPathName()
const {
return m_pathname; }
330 virtual int getVertexTriangleSize()
const = 0;
331 virtual int getNormalTriangleSize()
const = 0;
332 virtual int getTextureTriangleSize()
const = 0;
338 virtual void preProcess() = 0;
345 virtual void allocateData() = 0;
354 virtual void startWritingData() = 0;
359 virtual void postProcess() = 0;
364 virtual void finishWritingData() = 0;
381 void loadInfoFromObj(
const std::string& filename,
bool insertDefaultMaterial,
const MeshMaterialParams& defaultMaterial );
390 void loadDataFromObj(
const std::string& filename,
bool insertDefaultMaterial,
const MeshMaterialParams& defaultMaterial );
395 void loadInfoFromPly(
const std::string& filename,
bool insertDefaultMaterial );
400 void loadDataFromPly(
const std::string& filename );
404 void initSingleGroup();
414 MeshGroup& getOrAddGroup(
const std::string& name );
416 std::string m_filename;
417 std::string m_pathname;
422 int m_num_texture_coordinates;
431 float* m_vertex_data;
432 float* m_normal_data;
433 unsigned char* m_color_data;
434 float* m_texture_coordinate_data;
435 int* m_material_indices;
443 int m_texture_coordinate_stride;
447 int m_vertex_index_stride;
448 int m_normal_index_stride;
449 int m_color_index_stride;
450 int m_texture_index_stride;
454 MeshGrouping m_grouping;
455 MeshGroupMap m_mesh_groups;
456 MeshMaterialNumbersMap m_material_numbers_by_name;
457 std::vector<MeshMaterialParams> m_material_params;
459 std::string m_material_library_name;
466 template <
class Functor>
469 MeshGroupMap::const_iterator groups_end = m_mesh_groups.end();
470 for( MeshGroupMap::const_iterator groups_iter = m_mesh_groups.begin();
471 groups_iter != groups_end; )
473 functor( (groups_iter++)->second );
479 template <
class Functor>
482 MeshGroupMap::iterator groups_end = m_mesh_groups.end();
483 for( MeshGroupMap::iterator groups_iter = m_mesh_groups.begin();
484 groups_iter != groups_end; )
486 functor( (groups_iter++)->second );
Definition: MeshBase.h:57
void forEachGroup(Functor functor) const
Definition: MeshBase.h:467
Definition: MeshException.h:38
Definition: MeshBase.h:106
void setVertexData(float *vertex_data)
Definition: MeshBase.h:304
Definition: MeshBase.h:148
Definition: MeshBase.h:67