mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:57:58 +02:00
clean up some debugging spew. take dimensions into account when scaling points used for collision hull creation
This commit is contained in:
parent
f31ac8b968
commit
c8ad82917e
5 changed files with 64 additions and 18 deletions
|
@ -266,6 +266,14 @@ bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& ori
|
||||||
return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo, precisionPicking);
|
return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo, precisionPicking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderableModelEntityItem::updateDimensions(const glm::vec3& value) {
|
||||||
|
if (glm::distance(_dimensions, value) > MIN_DIMENSIONS_DELTA) {
|
||||||
|
_dimensions = value;
|
||||||
|
_dirtyFlags |= (EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS);
|
||||||
|
}
|
||||||
|
_model->setScaleToFit(true, _dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
bool RenderableModelEntityItem::isReadyToComputeShape() {
|
bool RenderableModelEntityItem::isReadyToComputeShape() {
|
||||||
|
|
||||||
if (!_model) {
|
if (!_model) {
|
||||||
|
@ -294,6 +302,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry();
|
const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry();
|
||||||
const FBXGeometry& fbxGeometry = collisionNetworkGeometry->getFBXGeometry();
|
const FBXGeometry& fbxGeometry = collisionNetworkGeometry->getFBXGeometry();
|
||||||
|
|
||||||
|
AABox aaBox;
|
||||||
_points.clear();
|
_points.clear();
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
foreach (const FBXMesh& mesh, fbxGeometry.meshes) {
|
foreach (const FBXMesh& mesh, fbxGeometry.meshes) {
|
||||||
|
@ -301,15 +310,29 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
||||||
QVector<glm::vec3> pointsInPart;
|
QVector<glm::vec3> pointsInPart;
|
||||||
unsigned int triangleCount = meshPart.triangleIndices.size() / 3;
|
unsigned int triangleCount = meshPart.triangleIndices.size() / 3;
|
||||||
for (unsigned int i = 0; i < triangleCount; i++) {
|
assert((unsigned int)meshPart.triangleIndices.size() == triangleCount*3);
|
||||||
unsigned int p0Index = meshPart.triangleIndices[i*3];
|
for (unsigned int j = 0; j < triangleCount; j++) {
|
||||||
unsigned int p1Index = meshPart.triangleIndices[i*3+1];
|
unsigned int p0Index = meshPart.triangleIndices[j*3];
|
||||||
unsigned int p2Index = meshPart.triangleIndices[i*3+2];
|
unsigned int p1Index = meshPart.triangleIndices[j*3+1];
|
||||||
|
unsigned int p2Index = meshPart.triangleIndices[j*3+2];
|
||||||
|
|
||||||
|
assert(p0Index < (unsigned int)mesh.vertices.size());
|
||||||
|
assert(p1Index < (unsigned int)mesh.vertices.size());
|
||||||
|
assert(p2Index < (unsigned int)mesh.vertices.size());
|
||||||
|
|
||||||
|
// glm::vec3 p0 = mesh.vertices[p0Index] * scale[0];
|
||||||
|
// glm::vec3 p1 = mesh.vertices[p1Index] * scale[1];
|
||||||
|
// glm::vec3 p2 = mesh.vertices[p2Index] * scale[2];
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 p0 = mesh.vertices[p0Index];
|
glm::vec3 p0 = mesh.vertices[p0Index];
|
||||||
glm::vec3 p1 = mesh.vertices[p1Index];
|
glm::vec3 p1 = mesh.vertices[p1Index];
|
||||||
glm::vec3 p2 = mesh.vertices[p2Index];
|
glm::vec3 p2 = mesh.vertices[p2Index];
|
||||||
|
|
||||||
|
aaBox += p0;
|
||||||
|
aaBox += p1;
|
||||||
|
aaBox += p2;
|
||||||
|
|
||||||
if (!pointsInPart.contains(p0)) {
|
if (!pointsInPart.contains(p0)) {
|
||||||
pointsInPart << p0;
|
pointsInPart << p0;
|
||||||
}
|
}
|
||||||
|
@ -327,7 +350,21 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.setParams(getShapeType(), 0.5f * getDimensions(), _collisionModelURL);
|
// make sure we aren't about to divide by zero
|
||||||
|
glm::vec3 aaBoxDim = aaBox.getDimensions();
|
||||||
|
aaBoxDim = glm::clamp(aaBoxDim, glm::vec3(FLT_EPSILON), aaBoxDim);
|
||||||
|
|
||||||
|
// scale = dimensions / aabox
|
||||||
|
glm::vec3 scale = _dimensions / aaBoxDim;
|
||||||
|
|
||||||
|
// multiply each point by scale before handing the point-set off to the physics engine
|
||||||
|
for (int i = 0; i < _points.size(); i++) {
|
||||||
|
for (int j = 0; j < _points[i].size(); j++) {
|
||||||
|
_points[i][j] *= scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info.setParams(getShapeType(), _dimensions, _collisionModelURL);
|
||||||
info.setConvexHulls(_points);
|
info.setConvexHulls(_points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ public:
|
||||||
|
|
||||||
bool needsToCallUpdate() const;
|
bool needsToCallUpdate() const;
|
||||||
|
|
||||||
|
virtual void updateDimensions(const glm::vec3& value);
|
||||||
|
|
||||||
bool isReadyToComputeShape();
|
bool isReadyToComputeShape();
|
||||||
void computeShapeInfo(ShapeInfo& info);
|
void computeShapeInfo(ShapeInfo& info);
|
||||||
ShapeType getShapeType() const;
|
ShapeType getShapeType() const;
|
||||||
|
|
|
@ -40,6 +40,15 @@ class EntityTreeElementExtraEncodeData;
|
||||||
#define debugTreeVector(V) V << "[" << V << " in meters ]"
|
#define debugTreeVector(V) V << "[" << V << " in meters ]"
|
||||||
|
|
||||||
|
|
||||||
|
extern const float MIN_POSITION_DELTA;
|
||||||
|
extern const float MIN_DIMENSIONS_DELTA;
|
||||||
|
extern const float MIN_ALIGNMENT_DOT;
|
||||||
|
extern const float MIN_VELOCITY_DELTA;
|
||||||
|
extern const float MIN_DAMPING_DELTA;
|
||||||
|
extern const float MIN_GRAVITY_DELTA;
|
||||||
|
extern const float MIN_SPIN_DELTA;
|
||||||
|
|
||||||
|
|
||||||
/// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available
|
/// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available
|
||||||
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
||||||
/// one directly, instead you must only construct one of it's derived classes with additional features.
|
/// one directly, instead you must only construct one of it's derived classes with additional features.
|
||||||
|
@ -270,7 +279,7 @@ public:
|
||||||
void updatePositionInDomainUnits(const glm::vec3& value);
|
void updatePositionInDomainUnits(const glm::vec3& value);
|
||||||
void updatePosition(const glm::vec3& value);
|
void updatePosition(const glm::vec3& value);
|
||||||
void updateDimensionsInDomainUnits(const glm::vec3& value);
|
void updateDimensionsInDomainUnits(const glm::vec3& value);
|
||||||
void updateDimensions(const glm::vec3& value);
|
virtual void updateDimensions(const glm::vec3& value);
|
||||||
void updateRotation(const glm::quat& rotation);
|
void updateRotation(const glm::quat& rotation);
|
||||||
void updateDensity(float value);
|
void updateDensity(float value);
|
||||||
void updateMass(float value);
|
void updateMass(float value);
|
||||||
|
|
|
@ -77,10 +77,12 @@ void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInf
|
||||||
const int numPoints = convexHullShape->getNumPoints();
|
const int numPoints = convexHullShape->getNumPoints();
|
||||||
const btVector3* btPoints = convexHullShape->getUnscaledPoints();
|
const btVector3* btPoints = convexHullShape->getUnscaledPoints();
|
||||||
QVector<QVector<glm::vec3>> points;
|
QVector<QVector<glm::vec3>> points;
|
||||||
|
QVector<glm::vec3> childPoints;
|
||||||
for (int i = 0; i < numPoints; i++) {
|
for (int i = 0; i < numPoints; i++) {
|
||||||
glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ());
|
glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ());
|
||||||
points[0] << point;
|
childPoints << point;
|
||||||
}
|
}
|
||||||
|
points << childPoints;
|
||||||
info.setConvexHulls(points);
|
info.setConvexHulls(points);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -116,9 +118,6 @@ void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInf
|
||||||
|
|
||||||
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
||||||
btCollisionShape* shape = NULL;
|
btCollisionShape* shape = NULL;
|
||||||
|
|
||||||
qDebug() << "\n\nHERE" << info.getType();
|
|
||||||
|
|
||||||
switch(info.getType()) {
|
switch(info.getType()) {
|
||||||
case SHAPE_TYPE_BOX: {
|
case SHAPE_TYPE_BOX: {
|
||||||
shape = new btBoxShape(glmToBullet(info.getHalfExtents()));
|
shape = new btBoxShape(glmToBullet(info.getHalfExtents()));
|
||||||
|
@ -149,13 +148,8 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
||||||
shape = new btCompoundShape();
|
shape = new btCompoundShape();
|
||||||
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
const QVector<QVector<glm::vec3>>& points = info.getPoints();
|
||||||
|
|
||||||
qDebug() << "\n\nSHAPE_TYPE_COMPOUND" << info.getPoints().size() << "hulls.";
|
|
||||||
|
|
||||||
foreach (QVector<glm::vec3> hullPoints, info.getPoints()) {
|
foreach (QVector<glm::vec3> hullPoints, info.getPoints()) {
|
||||||
auto hull = new btConvexHullShape();
|
auto hull = new btConvexHullShape();
|
||||||
|
|
||||||
qDebug() << " SHAPE_TYPE_COMPOUND" << hullPoints.size() << "points in hull.";
|
|
||||||
|
|
||||||
foreach (glm::vec3 point, hullPoints) {
|
foreach (glm::vec3 point, hullPoints) {
|
||||||
btVector3 btPoint(point[0], point[1], point[2]);
|
btVector3 btPoint(point[0], point[1], point[2]);
|
||||||
hull->addPoint(btPoint);
|
hull->addPoint(btPoint);
|
||||||
|
@ -165,9 +159,6 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
||||||
static_cast<btCompoundShape*>(shape)->addChildShape (trans, hull);
|
static_cast<btCompoundShape*>(shape)->addChildShape (trans, hull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "DONE, getNumChildShapes =" << static_cast<btCompoundShape*>(shape)->getNumChildShapes();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return shape;
|
return shape;
|
||||||
|
|
|
@ -38,6 +38,8 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString
|
||||||
}
|
}
|
||||||
case SHAPE_TYPE_CONVEX_HULL:
|
case SHAPE_TYPE_CONVEX_HULL:
|
||||||
_url = QUrl(url);
|
_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;
|
_halfExtents = halfExtents;
|
||||||
break;
|
break;
|
||||||
case SHAPE_TYPE_COMPOUND:
|
case SHAPE_TYPE_COMPOUND:
|
||||||
|
@ -51,18 +53,21 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeInfo::setBox(const glm::vec3& halfExtents) {
|
void ShapeInfo::setBox(const glm::vec3& halfExtents) {
|
||||||
|
_url = "";
|
||||||
_type = SHAPE_TYPE_BOX;
|
_type = SHAPE_TYPE_BOX;
|
||||||
_halfExtents = halfExtents;
|
_halfExtents = halfExtents;
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeInfo::setSphere(float radius) {
|
void ShapeInfo::setSphere(float radius) {
|
||||||
|
_url = "";
|
||||||
_type = SHAPE_TYPE_SPHERE;
|
_type = SHAPE_TYPE_SPHERE;
|
||||||
_halfExtents = glm::vec3(radius, radius, radius);
|
_halfExtents = glm::vec3(radius, radius, radius);
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) {
|
void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) {
|
||||||
|
_url = "";
|
||||||
_type = SHAPE_TYPE_ELLIPSOID;
|
_type = SHAPE_TYPE_ELLIPSOID;
|
||||||
_halfExtents = halfExtents;
|
_halfExtents = halfExtents;
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
|
@ -75,9 +80,11 @@ void ShapeInfo::setConvexHulls(const QVector<QVector<glm::vec3>>& points) {
|
||||||
_type = SHAPE_TYPE_COMPOUND;
|
_type = SHAPE_TYPE_COMPOUND;
|
||||||
}
|
}
|
||||||
_points = points;
|
_points = points;
|
||||||
|
_doubleHashKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeInfo::setCapsuleY(float radius, float halfHeight) {
|
void ShapeInfo::setCapsuleY(float radius, float halfHeight) {
|
||||||
|
_url = "";
|
||||||
_type = SHAPE_TYPE_CAPSULE_Y;
|
_type = SHAPE_TYPE_CAPSULE_Y;
|
||||||
_halfExtents = glm::vec3(radius, halfHeight, radius);
|
_halfExtents = glm::vec3(radius, halfHeight, radius);
|
||||||
_doubleHashKey.clear();
|
_doubleHashKey.clear();
|
||||||
|
|
Loading…
Reference in a new issue