QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgspoint3dsymbol_p.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspoint3dsymbol_p.cpp
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgspoint3dsymbol_p.h"
17 
18 #include <Qt3DRender/QAttribute>
19 #include <Qt3DRender/QBuffer>
20 #include <Qt3DRender/QEffect>
21 #include <Qt3DRender/QGraphicsApiFilter>
22 #include <Qt3DRender/QParameter>
23 #include <Qt3DRender/QTechnique>
24 
25 #include <Qt3DExtras/QCylinderGeometry>
26 #include <Qt3DExtras/QConeGeometry>
27 #include <Qt3DExtras/QCuboidGeometry>
28 #include <Qt3DExtras/QPlaneGeometry>
29 #include <Qt3DExtras/QSphereGeometry>
30 #include <Qt3DExtras/QTorusGeometry>
31 #include <Qt3DExtras/QPhongMaterial>
32 #include <Qt3DRender/QSceneLoader>
33 #include <Qt3DRender/QPaintedTextureImage>
34 
35 #include <Qt3DRender/QMesh>
36 
37 #if QT_VERSION >= 0x050900
38 #include <Qt3DExtras/QExtrudedTextGeometry>
39 #endif
40 
41 #include <QUrl>
42 #include <QVector3D>
43 
44 #include "qgspoint3dsymbol.h"
45 #include "qgs3dmapsettings.h"
46 
47 #include "qgsvectorlayer.h"
48 #include "qgspoint.h"
49 #include "qgs3dutils.h"
50 #include "qgsbillboardgeometry.h"
52 #include "qgslogger.h"
53 #include "qgssymbol.h"
54 #include "qgssymbollayerutils.h"
55 #include "qgssymbollayer.h"
56 
58 
59 
60 //* INSTANCED RENDERING *//
61 
62 
63 class QgsInstancedPoint3DSymbolHandler : public QgsFeature3DHandler
64 {
65  public:
66  QgsInstancedPoint3DSymbolHandler( const QgsPoint3DSymbol &symbol, const QgsFeatureIds &selectedIds )
67  : mSymbol( symbol ), mSelectedIds( selectedIds ) {}
68 
69  bool prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames ) override;
70  void processFeature( QgsFeature &feature, const Qgs3DRenderContext &context ) override;
71  void finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context ) override;
72 
73  private:
74 
75  static Qt3DRender::QMaterial *material( const QgsPoint3DSymbol &symbol );
76  static Qt3DRender::QGeometryRenderer *renderer( const QgsPoint3DSymbol &symbol, const QVector<QVector3D> &positions );
77  static Qt3DRender::QGeometry *symbolGeometry( QgsPoint3DSymbol::Shape shape, const QVariantMap &shapeProperties );
78 
80  struct PointData
81  {
82  QVector<QVector3D> positions; // contains triplets of float x,y,z for each point
83  };
84 
85  void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected );
86 
87  // input specific for this class
88  const QgsPoint3DSymbol &mSymbol;
89  // inputs - generic
90  QgsFeatureIds mSelectedIds;
91 
92  // outputs
93  PointData outNormal;
94  PointData outSelected;
95 };
96 
97 
98 bool QgsInstancedPoint3DSymbolHandler::prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames )
99 {
100  Q_UNUSED( context )
101  Q_UNUSED( attributeNames )
102  return true;
103 }
104 
105 void QgsInstancedPoint3DSymbolHandler::processFeature( QgsFeature &feature, const Qgs3DRenderContext &context )
106 {
107  PointData &out = mSelectedIds.contains( feature.id() ) ? outSelected : outNormal;
108 
109  if ( feature.geometry().isNull() )
110  return;
111 
112  Qgs3DUtils::extractPointPositions( feature, context.map(), mSymbol.altitudeClamping(), out.positions );
113 }
114 
115 void QgsInstancedPoint3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context )
116 {
117  makeEntity( parent, context, outNormal, false );
118  makeEntity( parent, context, outSelected, true );
119 }
120 
121 void QgsInstancedPoint3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected )
122 {
123  // build the default material
124  Qt3DRender::QMaterial *mat = material( mSymbol );
125 
126  if ( selected )
127  {
128  // update the material with selection colors
129  for ( Qt3DRender::QParameter *param : mat->effect()->parameters() )
130  {
131  if ( param->name() == QLatin1String( "kd" ) ) // diffuse
132  param->setValue( context.map().selectionColor() );
133  else if ( param->name() == QLatin1String( "ka" ) ) // ambient
134  param->setValue( context.map().selectionColor().darker() );
135  }
136  }
137 
138  // build the entity
139  Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
140  entity->addComponent( renderer( mSymbol, out.positions ) );
141  entity->addComponent( mat );
142  entity->setParent( parent );
143 }
144 
145 
146 
147 Qt3DRender::QMaterial *QgsInstancedPoint3DSymbolHandler::material( const QgsPoint3DSymbol &symbol )
148 {
149  Qt3DRender::QFilterKey *filterKey = new Qt3DRender::QFilterKey;
150  filterKey->setName( QStringLiteral( "renderingStyle" ) );
151  filterKey->setValue( "forward" );
152 
153  // the fragment shader implements a simplified version of phong shading that uses hardcoded light
154  // (instead of whatever light we have defined in the scene)
155  // TODO: use phong shading that respects lights from the scene
156  Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram;
157  shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/instanced.vert" ) ) ) );
158  shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/instanced.frag" ) ) ) );
159 
160  Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass;
161  renderPass->setShaderProgram( shaderProgram );
162 
163  Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique;
164  technique->addFilterKey( filterKey );
165  technique->addRenderPass( renderPass );
166  technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
167  technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
168  technique->graphicsApiFilter()->setMajorVersion( 3 );
169  technique->graphicsApiFilter()->setMinorVersion( 2 );
170 
171  Qt3DRender::QParameter *ambientParameter = new Qt3DRender::QParameter( QStringLiteral( "ka" ), QColor::fromRgbF( 0.05f, 0.05f, 0.05f, 1.0f ) );
172  Qt3DRender::QParameter *diffuseParameter = new Qt3DRender::QParameter( QStringLiteral( "kd" ), QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) );
173  Qt3DRender::QParameter *specularParameter = new Qt3DRender::QParameter( QStringLiteral( "ks" ), QColor::fromRgbF( 0.01f, 0.01f, 0.01f, 1.0f ) );
174  Qt3DRender::QParameter *shininessParameter = new Qt3DRender::QParameter( QStringLiteral( "shininess" ), 150.0f );
175 
176  diffuseParameter->setValue( symbol.material().diffuse() );
177  ambientParameter->setValue( symbol.material().ambient() );
178  specularParameter->setValue( symbol.material().specular() );
179  shininessParameter->setValue( symbol.material().shininess() );
180 
181  QMatrix4x4 transformMatrix = symbol.transform();
182  QMatrix3x3 normalMatrix = transformMatrix.normalMatrix(); // transponed inverse of 3x3 sub-matrix
183 
184  // QMatrix3x3 is not supported for passing to shaders, so we pass QMatrix4x4
185  float *n = normalMatrix.data();
186  QMatrix4x4 normalMatrix4(
187  n[0], n[3], n[6], 0,
188  n[1], n[4], n[7], 0,
189  n[2], n[5], n[8], 0,
190  0, 0, 0, 0 );
191 
192  Qt3DRender::QParameter *paramInst = new Qt3DRender::QParameter;
193  paramInst->setName( QStringLiteral( "inst" ) );
194  paramInst->setValue( transformMatrix );
195 
196  Qt3DRender::QParameter *paramInstNormal = new Qt3DRender::QParameter;
197  paramInstNormal->setName( QStringLiteral( "instNormal" ) );
198  paramInstNormal->setValue( normalMatrix4 );
199 
200  Qt3DRender::QEffect *effect = new Qt3DRender::QEffect;
201  effect->addTechnique( technique );
202  effect->addParameter( paramInst );
203  effect->addParameter( paramInstNormal );
204 
205  effect->addParameter( ambientParameter );
206  effect->addParameter( diffuseParameter );
207  effect->addParameter( specularParameter );
208  effect->addParameter( shininessParameter );
209 
210  Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial;
211  material->setEffect( effect );
212 
213  return material;
214 }
215 
216 Qt3DRender::QGeometryRenderer *QgsInstancedPoint3DSymbolHandler::renderer( const QgsPoint3DSymbol &symbol, const QVector<QVector3D> &positions )
217 {
218  int count = positions.count();
219  int byteCount = positions.count() * sizeof( QVector3D );
220  QByteArray ba;
221  ba.resize( byteCount );
222  memcpy( ba.data(), positions.constData(), byteCount );
223 
224  Qt3DRender::QBuffer *instanceBuffer = new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer );
225  instanceBuffer->setData( ba );
226 
227  Qt3DRender::QAttribute *instanceDataAttribute = new Qt3DRender::QAttribute;
228  instanceDataAttribute->setName( QStringLiteral( "pos" ) );
229  instanceDataAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
230  instanceDataAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
231  instanceDataAttribute->setVertexSize( 3 );
232  instanceDataAttribute->setDivisor( 1 );
233  instanceDataAttribute->setBuffer( instanceBuffer );
234  instanceDataAttribute->setCount( count );
235  instanceDataAttribute->setByteStride( 3 * sizeof( float ) );
236 
237  Qt3DRender::QGeometry *geometry = symbolGeometry( symbol.shape(), symbol.shapeProperties() );
238  geometry->addAttribute( instanceDataAttribute );
239  geometry->setBoundingVolumePositionAttribute( instanceDataAttribute );
240 
241  Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer;
242  renderer->setGeometry( geometry );
243  renderer->setInstanceCount( count );
244 
245  return renderer;
246 }
247 
248 Qt3DRender::QGeometry *QgsInstancedPoint3DSymbolHandler::symbolGeometry( QgsPoint3DSymbol::Shape shape, const QVariantMap &shapeProperties )
249 {
250  switch ( shape )
251  {
253  {
254  float radius = shapeProperties[QStringLiteral( "radius" )].toFloat();
255  float length = shapeProperties[QStringLiteral( "length" )].toFloat();
256  Qt3DExtras::QCylinderGeometry *g = new Qt3DExtras::QCylinderGeometry;
257  //g->setRings(2); // how many vertices vertically
258  //g->setSlices(8); // how many vertices on circumference
259  g->setRadius( radius ? radius : 10 );
260  g->setLength( length ? length : 10 );
261  return g;
262  }
263 
265  {
266  float radius = shapeProperties[QStringLiteral( "radius" )].toFloat();
267  Qt3DExtras::QSphereGeometry *g = new Qt3DExtras::QSphereGeometry;
268  g->setRadius( radius ? radius : 10 );
269  return g;
270  }
271 
273  {
274  float length = shapeProperties[QStringLiteral( "length" )].toFloat();
275  float bottomRadius = shapeProperties[QStringLiteral( "bottomRadius" )].toFloat();
276  float topRadius = shapeProperties[QStringLiteral( "topRadius" )].toFloat();
277  Qt3DExtras::QConeGeometry *g = new Qt3DExtras::QConeGeometry;
278  g->setLength( length ? length : 10 );
279  g->setBottomRadius( bottomRadius );
280  g->setTopRadius( topRadius );
281  //g->setHasBottomEndcap(hasBottomEndcap);
282  //g->setHasTopEndcap(hasTopEndcap);
283  return g;
284  }
285 
287  {
288  float size = shapeProperties[QStringLiteral( "size" )].toFloat();
289  Qt3DExtras::QCuboidGeometry *g = new Qt3DExtras::QCuboidGeometry;
290  g->setXExtent( size ? size : 10 );
291  g->setYExtent( size ? size : 10 );
292  g->setZExtent( size ? size : 10 );
293  return g;
294  }
295 
297  {
298  float radius = shapeProperties[QStringLiteral( "radius" )].toFloat();
299  float minorRadius = shapeProperties[QStringLiteral( "minorRadius" )].toFloat();
300  Qt3DExtras::QTorusGeometry *g = new Qt3DExtras::QTorusGeometry;
301  g->setRadius( radius ? radius : 10 );
302  g->setMinorRadius( minorRadius ? minorRadius : 5 );
303  return g;
304  }
305 
307  {
308  float size = shapeProperties[QStringLiteral( "size" )].toFloat();
309  Qt3DExtras::QPlaneGeometry *g = new Qt3DExtras::QPlaneGeometry;
310  g->setWidth( size ? size : 10 );
311  g->setHeight( size ? size : 10 );
312  return g;
313  }
314 
315 #if QT_VERSION >= 0x050900
317  {
318  float depth = shapeProperties[QStringLiteral( "depth" )].toFloat();
319  QString text = shapeProperties[QStringLiteral( "text" )].toString();
320  Qt3DExtras::QExtrudedTextGeometry *g = new Qt3DExtras::QExtrudedTextGeometry;
321  g->setDepth( depth ? depth : 1 );
322  g->setText( text );
323  return g;
324  }
325 #endif
326 
327  default:
328  Q_ASSERT( false );
329  return nullptr;
330  }
331 }
332 
333 //* 3D MODEL RENDERING *//
334 
335 
336 class QgsModelPoint3DSymbolHandler : public QgsFeature3DHandler
337 {
338  public:
339  QgsModelPoint3DSymbolHandler( const QgsPoint3DSymbol &symbol, const QgsFeatureIds &selectedIds )
340  : mSymbol( symbol ), mSelectedIds( selectedIds ) {}
341 
342  bool prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames ) override;
343  void processFeature( QgsFeature &feature, const Qgs3DRenderContext &context ) override;
344  void finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context ) override;
345 
346  private:
347 
348  static void addSceneEntities( const Qgs3DMapSettings &map, const QVector<QVector3D> &positions, const QgsPoint3DSymbol &symbol, Qt3DCore::QEntity *parent );
349  static void addMeshEntities( const Qgs3DMapSettings &map, const QVector<QVector3D> &positions, const QgsPoint3DSymbol &symbol, Qt3DCore::QEntity *parent, bool are_selected );
350  static Qt3DCore::QTransform *transform( QVector3D position, const QgsPoint3DSymbol &symbol );
351 
353  struct PointData
354  {
355  QVector<QVector3D> positions; // contains triplets of float x,y,z for each point
356  };
357 
358  void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected );
359 
360  // input specific for this class
361  const QgsPoint3DSymbol &mSymbol;
362  // inputs - generic
363  QgsFeatureIds mSelectedIds;
364 
365  // outputs
366  PointData outNormal;
367  PointData outSelected;
368 };
369 
370 bool QgsModelPoint3DSymbolHandler::prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames )
371 {
372  Q_UNUSED( context )
373  Q_UNUSED( attributeNames )
374  return true;
375 }
376 
377 void QgsModelPoint3DSymbolHandler::processFeature( QgsFeature &feature, const Qgs3DRenderContext &context )
378 {
379  PointData &out = mSelectedIds.contains( feature.id() ) ? outSelected : outNormal;
380 
381  if ( feature.geometry().isNull() )
382  return;
383 
384  Qgs3DUtils::extractPointPositions( feature, context.map(), mSymbol.altitudeClamping(), out.positions );
385 }
386 
387 void QgsModelPoint3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context )
388 {
389  makeEntity( parent, context, outNormal, false );
390  makeEntity( parent, context, outSelected, true );
391 }
392 
393 void QgsModelPoint3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected )
394 {
395  if ( selected )
396  {
397  addMeshEntities( context.map(), out.positions, mSymbol, parent, true );
398  }
399  else
400  {
401  if ( mSymbol.shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool() )
402  {
403  addMeshEntities( context.map(), out.positions, mSymbol, parent, false );
404  }
405  else
406  {
407  addSceneEntities( context.map(), out.positions, mSymbol, parent );
408  }
409  }
410 }
411 
412 
413 
414 void QgsModelPoint3DSymbolHandler::addSceneEntities( const Qgs3DMapSettings &map, const QVector<QVector3D> &positions, const QgsPoint3DSymbol &symbol, Qt3DCore::QEntity *parent )
415 {
416  Q_UNUSED( map )
417  for ( const QVector3D &position : positions )
418  {
419  // build the entity
420  Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
421 
422  QUrl url = QUrl::fromLocalFile( symbol.shapeProperties()[QStringLiteral( "model" )].toString() );
423  Qt3DRender::QSceneLoader *modelLoader = new Qt3DRender::QSceneLoader;
424  modelLoader->setSource( url );
425 
426  entity->addComponent( modelLoader );
427  entity->addComponent( transform( position, symbol ) );
428  entity->setParent( parent );
429  }
430 }
431 
432 void QgsModelPoint3DSymbolHandler::addMeshEntities( const Qgs3DMapSettings &map, const QVector<QVector3D> &positions, const QgsPoint3DSymbol &symbol, Qt3DCore::QEntity *parent, bool are_selected )
433 {
434  // build the default material
435  Qt3DExtras::QPhongMaterial *mat = Qgs3DUtils::phongMaterial( symbol.material() );
436 
437  if ( are_selected )
438  {
439  mat->setDiffuse( map.selectionColor() );
440  mat->setAmbient( map.selectionColor().darker() );
441  }
442 
443  // get nodes
444  for ( const QVector3D &position : positions )
445  {
446  // build the entity
447  Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
448 
449  QUrl url = QUrl::fromLocalFile( symbol.shapeProperties()[QStringLiteral( "model" )].toString() );
450  Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh;
451  mesh->setSource( url );
452 
453  entity->addComponent( mesh );
454  entity->addComponent( mat );
455  entity->addComponent( transform( position, symbol ) );
456  entity->setParent( parent );
457  }
458 }
459 
460 Qt3DCore::QTransform *QgsModelPoint3DSymbolHandler::transform( QVector3D position, const QgsPoint3DSymbol &symbol )
461 {
462  Qt3DCore::QTransform *tr = new Qt3DCore::QTransform;
463  tr->setMatrix( symbol.transform() );
464  tr->setTranslation( position + tr->translation() );
465  return tr;
466 }
467 
468 // --------------
469 
470 //* BILLBOARD RENDERING *//
471 
472 class QgsPoint3DBillboardSymbolHandler : public QgsFeature3DHandler
473 {
474  public:
475  QgsPoint3DBillboardSymbolHandler( const QgsPoint3DSymbol &symbol, const QgsFeatureIds &selectedIds )
476  : mSymbol( symbol ), mSelectedIds( selectedIds ) {}
477 
478  bool prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames ) override;
479  void processFeature( QgsFeature &feature, const Qgs3DRenderContext &context ) override;
480  void finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context ) override;
481 
482  private:
483 
485  struct PointData
486  {
487  QVector<QVector3D> positions; // contains triplets of float x,y,z for each point
488  };
489 
490  void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected );
491 
492  // input specific for this class
493  const QgsPoint3DSymbol &mSymbol;
494  // inputs - generic
495  QgsFeatureIds mSelectedIds;
496 
497  // outputs
498  PointData outNormal;
499  PointData outSelected;
500 };
501 
502 bool QgsPoint3DBillboardSymbolHandler::prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames )
503 {
504  Q_UNUSED( context )
505  Q_UNUSED( attributeNames )
506  return true;
507 }
508 
509 void QgsPoint3DBillboardSymbolHandler::processFeature( QgsFeature &feature, const Qgs3DRenderContext &context )
510 {
511  PointData &out = mSelectedIds.contains( feature.id() ) ? outSelected : outNormal;
512 
513  if ( feature.geometry().isNull() )
514  return;
515 
516  Qgs3DUtils::extractPointPositions( feature, context.map(), mSymbol.altitudeClamping(), out.positions );
517 }
518 
519 void QgsPoint3DBillboardSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context )
520 {
521  makeEntity( parent, context, outNormal, false );
522  makeEntity( parent, context, outSelected, true );
523 }
524 
525 void QgsPoint3DBillboardSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected )
526 {
527  // Billboard Geometry
528  QgsBillboardGeometry *billboardGeometry = new QgsBillboardGeometry();
529  billboardGeometry->setPoints( out.positions );
530 
531  // Billboard Geometry Renderer
532  Qt3DRender::QGeometryRenderer *billboardGeometryRenderer = new Qt3DRender::QGeometryRenderer;
533  billboardGeometryRenderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::Points );
534  billboardGeometryRenderer->setGeometry( billboardGeometry );
535  billboardGeometryRenderer->setVertexCount( billboardGeometry->count() );
536 
537  // Billboard Material
538  QgsPoint3DBillboardMaterial *billboardMaterial = new QgsPoint3DBillboardMaterial();
539  QgsMarkerSymbol *symbol = mSymbol.billboardSymbol();
540 
541  if ( symbol )
542  {
543  billboardMaterial->setTexture2DFromSymbol( symbol, context.map(), selected );
544  }
545  else
546  {
547  billboardMaterial->useDefaultSymbol( context.map(), selected );
548  }
549 
550  // Billboard Transform
551  Qt3DCore::QTransform *billboardTransform = new Qt3DCore::QTransform();
552  billboardTransform->setMatrix( mSymbol.billboardTransform() );
553 
554  // Build the entity
555  Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
556 
557  entity->addComponent( billboardMaterial );
558  entity->addComponent( billboardTransform );
559  entity->addComponent( billboardGeometryRenderer );
560  entity->setParent( parent );
561 }
562 
563 
564 namespace Qgs3DSymbolImpl
565 {
566 
567  QgsFeature3DHandler *handlerForPoint3DSymbol( QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol )
568  {
569  if ( symbol.shape() == QgsPoint3DSymbol::Model )
570  return new QgsModelPoint3DSymbolHandler( symbol, layer->selectedFeatureIds() );
571  // Add proper handler for billboard
572  else if ( symbol.shape() == QgsPoint3DSymbol::Billboard )
573  return new QgsPoint3DBillboardSymbolHandler( symbol, layer->selectedFeatureIds() );
574  else
575  return new QgsInstancedPoint3DSymbolHandler( symbol, layer->selectedFeatureIds() );
576  }
577 
578  Qt3DCore::QEntity *entityForPoint3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol )
579  {
580  QgsFeature3DHandler *handler = handlerForPoint3DSymbol( layer, symbol );
581  Qt3DCore::QEntity *e = entityFromHandler( handler, map, layer );
582  delete handler;
583  return e;
584  }
585 }
586 
3 Material of the billboard rendering for points in 3D map view.
QgsFeatureId id
Definition: qgsfeature.h:64
float shininess() const
Returns shininess of the surface.
void useDefaultSymbol(const Qgs3DMapSettings &map, bool selected=false)
Set default symbol for the texture with map and selected parameter for rendering. ...
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QColor selectionColor() const
Returns color used for selected features.
QColor specular() const
Returns specular color component.
static Qt3DExtras::QPhongMaterial * phongMaterial(const QgsPhongMaterialSettings &settings)
Returns phong material object based on the material settings.
Definition: qgs3dutils.cpp:490
Shape shape() const
Returns 3D shape for points.
3 Geometry of the billboard rendering for points in 3D map view.
QVariantMap shapeProperties() const
Returns a key-value dictionary of point shape properties.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Supported in Qt 5.9+.
3 Definition of the world
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:860
QMatrix4x4 transform() const
Returns transform for individual objects represented by the symbol.
void setTexture2DFromSymbol(QgsMarkerSymbol *markerSymbol, const Qgs3DMapSettings &map, bool selected=false)
Set markerSymbol for the texture with map and selected parameter for rendering.
static void extractPointPositions(QgsFeature &f, const Qgs3DMapSettings &map, Qgs3DTypes::AltitudeClamping altClamp, QVector< QVector3D > &positions)
Calculates (x,y,z) positions of (multi)point from the given feature.
Definition: qgs3dutils.cpp:346
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
3 3D symbol that draws point geometries as 3D objects using one of the predefined shapes...
QgsPhongMaterialSettings material() const
Returns material used for shading of the symbol.
QgsMarkerSymbol * billboardSymbol() const
Returns a symbol for billboard.
Shape
3D shape types supported by the symbol
void setPoints(const QVector< QVector3D > &vertices)
Set the points for the billboard with vertices.
QColor ambient() const
Returns ambient color component.
QColor diffuse() const
Returns diffuse color component.
QgsGeometry geometry
Definition: qgsfeature.h:67
Represents a vector layer which manages a vector based data sets.