From 9346171695830c30442ffdd2dc2758e44828aed7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 4 Mar 2016 16:47:30 -0800 Subject: [PATCH 1/9] if entity registration isn't default, adjust physics shapes to match --- .../src/RenderableModelEntityItem.cpp | 2 ++ .../src/RenderablePolyVoxEntityItem.cpp | 1 + libraries/entities/src/EntityItem.cpp | 22 +++++++++++++++++-- libraries/entities/src/EntityItem.h | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e3870705c9..1577cac10c 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -598,6 +598,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { if (type != SHAPE_TYPE_COMPOUND) { ModelEntityItem::computeShapeInfo(info); info.setParams(type, 0.5f * getDimensions()); + adjustShapeInfoByRegistration(info); } else { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); @@ -701,6 +702,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { glm::vec3 collisionModelDimensions = box.getDimensions(); info.setParams(type, collisionModelDimensions, _compoundShapeURL); info.setConvexHulls(_points); + adjustShapeInfoByRegistration(info); } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index ef777df403..8054ed9a8b 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -1228,6 +1228,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { _shapeInfoLock.lockForWrite(); _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, QString(b64)); _shapeInfo.setConvexHulls(points); + adjustShapeInfoByRegistration(_shapeInfo); _shapeInfoLock.unlock(); _meshLock.lockForWrite(); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 04ca7559a0..c421f3826d 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -677,7 +677,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_LIFETIME, float, updateLifetime); READ_ENTITY_PROPERTY(PROP_SCRIPT, QString, setScript); READ_ENTITY_PROPERTY(PROP_SCRIPT_TIMESTAMP, quint64, setScriptTimestamp); - READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint); + READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, updateRegistrationPoint); READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, updateAngularDamping); READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, setVisible); @@ -1120,7 +1120,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { // these (along with "position" above) affect tree structure SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, updateDimensions); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(registrationPoint, setRegistrationPoint); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(registrationPoint, updateRegistrationPoint); // these (along with all properties above) affect the simulation SET_ENTITY_PROPERTY_FROM_PROPERTIES(density, updateDensity); @@ -1340,6 +1340,15 @@ float EntityItem::getRadius() const { return 0.5f * glm::length(getDimensions()); } +void EntityItem::adjustShapeInfoByRegistration(ShapeInfo& info) const { + if (_registrationPoint != ENTITY_ITEM_DEFAULT_REGISTRATION_POINT) { + glm::mat4 scale = glm::scale(getDimensions()); + glm::mat4 registration = scale * glm::translate(ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()); + glm::vec3 regTransVec = glm::vec3(registration[3]); // extract position component from matrix + info.setOffset(regTransVec); + } +} + bool EntityItem::contains(const glm::vec3& point) const { if (getShapeType() == SHAPE_TYPE_COMPOUND) { bool success; @@ -1348,12 +1357,21 @@ bool EntityItem::contains(const glm::vec3& point) const { } else { ShapeInfo info; info.setParams(getShapeType(), glm::vec3(0.5f)); + adjustShapeInfoByRegistration(info); return info.contains(worldToEntity(point)); } } void EntityItem::computeShapeInfo(ShapeInfo& info) { info.setParams(getShapeType(), 0.5f * getDimensions()); + adjustShapeInfoByRegistration(info); +} + +void EntityItem::updateRegistrationPoint(const glm::vec3& value) { + if (value != _registrationPoint) { + setRegistrationPoint(value); + _dirtyFlags |= Simulation::DIRTY_SHAPE; + } } void EntityItem::updatePosition(const glm::vec3& value) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 975f571eb3..d327bd9004 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -305,6 +305,7 @@ public: // TODO: get rid of users of getRadius()... float getRadius() const; + virtual void adjustShapeInfoByRegistration(ShapeInfo& info) const; virtual bool contains(const glm::vec3& point) const; virtual bool isReadyToComputeShape() { return !isDead(); } @@ -319,6 +320,7 @@ public: virtual void setRotation(glm::quat orientation) { setOrientation(orientation); } // updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags + void updateRegistrationPoint(const glm::vec3& value); void updatePosition(const glm::vec3& value); void updatePositionFromNetwork(const glm::vec3& value); void updateDimensions(const glm::vec3& value); From 8bc2c76a8b59c995db92a65179e6d13e3b160586 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 5 Mar 2016 08:01:30 -0800 Subject: [PATCH 2/9] change shape-key when registration point changes so shape cache doesn't incorrectly reuse the old shape --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 6 +++++- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 1577cac10c..3b100cc4dd 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -700,7 +700,11 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { } glm::vec3 collisionModelDimensions = box.getDimensions(); - info.setParams(type, collisionModelDimensions, _compoundShapeURL); + QString shapeKey = _compoundShapeURL + "," + + QString::number(_registrationPoint.x) + "," + + QString::number(_registrationPoint.y) + "," + + QString::number(_registrationPoint.z); + info.setParams(type, collisionModelDimensions, shapeKey); info.setConvexHulls(_points); adjustShapeInfoByRegistration(info); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 8054ed9a8b..f59a943353 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -1224,9 +1224,12 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { } glm::vec3 collisionModelDimensions = box.getDimensions(); - QByteArray b64 = _voxelData.toBase64(); + QString shapeKey = QString(_voxelData.toBase64()) + "," + + QString::number(_registrationPoint.x) + "," + + QString::number(_registrationPoint.y) + "," + + QString::number(_registrationPoint.z); _shapeInfoLock.lockForWrite(); - _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, QString(b64)); + _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey); _shapeInfo.setConvexHulls(points); adjustShapeInfoByRegistration(_shapeInfo); _shapeInfoLock.unlock(); From 5241dc5394551a0c37aff3b84dff2e802fb25698 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 12:48:01 -0800 Subject: [PATCH 3/9] this seems to be working now. more cleanups to come --- .../src/RenderableModelEntityItem.cpp | 61 ++++++++++++------- .../src/RenderableModelEntityItem.h | 1 + libraries/physics/src/ShapeFactory.cpp | 17 +++++- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3b100cc4dd..3f46c5bf83 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -336,6 +336,37 @@ bool RenderableModelEntityItem::getAnimationFrame() { return newFrame; } +void RenderableModelEntityItem::updateModelBounds() { + if (!hasModel() || !_model) { + return; + } + if (_model->getRegistrationPoint() != getRegistrationPoint()) { + qDebug() << "HERE: " << _model->getRegistrationPoint() << getRegistrationPoint(); + } + + bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething(); + if ((movingOrAnimating || + _needsInitialSimulation || + _model->getTranslation() != getPosition() || + _model->getRotation() != getRotation() || + _model->getRegistrationPoint() != getRegistrationPoint()) + && _model->isActive() && _dimensionsInitialized) { + _model->setScaleToFit(true, getDimensions()); + _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); + _model->setRotation(getRotation()); + _model->setTranslation(getPosition()); + + // make sure to simulate so everything gets set up correctly for rendering + { + PerformanceTimer perfTimer("_model->simulate"); + _model->simulate(0.0f); + } + + _needsInitialSimulation = false; + } +} + + // NOTE: this only renders the "meta" portion of the Model, namely it renders debugging items, and it handles // the per frame simulation/update that might be required if the models properties changed. void RenderableModelEntityItem::render(RenderArgs* args) { @@ -414,27 +445,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } } }); - - bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething(); - if ((movingOrAnimating || - _needsInitialSimulation || - _model->getTranslation() != getPosition() || - _model->getRotation() != getRotation() || - _model->getRegistrationPoint() != getRegistrationPoint()) - && _model->isActive() && _dimensionsInitialized) { - _model->setScaleToFit(true, getDimensions()); - _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); - _model->setRotation(getRotation()); - _model->setTranslation(getPosition()); - - // make sure to simulate so everything gets set up correctly for rendering - { - PerformanceTimer perfTimer("_model->simulate"); - _model->simulate(0.0f); - } - - _needsInitialSimulation = false; - } + updateModelBounds(); } } } else { @@ -599,7 +610,9 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { ModelEntityItem::computeShapeInfo(info); info.setParams(type, 0.5f * getDimensions()); adjustShapeInfoByRegistration(info); + assert(false); // XXX } else { + updateModelBounds(); const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); // should never fall in here when collision model not fully loaded @@ -693,6 +706,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { for (int j = 0; j < _points[i].size(); j++) { // compensate for registraion _points[i][j] += _model->getOffset(); + // _points[i][j] += info.getOffset(); // scale so the collision points match the model points _points[i][j] *= scale; box += _points[i][j]; @@ -704,9 +718,14 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { QString::number(_registrationPoint.x) + "," + QString::number(_registrationPoint.y) + "," + QString::number(_registrationPoint.z); + + qDebug() << "NEW SHAPE FOR" << getName() << shapeKey; + qDebug() << " model-offset:" << _model->getOffset(); + info.setParams(type, collisionModelDimensions, shapeKey); info.setConvexHulls(_points); adjustShapeInfoByRegistration(info); + qDebug() << " info-offset:" << info.getOffset(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index d6deaa5d8d..69c1c13151 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -49,6 +49,7 @@ public: virtual void removeFromScene(EntityItemPointer self, std::shared_ptr scene, render::PendingChanges& pendingChanges) override; + void updateModelBounds(); virtual void render(RenderArgs* args) override; virtual bool supportsDetailedRayIntersection() const override { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index f138587030..b7eb417bca 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -15,7 +15,7 @@ #include "ShapeFactory.h" #include "BulletUtil.h" - +#include "StreamUtils.h" btConvexHullShape* ShapeFactory::createConvexHull(const QVector& points) { @@ -65,6 +65,11 @@ btConvexHullShape* ShapeFactory::createConvexHull(const QVector& poin hull->addPoint(btVector3(correctedPoint[0], correctedPoint[1], correctedPoint[2]), false); } hull->recalcLocalAabb(); + + qDebug() << "------- NEW COMPOUND SHAPE ------"; + qDebug() << " low = " << minCorner; + qDebug() << " high = " << maxCorner; + return hull; } @@ -92,11 +97,13 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { const QVector>& points = info.getPoints(); uint32_t numSubShapes = info.getNumSubShapes(); if (numSubShapes == 1) { + // XXX offset? shape = createConvexHull(info.getPoints()[0]); } else { auto compound = new btCompoundShape(); btTransform trans; trans.setIdentity(); + // trans.setOrigin(-glmToBullet(info.getOffset())); foreach (QVector hullPoints, points) { btConvexHullShape* hull = createConvexHull(hullPoints); compound->addChildShape (trans, hull); @@ -110,7 +117,7 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { if (glm::length2(info.getOffset()) > MIN_SHAPE_OFFSET * MIN_SHAPE_OFFSET) { // this shape has an offset, which we support by wrapping the true shape // in a btCompoundShape with a local transform - auto compound = new btCompoundShape(); + auto compound = new btCompoundShape(); btTransform trans; trans.setIdentity(); trans.setOrigin(glmToBullet(info.getOffset())); @@ -118,5 +125,11 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { shape = compound; } } + + if (type == SHAPE_TYPE_COMPOUND) { + qDebug() << " offset = " << info.getOffset(); + } + + return shape; } From 59804a0f54df433a8ca89e014ee4fc131127f489 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 12:58:30 -0800 Subject: [PATCH 4/9] cleanups --- .../src/RenderableModelEntityItem.cpp | 10 +--------- libraries/physics/src/ShapeFactory.cpp | 16 +--------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3f46c5bf83..52fcda7f3e 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -704,10 +704,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; for (int i = 0; i < _points.size(); i++) { for (int j = 0; j < _points[i].size(); j++) { - // compensate for registraion - _points[i][j] += _model->getOffset(); - // _points[i][j] += info.getOffset(); - // scale so the collision points match the model points _points[i][j] *= scale; box += _points[i][j]; } @@ -719,13 +715,9 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { QString::number(_registrationPoint.y) + "," + QString::number(_registrationPoint.z); - qDebug() << "NEW SHAPE FOR" << getName() << shapeKey; - qDebug() << " model-offset:" << _model->getOffset(); - info.setParams(type, collisionModelDimensions, shapeKey); info.setConvexHulls(_points); - adjustShapeInfoByRegistration(info); - qDebug() << " info-offset:" << info.getOffset(); + info.setOffset(_model->getOffset()); } } diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index b7eb417bca..0ed4b1d0a9 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -15,8 +15,6 @@ #include "ShapeFactory.h" #include "BulletUtil.h" -#include "StreamUtils.h" - btConvexHullShape* ShapeFactory::createConvexHull(const QVector& points) { assert(points.size() > 0); @@ -65,11 +63,6 @@ btConvexHullShape* ShapeFactory::createConvexHull(const QVector& poin hull->addPoint(btVector3(correctedPoint[0], correctedPoint[1], correctedPoint[2]), false); } hull->recalcLocalAabb(); - - qDebug() << "------- NEW COMPOUND SHAPE ------"; - qDebug() << " low = " << minCorner; - qDebug() << " high = " << maxCorner; - return hull; } @@ -97,13 +90,11 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { const QVector>& points = info.getPoints(); uint32_t numSubShapes = info.getNumSubShapes(); if (numSubShapes == 1) { - // XXX offset? shape = createConvexHull(info.getPoints()[0]); } else { auto compound = new btCompoundShape(); btTransform trans; trans.setIdentity(); - // trans.setOrigin(-glmToBullet(info.getOffset())); foreach (QVector hullPoints, points) { btConvexHullShape* hull = createConvexHull(hullPoints); compound->addChildShape (trans, hull); @@ -113,7 +104,7 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { } break; } - if (shape && type != SHAPE_TYPE_COMPOUND) { + if (shape) { if (glm::length2(info.getOffset()) > MIN_SHAPE_OFFSET * MIN_SHAPE_OFFSET) { // this shape has an offset, which we support by wrapping the true shape // in a btCompoundShape with a local transform @@ -126,10 +117,5 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { } } - if (type == SHAPE_TYPE_COMPOUND) { - qDebug() << " offset = " << info.getOffset(); - } - - return shape; } From dcb720a8324b841be4204d2e1202bbc61b23bb73 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 14:09:45 -0800 Subject: [PATCH 5/9] fix polyvox hull when registration changes. --- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderablePolyVoxEntityItem.cpp | 10 ++++++++-- .../src/RenderablePolyVoxEntityItem.h | 2 ++ libraries/entities/src/EntityItem.h | 2 +- libraries/physics/src/ShapeFactory.cpp | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 52fcda7f3e..7cda62f74d 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -610,7 +610,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { ModelEntityItem::computeShapeInfo(info); info.setParams(type, 0.5f * getDimensions()); adjustShapeInfoByRegistration(info); - assert(false); // XXX } else { updateModelBounds(); const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); @@ -704,6 +703,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; for (int i = 0; i < _points.size(); i++) { for (int j = 0; j < _points[i].size(); j++) { + // scale so the collision points match the model points _points[i][j] *= scale; box += _points[i][j]; } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index f59a943353..147905b72a 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -142,7 +142,7 @@ glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const { glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { glm::vec3 scale = getDimensions() / _voxelVolumeSize; // meters / voxel-units bool success; // TODO -- Does this actually have to happen in world space? - glm::vec3 center = getCenterPosition(success); + glm::vec3 center = getCenterPosition(success); // this handles registrationPoint changes glm::vec3 position = getPosition(success); glm::vec3 positionToCenter = center - position; @@ -430,6 +430,13 @@ ShapeType RenderablePolyVoxEntityItem::getShapeType() const { return SHAPE_TYPE_COMPOUND; } +void RenderablePolyVoxEntityItem::updateRegistrationPoint(const glm::vec3& value) { + if (value != _registrationPoint) { + _meshDirty = true; + EntityItem::updateRegistrationPoint(value); + } +} + bool RenderablePolyVoxEntityItem::isReadyToComputeShape() { _meshLock.lockForRead(); if (_meshDirty) { @@ -1231,7 +1238,6 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { _shapeInfoLock.lockForWrite(); _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey); _shapeInfo.setConvexHulls(points); - adjustShapeInfoByRegistration(_shapeInfo); _shapeInfoLock.unlock(); _meshLock.lockForWrite(); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index fdbaefb0c3..b40507f36a 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -116,6 +116,8 @@ public: virtual void rebakeMesh(); + virtual void updateRegistrationPoint(const glm::vec3& value); + private: // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions // may not match _voxelVolumeSize. diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d327bd9004..62cc8ad69a 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -320,7 +320,7 @@ public: virtual void setRotation(glm::quat orientation) { setOrientation(orientation); } // updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags - void updateRegistrationPoint(const glm::vec3& value); + virtual void updateRegistrationPoint(const glm::vec3& value); void updatePosition(const glm::vec3& value); void updatePositionFromNetwork(const glm::vec3& value); void updateDimensions(const glm::vec3& value); diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index 0ed4b1d0a9..f956e562cd 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -16,6 +16,8 @@ #include "ShapeFactory.h" #include "BulletUtil.h" + + btConvexHullShape* ShapeFactory::createConvexHull(const QVector& points) { assert(points.size() > 0); @@ -116,6 +118,5 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) { shape = compound; } } - return shape; } From 5c585acd9a0f0e30a8f50d96fe8fe4c7bd5a0e8e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 14:29:30 -0800 Subject: [PATCH 6/9] offset is included in shape key for models --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 7 +------ .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 3 +++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 7cda62f74d..fb79b8d5b2 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -710,12 +710,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { } glm::vec3 collisionModelDimensions = box.getDimensions(); - QString shapeKey = _compoundShapeURL + "," + - QString::number(_registrationPoint.x) + "," + - QString::number(_registrationPoint.y) + "," + - QString::number(_registrationPoint.z); - - info.setParams(type, collisionModelDimensions, shapeKey); + info.setParams(type, collisionModelDimensions, _compoundShapeURL); info.setConvexHulls(_points); info.setOffset(_model->getOffset()); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 147905b72a..5118664268 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -1231,6 +1231,8 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { } glm::vec3 collisionModelDimensions = box.getDimensions(); + // include the registrationPoint in the shape key, because the offset is already + // included in the points and the shapeManager wont know that the shape has changed. QString shapeKey = QString(_voxelData.toBase64()) + "," + QString::number(_registrationPoint.x) + "," + QString::number(_registrationPoint.y) + "," + @@ -1238,6 +1240,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { _shapeInfoLock.lockForWrite(); _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey); _shapeInfo.setConvexHulls(points); + // adjustShapeInfoByRegistration(_shapeInfo); _shapeInfoLock.unlock(); _meshLock.lockForWrite(); From c95d1f68f6a7d8988fe8e015336e81ed4f063e7c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 14:38:03 -0800 Subject: [PATCH 7/9] remove debug print --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index fb79b8d5b2..57dcf3d519 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -340,10 +340,6 @@ void RenderableModelEntityItem::updateModelBounds() { if (!hasModel() || !_model) { return; } - if (_model->getRegistrationPoint() != getRegistrationPoint()) { - qDebug() << "HERE: " << _model->getRegistrationPoint() << getRegistrationPoint(); - } - bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething(); if ((movingOrAnimating || _needsInitialSimulation || From 8b8604f9b0e518a5fde950ab06053c53efaaf07b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 7 Mar 2016 11:32:25 -0800 Subject: [PATCH 8/9] move offset handling for models back to how it was before this PR --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 57dcf3d519..53b7674b11 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -699,6 +699,8 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; for (int i = 0; i < _points.size(); i++) { for (int j = 0; j < _points[i].size(); j++) { + // compensate for registration + _points[i][j] += _model->getOffset(); // scale so the collision points match the model points _points[i][j] *= scale; box += _points[i][j]; @@ -708,7 +710,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { glm::vec3 collisionModelDimensions = box.getDimensions(); info.setParams(type, collisionModelDimensions, _compoundShapeURL); info.setConvexHulls(_points); - info.setOffset(_model->getOffset()); } } From 40c953e0b9d0770111cb6a6349cb95766413923e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 7 Mar 2016 11:40:18 -0800 Subject: [PATCH 9/9] fix model hulls --- libraries/entities-renderer/src/RenderableModelEntityItem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 53b7674b11..71b04d06a1 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -703,6 +703,9 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { _points[i][j] += _model->getOffset(); // scale so the collision points match the model points _points[i][j] *= scale; + // this next subtraction is done so we can give info the offset, which will cause + // the shape-key to change. + _points[i][j] -= _model->getOffset(); box += _points[i][j]; } } @@ -710,6 +713,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { glm::vec3 collisionModelDimensions = box.getDimensions(); info.setParams(type, collisionModelDimensions, _compoundShapeURL); info.setConvexHulls(_points); + info.setOffset(_model->getOffset()); } }