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;
156 const QVariantMap props {
157 { QStringLiteral(
"color" ), lineOrPolygon ? mColor.lighter( 130 ).name() : mColor.name() },
158 { QStringLiteral(
"size_unit" ), QStringLiteral(
"pixel" ) },
159 { QStringLiteral(
"size" ), QString::number( lineOrPolygon ? mWidth * 3.f : mWidth ) },
160 { QStringLiteral(
"outline_color" ), mColor.name() },
161 { QStringLiteral(
"outline_width" ), QString::number( lineOrPolygon ? 0.5 : 1 ) },
162 { QStringLiteral(
"name" ), mMarkerType == Square ? QStringLiteral(
"square" ) : QStringLiteral(
"circle" ) }
166 updateMarkerMaterial();
169QgsRubberBand3D::MarkerType QgsRubberBand3D::markerType()
const
174void QgsRubberBand3D::reset()
180void QgsRubberBand3D::addPoint(
const QgsPoint &pt )
182 mLineString.addVertex( pt );
186void QgsRubberBand3D::setPoints(
const QgsLineString &points )
188 mLineString = points;
192void QgsRubberBand3D::removeLastPoint()
194 const int lastVertexIndex = mLineString.numPoints() - 1;
195 mLineString.deleteVertex(
QgsVertexId( 0, 0, lastVertexIndex ) );
199void QgsRubberBand3D::moveLastPoint(
const QgsPoint &pt )
201 const int lastVertexIndex = mLineString.numPoints() - 1;
202 mLineString.moveVertex(
QgsVertexId( 0, 0, lastVertexIndex ), pt );
206void QgsRubberBand3D::updateGeometry()
208 QgsLineVertexData lineData;
209 lineData.withAdjacency =
true;
212 lineData.addLineString( mLineString, 0, closed );
216 mPositionAttribute->buffer()->setData( lineData.createVertexBuffer() );
217 mIndexAttribute->buffer()->setData( lineData.createIndexBuffer() );
218 mLineGeomRenderer->setVertexCount( lineData.indexes.count() );
222 lineData.vertices.pop_front();
225 if ( mHideLastMarker && !lineData.vertices.isEmpty() )
226 lineData.vertices.pop_back();
228 mMarkerGeometry->setPoints( lineData.vertices );
229 mMarkerGeometryRenderer->setVertexCount( lineData.vertices.count() );
232void QgsRubberBand3D::updateMarkerMaterial()
236 mMarkerEntity->addComponent( mMarkerMaterial );
240 mMarkerMaterial->setViewportSize( mEngine->size() );
242 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()
Line string geometry type, with support for z-dimension and m-values.
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.