Details
Description
In the following code, mapTo3DScene() will fail with the error:
QML View3D: Cannot resolve scene position without a camera assigned!
qml: pos3D: QVector3D(0, 0, 0)
View3D { id: view OrthographicCamera{ id: mainCamera z: 200 } Node { ..... } MouseArea { anchors.fill: view onMouseXChanged: { var pos3D = view.mapTo3DScene(Qt.vector3d(mouseX, mouseY, 0)) console.log("pos3D: "+pos3D) } }
Note that explicit setting the camera in View3D like this:
camera: OrthographicCamera{ id: mainCamera z: 200 }
will make mapTo3DScene() work properly, but then View3D content will fail to be displayed.
I notice that adding view.update() to onMouseXChanged will make View3D content to be display, but this is ugly since it will only show content on mouse move. I tried calling view.update() on Component.complet but this fails.
The attached example shows a red Sphere Model, be sure to compile commenting / uncommentig line 27 in main.qml, where the OrtographicCamera is explicitly set.
- camera explicit set: mapTo3DScene() works but View3D content display fails
- camera not explicit set: mapTo3DScene() fails, but View3D content display works