29 #include <Qt3DRender/QAttribute> 30 #include <Qt3DRender/QBuffer> 37 addEntityForSelectedLines( map, layer, symbol );
38 addEntityForNotSelectedLines( map, layer, symbol );
41 Qt3DExtras::QPhongMaterial *QgsLine3DSymbolEntity::material(
const QgsLine3DSymbol &symbol )
const 43 Qt3DExtras::QPhongMaterial *
material =
new Qt3DExtras::QPhongMaterial;
56 Qt3DExtras::QPhongMaterial *mat =
material( symbol );
68 QgsLine3DSymbolEntityNode *entity =
new QgsLine3DSymbolEntityNode( map, layer, symbol, req );
69 entity->addComponent( mat );
70 entity->setParent(
this );
76 Qt3DExtras::QPhongMaterial *mat =
material( symbol );
87 QgsLine3DSymbolEntityNode *entity =
new QgsLine3DSymbolEntityNode( map, layer, symbol, req );
88 entity->findChild<Qt3DRender::QGeometryRenderer *>()->setObjectName( QStringLiteral(
"main" ) );
89 entity->addComponent( mat );
90 entity->setParent(
this );
96 addComponent( symbol.
renderAsSimpleLines() ? rendererSimple( map, symbol, layer, req ) : renderer( map, symbol, layer, req ) );
107 double mitreLimit = 0;
109 QList<QgsPolygon *> polygons;
110 QList<QgsFeatureId> fids;
127 QgsAbstractGeometry *buffered = engine.buffer( symbol.
width() / 2., nSegments, endCapStyle, joinStyle, mitreLimit );
133 polygons.append( polyBuffered );
134 fids.append( f.
id() );
145 polygons.append( polyBuffered );
146 fids.append( f.
id() );
155 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
156 renderer->setGeometry( mGeometry );
164 QVector<QVector3D> vertices;
165 vertices << QVector3D();
166 QVector<unsigned int> indexes;
174 if ( f.geometry().isNull() )
178 centroid =
QgsPoint( f.geometry().centroid().asPoint() );
182 if (
const QgsLineString *ls = qgsgeometry_cast<const QgsLineString *>( g ) )
184 for (
int i = 0; i < ls->vertexCount(); ++i )
188 vertices << QVector3D( p.
x() - map.
origin().
x(), z, -( p.
y() - map.
origin().
y() ) );
189 indexes << vertices.count() - 1;
192 else if (
const QgsMultiLineString *mls = qgsgeometry_cast<const QgsMultiLineString *>( g ) )
194 for (
int nGeom = 0; nGeom < mls->numGeometries(); ++nGeom )
201 vertices << QVector3D( p.
x() - map.
origin().
x(), z, -( p.
y() - map.
origin().
y() ) );
202 indexes << vertices.count() - 1;
211 QByteArray vertexBufferData;
212 vertexBufferData.resize( vertices.size() * 3 *
sizeof( float ) );
213 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
215 for (
const auto &v : qgis::as_const( vertices ) )
217 rawVertexArray[idx++] = v.x();
218 rawVertexArray[idx++] = v.y();
219 rawVertexArray[idx++] = v.z();
222 QByteArray indexBufferData;
223 indexBufferData.resize( indexes.size() *
sizeof( int ) );
224 unsigned int *rawIndexArray =
reinterpret_cast<unsigned int *
>( indexBufferData.data() );
226 for (
unsigned int indexVal : qgis::as_const( indexes ) )
228 rawIndexArray[idx++] = indexVal;
231 Qt3DRender::QBuffer *vertexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer,
this );
232 vertexBuffer->setData( vertexBufferData );
234 Qt3DRender::QBuffer *indexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::IndexBuffer,
this );
235 indexBuffer->setData( indexBufferData );
237 Qt3DRender::QAttribute *positionAttribute =
new Qt3DRender::QAttribute(
this );
238 positionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
239 positionAttribute->setBuffer( vertexBuffer );
240 positionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
241 positionAttribute->setVertexSize( 3 );
242 positionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
244 Qt3DRender::QAttribute *indexAttribute =
new Qt3DRender::QAttribute(
this );
245 indexAttribute->setAttributeType( Qt3DRender::QAttribute::IndexAttribute );
246 indexAttribute->setBuffer( indexBuffer );
247 indexAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedInt );
249 Qt3DRender::QGeometry *geom =
new Qt3DRender::QGeometry;
250 geom->addAttribute( positionAttribute );
251 geom->addAttribute( indexAttribute );
253 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
254 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::LineStrip );
255 renderer->setGeometry( geom );
256 renderer->setVertexCount( vertices.count() );
257 renderer->setPrimitiveRestartEnabled(
true );
258 renderer->setRestartIndexValue( 0 );
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
Wrapper for iterator of features from vector data provider or vector layer.
float shininess() const
Returns shininess of the surface.
QSet< QgsFeatureId > QgsFeatureIds
float height() const
Returns height (altitude) of the symbol (in map units)
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
void setPolygons(const QList< QgsPolygon * > &polygons, const QList< QgsFeatureId > &featureIds, const QgsPointXY &origin, float extrusionHeight, const QList< float > &extrusionHeightPerPolygon=QList< float >())
Initializes vertex buffer from given polygons. Takes ownership of passed polygon geometries.
float width() const
Returns width of the line symbol (in map units)
A class to represent a 2D point.
Qgs3DTypes::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Multi line string geometry collection.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
bool renderAsSimpleLines() const
Returns whether the renderer will render data with simple lines (otherwise it uses buffer) ...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
EndCapStyle
End cap styles for buffers.
3 Definition of the world
QColor selectionColor() const
Returns color used for selected features.
QgsPhongMaterialSettings material() const
Returns material used for shading of the symbol.
float extrusionHeight() const
Returns extrusion height (in map units)
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
double x() const
Returns X coordinate.
QColor specular() const
Returns specular color component.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
3 Class derived from Qt3DRender::QGeometry that represents polygons tessellated into 3D geometry...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
static float clampAltitude(const QgsPoint &p, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, float height, const QgsPoint ¢roid, const Qgs3DMapSettings &map)
Clamps altitude of a vertex according to the settings, returns Z value.
3 3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer wi...
int numGeometries() const
Returns the number of geometries within the collection.
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Abstract base class for all geometries.
Does vector analysis using the geos library and handles import, export, exception handling*...
Point geometry type, with support for z-dimension and m-values.
double y() const
Returns Y coordinate.
Qgs3DTypes::AltitudeBinding altitudeBinding() const
Returns method that determines how altitude is bound to individual vertices.
QColor ambient() const
Returns ambient color component.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
Multi polygon geometry collection.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Line string geometry type, with support for z-dimension and m-values.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
static void clampAltitudes(QgsLineString *lineString, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, const QgsPoint ¢roid, float height, const Qgs3DMapSettings &map)
Clamps altitude of vertices of a linestring according to the settings.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
bool nextFeature(QgsFeature &f)
JoinStyle
Join styles for buffers.
Represents a vector layer which manages a vector based data sets.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Clamp just centroid of feature.
void setAmbient(const QColor &ambient)
Sets ambient color component.
QColor diffuse() const
Returns diffuse color component.