Use global picking API

When gobal picking is available (Qt 6.2+), use that instead of toggling
models pickable properties.

Task-number: QDS-4978
Change-Id: Id2a501ae97955128874447fa8a3b8afab3d1f2c7
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Kaj Grönholm
2021-09-06 14:24:23 +03:00
parent 7c2121bcfd
commit d8a7c97fcb
21 changed files with 59 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ DirectionalDraggable {
id: arrowRoot
Model {
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: LineGeometry {
id: lineGeometry
name: "Edit 3D ScalableArrow"
@@ -43,6 +44,7 @@ DirectionalDraggable {
Model {
id: arrowHead
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Cone"
materials: [ arrowRoot.material ]
y: arrowRoot.length - 3

View File

@@ -42,6 +42,7 @@ DirectionalDraggable {
Model {
id: handle
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
materials: [ handleRoot.material ]
scale: Qt.vector3d(0.02, 0.02, 0.02)

View File

@@ -35,6 +35,7 @@ Model {
property Node targetNode: null
property Node scene: null
property bool selected: false
readonly property bool _edit3dLocked: true // Make this non-pickable
function updateGeometry()
{

View File

@@ -41,6 +41,7 @@ Model {
property real offset: 0
readonly property bool hovering: mouseAreaYZ.hovering || mouseAreaXZ.hovering
readonly property bool _edit3dLocked: true // Make this non-pickable
property vector3d _scenePosPressed
property real _posPressed

View File

@@ -721,6 +721,7 @@ Item {
Model {
id: pivotCap
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
scale: pivotAutoScale.getScale(Qt.vector3d(0.03, 0.03, 0.03))
position: pivotLine.startPos
@@ -760,7 +761,7 @@ Item {
onPressed: (mouse)=> {
if (viewRoot.editView) {
var pickResult = viewRoot.editView.pick(mouse.x, mouse.y);
var pickResult = _generalHelper.pickViewAt(viewRoot.editView, mouse.x, mouse.y);
handleObjectClicked(_generalHelper.resolvePick(pickResult.objectHit),
mouse.modifiers & Qt.ControlModifier);

View File

@@ -41,6 +41,7 @@ DirectionalDraggable {
Model {
id: handle
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
materials: [ handleRoot.material ]
scale: Qt.vector3d(0.02, 0.02, 0.02)

View File

@@ -39,6 +39,7 @@ Node {
// Note: Only one instance of HelperGrid is supported, as the geometry names are fixed
Model { // Main grid lines
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: GridGeometry {
id: gridGeometry
name: "3D Edit View Helper Grid"
@@ -55,6 +56,7 @@ Node {
}
Model { // Subdivision lines
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: GridGeometry {
lines: gridGeometry.lines
step: gridGeometry.step
@@ -73,6 +75,7 @@ Node {
}
Model { // Z Axis
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: GridGeometry {
lines: gridGeometry.lines
step: gridGeometry.step
@@ -89,6 +92,7 @@ Node {
]
}
Model { // X Axis
readonly property bool _edit3dLocked: true // Make this non-pickable
eulerRotation.z: 90
geometry: GridGeometry {
lines: gridGeometry.lines

View File

@@ -33,6 +33,7 @@ Model {
property alias geometryName: lightGeometry.name // Name must be unique for each geometry
property alias geometryType: lightGeometry.lightType
property Material material
readonly property bool _edit3dLocked: true // Make this non-pickable
function updateGeometry()
{

View File

@@ -36,6 +36,7 @@ Node {
property alias color: lineMat.diffuseColor
Model {
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: LineGeometry {
id: lineGeometry
}

View File

@@ -52,6 +52,7 @@ View3D {
Model {
id: model
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
materials: previewMaterial
}

View File

@@ -82,6 +82,7 @@ View3D {
Model {
id: model
readonly property bool _edit3dLocked: true // Make this non-pickable
eulerRotation.y: 45
source: sourceModel.source

View File

@@ -40,6 +40,7 @@ Model {
property alias mouseArea: mouseArea
readonly property bool hovering: mouseArea.hovering
readonly property bool _edit3dLocked: true // Make this non-pickable
property vector3d _scenePosPressed
property vector2d _planePosPressed

View File

@@ -189,6 +189,7 @@ Node {
Model {
id: freeRotator
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
materials: DefaultMaterial {
id: material

View File

@@ -45,6 +45,7 @@ Model {
property vector3d _targetPosOnScreen
property vector3d _startRotation
property bool _trackBall
readonly property bool _edit3dLocked: true // Make this non-pickable
signal rotateCommit()
signal rotateChange()

View File

@@ -166,6 +166,7 @@ Node {
Model {
id: centerCube
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Cube"
scale: Qt.vector3d(0.024, 0.024, 0.024)
materials: DefaultMaterial {

View File

@@ -39,6 +39,7 @@ DirectionalDraggable {
property vector3d _startScale
Model {
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Cube"
y: 10
scale: Qt.vector3d(0.020, 0.020, 0.020)

View File

@@ -45,6 +45,7 @@ Node {
Model {
id: selectionBoxModel
readonly property bool _edit3dLocked: true // Make this non-pickable
geometry: selectionBoxGeometry
scale: selectionBox.targetNode ? selectionBox.targetNode.scale : Qt.vector3d(1, 1, 1)

View File

@@ -41,6 +41,7 @@ DirectionalDraggable {
Model {
id: handle
readonly property bool _edit3dLocked: true // Make this non-pickable
source: "#Sphere"
materials: [ handleRoot.material ]
scale: Qt.vector3d(0.02, 0.02, 0.02)

View File

@@ -267,6 +267,31 @@ void GeneralHelper::delayedPropertySet(QObject *obj, int delay, const QString &p
});
}
// Returns the first valid QQuick3DPickResult from view at (posX, PosY).
QQuick3DPickResult GeneralHelper::pickViewAt(QQuick3DViewport *view, float posX, float posY)
{
if (!view)
return QQuick3DPickResult();
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)
// Make sure global picking is on
view->setGlobalPickingEnabled(true);
// With Qt 6.2+, select first suitable result from all picked objects
auto pickResults = view->pickAll(posX, posY);
for (auto pickResult : pickResults) {
if (isPickable(pickResult.objectHit()))
return pickResult;
}
#else
// With older Qt version we'll just pick the single object
auto pickResult = view->pick(posX, posY);
if (isPickable(pickResult.objectHit()))
return pickResult;
#endif
return QQuick3DPickResult();
}
QQuick3DNode *GeneralHelper::resolvePick(QQuick3DNode *pickNode)
{
if (pickNode) {
@@ -315,6 +340,10 @@ bool GeneralHelper::isHidden(QQuick3DNode *node)
return false;
}
bool GeneralHelper::isPickable(QQuick3DNode *node) {
return (node && !isLocked(node) && !isHidden(node) && node->visible());
}
void GeneralHelper::storeToolState(const QString &sceneId, const QString &tool, const QVariant &state,
int delay)
{

View File

@@ -35,6 +35,7 @@
#include <QTimer>
#include <QVariant>
#include <QVector3D>
#include <QtQuick3D/private/qquick3dpickresult_p.h>
QT_BEGIN_NAMESPACE
class QQuick3DCamera;
@@ -74,12 +75,14 @@ public:
Q_INVOKABLE bool fuzzyCompare(double a, double b);
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
const QVariant& value);
Q_INVOKABLE QQuick3DPickResult pickViewAt(QQuick3DViewport *view, float posX, float posY);
Q_INVOKABLE QQuick3DNode *resolvePick(QQuick3DNode *pickNode);
Q_INVOKABLE void registerGizmoTarget(QQuick3DNode *node);
Q_INVOKABLE void unregisterGizmoTarget(QQuick3DNode *node);
Q_INVOKABLE bool isLocked(QQuick3DNode *node);
Q_INVOKABLE bool isHidden(QQuick3DNode *node);
Q_INVOKABLE bool isPickable(QQuick3DNode *node);
Q_INVOKABLE void storeToolState(const QString &sceneId, const QString &tool,
const QVariant &state, int delayEmit = 0);

View File

@@ -2047,8 +2047,10 @@ void Qt5InformationNodeInstanceServer::handleInstanceHidden(const ServerNodeInst
// as changes in the node tree (reparenting, adding new nodes) can make the previously set
// hide status based on ancestor unreliable.
node->setProperty("_edit3dHidden", edit3dHidden);
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 1)
if (auto model = qobject_cast<QQuick3DModel *>(node))
model->setPickable(!edit3dHidden); // allow 3D objects to receive mouse clicks
#endif
const auto childItems = node->childItems();
for (auto childItem : childItems) {
const ServerNodeInstance quick3dInstance = getQuick3DInstanceAndHidden(childItem);
@@ -2070,7 +2072,9 @@ void Qt5InformationNodeInstanceServer::handleInstanceHidden(const ServerNodeInst
value = QVariant::fromValue(node);
// Specify the actual pick target with dynamic property
checkModel->setProperty("_pickTarget", value);
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 1)
checkModel->setPickable(!edit3dHidden);
#endif
}
};
if (auto childNode = qobject_cast<QQuick3DNode *>(childItem))