mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
trim high-point convex hulls
This commit is contained in:
parent
95f7ea5609
commit
7866fcf78c
4 changed files with 38 additions and 0 deletions
|
@ -217,6 +217,13 @@ void PhysicalEntitySimulation::getObjectsToAddToPhysics(VectorOfMotionStates& re
|
|||
} else if (entity->isReadyToComputeShape()) {
|
||||
ShapeInfo shapeInfo;
|
||||
entity->computeShapeInfo(shapeInfo);
|
||||
int numPoints = shapeInfo.getMaxNumPoints();
|
||||
const int MAX_HULL_POINTS = 42;
|
||||
if (numPoints > MAX_HULL_POINTS) {
|
||||
glm::vec3 p = entity->getPosition();
|
||||
qDebug() << "entity" << entity->getName() << "at <" << p.x << p.y << p.z << ">"
|
||||
<< "has convex hull with" << numPoints << "points";
|
||||
}
|
||||
btCollisionShape* shape = ObjectMotionState::getShapeManager()->getShape(shapeInfo);
|
||||
if (shape) {
|
||||
EntityMotionState* motionState = new EntityMotionState(shape, entity);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
//
|
||||
|
||||
#include <glm/gtx/norm.hpp>
|
||||
#include <BulletCollision/CollisionShapes/btShapeHull.h>
|
||||
|
||||
#include <SharedUtil.h> // for MILLIMETERS_PER_METER
|
||||
|
||||
|
@ -64,6 +65,23 @@ btConvexHullShape* ShapeFactory::createConvexHull(const QVector<glm::vec3>& poin
|
|||
correctedPoint = (points[i] - center) * relativeScale + center;
|
||||
hull->addPoint(btVector3(correctedPoint[0], correctedPoint[1], correctedPoint[2]), false);
|
||||
}
|
||||
|
||||
const int MAX_HULL_POINTS = 42;
|
||||
if (points.size() > MAX_HULL_POINTS) {
|
||||
// create hull approximation
|
||||
btShapeHull* shapeHull = new btShapeHull(hull);
|
||||
shapeHull->buildHull(margin);
|
||||
btConvexHullShape* newHull = new btConvexHullShape();
|
||||
const btVector3* newPoints = shapeHull->getVertexPointer();
|
||||
for (int i = 0; i < shapeHull->numVertices(); ++i) {
|
||||
newHull->addPoint(newPoints[i], false);
|
||||
}
|
||||
delete hull;
|
||||
delete shapeHull;
|
||||
hull = newHull;
|
||||
qDebug() << "reduced hull with" << points.size() << "points down to" << hull->getNumPoints(); // TODO: remove after testing
|
||||
}
|
||||
|
||||
hull->recalcLocalAabb();
|
||||
return hull;
|
||||
}
|
||||
|
|
|
@ -99,6 +99,18 @@ uint32_t ShapeInfo::getNumSubShapes() const {
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ShapeInfo::getMaxNumPoints() const {
|
||||
int numPoints = 0;
|
||||
for (int i = 0; i < _points.size(); ++i) {
|
||||
int n = _points[i].size();
|
||||
if (n > numPoints) {
|
||||
numPoints = n;
|
||||
}
|
||||
}
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
float ShapeInfo::computeVolume() const {
|
||||
const float DEFAULT_VOLUME = 1.0f;
|
||||
float volume = DEFAULT_VOLUME;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
void clearPoints () { _points.clear(); }
|
||||
void appendToPoints (const QVector<glm::vec3>& newPoints) { _points << newPoints; }
|
||||
int getMaxNumPoints() const;
|
||||
|
||||
float computeVolume() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue