00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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;
00047
00049 ShObjVertex(
const ShPoint3f &p);
00050 };
00051
00052
struct ShObjFace:
public ShMeshFace<ShObjMeshType> {
00053 ShNormal3f normal;
00054 };
00055
00056
struct ShObjEdge:
public ShMeshEdge<ShObjMeshType> {
00057
00058 ShNormal3f normal;
00059 ShVector3f tangent;
00060 ShTexCoord2f texcoord;
00061 };
00062
00063
00064
00065
00066
00067
00068
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