MCPcopy Create free account
hub / github.com/Siv3D/OpenSiv3D / LoadObjWithCallback

Function LoadObjWithCallback

Siv3D/src/ThirdParty/tinyobjloader/tiny_obj_loader.h:2886–3168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2884}
2885
2886bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
2887 void *user_data /*= NULL*/,
2888 MaterialReader *readMatFn /*= NULL*/,
2889 std::string *warn, /* = NULL*/
2890 std::string *err /*= NULL*/) {
2891 std::stringstream errss;
2892
2893 // material
2894 std::map<std::string, int> material_map;
2895 int material_id = -1; // -1 = invalid
2896
2897 std::vector<index_t> indices;
2898 std::vector<material_t> materials;
2899 std::vector<std::string> names;
2900 names.reserve(2);
2901 std::vector<const char *> names_out;
2902
2903 std::string linebuf;
2904 while (inStream.peek() != -1) {
2905 safeGetline(inStream, linebuf);
2906
2907 // Trim newline '\r\n' or '\n'
2908 if (linebuf.size() > 0) {
2909 if (linebuf[linebuf.size() - 1] == '\n')
2910 linebuf.erase(linebuf.size() - 1);
2911 }
2912 if (linebuf.size() > 0) {
2913 if (linebuf[linebuf.size() - 1] == '\r')
2914 linebuf.erase(linebuf.size() - 1);
2915 }
2916
2917 // Skip if empty line.
2918 if (linebuf.empty()) {
2919 continue;
2920 }
2921
2922 // Skip leading space.
2923 const char *token = linebuf.c_str();
2924 token += strspn(token, " \t");
2925
2926 assert(token);
2927 if (token[0] == '\0') continue; // empty line
2928
2929 if (token[0] == '#') continue; // comment line
2930
2931 // vertex
2932 if (token[0] == 'v' && IS_SPACE((token[1]))) {
2933 token += 2;
2934 // TODO(syoyo): Support parsing vertex color extension.
2935 real_t x, y, z, w; // w is optional. default = 1.0
2936 parseV(&x, &y, &z, &w, &token);
2937 if (callback.vertex_cb) {
2938 callback.vertex_cb(user_data, x, y, z, w);
2939 }
2940 continue;
2941 }
2942
2943 // normal

Callers

nothing calls this directly

Calls 15

parseVFunction · 0.85
parseReal3Function · 0.85
parseRawTripleFunction · 0.85
SplitStringFunction · 0.85
parseStringFunction · 0.85
parseTagTripleFunction · 0.85
parseRealFunction · 0.85
stringClass · 0.50
reserveMethod · 0.45
peekMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected