Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt3D update scene



  • Hello everyone. I'm a newbie to Qt3D. I load surfaces from 3D scanner to scene and they look like overlapping one on another, furthermore appearing too slow. I made a function which deletes all children and components of a given node.

    void SceneRenderer::deleteChildrenRecursively(Qt3DCore::QNode* node)
    {
            Qt3DCore::QEntity* entity = (Qt3DCore::QEntity*)node;
    
            if (entity == nullptr) {
                return;
            }
             auto components = entity->components();
            foreach(Qt3DCore::QComponent * component, components) {
                const auto componentChildren = component->childNodes();
            
                foreach(auto * child, componentChildren)
                {
                    delete (child);
                    child = NULL;
                }
                const auto compChildrenSie = componentChildren.size();
                entity->removeComponent(component);
                delete(component);
                component = NULL;
            }
    
            const auto childNodes = node->childNodes();
            const auto childNodesSize = node->childNodes().size();
    
            const auto childentities = entity->childNodes();
            const auto childentitiesSize = entity->childNodes().size();
    
            auto componentsAfter = entity->components();
            auto parentEntity = entity->parentEntity();
            for (auto* child: childNodes)
            {
                deleteChildrenRecursively(child);
            }
            delete(entity);
            entity = NULL;
    }
    

    Usage:

        render_->loadSurfaceToScene(surface);
        Qt3DCore::QNodeVector rootEntityChildren;
        rootEntityChildren.reserve(render_->rootEntity_->childNodes().size());
        rootEntityChildren = render_->rootEntity_->childNodes();
        render_->deleteChildrenRecursively(rootEntityChildren[1]);
    

    So I pass added object to function deleteChildrenRecursively()
    Now scene is empty, nothing renders. Could you help me how to fix this problem and update scene manually? Maybe slow performance is not the issue of not deleting nodes from scene? Thank you in advance.


Log in to reply