mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 08:23:04 +02:00
more correct rebuild OtherAvatar detailed pickable shapes
This commit is contained in:
parent
723b4ac30f
commit
ce96ea5bf8
6 changed files with 31 additions and 25 deletions
|
@ -435,7 +435,7 @@ DetailedMotionState* AvatarManager::createDetailedMotionState(OtherAvatarPointer
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction, OtherAvatarPointer avatar) {
|
void AvatarManager::rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar) {
|
||||||
if (!avatar->_motionState) {
|
if (!avatar->_motionState) {
|
||||||
avatar->_motionState = new AvatarMotionState(avatar, nullptr);
|
avatar->_motionState = new AvatarMotionState(avatar, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -452,20 +452,24 @@ void AvatarManager::rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction
|
||||||
transaction.objectsToAdd.push_back(motionState);
|
transaction.objectsToAdd.push_back(motionState);
|
||||||
}
|
}
|
||||||
motionState->clearIncomingDirtyFlags();
|
motionState->clearIncomingDirtyFlags();
|
||||||
|
}
|
||||||
|
|
||||||
// Rather than reconcile numbers of joints after change to model or LOD
|
void AvatarManager::removeDetailedAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar) {
|
||||||
// we blow away old detailedMotionStates and create anew all around.
|
|
||||||
|
|
||||||
// delete old detailedMotionStates
|
// delete old detailedMotionStates
|
||||||
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
||||||
if (detailedMotionStates.size() != 0) {
|
if (detailedMotionStates.size() != 0) {
|
||||||
for (auto& detailedMotionState : detailedMotionStates) {
|
for (auto& detailedMotionState : detailedMotionStates) {
|
||||||
transaction.objectsToRemove.push_back(detailedMotionState);
|
transaction.objectsToRemove.push_back(detailedMotionState);
|
||||||
}
|
}
|
||||||
avatar->resetDetailedMotionStates();
|
avatar->forgetDetailedMotionStates();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// build new detailedMotionStates
|
void AvatarManager::rebuildDetailedAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar) {
|
||||||
|
// Rather than reconcile numbers of joints after change to model or LOD
|
||||||
|
// we blow away old detailedMotionStates and create anew all around.
|
||||||
|
removeDetailedAvatarPhysics(transaction, avatar);
|
||||||
|
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
||||||
OtherAvatar::BodyLOD lod = avatar->getBodyLOD();
|
OtherAvatar::BodyLOD lod = avatar->getBodyLOD();
|
||||||
if (lod == OtherAvatar::BodyLOD::Sphere) {
|
if (lod == OtherAvatar::BodyLOD::Sphere) {
|
||||||
auto dMotionState = createDetailedMotionState(avatar, -1);
|
auto dMotionState = createDetailedMotionState(avatar, -1);
|
||||||
|
@ -483,24 +487,21 @@ void AvatarManager::rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
avatar->_needsReinsertion = false;
|
avatar->_needsDetailedRebuild = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transaction) {
|
void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transaction) {
|
||||||
_myAvatar->getCharacterController()->buildPhysicsTransaction(transaction);
|
_myAvatar->getCharacterController()->buildPhysicsTransaction(transaction);
|
||||||
for (auto avatar : _otherAvatarsToChangeInPhysics) {
|
for (auto avatar : _otherAvatarsToChangeInPhysics) {
|
||||||
bool isInPhysics = avatar->isInPhysicsSimulation();
|
bool isInPhysics = avatar->isInPhysicsSimulation();
|
||||||
if (isInPhysics != avatar->shouldBeInPhysicsSimulation() || avatar->_needsReinsertion) {
|
if (isInPhysics != avatar->shouldBeInPhysicsSimulation()) {
|
||||||
if (isInPhysics) {
|
if (isInPhysics) {
|
||||||
transaction.objectsToRemove.push_back(avatar->_motionState);
|
transaction.objectsToRemove.push_back(avatar->_motionState);
|
||||||
avatar->_motionState = nullptr;
|
avatar->_motionState = nullptr;
|
||||||
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
removeDetailedAvatarPhysics(transaction, avatar);
|
||||||
for (auto& motionState : detailedMotionStates) {
|
|
||||||
transaction.objectsToRemove.push_back(motionState);
|
|
||||||
}
|
|
||||||
avatar->resetDetailedMotionStates();
|
|
||||||
} else {
|
} else {
|
||||||
rebuildAvatarPhysics(transaction, avatar);
|
rebuildAvatarPhysics(transaction, avatar);
|
||||||
|
rebuildDetailedAvatarPhysics(transaction, avatar);
|
||||||
}
|
}
|
||||||
} else if (isInPhysics) {
|
} else if (isInPhysics) {
|
||||||
AvatarMotionState* motionState = avatar->_motionState;
|
AvatarMotionState* motionState = avatar->_motionState;
|
||||||
|
@ -519,6 +520,10 @@ void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transact
|
||||||
}
|
}
|
||||||
motionState->clearIncomingDirtyFlags();
|
motionState->clearIncomingDirtyFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (avatar->_needsDetailedRebuild) {
|
||||||
|
rebuildDetailedAvatarPhysics(transaction, avatar);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_otherAvatarsToChangeInPhysics.clear();
|
_otherAvatarsToChangeInPhysics.clear();
|
||||||
|
|
|
@ -274,7 +274,9 @@ public slots:
|
||||||
protected:
|
protected:
|
||||||
AvatarSharedPointer addAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) override;
|
AvatarSharedPointer addAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) override;
|
||||||
DetailedMotionState* createDetailedMotionState(OtherAvatarPointer avatar, int32_t jointIndex);
|
DetailedMotionState* createDetailedMotionState(OtherAvatarPointer avatar, int32_t jointIndex);
|
||||||
void rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction, OtherAvatarPointer avatar);
|
void rebuildAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar);
|
||||||
|
void removeDetailedAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar);
|
||||||
|
void rebuildDetailedAvatarPhysics(PhysicsEngine::Transaction& transaction, const OtherAvatarPointer& avatar);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit AvatarManager(QObject* parent = 0);
|
explicit AvatarManager(QObject* parent = 0);
|
||||||
|
|
|
@ -398,15 +398,13 @@ DetailedMotionState* MyCharacterController::createDetailedMotionStateForJoint(in
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCharacterController::clearDetailedMotionStates() {
|
void MyCharacterController::clearDetailedMotionStates() {
|
||||||
|
// we don't actually clear the MotionStates here
|
||||||
|
// instead we twiddle some flags as a signal of what to do later
|
||||||
_pendingFlags |= PENDING_FLAG_REMOVE_DETAILED_FROM_SIMULATION;
|
_pendingFlags |= PENDING_FLAG_REMOVE_DETAILED_FROM_SIMULATION;
|
||||||
// We make sure we don't add them again
|
// We make sure we don't add them again
|
||||||
_pendingFlags &= ~PENDING_FLAG_ADD_DETAILED_TO_SIMULATION;
|
_pendingFlags &= ~PENDING_FLAG_ADD_DETAILED_TO_SIMULATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCharacterController::resetDetailedMotionStates() {
|
|
||||||
_detailedMotionStates.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyCharacterController::buildPhysicsTransaction(PhysicsEngine::Transaction& transaction) {
|
void MyCharacterController::buildPhysicsTransaction(PhysicsEngine::Transaction& transaction) {
|
||||||
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
|
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
|
||||||
_detailedMotionStates[i]->forceActive();
|
_detailedMotionStates[i]->forceActive();
|
||||||
|
@ -416,6 +414,8 @@ void MyCharacterController::buildPhysicsTransaction(PhysicsEngine::Transaction&
|
||||||
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
|
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
|
||||||
transaction.objectsToRemove.push_back(_detailedMotionStates[i]);
|
transaction.objectsToRemove.push_back(_detailedMotionStates[i]);
|
||||||
}
|
}
|
||||||
|
// NOTE: the DetailedMotionStates are deleted after being added to PhysicsEngine::Transaction::_objectsToRemove
|
||||||
|
// See AvatarManager::handleProcessedPhysicsTransaction()
|
||||||
_detailedMotionStates.clear();
|
_detailedMotionStates.clear();
|
||||||
}
|
}
|
||||||
if (_pendingFlags & PENDING_FLAG_ADD_DETAILED_TO_SIMULATION) {
|
if (_pendingFlags & PENDING_FLAG_ADD_DETAILED_TO_SIMULATION) {
|
||||||
|
|
|
@ -48,7 +48,6 @@ public:
|
||||||
DetailedMotionState* createDetailedMotionStateForJoint(int32_t jointIndex);
|
DetailedMotionState* createDetailedMotionStateForJoint(int32_t jointIndex);
|
||||||
std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
|
std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
|
||||||
void clearDetailedMotionStates();
|
void clearDetailedMotionStates();
|
||||||
void resetDetailedMotionStates();
|
|
||||||
|
|
||||||
void buildPhysicsTransaction(PhysicsEngine::Transaction& transaction);
|
void buildPhysicsTransaction(PhysicsEngine::Transaction& transaction);
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ const btCollisionShape* OtherAvatar::createCollisionShape(int32_t jointIndex, bo
|
||||||
return ObjectMotionState::getShapeManager()->getShape(shapeInfo);
|
return ObjectMotionState::getShapeManager()->getShape(shapeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtherAvatar::resetDetailedMotionStates() {
|
void OtherAvatar::forgetDetailedMotionStates() {
|
||||||
// NOTE: the DetailedMotionStates are deleted after being added to PhysicsEngine::Transaction::_objectsToRemove
|
// NOTE: the DetailedMotionStates are deleted after being added to PhysicsEngine::Transaction::_objectsToRemove
|
||||||
// See AvatarManager::handleProcessedPhysicsTransaction()
|
// See AvatarManager::handleProcessedPhysicsTransaction()
|
||||||
_detailedMotionStates.clear();
|
_detailedMotionStates.clear();
|
||||||
|
@ -209,7 +209,7 @@ void OtherAvatar::computeShapeLOD() {
|
||||||
if (newLOD != _bodyLOD) {
|
if (newLOD != _bodyLOD) {
|
||||||
_bodyLOD = newLOD;
|
_bodyLOD = newLOD;
|
||||||
if (isInPhysicsSimulation()) {
|
if (isInPhysicsSimulation()) {
|
||||||
_needsReinsertion = true;
|
_needsDetailedRebuild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,14 +224,14 @@ bool OtherAvatar::shouldBeInPhysicsSimulation() const {
|
||||||
|
|
||||||
bool OtherAvatar::needsPhysicsUpdate() const {
|
bool OtherAvatar::needsPhysicsUpdate() const {
|
||||||
constexpr uint32_t FLAGS_OF_INTEREST = Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS | Simulation::DIRTY_POSITION | Simulation::DIRTY_COLLISION_GROUP;
|
constexpr uint32_t FLAGS_OF_INTEREST = Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS | Simulation::DIRTY_POSITION | Simulation::DIRTY_COLLISION_GROUP;
|
||||||
return (_needsReinsertion || (_motionState && (bool)(_motionState->getIncomingDirtyFlags() & FLAGS_OF_INTEREST)));
|
return (_needsDetailedRebuild || (_motionState && (bool)(_motionState->getIncomingDirtyFlags() & FLAGS_OF_INTEREST)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtherAvatar::rebuildCollisionShape() {
|
void OtherAvatar::rebuildCollisionShape() {
|
||||||
if (_motionState) {
|
if (_motionState) {
|
||||||
// do not actually rebuild here, instead flag for later
|
// do not actually rebuild here, instead flag for later
|
||||||
_motionState->addDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
|
_motionState->addDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
|
||||||
_needsReinsertion = true;
|
_needsDetailedRebuild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
const btCollisionShape* createCollisionShape(int32_t jointIndex, bool& isBound, std::vector<int32_t>& boundJoints);
|
const btCollisionShape* createCollisionShape(int32_t jointIndex, bool& isBound, std::vector<int32_t>& boundJoints);
|
||||||
std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
|
std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
|
||||||
void resetDetailedMotionStates();
|
void forgetDetailedMotionStates();
|
||||||
BodyLOD getBodyLOD() { return _bodyLOD; }
|
BodyLOD getBodyLOD() { return _bodyLOD; }
|
||||||
void computeShapeLOD();
|
void computeShapeLOD();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ protected:
|
||||||
int32_t _spaceIndex { -1 };
|
int32_t _spaceIndex { -1 };
|
||||||
uint8_t _workloadRegion { workload::Region::INVALID };
|
uint8_t _workloadRegion { workload::Region::INVALID };
|
||||||
BodyLOD _bodyLOD { BodyLOD::Sphere };
|
BodyLOD _bodyLOD { BodyLOD::Sphere };
|
||||||
bool _needsReinsertion { false };
|
bool _needsDetailedRebuild { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
using OtherAvatarPointer = std::shared_ptr<OtherAvatar>;
|
using OtherAvatarPointer = std::shared_ptr<OtherAvatar>;
|
||||||
|
|
Loading…
Reference in a new issue