00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2005 Serious Hack Inc. 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 // MA 02110-1301, USA 00020 #ifndef SHUTIL_SHOBJMESH_HPP 00021 #define SHUTIL_SHOBJMESH_HPP 00022 00023 #include <iosfwd> 00024 00025 #include "sh.hpp" 00026 #include "ShMesh.hpp" 00027 00028 namespace ShUtil { 00029 00030 using namespace SH; 00031 00032 struct ShObjVertex; 00033 struct ShObjFace; 00034 struct ShObjEdge; 00035 00036 typedef ShMeshType<ShObjVertex, ShObjFace, ShObjEdge> ShObjMeshType; 00037 00038 struct ShObjVertex: public ShMeshVertex<ShObjMeshType> { 00039 ShPoint3f pos; // vertex position 00040 00042 ShObjVertex(const ShPoint3f &p); 00043 }; 00044 00045 struct ShObjFace: public ShMeshFace<ShObjMeshType> { 00046 ShNormal3f normal; // face normal 00047 }; 00048 00049 struct ShObjEdge: public ShMeshEdge<ShObjMeshType> { 00050 // properties for start vertex in this edge's face 00051 ShNormal3f normal; 00052 ShVector3f tangent; 00053 ShTexCoord2f texcoord; 00054 }; 00055 00056 /* OBJ file mesh where each vertex stores its position, 00057 * Each edge stores the normal/tc/tangent for its start vertex, 00058 * and each face stores its face normal 00059 * 00060 * Each face in the object mesh is a triangle. (Triangulation 00061 * happens on loading from the OBJ file) 00062 */ 00063 class ShObjMesh: public ShMesh<ShObjMeshType> { 00064 public: 00065 typedef ShMesh<ShObjMeshType> ParentType; 00066 00068 ShObjMesh(); 00069 00071 ShObjMesh(std::istream &in); 00072 00074 std::istream& readObj(std::istream &in); 00075 00077 void generateFaceNormals(); 00078 00083 int generateVertexNormals(bool force = false); 00084 00090 int generateTangents(bool force = false); 00091 00097 int generateSphericalTexCoords(bool force = false); 00098 00100 void normalizeNormals(); 00101 00105 void consolidateVertices(); 00106 00108 friend std::istream& operator>>(std::istream &in, ShObjMesh &mesh); 00109 }; 00110 00111 } 00112 00113 #endif
1.4.3-20050530