Skip to content

Commit 5c6a217

Browse files
committed
[qt6][Viewer3D] Change picking behavior
1 parent ed41b8d commit 5c6a217

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

meshroom/ui/qml/Viewer3D/MediaLibrary.qml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Entity {
3535
return false
3636
}
3737

38-
signal pressed(var pick)
38+
signal clicked(var pick)
3939
signal loadRequest(var idx)
4040

4141
QtObject {
@@ -192,6 +192,8 @@ Entity {
192192
MediaLoader {
193193
id: mediaLoader
194194

195+
cameraPickingEnabled: !sceneCameraController.pickingActive
196+
195197
// Whether MediaLoader has been fully instantiated by the NodeInstantiator
196198
property bool fullyInstantiated: false
197199

@@ -335,7 +337,7 @@ Entity {
335337
ObjectPicker {
336338
enabled: mediaLoader.enabled && pickingEnabled
337339
hoverEnabled: false
338-
onPressed: function(pick) { root.pressed(pick) }
340+
onClicked: function(pick) { root.clicked(pick) }
339341
}
340342
]
341343
}

meshroom/ui/qml/Viewer3D/MediaLoader.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Utils 1.0
2525
property Camera camera: null
2626

2727
property bool cached: false
28+
property bool cameraPickingEnabled: false
2829

2930
onSourceChanged: {
3031
if (cached) {
@@ -109,7 +110,7 @@ import Utils 1.0
109110
"source": source,
110111
"pointSize": Qt.binding(function() { return 0.01 * Viewer3DSettings.pointSize }),
111112
"locatorScale": Qt.binding(function() { return Viewer3DSettings.cameraScale }),
112-
"cameraPickingEnabled": Qt.binding(function() { return root.enabled }),
113+
"cameraPickingEnabled": Qt.binding(function() { return root.enabled && root.cameraPickingEnabled }),
113114
"resectionId": Qt.binding(function() { return Viewer3DSettings.resectionId }),
114115
"displayResections": Qt.binding(function() { return Viewer3DSettings.displayResectionIds }),
115116
"syncPickedViewId": Qt.binding(function() { return Viewer3DSettings.syncWithPickedViewId })

meshroom/ui/qml/Viewer3D/SfmDataLoader.qml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import SfmDataEntity 1.0
99
* Support for SfMData files in Qt3D.
1010
* Create this component dynamically to test for SfmDataEntity plugin availability.
1111
*/
12+
1213
SfmDataEntity {
1314
id: root
1415

1516
property bool cameraPickingEnabled: true
1617
property bool syncPickedViewId: false
1718

18-
// filter out non-reconstructed cameras
19+
// Filter out non-reconstructed cameras
1920
skipHidden: true
2021

2122
signal cameraSelected(var viewId)
@@ -32,7 +33,7 @@ SfmDataEntity {
3233

3334
function spawnCameraSelectors() {
3435
var validCameras = 0;
35-
// spawn camera selector for each camera
36+
// Spawn camera selector for each camera
3637
for (var i = 0; i < root.cameras.length; ++i)
3738
{
3839
var cam = root.cameras[i];
@@ -41,6 +42,7 @@ SfmDataEntity {
4142
if (viewId === undefined)
4243
continue;
4344
camSelectionComponent.createObject(cam, {"viewId": viewId});
45+
dummyCamSelectionComponent.createObject(cam, {"viewId": viewId});
4446
validCameras++;
4547
}
4648
return validCameras;
@@ -80,11 +82,11 @@ SfmDataEntity {
8082
id: activePalette
8183
}
8284

83-
// Camera selection picking and display
85+
// Camera selection display only
8486
Component {
85-
id: camSelectionComponent
87+
id: dummyCamSelectionComponent
8688
Entity {
87-
id: camSelector
89+
id: dummyCamSelector
8890
property string viewId
8991
property color customColor: Qt.hsva((parseInt(viewId) / 255.0) % 1.0, 0.3, 1.0, 1.0)
9092
property real extent: cameraPickingEnabled ? 0.2 : 0
@@ -102,8 +104,33 @@ SfmDataEntity {
102104
},
103105
PhongMaterial{
104106
id: mat
105-
ambient: _reconstruction && (viewId === _reconstruction.selectedViewId || (viewId === _reconstruction.pickedViewId && syncPickedViewId)) ? activePalette.highlight : customColor // "#CCC"
106-
diffuse: cameraPicker.containsMouse ? Qt.lighter(activePalette.highlight, 1.2) : ambient
107+
ambient: _reconstruction && (viewId === _reconstruction.selectedViewId ||
108+
(viewId === _reconstruction.pickedViewId && syncPickedViewId)) ?
109+
activePalette.highlight : customColor // "#CCC"
110+
}
111+
]
112+
}
113+
}
114+
115+
// Camera selection picking only
116+
Component {
117+
id: camSelectionComponent
118+
Entity {
119+
id: camSelector
120+
property string viewId
121+
property color customColor: Qt.hsva((parseInt(viewId) / 255.0) % 1.0, 0.3, 1.0, 1.0)
122+
property real extent: cameraPickingEnabled ? 0.5 : 0
123+
124+
components: [
125+
// Use cuboid to represent the camera
126+
Transform {
127+
translation: Qt.vector3d(0, 0, 0.5 * cameraBack.zExtent)
128+
},
129+
CuboidMesh {
130+
id: cameraBack
131+
xExtent: parent.extent
132+
yExtent: xExtent
133+
zExtent: xExtent
107134
},
108135
ObjectPicker {
109136
id: cameraPicker
@@ -113,11 +140,10 @@ SfmDataEntity {
113140
pick.accepted = (pick.buttons & Qt.LeftButton) && cameraPickingEnabled
114141
}
115142
onReleased: function(pick) {
116-
const delta = Qt.point(Math.abs(pos.x - pick.position.x), Math.abs(pos.y - pick.position.y));
117-
// only trigger picking when mouse has not moved between press and release
118-
if (delta.x + delta.y < 4)
119-
{
120-
_reconstruction.selectedViewId = camSelector.viewId;
143+
const delta = Qt.point(Math.abs(pos.x - pick.position.x), Math.abs(pos.y - pick.position.y))
144+
// Only trigger picking when mouse has not moved between press and release
145+
if (delta.x + delta.y < 4) {
146+
_reconstruction.selectedViewId = camSelector.viewId
121147
}
122148
}
123149
}

meshroom/ui/qml/Viewer3D/Viewer3D.qml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ FocusScope {
154154
focus: scene3D.activeFocus
155155
onMousePressed: function(mouse) {
156156
scene3D.forceActiveFocus()
157-
if (mouse.button === Qt.LeftButton) {
158-
if (!doubleClickTimer.running)
159-
doubleClickTimer.restart()
160-
} else
161-
doubleClickTimer.stop()
162157
}
163158
onMouseReleased: function(mouse, moved) {
164159
if (moving)
@@ -167,14 +162,6 @@ FocusScope {
167162
contextMenu.popup()
168163
}
169164
}
170-
171-
// Manually handle double click to activate object picking
172-
// for camera re-centering only during a short amount of time
173-
Timer {
174-
id: doubleClickTimer
175-
running: false
176-
interval: 300
177-
}
178165
}
179166

180167
components: [
@@ -223,8 +210,8 @@ FocusScope {
223210
id: mediaLibrary
224211
renderMode: Viewer3DSettings.renderMode
225212
// Picking to set focus point (camera view center)
226-
// Only activate it when a double click may happen or when the 'Control' key is pressed
227-
pickingEnabled: cameraController.pickingActive || doubleClickTimer.running
213+
// Only activate it when the 'Control' key is pressed
214+
pickingEnabled: cameraController.pickingActive
228215
camera: cameraSelector.camera
229216

230217
// Used for TransformGizmo in BoundingBox
@@ -238,11 +225,10 @@ FocusScope {
238225
}
239226
]
240227

241-
onPressed: function(pick) {
228+
onClicked: function(pick) {
242229
if (pick.button === Qt.LeftButton) {
243230
mainCamera.viewCenter = pick.worldIntersection
244231
}
245-
doubleClickTimer.stop()
246232
}
247233

248234
}

0 commit comments

Comments
 (0)