7#include <QtQuick3DUtils/private/qssgplane_p.h>
8#include <QtQuick3DUtils/private/qssgutils_p.h>
9#include <QtQuick3DUtils/private/qssgmeshbvh_p.h>
10#include <QtQuick3DRuntimeRender/private/qssgrendermesh_p.h>
21 if (std::abs(Vd) < .0001f)
34 float *outOriginTransformPtr(originTransform.
data());
35 outOriginTransformPtr[12] = outOriginTransformPtr[13] = outOriginTransformPtr[14] = 0.0f;
37 static auto getInverseAndDirOp = [](
const QVector3D &
dir,
QVector3D &invDir, DirectionOp (&dirOp)[3]) {
38 for (
int i = 0;
i != 3; ++
i) {
39 const float axisDir =
dir[
i];
40 dirOp[
i] =
qFuzzyIsNull(axisDir) ? DirectionOp::Zero : ((axisDir < -std::numeric_limits<float>::epsilon())
42 : DirectionOp::Normal);
48 getInverseAndDirOp(transformedDirection, transformedDirectionInvers, dirOp);
49 return RayData{ globalTransform, ray, transformedOrigin, transformedDirectionInvers,
50 transformedDirection, { dirOp[0], dirOp[1], dirOp[2] } };
64 const QVector3D &cameraToLocal =
data.ray.origin - globalPosition;
67 const auto &boundsMin = bounds.
minimum;
68 const auto &boundsMax = bounds.
maximum;
69 const float xRange = boundsMax.
x() - boundsMin.x();
70 const float yRange = boundsMax.y() - boundsMin.y();
71 const QVector2D uvCoords{((localPosition[0] - boundsMin.
x()) / xRange), ((localPosition[1] - boundsMin.
y()) / yRange)};
89 float tmax = std::numeric_limits<float>::max();
90 float tmin = std::numeric_limits<float>::min();
94 for (
int axis = 0; axis != 3; ++axis) {
100 return { -1.0f, -1.0f,
nullptr };
123 const float epsilon = std::numeric_limits<float>::epsilon();
144 if (u < 0.0f || u > determinant)
152 if (
v < 0.0f || ((u +
v) > determinant))
175 const float invDeterminant = 1.0f / determinant;
197 if (!bvh || !mesh || !mesh->
bvh)
201 if (bvh->
count != 0) {
210 if (hit.intersects())
214 if (hit.intersects())
225 Q_ASSERT(bvhTriangles.
size() >= triangleOffset + triangleCount);
229 for (
int i = triangleOffset;
i < triangleCount + triangleOffset; ++
i) {
230 const auto &triangle = bvhTriangles[
i];
246 const float w = 1.0f - u -
v;
247 const QVector3D localIntersectionPoint =
w * triangle->vertex1 +
248 u * triangle->vertex2 +
249 v * triangle->vertex3;
251 const QVector2D uvCoordinate =
w * triangle->uvCoord1 +
252 u * triangle->uvCoord2 +
253 v * triangle->uvCoord3;
256 localIntersectionPoint);
257 const QVector3D hitVector =
data.ray.origin - sceneIntersectionPos;
262 sceneIntersectionPos,
263 localIntersectionPoint,
279 float *outOriginTransformPtr(theOriginTransform.
data());
280 outOriginTransformPtr[12] = outOriginTransformPtr[13] = outOriginTransformPtr[14] = 0.0f;
305 const QSSGRenderRay relativeRay(theTransformedOrigin, theTransformedDirection);
307 if (localIsect.has_value()) {
qsizetype size() const noexcept
bool isEmpty() const noexcept
void append(parameter_type t)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
float * data()
Returns a pointer to the raw data of this matrix.
QMatrix4x4 inverted(bool *invertible=nullptr) const
Returns the inverse of this matrix.
Class representing 3D range or axis aligned bounding box.
Representation of a plane.
float d
The distance from the origin.
QVector3D n
The normal to the plane.
The QVector2D class represents a vector or vertex in 2D space.
The QVector3D class represents a vector or vertex in 3D space.
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
Combined button and popup list for selecting options.
QVector3D Q_QUICK3DUTILS_EXPORT transform(const QMatrix4x4 &m, const QVector3D &v)
QVector3D Q_QUICK3DUTILS_EXPORT rotate(const QMatrix4x4 &m, const QVector3D &v)
float Q_QUICK3DUTILS_EXPORT magnitudeSquared(const QVector3D &v)
bool qFuzzyIsNull(qfloat16 f) noexcept
GLint GLfloat GLfloat GLfloat v2
GLsizei const GLfloat * v
[13]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static const qreal epsilon
QVector< QSSGMeshBVHTriangle * > triangles
const QSSGBounds3 * bounds
static void intersectWithBVH(const RayData &data, const QSSGMeshBVHNode *bvh, const QSSGRenderMesh *mesh, QVector< IntersectionResult > &intersections, int depth=0)
static std::optional< QVector3D > intersect(const QSSGPlane &inPlane, const QSSGRenderRay &ray)
static bool triangleIntersect(const QSSGRenderRay &ray, const QVector3D &v0, const QVector3D &v1, const QVector3D &v2, float &u, float &v, QVector3D &normal)
static QVector< IntersectionResult > intersectWithBVHTriangles(const RayData &data, const QVector< QSSGMeshBVHTriangle * > &bvhTriangles, int triangleOffset, int triangleCount)
static IntersectionResult createIntersectionResult(const RayData &data, const HitResult &hit)
static RayData createRayData(const QMatrix4x4 &globalTransform, const QSSGRenderRay &ray)
std::optional< QVector2D > relative(const QMatrix4x4 &inGlobalTransform, const QSSGBounds3 &inBounds, QSSGRenderBasisPlanes inPlane) const
static HitResult intersectWithAABBv2(const RayData &data, const QSSGBounds3 &bounds)