1 // -*-c++-*- 2 3 /* 4 * $Id$ 5 * 6 * Loader for DirectX .x files. 7 * Copyright (c)2002-2006 Ulrich Hertlein <u.hertlein@sandbox.de> 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef _MESH_H_ 25 #define _MESH_H_ 26 27 #include "types.h" 28 29 namespace DX { 30 31 class Object; 32 33 /** 34 * DirectX mesh. 35 */ 36 class Mesh { 37 public: 38 Mesh(Object * obj); ~Mesh()39 virtual ~Mesh() { 40 clear(); 41 } 42 43 void clear(); 44 45 /** 46 * Generate per-vertex normals for the mesh. 47 * @return false if an error occurred, else true. 48 */ 49 bool generateNormals(float creaseAngle); 50 51 /// Get Vertices. getVertices()52 const std::vector<Vector> & getVertices() const { 53 return _vertices; 54 } 55 56 /// Get MeshFaces. getFaces()57 const std::vector<MeshFace> & getFaces() const { 58 return _faces; 59 } 60 61 /// Get MeshTextureCoords. getMeshTextureCoords()62 inline const MeshTextureCoords* getMeshTextureCoords() const { 63 return _textureCoords; 64 } 65 66 /// Get MeshMaterialList. getMeshMaterialList()67 inline const MeshMaterialList* getMeshMaterialList() const { 68 return _materialList; 69 } 70 71 /// Get MeshNormals. getMeshNormals()72 inline const MeshNormals* getMeshNormals() const { 73 return _normals; 74 } 75 76 /// Parse 'Mesh'. 77 void parseMesh(std::istream& fin); 78 79 private: 80 Object * _obj; 81 82 std::vector<Vector> _vertices; 83 std::vector<MeshFace> _faces; 84 85 /// Normals (per-face). 86 MeshNormals* _normals; 87 88 /// Texture coordinates (per-vertex). 89 MeshTextureCoords* _textureCoords; 90 91 /// Materials. 92 MeshMaterialList* _materialList; 93 94 /// Parse 'MeshNormals'. 95 void parseMeshNormals(std::istream& fin); 96 97 /// Parse 'MeshMaterialList'. 98 void parseMeshMaterialList(std::istream& fin); 99 100 /// Read 'MeshTextureCoords'. 101 void readMeshTexCoords(std::istream& fin); 102 }; 103 104 } // namespace 105 106 #endif 107