19#include <Qt3DCore/QEntity>
20#include <Qt3DCore/QTransform>
21#include <Qt3DExtras/QConeMesh>
22#include <Qt3DExtras/QCuboidMesh>
23#include <Qt3DExtras/QSphereMesh>
24#include <Qt3DRender/QParameter>
25#include <Qt3DRender/QPointLight>
26#include <Qt3DRender/QTechnique>
28using namespace Qt::StringLiterals;
34 Q_UNUSED( expressionContext )
42 Q_UNUSED( vertexCount )
43 Q_UNUSED( dataDefinedBytes )
54 sphere.
type = u
"sphere"_s;
58 cube.
type = u
"cube"_s;
62 cone.
type = u
"cone"_s;
65 return { sphere, cube, cone };
70 const QList<Qt3DRender::QParameter *> parameters = effect->parameters();
71 for ( Qt3DRender::QParameter *parameter : parameters )
73 if ( parameter->name() == name )
79 const QList< Qt3DRender::QTechnique *> techniques = effect->techniques();
80 for ( Qt3DRender::QTechnique *technique : techniques )
82 const QList<Qt3DRender::QParameter *> parameters = technique->parameters();
83 for ( Qt3DRender::QParameter *parameter : parameters )
85 if ( parameter->name() == name )
97 auto *entity =
new Qt3DCore::QEntity( parent );
98 if ( type ==
"sphere"_L1 )
100 auto *mesh =
new Qt3DExtras::QSphereMesh( entity );
101 mesh->setRadius( 1.0f );
102 mesh->setRings( 32 );
103 mesh->setSlices( 32 );
104 entity->addComponent( mesh );
106 else if ( type ==
"cube"_L1 )
108 auto *mesh =
new Qt3DExtras::QCuboidMesh( entity );
109 mesh->setXExtent( 1.8f );
110 mesh->setYExtent( 1.8f );
111 mesh->setZExtent( 1.8f );
113 auto *transform =
new Qt3DCore::QTransform( mesh );
114 transform->setRotation( QQuaternion::fromEulerAngles( 15, 35, 15 ) );
116 entity->addComponent( mesh );
117 entity->addComponent( transform );
119 else if ( type ==
"cone"_L1 )
121 auto *mesh =
new Qt3DExtras::QConeMesh( entity );
122 mesh->setBottomRadius( 1.2f );
123 mesh->setLength( 1.8f );
124 mesh->setRings( 32 );
125 mesh->setSlices( 32 );
126 auto *transform =
new Qt3DCore::QTransform( mesh );
127 transform->setRotation( QQuaternion::fromEulerAngles( 5, 0, 0 ) );
129 entity->addComponent( mesh );
130 entity->addComponent( transform );
139 auto *root =
new Qt3DCore::QEntity( parent );
142 Q_ASSERT( meshEntity );
143 meshEntity->setObjectName(
"mesh" );
146 mat->setParent( meshEntity );
147 meshEntity->addComponent( mat );
150 auto *lightEntity =
new Qt3DCore::QEntity( root );
151 auto *light =
new Qt3DRender::QPointLight( lightEntity );
152 light->setColor( Qt::white );
153 light->setIntensity( 1.0f );
154 auto *lightTransform =
new Qt3DCore::QTransform( lightEntity );
155 lightTransform->setTranslation( QVector3D( 3, 3, 3 ) );
156 lightEntity->addComponent( light );
157 lightEntity->addComponent( lightTransform );
@ Triangles
Triangle based rendering (default).
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 Qt3DCore::QEntity * createPreviewScene(const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, Qt3DExtras::Qt3DWindow *window, Qt3DCore::QEntity *parent) const
Builds a complete self-contained scene for previewing the material, using the specified mesh type.
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.
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.