29#include <Qt3DCore/QEntity>
31#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
32#include <Qt3DRender/QAttribute>
33#include <Qt3DRender/QBuffer>
34#include <Qt3DRender/QGeometry>
36#include <Qt3DCore/QAttribute>
37#include <Qt3DCore/QBuffer>
38#include <Qt3DCore/QGeometry>
41#include <Qt3DRender/QGeometryRenderer>
49 : mMapSettings( &map )
51 , mGeometryType( geometryType )
56 mLineEntity =
new Qt3DCore::QEntity( parentEntity );
58 QgsLineVertexData dummyLineData;
59 mGeometry = dummyLineData.createGeometry( mLineEntity );
61 Q_ASSERT( mGeometry->attributes().count() == 2 );
62 mPositionAttribute = mGeometry->attributes().at( 0 );
63 mIndexAttribute = mGeometry->attributes().at( 1 );
65 mLineGeomRenderer =
new Qt3DRender::QGeometryRenderer;
66 mLineGeomRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::LineStripAdjacency );
67 mLineGeomRenderer->setGeometry( mGeometry );
68 mLineGeomRenderer->setPrimitiveRestartEnabled(
true );
69 mLineGeomRenderer->setRestartIndexValue( 0 );
71 mLineEntity->addComponent( mLineGeomRenderer );
73 mLineMaterial =
new QgsLineMaterial;
74 mLineMaterial->setLineWidth( mWidth );
75 mLineMaterial->setLineColor( mColor );
78 mLineMaterial->setViewportSize( engine->
size() );
80 mLineMaterial->setViewportSize( engine->
size() );
82 mLineEntity->addComponent( mLineMaterial );
86 mMarkerEntity =
new Qt3DCore::QEntity( parentEntity );
88 mMarkerGeometryRenderer =
new Qt3DRender::QGeometryRenderer;
89 mMarkerGeometryRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
90 mMarkerGeometryRenderer->setGeometry( mMarkerGeometry );
91 mMarkerGeometryRenderer->setVertexCount( mMarkerGeometry->count() );
93 setMarkerType( mMarkerType );
94 mMarkerEntity->addComponent( mMarkerGeometryRenderer );
97QgsRubberBand3D::~QgsRubberBand3D()
100 mLineEntity->deleteLater();
101 mMarkerEntity->deleteLater();
104float QgsRubberBand3D::width()
const
109void QgsRubberBand3D::setWidth(
float width )
116 mLineMaterial->setLineWidth( width );
120 mMarkerSymbol->setSize( width );
121 updateMarkerMaterial();
124QColor QgsRubberBand3D::color()
const
129void QgsRubberBand3D::setColor( QColor color )
135 mLineMaterial->setLineColor( color );
136 mMarkerSymbol->setColor( color.lighter( 130 ) );
140 mMarkerSymbol->setColor( color );
143 if ( mMarkerSymbol->symbolLayerCount() > 0 && mMarkerSymbol->symbolLayer( 0 )->layerType() == QLatin1String(
"SimpleMarker" ) )
145 static_cast<QgsMarkerSymbolLayer *
>( mMarkerSymbol->symbolLayer( 0 ) )->setStrokeColor( color );
147 updateMarkerMaterial();
150void QgsRubberBand3D::setMarkerType( MarkerType marker )
152 mMarkerType = marker;
154 const QVariantMap props {
155 { QStringLiteral(
"color" ), mGeometryType ==
Qgis::GeometryType::Line ? mColor.lighter( 130 ).name() : mColor.name() },
156 { QStringLiteral(
"size_unit" ), QStringLiteral(
"pixel" ) },
158 { QStringLiteral(
"outline_color" ), mColor.name() },
160 { QStringLiteral(
"name" ), mMarkerType == Square ? QStringLiteral(
"square" ) : QStringLiteral(
"circle" ) }
164 updateMarkerMaterial();
167QgsRubberBand3D::MarkerType QgsRubberBand3D::markerType()
const
172void QgsRubberBand3D::reset()
178void QgsRubberBand3D::addPoint(
const QgsPoint &pt )
180 mLineString.addVertex( pt );
184void QgsRubberBand3D::removeLastPoint()
186 const int lastVertexIndex = mLineString.numPoints() - 1;
187 mLineString.deleteVertex(
QgsVertexId( 0, 0, lastVertexIndex ) );
191void QgsRubberBand3D::moveLastPoint(
const QgsPoint &pt )
193 const int lastVertexIndex = mLineString.numPoints() - 1;
194 mLineString.moveVertex(
QgsVertexId( 0, 0, lastVertexIndex ), pt );
198void QgsRubberBand3D::updateGeometry()
200 QgsLineVertexData lineData;
201 lineData.withAdjacency =
true;
203 lineData.addLineString( mLineString );
207 mPositionAttribute->buffer()->setData( lineData.createVertexBuffer() );
208 mIndexAttribute->buffer()->setData( lineData.createIndexBuffer() );
209 mLineGeomRenderer->setVertexCount( lineData.indexes.count() );
213 lineData.vertices.pop_front();
216 if ( mHideLastMarker && !lineData.vertices.isEmpty() )
217 lineData.vertices.pop_back();
219 mMarkerGeometry->setPoints( lineData.vertices );
220 mMarkerGeometryRenderer->setVertexCount( lineData.vertices.count() );
223void QgsRubberBand3D::updateMarkerMaterial()
227 mMarkerEntity->addComponent( mMarkerMaterial );
231 mMarkerMaterial->setViewportSize( mEngine->size() );
233 mMarkerMaterial->setViewportSize( mEngine->size() );
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Vertex
Clamp every vertex of feature.
static Qgs3DRenderContext fromMapSettings(const Qgs3DMapSettings *mapSettings)
Creates an initialized Qgs3DRenderContext instance from given Qgs3DMapSettings.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
void sizeChanged()
Emitted after a call to setSize()
Abstract base class for marker symbol layers.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Point geometry type, with support for z-dimension and m-values.
QSize size() const override
Returns size of the engine's rendering area in pixels.
Utility class for identifying a unique vertex within a geometry.