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 );
83 Qt3DCore::QTransform *lineTransform =
new Qt3DCore::QTransform;
84 mLineEntity->addComponent( lineTransform );
87 mMarkerEntity =
new Qt3DCore::QEntity( parentEntity );
89 mMarkerGeometryRenderer =
new Qt3DRender::QGeometryRenderer;
90 mMarkerGeometryRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
91 mMarkerGeometryRenderer->setGeometry( mMarkerGeometry );
92 mMarkerGeometryRenderer->setVertexCount( mMarkerGeometry->count() );
94 const QVariantMap props
96 {QStringLiteral(
"color" ), QStringLiteral(
"red" ) },
97 {QStringLiteral(
"size" ), 6 },
98 {QStringLiteral(
"outline_color" ), QStringLiteral(
"green" ) },
99 {QStringLiteral(
"outline_width" ), 0.5 }
103 updateMarkerMaterial();
104 mMarkerEntity->addComponent( mMarkerGeometryRenderer );
106 Qt3DCore::QTransform *markerTransform =
new Qt3DCore::QTransform;
107 mMarkerEntity->addComponent( markerTransform );
110QgsRubberBand3D::~QgsRubberBand3D()
113 delete mMarkerEntity;
114 delete mMarkerSymbol;
117float QgsRubberBand3D::width()
const
119 return mLineMaterial->lineWidth();
122void QgsRubberBand3D::setWidth(
float width )
124 mLineMaterial->setLineWidth( width );
125 mMarkerSymbol->setSize( width );
126 updateMarkerMaterial();
129QColor QgsRubberBand3D::color()
const
131 return mLineMaterial->lineColor();
134void QgsRubberBand3D::setColor( QColor color )
136 mLineMaterial->setLineColor( color );
137 mMarkerSymbol->setColor( color.lighter( 130 ) );
138 if ( mMarkerSymbol->symbolLayerCount() > 0 && mMarkerSymbol->symbolLayer( 0 )->layerType() == QLatin1String(
"SimpleMarker" ) )
140 static_cast<QgsMarkerSymbolLayer *
>( mMarkerSymbol->symbolLayer( 0 ) )->setStrokeColor( color );
142 updateMarkerMaterial();
145void QgsRubberBand3D::reset()
148 mShowLastMarker =
false;
152void QgsRubberBand3D::addPoint(
const QgsPoint &pt )
154 mLineString.addVertex( pt );
158void QgsRubberBand3D::removeLastPoint()
160 const int lastVertexIndex = mLineString.numPoints() - 1;
161 mLineString.deleteVertex(
QgsVertexId( 0, 0, lastVertexIndex ) );
165void QgsRubberBand3D::moveLastPoint(
const QgsPoint &pt )
167 const int lastVertexIndex = mLineString.numPoints() - 1;
168 mLineString.moveVertex(
QgsVertexId( 0, 0, lastVertexIndex ), pt );
172void QgsRubberBand3D::updateGeometry()
174 QgsLineVertexData lineData;
175 lineData.withAdjacency =
true;
177 lineData.addLineString( mLineString );
179 mPositionAttribute->buffer()->setData( lineData.createVertexBuffer() );
180 mIndexAttribute->buffer()->setData( lineData.createIndexBuffer() );
181 mGeomRenderer->setVertexCount( lineData.indexes.count() );
184 lineData.vertices.pop_front();
187 if ( !mShowLastMarker && !lineData.vertices.isEmpty() )
188 lineData.vertices.pop_back();
190 mMarkerGeometry->setPoints( lineData.vertices );
191 mMarkerGeometryRenderer->setVertexCount( lineData.vertices.count() );
194void QgsRubberBand3D::updateMarkerMaterial()
196 delete mMarkerMaterial;
199 mMarkerEntity->addComponent( mMarkerMaterial );
204 mMarkerMaterial->setViewportSize( mEngine->size() );
206 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.
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.