mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:56:52 +02:00
Move contain function to FBXGeometry
This commit is contained in:
parent
9cec256142
commit
99b3ef0d75
3 changed files with 44 additions and 38 deletions
|
@ -420,42 +420,8 @@ bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
|
||||||
const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry();
|
const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry();
|
||||||
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
|
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
|
||||||
|
|
||||||
auto checkEachPrimitive = [=](FBXMesh& mesh, QVector<int> indices, int primitiveSize) -> bool {
|
return collisionGeometry.convexHullContains(point);
|
||||||
// Check whether the point is "behind" all the primitives.
|
|
||||||
for (unsigned int j = 0; j < indices.size(); j += primitiveSize) {
|
|
||||||
if (!isPointBehindTrianglesPlane(point,
|
|
||||||
mesh.vertices[indices[j]],
|
|
||||||
mesh.vertices[indices[j + 1]],
|
|
||||||
mesh.vertices[indices[j + 2]])) {
|
|
||||||
// it's not behind at least one so we bail
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check that the point is contained in at least one convex mesh.
|
|
||||||
for (auto mesh : collisionGeometry.meshes) {
|
|
||||||
bool insideMesh = true;
|
|
||||||
|
|
||||||
// To be considered inside a convex mesh,
|
|
||||||
// the point needs to be "behind" all the primitives respective planes.
|
|
||||||
for (auto part : mesh.parts) {
|
|
||||||
// run through all the triangles and quads
|
|
||||||
if (!checkEachPrimitive(mesh, part.triangleIndices, 3) ||
|
|
||||||
!checkEachPrimitive(mesh, part.quadIndices, 4)) {
|
|
||||||
// If not, the point is outside, bail for this mesh
|
|
||||||
insideMesh = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (insideMesh) {
|
|
||||||
// It's inside this mesh, return true.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// It wasn't in any mesh, return false.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,47 @@ Extents FBXGeometry::getUnscaledMeshExtents() const {
|
||||||
return scaledExtents;
|
return scaledExtents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move to model::Mesh when Sam's ready
|
||||||
|
bool FBXGeometry::convexHullContains(const glm::vec3& point) const {
|
||||||
|
auto checkEachPrimitive = [=](FBXMesh& mesh, QVector<int> indices, int primitiveSize) -> bool {
|
||||||
|
// Check whether the point is "behind" all the primitives.
|
||||||
|
for (unsigned int j = 0; j < indices.size(); j += primitiveSize) {
|
||||||
|
if (!isPointBehindTrianglesPlane(point,
|
||||||
|
mesh.vertices[indices[j]],
|
||||||
|
mesh.vertices[indices[j + 1]],
|
||||||
|
mesh.vertices[indices[j + 2]])) {
|
||||||
|
// it's not behind at least one so we bail
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check that the point is contained in at least one convex mesh.
|
||||||
|
for (auto mesh : meshes) {
|
||||||
|
bool insideMesh = true;
|
||||||
|
|
||||||
|
// To be considered inside a convex mesh,
|
||||||
|
// the point needs to be "behind" all the primitives respective planes.
|
||||||
|
for (auto part : mesh.parts) {
|
||||||
|
// run through all the triangles and quads
|
||||||
|
if (!checkEachPrimitive(mesh, part.triangleIndices, 3) ||
|
||||||
|
!checkEachPrimitive(mesh, part.quadIndices, 4)) {
|
||||||
|
// If not, the point is outside, bail for this mesh
|
||||||
|
insideMesh = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (insideMesh) {
|
||||||
|
// It's inside this mesh, return true.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// It wasn't in any mesh, return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QString FBXGeometry::getModelNameOfMesh(int meshIndex) const {
|
QString FBXGeometry::getModelNameOfMesh(int meshIndex) const {
|
||||||
if (meshIndicesToModelNames.contains(meshIndex)) {
|
if (meshIndicesToModelNames.contains(meshIndex)) {
|
||||||
return meshIndicesToModelNames.value(meshIndex);
|
return meshIndicesToModelNames.value(meshIndex);
|
||||||
|
@ -132,8 +173,6 @@ QString FBXGeometry::getModelNameOfMesh(int meshIndex) const {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int fbxGeometryMetaTypeId = qRegisterMetaType<FBXGeometry>();
|
static int fbxGeometryMetaTypeId = qRegisterMetaType<FBXGeometry>();
|
||||||
static int fbxAnimationFrameMetaTypeId = qRegisterMetaType<FBXAnimationFrame>();
|
static int fbxAnimationFrameMetaTypeId = qRegisterMetaType<FBXAnimationFrame>();
|
||||||
static int fbxAnimationFrameVectorMetaTypeId = qRegisterMetaType<QVector<FBXAnimationFrame> >();
|
static int fbxAnimationFrameVectorMetaTypeId = qRegisterMetaType<QVector<FBXAnimationFrame> >();
|
||||||
|
|
|
@ -252,6 +252,7 @@ public:
|
||||||
/// Returns the unscaled extents of the model's mesh
|
/// Returns the unscaled extents of the model's mesh
|
||||||
Extents getUnscaledMeshExtents() const;
|
Extents getUnscaledMeshExtents() const;
|
||||||
|
|
||||||
|
bool convexHullContains(const glm::vec3& point) const;
|
||||||
|
|
||||||
QHash<int, QString> meshIndicesToModelNames;
|
QHash<int, QString> meshIndicesToModelNames;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue