Small code cleanup

Signed-off-by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
Arthur Brainville 2018-02-21 08:56:09 +01:00
parent 0b4f54162b
commit 07e6c5c109
No known key found for this signature in database
GPG Key ID: BC05C4812A06BCF3

View File

@ -70,7 +70,7 @@ bool LoadGLTF(const std::string &filename, float scale,
Mesh<float> loadedMesh(sizeof(float) * 3); Mesh<float> loadedMesh(sizeof(float) * 3);
v3f pMin, pMax; v3f pMin = {}, pMax = {};
loadedMesh.name = gltfMesh.name; loadedMesh.name = gltfMesh.name;
for (const auto &meshPrimitive : gltfMesh.primitives) { for (const auto &meshPrimitive : gltfMesh.primitives) {
@ -80,12 +80,13 @@ bool LoadGLTF(const std::string &filename, float scale,
auto &indicesAccessor = model.accessors[meshPrimitive.indices]; auto &indicesAccessor = model.accessors[meshPrimitive.indices];
auto &bufferView = model.bufferViews[indicesAccessor.bufferView]; auto &bufferView = model.bufferViews[indicesAccessor.bufferView];
auto &buffer = model.buffers[bufferView.buffer]; auto &buffer = model.buffers[bufferView.buffer];
unsigned char *dataAddress = buffer.data.data() + auto dataAddress = buffer.data.data() + bufferView.byteOffset +
bufferView.byteOffset +
indicesAccessor.byteOffset; indicesAccessor.byteOffset;
const auto byteStride = indicesAccessor.ByteStride(bufferView); const auto byteStride = indicesAccessor.ByteStride(bufferView);
const auto count = indicesAccessor.count; const auto count = indicesAccessor.count;
// Allocate the index array in the pointer-to-base declared in the
// parent scope
switch (indicesAccessor.componentType) { switch (indicesAccessor.componentType) {
case TINYGLTF_COMPONENT_TYPE_BYTE: case TINYGLTF_COMPONENT_TYPE_BYTE:
indicesArrayPtr = indicesArrayPtr =
@ -125,12 +126,14 @@ bool LoadGLTF(const std::string &filename, float scale,
break; break;
} }
} }
// Get access to the index array. Don't worry about underlying type
const auto &indices = *indicesArrayPtr; const auto &indices = *indicesArrayPtr;
if (indicesArrayPtr) if (indicesArrayPtr)
for (size_t i(0); i < indicesArrayPtr->size(); ++i) { for (size_t i(0); i < indices.size(); ++i) {
std::cout << indices[i] << " ";
loadedMesh.faces.push_back(indices[i]); loadedMesh.faces.push_back(indices[i]);
std::cout << indices[i] << " ";
} }
std::cout << '\n'; std::cout << '\n';