mirror of https://github.com/qt/qt3d.git
Scene2D example: highlight that QtQuick is a Texture on a Mesh
Change-Id: Ibc78cc120ceed26c8521fa116e1794500b47c2dd Task-number: QTBUG-60695 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
parent
2eb53d7354
commit
b35237bfee
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 59 KiB |
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -108,25 +108,41 @@ Entity {
|
|||
}
|
||||
|
||||
Entity {
|
||||
id: plane
|
||||
id: cube
|
||||
|
||||
components: [planeTransform, planeMaterial, planeMesh, planePicker]
|
||||
components: [cubeTransform, cubeMaterial, cubeMesh, cubePicker]
|
||||
|
||||
Transform {
|
||||
id: planeTransform
|
||||
translation: Qt.vector3d(2, 0, 10)
|
||||
rotation: fromAxisAndAngle(Qt.vector3d(1,0,0), 90)
|
||||
property real rotationAngle: 0
|
||||
|
||||
Behavior on rotationAngle {
|
||||
enabled: logoControls.enabled
|
||||
RotationAnimation {
|
||||
direction: RotationAnimation.Shortest
|
||||
duration: 450
|
||||
}
|
||||
}
|
||||
|
||||
PlaneMesh {
|
||||
id: planeMesh
|
||||
width: 1
|
||||
height: 4
|
||||
mirrored: true // Align OpenGL and Qt window coordinates by flipping texture coordinates
|
||||
RotationAnimation on rotationAngle {
|
||||
running: !logoControls.enabled
|
||||
loops: Animation.Infinite
|
||||
from: 0; to: 360
|
||||
duration: 4000
|
||||
onStopped: cube.rotationAngle = 0
|
||||
}
|
||||
|
||||
Transform {
|
||||
id: cubeTransform
|
||||
translation: Qt.vector3d(2, 0, 10)
|
||||
scale3D: Qt.vector3d(1, 4, 1)
|
||||
rotation: fromAxisAndAngle(Qt.vector3d(0,1,0), cube.rotationAngle)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue