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>
54 mLineEntity =
new Qt3DCore::QEntity( parentEntity );
56 QgsLineVertexData dummyLineData;
57 mGeometry = dummyLineData.createGeometry( mLineEntity );
59 Q_ASSERT( mGeometry->attributes().count() == 2 );
60 mPositionAttribute = mGeometry->attributes()[0];
61 mIndexAttribute = mGeometry->attributes()[1];
63 mGeomRenderer =
new Qt3DRender::QGeometryRenderer;
64 mGeomRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::LineStripAdjacency );
65 mGeomRenderer->setGeometry( mGeometry );
66 mGeomRenderer->setPrimitiveRestartEnabled(
true );
67 mGeomRenderer->setRestartIndexValue( 0 );
69 mLineEntity->addComponent( mGeomRenderer );
71 mLineMaterial =
new QgsLineMaterial;
72 mLineMaterial->setLineWidth( 3 );
73 mLineMaterial->setLineColor( Qt::red );
77 mLineMaterial->setViewportSize( engine->
size() );
79 mLineMaterial->setViewportSize( engine->
size() );
81 mLineEntity->addComponent( mLineMaterial );
84 mMarkerEntity =
new Qt3DCore::QEntity( parentEntity );
86 mMarkerGeometryRenderer =
new Qt3DRender::QGeometryRenderer;
87 mMarkerGeometryRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
88 mMarkerGeometryRenderer->setGeometry( mMarkerGeometry );
89 mMarkerGeometryRenderer->setVertexCount( mMarkerGeometry->count() );
91 const QVariantMap props
93 {QStringLiteral(
"color" ), QStringLiteral(
"red" ) },
94 {QStringLiteral(
"size" ), 6 },
95 {QStringLiteral(
"outline_color" ), QStringLiteral(
"green" ) },
96 {QStringLiteral(
"outline_width" ), 0.5 }
100 updateMarkerMaterial();
101 mMarkerEntity->addComponent( mMarkerGeometryRenderer );
104QgsRubberBand3D::~QgsRubberBand3D()
107 delete mMarkerEntity;
108 delete mMarkerSymbol;
111float QgsRubberBand3D::width()
const
113 return mLineMaterial->lineWidth();
116void QgsRubberBand3D::setWidth(
float width )
118 mLineMaterial->setLineWidth( width );
119 mMarkerSymbol->setSize( width );
120 updateMarkerMaterial();
123QColor QgsRubberBand3D::color()
const
125 return mLineMaterial->lineColor();
128void QgsRubberBand3D::setColor( QColor color )
130 mLineMaterial->setLineColor( color );
131 mMarkerSymbol->setColor( color.lighter( 130 ) );
132 if ( mMarkerSymbol->symbolLayerCount() > 0 && mMarkerSymbol->symbolLayer( 0 )->layerType() == QLatin1String(
"SimpleMarker" ) )
134 static_cast<QgsMarkerSymbolLayer *
>( mMarkerSymbol->symbolLayer( 0 ) )->setStrokeColor( color );
136 updateMarkerMaterial();
139void QgsRubberBand3D::reset()
142 mShowLastMarker =
false;
146void QgsRubberBand3D::addPoint(
const QgsPoint &pt )
148 mLineString.addVertex( pt );
152void QgsRubberBand3D::removeLastPoint()
154 const int lastVertexIndex = mLineString.numPoints() - 1;
155 mLineString.deleteVertex(
QgsVertexId( 0, 0, lastVertexIndex ) );
159void QgsRubberBand3D::moveLastPoint(
const QgsPoint &pt )
161 const int lastVertexIndex = mLineString.numPoints() - 1;
162 mLineString.moveVertex(
QgsVertexId( 0, 0, lastVertexIndex ), pt );
166void QgsRubberBand3D::updateGeometry()
168 QgsLineVertexData lineData;
169 lineData.withAdjacency =
true;
171 lineData.addLineString( mLineString );
173 mPositionAttribute->buffer()->setData( lineData.createVertexBuffer() );
174 mIndexAttribute->buffer()->setData( lineData.createIndexBuffer() );
175 mGeomRenderer->setVertexCount( lineData.indexes.count() );
178 lineData.vertices.pop_front();
181 if ( !mShowLastMarker && !lineData.vertices.isEmpty() )
182 lineData.vertices.pop_back();
184 mMarkerGeometry->setPoints( lineData.vertices );
185 mMarkerGeometryRenderer->setVertexCount( lineData.vertices.count() );
188void QgsRubberBand3D::updateMarkerMaterial()
190 delete mMarkerMaterial;
193 mMarkerEntity->addComponent( mMarkerMaterial );
198 mMarkerMaterial->setViewportSize( mEngine->size() );
200 mMarkerMaterial->setViewportSize( mEngine->size() );
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
@ Vertex
Clamp every vertex of feature.
static Qgs3DRenderContext fromMapSettings(const Qgs3DMapSettings *mapSettings)
Creates an initialized Qgs3DRenderContext instance from given Qgs3DMapSettings.
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.