Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShObjMesh.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHUTIL_SHOBJMESH_HPP
00028 #define SHUTIL_SHOBJMESH_HPP
00029 
00030 #include <iosfwd>
00031 
00032 #include "sh.hpp"
00033 #include "ShMesh.hpp"
00034 
00035 namespace ShUtil {
00036 
00037 using namespace SH;
00038 
00039 struct ShObjVertex; 
00040 struct ShObjFace;
00041 struct ShObjEdge;
00042 
00043 typedef ShMeshType<ShObjVertex, ShObjFace, ShObjEdge> ShObjMeshType;
00044 
00045 struct ShObjVertex: public ShMeshVertex<ShObjMeshType> {
00046   ShPoint3f pos; // vertex position
00047 
00049   ShObjVertex(const ShPoint3f &p);
00050 };
00051 
00052 struct ShObjFace: public ShMeshFace<ShObjMeshType> {
00053   ShNormal3f normal; // face normal
00054 };
00055 
00056 struct ShObjEdge: public ShMeshEdge<ShObjMeshType> {
00057   // properties for start vertex in this edge's face
00058   ShNormal3f normal;  
00059   ShVector3f tangent;
00060   ShTexCoord2f texcoord;
00061 };
00062 
00063 /* OBJ file mesh where each vertex stores its position,
00064  * Each edge stores the normal/tc/tangent for its start vertex,
00065  * and each face stores its face normal
00066  *
00067  * Each face in the object mesh is a triangle. (Triangulation
00068  * happens on loading from the OBJ file)
00069  */
00070 class ShObjMesh: public ShMesh<ShObjMeshType> {
00071   public:
00072     typedef ShMesh<ShObjMeshType> ParentType;
00073 
00075     ShObjMesh();
00076 
00078     ShObjMesh(std::istream &in);
00079 
00081     std::istream& readObj(std::istream &in);
00082 
00084     void generateFaceNormals();
00085 
00090     int generateVertexNormals(bool force = false);
00091 
00097     int generateTangents(bool force = false);
00098 
00104     int generateSphericalTexCoords(bool force = false);
00105 
00107     void normalizeNormals();
00108 
00112     void consolidateVertices();
00113 
00115     friend std::istream& operator>>(std::istream &in, ShObjMesh &mesh);
00116 };
00117 
00118 }
00119 
00120 #endif

Generated on Mon Jan 24 18:36:34 2005 for Sh by  doxygen 1.4.1