Skip to content

Commit

Permalink
Merge pull request #819 from overte-org/fix/entity_density
Browse files Browse the repository at this point in the history
Fix entity density not setting and not updating for motion states
  • Loading branch information
ksuprynowicz authored Feb 17, 2024
2 parents 1fd3f80 + 9a00edd commit 68fffe0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions interface/src/avatar/AvatarMotionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions interface/src/avatar/DetailedMotionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions libraries/entities/src/EntityItemPropertiesDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion libraries/physics/src/EntityMotionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,6 +178,11 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) {
_body->activate();
}
}

if (flags & Simulation::DIRTY_MASS) {
setMass(_entity->computeMass());
updateBodyMassProperties();
}
}


Expand Down
4 changes: 0 additions & 4 deletions libraries/physics/src/ObjectMotionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 68fffe0

Please sign in to comment.