18#include <Qt3DCore/QEntity>
39 std::unique_ptr< QgsPolygon3DSymbol > result = std::make_unique< QgsPolygon3DSymbol >();
40 result->mAltClamping = mAltClamping;
41 result->mAltBinding = mAltBinding;
42 result->mOffset = mOffset;
43 result->mExtrusionHeight = mExtrusionHeight;
44 result->mMaterialSettings.reset( mMaterialSettings->clone() );
45 result->mCullingMode = mCullingMode;
46 result->mInvertNormals = mInvertNormals;
47 result->mAddBackFaces = mAddBackFaces;
48 result->mRenderedFacade = mRenderedFacade;
49 result->mEdgesEnabled = mEdgesEnabled;
50 result->mEdgeWidth = mEdgeWidth;
51 result->mEdgeColor = mEdgeColor;
52 copyBaseSettings( result.get() );
53 return result.release();
60 QDomDocument doc = elem.ownerDocument();
62 QDomElement elemDataProperties = doc.createElement( QStringLiteral(
"data" ) );
65 elemDataProperties.setAttribute( QStringLiteral(
"offset" ), mOffset );
66 elemDataProperties.setAttribute( QStringLiteral(
"extrusion-height" ), mExtrusionHeight );
68 elemDataProperties.setAttribute( QStringLiteral(
"invert-normals" ), mInvertNormals ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
69 elemDataProperties.setAttribute( QStringLiteral(
"add-back-faces" ), mAddBackFaces ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
70 elemDataProperties.setAttribute( QStringLiteral(
"rendered-facade" ), mRenderedFacade );
71 elem.appendChild( elemDataProperties );
73 elem.setAttribute( QStringLiteral(
"material_type" ), mMaterialSettings->type() );
74 QDomElement elemMaterial = doc.createElement( QStringLiteral(
"material" ) );
75 mMaterialSettings->writeXml( elemMaterial, context );
76 elem.appendChild( elemMaterial );
78 QDomElement elemDDP = doc.createElement( QStringLiteral(
"data-defined-properties" ) );
79 mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
80 elem.appendChild( elemDDP );
82 QDomElement elemEdges = doc.createElement( QStringLiteral(
"edges" ) );
83 elemEdges.setAttribute( QStringLiteral(
"enabled" ), mEdgesEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
84 elemEdges.setAttribute( QStringLiteral(
"width" ), mEdgeWidth );
86 elem.appendChild( elemEdges );
93 const QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral(
"data" ) );
96 mOffset = elemDataProperties.attribute( QStringLiteral(
"offset" ) ).toFloat();
97 mExtrusionHeight = elemDataProperties.attribute( QStringLiteral(
"extrusion-height" ) ).toFloat();
99 mInvertNormals = elemDataProperties.attribute( QStringLiteral(
"invert-normals" ) ).toInt();
100 mAddBackFaces = elemDataProperties.attribute( QStringLiteral(
"add-back-faces" ) ).toInt();
101 mRenderedFacade = elemDataProperties.attribute( QStringLiteral(
"rendered-facade" ),
"3" ).toInt();
103 const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral(
"material" ) );
104 const QString materialType = elem.attribute( QStringLiteral(
"material_type" ), QStringLiteral(
"phong" ) );
106 if ( !mMaterialSettings )
108 mMaterialSettings->readXml( elemMaterial, context );
110 const QDomElement elemDDP = elem.firstChildElement( QStringLiteral(
"data-defined-properties" ) );
111 if ( !elemDDP.isNull() )
112 mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
114 const QDomElement elemEdges = elem.firstChildElement( QStringLiteral(
"edges" ) );
115 if ( !elemEdges.isNull() )
117 mEdgesEnabled = elemEdges.attribute( QStringLiteral(
"enabled" ) ).toInt();
118 mEdgeWidth = elemEdges.attribute( QStringLiteral(
"width" ) ).toFloat();
133 mAltBinding = props->
binding();
151 mOffset =
static_cast< float >( props->
zOffset() );
161 return mMaterialSettings.get();
174 QList<Qt3DCore::QEntity *> subEntities = entity->findChildren<Qt3DCore::QEntity *>( QString(), Qt::FindDirectChildrenOnly );
176 std::sort( subEntities.begin(), subEntities.end(), [](
const Qt3DCore::QEntity * a,
const Qt3DCore::QEntity * b )
178 return a->objectName() < b->objectName();
181 if ( subEntities.isEmpty() )
183 const QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
184 const int startSize = exporter->mObjects.size();
185 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
187 Qgs3DExportObject *
object = exporter->processGeometryRenderer( renderer, objectNamePrefix );
190 exporter->processEntityMaterial( entity,
object );
191 exporter->mObjects.push_back(
object );
194 return exporter->mObjects.size() > startSize;
200 for ( Qt3DCore::QEntity *e : subEntities )
202 if ( e->objectName().isEmpty() )
203 prefix = objectNamePrefix;
205 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
Z offset.
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.
QgsPolygon3DSymbol()
Constructor for QgsPolygon3DSymbol.
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.