Go to the documentation of this file.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( std::shared_ptr<IStream> aStream, bool includeUVs = true );
00054 ObjLoader( DataSourceRef dataSource, bool includeUVs = true );
00055 ~ObjLoader();
00056
00062 void load( TriMesh *destTriMesh, boost::tribool loadNormals = boost::logic::indeterminate, boost::tribool loadTexCoords = boost::logic::indeterminate, bool optimizeVertices = true );
00067 void load( size_t groupIndex, TriMesh *destTriMesh, boost::tribool loadNormals = boost::logic::indeterminate, boost::tribool loadTexCoords = boost::logic::indeterminate, bool optimizeVertices = true );
00068
00069 struct Face {
00070 int mNumVertices;
00071 std::vector<int> mVertexIndices;
00072 std::vector<int> mTexCoordIndices;
00073 std::vector<int> mNormalIndices;
00074 };
00075
00076 struct Group {
00077 std::string mName;
00078 int mBaseVertexOffset, mBaseTexCoordOffset, mBaseNormalOffset;
00079 std::vector<Face> mFaces;
00080 bool mHasTexCoords;
00081 bool mHasNormals;
00082 };
00083
00085 static void write( DataTargetRef dataTarget, const TriMesh &mesh, bool writeNormals = true, bool writeUVs = true );
00086
00087 private:
00088 typedef boost::tuple<int,int> VertexPair;
00089 typedef boost::tuple<int,int,int> VertexTriple;
00090
00091 void parse( bool includeUVs );
00092
00093 void parseFace( Group *group, const std::string &s, bool includeUVs );
00094 void loadInternalNoOptimize( const Group &group, TriMesh *destTriMesh, bool texCoords, bool normals );
00095 void loadInternalNormalsTextures( const Group &group, std::map<boost::tuple<int,int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00096 void loadInternalNormals( const Group &group, std::map<boost::tuple<int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00097 void loadInternalTextures( const Group &group, std::map<boost::tuple<int,int>,int> &uniqueVerts, TriMesh *destTriMesh );
00098 void loadInternal( const Group &group, std::map<int,int> &uniqueVerts, TriMesh *destTriMesh );
00099
00100 std::shared_ptr<IStream> mStream;
00101 std::vector<Vec3f> mVertices, mNormals;
00102 std::vector<Vec2f> mTexCoords;
00103 std::vector<Group> mGroups;
00104 };
00105
00106 }