From 251810edc547979b01351e03e77ac1002b8b509e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 9 Feb 2016 15:03:36 -0800 Subject: [PATCH 1/3] only suppress location edits when they arrive over the network -- script can still update --- libraries/entities/src/EntityItem.cpp | 48 ++++++++++++++++++--------- libraries/entities/src/EntityItem.h | 4 +++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index e56f2c267a..8f8485236c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -659,10 +659,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // but since we're using macros below we have to temporarily modify overwriteLocalData. bool oldOverwrite = overwriteLocalData; overwriteLocalData = overwriteLocalData && !weOwnSimulation; - READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, updatePosition); - READ_ENTITY_PROPERTY(PROP_ROTATION, glm::quat, updateRotation); - READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, updateVelocity); - READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, updateAngularVelocity); + READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, updatePositionFromNetwork); + READ_ENTITY_PROPERTY(PROP_ROTATION, glm::quat, updateRotationFromNetwork); + READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, updateVelocityFromNetwork); + READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, updateAngularVelocityFromNetwork); READ_ENTITY_PROPERTY(PROP_ACCELERATION, glm::vec3, setAcceleration); overwriteLocalData = oldOverwrite; } @@ -1344,9 +1344,6 @@ void EntityItem::computeShapeInfo(ShapeInfo& info) { } void EntityItem::updatePosition(const glm::vec3& value) { - if (shouldSuppressLocationEdits()) { - return; - } if (getLocalPosition() != value) { setLocalPosition(value); _dirtyFlags |= Simulation::DIRTY_POSITION; @@ -1359,6 +1356,13 @@ void EntityItem::updatePosition(const glm::vec3& value) { } } +void EntityItem::updatePositionFromNetwork(const glm::vec3& value) { + if (shouldSuppressLocationEdits()) { + return; + } + updatePosition(value); +} + void EntityItem::updateDimensions(const glm::vec3& value) { if (getDimensions() != value) { setDimensions(value); @@ -1367,9 +1371,6 @@ void EntityItem::updateDimensions(const glm::vec3& value) { } void EntityItem::updateRotation(const glm::quat& rotation) { - if (shouldSuppressLocationEdits()) { - return; - } if (getLocalOrientation() != rotation) { setLocalOrientation(rotation); _dirtyFlags |= Simulation::DIRTY_ROTATION; @@ -1383,6 +1384,13 @@ void EntityItem::updateRotation(const glm::quat& rotation) { } } +void EntityItem::updateRotationFromNetwork(const glm::quat& rotation) { + if (shouldSuppressLocationEdits()) { + return; + } + updateRotation(rotation); +} + void EntityItem::updateMass(float mass) { // Setting the mass actually changes the _density (at fixed volume), however // we must protect the density range to help maintain stability of physics simulation @@ -1407,9 +1415,6 @@ void EntityItem::updateMass(float mass) { } void EntityItem::updateVelocity(const glm::vec3& value) { - if (shouldSuppressLocationEdits()) { - return; - } glm::vec3 velocity = getLocalVelocity(); if (velocity != value) { const float MIN_LINEAR_SPEED = 0.001f; @@ -1423,6 +1428,13 @@ void EntityItem::updateVelocity(const glm::vec3& value) { } } +void EntityItem::updateVelocityFromNetwork(const glm::vec3& value) { + if (shouldSuppressLocationEdits()) { + return; + } + updateVelocity(value); +} + void EntityItem::updateDamping(float value) { auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); if (_damping != clampedDamping) { @@ -1439,9 +1451,6 @@ void EntityItem::updateGravity(const glm::vec3& value) { } void EntityItem::updateAngularVelocity(const glm::vec3& value) { - if (shouldSuppressLocationEdits()) { - return; - } glm::vec3 angularVelocity = getLocalAngularVelocity(); if (angularVelocity != value) { const float MIN_ANGULAR_SPEED = 0.0002f; @@ -1455,6 +1464,13 @@ void EntityItem::updateAngularVelocity(const glm::vec3& value) { } } +void EntityItem::updateAngularVelocityFromNetwork(const glm::vec3& value) { + if (shouldSuppressLocationEdits()) { + return; + } + return updateAngularVelocity(value); +} + void EntityItem::updateAngularDamping(float value) { auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); if (_angularDamping != clampedDamping) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index c8b54bca87..e6f2e44930 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -317,16 +317,20 @@ public: // updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags void updatePosition(const glm::vec3& value); + void updatePositionFromNetwork(const glm::vec3& value); void updateDimensions(const glm::vec3& value); void updateRotation(const glm::quat& rotation); + void updateRotationFromNetwork(const glm::quat& rotation); void updateDensity(float value); void updateMass(float value); void updateVelocity(const glm::vec3& value); + void updateVelocityFromNetwork(const glm::vec3& value); void updateDamping(float value); void updateRestitution(float value); void updateFriction(float value); void updateGravity(const glm::vec3& value); void updateAngularVelocity(const glm::vec3& value); + void updateAngularVelocityFromNetwork(const glm::vec3& value); void updateAngularDamping(float value); void updateCollisionless(bool value); void updateCollisionMask(uint8_t value); From c2cbca88cbc0dda409abc2f120523f96b1b29ed2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 9 Feb 2016 16:54:32 -0800 Subject: [PATCH 2/3] allow grabbing with one hand and then equipping with other --- examples/attachedEntitiesManager.js | 14 +++++++++----- examples/controllers/handControllerGrab.js | 11 +++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/attachedEntitiesManager.js b/examples/attachedEntitiesManager.js index 8cd159ec14..b5d023c70c 100644 --- a/examples/attachedEntitiesManager.js +++ b/examples/attachedEntitiesManager.js @@ -148,7 +148,7 @@ function AttachedEntitiesManager() { this.checkIfWearable = function(grabbedEntity, releasedFromJoint) { var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints; - var props = Entities.getEntityProperties(grabbedEntity, ["position", "parentID"]); + var props = Entities.getEntityProperties(grabbedEntity, ["position", "parentID", "parentJointIndex"]); if (props.parentID === NULL_UUID || props.parentID === MyAvatar.sessionUUID) { var bestJointName = ""; var bestJointIndex = -1; @@ -192,10 +192,14 @@ function AttachedEntitiesManager() { } Entities.editEntity(grabbedEntity, wearProps); } else if (props.parentID != NULL_UUID) { - // drop the entity with no parent (not on the avatar) - Entities.editEntity(grabbedEntity, { - parentID: NULL_UUID - }); + // drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand. + if (props.parentID === MyAvatar.sessionUUID && + (props.parentJointIndex == MyAvatar.getJointIndex("RightHand") || + props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) { + // this is equipped on a hand -- don't clear the parent. + } else { + Entities.editEntity(grabbedEntity, { parentID: NULL_UUID }); + } } } } diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 61c57fd86f..51814ad5d7 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -946,13 +946,15 @@ function MyController(hand) { return; } // near grab or equip with action - if (near && (grabbableData.refCount < 1 || entityHasActions(this.grabbedEntity))) { + var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {}); + var refCount = ("refCount" in grabData) ? grabData.refCount : 0; + if (near && (refCount < 1 || entityHasActions(this.grabbedEntity))) { this.setState(this.state == STATE_SEARCHING ? STATE_NEAR_GRABBING : STATE_EQUIP); return; } // far grab or equip with action if ((isPhysical || this.state == STATE_EQUIP_SEARCHING) && !near) { - if (entityIsGrabbedByOther(intersection.entityID)) { + if (entityIsGrabbedByOther(this.grabbedEntity)) { // don't distance grab something that is already grabbed. if (WANT_DEBUG_SEARCH_NAME && props.name == WANT_DEBUG_SEARCH_NAME) { print("grab is skipping '" + WANT_DEBUG_SEARCH_NAME + "': already grabbed by another."); @@ -1449,11 +1451,12 @@ function MyController(hand) { return; } - var props = Entities.getEntityProperties(this.grabbedEntity, ["localPosition", "parentID"]); + var props = Entities.getEntityProperties(this.grabbedEntity, ["localPosition", "parentID", "position"]); if (props.parentID == MyAvatar.sessionUUID && Vec3.length(props.localPosition) > NEAR_PICK_MAX_DISTANCE * 2.0) { // for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip. - print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand."); + print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + + props.parentID + " " + vec3toStr(props.position)); this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip", [JSON.stringify(this.hand)]); From 49f2724608370d86c62ba6415079c4ad80e450cd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 13:49:03 -0800 Subject: [PATCH 3/3] don't return void --- libraries/entities/src/EntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 64d33ceac5..f496eaced4 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1482,7 +1482,7 @@ void EntityItem::updateAngularVelocityFromNetwork(const glm::vec3& value) { if (shouldSuppressLocationEdits()) { return; } - return updateAngularVelocity(value); + updateAngularVelocity(value); } void EntityItem::updateAngularDamping(float value) {