QLevelOfDetail Class

class Qt3DRender::QLevelOfDetail

The QLevelOfDetail class provides a way of controlling the complexity of rendered entities based on their size on the screen. More...

Header: #include <QLevelOfDetail>
qmake: QT += 3drender
Since: Qt 5.9
Instantiated By: LevelOfDetail
Inherits: Qt3DCore::QComponent
Inherited By:

Qt3DRender::QLevelOfDetailSwitch

This class was introduced in Qt 5.9.

Public Types

enum ThresholdType { DistanceToCameraThreshold, ProjectedScreenPixelSizeThreshold }

Public Functions

void setCamera(Qt3DRender::QCamera *camera)
void setCurrentIndex(int currentIndex)
void setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType)
void setThresholds(const QVector<qreal> &thresholds)

Detailed Description

QLevelOfDetail can be used to control the representation of an entity based on distance from the observer or size on the screen.

In order to improve rendering performance, objects that are very small can be rendered using far fewer details, in geometry or texture.

The component is controlled by specifying thresholds of values which are interpreted as either distances from the camera or screen size.

As the point of view changes, the currentIndex property will change to reflect matching value in the range array.

The currentIndex property can then be used, for example, to enable or disable entities, change material, etc.

The LevelOfDetail component is not shareable between multiple entities.

  #include <Qt3DCore/QEntity>
  #include <Qt3DRender/QGeometryRenderer>
  #include <Qt3DRender/QLevelOfDetail>

 // Scene
 Qt3DCore::QEntity *rootEntity = new Qt3DCore::Qt3DCore::QEntity;

 Qt3DCore::QEntity *renderableEntity = new Qt3DCore::QEntity(rootEntity);
 Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DCore::QGeometryRenderer(renderableEntity);
 renderableEntity->addComponent(geometryRenderer);
 Qt3DRender::QLevelOfDetail* lod = new Qt3Render::QLevelOfDetail(renderableEntity);
 QVector<qreal> thresholds = {20, 35, 50, 65};
 lod->setThresholds(thresholds);
 lod->setCamera(mainCamera);
 renderableEntity->addComponent(lod);

 // connect to QLevelOfDetail::currentIndexChanged to toggle rendering
 ...

Member Type Documentation

enum QLevelOfDetail::ThresholdType

Specifies how the values in the thresholds are interpreted

ConstantValueDescription
Qt3DRender::QLevelOfDetail::DistanceToCameraThreshold0Distance from the entity to the selected camera
Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold1Size of the entity when projected on the screen as seen from the selected camera, expressed in number of pixels on the side of the bounding square in screen space.

Member Function Documentation

void QLevelOfDetail::setCamera(Qt3DRender::QCamera *camera)

Sets the camera relative to which distance and size are computed.

void QLevelOfDetail::setCurrentIndex(int currentIndex)

Sets the currentIndex.

Note: This should not normally be set by the user.

However, if the component is disabled, then changing the current index is a simple way of switching between multiple representations.

void QLevelOfDetail::setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType)

Sets the way thresholds values are interpreted with parameter thresholdType

See also Qt3DRender::QLevelOfDetail::ThresholdType.

void QLevelOfDetail::setThresholds(const QVector<qreal> &thresholds)

Sets the range values in thresholds.

See also Qt3DRender::QLevelOfDetail::thresholdType.