MCPcopy Create free account
hub / github.com/Apress/Ray-Tracing-Gems-II / LoadObjWithCallback

Function LoadObjWithCallback

Chapter_39/tiny_obj_loader.h:2642–2923  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2640 }
2641
2642 bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
2643 void *user_data /*= NULL*/,
2644 MaterialReader *readMatFn /*= NULL*/,
2645 std::string *warn, /* = NULL*/
2646 std::string *err /*= NULL*/) {
2647 std::stringstream errss;
2648
2649 // material
2650 std::map<std::string, int> material_map;
2651 int material_id = -1; // -1 = invalid
2652
2653 std::vector<index_t> indices;
2654 std::vector<material_t> materials;
2655 std::vector<std::string> names;
2656 names.reserve(2);
2657 std::vector<const char *> names_out;
2658
2659 std::string linebuf;
2660 while (inStream.peek() != -1) {
2661 safeGetline(inStream, linebuf);
2662
2663 // Trim newline '\r\n' or '\n'
2664 if (linebuf.size() > 0) {
2665 if (linebuf[linebuf.size() - 1] == '\n')
2666 linebuf.erase(linebuf.size() - 1);
2667 }
2668 if (linebuf.size() > 0) {
2669 if (linebuf[linebuf.size() - 1] == '\r')
2670 linebuf.erase(linebuf.size() - 1);
2671 }
2672
2673 // Skip if empty line.
2674 if (linebuf.empty()) {
2675 continue;
2676 }
2677
2678 // Skip leading space.
2679 const char *token = linebuf.c_str();
2680 token += strspn(token, " \t");
2681
2682 assert(token);
2683 if (token[0] == '\0') continue; // empty line
2684
2685 if (token[0] == '#') continue; // comment line
2686
2687 // vertex
2688 if (token[0] == 'v' && IS_SPACE((token[1]))) {
2689 token += 2;
2690 // TODO(syoyo): Support parsing vertex color extension.
2691 real_t x, y, z, w; // w is optional. default = 1.0
2692 parseV(&x, &y, &z, &w, &token);
2693 if (callback.vertex_cb) {
2694 callback.vertex_cb(user_data, x, y, z, w);
2695 }
2696 continue;
2697 }
2698
2699 // normal

Callers

nothing calls this directly

Calls 15

assertFunction · 0.85
stringFunction · 0.85
eraseMethod · 0.80
c_strMethod · 0.80
parseVFunction · 0.70
parseReal3Function · 0.70
parseRawTripleFunction · 0.70
SplitStringFunction · 0.70
parseStringFunction · 0.70
parseTagTripleFunction · 0.70
parseRealFunction · 0.70
reserveMethod · 0.45

Tested by

no test coverage detected