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>
42#include <Qt3DRender/QMaterial>
55 mLineEntity =
new Qt3DCore::QEntity( parentEntity );
57 QgsLineVertexData dummyLineData;
58 mGeometry = dummyLineData.createGeometry( mLineEntity );
60 Q_ASSERT( mGeometry->attributes().count() == 2 );
61 mPositionAttribute = mGeometry->attributes()[0];
62 mIndexAttribute = mGeometry->attributes()[1];
64 mGeomRenderer =
new Qt3DRender::QGeometryRenderer;
65 mGeomRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::LineStripAdjacency );
66 mGeomRenderer->setGeometry( mGeometry );
67 mGeomRenderer->setPrimitiveRestartEnabled(
true );
68 mGeomRenderer->setRestartIndexValue( 0 );
70 mLineEntity->addComponent( mGeomRenderer );
72 mLineMaterial =
new QgsLineMaterial;
73 mLineMaterial->setLineWidth( 3 );
74 mLineMaterial->setLineColor( Qt::red );
78 mLineMaterial->setViewportSize( engine->
size() );
80 mLineMaterial->setViewportSize( engine->
size() );
82 mLineEntity->addComponent( mLineMaterial );
85 mMarkerEntity =
new Qt3DCore::QEntity( parentEntity );
87 mMarkerGeometryRenderer =
new Qt3DRender::QGeometryRenderer;
88 mMarkerGeometryRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
89 mMarkerGeometryRenderer->setGeometry( mMarkerGeometry );
90 mMarkerGeometryRenderer->setVertexCount( mMarkerGeometry->count() );
92 const QVariantMap props
94 {QStringLiteral(
"color" ), QStringLiteral(
"red" ) },
95 {QStringLiteral(
"size" ), 6 },
96 {QStringLiteral(
"outline_color" ), QStringLiteral(
"green" ) },
97 {QStringLiteral(
"outline_width" ), 0.5 }
101 updateMarkerMaterial();
102 mMarkerEntity->addComponent( mMarkerGeometryRenderer );
105QgsRubberBand3D::~QgsRubberBand3D()
108 delete mMarkerEntity;
109 delete mMarkerSymbol;
112float QgsRubberBand3D::width()
const
114 return mLineMaterial->lineWidth();
117void QgsRubberBand3D::setWidth(
float width )
119 mLineMaterial->setLineWidth( width );
120 mMarkerSymbol->setSize( width );
121 updateMarkerMaterial();
124QColor QgsRubberBand3D::color()
const
126 return mLineMaterial->lineColor();
129void QgsRubberBand3D::setColor( QColor color )
131 mLineMaterial->setLineColor( color );
132 mMarkerSymbol->setColor( color.lighter( 130 ) );
133 if ( mMarkerSymbol->symbolLayerCount() > 0 && mMarkerSymbol->symbolLayer( 0 )->layerType() == QLatin1String(
"SimpleMarker" ) )
135 static_cast<QgsMarkerSymbolLayer *
>( mMarkerSymbol->symbolLayer( 0 ) )->setStrokeColor( color );
137 updateMarkerMaterial();
140void QgsRubberBand3D::reset()
143 mShowLastMarker =
false;
147void QgsRubberBand3D::addPoint(
const QgsPoint &pt )
149 mLineString.addVertex( pt );
153void QgsRubberBand3D::removeLastPoint()
155 const int lastVertexIndex = mLineString.numPoints() - 1;
156 mLineString.deleteVertex(
QgsVertexId( 0, 0, lastVertexIndex ) );
160void QgsRubberBand3D::moveLastPoint(
const QgsPoint &pt )
162 const int lastVertexIndex = mLineString.numPoints() - 1;
163 mLineString.moveVertex(
QgsVertexId( 0, 0, lastVertexIndex ), pt );
167void QgsRubberBand3D::updateGeometry()
169 QgsLineVertexData lineData;
170 lineData.withAdjacency =
true;
172 lineData.addLineString( mLineString );
174 mPositionAttribute->buffer()->setData( lineData.createVertexBuffer() );
175 mIndexAttribute->buffer()->setData( lineData.createIndexBuffer() );
176 mGeomRenderer->setVertexCount( lineData.indexes.count() );
179 lineData.vertices.pop_front();
182 if ( !mShowLastMarker && !lineData.vertices.isEmpty() )
183 lineData.vertices.pop_back();
185 mMarkerGeometry->setPoints( lineData.vertices );
186 mMarkerGeometryRenderer->setVertexCount( lineData.vertices.count() );
189void QgsRubberBand3D::updateMarkerMaterial()
191 delete mMarkerMaterial;
194 mMarkerEntity->addComponent( mMarkerMaterial );
199 mMarkerMaterial->setViewportSize( mEngine->size() );
201 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.