[英]Qt3d qml user input
我是Qt3d的新手,我需要處理多個模型的場景用戶輸入。 特別是我需要找到用戶點擊的模型。 我嘗試使用mouseHandler和ObjectPicker,但它似乎不起作用。 有人有例子嗎?
例如,如果我有:
Entity {
Camera { id: camera ... }
FirstPersonCameraController {
camera: camera
}
components: [
RenderSettings{
activeFrameGraph: ForwardRenderer {
camera: camera
clearColor: "transparent"
},
InputSettings{}
]
MouseDevice {
id: mouse1
sensitivity: 0.1
}
SphereMesh {
id: sphereMesh
radius: 3
}
PhongMaterial{
id: material
}
Entity {
id: sphere1
components: [sphereMesh, material]
MouseHandler {
sourceDevice: mouse1
onClicked: console.log("[sphere 1] clicked"
}
}
Entity {
id: sphere2
components: [sphereMesh, material]
MouseHandler {
sourceDevice: mouse1
onClicked: console.log("[sphere 2] clicked"
}
}
}
我需要區分用戶是否點擊了sphere1或sphere2,但如果我點擊球體,我看不到任何日志!
Entity {
id: sphere2
components: [sphereMesh, material, spherePicker]
}
ObjectPicker{
id: spherePicker
onPressed:{
console.log("Sphere clicked")
}
}
components: [
RenderSettings{
activeFrameGraph:ForwardRenderer {
camera: camera
clearColor: "transparent"
},
InputSettings{}
pickingSettings.pickMethod: PickingSettings.TrianglePicking
pickingSettings.faceOrientationPickingMode: PickingSettings.FrontAndBackFace
]
ObjectPicker{
onPressed:{
console.log("Pressed at: " + pick.worldIntersection)
//If using triangle picking, you can also see index of the pressed triangle
console.log("Triangle index: " + pick.triangleIndex)
}
}
相關文檔在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.