disable positionand velocity script edits on grabbed entities

This commit is contained in:
Seth Alves 2018-12-18 14:09:20 -08:00
parent bf46960dc3
commit 3ccbd0bc7b
5 changed files with 26 additions and 0 deletions

View file

@ -3595,6 +3595,18 @@ bool EntityItemProperties::hasTransformOrVelocityChanges() const {
|| _accelerationChanged;
}
void EntityItemProperties::clearTransformOrVelocityChanges() {
_positionChanged = false;
_localPositionChanged = false;
_rotationChanged = false;
_localRotationChanged = false;
_velocityChanged = false;
_localVelocityChanged = false;
_angularVelocityChanged = false;
_localAngularVelocityChanged = false;
_accelerationChanged = false;
}
bool EntityItemProperties::hasMiscPhysicsChanges() const {
return _gravityChanged || _dimensionsChanged || _densityChanged || _frictionChanged
|| _restitutionChanged || _dampingChanged || _angularDampingChanged || _registrationPointChanged ||

View file

@ -390,6 +390,7 @@ public:
void setCreated(QDateTime& v);
bool hasTransformOrVelocityChanges() const;
void clearTransformOrVelocityChanges();
bool hasMiscPhysicsChanges() const;
bool hasSimulationRestrictedChanges() const;

View file

@ -816,6 +816,10 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
QString previousUserdata;
if (entity) {
if (properties.hasTransformOrVelocityChanges() && entity->hasGrabs()) {
// if an entity is grabbed, the grab will override any position changes
properties.clearTransformOrVelocityChanges();
}
if (properties.hasSimulationRestrictedChanges()) {
if (_bidOnSimulationOwnership) {
// flag for simulation ownership, or upgrade existing ownership priority

View file

@ -1386,6 +1386,14 @@ void SpatiallyNestable::removeGrab(GrabPointer grab) {
});
}
bool SpatiallyNestable::hasGrabs() {
bool result { false };
_grabsLock.withReadLock([&] {
result = !_grabs.isEmpty();
});
return result;
}
QUuid SpatiallyNestable::getEditSenderID() {
// if more than one avatar is grabbing something, decide which one should tell the enity-server about it
QUuid editSenderID;

View file

@ -216,6 +216,7 @@ public:
virtual void addGrab(GrabPointer grab);
virtual void removeGrab(GrabPointer grab);
bool hasGrabs();
virtual QUuid getEditSenderID();
protected: