| 232 | }; |
| 233 | |
| 234 | Expected<ObjFaceInfo> parseObjFaceInfo( const std::string_view& str ) |
| 235 | { |
| 236 | using namespace boost::spirit::x3; |
| 237 | |
| 238 | ObjFaceInfo res; |
| 239 | auto v = [&] ( auto& ) |
| 240 | { |
| 241 | ++res.numVerts; |
| 242 | }; |
| 243 | auto vt = [&] ( auto& ) |
| 244 | { |
| 245 | ++res.numTexVerts; |
| 246 | }; |
| 247 | auto vn = [&] ( auto& ) |
| 248 | { |
| 249 | // normals are not used currently |
| 250 | }; |
| 251 | |
| 252 | bool r = phrase_parse( |
| 253 | str.begin(), |
| 254 | str.end(), |
| 255 | // NOTE: actions are not being reverted after backtracking |
| 256 | // https://github.com/boostorg/spirit/issues/378 |
| 257 | ( 'f' >> *( int_[v] >> -( '/' >> ( ( int_[vt] >> -( '/' >> int_[vn] ) ) | ( '/' >> int_[vn] ) ) ) ) ), |
| 258 | ascii::space |
| 259 | ); |
| 260 | if ( !r ) |
| 261 | return unexpected( "Failed to parse face in OBJ-file" ); |
| 262 | |
| 263 | if ( !res.numVerts ) |
| 264 | return unexpected( "Invalid face vertex count in OBJ-file" ); |
| 265 | if ( res.numTexVerts && res.numVerts != res.numTexVerts ) |
| 266 | return unexpected( "Invalid face texture count in OBJ-file" ); |
| 267 | return res; |
| 268 | } |
| 269 | |
| 270 | struct ObjFaces |
| 271 | { |
no test coverage detected