1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "scene_p.h"
5#include <Qt3DCore/qentity.h>
6#include <Qt3DCore/private/qnode_p.h>
7#include <Qt3DCore/private/qscene_p.h>
8#include <Qt3DCore/private/qdownloadhelperservice_p.h>
9#include <Qt3DRender/qsceneloader.h>
10#include <Qt3DRender/private/qsceneloader_p.h>
11#include <Qt3DRender/private/scenemanager_p.h>
12#include <QtCore/qcoreapplication.h>
13
14QT_BEGIN_NAMESPACE
15
16using namespace Qt3DCore;
17
18namespace Qt3DRender {
19namespace Render {
20
21Scene::Scene()
22 : BackendNode(QBackendNode::ReadWrite)
23 , m_sceneManager(nullptr)
24{
25}
26
27void Scene::cleanup()
28{
29 m_source.clear();
30}
31
32void Scene::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
33{
34 const QSceneLoader *node = qobject_cast<const QSceneLoader *>(object: frontEnd);
35 if (!node)
36 return;
37
38 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
39
40 if (node->source() != m_source) {
41 m_source = node->source();
42 if (m_source.isEmpty() || Qt3DCore::QDownloadHelperService::isLocal(url: m_source))
43 m_sceneManager->addSceneData(source: m_source, sceneUuid: peerId());
44 else
45 m_sceneManager->startSceneDownload(source: m_source, sceneUuid: peerId());
46
47 const auto d = static_cast<const QSceneLoaderPrivate *>(Qt3DCore::QNodePrivate::get(q: node));
48 const_cast<QSceneLoaderPrivate *>(d)->setStatus(QSceneLoader::Loading);
49 }
50 markDirty(changes: AbstractRenderer::AllDirty);
51}
52
53QUrl Scene::source() const
54{
55 return m_source;
56}
57
58void Scene::setSceneManager(SceneManager *manager)
59{
60 if (m_sceneManager != manager)
61 m_sceneManager = manager;
62}
63
64RenderSceneFunctor::RenderSceneFunctor(AbstractRenderer *renderer, SceneManager *sceneManager)
65 : m_sceneManager(sceneManager)
66 , m_renderer(renderer)
67{
68}
69
70Qt3DCore::QBackendNode *RenderSceneFunctor::create(Qt3DCore::QNodeId id) const
71{
72 Scene *scene = m_sceneManager->getOrCreateResource(id);
73 scene->setSceneManager(m_sceneManager);
74 scene->setRenderer(m_renderer);
75 return scene;
76}
77
78Qt3DCore::QBackendNode *RenderSceneFunctor::get(Qt3DCore::QNodeId id) const
79{
80 return m_sceneManager->lookupResource(id);
81}
82
83void RenderSceneFunctor::destroy(Qt3DCore::QNodeId id) const
84{
85 m_sceneManager->releaseResource(id);
86}
87
88} // namespace Render
89} // namespace Qt3DRender
90
91QT_END_NAMESPACE
92

source code of qt3d/src/render/io/scene.cpp