Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fastgltf no instance of function template "fastgltf::iterateSceneNodes" matches the argument list

Tags:

c++

I'm currently working on a gltf reader and renderer using OpenGL and C++.

Currently I'm using fastgltf and I keep getting the following compilation error:

no instance of function template "fastgltf::iterateSceneNodes" matches the argument list

I'm just following the usage guide from here https://fastgltf.readthedocs.io/v0.8.x/guides.html#iterating-over-the-node-hierarchy

Here is my loader function:

void GLTFHelper::LoadGLTF(std::filesystem::path path)
{
    fastgltf::Parser parser;

    auto data = fastgltf::GltfDataBuffer::FromPath(path);
    
    auto asset = parser.loadGltf(data.get(), path.parent_path(), fastgltf::Options::None);
    auto scene = asset->defaultScene.value();

    fastgltf::iterateSceneNodes(asset, scene, fastgltf::math::fmat4x4(), 
        [&](fastgltf::Node& node, fastgltf::math::fmat4x4 matrix) {
            if (node.meshIndex.has_value()) {
                std::cout << "Node Here" << std::endl;
            }
        });

    std::cout << "Loaded data" << std::endl;
}

I already included the core.hpp, types.hpp and tools.hpp in the header file.

Edit:

I using Visual Studio 2022 to build my project- and it gives me this error exactly on that function call:

enter image description here

and error instantiating template in the tools.hpp of fastgltf for that function

enter image description here

like image 245
Syn Avatar asked Oct 26 '25 04:10

Syn


1 Answers

It looks like the fastgltf::Parser::loadGltf returns some kind of a wrapper object (i.e. fastgltf::Expected<fastgltf::Asset>) while fastgltf::iterateSceneNodes takes an instance of fastgltf::Asset itself. You are supposed to check for an error of the Expected and "dereference" it after that:

...
auto assetExpected = parser.loadGltf(data.get(), path.parent_path(), fastgltf::Options::None);
if (const auto assetPtr = assetExpected.get_if()) {
    auto& asset = *assetPtr;
    const auto scene = asset.defaultScene.value();
    fastgltf::iterateSceneNodes(asset, scene, fastgltf::math::fmat4x4(), ...);
    ...
}
like image 57
The Dreams Wind Avatar answered Oct 27 '25 20:10

The Dreams Wind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!