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

Function RearrangeVertices

Source/Graphics/model.cpp:63–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61
62namespace {
63void RearrangeVertices(Model &model, const std::vector<int> &new_order) {
64 std::vector<float> old_vertices = model.vertices;
65 std::vector<float> old_normals = model.normals;
66 std::vector<float> old_tex_coords = model.tex_coords;
67 std::vector<float> old_tex_coords2 = model.tex_coords2;
68 std::vector<float> old_tangents = model.tangents;
69 std::vector<float> old_bitangents = model.bitangents;
70 std::vector<float> old_aux = model.aux;
71 std::vector<vec4> old_bone_weights = model.bone_weights;
72 std::vector<vec4> old_bone_ids = model.bone_ids;
73
74 for (unsigned i = 0; i < new_order.size(); ++i) {
75 model.vertices[i * 3 + 0] = old_vertices[new_order[i] * 3 + 0];
76 model.vertices[i * 3 + 1] = old_vertices[new_order[i] * 3 + 1];
77 model.vertices[i * 3 + 2] = old_vertices[new_order[i] * 3 + 2];
78 if (!model.normals.empty()) {
79 model.normals[i * 3 + 0] = old_normals[new_order[i] * 3 + 0];
80 model.normals[i * 3 + 1] = old_normals[new_order[i] * 3 + 1];
81 model.normals[i * 3 + 2] = old_normals[new_order[i] * 3 + 2];
82 }
83 if (!model.tex_coords.empty()) {
84 model.tex_coords[i * 2 + 0] = old_tex_coords[new_order[i] * 2 + 0];
85 model.tex_coords[i * 2 + 1] = old_tex_coords[new_order[i] * 2 + 1];
86 }
87 if (!model.tex_coords2.empty()) {
88 model.tex_coords2[i * 2 + 0] = old_tex_coords2[new_order[i] * 2 + 0];
89 model.tex_coords2[i * 2 + 1] = old_tex_coords2[new_order[i] * 2 + 1];
90 }
91 if (!model.tangents.empty()) {
92 model.tangents[i * 3 + 0] = old_tangents[new_order[i] * 3 + 0];
93 model.tangents[i * 3 + 1] = old_tangents[new_order[i] * 3 + 1];
94 model.tangents[i * 3 + 2] = old_tangents[new_order[i] * 3 + 2];
95 }
96 if (!model.bitangents.empty()) {
97 model.bitangents[i * 3 + 0] = old_bitangents[new_order[i] * 3 + 0];
98 model.bitangents[i * 3 + 1] = old_bitangents[new_order[i] * 3 + 1];
99 model.bitangents[i * 3 + 2] = old_bitangents[new_order[i] * 3 + 2];
100 }
101 if (!model.aux.empty()) {
102 model.aux[i * 3 + 0] = old_aux[new_order[i] * 3 + 0];
103 model.aux[i * 3 + 1] = old_aux[new_order[i] * 3 + 1];
104 model.aux[i * 3 + 2] = old_aux[new_order[i] * 3 + 2];
105 }
106 if (!model.bone_weights.empty()) {
107 model.bone_weights[i] = old_bone_weights[new_order[i]];
108 }
109 if (!model.bone_ids.empty()) {
110 model.bone_ids[i] = old_bone_ids[new_order[i]];
111 }
112 }
113 model.ResizeVertices(new_order.size());
114}
115} // namespace
116
117// Initialize model

Callers 3

RemoveDuplicatedVertsMethod · 0.85
CopyVertCollapseMethod · 0.85
OptimizeVertexOrderMethod · 0.85

Calls 3

ResizeVerticesMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected