| 165 | } |
| 166 | |
| 167 | void ModelDef::Compact() |
| 168 | { |
| 169 | for (auto& mesh : mMeshes) |
| 170 | { |
| 171 | for (auto& prims : mesh.mPrimitives) |
| 172 | { |
| 173 | Array<int> vtxMap; |
| 174 | vtxMap.Insert(0, -1, prims.mVertices.mSize); |
| 175 | int newVtxIdx = 0; |
| 176 | |
| 177 | for (uint16 vtxIdx : prims.mIndices) |
| 178 | { |
| 179 | if (vtxMap[vtxIdx] == -1) |
| 180 | vtxMap[vtxIdx] = newVtxIdx++; |
| 181 | } |
| 182 | |
| 183 | if (newVtxIdx >= prims.mVertices.mSize) |
| 184 | continue; |
| 185 | |
| 186 | for (uint16& vtxIdx : prims.mIndices) |
| 187 | vtxIdx = vtxMap[vtxIdx]; |
| 188 | |
| 189 | Array<ModelVertex> oldVertices = prims.mVertices; |
| 190 | prims.mVertices.Resize(newVtxIdx); |
| 191 | for (int oldVtxIdx = 0; oldVtxIdx < oldVertices.mSize; oldVtxIdx++) |
| 192 | { |
| 193 | int newVtxIdx = vtxMap[oldVtxIdx]; |
| 194 | if (newVtxIdx != -1) |
| 195 | prims.mVertices[newVtxIdx] = oldVertices[oldVtxIdx]; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void ModelDef::CalcBounds() |
| 202 | { |
no test coverage detected