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
- name : QString
Public Functions
void | addAttribute(Attribute::Semantic semantic, int offset, Attribute::ComponentType componentType) |
void | addAttribute(const Attribute &attribute) |
Attribute | attribute(int index) const |
int | attributeCount() const |
QVector3D | boundsMax() const |
QVector3D | boundsMin() const |
void | clear() |
QByteArray | indexBuffer() const |
QString | name() const |
PrimitiveType | primitiveType() const |
void | setBounds(const QVector3D &min, const QVector3D &max) |
void | setIndexData(const QByteArray &data) |
void | setPrimitiveType(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:
Constant | Description |
---|---|
UnknownSemantic | The semantic is not set. |
IndexSemantic | The attribute is an index. |
PositionSemantic | The attribute is a position. |
NormalSemantic | The attribute is a normal vector. |
TexCoordSemantic | The attribute is a texture coordinate. |
TangentSemantic | The attribute is a tangent vector. |
BinormalSemantic | The attribute is a binormal vector. |
The component type can be one of the following:
Constant | Description |
---|---|
DefaultType | The attribute uses default type depending on the semantic. |
U16Type | The attribute is an unsigned 16-bit integer. |
U32Type | The attribute is an unsigned 32-bit integer. This is the default for IndexSemantic. |
F32Type | The attribute is a single-precision float. This is the default for most semantics. |
void QQuick3DGeometry::addAttribute(const 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.
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.
PrimitiveType QQuick3DGeometry::primitiveType() const
Returns the primitive type. The default is Triangles
.
Constant | Description |
---|---|
Unknown | The primitive type is not set. |
Points | The primitives are points. |
LineStrip | The primitives are lines in a strip. |
Lines | The primitives are lines in a list. |
TriangleStrip | The primitives are triangles in a strip. |
TriangleFan | The primitives are triangles in a fan. |
Triangles | The 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(PrimitiveType type)
Sets the primitive type.
Constant | Description |
---|---|
UnknownType | The primitive type is not set. |
Points | The primitives are points. |
LineStrip | The primitives are lines in a strip. |
Lines | The primitives are lines in a list. |
TriangleStrip | The primitives are triangles in a strip. |
TriangleFan | The primitives are triangles in a fan. |
Triangles | The 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.