QQuick3DGeometry Class

Base class for defining custom geometry. 更多...

头: #include <QQuick3DGeometry>
Since: Qt 5.15
实例化: 几何体
继承: QQuick3DObject

该类在 Qt 5.15 引入。

特性

公共函数

void addAttribute (Attribute::Semantic semantic , int offset , Attribute::ComponentType componentType )
void addAttribute (const QQuick3DGeometry::Attribute & 属性 )
QQuick3DGeometry::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

公共槽

void setName (const QString & name )

信号

void nameChanged ()

详细描述

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 {
    }
}
					

特性文档编制

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.

访问函数:

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

通知程序信号:

void nameChanged ()

成员函数文档编制

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:

常量 描述
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:

常量 描述
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 QQuick3DGeometry::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:: 属性 ( 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 .

常量 描述
未知 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.

另请参阅 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 .

常量 描述
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.

另请参阅 primitiveType ().

void QQuick3DGeometry:: setStride ( int stride )

Sets the byte stride of the vertex.

另请参阅 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.

另请参阅 setStride ().

QByteArray QQuick3DGeometry:: vertexBuffer () const

Returns the vertex buffer data.