-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Configuration of lights in 3D map scene
This adds a section to define point lights in 3D scenes. Up to 8 lights are supported (limitation by implementation of materials). For each light one can set the position, intensity, color and attenuation
- Loading branch information
Showing
14 changed files
with
623 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgspointlightsettings.cpp | ||
-------------------------------------- | ||
Date : November 2018 | ||
Copyright : (C) 2018 by Martin Dobias | ||
Email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgspointlightsettings.h" | ||
|
||
#include <QDomDocument> | ||
|
||
#include "qgssymbollayerutils.h" | ||
|
||
|
||
QDomElement QgsPointLightSettings::writeXml( QDomDocument &doc ) const | ||
{ | ||
QDomElement elemLight = doc.createElement( QStringLiteral( "point-light" ) ); | ||
elemLight.setAttribute( QStringLiteral( "x" ), mPosition.x() ); | ||
elemLight.setAttribute( QStringLiteral( "y" ), mPosition.y() ); | ||
elemLight.setAttribute( QStringLiteral( "z" ), mPosition.z() ); | ||
elemLight.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); | ||
elemLight.setAttribute( QStringLiteral( "intensity" ), mIntensity ); | ||
elemLight.setAttribute( QStringLiteral( "attenuation-0" ), mConstantAttenuation ); | ||
elemLight.setAttribute( QStringLiteral( "attenuation-1" ), mLinearAttenuation ); | ||
elemLight.setAttribute( QStringLiteral( "attenuation-2" ), mQuadraticAttenuation ); | ||
return elemLight; | ||
} | ||
|
||
void QgsPointLightSettings::readXml( const QDomElement &elem ) | ||
{ | ||
mPosition.set( elem.attribute( QStringLiteral( "x" ) ).toDouble(), | ||
elem.attribute( QStringLiteral( "y" ) ).toDouble(), | ||
elem.attribute( QStringLiteral( "z" ) ).toDouble() ); | ||
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) ); | ||
mIntensity = elem.attribute( QStringLiteral( "intensity" ) ).toFloat(); | ||
mConstantAttenuation = elem.attribute( QStringLiteral( "attenuation-0" ) ).toDouble(); | ||
mLinearAttenuation = elem.attribute( QStringLiteral( "attenuation-1" ) ).toDouble(); | ||
mQuadraticAttenuation = elem.attribute( QStringLiteral( "attenuation-2" ) ).toDouble(); | ||
} | ||
|
||
bool QgsPointLightSettings::operator==( const QgsPointLightSettings &other ) | ||
{ | ||
return mPosition == other.mPosition && mColor == other.mColor && mIntensity == other.mIntensity && | ||
mConstantAttenuation == other.mConstantAttenuation && mLinearAttenuation == other.mLinearAttenuation && | ||
mQuadraticAttenuation == other.mQuadraticAttenuation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef QGSPOINTLIGHTSETTINGS_H | ||
#define QGSPOINTLIGHTSETTINGS_H | ||
|
||
#include "qgsvector3d.h" | ||
#include <QColor> | ||
|
||
class QDomDocument; | ||
class QDomElement; | ||
|
||
/** | ||
* \ingroup 3d | ||
* Definition of a point light in a 3D map scene | ||
* \since QGIS 3.6 | ||
*/ | ||
class QgsPointLightSettings | ||
{ | ||
public: | ||
QgsPointLightSettings() = default; | ||
|
||
//! Returns position of the light (in 3D world coordinates) | ||
QgsVector3D position() const { return mPosition; } | ||
//! Sets position of the light (in 3D world coordinates) | ||
void setPosition( const QgsVector3D &pos ) { mPosition = pos; } | ||
|
||
//! Returns color of the light | ||
QColor color() const { return mColor; } | ||
//! Sets color of the light | ||
void setColor( const QColor &c ) { mColor = c; } | ||
|
||
//! Returns intensity of the light | ||
float intensity() const { return mIntensity; } | ||
//! Sets intensity of the light | ||
void setIntensity( float intensity ) { mIntensity = intensity; } | ||
|
||
float constantAttenuation() const { return mConstantAttenuation; } | ||
void setConstantAttenuation( float value ) { mConstantAttenuation = value; } | ||
|
||
float linearAttenuation() const { return mLinearAttenuation; } | ||
void setLinearAttenuation( float value ) { mLinearAttenuation = value; } | ||
|
||
float quadraticAttenuation() const { return mQuadraticAttenuation; } | ||
void setQuadraticAttenuation( float value ) { mQuadraticAttenuation = value; } | ||
|
||
//! Writes configuration to a new DOM element and returns it | ||
QDomElement writeXml( QDomDocument &doc ) const; | ||
//! Reads configuration from a DOM element previously written using writeXml() | ||
void readXml( const QDomElement &elem ); | ||
|
||
bool operator==( const QgsPointLightSettings &other ); | ||
|
||
private: | ||
QgsVector3D mPosition; | ||
QColor mColor = Qt::white; | ||
float mIntensity = 0.5; | ||
float mConstantAttenuation = 1.0f; | ||
float mLinearAttenuation = 0.0f; | ||
float mQuadraticAttenuation = 0.0f; | ||
}; | ||
|
||
#endif // QGSPOINTLIGHTSETTINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.