QQuick3DInstancing Class

Base class for defining instance tables. More...

Header: #include <QQuick3DInstancing>
Since: Qt 6.1
Instantiated By: Instancing
Inherits: QQuick3DObject

This class is under development and is subject to change.

Public Functions

bool hasTransparency() const
int instanceCountOverride() const

Public Slots

void setHasTransparency(bool hasTransparency)
void setInstanceCountOverride(int instanceCountOverride)

Signals

Protected Functions

(preliminary) virtual QByteArray getInstanceBuffer(int *instanceCount) = 0

Static Protected Members

(preliminary) QQuick3DInstancing::InstanceTableEntry calculateTableEntry(const QVector3D &position, const QVector3D &scale, const QVector3D &eulerRotation, const QColor &color, const QVector4D &customData = {})
(preliminary) QQuick3DInstancing::InstanceTableEntry calculateTableEntryFromQuaternion(const QVector3D &position, const QVector3D &scale, const QQuaternion &rotation, const QColor &color, const QVector4D &customData = {})

Detailed Description

The QQuick3DInstancing class can be inherited to specify a custom instance table for a Model in the Qt Quick 3D scene.

This class is abstract: To use it, create a subclass and implement getInstanceBuffer(). The subclass is then exposed to QML by registering it to the type system. The instancing property of a Model can then be set to reference an object of the registered type.

Member Function Documentation

[static protected] QQuick3DInstancing::InstanceTableEntry QQuick3DInstancing::calculateTableEntry(const QVector3D &position, const QVector3D &scale, const QVector3D &eulerRotation, const QColor &color, const QVector4D &customData = {})

This function is under development and is subject to change.

Converts the position scale eulerRotation color and customData to the instance table format expected by the standard vertex shaders. Typical pattern:

 QByteArray MyInstanceTable::getInstanceBuffer(int *instanceCount)
 {
     QByteArray instanceData;

     ...

     auto entry = calculateTableEntry({xPos, yPos, zPos}, {xScale, yScale, zScale}, {xRot, yRot, zRot}, color, {});
     instanceData.append(reinterpret_cast<const char *>(&entry), sizeof(entry));

See also calculateTableEntryFromQuaternion.

[static protected] QQuick3DInstancing::InstanceTableEntry QQuick3DInstancing::calculateTableEntryFromQuaternion(const QVector3D &position, const QVector3D &scale, const QQuaternion &rotation, const QColor &color, const QVector4D &customData = {})

This function is under development and is subject to change.

Converts the position scale rotation color and customData to the instance table format expected by the standard vertex shaders. Typical pattern:

This is the same as calculateTableEntry(), except for using a quaternion to specify the rotation.

[pure virtual protected] QByteArray QQuick3DInstancing::getInstanceBuffer(int *instanceCount)

This function is under development and is subject to change.

Implement this function to return the contents of the instance table. The number of instances should be returned in instanceCount. The subclass is responsible for caching the result if necessary.