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 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHUTIL_SHOBJMESH_HPP
00025 #define SHUTIL_SHOBJMESH_HPP
00026 
00027 #include <iosfwd>
00028 
00029 #include "sh.hpp"
00030 #include "ShMesh.hpp"
00031 
00032 namespace ShUtil {
00033 
00034 using namespace SH;
00035 
00036 struct ShObjVertex; 
00037 struct ShObjFace;
00038 struct ShObjEdge;
00039 
00040 typedef ShMeshType<ShObjVertex, ShObjFace, ShObjEdge> ShObjMeshType;
00041 
00042 struct ShObjVertex: public ShMeshVertex<ShObjMeshType> {
00043   ShPoint3f pos; // vertex position
00044 
00046   ShObjVertex(const ShPoint3f &p);
00047 };
00048 
00049 struct ShObjFace: public ShMeshFace<ShObjMeshType> {
00050   ShNormal3f normal; // face normal
00051 };
00052 
00053 struct ShObjEdge: public ShMeshEdge<ShObjMeshType> {
00054   // properties for start vertex in this edge's face
00055   ShNormal3f normal;  
00056   ShVector3f tangent;
00057   ShTexCoord2f texcoord;
00058 };
00059 
00060 /* OBJ file mesh where each vertex stores its position,
00061  * Each edge stores the normal/tc/tangent for its start vertex,
00062  * and each face stores its face normal
00063  *
00064  * Each face in the object mesh is a triangle. (Triangulation
00065  * happens on loading from the OBJ file)
00066  */
00067 class ShObjMesh: public ShMesh<ShObjMeshType> {
00068   public:
00069     typedef ShMesh<ShObjMeshType> ParentType;
00070 
00072     ShObjMesh();
00073 
00075     ShObjMesh(std::istream &in);
00076 
00078     std::istream& readObj(std::istream &in);
00079 
00081     void generateFaceNormals();
00082 
00087     int generateVertexNormals(bool force = false);
00088 
00094     int generateTangents(bool force = false);
00095 
00101     int generateSphericalTexCoords(bool force = false);
00102 
00104     void normalizeNormals();
00105 
00109     void consolidateVertices();
00110 
00112     friend std::istream& operator>>(std::istream &in, ShObjMesh &mesh);
00113 };
00114 
00115 }
00116 
00117 #endif

Generated on Wed Jun 15 18:12:41 2005 for Sh by  doxygen 1.4.3-20050530