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
|
\section1 Rendering Qt Quick into a Texture
|
||||||
|
|
||||||
We begin by declaring the Entity that will become our control panel. It consists of
|
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
|
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 flat plane for the geometry, but we could use
|
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
|
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
|
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.
|
coordinates of mouse events to be passed to the originating Qt Quick scene.
|
||||||
|
|
||||||
\skipto Entity {
|
\skipto Entity {
|
||||||
\printto }
|
\printto Behavior
|
||||||
\printto }
|
\skipto Transform {
|
||||||
|
\printuntil }
|
||||||
Note that we enable the mirrored property on the PlaneMesh to ensure that the texture
|
\printuntil }
|
||||||
coordinate vertical axis is aligned with the usual Qt window coordinate system.
|
|
||||||
|
|
||||||
We also include an ObjectPicker component so that we can interact with the controls
|
We also include an ObjectPicker component so that we can interact with the controls
|
||||||
using the mouse:
|
using the mouse:
|
||||||
|
|
||||||
\skipto ObjectPicker {
|
\skipto ObjectPicker {
|
||||||
\printto }
|
\printuntil }
|
||||||
\printto }
|
\printuntil }
|
||||||
|
\printuntil }
|
||||||
|
|
||||||
For this example we have chosen to use an interaction mechanism whereby you must
|
For this example we have chosen to use an interaction mechanism whereby you must
|
||||||
explicitly middle-click the controls to enable them.
|
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:
|
To apply the texture to the mesh, we make use of the built in TextureMaterial:
|
||||||
|
|
||||||
\skipto TextureMaterial
|
\skipto TextureMaterial
|
||||||
\printto }
|
\printuntil }
|
||||||
|
|
||||||
The final remaining piece is how to render the above texture from a Qt Quick scene.
|
The final remaining piece is how to render the above texture from a Qt Quick scene.
|
||||||
This is done with the Scene2D element:
|
This is done with the Scene2D element:
|
||||||
|
|
@ -122,7 +122,8 @@
|
||||||
as a child to the Scene2D element:
|
as a child to the Scene2D element:
|
||||||
|
|
||||||
\skipto LogoControls
|
\skipto LogoControls
|
||||||
\printto }
|
\printuntil }
|
||||||
|
\printuntil }
|
||||||
|
|
||||||
When the mouseEnabled property is set to true by the ObjectPicker, then the Scene2D
|
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.
|
object will process mouse events from any ObjectPickers attached to the listed entities.
|
||||||
|
|
|
||||||
|
|
@ -108,25 +108,41 @@ Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity {
|
Entity {
|
||||||
id: plane
|
id: cube
|
||||||
|
|
||||||
components: [planeTransform, planeMaterial, planeMesh, planePicker]
|
components: [cubeTransform, cubeMaterial, cubeMesh, cubePicker]
|
||||||
|
|
||||||
Transform {
|
property real rotationAngle: 0
|
||||||
id: planeTransform
|
|
||||||
translation: Qt.vector3d(2, 0, 10)
|
Behavior on rotationAngle {
|
||||||
rotation: fromAxisAndAngle(Qt.vector3d(1,0,0), 90)
|
enabled: logoControls.enabled
|
||||||
|
RotationAnimation {
|
||||||
|
direction: RotationAnimation.Shortest
|
||||||
|
duration: 450
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaneMesh {
|
RotationAnimation on rotationAngle {
|
||||||
id: planeMesh
|
running: !logoControls.enabled
|
||||||
width: 1
|
loops: Animation.Infinite
|
||||||
height: 4
|
from: 0; to: 360
|
||||||
mirrored: true // Align OpenGL and Qt window coordinates by flipping texture coordinates
|
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 {
|
ObjectPicker {
|
||||||
id: planePicker
|
id: cubePicker
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
dragEnabled: true
|
dragEnabled: true
|
||||||
|
|
||||||
|
|
@ -141,7 +157,7 @@ Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureMaterial {
|
TextureMaterial {
|
||||||
id: planeMaterial
|
id: cubeMaterial
|
||||||
texture: offscreenTexture
|
texture: offscreenTexture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +180,7 @@ Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entities: [ plane ]
|
entities: [ cube ]
|
||||||
mouseEnabled: false
|
mouseEnabled: false
|
||||||
|
|
||||||
LogoControls {
|
LogoControls {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue