将3D内容放入2D场景:使用View3D元素表示一个2D表面即可,修改View3D的renderMode属性可以控制融合的顺序(默认为:View3D。Offscreen)
将2D内容放入3D场景:使用QtQuick 3D Texture 元素的sourceItem属性, 将2D元素直接放入3D场景。
import QtQuick
import QtQuick.Window
import QtQuick3D
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
View3D{
anchors.fill:parent
environment: SceneEnvironment{
clearColor: "#222222"
backgroundMode: SceneEnvironment.Color
}
Node{
y:-30
eulerRotation.y:-30
Rectangle{
anchors.horizontalCenter: parent.horizontalCenter
color:"orange"
width:text.width + 10
height:text.height + 10
Text{
anchors.centerIn: parent
id:text
text:"I'm Suzanne"
font.pointSize: 14
color:"black"
}
}
}
Model{
source:"meshes/suzanne.mesh"
position:Qt.vector3d(0,0,0)
scale:Qt.vector3d(30,30,30)
eulerRotation:Qt.vector3d(-80,30,0)
materials:[
DefaultMaterial{
diffuseColor: "yellow"
specularTint: "red"
specularAmount: 0.7
}
]
}
PerspectiveCamera{
position:Qt.vector3d(0,0,150)
Component.onCompleted: lookAt(Qt.vector3d(0,0,0))
}
DirectionalLight{
eulerRotation.x:-20
eulerRotation.y:110
brightness: 2
castsShadow: true
}
}
}
显示效果图