| 383 | }; |
| 384 | |
| 385 | void LoadTempModel(std::string rel_path, TempModel &temp, const ObjFileStats &obj_stats) { |
| 386 | temp.vertices.resize(obj_stats.num_vert * 3); |
| 387 | temp.normals.resize(obj_stats.num_normal * 3); |
| 388 | temp.tangents.resize(obj_stats.num_tex * 3); |
| 389 | temp.bitangents.resize(obj_stats.num_tex * 3); |
| 390 | temp.tex_coords.resize(obj_stats.num_tex * 2); |
| 391 | temp.tex_coords2.resize(0); |
| 392 | temp.vert_indices.resize(obj_stats.num_face * 6); |
| 393 | temp.tex_indices.resize(obj_stats.num_face * 6); |
| 394 | temp.norm_indices.resize(obj_stats.num_face * 6); |
| 395 | |
| 396 | char abs_path[kPathSize]; |
| 397 | FindFilePath(rel_path.c_str(), abs_path, kPathSize, kAnyPath); |
| 398 | FILE *fp = my_fopen(abs_path, "r"); |
| 399 | |
| 400 | int num_read; |
| 401 | |
| 402 | temp.fc = 0; |
| 403 | temp.nc = 0; |
| 404 | temp.tc = 0; |
| 405 | temp.vc = 0; |
| 406 | |
| 407 | char buffer[256]; |
| 408 | while (!feof(fp)) { |
| 409 | memset(buffer, 0, 255); |
| 410 | fgets(buffer, 256, fp); |
| 411 | |
| 412 | if (strncmp("vn ", buffer, 3) == 0) { |
| 413 | sscanf((buffer + 2), "%f%f%f", |
| 414 | &temp.normals[temp.nc * 3 + 0], |
| 415 | &temp.normals[temp.nc * 3 + 1], |
| 416 | &temp.normals[temp.nc * 3 + 2]); |
| 417 | ++temp.nc; |
| 418 | } else if (strncmp("vt ", buffer, 3) == 0) { |
| 419 | sscanf((buffer + 2), "%f%f", |
| 420 | &temp.tex_coords[temp.tc * 2 + 0], |
| 421 | &temp.tex_coords[temp.tc * 2 + 1]); |
| 422 | ++temp.tc; |
| 423 | } else if (strncmp("v ", buffer, 2) == 0) { |
| 424 | sscanf((buffer + 1), "%f%f%f", |
| 425 | &temp.vertices[temp.vc * 3 + 0], |
| 426 | &temp.vertices[temp.vc * 3 + 1], |
| 427 | &temp.vertices[temp.vc * 3 + 2]); |
| 428 | ++temp.vc; |
| 429 | } else if (strncmp("f ", buffer, 2) == 0) { |
| 430 | if (obj_stats.num_tex && obj_stats.num_normal) { |
| 431 | num_read = sscanf(buffer + 1, "%u/%u/%u %u/%u/%u %u/%u/%u %u/%u/%u", |
| 432 | &temp.vert_indices[temp.fc * 3 + 0], |
| 433 | &temp.tex_indices[temp.fc * 3 + 0], |
| 434 | &temp.norm_indices[temp.fc * 3 + 0], |
| 435 | |
| 436 | &temp.vert_indices[temp.fc * 3 + 1], |
| 437 | &temp.tex_indices[temp.fc * 3 + 1], |
| 438 | &temp.norm_indices[temp.fc * 3 + 1], |
| 439 | |
| 440 | &temp.vert_indices[temp.fc * 3 + 2], |
| 441 | &temp.tex_indices[temp.fc * 3 + 2], |
| 442 | &temp.norm_indices[temp.fc * 3 + 2], |
no test coverage detected