From 5bf4f93fcb8ff16aeadf55644be351c9989ab5b2 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 11 Feb 2020 14:14:30 +0000 Subject: 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 --- examples/qt3d/3d-text/main.cpp | 6 +- examples/qt3d/anaglyph-rendering/main.qml | 24 ++++---- examples/qt3d/audio-visualizer-qml/Visualizer.qml | 18 +++--- examples/qt3d/basicshapes-cpp/scenemodifier.cpp | 73 +++++++++++++++-------- examples/qt3d/lights/PlaneEntity.qml | 15 +++-- examples/qt3d/lights/main.qml | 18 ++++-- examples/qt3d/phong-cubes/CubeEntity.qml | 10 ++-- examples/qt3d/planets-qml/Planet.qml | 12 ++-- examples/qt3d/qardboard/main.qml | 24 ++++---- examples/qt3d/scene2d/doc/src/scene2d.qdoc | 10 ++-- examples/qt3d/scene2d/main.qml | 3 +- examples/qt3d/scene3d/AnimatedEntity.qml | 18 +++--- examples/qt3d/scene3dview/AnimatedEntity.qml | 18 +++--- examples/qt3d/shadow-map-qml/GroundPlane.qml | 10 ++-- examples/qt3d/simple-cpp/main.cpp | 11 +++- examples/qt3d/simple-qml/main.qml | 19 +++--- examples/qt3d/simplecustommaterial/PlaneModel.qml | 10 ++-- examples/qt3d/wave/Wave.qml | 10 ++-- 18 files changed, 193 insertions(+), 116 deletions(-) (limited to 'examples/qt3d') diff --git a/examples/qt3d/3d-text/main.cpp b/examples/qt3d/3d-text/main.cpp index f480f8a2e..e7da8af45 100644 --- a/examples/qt3d/3d-text/main.cpp +++ b/examples/qt3d/3d-text/main.cpp @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -71,8 +72,11 @@ int main(int argc, char *argv[]) planeTransform->setTranslation(QVector3D(0, 0, 0)); planeMaterial->setDiffuse(QColor(150, 150, 150)); + auto renderer = new Qt3DRender::QGeometryRenderer; + renderer->setView(planeMesh); + plane->addComponent(planeMaterial); - plane->addComponent(planeMesh); + plane->addComponent(renderer); plane->addComponent(planeTransform); } diff --git a/examples/qt3d/anaglyph-rendering/main.qml b/examples/qt3d/anaglyph-rendering/main.qml index 89e5c3664..1301a510a 100644 --- a/examples/qt3d/anaglyph-rendering/main.qml +++ b/examples/qt3d/anaglyph-rendering/main.qml @@ -92,11 +92,13 @@ Entity { // Cylinder Entity { - property CylinderMesh cylinder: CylinderMesh { - radius: 1 - length: 3 - rings: 100 - slices: 20 + property GeometryRenderer cylinder: GeometryRenderer { + view: CylinderMesh { + radius: 1 + length: 3 + rings: 100 + slices: 20 + } } property Transform transform: Transform { id: cylinderTransform @@ -196,11 +198,13 @@ Entity { readonly property real det: 1.0 / model delegate: Entity { components: [ - TorusMesh { - radius: 35 - minorRadius: 5 - rings: 100 - slices: 20 + GeometryRenderer { + view: TorusMesh { + radius: 35 + minorRadius: 5 + rings: 100 + slices: 20 + } }, Transform { id: transform diff --git a/examples/qt3d/audio-visualizer-qml/Visualizer.qml b/examples/qt3d/audio-visualizer-qml/Visualizer.qml index 42373f950..e6ba6891b 100644 --- a/examples/qt3d/audio-visualizer-qml/Visualizer.qml +++ b/examples/qt3d/audio-visualizer-qml/Visualizer.qml @@ -157,11 +157,13 @@ Entity { //![1] // Bars - CuboidMesh { + GeometryRenderer { id: barMesh - xExtent: 0.1 - yExtent: 0.1 - zExtent: 0.1 + view: CuboidMesh { + xExtent: 0.1 + yExtent: 0.1 + zExtent: 0.1 + } } NodeInstantiator { @@ -189,10 +191,12 @@ Entity { Entity { id: titlePlane - PlaneMesh { + GeometryRenderer { id: titlePlaneMesh - width: 550 - height: 100 + view: PlaneMesh { + width: 550 + height: 100 + } } Transform { 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 #include 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); } diff --git a/examples/qt3d/lights/PlaneEntity.qml b/examples/qt3d/lights/PlaneEntity.qml index 268c59add..1e84543f6 100644 --- a/examples/qt3d/lights/PlaneEntity.qml +++ b/examples/qt3d/lights/PlaneEntity.qml @@ -61,14 +61,17 @@ Entity { property alias resolution: mesh.meshResolution property Material material - components: [ transform, mesh, root.material ] + components: [ transform, renderer, root.material ] Transform { id: transform } - PlaneMesh { - id: mesh - width: 1.0 - height: 1.0 - meshResolution: Qt.size(2, 2) + GeometryRenderer { + id: renderer + view: PlaneMesh { + id: mesh + width: 1.0 + height: 1.0 + meshResolution: Qt.size(2, 2) + } } } diff --git a/examples/qt3d/lights/main.qml b/examples/qt3d/lights/main.qml index 38a283d37..c647788fe 100644 --- a/examples/qt3d/lights/main.qml +++ b/examples/qt3d/lights/main.qml @@ -95,8 +95,10 @@ Entity Entity { id: redLight components: [ - SphereMesh { - radius: 2 + GeometryRenderer { + view: SphereMesh { + radius: 2 + } }, Transform { translation: Qt.vector3d(2.0, 8.0, -2.0) @@ -118,8 +120,10 @@ Entity Entity { id: greenLight components: [ - SphereMesh { - radius: 2 + GeometryRenderer { + view: SphereMesh { + radius: 2 + } }, Transform { translation: Qt.vector3d(0.0, 3.0, 4.0) @@ -141,8 +145,10 @@ Entity Entity { id: spotLight components: [ - SphereMesh { - radius: 1 + GeometryRenderer { + view: SphereMesh { + radius: 2 + } }, Transform { translation: Qt.vector3d(-20.0, 40.0, 0.0) diff --git a/examples/qt3d/phong-cubes/CubeEntity.qml b/examples/qt3d/phong-cubes/CubeEntity.qml index 558f53327..2c3939662 100644 --- a/examples/qt3d/phong-cubes/CubeEntity.qml +++ b/examples/qt3d/phong-cubes/CubeEntity.qml @@ -60,11 +60,13 @@ Entity { components: [mesh, material, transform] - CuboidMesh { + GeometryRenderer { id: mesh - xExtent: 0.5 - yExtent: xExtent - zExtent: xExtent + view: CuboidMesh { + xExtent: 0.5 + yExtent: xExtent + zExtent: xExtent + } } Transform { diff --git a/examples/qt3d/planets-qml/Planet.qml b/examples/qt3d/planets-qml/Planet.qml index 231cd7bac..bbec74444 100644 --- a/examples/qt3d/planets-qml/Planet.qml +++ b/examples/qt3d/planets-qml/Planet.qml @@ -51,7 +51,7 @@ import Qt3D.Render 2.0 import Qt3D.Extras 2.0 -SphereMesh { +GeometryRenderer { property real r: 0 property real x: 0 property real y: 0 @@ -59,8 +59,10 @@ SphereMesh { property real roll: 0 property real tilt: 0 - radius: 1.0 - generateTangents: true - rings: 64 - slices: 64 + view: SphereMesh { + radius: 1.0 + generateTangents: true + rings: 64 + slices: 64 + } } diff --git a/examples/qt3d/qardboard/main.qml b/examples/qt3d/qardboard/main.qml index b273c0f57..906b43232 100644 --- a/examples/qt3d/qardboard/main.qml +++ b/examples/qt3d/qardboard/main.qml @@ -122,11 +122,13 @@ QardboardRootEntity { // Cylinder Entity { - property CylinderMesh cylinder: CylinderMesh { - radius: 1 - length: 3 - rings: 100 - slices: 20 + property GeometryRenderer cylinder: GeometryRenderer { + view: CylinderMesh { + radius: 1 + length: 3 + rings: 100 + slices: 20 + } } property Transform transform: Transform { id: cylinderTransform @@ -180,11 +182,13 @@ QardboardRootEntity { readonly property real det: 1.0 / model delegate: Entity { components: [ - TorusMesh { - radius: 35 - minorRadius: 5 - rings: 100 - slices: 20 + GeometryRenderer { + view: TorusMesh { + radius: 35 + minorRadius: 5 + rings: 100 + slices: 20 + } }, Transform { id: transform diff --git a/examples/qt3d/scene2d/doc/src/scene2d.qdoc b/examples/qt3d/scene2d/doc/src/scene2d.qdoc index fd8a5b825..aad80053e 100644 --- a/examples/qt3d/scene2d/doc/src/scene2d.qdoc +++ b/examples/qt3d/scene2d/doc/src/scene2d.qdoc @@ -74,11 +74,11 @@ \section1 Rendering Qt Quick into a Texture We begin by declaring the Entity that will become our control panel. It consists of - a CuboidMesh onto which we will place the texture containing a rendering of the Qt Quick - scene. In this case we are using a simple cube for the geometry, but we could use - any valid 3D geometry as long as it has texture coordinates. The texture coordinates - are used for projecting the texture onto the 3D surface, and also for calculating the - coordinates of mouse events to be passed to the originating Qt Quick scene. + a GeometryRenderer with a CuboidMesh view onto which we will place the texture containing + a rendering of the Qt Quick scene. In this case we are using a simple cube for the + geometry, but we could use any valid 3D geometry as long as it has texture coordinates. + The texture coordinates are used for projecting the texture onto the 3D surface, and also + for calculating the coordinates of mouse events to be passed to the originating Qt Quick scene. \skipto Entity { \printto Behavior diff --git a/examples/qt3d/scene2d/main.qml b/examples/qt3d/scene2d/main.qml index ceaac3b34..671ab3990 100644 --- a/examples/qt3d/scene2d/main.qml +++ b/examples/qt3d/scene2d/main.qml @@ -137,8 +137,9 @@ Entity { rotation: fromAxisAndAngle(Qt.vector3d(0,1,0), cube.rotationAngle) } - CuboidMesh { + GeometryRenderer { id: cubeMesh + view: CuboidMesh { } } ObjectPicker { diff --git a/examples/qt3d/scene3d/AnimatedEntity.qml b/examples/qt3d/scene3d/AnimatedEntity.qml index 77cc15aa3..3e24dc785 100644 --- a/examples/qt3d/scene3d/AnimatedEntity.qml +++ b/examples/qt3d/scene3d/AnimatedEntity.qml @@ -89,12 +89,14 @@ Entity { id: material } - TorusMesh { + GeometryRenderer { id: torusMesh - radius: 5 - minorRadius: 1 - rings: 100 - slices: 20 + view: TorusMesh { + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + } } Transform { @@ -108,9 +110,11 @@ Entity { components: [ torusMesh, material, torusTransform ] } - SphereMesh { + GeometryRenderer { id: sphereMesh - radius: 3 + view: SphereMesh { + radius: 3 + } } Transform { diff --git a/examples/qt3d/scene3dview/AnimatedEntity.qml b/examples/qt3d/scene3dview/AnimatedEntity.qml index db27f3584..774928f74 100644 --- a/examples/qt3d/scene3dview/AnimatedEntity.qml +++ b/examples/qt3d/scene3dview/AnimatedEntity.qml @@ -90,12 +90,14 @@ Entity { diffuse: sceneColor } - TorusMesh { + GeometryRenderer { id: torusMesh - radius: 5 - minorRadius: 1 - rings: 100 - slices: 20 + view: TorusMesh { + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + } } Transform { @@ -109,9 +111,11 @@ Entity { components: [ torusMesh, material, torusTransform ] } - SphereMesh { + GeometryRenderer { id: sphereMesh - radius: 3 + view: SphereMesh { + radius: 3 + } } Transform { diff --git a/examples/qt3d/shadow-map-qml/GroundPlane.qml b/examples/qt3d/shadow-map-qml/GroundPlane.qml index d78f5b07a..072e3663a 100644 --- a/examples/qt3d/shadow-map-qml/GroundPlane.qml +++ b/examples/qt3d/shadow-map-qml/GroundPlane.qml @@ -56,11 +56,13 @@ Entity { id: root property Material material - PlaneMesh { + GeometryRenderer { id: groundMesh - width: 50 - height: width - meshResolution: Qt.size(2, 2) + view: PlaneMesh { + width: 50 + height: width + meshResolution: Qt.size(2, 2) + } } Transform { diff --git a/examples/qt3d/simple-cpp/main.cpp b/examples/qt3d/simple-cpp/main.cpp index 32f19c194..6b45dd1d0 100644 --- a/examples/qt3d/simple-cpp/main.cpp +++ b/examples/qt3d/simple-cpp/main.cpp @@ -59,9 +59,9 @@ #include #include +#include #include #include -#include #include #include @@ -91,7 +91,9 @@ Qt3DCore::QEntity *createScene() torusTransform->setScale3D(QVector3D(1.5, 1, 0.5)); torusTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f)); - torusEntity->addComponent(torusMesh); + auto renderer = new Qt3DRender::QGeometryRenderer; + renderer->setView(torusMesh); + torusEntity->addComponent(renderer); torusEntity->addComponent(torusTransform); torusEntity->addComponent(material); @@ -114,7 +116,10 @@ Qt3DCore::QEntity *createScene() sphereRotateTransformAnimation->setLoopCount(-1); sphereRotateTransformAnimation->start(); - sphereEntity->addComponent(sphereMesh); + renderer = new Qt3DRender::QGeometryRenderer; + renderer->setView(sphereMesh); + + sphereEntity->addComponent(renderer); sphereEntity->addComponent(sphereTransform); sphereEntity->addComponent(material); diff --git a/examples/qt3d/simple-qml/main.qml b/examples/qt3d/simple-qml/main.qml index 9f4149202..60b9a0990 100644 --- a/examples/qt3d/simple-qml/main.qml +++ b/examples/qt3d/simple-qml/main.qml @@ -89,14 +89,17 @@ Entity { id: material } - TorusMesh { + GeometryRenderer { id: torusMesh - radius: 5 - minorRadius: 1 - rings: 100 - slices: 20 + view: TorusMesh { + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + } } + Transform { id: torusTransform scale3D: Qt.vector3d(1.5, 1, 0.5) @@ -108,9 +111,11 @@ Entity { components: [ torusMesh, material, torusTransform ] } - SphereMesh { + GeometryRenderer { id: sphereMesh - radius: 3 + view: SphereMesh { + radius: 3 + } } Transform { diff --git a/examples/qt3d/simplecustommaterial/PlaneModel.qml b/examples/qt3d/simplecustommaterial/PlaneModel.qml index b5271fe0c..bc95f8600 100644 --- a/examples/qt3d/simplecustommaterial/PlaneModel.qml +++ b/examples/qt3d/simplecustommaterial/PlaneModel.qml @@ -67,10 +67,12 @@ Entity { rotationX: 45 } - PlaneMesh { + GeometryRenderer { id: mesh - width: 1.0 - height: 1.0 - meshResolution: Qt.size(2, 2) + view: PlaneMesh { + width: 1.0 + height: 1.0 + meshResolution: Qt.size(2, 2) + } } } diff --git a/examples/qt3d/wave/Wave.qml b/examples/qt3d/wave/Wave.qml index 107502897..428ca8e56 100644 --- a/examples/qt3d/wave/Wave.qml +++ b/examples/qt3d/wave/Wave.qml @@ -81,10 +81,12 @@ Entity { diffuse: Qt.rgba( root.intensity, root.intensity, root.intensity, 1.0 ) // Set how bright the wave is } - PlaneMesh { + GeometryView { id: mesh - width: 25.0 - height: 5.0 - meshResolution: Qt.size( 125, 50 ) + view: PlaneMesh { + width: 25.0 + height: 5.0 + meshResolution: Qt.size( 125, 50 ) + } } } -- cgit v1.2.3