|
| 1 | +#include "tiny_obj_loader.h" |
| 2 | + |
| 3 | +#include <cassert> |
| 4 | +#include <iostream> |
| 5 | + |
| 6 | +int |
| 7 | +main( |
| 8 | + int argc, |
| 9 | + char **argv) |
| 10 | +{ |
| 11 | + std::string inputfile = "cornell_box.obj"; |
| 12 | + std::vector<tinyobj::shape_t> shapes; |
| 13 | + |
| 14 | + if (argc > 1) { |
| 15 | + inputfile = std::string(argv[1]); |
| 16 | + } |
| 17 | + |
| 18 | + std::string err = tinyobj::LoadObj(shapes, inputfile.c_str()); |
| 19 | + |
| 20 | + if (!err.empty()) { |
| 21 | + std::cerr << err << std::endl; |
| 22 | + } |
| 23 | + |
| 24 | + std::cout << "# of shapes : " << shapes.size() << std::endl; |
| 25 | + |
| 26 | + for (size_t i = 0; i < shapes.size(); i++) { |
| 27 | + printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str()); |
| 28 | + printf("shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size()); |
| 29 | + assert((shapes[i].mesh.indices.size() % 3) == 0); |
| 30 | + for (size_t f = 0; f < shapes[i].mesh.indices.size(); f++) { |
| 31 | + printf(" idx[%ld] = %d\n", f, shapes[i].mesh.indices[f]); |
| 32 | + } |
| 33 | + |
| 34 | + printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size()); |
| 35 | + assert((shapes[i].mesh.positions.size() % 3) == 0); |
| 36 | + for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++) { |
| 37 | + printf(" v[%ld] = (%f, %f, %f)\n", v, |
| 38 | + shapes[i].mesh.positions[3*v+0], |
| 39 | + shapes[i].mesh.positions[3*v+1], |
| 40 | + shapes[i].mesh.positions[3*v+2]); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
0 commit comments