Revision control
Copy as Markdown
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example dynamictexture
\ingroup quick3d-examples
\title Qt Quick 3D - Dynamic Texture Example
\brief Demonstrates how to use a 2D layer as a 3D texture.
\image dynamictexture.png
This example shows how to use 2D content from Qt Quick and use it as a
texture for 3D objects. The 2D item used in this example is a fancy
corkboard and it is textured onto a simple double door.
\section1 The 2D scene
The 2D content we use for this example is the \e CorkBoard scene from Qt
Quick's \l {Qt Quick Examples - Touch Interaction}{Touch Interaction
Example}. We put it in a Rectangle and show it on top of our View3D.
\snippet dynamictexture/main.qml 2d layer
We give the 2D object the name \c {object2d}, so we can refer to it later.
\section1 The 3D view
To use the 2D content in our 3D scene, we first have to put it into a material.
The texture is identified by the \l {Texture::sourceItem}{sourceItem} property,
referring back to \c object2d.
\snippet dynamictexture/Doors.qml material
We use the same material for each door, but different meshes. The meshes are
designed so that the texture is divided evenly across the doors. In addition to setting
the material and the source mesh, we also set the \l {Model::pickable}{pickable} property,
so we can click on the doors to open and close them:
\snippet dynamictexture/Doors.qml model heading
\dots
\snippet dynamictexture/Doors.qml model content
Finally, we add some interaction to our 3D scene, using \l {View3D::pick}{View3D.pick}:
\snippet dynamictexture/main.qml picking
Each door will open when clicked and its state is set to \c {"opened"}.
\snippet dynamictexture/Doors.qml state
*/