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 {
}
}
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 () |
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. |
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.
Returns an attribute at index
Returns the attribute count.
Returns the maximum bound coordinate.
Returns the minimum bound coordinate.
Clears previously set vertex- and index data as well as attributes.
Returns the index buffer data.
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 ().
Sets the bounds of the geometry with min and max point.
Sets the index buffer data . If the index buffer is not set, the vertex buffer is used as is for the vertices.
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 ().
Sets the byte stride of the vertex.
另请参阅 stride ().
Sets the vertex buffer data . The buffer should hold all the vertex data packed in the array described by the attributes.
Returns the byte stride of the vertex buffer.
另请参阅 setStride ().
Returns the vertex buffer data.