- Timestamp:
- 07/24/15 12:52:05 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/nmd_loader.cc
r431 r442 6 6 7 7 #include "nv/formats/nmd_loader.hh" 8 #include "nv/io/std_stream.hh"9 8 #include "nv/stl/string.hh" 10 9 #include "nv/interface/data_channel_access.hh" -
trunk/src/formats/obj_loader.cc
r433 r442 6 6 7 7 #include "nv/formats/obj_loader.hh" 8 #include "nv/io/std_stream.hh"9 8 #include "nv/interface/data_channel_access.hh" 10 9 11 #include < sstream>10 #include <cstdio> 12 11 13 12 using namespace nv; … … 50 49 vector< vec2 > t; 51 50 52 std::string line; 53 std::string cmd; 54 std::string name; 55 std::string next_name; 51 string32 name; 52 string32 next_name; 56 53 57 54 nv::size_t size; … … 59 56 60 57 obj_reader(); 61 bool read_stream( st d::istream& stream);58 bool read_stream( stream& str ); 62 59 virtual nv::size_t add_face( uint32* vi, uint32* ti, uint32* ni, nv::size_t count ) = 0; 63 60 virtual nv::size_t raw_size() const = 0; … … 79 76 } 80 77 81 bool obj_reader::read_stream( st d::istream& stream)82 { 83 name = next_name;78 bool obj_reader::read_stream( stream& str ) 79 { 80 name.assign( next_name ); 84 81 bool added_faces = false; 85 82 f32 x, y, z; 86 83 if ( eof ) return false; 87 88 while ( std::getline( stream, line ) ) 89 { 90 if ( line.length() < 3 || line[0] == '#' ) 91 { 92 continue; 93 } 94 95 std::istringstream ss(line); 96 ss >> cmd; 97 98 if ( cmd == "v" ) 99 { 100 ss >> x >> y >> z; 84 char buffer[256]; 85 while ( str.gets( buffer, 256 ) ) 86 { 87 string_view cline( static_cast<const char*>( buffer ) ); 88 cline = nv::trimmed( cline ); 89 90 if ( cline.length() < 3 || cline[0] == '#' ) 91 { 92 continue; 93 } 94 95 if ( cline.starts_with( "vn " ) ) 96 { 97 sscanf( cline.data(), "vn %f %f %f", &x, &y, &z ); 98 n.push_back( vec3( x, y, z ) ); 99 continue; 100 } 101 102 if ( cline.starts_with( "vt " ) ) 103 { 104 sscanf( cline.data(), "vt %f %f", &x, &y ); 105 t.push_back( vec2( x, 1.0f - y ) ); 106 continue; 107 } 108 109 if ( cline.starts_with( "v " ) ) 110 { 111 sscanf( cline.data(), "v %f %f %f", &x, &y, &z ); 101 112 v.push_back( vec3( x, y, z ) ); 102 113 continue; 103 114 } 104 115 105 if ( cmd == "vn" ) 106 { 107 ss >> x >> y >> z; 108 n.push_back( vec3( x, y, z ) ); 109 continue; 110 } 111 112 if ( cmd == "vt" ) 113 { 114 ss >> x >> y; 115 t.push_back( vec2( x, 1.0f - y ) ); 116 continue; 117 } 118 119 if ( cmd == "f" ) 116 if ( cline.starts_with( "f " ) ) 120 117 { 121 118 added_faces = true; 122 ss >> cmd;123 119 124 120 uint32 vis[8]; … … 128 124 uint32 count = 0; 129 125 130 while ( !ss.fail() ) 126 string_view scan( cline ); 127 scan.remove_prefix( 2 ); 128 size_t pos = 0; 129 while ( pos != string_view::npos ) 131 130 { 132 char ch; 133 134 std::istringstream ss2( cmd ); 135 ss2 >> vis[count] >> ch; 136 ss2 >> tis[count] >> ch; 137 if ( ch == '/') 131 scan.remove_prefix( pos ); 132 scan = nv::trimmed( scan ); 133 if ( sscanf( scan.data(), "%u/%u/%u", &vis[count], &tis[count], &nis[count] ) == 3 ) 138 134 { 139 135 normals = true; 140 ss2 >> nis[count];141 136 } 142 143 ss >> cmd; 137 else if ( !normals && sscanf( scan.data(), "%u/%u", &vis[count], &tis[count] ) == 2 ) 138 { 139 140 } 141 else 142 { 143 break; 144 } 144 145 count++; 146 pos = scan.find_first_of( "\t " ); 145 147 } 146 148 … … 149 151 } 150 152 151 if ( c md == "g")152 { 153 ss >> next_name;153 if ( cline.starts_with( "g " ) ) 154 { 155 next_name.assign( nv::trimmed( cline.without_prefix( 2 ) ) ); 154 156 if (added_faces) 155 157 return true; 156 name = next_name;157 continue; 158 } 159 160 if ( c md == "s")158 name.assign( next_name ); 159 continue; 160 } 161 162 if ( cline.starts_with( "s " ) ) 161 163 { 162 164 continue; … … 317 319 else 318 320 reader = new mesh_data_reader_vt(); 319 std_stream sstream( &source ); 320 321 while ( reader->read_stream( sstream ) ) 321 while ( reader->read_stream( source ) ) 322 322 { 323 323 if ( m_tangents ) … … 328 328 data_channel_set* result = data_channel_set_creator::create_set( 1 ); 329 329 data_channel_set_creator raccess( result ); 330 raccess.set_name( make_name( reader->name .c_str()) );330 raccess.set_name( make_name( reader->name ) ); 331 331 uint8* rdata = raccess.add_channel( m_descriptor, reader->size * 3 ).raw_data(); 332 332 -
trunk/src/io/c_stream.cc
r406 r442 47 47 } 48 48 49 bool c_stream::gets( char* buffer, size_t max_count ) 50 { 51 NV_ASSERT( buffer != nullptr && max_count != 0, "Bad parameter passed to write!" ); 52 char* result = ::fgets( buffer, max_count, reinterpret_cast<FILE*>( m_file ) ); 53 if ( !result ) return false; 54 return true; 55 } 56 49 57 bool c_stream::seek( long offset, origin orig ) 50 58 { -
trunk/src/stl/string.cc
r438 r442 11 11 #include <cstdio> 12 12 #include <cstdlib> 13 #include <fstream> // for slurp only14 #include <sstream> // for slurp only15 13 16 14 using namespace nv;
Note: See TracChangeset
for help on using the changeset viewer.