MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / GetObjFileStats

Function GetObjFileStats

Source/Graphics/model.cpp:326–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324};
325
326bool GetObjFileStats(std::string rel_path, ObjFileStats &stats, bool file_necessary) {
327 stats.num_normal = 0;
328 stats.num_tex = 0;
329 stats.num_vert = 0;
330 stats.num_face = 0;
331 stats.objects = 0;
332
333 char abs_path[kPathSize];
334 FindFilePath(rel_path.c_str(), abs_path, kPathSize, kAnyPath, file_necessary);
335 FILE *fp = my_fopen(abs_path, "r");
336
337 if (!fp) {
338 if (file_necessary) {
339 FatalError("Error", "Could not open file fs \"%s\"", rel_path.c_str());
340 } else {
341 return false;
342 }
343 }
344
345 char buffer[256];
346 while (!feof(fp)) {
347 memset(buffer, 0, 200);
348 fgets(buffer, 256, fp);
349
350 if (strncmp("vn ", buffer, 3) == 0)
351 ++stats.num_normal;
352 else if (strncmp("vt ", buffer, 3) == 0)
353 ++stats.num_tex;
354 else if (strncmp("v ", buffer, 2) == 0)
355 ++stats.num_vert;
356 else if (strncmp("f ", buffer, 2) == 0)
357 ++stats.num_face;
358 else if (strncmp("o ", buffer, 2) == 0)
359 ++stats.objects;
360 }
361
362 // There is always at least one object in a file.
363 if (stats.objects == 0)
364 stats.objects = 1;
365
366 fclose(fp);
367
368 return true;
369}
370
371struct TempModel {
372 std::vector<GLfloat> vertices;

Callers 3

LoadObjMethod · 0.85
LoadObjMorphMethod · 0.85

Calls 4

FindFilePathFunction · 0.85
my_fopenFunction · 0.85
FatalErrorFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected