admin管理员组文章数量:1124550
i'm following vk-guide and use this library for loading gltf model. But I encounter this error, when I load the vertex.
Severity Code Description Project File Line Suppression State Details
Error GAF447572 no matching function for call to 'iterateAccessorWithIndex' F:\dev\vulkan\VulkanEngine\out\build\debug\VulkanEngine F:\dev\vulkan\VulkanEngine\renderer\src\huan\utils\gltf\gltf_loader.cpp 67
Here is my code:
#include "huan/utils/gltf/gltf_loader.hpp"
#include <spdlog/spdlog.h>
#include <fastgltf/core.hpp>
#include <fastgltf/tools.hpp>
#include <glm/glm.hpp>
namespace huan
{
std::optional<std::vector<Ref<MeshAsset>>> loadGltfMeshes(VulkanEngine* engine, std::filesystem::path filePath)
{
spdlog::info("Loading GLTF meshes from {}", filePath.string());
auto data = fastgltf::GltfDataBuffer::FromPath(filePath);
if (data.error() != fastgltf::Error::None)
{
spdlog::error("Failed to load GLTF data from {}", filePath.string());
return std::nullopt;
}
constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers | fastgltf::Options::LoadExternalBuffers;
fastgltf::Parser parser{};
fastgltf::Asset gltfAsset;
auto load = parser.loadGltfBinary(data.get(), filePath.parent_path(), gltfOptions);
if (load.error() == fastgltf::Error::None)
{
gltfAsset = std::move(load.get());
}
else
{
spdlog::error("Failed to parse GLTF binary from {}", filePath.string());
return std::nullopt;
}
std::vector<Ref<MeshAsset>> meshes;
// Process the GLTF asset to extract mesh data
std::vector<uint32_t> indices;
std::vector<Vertex> vertices;
for (const auto& mesh : gltfAsset.meshes)
{
Ref<MeshAsset> newMesh = std::make_shared<MeshAsset>();
// Populate meshAsset with data from mesh
newMesh->name = mesh.name;
indices.clear();
vertices.clear();
for (auto&& prim : mesh.primitives)
{
GeometrySuface newSurface;
newSurface.startIndex = (uint32_t)indices.size();
newSurface.count = (uint32_t)gltfAsset.accessors[prim.indicesAccessor.value()].count;
size_t initialVerticesSize = vertices.size();
// load indices
{
fastgltf::Accessor& indexAccessor = gltfAsset.accessors[prim.indicesAccessor.value()];
indices.reserve(indices.size() + indexAccessor.count);
fastgltf::iterateAccessor<std::uint32_t>(gltfAsset, indexAccessor, [&](std::uint32_t index) {
indices.push_back(index + initialVerticesSize);
});
}
// load vertices
{
fastgltf::Accessor& positionAccessor =
gltfAsset.accessors[prim.findAttribute("POSITION")->accessorIndex];
vertices.resize(vertices.size() + positionAccessor.count);
fastgltf::iterateAccessorWithIndex<glm::vec3>(
gltfAsset, positionAccessor, [&](glm::vec3 v, size_t index) {
auto& curVertex = vertices[initialVerticesSize + index];
curVertex.position = v;
curVertex.normal = {1, 0, 0};
curVertex.color = glm::vec4(1.0f);
curVertex.uvX = 0;
curVertex.uvY = 0;
});
}
// load normal
if (auto normalAccessor = prim.findAttribute("NORMAL"))
{
fastgltf::Accessor& normalAcc = gltfAsset.accessors[normalAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec3>(
gltfAsset, normalAcc,
[&](glm::vec3 n, std::size_t index) { vertices[initialVerticesSize + index].normal = n; });
}
// load UVs
if (auto uvAccessor = prim.findAttribute("TEXCOORD_0"))
{
fastgltf::Accessor& uvAcc = gltfAsset.accessors[uvAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec2>(gltfAsset, uvAcc, [&](glm::vec2 uv, std::size_t index) {
vertices[initialVerticesSize + index].uvX = uv.x;
vertices[initialVerticesSize + index].uvY = uv.y;
});
}
// load vertex color
if (auto colorAccessor = prim.findAttribute("COLOR_0"))
{
fastgltf::Accessor& colorAcc = gltfAsset.accessors[colorAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec4>(
gltfAsset, colorAcc,
[&](glm::vec4 color, std::size_t index) { vertices[initialVerticesSize + index].color = color; });
}
newMesh->surfaces.push_back(newSurface);
}
/**
* @brief Display the vertex normal
*/
constexpr bool overrideColors = true;
if (overrideColors)
{
for (auto& vertex : vertices)
{
vertex.color = glm::vec4(vertex.normal * 0.5f + 0.5f, 1.0f);
}
}
newMesh->meshBuffers = engine->uploadMesh(indices, vertices);
meshes.push_back(newMesh);
}
return meshes;
}
} // namespace huan
I think it's weird, because the iterateAccessor is fine, but iterateAccessorWithIndex got an error.
I check the definition and didn't find any wrong with that. Is that a bug?
i'm following vk-guide and use this library for loading gltf model. But I encounter this error, when I load the vertex.
Severity Code Description Project File Line Suppression State Details
Error GAF447572 no matching function for call to 'iterateAccessorWithIndex' F:\dev\vulkan\VulkanEngine\out\build\debug\VulkanEngine F:\dev\vulkan\VulkanEngine\renderer\src\huan\utils\gltf\gltf_loader.cpp 67
Here is my code:
#include "huan/utils/gltf/gltf_loader.hpp"
#include <spdlog/spdlog.h>
#include <fastgltf/core.hpp>
#include <fastgltf/tools.hpp>
#include <glm/glm.hpp>
namespace huan
{
std::optional<std::vector<Ref<MeshAsset>>> loadGltfMeshes(VulkanEngine* engine, std::filesystem::path filePath)
{
spdlog::info("Loading GLTF meshes from {}", filePath.string());
auto data = fastgltf::GltfDataBuffer::FromPath(filePath);
if (data.error() != fastgltf::Error::None)
{
spdlog::error("Failed to load GLTF data from {}", filePath.string());
return std::nullopt;
}
constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers | fastgltf::Options::LoadExternalBuffers;
fastgltf::Parser parser{};
fastgltf::Asset gltfAsset;
auto load = parser.loadGltfBinary(data.get(), filePath.parent_path(), gltfOptions);
if (load.error() == fastgltf::Error::None)
{
gltfAsset = std::move(load.get());
}
else
{
spdlog::error("Failed to parse GLTF binary from {}", filePath.string());
return std::nullopt;
}
std::vector<Ref<MeshAsset>> meshes;
// Process the GLTF asset to extract mesh data
std::vector<uint32_t> indices;
std::vector<Vertex> vertices;
for (const auto& mesh : gltfAsset.meshes)
{
Ref<MeshAsset> newMesh = std::make_shared<MeshAsset>();
// Populate meshAsset with data from mesh
newMesh->name = mesh.name;
indices.clear();
vertices.clear();
for (auto&& prim : mesh.primitives)
{
GeometrySuface newSurface;
newSurface.startIndex = (uint32_t)indices.size();
newSurface.count = (uint32_t)gltfAsset.accessors[prim.indicesAccessor.value()].count;
size_t initialVerticesSize = vertices.size();
// load indices
{
fastgltf::Accessor& indexAccessor = gltfAsset.accessors[prim.indicesAccessor.value()];
indices.reserve(indices.size() + indexAccessor.count);
fastgltf::iterateAccessor<std::uint32_t>(gltfAsset, indexAccessor, [&](std::uint32_t index) {
indices.push_back(index + initialVerticesSize);
});
}
// load vertices
{
fastgltf::Accessor& positionAccessor =
gltfAsset.accessors[prim.findAttribute("POSITION")->accessorIndex];
vertices.resize(vertices.size() + positionAccessor.count);
fastgltf::iterateAccessorWithIndex<glm::vec3>(
gltfAsset, positionAccessor, [&](glm::vec3 v, size_t index) {
auto& curVertex = vertices[initialVerticesSize + index];
curVertex.position = v;
curVertex.normal = {1, 0, 0};
curVertex.color = glm::vec4(1.0f);
curVertex.uvX = 0;
curVertex.uvY = 0;
});
}
// load normal
if (auto normalAccessor = prim.findAttribute("NORMAL"))
{
fastgltf::Accessor& normalAcc = gltfAsset.accessors[normalAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec3>(
gltfAsset, normalAcc,
[&](glm::vec3 n, std::size_t index) { vertices[initialVerticesSize + index].normal = n; });
}
// load UVs
if (auto uvAccessor = prim.findAttribute("TEXCOORD_0"))
{
fastgltf::Accessor& uvAcc = gltfAsset.accessors[uvAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec2>(gltfAsset, uvAcc, [&](glm::vec2 uv, std::size_t index) {
vertices[initialVerticesSize + index].uvX = uv.x;
vertices[initialVerticesSize + index].uvY = uv.y;
});
}
// load vertex color
if (auto colorAccessor = prim.findAttribute("COLOR_0"))
{
fastgltf::Accessor& colorAcc = gltfAsset.accessors[colorAccessor->accessorIndex];
fastgltf::iterateAccessorWithIndex<glm::vec4>(
gltfAsset, colorAcc,
[&](glm::vec4 color, std::size_t index) { vertices[initialVerticesSize + index].color = color; });
}
newMesh->surfaces.push_back(newSurface);
}
/**
* @brief Display the vertex normal
*/
constexpr bool overrideColors = true;
if (overrideColors)
{
for (auto& vertex : vertices)
{
vertex.color = glm::vec4(vertex.normal * 0.5f + 0.5f, 1.0f);
}
}
newMesh->meshBuffers = engine->uploadMesh(indices, vertices);
meshes.push_back(newMesh);
}
return meshes;
}
} // namespace huan
I think it's weird, because the iterateAccessor is fine, but iterateAccessorWithIndex got an error.
I check the definition and didn't find any wrong with that. Is that a bug?
Share Improve this question asked 2 days ago qiyuewuyi2333qiyuewuyi2333 675 bronze badges 4 |1 Answer
Reset to default 0Ok i get that. The ElementType in the function template( iterateAccessorWithIndex ) need to have a ElementTraits specialization. So just use #include <fastgltf/glm_element_traits.hpp> and done. For details, you can check this link
本文标签: cno matching function for call to iterateAccessorWithIndex when using fastgltfStack Overflow
版权声明:本文标题:c++ - no matching function for call to iterateAccessorWithIndex when using fastgltf - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736629465a1945744.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
iterateAccessorWithIndex
was added in 0.6.0: https://fastgltf.readthedocs.io/v0.7.x/changelog.html#id10 – drescherjm Commented 2 days ago