21#include <QDomDocument> 
   23#include <Qt3DCore/QEntity> 
   24#include <Qt3DRender/QPointLight> 
   25#include <Qt3DExtras/QPhongMaterial> 
   26#include <Qt3DExtras/QSphereMesh> 
   40  Qt3DCore::QEntity *lightEntity = 
new Qt3DCore::QEntity();
 
   41  Qt3DCore::QTransform *lightTransform = 
new Qt3DCore::QTransform;
 
   42  lightTransform->setTranslation( 
position().toVector3D() );
 
   44  Qt3DRender::QPointLight *light = 
new Qt3DRender::QPointLight;
 
   45  light->setColor( 
color() );
 
   52  lightEntity->addComponent( light );
 
   53  lightEntity->addComponent( lightTransform );
 
   57    lightEntity->setParent( parent );
 
   62    Qt3DCore::QEntity *originEntity = 
new Qt3DCore::QEntity();
 
   64    Qt3DCore::QTransform *trLightOriginCenter = 
new Qt3DCore::QTransform;
 
   65    trLightOriginCenter->setTranslation( lightTransform->translation() );
 
   66    originEntity->addComponent( trLightOriginCenter );
 
   68    Qt3DExtras::QPhongMaterial *materialLightOriginCenter = 
new Qt3DExtras::QPhongMaterial;
 
   69    materialLightOriginCenter->setAmbient( 
color() );
 
   70    originEntity->addComponent( materialLightOriginCenter );
 
   72    Qt3DExtras::QSphereMesh *rendererLightOriginCenter = 
new Qt3DExtras::QSphereMesh;
 
   73    rendererLightOriginCenter->setRadius( 20 );
 
   74    originEntity->addComponent( rendererLightOriginCenter );
 
   76    originEntity->setEnabled( 
true );
 
   78    Qt3DCore::QEntity *groupEntity = 
new Qt3DCore::QEntity( parent );
 
   79    lightEntity->setParent( groupEntity );
 
   80    originEntity->setParent( groupEntity );
 
   81    groupEntity->setEnabled( 
true );
 
 
   88  QDomElement elemLight = doc.createElement( QStringLiteral( 
"point-light" ) );
 
   89  elemLight.setAttribute( QStringLiteral( 
"x" ), mPosition.
x() );
 
   90  elemLight.setAttribute( QStringLiteral( 
"y" ), mPosition.
y() );
 
   91  elemLight.setAttribute( QStringLiteral( 
"z" ), mPosition.
z() );
 
   93  elemLight.setAttribute( QStringLiteral( 
"intensity" ), mIntensity );
 
   94  elemLight.setAttribute( QStringLiteral( 
"attenuation-0" ), mConstantAttenuation );
 
   95  elemLight.setAttribute( QStringLiteral( 
"attenuation-1" ), mLinearAttenuation );
 
   96  elemLight.setAttribute( QStringLiteral( 
"attenuation-2" ), mQuadraticAttenuation );
 
 
  102  mPosition.
set( elem.attribute( QStringLiteral( 
"x" ) ).toDouble(), elem.attribute( QStringLiteral( 
"y" ) ).toDouble(), elem.attribute( QStringLiteral( 
"z" ) ).toDouble() );
 
  104  mIntensity = elem.attribute( QStringLiteral( 
"intensity" ) ).toFloat();
 
  105  mConstantAttenuation = elem.attribute( QStringLiteral( 
"attenuation-0" ) ).toDouble();
 
  106  mLinearAttenuation = elem.attribute( QStringLiteral( 
"attenuation-1" ) ).toDouble();
 
  107  mQuadraticAttenuation = elem.attribute( QStringLiteral( 
"attenuation-2" ) ).toDouble();
 
 
  112  return mPosition == other.mPosition && mColor == other.mColor && mIntensity == other.mIntensity && mConstantAttenuation == other.mConstantAttenuation && mLinearAttenuation == other.mLinearAttenuation && 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)
 
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
 
static QString colorToString(const QColor &color)
Encodes a color into a string value.
 
Definition of a point light in a 3D map scene.
 
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.
 
bool operator==(const QgsPointLightSettings &other) const
 
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)
 
QColor color() const
Returns color of the light.
 
A container for the context for various read/write operations on objects.
 
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.