From db5b272a1b5042254e048e3d07f66eb615f83a5c Mon Sep 17 00:00:00 2001 From: Arthur Brainville Date: Tue, 20 Feb 2018 01:30:15 +0100 Subject: [PATCH] Load the normal vectors of the primitive Signed-off-by: Arthur Brainville (Ybalrid) --- examples/raytrace/gltf-loader.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/raytrace/gltf-loader.cc b/examples/raytrace/gltf-loader.cc index b17d848..58cee99 100644 --- a/examples/raytrace/gltf-loader.cc +++ b/examples/raytrace/gltf-loader.cc @@ -283,6 +283,32 @@ bool LoadGLTF(const std::string &filename, float scale, if (attribute.first == "NORMAL") { std::cout << "found normal attribute\n"; + + switch (attribAccessor.componentType) { + case TINYGLTF_COMPONENT_TYPE_FLOAT: + switch (attribAccessor.type) { + case TINYGLTF_TYPE_VEC3: { + std::cout << "normal vec3\n"; + v3fArray normals( + arrayAdapter(dataPtr, count, byte_stride)); + for (size_t i{0}; i < indices.size(); ++i) { + const auto index{indices[i]}; + const auto v = normals[index]; + std::cout << '(' << v.x << ", " << v.y << ", " << v.z + << ")\n"; + } + } break; + case TINYGLTF_TYPE_VEC4: + std::cout << "normal vec4"; + break; + default: + // TODO handle error + break; + } + default: + // TODO handle error + break; + } } } }