Merge pull request #9347 from sethalves/tablet-ui-grab-no-patch

remember previous parentID in the script and try to put it back when releasing
This commit is contained in:
druiz17 2017-01-10 14:08:08 -08:00 committed by GitHub
commit 85c143e64d

View file

@ -1523,7 +1523,8 @@ function MyController(hand) {
this.grabbedEntity = null; this.grabbedEntity = null;
this.grabbedOverlay = null; this.grabbedOverlay = null;
this.isInitialGrab = false; this.isInitialGrab = false;
this.shouldResetParentOnRelease = false; this.previousParentID = NULL_UUID;
this.previousParentJointIndex = -1;
this.preparingHoldRelease = false; this.preparingHoldRelease = false;
this.checkForStrayChildren(); this.checkForStrayChildren();
@ -1594,10 +1595,6 @@ function MyController(hand) {
// If near something grabbable, grab it! // If near something grabbable, grab it!
if ((this.triggerSmoothedGrab() || this.secondarySqueezed()) && nearGrabEnabled) { if ((this.triggerSmoothedGrab() || this.secondarySqueezed()) && nearGrabEnabled) {
this.setState(STATE_NEAR_GRABBING, "near grab '" + name + "'"); this.setState(STATE_NEAR_GRABBING, "near grab '" + name + "'");
var props = entityPropertiesCache.getProps(entity);
this.shouldResetParentOnRelease = true;
this.previousParentID = props.parentID;
this.previousParentJointIndex = props.parentJointIndex;
return; return;
} else { } else {
// potentialNearGrabEntity = entity; // potentialNearGrabEntity = entity;
@ -2271,7 +2268,7 @@ function MyController(hand) {
} }
var isPhysical = propsArePhysical(grabbedProperties) || entityHasActions(this.grabbedEntity); var isPhysical = propsArePhysical(grabbedProperties) || entityHasActions(this.grabbedEntity);
if (isPhysical && this.state == STATE_NEAR_GRABBING) { if (isPhysical && this.state == STATE_NEAR_GRABBING && grabbedProperties.parentID === NULL_UUID) {
// grab entity via action // grab entity via action
if (!this.setupHoldAction()) { if (!this.setupHoldAction()) {
return; return;
@ -2305,6 +2302,15 @@ function MyController(hand) {
} }
Entities.editEntity(this.grabbedEntity, reparentProps); Entities.editEntity(this.grabbedEntity, reparentProps);
this.previousParentID = grabbedProperties.parentID;
this.previousParentJointIndex = grabbedProperties.parentJointIndex;
if (grabbedProperties.parentID === MyAvatar.sessionUUID &&
this.getOtherHandController().state == STATE_NEAR_GRABBING) {
// one hand took it from the other
this.previousParentID = NULL_UUID;
this.previousParentJointIndex = -1;
}
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'equip', action: 'equip',
grabbedEntity: this.grabbedEntity, grabbedEntity: this.grabbedEntity,
@ -2845,13 +2851,22 @@ function MyController(hand) {
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
if (this.actionID !== null) { if (this.actionID !== null) {
Entities.deleteAction(this.grabbedEntity, this.actionID); Entities.deleteAction(this.grabbedEntity, this.actionID);
} } else {
// no action, so it's a parenting grab
if (this.shouldResetParentOnRelease) { if (this.previousParentID === NULL_UUID) {
Entities.editEntity(this.grabbedEntity, { Entities.editEntity(this.grabbedEntity, {
parentID: this.previousParentID, parentID: this.previousParentID,
parentJointIndex: this.previousParentJointIndex parentJointIndex: this.previousParentJointIndex
}); });
} else {
// we're putting this back as a child of some other parent, so zero its velocity
Entities.editEntity(this.grabbedEntity, {
parentID: this.previousParentID,
parentJointIndex: this.previousParentJointIndex,
velocity: {x: 0, y: 0, z: 0},
angularVelocity: {x: 0, y: 0, z: 0}
});
}
} }
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({