QQuick3DGeometry Class

Base class for defining custom geometry. More...

Header: #include <QQuick3DGeometry>
Since: Qt 5.15
Instantiated By: Geometry
Inherits: QQuick3DObject

This class was introduced in Qt 5.15.

Properties

Public Functions

QString name() const

Public Slots

void setName(const QString &name)

Signals

void nameChanged()

Detailed Description

The QQuick3DGeometry can be used to specify custom geometry used with Qt Quick 3D.

The user should inherit this class and specify it's own properties, which can then be used from QML code. The user then should use these properties to construct the geometry and set it for the QQuick3DGeometry, which then uploads it to the Qt Quick3D engine.

Example implementation:

 class CustomGeometry : public QQuick3DGeometry
 {
     Q_OBJECT
     ... properties ...

 public:
     CustomGeometry();

     void setProperty(...)
     {
         ...
         rebuildGeometry();
     }

 private:
     void rebuildGeometry()
     {
         QByteArray vertices;
         QByteArray indices;
         fillGeometry(vertices, indices);
         setPrimitiveType(Lines);
         setVertexBuffer(vertices);
         setIndexBuffer(indices);
         setStride(sizeof(QVector3D));
         setBounds(...);
         addAttrubute(PositionSemantic, 0, F32Type);
     }
 };

This class can then be registered as a QML type and used with Model.

 qmlRegisterType<CustomGeometry>("Example", 1, 0, "CustomGeometry");
 import Example 1.0

 Model {
     id: customModel
     geometry: CustomGeometry {
     }
 }

Property Documentation

name : QString

Unique name identifying the geometry. This becomes the source path for the geometry. If multiple instances from the same geometry class are used, each of them must have their own unique name. Otherwise, geometry with same name will override the others. Geometry can be shared either by setting the geometry parameter for a model or using the name of the geometry as source parameter for the model.

Access functions:

QString name() const
void setName(const QString &name)

Notifier signal:

void nameChanged()