mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-09-24 16:23:16 +08:00
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:
parent
8eb0fbb3d4
commit
0e0a884378
@ -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.type) {
|
||||||
|
case TINYGLTF_TYPE_VEC3: {
|
||||||
switch (attribAccessor.componentType) {
|
switch (attribAccessor.componentType) {
|
||||||
case TINYGLTF_COMPONENT_TYPE_FLOAT:
|
case TINYGLTF_COMPONENT_TYPE_FLOAT:
|
||||||
std::cout << "Type is FLOAT\n";
|
std::cout << "Type is FLOAT\n";
|
||||||
switch (attribAccessor.type) {
|
|
||||||
case TINYGLTF_TYPE_VEC3: {
|
|
||||||
// 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,10 +187,6 @@ 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: {
|
||||||
@ -201,37 +197,41 @@ bool LoadGLTF(const std::string &filename, float scale,
|
|||||||
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) {
|
|
||||||
case TINYGLTF_COMPONENT_TYPE_FLOAT:
|
|
||||||
switch (attribAccessor.type) {
|
switch (attribAccessor.type) {
|
||||||
case TINYGLTF_TYPE_VEC3: {
|
case TINYGLTF_TYPE_VEC3: {
|
||||||
|
switch (attribAccessor.componentType) {
|
||||||
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO handle error
|
// TODO handle error
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
case TINYGLTF_TYPE_VEC4:
|
||||||
// TODO handle error
|
std::cout << "normal vec4";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user