| 713 | const int Model::ERROR_MORE_THAN_ONE_OBJECT = 1; |
| 714 | |
| 715 | int Model::SimpleLoadTriangleCutObj(const std::string &name_to_load) { |
| 716 | ObjFileStats obj_stats; |
| 717 | GetObjFileStats(name_to_load, obj_stats, true); |
| 718 | |
| 719 | TempModel temp; |
| 720 | LoadTempModel(name_to_load, temp, obj_stats); |
| 721 | |
| 722 | // Check if the obj file has more than one model object packed into it. |
| 723 | if (obj_stats.objects == 1) { |
| 724 | int num_faces = temp.fc; |
| 725 | int num_vertices = num_faces * 3; |
| 726 | |
| 727 | vertices.resize(num_vertices * 3); |
| 728 | if (obj_stats.num_normal) { |
| 729 | normals.resize(num_vertices * 3); |
| 730 | } else { |
| 731 | normals.clear(); |
| 732 | } |
| 733 | tangents.resize(num_vertices * 3, 0.0f); |
| 734 | bitangents.resize(num_vertices * 3, 0.0f); |
| 735 | tex_coords.resize(num_vertices * 2); |
| 736 | faces.resize(num_faces * 3); |
| 737 | face_normals.resize(num_faces); |
| 738 | |
| 739 | for (int i = 0, len = faces.size(); i < len; i++) { |
| 740 | faces[i] = i; |
| 741 | |
| 742 | vertices[i * 3 + 0] = temp.vertices[temp.vert_indices[i] * 3 + 0]; |
| 743 | vertices[i * 3 + 1] = temp.vertices[temp.vert_indices[i] * 3 + 1]; |
| 744 | vertices[i * 3 + 2] = temp.vertices[temp.vert_indices[i] * 3 + 2]; |
| 745 | |
| 746 | if (obj_stats.num_normal) { |
| 747 | normals[i * 3 + 0] = temp.normals[temp.norm_indices[i] * 3 + 0]; |
| 748 | normals[i * 3 + 1] = temp.normals[temp.norm_indices[i] * 3 + 1]; |
| 749 | normals[i * 3 + 2] = temp.normals[temp.norm_indices[i] * 3 + 2]; |
| 750 | } |
| 751 | |
| 752 | if (obj_stats.num_tex) { |
| 753 | tangents[i * 3 + 0] = temp.tangents[temp.tex_indices[i] * 3 + 0]; |
| 754 | tangents[i * 3 + 1] = temp.tangents[temp.tex_indices[i] * 3 + 1]; |
| 755 | tangents[i * 3 + 2] = temp.tangents[temp.tex_indices[i] * 3 + 2]; |
| 756 | |
| 757 | bitangents[i * 3 + 0] = temp.bitangents[temp.tex_indices[i] * 3 + 0]; |
| 758 | bitangents[i * 3 + 1] = temp.bitangents[temp.tex_indices[i] * 3 + 1]; |
| 759 | bitangents[i * 3 + 2] = temp.bitangents[temp.tex_indices[i] * 3 + 2]; |
| 760 | |
| 761 | tex_coords[i * 2 + 0] = temp.tex_coords[temp.tex_indices[i] * 2 + 0]; |
| 762 | tex_coords[i * 2 + 1] = temp.tex_coords[temp.tex_indices[i] * 2 + 1]; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | tex_coords2.resize(num_vertices * 2); |
| 767 | for (int i = 0; i < num_vertices; i++) { |
| 768 | tex_coords2[i * 2 + 0] = tex_coords[i * 2 + 0]; |
| 769 | tex_coords2[i * 2 + 1] = tex_coords[i * 2 + 1]; |
| 770 | } |
| 771 | } else { |
| 772 | return ERROR_MORE_THAN_ONE_OBJECT; |
no test coverage detected