diff --git a/examples/raytrace/gltf-loader.cc b/examples/raytrace/gltf-loader.cc index 1553166..57d6a95 100644 --- a/examples/raytrace/gltf-loader.cc +++ b/examples/raytrace/gltf-loader.cc @@ -240,6 +240,43 @@ bool LoadGLTF(const std::string &filename, float scale, break; } } + + if (attribute.first == "TEXCOORD_0") { + std::cout << "Found texture coordinates\n"; + + switch (attribAccessor.type) { + case TINYGLTF_TYPE_VEC2: { + switch (attribAccessor.componentType) { + case TINYGLTF_COMPONENT_TYPE_FLOAT: { + v2fArray uvs( + arrayAdapter(dataPtr, count, byte_stride)); + for (size_t i{0}; i < uvs.size(); ++i) { + const auto v = uvs[i]; + std::cout << '(' << v.x << ", " << v.y << ")\n"; + + loadedMesh.facevarying_uvs.push_back(v.x); + loadedMesh.facevarying_uvs.push_back(v.y); + } + } break; + case TINYGLTF_COMPONENT_TYPE_DOUBLE: { + v2dArray uvs( + arrayAdapter(dataPtr, count, byte_stride)); + for (size_t i{0}; i < uvs.size(); ++i) { + const auto v = uvs[i]; + std::cout << '(' << v.x << ", " << v.y << ")\n"; + + loadedMesh.facevarying_uvs.push_back(v.x); + loadedMesh.facevarying_uvs.push_back(v.y); + } + } break; + default: + break; + } + } break; + default: + break; + } + } } } diff --git a/examples/raytrace/gltf-loader.h b/examples/raytrace/gltf-loader.h index 83a1f6b..567ebd8 100644 --- a/examples/raytrace/gltf-loader.h +++ b/examples/raytrace/gltf-loader.h @@ -104,6 +104,14 @@ using v2d = v2; using v3d = v3; using v4d = v4; +struct v2fArray { + arrayAdapter adapter; + v2fArray(const arrayAdapter &a) : adapter(a) {} + + v2f operator[](size_t position) const { return adapter[position]; } + size_t size() const { return adapter.elemCount; } +}; + struct v3fArray { arrayAdapter adapter; v3fArray(const arrayAdapter &a) : adapter(a) {} @@ -120,6 +128,14 @@ struct v4fArray { size_t size() const { return adapter.elemCount; } }; +struct v2dArray { + arrayAdapter adapter; + v2dArray(const arrayAdapter &a) : adapter(a) {} + + v2d operator[](size_t position) const { return adapter[position]; } + size_t size() const { return adapter.elemCount; } +}; + struct v3dArray { arrayAdapter adapter; v3dArray(const arrayAdapter &a) : adapter(a) {}