MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / loadObj

Method loadObj

Utilities/OBJLoader.h:32–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 */
31
32 static void loadObj(const std::string &filename, std::vector<Vec3f> *x, std::vector<MeshFaceIndices> *faces, std::vector<Vec3f> *normals, std::vector<Vec2f> *texcoords, const Vec3f &scale)
33 {
34 LOG_INFO << "Loading " << filename;
35
36 std::ifstream filestream;
37 filestream.open(filename.c_str());
38 if (filestream.fail())
39 {
40 LOG_ERR << "Failed to open file: " << filename;
41 return;
42 }
43
44 std::string line_stream;
45 bool vt = false;
46 bool vn = false;
47
48 std::vector<std::string> pos_buffer;
49 std::vector<std::string> f_buffer;
50
51 while (getline(filestream, line_stream))
52 {
53 std::stringstream str_stream(line_stream);
54 std::string type_str;
55 str_stream >> type_str;
56
57 if (type_str == "v")
58 {
59 Vec3f pos;
60 pos_buffer.clear();
61 std::string parse_str = line_stream.substr(line_stream.find("v") + 1);
62 StringTools::tokenize(parse_str, pos_buffer);
63 for (unsigned int i = 0; i < 3; i++)
64 pos[i] = stof(pos_buffer[i]) * scale[i];
65
66 x->push_back(pos);
67 }
68 else if (type_str == "vt")
69 {
70 if (texcoords != nullptr)
71 {
72 Vec2f tex;
73 pos_buffer.clear();
74 std::string parse_str = line_stream.substr(line_stream.find("vt") + 2);
75 StringTools::tokenize(parse_str, pos_buffer);
76 for (unsigned int i = 0; i < 2; i++)
77 tex[i] = stof(pos_buffer[i]);
78
79 texcoords->push_back(tex);
80 vt = true;
81 }
82 }
83 else if (type_str == "vn")
84 {
85 if (normals != nullptr)
86 {
87 Vec3f nor;
88 pos_buffer.clear();
89 std::string parse_str = line_stream.substr(line_stream.find("vn") + 2);

Callers

nothing calls this directly

Calls 8

failMethod · 0.80
substrMethod · 0.80
openMethod · 0.45
c_strMethod · 0.45
clearMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected