mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 05:09:23 +02:00
remove SHAPE_TYPE_CONVEX_HULL from libs and tests
This commit is contained in:
parent
9388ae4212
commit
da9091a99d
6 changed files with 39 additions and 163 deletions
|
@ -14,107 +14,6 @@
|
||||||
#include "ShapeInfoUtil.h"
|
#include "ShapeInfoUtil.h"
|
||||||
#include "BulletUtil.h"
|
#include "BulletUtil.h"
|
||||||
|
|
||||||
int ShapeInfoUtil::toBulletShapeType(int shapeInfoType) {
|
|
||||||
int bulletShapeType = INVALID_SHAPE_PROXYTYPE;
|
|
||||||
switch(shapeInfoType) {
|
|
||||||
case SHAPE_TYPE_BOX:
|
|
||||||
bulletShapeType = BOX_SHAPE_PROXYTYPE;
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_SPHERE:
|
|
||||||
bulletShapeType = SPHERE_SHAPE_PROXYTYPE;
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_CAPSULE_Y:
|
|
||||||
bulletShapeType = CAPSULE_SHAPE_PROXYTYPE;
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_CONVEX_HULL:
|
|
||||||
bulletShapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_COMPOUND:
|
|
||||||
bulletShapeType = COMPOUND_SHAPE_PROXYTYPE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return bulletShapeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ShapeInfoUtil::fromBulletShapeType(int bulletShapeType) {
|
|
||||||
int shapeInfoType = SHAPE_TYPE_NONE;
|
|
||||||
switch(bulletShapeType) {
|
|
||||||
case BOX_SHAPE_PROXYTYPE:
|
|
||||||
shapeInfoType = SHAPE_TYPE_BOX;
|
|
||||||
break;
|
|
||||||
case SPHERE_SHAPE_PROXYTYPE:
|
|
||||||
shapeInfoType = SHAPE_TYPE_SPHERE;
|
|
||||||
break;
|
|
||||||
case CAPSULE_SHAPE_PROXYTYPE:
|
|
||||||
shapeInfoType = SHAPE_TYPE_CAPSULE_Y;
|
|
||||||
break;
|
|
||||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
|
||||||
shapeInfoType = SHAPE_TYPE_CONVEX_HULL;
|
|
||||||
break;
|
|
||||||
case COMPOUND_SHAPE_PROXYTYPE:
|
|
||||||
shapeInfoType = SHAPE_TYPE_COMPOUND;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return shapeInfoType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInfo& info) {
|
|
||||||
if (shape) {
|
|
||||||
int type = ShapeInfoUtil::fromBulletShapeType(shape->getShapeType());
|
|
||||||
switch(type) {
|
|
||||||
case SHAPE_TYPE_BOX: {
|
|
||||||
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
|
|
||||||
info.setBox(bulletToGLM(boxShape->getHalfExtentsWithMargin()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_SPHERE: {
|
|
||||||
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
|
|
||||||
info.setSphere(sphereShape->getRadius());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_CONVEX_HULL: {
|
|
||||||
const btConvexHullShape* convexHullShape = static_cast<const btConvexHullShape*>(shape);
|
|
||||||
const int numPoints = convexHullShape->getNumPoints();
|
|
||||||
const btVector3* btPoints = convexHullShape->getUnscaledPoints();
|
|
||||||
QVector<QVector<glm::vec3>> points;
|
|
||||||
QVector<glm::vec3> childPoints;
|
|
||||||
for (int i = 0; i < numPoints; i++) {
|
|
||||||
glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ());
|
|
||||||
childPoints << point;
|
|
||||||
}
|
|
||||||
points << childPoints;
|
|
||||||
info.setConvexHulls(points);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_COMPOUND: {
|
|
||||||
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
|
||||||
const int numChildShapes = compoundShape->getNumChildShapes();
|
|
||||||
QVector<QVector<glm::vec3>> points;
|
|
||||||
for (int i = 0; i < numChildShapes; i ++) {
|
|
||||||
const btCollisionShape* childShape = compoundShape->getChildShape(i);
|
|
||||||
const btConvexHullShape* convexHullShape = static_cast<const btConvexHullShape*>(childShape);
|
|
||||||
const int numPoints = convexHullShape->getNumPoints();
|
|
||||||
const btVector3* btPoints = convexHullShape->getUnscaledPoints();
|
|
||||||
|
|
||||||
QVector<glm::vec3> childPoints;
|
|
||||||
for (int j = 0; j < numPoints; j++) {
|
|
||||||
glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ());
|
|
||||||
childPoints << point;
|
|
||||||
}
|
|
||||||
points << childPoints;
|
|
||||||
}
|
|
||||||
info.setConvexHulls(points);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
info.clear();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
info.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
||||||
btCollisionShape* shape = NULL;
|
btCollisionShape* shape = NULL;
|
||||||
|
@ -135,33 +34,34 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
||||||
shape = new btCapsuleShape(radius, height);
|
shape = new btCapsuleShape(radius, height);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SHAPE_TYPE_CONVEX_HULL: {
|
|
||||||
auto hull = new btConvexHullShape();
|
|
||||||
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
|
||||||
foreach (glm::vec3 point, points[0]) {
|
|
||||||
btVector3 btPoint(point[0], point[1], point[2]);
|
|
||||||
hull->addPoint(btPoint, false);
|
|
||||||
}
|
|
||||||
hull->recalcLocalAabb();
|
|
||||||
shape = hull;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_COMPOUND: {
|
case SHAPE_TYPE_COMPOUND: {
|
||||||
auto compound = new btCompoundShape();
|
|
||||||
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
||||||
|
uint32_t numSubShapes = info.getNumSubShapes();
|
||||||
btTransform trans;
|
if (numSubShapes == 1) {
|
||||||
trans.setIdentity();
|
|
||||||
foreach (QVector<glm::vec3> hullPoints, points) {
|
|
||||||
auto hull = new btConvexHullShape();
|
auto hull = new btConvexHullShape();
|
||||||
foreach (glm::vec3 point, hullPoints) {
|
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
||||||
|
foreach (glm::vec3 point, points[0]) {
|
||||||
btVector3 btPoint(point[0], point[1], point[2]);
|
btVector3 btPoint(point[0], point[1], point[2]);
|
||||||
hull->addPoint(btPoint, false);
|
hull->addPoint(btPoint, false);
|
||||||
}
|
}
|
||||||
hull->recalcLocalAabb();
|
hull->recalcLocalAabb();
|
||||||
compound->addChildShape (trans, hull);
|
shape = hull;
|
||||||
|
} else {
|
||||||
|
assert(numSubShapes > 1);
|
||||||
|
auto compound = new btCompoundShape();
|
||||||
|
btTransform trans;
|
||||||
|
trans.setIdentity();
|
||||||
|
foreach (QVector<glm::vec3> hullPoints, points) {
|
||||||
|
auto hull = new btConvexHullShape();
|
||||||
|
foreach (glm::vec3 point, hullPoints) {
|
||||||
|
btVector3 btPoint(point[0], point[1], point[2]);
|
||||||
|
hull->addPoint(btPoint, false);
|
||||||
|
}
|
||||||
|
hull->recalcLocalAabb();
|
||||||
|
compound->addChildShape (trans, hull);
|
||||||
|
}
|
||||||
|
shape = compound;
|
||||||
}
|
}
|
||||||
shape = compound;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,10 @@
|
||||||
|
|
||||||
// translates between ShapeInfo and btShape
|
// translates between ShapeInfo and btShape
|
||||||
|
|
||||||
|
// TODO: rename this to ShapeFactory
|
||||||
namespace ShapeInfoUtil {
|
namespace ShapeInfoUtil {
|
||||||
|
|
||||||
// XXX is collectInfoFromShape no longer strictly needed?
|
|
||||||
void collectInfoFromShape(const btCollisionShape* shape, ShapeInfo& info);
|
|
||||||
|
|
||||||
btCollisionShape* createShapeFromInfo(const ShapeInfo& info);
|
btCollisionShape* createShapeFromInfo(const ShapeInfo& info);
|
||||||
|
|
||||||
// TODO? just use bullet shape types everywhere?
|
|
||||||
int toBulletShapeType(int shapeInfoType);
|
|
||||||
int fromBulletShapeType(int bulletShapeType);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ShapeInfoUtil_h
|
#endif // hifi_ShapeInfoUtil_h
|
||||||
|
|
|
@ -37,12 +37,6 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString
|
||||||
_halfExtents = glm::vec3(radius);
|
_halfExtents = glm::vec3(radius);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHAPE_TYPE_CONVEX_HULL:
|
|
||||||
_url = QUrl(url);
|
|
||||||
// halfExtents aren't used by convex-hull or compound convex-hull except as part of
|
|
||||||
// the generation of the key for the ShapeManager.
|
|
||||||
_halfExtents = halfExtents;
|
|
||||||
break;
|
|
||||||
case SHAPE_TYPE_COMPOUND:
|
case SHAPE_TYPE_COMPOUND:
|
||||||
_url = QUrl(url);
|
_url = QUrl(url);
|
||||||
_halfExtents = halfExtents;
|
_halfExtents = halfExtents;
|
||||||
|
@ -78,12 +72,8 @@ void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeInfo::setConvexHulls(const QVector<QVector<glm::vec3>>& points) {
|
void ShapeInfo::setConvexHulls(const QVector<QVector<glm::vec3>>& points) {
|
||||||
if (points.size() == 1) {
|
|
||||||
_type = SHAPE_TYPE_CONVEX_HULL;
|
|
||||||
} else {
|
|
||||||
_type = SHAPE_TYPE_COMPOUND;
|
|
||||||
}
|
|
||||||
_points = points;
|
_points = points;
|
||||||
|
_type = (_points.size() > 0) ? SHAPE_TYPE_COMPOUND : SHAPE_TYPE_NONE;
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +85,14 @@ void ShapeInfo::setCapsuleY(float radius, float halfHeight) {
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t ShapeInfo::getNumSubShapes() const {
|
||||||
|
if (_type == SHAPE_TYPE_NONE) {
|
||||||
|
return 0;
|
||||||
|
} else if (_type == SHAPE_TYPE_COMPOUND) {
|
||||||
|
return _points.size();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
float ShapeInfo::computeVolume() const {
|
float ShapeInfo::computeVolume() const {
|
||||||
const float DEFAULT_VOLUME = 1.0f;
|
const float DEFAULT_VOLUME = 1.0f;
|
||||||
float volume = DEFAULT_VOLUME;
|
float volume = DEFAULT_VOLUME;
|
||||||
|
|
|
@ -24,7 +24,6 @@ enum ShapeType {
|
||||||
SHAPE_TYPE_BOX,
|
SHAPE_TYPE_BOX,
|
||||||
SHAPE_TYPE_SPHERE,
|
SHAPE_TYPE_SPHERE,
|
||||||
SHAPE_TYPE_ELLIPSOID,
|
SHAPE_TYPE_ELLIPSOID,
|
||||||
SHAPE_TYPE_CONVEX_HULL,
|
|
||||||
SHAPE_TYPE_PLANE,
|
SHAPE_TYPE_PLANE,
|
||||||
SHAPE_TYPE_COMPOUND,
|
SHAPE_TYPE_COMPOUND,
|
||||||
SHAPE_TYPE_CAPSULE_X,
|
SHAPE_TYPE_CAPSULE_X,
|
||||||
|
@ -52,6 +51,7 @@ public:
|
||||||
const glm::vec3& getHalfExtents() const { return _halfExtents; }
|
const glm::vec3& getHalfExtents() const { return _halfExtents; }
|
||||||
|
|
||||||
const QVector<QVector<glm::vec3>>& getPoints() const { return _points; }
|
const QVector<QVector<glm::vec3>>& getPoints() const { return _points; }
|
||||||
|
uint32_t getNumSubShapes() const;
|
||||||
|
|
||||||
void clearPoints () { _points.clear(); }
|
void clearPoints () { _points.clear(); }
|
||||||
void appendToPoints (const QVector<glm::vec3>& newPoints) { _points << newPoints; }
|
void appendToPoints (const QVector<glm::vec3>& newPoints) { _points << newPoints; }
|
||||||
|
|
|
@ -147,9 +147,7 @@ void ShapeInfoTests::testBoxShape() {
|
||||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl;
|
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
DoubleHashKey otherKey = otherInfo.getHash();
|
DoubleHashKey otherKey = otherInfo.getHash();
|
||||||
if (key.getHash() != otherKey.getHash()) {
|
if (key.getHash() != otherKey.getHash()) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -172,9 +170,7 @@ void ShapeInfoTests::testSphereShape() {
|
||||||
|
|
||||||
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
DoubleHashKey otherKey = otherInfo.getHash();
|
DoubleHashKey otherKey = otherInfo.getHash();
|
||||||
if (key.getHash() != otherKey.getHash()) {
|
if (key.getHash() != otherKey.getHash()) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -198,9 +194,7 @@ void ShapeInfoTests::testCylinderShape() {
|
||||||
|
|
||||||
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
DoubleHashKey otherKey = otherInfo.getHash();
|
DoubleHashKey otherKey = otherInfo.getHash();
|
||||||
if (key.getHash() != otherKey.getHash()) {
|
if (key.getHash() != otherKey.getHash()) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -225,9 +219,7 @@ void ShapeInfoTests::testCapsuleShape() {
|
||||||
|
|
||||||
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
DoubleHashKey otherKey = otherInfo.getHash();
|
DoubleHashKey otherKey = otherInfo.getHash();
|
||||||
if (key.getHash() != otherKey.getHash()) {
|
if (key.getHash() != otherKey.getHash()) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
|
|
@ -187,9 +187,7 @@ void ShapeManagerTests::addBoxShape() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
if (shape != otherShape) {
|
if (shape != otherShape) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -205,9 +203,7 @@ void ShapeManagerTests::addSphereShape() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
if (shape != otherShape) {
|
if (shape != otherShape) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -225,9 +221,7 @@ void ShapeManagerTests::addCylinderShape() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
if (shape != otherShape) {
|
if (shape != otherShape) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
@ -246,9 +240,7 @@ void ShapeManagerTests::addCapsuleShape() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo;
|
ShapeInfo otherInfo = info;
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);
|
|
||||||
|
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
if (shape != otherShape) {
|
if (shape != otherShape) {
|
||||||
std::cout << __FILE__ << ":" << __LINE__
|
std::cout << __FILE__ << ":" << __LINE__
|
||||||
|
|
Loading…
Reference in a new issue