From dcb720a8324b841be4204d2e1202bbc61b23bb73 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 6 Mar 2016 14:09:45 -0800 Subject: [PATCH] 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; }