MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / read

Method read

src/3D/Model.cpp:100–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100bool OBJModel::read(const std::string& fileName) {
101 faces.clear();
102 vertList.clear();
103 normList.clear();
104 uvList.clear();
105
106 std::ifstream ifs(fileName.c_str(), std::ios::in);
107 std::string line;
108 while (ifs.good() && !ifs.eof()) {
109 std::getline(ifs, line);
110 if (line.size()) {
111 // parse it
112 switch (line[0]) {
113 case 'v':
114 if (line.size() > 5) { // there have to be enough characters for a full vert
115 OBJVert v;
116
117 switch (line[1]) {
118 case 'n':
119 v.read3(line.c_str() + 2);
120 normList.push_back(v);
121 break;
122
123 case 't':
124 v.read2(line.c_str() + 2);
125 uvList.push_back(v);
126 break;
127
128 default:
129 v.read3(line.c_str() + 1);
130 vertList.push_back(v);
131 break;
132 }
133 }
134 break;
135
136 case 'f': {
137 std::vector<std::string> verts = TextUtils::tokenize(std::string(line.c_str() + 2), std::string(" "));
138 OBJFace face;
139 for (size_t v = 0; v < verts.size(); v++) {
140 std::vector<std::string> indexes = TextUtils::tokenize(verts[v], std::string("/"));
141 if (indexes.size()) {
142 face.verts.push_back(atoi(indexes[0].c_str()) - 1);
143
144 if (indexes.size() > 1 && indexes[1].size()) {
145 face.uvs.push_back(atoi(indexes[1].c_str()) - 1);
146 }
147 else {
148 face.uvs.push_back(0);
149 }
150
151 if (indexes.size() > 2 && indexes[2].size()) {
152 face.norms.push_back(atoi(indexes[2].c_str()) - 1);
153 }
154 else {
155 face.norms.push_back(0);
156 }
157 }

Callers 15

readFileMethod · 0.45
FT_Stream_SeekFunction · 0.45
FT_Stream_ReadAtFunction · 0.45
FT_Stream_TryReadFunction · 0.45
FT_Stream_EnterFrameFunction · 0.45
FT_Stream_ReadCharFunction · 0.45
FT_Stream_ReadShortFunction · 0.45
FT_Stream_ReadShortLEFunction · 0.45
FT_Stream_ReadOffsetFunction · 0.45
FT_Stream_ReadLongFunction · 0.45
FT_Stream_ReadLongLEFunction · 0.45
ft_gzip_file_fill_inputFunction · 0.45

Calls 8

c_strMethod · 0.80
read3Method · 0.80
read2Method · 0.80
tokenizeFunction · 0.50
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected