summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/basicshapes-cpp
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-02-11 14:14:30 +0000
committerMike Krus <mike.krus@kdab.com>2020-02-27 12:10:08 +0000
commit5bf4f93fcb8ff16aeadf55644be351c9989ab5b2 (patch)
tree9a502509da33a48dade8f7cbd0af1e7d3444b2f3 /examples/qt3d/basicshapes-cpp
parent703090204ef41bced5634bbb332551dea1dd7b37 (diff)
Make default geometries views
In Extras, make QTorusMesh and others a QGeometryView rather than a QGeometryRenderer. Requires changes to scene graphs here and there but going forward there simple shapes could be used as proxies for picking or collision detection, etc. Change-Id: Id488e064080dfd303e448aba11e6b242236b81d4 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples/qt3d/basicshapes-cpp')
-rw-r--r--examples/qt3d/basicshapes-cpp/scenemodifier.cpp73
1 files changed, 48 insertions, 25 deletions
diff --git a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp
index d89b7f2fb..fa268afa6 100644
--- a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp
+++ b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp
@@ -49,7 +49,7 @@
****************************************************************************/
#include "scenemodifier.h"
-
+#include <Qt3DRender/QGeometryRenderer>
#include <QtCore/QDebug>
SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
@@ -78,13 +78,17 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
torusMaterial->setDiffuse(QColor(QRgb(0xbeb32b)));
//! [2]
- // Torus
- //! [3]
- m_torusEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_torusEntity->addComponent(m_torus);
- m_torusEntity->addComponent(torusMaterial);
- m_torusEntity->addComponent(torusTransform);
- //! [3]
+ {
+ // Torus
+ //! [3]
+ m_torusEntity = new Qt3DCore::QEntity(m_rootEntity);
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(m_torus);
+ m_torusEntity->addComponent(renderer);
+ m_torusEntity->addComponent(torusMaterial);
+ m_torusEntity->addComponent(torusTransform);
+ //! [3]
+ }
// Cone shape data
Qt3DExtras::QConeMesh *cone = new Qt3DExtras::QConeMesh();
@@ -104,10 +108,14 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
coneMaterial->setDiffuse(QColor(QRgb(0x928327)));
// Cone
- m_coneEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_coneEntity->addComponent(cone);
- m_coneEntity->addComponent(coneMaterial);
- m_coneEntity->addComponent(coneTransform);
+ {
+ m_coneEntity = new Qt3DCore::QEntity(m_rootEntity);
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(cone);
+ m_coneEntity->addComponent(renderer);
+ m_coneEntity->addComponent(coneMaterial);
+ m_coneEntity->addComponent(coneTransform);
+ }
// Cylinder shape data
Qt3DExtras::QCylinderMesh *cylinder = new Qt3DExtras::QCylinderMesh();
@@ -126,10 +134,14 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
cylinderMaterial->setDiffuse(QColor(QRgb(0x928327)));
// Cylinder
- m_cylinderEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_cylinderEntity->addComponent(cylinder);
- m_cylinderEntity->addComponent(cylinderMaterial);
- m_cylinderEntity->addComponent(cylinderTransform);
+ {
+ m_cylinderEntity = new Qt3DCore::QEntity(m_rootEntity);
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(cylinder);
+ m_cylinderEntity->addComponent(renderer);
+ m_cylinderEntity->addComponent(cylinderMaterial);
+ m_cylinderEntity->addComponent(cylinderTransform);
+ }
// Cuboid shape data
Qt3DExtras::QCuboidMesh *cuboid = new Qt3DExtras::QCuboidMesh();
@@ -143,10 +155,14 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
cuboidMaterial->setDiffuse(QColor(QRgb(0x665423)));
//Cuboid
- m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_cuboidEntity->addComponent(cuboid);
- m_cuboidEntity->addComponent(cuboidMaterial);
- m_cuboidEntity->addComponent(cuboidTransform);
+ {
+ m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity);
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(cuboid);
+ m_cuboidEntity->addComponent(renderer);
+ m_cuboidEntity->addComponent(cuboidMaterial);
+ m_cuboidEntity->addComponent(cuboidTransform);
+ }
// Plane shape data
Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh();
@@ -163,10 +179,14 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
planeMaterial->setDiffuse(QColor(QRgb(0xa69929)));
// Plane
- m_planeEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_planeEntity->addComponent(planeMesh);
- m_planeEntity->addComponent(planeMaterial);
- m_planeEntity->addComponent(planeTransform);
+ {
+ m_planeEntity = new Qt3DCore::QEntity(m_rootEntity);
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(planeMesh);
+ m_planeEntity->addComponent(renderer);
+ m_planeEntity->addComponent(planeMaterial);
+ m_planeEntity->addComponent(planeTransform);
+ }
// Sphere shape data
Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();
@@ -183,9 +203,12 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
Qt3DExtras::QPhongMaterial *sphereMaterial = new Qt3DExtras::QPhongMaterial();
sphereMaterial->setDiffuse(QColor(QRgb(0xa69929)));
+ auto renderer = new Qt3DRender::QGeometryRenderer;
+ renderer->setView(sphereMesh);
+
// Sphere
m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
- m_sphereEntity->addComponent(sphereMesh);
+ m_sphereEntity->addComponent(renderer);
m_sphereEntity->addComponent(sphereMaterial);
m_sphereEntity->addComponent(sphereTransform);
}