Skip to content

Commit

Permalink
Preallocate indices at loading model. #40
Browse files Browse the repository at this point in the history
  • Loading branch information
tanitta committed Oct 5, 2016
1 parent 6c1f058 commit 88c8c97
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/armos/graphics/model.d
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,20 @@ class AssimpModelLoader {
return Vector4f(vec[0], vec[1], vec[2], 1f);
}).array;

auto totalIndices = 0;
foreach(f; mesh.mFaces[0 .. mesh.mNumFaces]) {
totalIndices += f.mNumIndices;
}

convertedMesh.indices = new int[totalIndices];
auto indexCounter = 0;
foreach(f; mesh.mFaces[0 .. mesh.mNumFaces]) {
immutable int numVertices = f.mNumIndices;
foreach(i; f.mIndices[0 .. numVertices]){
convertedMesh.addIndex(i);
convertedMesh.indices[indexCounter] = i;
indexCounter++;
}
}

// immutable mi = mesh.mMaterialIndex;
// auto material = (mi < materials.length) ? materials[mi] : null;
// convertedMesh.material = material;
Expand Down

0 comments on commit 88c8c97

Please sign in to comment.