From db1e8b3e8b09d3f82381cb269f17e98e18c69947 Mon Sep 17 00:00:00 2001 From: Arthur Brainville Date: Tue, 20 Feb 2018 21:42:44 +0100 Subject: [PATCH] added loading of doubles for position Signed-off-by: Arthur Brainville (Ybalrid) --- examples/raytrace/gltf-loader.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/raytrace/gltf-loader.cc b/examples/raytrace/gltf-loader.cc index 588f8f6..1553166 100644 --- a/examples/raytrace/gltf-loader.cc +++ b/examples/raytrace/gltf-loader.cc @@ -153,17 +153,20 @@ bool LoadGLTF(const std::string &filename, float scale, if (attribute.first == "POSITION") { std::cout << "found position attribute\n"; + + // get the position min/max for computing the boundingbox pMin.x = attribAccessor.minValues[0]; pMin.y = attribAccessor.minValues[1]; pMin.z = attribAccessor.minValues[2]; pMax.x = attribAccessor.maxValues[0]; pMax.y = attribAccessor.maxValues[1]; pMax.z = attribAccessor.maxValues[2]; + switch (attribAccessor.componentType) { case TINYGLTF_COMPONENT_TYPE_FLOAT: switch (attribAccessor.type) { case TINYGLTF_TYPE_VEC3: { - /// 3D vector of float + // 3D vector of float v3fArray positions( arrayAdapter(dataPtr, count, byte_stride)); for (size_t i{0}; i < positions.size(); ++i) { @@ -180,7 +183,25 @@ bool LoadGLTF(const std::string &filename, float scale, // TODO Handle error break; } - break; + case TINYGLTF_COMPONENT_TYPE_DOUBLE: { + switch (attribAccessor.type) { + case TINYGLTF_TYPE_VEC3: { + v3dArray positions( + arrayAdapter(dataPtr, count, byte_stride)); + for (size_t i{0}; i < positions.size(); ++i) { + const auto v = positions[i]; + std::cout << '(' << v.x << ", " << v.y << ", " << v.z + << ")\n"; + + loadedMesh.vertices.push_back(v.x * scale); + loadedMesh.vertices.push_back(v.y * scale); + loadedMesh.vertices.push_back(v.z * scale); + } + } break; + default: + break; + } + } break; default: // TODO handle error break;