23 #include <Qt3DCore/QTransform> 24 #include <Qt3DRender/QEffect> 25 #include <Qt3DRender/QTechnique> 26 #include <Qt3DRender/QCullFace> 54 addEntityForSelectedPolygons( map, layer, symbol );
55 addEntityForNotSelectedPolygons( map, layer, symbol );
61 Qt3DExtras::QPhongMaterial *mat =
material( symbol );
68 Qt3DCore::QTransform *tform =
new Qt3DCore::QTransform;
69 tform->setTranslation( QVector3D( 0, 0, 0 ) );
78 QgsPolygon3DSymbolEntityNode *entity =
new QgsPolygon3DSymbolEntityNode( map, layer, symbol, req );
79 entity->addComponent( mat );
80 entity->addComponent( tform );
81 entity->setParent(
this );
87 Qt3DExtras::QPhongMaterial *mat =
material( symbol );
90 Qt3DCore::QTransform *tform =
new Qt3DCore::QTransform;
91 tform->setTranslation( QVector3D( 0, 0, 0 ) );
103 QgsPolygon3DSymbolEntityNode *entity =
new QgsPolygon3DSymbolEntityNode( map, layer, symbol, req );
104 entity->findChild<Qt3DRender::QGeometryRenderer *>()->setObjectName( QStringLiteral(
"main" ) );
105 entity->addComponent( mat );
106 entity->addComponent( tform );
107 entity->setParent(
this );
119 return Qt3DRender::QCullFace::NoCulling;
122 Qt3DExtras::QPhongMaterial *QgsPolygon3DSymbolEntity::material(
const QgsPolygon3DSymbol &symbol )
const 124 Qt3DExtras::QPhongMaterial *
material =
new Qt3DExtras::QPhongMaterial;
127 auto techniques = material->effect()->techniques();
128 for (
auto tit = techniques.constBegin(); tit != techniques.constEnd(); ++tit )
130 auto renderPasses = ( *tit )->renderPasses();
131 for (
auto rpit = renderPasses.begin(); rpit != renderPasses.end(); ++rpit )
133 Qt3DRender::QCullFace *cullFace =
new Qt3DRender::QCullFace;
134 cullFace->setMode( _qt3DcullingMode( symbol.
cullingMode() ) );
135 ( *rpit )->addRenderState( cullFace );
149 addComponent( renderer( map, symbol, layer, req ) );
155 QList<QgsPolygon *> polygons;
156 QList<QgsFeatureId> fids;
157 QList<float> extrusionHeightPerPolygon;
186 if ( hasDDExtrusion )
189 if (
const QgsPolygon *poly = qgsgeometry_cast< const QgsPolygon *>( g ) )
193 polygons.append( polyClone );
194 fids.append( f.
id() );
195 if ( hasDDExtrusion )
196 extrusionHeightPerPolygon.append( extrusionHeight );
198 else if (
const QgsMultiPolygon *mpoly = qgsgeometry_cast< const QgsMultiPolygon *>( g ) )
200 for (
int i = 0; i < mpoly->numGeometries(); ++i )
206 polygons.append( polyClone );
207 fids.append( f.
id() );
208 if ( hasDDExtrusion )
209 extrusionHeightPerPolygon.append( extrusionHeight );
214 for (
int i = 0; i < gc->numGeometries(); ++i )
221 polygons.append( polyClone );
222 fids.append( f.
id() );
223 if ( hasDDExtrusion )
224 extrusionHeightPerPolygon.append( extrusionHeight );
228 qDebug() <<
"not a polygon";
234 mGeometry->setPolygons( polygons, fids, origin, symbol.
extrusionHeight(), extrusionHeightPerPolygon );
236 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
237 renderer->setGeometry( mGeometry );
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
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
void setInvertNormals(bool invert)
Sets whether the normals of triangles will be inverted (useful for fixing clockwise / counter-clockwi...
QgsPhongMaterialSettings material() const
Returns material used for shading of the symbol.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
A class to represent a 2D point.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
3 3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls)...
CullingMode
Triangle culling mode.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
Extrusion height (zero means no extrusion)
A geometry is the spatial representation of a feature.
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Will not render anything.
Qgs3DTypes::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
3 Definition of the world
QColor selectionColor() const
Returns color used for selected features.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool addBackFaces() const
Returns whether also triangles facing the other side will be created.
Qgs3DTypes::CullingMode cullingMode() const
Returns front/back culling mode.
Will render only front faces of triangles (recommended when input data are consistent) ...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double x() const
Returns X coordinate.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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.
Will render only back faces of triangles.
Will render both front and back faces of triangles.
bool invertNormals() const
Returns whether the normals of triangles will be inverted (useful for fixing clockwise / counter-cloc...
Qgs3DTypes::AltitudeBinding altitudeBinding() const
Returns method that determines how altitude is bound to individual vertices.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
float height() const
Returns height (altitude) of the symbol (in map units)
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)...
float extrusionHeight() const
Returns extrusion height (in map units)
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Abstract base class for all geometries.
double y() const
Returns Y coordinate.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QColor ambient() const
Returns ambient color component.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
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)
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsPolygon * clone() const override
Clones the geometry by performing a deep copy.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
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.
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
static Type flatType(Type type)
Returns the flat type for a WKB type.
void setAmbient(const QColor &ambient)
Sets ambient color component.
QColor diffuse() const
Returns diffuse color component.