28#include <Qt3DCore/QTransform>
29#include <Qt3DRender/QGeometryRenderer>
31#include "moc_qgsabstractfeaturebasedchunkedentity.cpp"
33using namespace Qt::StringLiterals;
37QgsAbstractFeatureBasedChunkedEntity::QgsAbstractFeatureBasedChunkedEntity(
38 Qgs3DMapSettings *mapSettings,
float tau, QgsChunkLoaderFactory *loaderFactory,
bool ownsFactory,
int primitivesBudget, Qt3DCore::QNode *parent
40 : QgsChunkedEntity( mapSettings, tau, loaderFactory, ownsFactory, primitivesBudget, parent )
42 mTransform =
new Qt3DCore::QTransform;
43 this->addComponent( mTransform );
48void QgsAbstractFeatureBasedChunkedEntity::onTerrainElevationOffsetChanged()
50 QgsDebugMsgLevel( u
"QgsAbstractFeatureBasedChunkedEntity::onTerrainElevationOffsetChanged"_s, 2 );
52 float newOffset =
static_cast<float>( mMapSettings->terrainSettings()->elevationOffset() );
53 if ( !applyTerrainOffset() )
57 mTransform->setTranslation( QVector3D( 0.0f, 0.0f, newOffset ) );
60QList<QgsRayCastHit> QgsAbstractFeatureBasedChunkedEntity::rayIntersection(
const QgsRay3D &ray,
const QgsRayCastContext &context )
const
62 return rayIntersection( activeNodes(), mTransform->matrix(), ray, context, mMapSettings->origin() );
65QList<QgsRayCastHit> QgsAbstractFeatureBasedChunkedEntity::rayIntersection(
74 int ignoredGeometries = 0;
76 QList<QgsRayCastHit> result;
79 QVector3D intersectionPoint;
82 for ( QgsChunkNode *node : activeNodes )
95 const QList<Qt3DRender::QGeometryRenderer *> rendLst = node->entity()->findChildren<Qt3DRender::QGeometryRenderer *>();
96 for (
const auto &rend : rendLst )
98 auto *geom = rend->geometry();
108 QVector3D nodeIntPoint;
109 int triangleIndex = -1;
114 const QMatrix4x4 nodeTransformMatrix = node->entity()->findChild<QgsGeoTransform *>()->matrix();
115 const QMatrix4x4 fullTransformMatrix = transformMatrix * nodeTransformMatrix;
121 float dist = ( ray.
origin() - nodeIntPoint ).length();
122 if ( minDist < 0 || dist < minDist )
125 intersectionPoint = nodeIntPoint;
138 result.append( hit );
140 QgsDebugMsgLevel( u
"Active Nodes: %1, checked nodes: %2, hits found: %3, incompatible geometries: %4"_s.arg( nodesAll ).arg( nodeUsed ).arg( hits ).arg( ignoredGeometries ), 2 );
void terrainSettingsChanged()
Emitted when the terrain settings are changed.
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset).
Axis-aligned bounding box - in world coords.
float distanceFromPoint(float x, float y, float z) const
Returns shortest distance from the box to a point.
A representation of a ray in 3D.
QVector3D origin() const
Returns the origin of the ray.
Responsible for defining parameters of the ray casting operations in 3D map canvases.
float maximumDistance() const
The maximum distance from ray origin to look for hits when casting a ray.
Contains details about the ray intersecting entities when ray casting in a 3D map canvas.
void setProperties(const QVariantMap &attributes)
Sets the point cloud point attributes, empty map if hit was not on a point cloud point.
void setMapCoordinates(const QgsVector3D &point)
Sets the hit point position in 3d map coordinates.
void setDistance(double distance)
Sets the hit's distance from the ray's origin.
Qt3DRender::QGeometry subclass that represents polygons tessellated into 3D geometry.
QgsFeatureId triangleIndexToFeatureId(uint triangleIndex) const
Returns ID of the feature to which given triangle index belongs (used for picking).
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
bool rayBoxIntersection(const QgsRay3D &ray, const QgsAABB &nodeBbox)
Tests whether an axis aligned box is intersected by a ray.
bool rayMeshIntersection(Qt3DRender::QGeometryRenderer *geometryRenderer, const QgsRay3D &r, float maxDist, const QMatrix4x4 &worldTransform, QVector3D &intPt, int &triangleIndex)
Tests whether a triangular mesh is intersected by a ray.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugMsgLevel(str, level)