18#include <Qt3DCore/QEntity>
38 std::unique_ptr<QgsPolygon3DSymbol> result = std::make_unique<QgsPolygon3DSymbol>();
39 result->mAltClamping = mAltClamping;
40 result->mAltBinding = mAltBinding;
41 result->mOffset = mOffset;
42 result->mExtrusionHeight = mExtrusionHeight;
43 result->mMaterialSettings.reset( mMaterialSettings->clone() );
44 result->mCullingMode = mCullingMode;
45 result->mInvertNormals = mInvertNormals;
46 result->mAddBackFaces = mAddBackFaces;
47 result->mRenderedFacade = mRenderedFacade;
48 result->mEdgesEnabled = mEdgesEnabled;
49 result->mEdgeWidth = mEdgeWidth;
50 result->mEdgeColor = mEdgeColor;
51 copyBaseSettings( result.get() );
52 return result.release();
59 QDomDocument doc = elem.ownerDocument();
61 QDomElement elemDataProperties = doc.createElement( QStringLiteral(
"data" ) );
64 elemDataProperties.setAttribute( QStringLiteral(
"offset" ), mOffset );
65 elemDataProperties.setAttribute( QStringLiteral(
"extrusion-height" ), mExtrusionHeight );
67 elemDataProperties.setAttribute( QStringLiteral(
"invert-normals" ), mInvertNormals ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
68 elemDataProperties.setAttribute( QStringLiteral(
"add-back-faces" ), mAddBackFaces ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
69 elemDataProperties.setAttribute( QStringLiteral(
"rendered-facade" ), mRenderedFacade );
70 elem.appendChild( elemDataProperties );
72 elem.setAttribute( QStringLiteral(
"material_type" ), mMaterialSettings->type() );
73 QDomElement elemMaterial = doc.createElement( QStringLiteral(
"material" ) );
74 mMaterialSettings->writeXml( elemMaterial, context );
75 elem.appendChild( elemMaterial );
77 QDomElement elemDDP = doc.createElement( QStringLiteral(
"data-defined-properties" ) );
78 mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
79 elem.appendChild( elemDDP );
81 QDomElement elemEdges = doc.createElement( QStringLiteral(
"edges" ) );
82 elemEdges.setAttribute( QStringLiteral(
"enabled" ), mEdgesEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
83 elemEdges.setAttribute( QStringLiteral(
"width" ), mEdgeWidth );
85 elem.appendChild( elemEdges );
92 const QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral(
"data" ) );
95 mOffset = elemDataProperties.attribute( QStringLiteral(
"offset" ) ).toFloat();
96 mExtrusionHeight = elemDataProperties.attribute( QStringLiteral(
"extrusion-height" ) ).toFloat();
98 mInvertNormals = elemDataProperties.attribute( QStringLiteral(
"invert-normals" ) ).toInt();
99 mAddBackFaces = elemDataProperties.attribute( QStringLiteral(
"add-back-faces" ) ).toInt();
100 mRenderedFacade = elemDataProperties.attribute( QStringLiteral(
"rendered-facade" ),
"3" ).toInt();
102 const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral(
"material" ) );
103 const QString materialType = elem.attribute( QStringLiteral(
"material_type" ), QStringLiteral(
"phong" ) );
105 if ( !mMaterialSettings )
107 mMaterialSettings->readXml( elemMaterial, context );
109 const QDomElement elemDDP = elem.firstChildElement( QStringLiteral(
"data-defined-properties" ) );
110 if ( !elemDDP.isNull() )
111 mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
113 const QDomElement elemEdges = elem.firstChildElement( QStringLiteral(
"edges" ) );
114 if ( !elemEdges.isNull() )
116 mEdgesEnabled = elemEdges.attribute( QStringLiteral(
"enabled" ) ).toInt();
117 mEdgeWidth = elemEdges.attribute( QStringLiteral(
"width" ) ).toFloat();
132 mAltBinding = props->
binding();
150 mOffset =
static_cast<float>( props->
zOffset() );
160 return mMaterialSettings.get();
173 QList<Qt3DCore::QEntity *> subEntities = entity->findChildren<Qt3DCore::QEntity *>( QString(), Qt::FindDirectChildrenOnly );
175 std::sort( subEntities.begin(), subEntities.end(), [](
const Qt3DCore::QEntity *a,
const Qt3DCore::QEntity *b ) {
176 return a->objectName() < b->objectName();
179 if ( subEntities.isEmpty() )
181 const QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
182 const int startSize = exporter->mObjects.size();
183 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
185 Qgs3DExportObject *
object = exporter->processGeometryRenderer( renderer, objectNamePrefix );
188 exporter->processEntityMaterial( entity,
object );
189 exporter->mObjects.push_back(
object );
192 return exporter->mObjects.size() > startSize;
198 for ( Qt3DCore::QEntity *e : subEntities )
200 if ( e->objectName().isEmpty() )
201 prefix = objectNamePrefix;
203 prefix = e->objectName() +
"_";
Manages the data of each object of the scene (positions, normals, texture coordinates ....
Entity that handles the exporting of 3D scene.
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
static Qgis::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
static Qgis::AltitudeBinding altBindingFromString(const QString &str)
Converts a string to a value from AltitudeBinding enum.
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
static QString altClampingToString(Qgis::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
static QString altBindingToString(Qgis::AltitudeBinding altBind)
Converts a value from AltitudeBinding enum to a string.
static QgsMaterialRegistry * materialRegistry()
Returns the material registry, used for managing 3D materials.
@ ExtrusionHeight
Extrusion height (zero means no extrusion)
@ Height
Height (altitude)
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.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
@ ExtrusionHeight
Extrusion height.
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
static QgsAbstract3DSymbol * create() SIP_FACTORY
Creates a new QgsPolygon3DSymbol.
QgsAbstractMaterialSettings * materialSettings() const
Returns material settings used for shading of the symbol.
QgsAbstract3DSymbol * clone() const override SIP_FACTORY
void setMaterialSettings(QgsAbstractMaterialSettings *materialSettings SIP_TRANSFER)
Sets the material settings used for shading of the symbol.
~QgsPolygon3DSymbol() override
bool exportGeometries(Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix) const override SIP_SKIP
Exports the geometries contained within the hierarchy of entity.
void setDefaultPropertiesFromLayer(const QgsVectorLayer *layer) override
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
QList< Qgis::GeometryType > compatibleGeometryTypes() const override
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
Vector layer specific subclass of QgsMapLayerElevationProperties.
double extrusionHeight() const
Returns the feature extrusion height.
Qgis::AltitudeClamping clamping() const
Returns the altitude clamping method, which dictates how feature heights are interpreted with respect...
Qgis::AltitudeBinding binding() const
Returns the altitude binding method, which determines how altitude is bound to individual vertices in...
bool extrusionEnabled() const
Returns true if extrusion is enabled.
Represents a vector layer which manages a vector based data sets.