fix collisions for newly added avatars

This commit is contained in:
luiscuenca 2019-01-03 13:36:26 -07:00
parent bd21d0589a
commit 21a4da4d5f
3 changed files with 9 additions and 15 deletions

View file

@ -417,7 +417,7 @@ void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transact
avatar->resetDetailedMotionStates();
} else {
{
if (avatar->_motionState == nullptr) {
ShapeInfo shapeInfo;
avatar->computeShapeInfo(shapeInfo);
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShape(shapeInfo));
@ -427,21 +427,20 @@ void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transact
avatar->_motionState = motionState;
transaction.objectsToAdd.push_back(motionState);
}
else {
failedShapeBuilds.insert(avatar);
}
}
{
auto& detailedMotionStates = avatar->getDetailedMotionStates();
if (detailedMotionStates.size() == 0) {
for (int i = 0; i < avatar->getJointCount(); i++) {
avatar->addNewMotionState(avatar, i);
}
auto& detailedMotionStates = avatar->getDetailedMotionStates();
for (auto& mState : detailedMotionStates) {
transaction.objectsToAdd.push_back(mState);
}
qCDebug(animation) << "Creating " << detailedMotionStates.size() << " detailed motion states from " << avatar->getSessionUUID();
}
if (avatar->_motionState == nullptr || detailedMotionStates.size() == 0) {
failedShapeBuilds.insert(avatar);
}
}
} else if (isInPhysics) {
transaction.objectsToChange.push_back(avatar->_motionState);

View file

@ -118,7 +118,6 @@ int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) {
}
void OtherAvatar::addNewMotionState(std::shared_ptr<OtherAvatar> avatar, int jointIndex) {
std::lock_guard<std::mutex> lock(_mStateLock);
if (jointIndex > -1 && jointIndex < _multiSphereShapes.size()) {
auto& data = _multiSphereShapes[jointIndex].getSpheresData();
std::vector<btVector3> positions;
@ -138,10 +137,7 @@ void OtherAvatar::addNewMotionState(std::shared_ptr<OtherAvatar> avatar, int joi
}
}
}
const std::vector<DetailedMotionState*>& OtherAvatar::getDetailedMotionStates() {
std::lock_guard<std::mutex> lock(_mStateLock);
return _detailedMotionStates;
}
void OtherAvatar::resetDetailedMotionStates() {
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
_detailedMotionStates[i] = nullptr;

View file

@ -39,7 +39,7 @@ public:
int parseDataFromBuffer(const QByteArray& buffer) override;
bool isInPhysicsSimulation() const { return _motionState != nullptr; }
bool isInPhysicsSimulation() const { return _motionState != nullptr && _detailedMotionStates.size() > 0; }
void rebuildCollisionShape() override;
void setWorkloadRegion(uint8_t region);
@ -47,7 +47,7 @@ public:
bool needsPhysicsUpdate() const;
void addNewMotionState(std::shared_ptr<OtherAvatar> avatar, int jointIndex);
const std::vector<DetailedMotionState*>& getDetailedMotionStates();
const std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
void resetDetailedMotionStates();
friend AvatarManager;
@ -59,7 +59,6 @@ protected:
std::vector<DetailedMotionState*> _detailedMotionStates;
int32_t _spaceIndex { -1 };
uint8_t _workloadRegion { workload::Region::INVALID };
std::mutex _mStateLock;
};
using OtherAvatarPointer = std::shared_ptr<OtherAvatar>;