23 #include <Qt3DCore/QTransform> 24 #include <Qt3DRender/QEffect> 25 #include <Qt3DRender/QTechnique> 26 #include <Qt3DRender/QCullFace> 46 Qt3DCore::QNode *parent )
50 Qt3DExtras::QPhongMaterial *mat =
material( symbol );
53 Qt3DCore::QTransform *tform =
new Qt3DCore::QTransform;
54 tform->setTranslation( QVector3D( 0, 0, 0 ) );
57 QgsMesh3DSymbolEntityNode *entity =
new QgsMesh3DSymbolEntityNode( map, layer, symbol );
58 entity->findChild<Qt3DRender::QGeometryRenderer *>()->setObjectName( QStringLiteral(
"main" ) );
59 entity->addComponent( mat );
60 entity->addComponent( tform );
61 entity->setParent(
this );
64 Qt3DExtras::QPhongMaterial *QgsMesh3DSymbolEntity::material(
const QgsMesh3DSymbol &symbol )
const 66 Qt3DExtras::QPhongMaterial *
material =
new Qt3DExtras::QPhongMaterial;
69 auto techniques = material->effect()->techniques();
70 for (
auto tit = techniques.constBegin(); tit != techniques.constEnd(); ++tit )
72 auto renderPasses = ( *tit )->renderPasses();
73 for (
auto rpit = renderPasses.begin(); rpit != renderPasses.end(); ++rpit )
75 Qt3DRender::QCullFace *cullFace =
new Qt3DRender::QCullFace;
76 cullFace->setMode( Qt3DRender::QCullFace::Back );
77 ( *rpit )->addRenderState( cullFace );
88 QgsMesh3DSymbolEntityNode::QgsMesh3DSymbolEntityNode(
const Qgs3DMapSettings &map,
91 Qt3DCore::QNode *parent ) :
Qt3DCore::QEntity( parent )
93 addComponent( renderer( map, symbol, layer ) );
96 Qt3DRender::QGeometryRenderer *QgsMesh3DSymbolEntityNode::renderer(
const Qgs3DMapSettings &map,
101 QList<QgsPolygon *> polygons;
102 QList<QgsFeatureId> fids;
112 static_cast<double>( height )
120 const QVector<QgsMeshFace> &triangles = mesh->
triangles();
121 const QVector<QgsMeshVertex> &vertices = mesh->
vertices();
122 for (
int i = 0; i < triangles.size(); ++i )
125 Q_ASSERT( triangle.size() == 3 );
129 Qgs3DTypes::AltitudeBinding::AltBindVertex,
132 polygons.append( polygon.release() );
143 QList<float> extrusionHeightPerPolygon;
144 mGeometry->setPolygons( polygons, fids, origin, 0.0, extrusionHeightPerPolygon );
146 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
147 renderer->setGeometry( mGeometry );
float shininess() const
Returns shininess of the surface.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
3 3D symbol that draws mesh geometry as planar triangles.
void setInvertNormals(bool invert)
Sets whether the normals of triangles will be inverted (useful for fixing clockwise / counter-clockwi...
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...
QColor specular() const
Returns specular color component.
A class to represent a 2D point.
float height() const
Returns height (altitude) of the symbol (in map units)
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
double y() const
Returns Y coordinate.
3 Definition of the world
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
bool addBackFaces() const
Returns whether also triangles facing the other side will be created.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
3 Class derived from Qt3DRender::QGeometry that represents polygons tessellated into 3D geometry...
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
QgsPhongMaterialSettings material() const
Returns material used for shading of the symbol.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QVector< int > QgsMeshFace
List of vertex indexes.
QColor ambient() const
Returns ambient color component.
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.
QColor diffuse() const
Returns diffuse color component.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Qgs3DTypes::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
void setAmbient(const QColor &ambient)
Sets ambient color component.
double x() const
Returns X coordinate.