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

void addAttribute(Attribute::Semantic semantic, int offset, Attribute::ComponentType componentType)
void addAttribute(const QQuick3DGeometry::Attribute &attribute)
QQuick3DGeometry::Attribute attribute(int index) const
int attributeCount() const
QVector3D boundsMax() const
QVector3D boundsMin() const
void clear()
QByteArray indexBuffer() const
QString name() const
QQuick3DGeometry::PrimitiveType primitiveType() const
void setBounds(const QVector3D &min, const QVector3D &max)
void setIndexData(const QByteArray &data)
void setPrimitiveType(QQuick3DGeometry::PrimitiveType type)
void setStride(int stride)
void setVertexData(const QByteArray &data)
int stride() const
QByteArray vertexBuffer() 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()

Member Function Documentation

void QQuick3DGeometry::addAttribute(Attribute::Semantic semantic, int offset, Attribute::ComponentType componentType)

Adds vertex attribute description. Each attribute has a semantic, which specifies the usage of the attribute and the number of components it has, an offset from the beginning to the vertex to the attribute location inside a vertex and a componentType specifying the datatype and size of the attribute.

The semantic can be one of the following:

ConstantDescription
UnknownSemanticThe semantic is not set.
IndexSemanticThe attribute is an index.
PositionSemanticThe attribute is a position.
NormalSemanticThe attribute is a normal vector.
TexCoordSemanticThe attribute is a texture coordinate.
TangentSemanticThe attribute is a tangent vector.
BinormalSemanticThe attribute is a binormal vector.

The component type can be one of the following:

ConstantDescription
DefaultTypeThe attribute uses default type depending on the semantic.
U16TypeThe attribute is an unsigned 16-bit integer.
U32TypeThe attribute is an unsigned 32-bit integer. This is the default for IndexSemantic.
F32TypeThe attribute is a single-precision float. This is the default for most semantics.

void QQuick3DGeometry::addAttribute(const QQuick3DGeometry::Attribute &attribute)

Adds vertex attribute description. Each attribute has a semantic, which specifies the usage of the attribute and the number of components it has, an offset from the beginning to the vertex to the attribute location inside a vertex and a componentType specifying the datatype and size of the attribute.

QQuick3DGeometry::Attribute QQuick3DGeometry::attribute(int index) const

Returns an attribute at index

int QQuick3DGeometry::attributeCount() const

Returns the attribute count.

QVector3D QQuick3DGeometry::boundsMax() const

Returns the maximum bound coordinate.

QVector3D QQuick3DGeometry::boundsMin() const

Returns the minimum bound coordinate.

void QQuick3DGeometry::clear()

Clears previously set vertex- and index data as well as attributes.

QByteArray QQuick3DGeometry::indexBuffer() const

Returns the index buffer data.

QQuick3DGeometry::PrimitiveType QQuick3DGeometry::primitiveType() const

Returns the primitive type. The default is Triangles.

ConstantDescription
UnknownThe primitive type is not set.
PointsThe primitives are points.
LineStripThe primitives are lines in a strip.
LinesThe primitives are lines in a list.
TriangleStripThe primitives are triangles in a strip.
TriangleFanThe primitives are triangles in a fan.
TrianglesThe primitives are triangles in a list.

See also setPrimitiveType().

void QQuick3DGeometry::setBounds(const QVector3D &min, const QVector3D &max)

Sets the bounds of the geometry with min and max point.

void QQuick3DGeometry::setIndexData(const QByteArray &data)

Sets the index buffer data. If the index buffer is not set, the vertex buffer is used as is for the vertices.

void QQuick3DGeometry::setPrimitiveType(QQuick3DGeometry::PrimitiveType type)

Sets the primitive type.

ConstantDescription
UnknownTypeThe primitive type is not set.
PointsThe primitives are points.
LineStripThe primitives are lines in a strip.
LinesThe primitives are lines in a list.
TriangleStripThe primitives are triangles in a strip.
TriangleFanThe primitives are triangles in a fan.
TrianglesThe primitives are triangles in a list.

See also primitiveType().

void QQuick3DGeometry::setStride(int stride)

Sets the byte stride of the vertex.

See also stride().

void QQuick3DGeometry::setVertexData(const QByteArray &data)

Sets the vertex buffer data. The buffer should hold all the vertex data packed in the array described by the attributes.

int QQuick3DGeometry::stride() const

Returns the byte stride of the vertex buffer.

See also setStride().

QByteArray QQuick3DGeometry::vertexBuffer() const

Returns the vertex buffer data.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.