20#include <QDomDocument> 
   22#include <Qt3DCore/QEntity> 
   23#include <Qt3DRender/QPointLight> 
   24#include <Qt3DExtras/QPhongMaterial> 
   25#include <Qt3DExtras/QSphereMesh> 
   39  Qt3DCore::QEntity *lightEntity = 
new Qt3DCore::QEntity();
 
   40  Qt3DCore::QTransform *lightTransform = 
new Qt3DCore::QTransform;
 
   41  lightTransform->setTranslation( QVector3D( 
position().x(),
 
   45  Qt3DRender::QPointLight *light = 
new Qt3DRender::QPointLight;
 
   46  light->setColor( 
color() );
 
   53  lightEntity->addComponent( light );
 
   54  lightEntity->addComponent( lightTransform );
 
   58    lightEntity->setParent( parent );
 
   63    Qt3DCore::QEntity *originEntity = 
new Qt3DCore::QEntity();
 
   65    Qt3DCore::QTransform *trLightOriginCenter = 
new Qt3DCore::QTransform;
 
   66    trLightOriginCenter->setTranslation( lightTransform->translation() );
 
   67    originEntity->addComponent( trLightOriginCenter );
 
   69    Qt3DExtras::QPhongMaterial *materialLightOriginCenter = 
new Qt3DExtras::QPhongMaterial;
 
   70    materialLightOriginCenter->setAmbient( 
color() );
 
   71    originEntity->addComponent( materialLightOriginCenter );
 
   73    Qt3DExtras::QSphereMesh *rendererLightOriginCenter = 
new Qt3DExtras::QSphereMesh;
 
   74    rendererLightOriginCenter->setRadius( 20 );
 
   75    originEntity->addComponent( rendererLightOriginCenter );
 
   77    originEntity->setEnabled( 
true );
 
   79    Qt3DCore::QEntity *groupEntity = 
new Qt3DCore::QEntity( parent );
 
   80    lightEntity->setParent( groupEntity );
 
   81    originEntity->setParent( groupEntity );
 
   82    groupEntity->setEnabled( 
true );
 
   89  QDomElement elemLight = doc.createElement( QStringLiteral( 
"point-light" ) );
 
   90  elemLight.setAttribute( QStringLiteral( 
"x" ), mPosition.
x() );
 
   91  elemLight.setAttribute( QStringLiteral( 
"y" ), mPosition.
y() );
 
   92  elemLight.setAttribute( QStringLiteral( 
"z" ), mPosition.
z() );
 
   94  elemLight.setAttribute( QStringLiteral( 
"intensity" ), mIntensity );
 
   95  elemLight.setAttribute( QStringLiteral( 
"attenuation-0" ), mConstantAttenuation );
 
   96  elemLight.setAttribute( QStringLiteral( 
"attenuation-1" ), mLinearAttenuation );
 
   97  elemLight.setAttribute( QStringLiteral( 
"attenuation-2" ), mQuadraticAttenuation );
 
  103  mPosition.
set( elem.attribute( QStringLiteral( 
"x" ) ).toDouble(),
 
  104                 elem.attribute( QStringLiteral( 
"y" ) ).toDouble(),
 
  105                 elem.attribute( QStringLiteral( 
"z" ) ).toDouble() );
 
  107  mIntensity = elem.attribute( QStringLiteral( 
"intensity" ) ).toFloat();
 
  108  mConstantAttenuation = elem.attribute( QStringLiteral( 
"attenuation-0" ) ).toDouble();
 
  109  mLinearAttenuation = elem.attribute( QStringLiteral( 
"attenuation-1" ) ).toDouble();
 
  110  mQuadraticAttenuation = elem.attribute( QStringLiteral( 
"attenuation-2" ) ).toDouble();
 
  115  return mPosition == other.mPosition && mColor == other.mColor && mIntensity == other.mIntensity &&
 
  116         mConstantAttenuation == other.mConstantAttenuation && mLinearAttenuation == other.mLinearAttenuation &&
 
  117         mQuadraticAttenuation == other.mQuadraticAttenuation;
 
LightSourceType
Light source types for 3D scenes.
 
@ Point
Point light source.
 
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
 
QgsPointLightSettings()=default
Construct a point light with default values.
 
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const override
Writes the light source's configuration to a new DOM element and returns it.
 
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map, Qt3DCore::QEntity *parent) const override
Creates an entity representing the light source.
 
float quadraticAttenuation() const
Returns quadratic attenuation (A_2)
 
QgsPointLightSettings * clone() const override
Returns a copy of the light source.
 
float linearAttenuation() const
Returns linear attenuation (A_1)
 
float intensity() const
Returns intensity of the light.
 
Qgis::LightSourceType type() const override
Returns the light source type.
 
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext()) override
Reads configuration from a DOM element previously written using writeXml().
 
QgsVector3D position() const
Returns position of the light (in 3D world coordinates)
 
float constantAttenuation() const
Returns constant attenuation (A_0)
 
bool operator==(const QgsPointLightSettings &other)
 
QColor color() const
Returns color of the light.
 
The class is used as a container of context for various read/write operations on other objects.
 
static QColor decodeColor(const QString &str)
 
static QString encodeColor(const QColor &color)
 
double y() const
Returns Y coordinate.
 
double z() const
Returns Z coordinate.
 
double x() const
Returns X coordinate.
 
void set(double x, double y, double z)
Sets vector coordinates.