Extract loadPrimitives method from createMesh

This commit is contained in:
JosiahWI 2023-05-18 07:11:33 -05:00 committed by Josiah VanderZee
parent f383dd3c84
commit 311a176cf0
2 changed files with 146 additions and 137 deletions

View File

@ -92,7 +92,18 @@ IAnimatedMesh* CGLTFMeshFileLoader::createMesh(io::IReadFile* file)
MeshExtractor parser(std::move(model));
SMesh* baseMesh(new SMesh {});
loadPrimitives(parser, baseMesh);
SAnimatedMesh* animatedMesh(new SAnimatedMesh {});
animatedMesh->addMesh(baseMesh);
return animatedMesh;
}
void CGLTFMeshFileLoader::loadPrimitives(
const MeshExtractor& parser,
SMesh* mesh)
{
for (std::size_t i = 0; i < parser.getMeshCount(); ++i) {
for (std::size_t j = 0; j < parser.getPrimitiveCount(i); ++j) {
auto indices = parser.getIndices(i, j);
@ -101,14 +112,9 @@ IAnimatedMesh* CGLTFMeshFileLoader::createMesh(io::IReadFile* file)
SMeshBuffer* meshbuf(new SMeshBuffer {});
meshbuf->append(vertices.data(), vertices.size(),
indices.data(), indices.size());
baseMesh->addMeshBuffer(meshbuf);
mesh->addMeshBuffer(meshbuf);
}
}
SAnimatedMesh* animatedMesh(new SAnimatedMesh {});
animatedMesh->addMesh(baseMesh);
return animatedMesh;
}
CGLTFMeshFileLoader::MeshExtractor::MeshExtractor(

View File

@ -7,6 +7,7 @@
#include "irrTypes.h"
#include "path.h"
#include "S3DVertex.h"
#include "SMesh.h"
#include "vector2d.h"
#include "vector3d.h"
@ -119,6 +120,8 @@ private:
const std::size_t primitiveIdx) const;
};
void loadPrimitives(const MeshExtractor& parser, SMesh* mesh);
static bool tryParseGLTF(io::IReadFile* file,
tinygltf::Model& model);
};