[qt6][Viewer3D] Change picking behavior

This commit is contained in:
Candice Bentéjac 2024-10-11 17:29:33 +02:00
parent b884fc4e6b
commit 62f0a3e5df
4 changed files with 47 additions and 32 deletions

View file

@ -9,13 +9,14 @@ import SfmDataEntity 1.0
* Support for SfMData files in Qt3D.
* Create this component dynamically to test for SfmDataEntity plugin availability.
*/
SfmDataEntity {
id: root
property bool cameraPickingEnabled: true
property bool syncPickedViewId: false
// filter out non-reconstructed cameras
// Filter out non-reconstructed cameras
skipHidden: true
signal cameraSelected(var viewId)
@ -32,7 +33,7 @@ SfmDataEntity {
function spawnCameraSelectors() {
var validCameras = 0;
// spawn camera selector for each camera
// Spawn camera selector for each camera
for (var i = 0; i < root.cameras.length; ++i)
{
var cam = root.cameras[i];
@ -41,6 +42,7 @@ SfmDataEntity {
if (viewId === undefined)
continue;
camSelectionComponent.createObject(cam, {"viewId": viewId});
dummyCamSelectionComponent.createObject(cam, {"viewId": viewId});
validCameras++;
}
return validCameras;
@ -80,11 +82,11 @@ SfmDataEntity {
id: activePalette
}
// Camera selection picking and display
// Camera selection display only
Component {
id: camSelectionComponent
id: dummyCamSelectionComponent
Entity {
id: camSelector
id: dummyCamSelector
property string viewId
property color customColor: Qt.hsva((parseInt(viewId) / 255.0) % 1.0, 0.3, 1.0, 1.0)
property real extent: cameraPickingEnabled ? 0.2 : 0
@ -102,8 +104,33 @@ SfmDataEntity {
},
PhongMaterial{
id: mat
ambient: _reconstruction && (viewId === _reconstruction.selectedViewId || (viewId === _reconstruction.pickedViewId && syncPickedViewId)) ? activePalette.highlight : customColor // "#CCC"
diffuse: cameraPicker.containsMouse ? Qt.lighter(activePalette.highlight, 1.2) : ambient
ambient: _reconstruction && (viewId === _reconstruction.selectedViewId ||
(viewId === _reconstruction.pickedViewId && syncPickedViewId)) ?
activePalette.highlight : customColor // "#CCC"
}
]
}
}
// Camera selection picking only
Component {
id: camSelectionComponent
Entity {
id: camSelector
property string viewId
property color customColor: Qt.hsva((parseInt(viewId) / 255.0) % 1.0, 0.3, 1.0, 1.0)
property real extent: cameraPickingEnabled ? 0.5 : 0
components: [
// Use cuboid to represent the camera
Transform {
translation: Qt.vector3d(0, 0, 0.5 * cameraBack.zExtent)
},
CuboidMesh {
id: cameraBack
xExtent: parent.extent
yExtent: xExtent
zExtent: xExtent
},
ObjectPicker {
id: cameraPicker
@ -113,11 +140,10 @@ SfmDataEntity {
pick.accepted = (pick.buttons & Qt.LeftButton) && cameraPickingEnabled
}
onReleased: function(pick) {
const delta = Qt.point(Math.abs(pos.x - pick.position.x), Math.abs(pos.y - pick.position.y));
// only trigger picking when mouse has not moved between press and release
if (delta.x + delta.y < 4)
{
_reconstruction.selectedViewId = camSelector.viewId;
const delta = Qt.point(Math.abs(pos.x - pick.position.x), Math.abs(pos.y - pick.position.y))
// Only trigger picking when mouse has not moved between press and release
if (delta.x + delta.y < 4) {
_reconstruction.selectedViewId = camSelector.viewId
}
}
}