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;
46 Q_UNUSED( expressionContext )
54 Q_UNUSED( vertexCount )
55 Q_UNUSED( dataDefinedBytes )
66 sphere.
type = u
"sphere"_s;
70 cube.
type = u
"cube"_s;
74 cone.
type = u
"cone"_s;
77 return { sphere, cube, cone };
82 const QList<Qt3DRender::QParameter *> parameters = effect->parameters();
83 for ( Qt3DRender::QParameter *parameter : parameters )
85 if ( parameter->name() == name )
91 const QList< Qt3DRender::QTechnique *> techniques = effect->techniques();
92 for ( Qt3DRender::QTechnique *technique : techniques )
94 const QList<Qt3DRender::QParameter *> parameters = technique->parameters();
95 for ( Qt3DRender::QParameter *parameter : parameters )
97 if ( parameter->name() == name )
109 auto *entity =
new Qt3DCore::QEntity( parent );
110 if ( type ==
"sphere"_L1 )
112 auto *mesh =
new Qt3DExtras::QSphereMesh( entity );
113 mesh->setRadius( 1.0f );
114 mesh->setRings( 32 );
115 mesh->setSlices( 32 );
116 mesh->setGenerateTangents(
true );
117 entity->addComponent( mesh );
119 else if ( type ==
"cube"_L1 )
121 auto *mesh =
new Qt3DExtras::QCuboidMesh( entity );
122 mesh->setXExtent( 1.8f );
123 mesh->setYExtent( 1.8f );
124 mesh->setZExtent( 1.8f );
126 auto *transform =
new Qt3DCore::QTransform( mesh );
127 transform->setRotation( QQuaternion::fromEulerAngles( 15, 35, 15 ) );
129 entity->addComponent( mesh );
130 entity->addComponent( transform );
132 else if ( type ==
"cone"_L1 )
134 auto *mesh =
new Qt3DExtras::QConeMesh( entity );
135 mesh->setBottomRadius( 1.2f );
136 mesh->setLength( 1.8f );
137 mesh->setRings( 32 );
138 mesh->setSlices( 32 );
139 auto *transform =
new Qt3DCore::QTransform( mesh );
140 transform->setRotation( QQuaternion::fromEulerAngles( 5, 0, 0 ) );
142 entity->addComponent( mesh );
143 entity->addComponent( transform );
152 auto *root =
new Qt3DCore::QEntity( parent );
155 Q_ASSERT( meshEntity );
156 meshEntity->setObjectName(
"mesh" );
159 mat->setParent( meshEntity );
160 meshEntity->addComponent( mat );
163 auto *lightEntity =
new Qt3DCore::QEntity( root );
164 auto *light =
new Qt3DRender::QPointLight( lightEntity );
165 light->setColor( Qt::white );
166 light->setIntensity( 1.0f );
167 auto *lightTransform =
new Qt3DCore::QTransform( lightEntity );
168 lightTransform->setTranslation( QVector3D( 3, 3, 3 ) );
169 lightEntity->addComponent( light );
170 lightEntity->addComponent( lightTransform );
172 auto *animGroup =
new QSequentialAnimationGroup( lightEntity );
173 animGroup->setLoopCount( -1 );
175 auto *swingLeft =
new QPropertyAnimation( lightTransform,
"translation", animGroup );
176 swingLeft->setDuration( 8000 );
177 swingLeft->setStartValue( QVector3D( 3, 3, 3 ) );
178 swingLeft->setEndValue( QVector3D( -5, 5, 3 ) );
179 swingLeft->setEasingCurve( QEasingCurve::InOutSine );
181 auto *swingRight =
new QPropertyAnimation( lightTransform,
"translation", animGroup );
182 swingRight->setDuration( 8000 );
183 swingRight->setStartValue( QVector3D( -5, 5, 3 ) );
184 swingRight->setEndValue( QVector3D( 3, 3, 3 ) );
185 swingRight->setEasingCurve( QEasingCurve::InOutSine );
187 animGroup->addAnimation( swingLeft );
188 animGroup->addAnimation( swingRight );
@ Triangles
Triangle based rendering (default).
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 int dataDefinedByteStride(const QgsAbstractMaterialSettings *settings) const
Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for...
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 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.