00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/TriMesh.h"
00026 #include "cinder/Stream.h"
00027
00028 #include <boost/logic/tribool.hpp>
00029 #include <boost/tuple/tuple_comparison.hpp>
00030 #include <map>
00031
00032 namespace cinder {
00033
00045 class ObjLoader {
00046 public:
00050 ObjLoader( shared_ptr<IStream> aStream, bool includeUVs = true );
00051 ~ObjLoader();
00052
00058 void load( TriMesh *destTriMesh, boost::tribool loadNormals = boost::logic::indeterminate, boost::tribool loadTexCoords = boost::logic::indeterminate, bool optimizeVertices = true );
00063 void load( size_t groupIndex, TriMesh *destTriMesh, boost::tribool loadNormals = boost::logic::indeterminate, boost::tribool loadTexCoords = boost::logic::indeterminate, bool optimizeVertices = true );
00064
00065 struct Face {
00066 int mNumVertices;
00067 std::vector<int> mVertexIndices;
00068 std::vector<int> mTexCoordIndices;
00069 std::vector<int> mNormalIndices;
00070 };
00071
00072 struct Group {
00073 std::string mName;
00074 int mBaseVertexOffset, mBaseTexCoordOffset, mBaseNormalOffset;
00075 std::vector<Face> mFaces;
00076 bool mHasTexCoords;
00077 bool mHasNormals;
00078 };
00079
00080 private:
00081 typedef boost::tuple<int,int> VertexPair;
00082 typedef boost::tuple<int,int,int> VertexTriple;
00083
00084 void parseFace( Group *group, const std::string &s, bool includeUVs );
00085 void loadInternalNoOptimize( const Group &group, TriMesh *destTriMesh, bool texCoords, bool normals );
00086 void loadInternalNormalsTextures( const Group &group, std::map<boost::tuple<int,int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00087 void loadInternalNormals( const Group &group, std::map<boost::tuple<int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00088 void loadInternalTextures( const Group &group, std::map<boost::tuple<int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00089 void loadInternal( const Group &group, std::map<int,int> &uniqueVerts, TriMesh *destTriMesh );
00090
00091 shared_ptr<IStream> mStream;
00092 std::vector<Vec3f> mVertices, mNormals;
00093 std::vector<Vec2f> mTexCoords;
00094 std::vector<Group> mGroups;
00095 };
00096
00097 }