20#include <QPropertyAnimation>
21#include <QSequentialAnimationGroup>
23#include <Qt3DCore/QEntity>
24#include <Qt3DCore/QTransform>
25#include <Qt3DExtras/QConeMesh>
26#include <Qt3DExtras/QCuboidMesh>
27#include <Qt3DExtras/QSphereMesh>
28#include <Qt3DRender/QParameter>
29#include <Qt3DRender/QPointLight>
30#include <Qt3DRender/QTechnique>
32using namespace Qt::StringLiterals;
54 Q_UNUSED( expressionContext )
62 Q_UNUSED( vertexCount )
63 Q_UNUSED( dataDefinedBytes )
69 sphere.
type = u
"sphere"_s;
73 cube.
type = u
"cube"_s;
77 cone.
type = u
"cone"_s;
80 return { sphere, cube, cone };
85 const QList<Qt3DRender::QParameter *> parameters = effect->parameters();
86 for ( Qt3DRender::QParameter *parameter : parameters )
88 if ( parameter->name() == name )
94 const QList< Qt3DRender::QTechnique *> techniques = effect->techniques();
95 for ( Qt3DRender::QTechnique *technique : techniques )
97 const QList<Qt3DRender::QParameter *> parameters = technique->parameters();
98 for ( Qt3DRender::QParameter *parameter : parameters )
100 if ( parameter->name() == name )
112 auto *entity =
new Qt3DCore::QEntity( parent );
113 if ( type ==
"sphere"_L1 )
115 auto *mesh =
new Qt3DExtras::QSphereMesh( entity );
116 mesh->setRadius( 1.0f );
117 mesh->setRings( 32 );
118 mesh->setSlices( 32 );
119 mesh->setGenerateTangents(
true );
120 entity->addComponent( mesh );
122 else if ( type ==
"cube"_L1 )
124 auto *mesh =
new Qt3DExtras::QCuboidMesh( entity );
125 mesh->setXExtent( 1.8f );
126 mesh->setYExtent( 1.8f );
127 mesh->setZExtent( 1.8f );
129 auto *transform =
new Qt3DCore::QTransform( mesh );
130 transform->setRotation( QQuaternion::fromEulerAngles( 15, 35, 15 ) );
132 entity->addComponent( mesh );
133 entity->addComponent( transform );
135 else if ( type ==
"cone"_L1 )
137 auto *mesh =
new Qt3DExtras::QConeMesh( entity );
138 mesh->setBottomRadius( 1.2f );
139 mesh->setLength( 1.8f );
140 mesh->setRings( 32 );
141 mesh->setSlices( 32 );
142 auto *transform =
new Qt3DCore::QTransform( mesh );
143 transform->setRotation( QQuaternion::fromEulerAngles( 5, 0, 0 ) );
145 entity->addComponent( mesh );
146 entity->addComponent( transform );
155 auto *root =
new Qt3DCore::QEntity( parent );
158 Q_ASSERT( meshEntity );
159 meshEntity->setObjectName(
"mesh" );
162 mat->setParent( meshEntity );
163 meshEntity->addComponent( mat );
166 auto *lightEntity =
new Qt3DCore::QEntity( root );
167 auto *light =
new Qt3DRender::QPointLight( lightEntity );
168 light->setColor( Qt::white );
169 light->setIntensity( 1.0f );
170 auto *lightTransform =
new Qt3DCore::QTransform( lightEntity );
171 lightTransform->setTranslation( QVector3D( 3, 3, 3 ) );
172 lightEntity->addComponent( light );
173 lightEntity->addComponent( lightTransform );
175 auto *animGroup =
new QSequentialAnimationGroup( lightEntity );
176 animGroup->setLoopCount( -1 );
178 auto *swingLeft =
new QPropertyAnimation( lightTransform,
"translation", animGroup );
179 swingLeft->setDuration( 8000 );
180 swingLeft->setStartValue( QVector3D( 3, 3, 3 ) );
181 swingLeft->setEndValue( QVector3D( -5, 5, 3 ) );
182 swingLeft->setEasingCurve( QEasingCurve::InOutSine );
184 auto *swingRight =
new QPropertyAnimation( lightTransform,
"translation", animGroup );
185 swingRight->setDuration( 8000 );
186 swingRight->setStartValue( QVector3D( -5, 5, 3 ) );
187 swingRight->setEndValue( QVector3D( 3, 3, 3 ) );
188 swingRight->setEasingCurve( QEasingCurve::InOutSine );
190 animGroup->addAnimation( swingLeft );
191 animGroup->addAnimation( swingRight );
@ Triangles
Triangle based rendering (default).
QFlags< InstancedMaterialFlag > InstancedMaterialFlags
Rendering context for preparation of 3D entities.
QColor selectionColor() const
Returns color used for selected features.
Qgis::TextureFilterQuality textureFilterQuality() const
Returns the texture filtering quality.
virtual Qt3DCore::QEntity * createPreviewScene(const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, QWindow *window, Qt3DCore::QEntity *parent) const
Builds a complete self-contained scene for previewing the material, using the specified mesh type.
static Qt3DRender::QParameter * findParameter(Qt3DRender::QEffect *effect, const QString &name)
Finds an existing parameter in an effect by name.
virtual void applyDataDefinedToGeometry(const QgsAbstractMaterialSettings *settings, Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
virtual Qt3DCore::QEntity * createPreviewMesh(const QString &type, Qt3DCore::QEntity *parent) const
Creates a new entity representing a suitable preview mesh for this material type.
virtual QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QgsMaterial object representing the material settings.
virtual QList< PreviewMeshType > previewMeshTypes() const
Returns a list of available preview mesh types for the material.
virtual QgsMaterial * toInstancedMaterial(const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context, Qgis::InstancedMaterialFlags flags) const
Creates a QgsMaterial for instanced point rendering.
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsAbstractMaterialSettings *settings, const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
Abstract base class for material settings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Context settings for a material.
static QgsMaterialContext fromRenderContext(const Qgs3DRenderContext &context)
Constructs a material context from the settings in a 3D render context.
Base class for all materials used within QGIS 3D views.
Encapsulates information about available preview meshes.
QString type
Identifier string.
QString displayName
Translated, user-friendly name.