Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3D] Point cloud editing paintbrush tool #60386

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions python/3d/auto_generated/qgscameracontroller.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ relative to other entities.
Sets whether the camera controller responds to mouse and keyboard events

.. versionadded:: 3.42
%End

bool inputHandlersEnabled() const;
%Docstring
Returns whether the camera controller responds to mouse and keyboard events

.. versionadded:: 3.44
%End

public slots:
Expand Down
7 changes: 7 additions & 0 deletions python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ relative to other entities.
Sets whether the camera controller responds to mouse and keyboard events

.. versionadded:: 3.42
%End

bool inputHandlersEnabled() const;
%Docstring
Returns whether the camera controller responds to mouse and keyboard events

.. versionadded:: 3.44
%End

public slots:
Expand Down
3 changes: 3 additions & 0 deletions src/3d/qgs3dmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ bool Qgs3DMapCanvas::eventFilter( QObject *watched, QEvent *event )
case QEvent::KeyPress:
mMapTool->keyPressEvent( static_cast<QKeyEvent *>( event ) );
break;
case QEvent::Wheel:
mMapTool->mouseWheelEvent( static_cast<QWheelEvent *>( event ) );
break;
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/3d/qgs3dmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void Qgs3DMapTool::keyPressEvent( QKeyEvent *event )
Q_UNUSED( event )
}

void Qgs3DMapTool::mouseWheelEvent( QWheelEvent *event )
{
Q_UNUSED( event )
}

void Qgs3DMapTool::activate()
{
}
Expand Down
4 changes: 4 additions & 0 deletions src/3d/qgs3dmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class Qgs3DMapCanvas;
class QMouseEvent;
class QKeyEvent;
class QWheelEvent;

#define SIP_NO_FILE

Expand All @@ -49,6 +50,8 @@ class _3D_EXPORT Qgs3DMapTool : public QObject
virtual void mouseMoveEvent( QMouseEvent *event );
//! Reimplement to handle key press \a event forwarded by the parent Qgs3DMapCanvas
virtual void keyPressEvent( QKeyEvent *event );
//! Reimplement to handle mouse wheel \a event forwarded by the parent Qgs3DMapCanvas
virtual void mouseWheelEvent( QWheelEvent *event );

//! Called when set as currently active map tool
virtual void activate();
Expand All @@ -59,6 +62,7 @@ class _3D_EXPORT Qgs3DMapTool : public QObject
//! Mouse cursor to be used when the tool is active
virtual QCursor cursor() const;

// TODO: needs fix, currently doesn't block camera movement, see setInputHandlersEnabled() in Camera Controller
/**
* Whether the default mouse controls to zoom/pan/rotate camera can stay enabled
* while the tool is active. This may be useful for some basic tools using just
Expand Down
13 changes: 13 additions & 0 deletions src/3d/qgs3dutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "qgs3dutils.h"

#include "qgs3dmapcanvas.h"
#include "qgslinestring.h"
#include "qgspolygon.h"
#include "qgsfeaturerequest.h"
Expand Down Expand Up @@ -990,3 +991,15 @@ QQuaternion Qgs3DUtils::rotationFromPitchHeadingAngles( float pitchAngle, float
{
return QQuaternion::fromAxisAndAngle( QVector3D( 0, 0, 1 ), headingAngle ) * QQuaternion::fromAxisAndAngle( QVector3D( 1, 0, 0 ), pitchAngle );
}

QgsPoint Qgs3DUtils::screenPointToMapCoordinates( const QPoint &screenPoint, Qgs3DMapCanvas &canvas )
{
const QgsRay3D ray = rayFromScreenPoint( screenPoint, canvas.size(), canvas.cameraController()->camera() );

// pick an arbitrary point mid-way between near and far plane
const float pointDistance = ( canvas.cameraController()->camera()->farPlane() + canvas.cameraController()->camera()->nearPlane() ) / 2;
const QVector3D worldPoint = ray.origin() + pointDistance * ray.direction().normalized();
const QgsVector3D mapTransform = worldToMapCoordinates( worldPoint, canvas.mapSettings()->origin() );
const QgsPoint mapPoint( mapTransform.x(), mapTransform.y(), mapTransform.z() );
return mapPoint;
}
8 changes: 8 additions & 0 deletions src/3d/qgs3dutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifndef QGS3DUTILS_H
#define QGS3DUTILS_H
#include "qgs3dmapcanvas.h"

class QgsLineString;
class QgsPolygon;
Expand Down Expand Up @@ -348,6 +349,13 @@ class _3D_EXPORT Qgs3DUtils
* \since QGIS 3.42
*/
static QQuaternion rotationFromPitchHeadingAngles( float pitchAngle, float headingAngle );

/**
* Transform the given screen point to \a QgsPoint in map coordinates
*
* \since QGIS 3.44
*/
static QgsPoint screenPointToMapCoordinates( const QPoint &screenPoint, Qgs3DMapCanvas &canvas );
};

#endif // QGS3DUTILS_H
6 changes: 6 additions & 0 deletions src/3d/qgscameracontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ class _3D_EXPORT QgsCameraController : public QObject
*/
void setInputHandlersEnabled( bool enable ) { mInputHandlersEnabled = enable; }

/**
* Returns whether the camera controller responds to mouse and keyboard events
* \since QGIS 3.44
*/
bool inputHandlersEnabled() const { return mInputHandlersEnabled; }

public slots:

/**
Expand Down
9 changes: 9 additions & 0 deletions src/3d/qgsframegraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,19 @@ Qt3DRender::QFrameGraphNode *QgsFrameGraph::constructRubberBandsPass()
mRubberBandsLayerFilter = new Qt3DRender::QLayerFilter( mRubberBandsCameraSelector );
mRubberBandsLayerFilter->addLayer( mRubberBandsLayer );

Qt3DRender::QBlendEquationArguments *blendState = new Qt3DRender::QBlendEquationArguments;
blendState->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
blendState->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );

Qt3DRender::QBlendEquation *blendEquation = new Qt3DRender::QBlendEquation;
blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );

mRubberBandsStateSet = new Qt3DRender::QRenderStateSet( mRubberBandsLayerFilter );
Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest;
depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
mRubberBandsStateSet->addRenderState( depthTest );
mRubberBandsStateSet->addRenderState( blendState );
mRubberBandsStateSet->addRenderState( blendEquation );

// Here we attach our drawings to the render target also used by forward pass.
// This is kind of okay, but as a result, post-processing effects get applied
Expand Down
Loading