为什么 FirstPersonCameraController {camera: camera} 不能与 QML ApplicationWindow 一起使用?
why FirstPersonCameraController {camera: camera } not working with QML ApplicationWindow?
我正在 ApplicationWindow 中从 PyQT5 加载 QML 3D 场景。
但是,我无法使用鼠标平移和旋转我的自定义模型。
import QtQuick.Controls 2.5
import QtQuick.Scene3D 2.12
import Qt3D.Core 2.12
import Qt3D.Render 2.12
import Qt3D.Input 2.12
import Qt3D.Extras 2.13
import QtQuick 2.12 as QQ2
ApplicationWindow{
Scene3D {
id: scene3d
anchors.fill: parent
anchors.margins: 10
focus: true
aspects: "input"
FirstPersonCameraController {
camera: camera
}
Entity {
id: sceneRoot
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
nearPlane : 0.1
farPlane : 1000.0
position: Qt.vector3d( 0.0, 0.0, 40.0 )
upVector: Qt.vector3d( 0.0, 1.0, 1.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
PointLight{
id:pl3
}
}
ObjectPicker{
id: spherePicker
onPressed:{
console.log("Sphere clicked")
}
}
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
camera: camera
clearColor: "transparent"
}
},
InputSettings { }
]
PhongMaterial {
id: material
diffuse:Qt.rgba(0.5,0.5,0,1)
}
PointLight{
id:pl2
}
Mesh {
id: esh
source: "egg1.obj"
}
Transform {
id: torusTransform
scale3D: Qt.vector3d(5, 5, 5)
rotation: fromAxisAndAngle(Qt.vector3d(1, 1, 0), 45)
}
Entity {
id: torusEntity
components: [ esh, material, torusTransform,spherePicker ]
}
}
}
}
模型加载正确,只是我无法用鼠标控制它的旋转。
我认为这与 "FirstPersonCameraController"
有关
我目前无法自行验证这一点,但我假设您必须将 FirstPersonCameraController
移动到名为 sceneRoot
.
的根实体中
现在它是 Scene3D
的子项。尝试将其移动到 Camera
节点下方,看看是否可行。
顺便说一句:我假设你的意思是你无法控制相机,而当你说
时,这就是你想要的
The model loads correctly just that I am not able to control it's rotation wit the mouse.
这是我目前用于旋转和平移对象的工作。 `
Scene3D
{
id:myScene3d
property int rotX:0
property int rotY:0
property int rotZ:0`
Entity
{
id: sceneRoot
Camera
{
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 2
aspectRatio: 16/9
nearPlane : 0.1
farPlane : 20.0
position: Qt.vector3d(posX,posY,posZ)
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}
FirstPersonCameraController
{
camera: camera
linearSpeed: 1.0
acceleration: 0.1
deceleration: 1.0
}
Entity
{
id: monkeyEntity
components: [
SceneLoader
{
id: sceneLoader
},
Transform
{
rotationX : rotX
rotationY : rotY
rotationZ : rotZ
},
ObjectPicker
{
onPressed: {
console.log("Object clicked! Pressed at world-intersection: ", pick.worldIntersection)
console.log("Triangle index: ", pick.triangleIndex)
}
}
]
如您所见,rotX、rotY 和 rotZ 从场景外部用作 属性。
然后我只是在 MouseX 和 MouseY 值上使用了 case 语句。我希望你明白了。
}
我正在 ApplicationWindow 中从 PyQT5 加载 QML 3D 场景。 但是,我无法使用鼠标平移和旋转我的自定义模型。
import QtQuick.Controls 2.5
import QtQuick.Scene3D 2.12
import Qt3D.Core 2.12
import Qt3D.Render 2.12
import Qt3D.Input 2.12
import Qt3D.Extras 2.13
import QtQuick 2.12 as QQ2
ApplicationWindow{
Scene3D {
id: scene3d
anchors.fill: parent
anchors.margins: 10
focus: true
aspects: "input"
FirstPersonCameraController {
camera: camera
}
Entity {
id: sceneRoot
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
nearPlane : 0.1
farPlane : 1000.0
position: Qt.vector3d( 0.0, 0.0, 40.0 )
upVector: Qt.vector3d( 0.0, 1.0, 1.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
PointLight{
id:pl3
}
}
ObjectPicker{
id: spherePicker
onPressed:{
console.log("Sphere clicked")
}
}
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
camera: camera
clearColor: "transparent"
}
},
InputSettings { }
]
PhongMaterial {
id: material
diffuse:Qt.rgba(0.5,0.5,0,1)
}
PointLight{
id:pl2
}
Mesh {
id: esh
source: "egg1.obj"
}
Transform {
id: torusTransform
scale3D: Qt.vector3d(5, 5, 5)
rotation: fromAxisAndAngle(Qt.vector3d(1, 1, 0), 45)
}
Entity {
id: torusEntity
components: [ esh, material, torusTransform,spherePicker ]
}
}
}
}
模型加载正确,只是我无法用鼠标控制它的旋转。
我认为这与 "FirstPersonCameraController"
有关我目前无法自行验证这一点,但我假设您必须将 FirstPersonCameraController
移动到名为 sceneRoot
.
现在它是 Scene3D
的子项。尝试将其移动到 Camera
节点下方,看看是否可行。
顺便说一句:我假设你的意思是你无法控制相机,而当你说
时,这就是你想要的The model loads correctly just that I am not able to control it's rotation wit the mouse.
这是我目前用于旋转和平移对象的工作。 `
Scene3D
{
id:myScene3d
property int rotX:0
property int rotY:0
property int rotZ:0`
Entity
{
id: sceneRoot
Camera
{
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 2
aspectRatio: 16/9
nearPlane : 0.1
farPlane : 20.0
position: Qt.vector3d(posX,posY,posZ)
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}
FirstPersonCameraController
{
camera: camera
linearSpeed: 1.0
acceleration: 0.1
deceleration: 1.0
}
Entity
{
id: monkeyEntity
components: [
SceneLoader
{
id: sceneLoader
},
Transform
{
rotationX : rotX
rotationY : rotY
rotationZ : rotZ
},
ObjectPicker
{
onPressed: {
console.log("Object clicked! Pressed at world-intersection: ", pick.worldIntersection)
console.log("Triangle index: ", pick.triangleIndex)
}
}
]
如您所见,rotX、rotY 和 rotZ 从场景外部用作 属性。 然后我只是在 MouseX 和 MouseY 值上使用了 case 语句。我希望你明白了。 }