From b35237bfee04ae38cc35bdb333ab1ef8a74ffaae Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 9 May 2017 15:14:00 +0200 Subject: Scene2D example: highlight that QtQuick is a Texture on a Mesh Change-Id: Ibc78cc120ceed26c8521fa116e1794500b47c2dd Task-number: QTBUG-60695 Reviewed-by: Sean Harmer --- examples/qt3d/scene2d/doc/images/scene2d.png | Bin 45997 -> 60762 bytes examples/qt3d/scene2d/doc/src/scene2d.qdoc | 23 +++++++-------- examples/qt3d/scene2d/main.qml | 40 +++++++++++++++++++-------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/examples/qt3d/scene2d/doc/images/scene2d.png b/examples/qt3d/scene2d/doc/images/scene2d.png index 789148537..db55a2fe5 100644 Binary files a/examples/qt3d/scene2d/doc/images/scene2d.png and b/examples/qt3d/scene2d/doc/images/scene2d.png differ diff --git a/examples/qt3d/scene2d/doc/src/scene2d.qdoc b/examples/qt3d/scene2d/doc/src/scene2d.qdoc index 66cf7dd21..90b767e43 100644 --- a/examples/qt3d/scene2d/doc/src/scene2d.qdoc +++ b/examples/qt3d/scene2d/doc/src/scene2d.qdoc @@ -74,25 +74,25 @@ \section1 Rendering Qt Quick into a Texture We begin by declaring the Entity that will become our control panel. It consists of - a PlaneMesh onto which we will place the texture containing a rendering of the Qt Quick - scene. In this case we are using a simple flat plane for the geometry, but we could use + 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. \skipto Entity { - \printto } - \printto } - - Note that we enable the mirrored property on the PlaneMesh to ensure that the texture - coordinate vertical axis is aligned with the usual Qt window coordinate system. + \printto Behavior + \skipto Transform { + \printuntil } + \printuntil } We also include an ObjectPicker component so that we can interact with the controls using the mouse: \skipto ObjectPicker { - \printto } - \printto } + \printuntil } + \printuntil } + \printuntil } For this example we have chosen to use an interaction mechanism whereby you must explicitly middle-click the controls to enable them. @@ -100,7 +100,7 @@ To apply the texture to the mesh, we make use of the built in TextureMaterial: \skipto TextureMaterial - \printto } + \printuntil } The final remaining piece is how to render the above texture from a Qt Quick scene. This is done with the Scene2D element: @@ -122,7 +122,8 @@ as a child to the Scene2D element: \skipto LogoControls - \printto } + \printuntil } + \printuntil } When the mouseEnabled property is set to true by the ObjectPicker, then the Scene2D object will process mouse events from any ObjectPickers attached to the listed entities. diff --git a/examples/qt3d/scene2d/main.qml b/examples/qt3d/scene2d/main.qml index d9d4676c2..35b8f3eb6 100644 --- a/examples/qt3d/scene2d/main.qml +++ b/examples/qt3d/scene2d/main.qml @@ -108,25 +108,41 @@ Entity { } Entity { - id: plane + id: cube - components: [planeTransform, planeMaterial, planeMesh, planePicker] + components: [cubeTransform, cubeMaterial, cubeMesh, cubePicker] + + property real rotationAngle: 0 + + Behavior on rotationAngle { + enabled: logoControls.enabled + RotationAnimation { + direction: RotationAnimation.Shortest + duration: 450 + } + } + + RotationAnimation on rotationAngle { + running: !logoControls.enabled + loops: Animation.Infinite + from: 0; to: 360 + duration: 4000 + onStopped: cube.rotationAngle = 0 + } Transform { - id: planeTransform + id: cubeTransform translation: Qt.vector3d(2, 0, 10) - rotation: fromAxisAndAngle(Qt.vector3d(1,0,0), 90) + scale3D: Qt.vector3d(1, 4, 1) + rotation: fromAxisAndAngle(Qt.vector3d(0,1,0), cube.rotationAngle) } - PlaneMesh { - id: planeMesh - width: 1 - height: 4 - mirrored: true // Align OpenGL and Qt window coordinates by flipping texture coordinates + CuboidMesh { + id: cubeMesh } ObjectPicker { - id: planePicker + id: cubePicker hoverEnabled: true dragEnabled: true @@ -141,7 +157,7 @@ Entity { } TextureMaterial { - id: planeMaterial + id: cubeMaterial texture: offscreenTexture } @@ -164,7 +180,7 @@ Entity { } } - entities: [ plane ] + entities: [ cube ] mouseEnabled: false LogoControls { -- cgit v1.2.3