-
Notifications
You must be signed in to change notification settings - Fork 0
/
sceneviewer.cpp
77 lines (58 loc) · 2.09 KB
/
sceneviewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "sceneviewer.h"
SceneViewer::SceneViewer(ViewSettings params)
{
this->_view.setTitle("[4332] Просмотр моделей");
this->_view.defaultFramegraph()->setClearColor(params.backgroundColor);
this->_view.setWidth(params.resolution.width);
this->_view.setHeight(params.resolution.height);
this->m_sceneRoot = new Qt3DCore::QEntity();
this->m_camera = this->_view.camera();
this->setCameraSettings(float(params.speed));
this->setSceneLoader();
}
void SceneViewer::setCameraSettings(float speed=250.0f)
{
// Scene Camera
this->m_camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
this->m_camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
this->m_camera->setPosition(QVector3D(50.0f, 10.0f, 0.0f));
this->m_camera->setNearPlane(0.001f);
this->m_camera->setFarPlane(100.0f);
// For camera controls
this->m_camController = new Qt3DExtras::QOrbitCameraController(this->m_sceneRoot);
this->m_camController->setLinearSpeed(speed);
this->m_camController->setLookSpeed(speed);
this->m_camController->setCamera(this->m_camera);
}
void SceneViewer::setSceneLoader()
{
this->m_sceneLoaderEntity = new Qt3DCore::QEntity(this->m_sceneRoot);
this->m_sceneLoader = new Qt3DRender::QSceneLoader(this->m_sceneLoaderEntity);
this->m_sceneWalker = new SceneWalker(this->m_sceneLoader);
QObject::connect(
this->m_sceneLoader,
&Qt3DRender::QSceneLoader::statusChanged,
this->m_sceneWalker,
&SceneWalker::onStatusChanged
);
this->m_sceneLoaderEntity->addComponent(this->m_sceneLoader);
}
int SceneViewer::exec(QString file)
{
if (file.isEmpty())
return 0;
this->m_sceneLoader->setSource(QUrl("file:///" + file));
this->_view.setRootEntity(this->m_sceneRoot);
this->_view.show();
return 0;
}
SceneViewer::~SceneViewer()
{
delete this->m_app;
delete this->m_sceneRoot;
delete this->m_camera;
delete this->m_camController;
delete this->m_sceneLoaderEntity;
delete this->m_sceneLoader;
delete this->m_sceneWalker;
}