#Creating a parent-child structure with assimp

1 messages · Page 1 of 1 (latest)

knotty peak
#

I'm having a bit of a hard time constructing a tree like structure ussing assimp and openGL
This is called recursively and it should give me this:
parent Model -> child Model (this one should contain a Mesh)

but at the end of the process the parent model contains a child model but the child model in question does not have a mesh
(I checked and the function addMesh is called)
Thanks,

void Model::parseNodes(aiNode* node, const aiScene* scene, Model& parent) {
    
    Model model;
    
    for (size_t i = 0; i < node->mNumMeshes; i++)
    {
        ...
        Mesh mesh = createMesh(scene->mMeshes[currentMesh], scene);
        model.addMesh(mesh);
    }
    model.m_localTransform = node->mTransformation * parent.m_localTransform;
    parent.addChild(model);
    for (size_t i = 0; i < node->mNumChildren; i++)
    {
      parseNodes(node->mChildren[i], scene, model);
    }
}
the signature of the important functions
void addChild(Model& child);
void addMesh(Mesh mesh);
zealous barn
#

None of them have mesh or only the last child?

knotty peak
#

none of them, I should only be the last child who have a mesh tho

zealous barn
#

did you try putting a breakpoint inside the addmesh function and using the debugger?

knotty peak
#

yes, it goes into addmesh()

zealous barn
#

and was the mesh added after the function?

knotty peak
#

yes which is why I found it strange

#

I think I found a solution tho, I might have been a reference problem ?
I returned the reference to the added object in addChild() and passed it as the argument for
parseNodes()

#

don't know if this is good tho

zealous barn
#

does m_children contains pointers or only a copy of child?

knotty peak
#

copy of child

zealous barn
#

when you used the debugger you saw the last model being added to the node ? and the mesh was there ? then at the first end of the function the mesh just disappeared? @knotty peak

knotty peak
#

if by first end of the function you mean first call then not really because the mesh is only in the second call of the function (so in the second child)
I indeed saw the mesh was added to the model
but when I call the draw function (which is supposed to call the mesh of each child of my Model)
it does nothing (because it does not have a mesh)

zealous barn
#

but do you see the mesh inside the variable in the debugger?

knotty peak
#

It said m_meshes[1] so yes

zealous barn
#

does your node have a destructor which free the mesh?

#

I mean model*

knotty peak
#

no it does not

#

I didn't create one because I (at least I don't think) don't have dynamically allocated objects

zealous barn
knotty peak
#

I must say I didn't check
I said it draws nothing but it's more like it does not even enter the loop
for(Mesh mesh : m_meshes)

#

I don't have access to my pc anymore to check for the data structure tho, sorry