From 9a00edd371f3c095a1f363faaac62a04a2e51a1e Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 17 Feb 2024 19:52:54 +0100 Subject: [PATCH] Fix entity density not setting and not updating for motion states --- interface/src/avatar/AvatarMotionState.cpp | 4 ++++ interface/src/avatar/DetailedMotionState.cpp | 4 ++++ libraries/entities/src/EntityItemPropertiesDefaults.h | 6 +++--- libraries/physics/src/EntityMotionState.cpp | 7 ++++++- libraries/physics/src/ObjectMotionState.cpp | 4 ---- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/interface/src/avatar/AvatarMotionState.cpp b/interface/src/avatar/AvatarMotionState.cpp index 97085c8443..362ac579a9 100644 --- a/interface/src/avatar/AvatarMotionState.cpp +++ b/interface/src/avatar/AvatarMotionState.cpp @@ -27,6 +27,10 @@ void AvatarMotionState::handleEasyChanges(uint32_t& flags) { if (flags & Simulation::DIRTY_PHYSICS_ACTIVATION && !_body->isActive()) { _body->activate(); } + + if (flags & Simulation::DIRTY_MASS) { + updateBodyMassProperties(); + } } AvatarMotionState::~AvatarMotionState() { diff --git a/interface/src/avatar/DetailedMotionState.cpp b/interface/src/avatar/DetailedMotionState.cpp index 02a2b9d425..a22d533bc9 100644 --- a/interface/src/avatar/DetailedMotionState.cpp +++ b/interface/src/avatar/DetailedMotionState.cpp @@ -31,6 +31,10 @@ void DetailedMotionState::handleEasyChanges(uint32_t& flags) { if (flags & Simulation::DIRTY_PHYSICS_ACTIVATION && !_body->isActive()) { _body->activate(); } + + if (flags & Simulation::DIRTY_MASS) { + updateBodyMassProperties(); + } } DetailedMotionState::~DetailedMotionState() { diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index c9ecff41f2..ad9de6ac18 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -57,9 +57,9 @@ const glm::vec3 ENTITY_ITEM_DEFAULT_DIMENSIONS = glm::vec3(ENTITY_ITEM_DEFAULT_W const float ENTITY_ITEM_DEFAULT_VOLUME = ENTITY_ITEM_DEFAULT_WIDTH * ENTITY_ITEM_DEFAULT_WIDTH * ENTITY_ITEM_DEFAULT_WIDTH; const float ENTITY_ITEM_MIN_VOLUME = ENTITY_ITEM_MIN_DIMENSION * ENTITY_ITEM_MIN_DIMENSION * ENTITY_ITEM_MIN_DIMENSION; -const float ENTITY_ITEM_MAX_DENSITY = 10000.0f; // kg/m^3 density of silver -const float ENTITY_ITEM_MIN_DENSITY = 100.0f; // kg/m^3 density of balsa wood -const float ENTITY_ITEM_DEFAULT_DENSITY = 1000.0f; // density of water +const float ENTITY_ITEM_MAX_DENSITY = 100000.0f; // kg/m^3 more than 5 times density of tungsten. +const float ENTITY_ITEM_MIN_DENSITY = 0.1f; // kg/m^3 ten times less than air density. +const float ENTITY_ITEM_DEFAULT_DENSITY = 1000.0f; // density of water. const float ENTITY_ITEM_DEFAULT_MASS = ENTITY_ITEM_DEFAULT_DENSITY * ENTITY_ITEM_DEFAULT_VOLUME; const glm::vec3 ENTITY_ITEM_DEFAULT_VELOCITY = ENTITY_ITEM_ZERO_VEC3; diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f3d129871f..ac36d37aaa 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -57,10 +57,10 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer _type = MOTIONSTATE_TYPE_ENTITY; assert(_entity); - setMass(_entity->computeMass()); // we need the side-effects of EntityMotionState::setShape() so we call it explicitly here // rather than pass the legit shape pointer to the ObjectMotionState ctor above. setShape(shape); + setMass(_entity->computeMass()); if (_entity->isAvatarEntity() && !_entity->isMyAvatarEntity()) { // avatar entities are always thus, so we cache this fact in _ownershipState @@ -178,6 +178,11 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) { _body->activate(); } } + + if (flags & Simulation::DIRTY_MASS) { + setMass(_entity->computeMass()); + updateBodyMassProperties(); + } } diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index ad7332cb15..5376d296aa 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -284,10 +284,6 @@ void ObjectMotionState::handleEasyChanges(uint32_t& flags) { if (flags & Simulation::DIRTY_MATERIAL) { updateBodyMaterialProperties(); } - - if (flags & Simulation::DIRTY_MASS) { - updateBodyMassProperties(); - } } void ObjectMotionState::updateBodyMaterialProperties() {