diff --git a/examples/raytrace/gltf-loader.cc b/examples/raytrace/gltf-loader.cc index 981a689..32a16e0 100644 --- a/examples/raytrace/gltf-loader.cc +++ b/examples/raytrace/gltf-loader.cc @@ -129,13 +129,14 @@ bool LoadGLTF(const std::string &filename, float scale, } const auto &indices = *indicesArrayPtr; - if (indicesArrayPtr) + if (indicesArrayPtr) { + std::cout << "indices: "; for (size_t i(0); i < indicesArrayPtr->size(); ++i) { - // std::cout << indices[i] << " "; + std::cout << indices[i] << " "; loadedMesh.faces.push_back(indices[i]); } - - std::cout << '\n'; + std::cout << '\n'; + } switch (meshPrimitive.mode) { case TINYGLTF_MODE_TRIANGLES: // this is the simpliest case to handle @@ -153,6 +154,9 @@ bool LoadGLTF(const std::string &filename, float scale, const auto byte_stride = attribAccessor.ByteStride(bufferView); const auto count = attribAccessor.count; + std::cout << "current attribute has count " << count + << " and stride " << byte_stride << " bytes\n"; + if (attribute.first == "POSITION") { std::cout << "found position attribute\n"; @@ -166,15 +170,20 @@ bool LoadGLTF(const std::string &filename, float scale, switch (attribAccessor.componentType) { case TINYGLTF_COMPONENT_TYPE_FLOAT: + std::cout << "Type is FLOAT\n"; switch (attribAccessor.type) { case TINYGLTF_TYPE_VEC3: { // 3D vector of float v3fArray positions( arrayAdapter(dataPtr, count, byte_stride)); + + std::cout << "positions's size : " << positions.size() + << '\n'; + for (size_t i{0}; i < positions.size(); ++i) { const auto v = positions[i]; - std::cout << '(' << v.x << ", " << v.y << ", " << v.z - << ")\n"; + std::cout << "positions[" << i << "]: (" << v.x << ", " + << v.y << ", " << v.z << ")\n"; loadedMesh.vertices.push_back(v.x * scale); loadedMesh.vertices.push_back(v.y * scale); @@ -185,15 +194,17 @@ bool LoadGLTF(const std::string &filename, float scale, // TODO Handle error break; } + break; case TINYGLTF_COMPONENT_TYPE_DOUBLE: { + std::cout << "Type is DOUBLE\n"; 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"; + std::cout << "positions[" << i << "]: (" << v.x << ", " + << v.y << ", " << v.z << ")\n"; loadedMesh.vertices.push_back(v.x * scale); loadedMesh.vertices.push_back(v.y * scale); @@ -280,9 +291,7 @@ bool LoadGLTF(const std::string &filename, float scale, } } } - } - - break; + } break; // Other trigangle based modes case TINYGLTF_MODE_TRIANGLE_FAN: @@ -303,8 +312,6 @@ bool LoadGLTF(const std::string &filename, float scale, } } - // TODO compute pivot point - // bbox : v3f bCenter; bCenter.x = 0.5f * (pMax.x - pMin.x) + pMin.x; diff --git a/examples/raytrace/gltf-loader.h b/examples/raytrace/gltf-loader.h index 567ebd8..32d9e7c 100644 --- a/examples/raytrace/gltf-loader.h +++ b/examples/raytrace/gltf-loader.h @@ -20,7 +20,6 @@ struct arrayAdapter { const size_t elemCount; /// Stride in bytes between two elements const size_t stride; - /// Constructor. /// Construct an array adapter. /// \param ptr Pointer to the start of the data, with offset applied diff --git a/examples/raytrace/main.cc b/examples/raytrace/main.cc index c02aecf..c0091c6 100644 --- a/examples/raytrace/main.cc +++ b/examples/raytrace/main.cc @@ -773,6 +773,14 @@ int main(int argc, char **argv) { for (size_t n = 0; n < gAsset.meshes.size(); n++) { nanosg::Node > node(&gAsset.meshes[n]); + + // case where the name of a mesh isn't defined in the loaded file + if (gAsset.meshes[n].name.empty()) { + std::string generatedName = "unnamed_" + std::to_string(n); + gAsset.meshes[n].name = generatedName; + meshes[n].name = generatedName; + } + node.SetName(meshes[n].name); node.SetLocalXform(meshes[n].pivot_xform); // Use mesh's pivot transform // as node's local transform.