Check the type of vectors before checking the type of their component

This order makes more sense.

Signed-off by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
Arthur Brainville (Ybalrid) 2018-02-24 22:09:17 +01:00
parent 8eb0fbb3d4
commit 0e0a884378
No known key found for this signature in database
GPG Key ID: BC05C4812A06BCF3

View File

@ -166,11 +166,11 @@ bool LoadGLTF(const std::string &filename, float scale,
pMax.y = attribAccessor.maxValues[1]; pMax.y = attribAccessor.maxValues[1];
pMax.z = attribAccessor.maxValues[2]; pMax.z = attribAccessor.maxValues[2];
switch (attribAccessor.componentType) { switch (attribAccessor.type) {
case TINYGLTF_COMPONENT_TYPE_FLOAT: case TINYGLTF_TYPE_VEC3: {
std::cout << "Type is FLOAT\n"; switch (attribAccessor.componentType) {
switch (attribAccessor.type) { case TINYGLTF_COMPONENT_TYPE_FLOAT:
case TINYGLTF_TYPE_VEC3: { std::cout << "Type is FLOAT\n";
// 3D vector of float // 3D vector of float
v3fArray positions( v3fArray positions(
arrayAdapter<v3f>(dataPtr, count, byte_stride)); arrayAdapter<v3f>(dataPtr, count, byte_stride));
@ -187,51 +187,51 @@ bool LoadGLTF(const std::string &filename, float scale,
loadedMesh.vertices.push_back(v.y * scale); loadedMesh.vertices.push_back(v.y * scale);
loadedMesh.vertices.push_back(v.z * scale); loadedMesh.vertices.push_back(v.z * scale);
} }
} break;
default:
// TODO Handle error
break;
} }
break; break;
case TINYGLTF_COMPONENT_TYPE_DOUBLE: { case TINYGLTF_COMPONENT_TYPE_DOUBLE: {
std::cout << "Type is DOUBLE\n"; std::cout << "Type is DOUBLE\n";
switch (attribAccessor.type) { switch (attribAccessor.type) {
case TINYGLTF_TYPE_VEC3: { case TINYGLTF_TYPE_VEC3: {
v3dArray positions( v3dArray positions(
arrayAdapter<v3d>(dataPtr, count, byte_stride)); arrayAdapter<v3d>(dataPtr, count, byte_stride));
for (size_t i{0}; i < positions.size(); ++i) { for (size_t i{0}; i < positions.size(); ++i) {
const auto v = positions[i]; const auto v = positions[i];
std::cout << "positions[" << i << "]: (" << v.x << ", " std::cout << "positions[" << i << "]: (" << v.x
<< v.y << ", " << v.z << ")\n"; << ", " << v.y << ", " << v.z << ")\n";
loadedMesh.vertices.push_back(v.x * scale); loadedMesh.vertices.push_back(v.x * scale);
loadedMesh.vertices.push_back(v.y * scale); loadedMesh.vertices.push_back(v.y * scale);
loadedMesh.vertices.push_back(v.z * scale); loadedMesh.vertices.push_back(v.z * scale);
} }
} break; } break;
default:
// TODO Handle error
break;
}
break;
default: default:
break; break;
} }
} break; } break;
default:
// TODO handle error
break;
} }
} }
if (attribute.first == "NORMAL") { if (attribute.first == "NORMAL") {
std::cout << "found normal attribute\n"; std::cout << "found normal attribute\n";
switch (attribAccessor.componentType) { switch (attribAccessor.type) {
case TINYGLTF_COMPONENT_TYPE_FLOAT: case TINYGLTF_TYPE_VEC3: {
switch (attribAccessor.type) { switch (attribAccessor.componentType) {
case TINYGLTF_TYPE_VEC3: { case TINYGLTF_COMPONENT_TYPE_FLOAT:
std::cout << "normal vec3\n"; std::cout << "normal vec3\n";
v3fArray normals( v3fArray normals(
arrayAdapter<v3f>(dataPtr, count, byte_stride)); arrayAdapter<v3f>(dataPtr, count, byte_stride));
// IMPORTANT: We need to reorder normals (and texture // IMPORTANT: We need to reorder normals (and texture
// coordinates into "facevarying" order) for each face // coordinates into "facevarying" order) for each face
// For each triangle :
for (size_t i{0}; i < indices.size() / 3; ++i) { for (size_t i{0}; i < indices.size() / 3; ++i) {
// get the i'th triange's indexes // get the i'th triange's indexes
auto f0 = indices[3 * i + 0]; auto f0 = indices[3 * i + 0];
@ -250,23 +250,23 @@ bool LoadGLTF(const std::string &filename, float scale,
loadedMesh.facevarying_normals.push_back(n0.x); loadedMesh.facevarying_normals.push_back(n0.x);
loadedMesh.facevarying_normals.push_back(n0.y); loadedMesh.facevarying_normals.push_back(n0.y);
loadedMesh.facevarying_normals.push_back(n0.z); loadedMesh.facevarying_normals.push_back(n0.z);
loadedMesh.facevarying_normals.push_back(n1.x); loadedMesh.facevarying_normals.push_back(n1.x);
loadedMesh.facevarying_normals.push_back(n1.y); loadedMesh.facevarying_normals.push_back(n1.y);
loadedMesh.facevarying_normals.push_back(n2.z); loadedMesh.facevarying_normals.push_back(n2.z);
loadedMesh.facevarying_normals.push_back(n2.x); loadedMesh.facevarying_normals.push_back(n2.x);
loadedMesh.facevarying_normals.push_back(n2.y); loadedMesh.facevarying_normals.push_back(n2.y);
loadedMesh.facevarying_normals.push_back(n2.z); loadedMesh.facevarying_normals.push_back(n2.z);
} }
} break;
case TINYGLTF_TYPE_VEC4:
std::cout << "normal vec4";
break;
default:
// TODO handle error
break;
} }
default: break;
// TODO handle error default:
// TODO handle error
break;
}
case TINYGLTF_TYPE_VEC4:
std::cout << "normal vec4";
break; break;
} }
} }