Merge pull request #7077 from sethalves/clean-up-grab-signaling

Clean up grab signaling + various fixes
This commit is contained in:
Chris Collins 2016-02-11 10:20:56 -08:00
commit a4afa03fe5
18 changed files with 165 additions and 230 deletions

View file

@ -120,10 +120,7 @@ function AttachedEntitiesManager() {
parsedMessage.action === 'loaded') {
// ignore
} else if (parsedMessage.action === 'release') {
manager.checkIfWearable(parsedMessage.grabbedEntity, parsedMessage.joint)
// manager.saveAttachedEntities();
} else if (parsedMessage.action === 'shared-release') {
manager.updateRelativeOffsets(parsedMessage.grabbedEntity);
manager.handleEntityRelease(parsedMessage.grabbedEntity, parsedMessage.joint)
// manager.saveAttachedEntities();
} else if (parsedMessage.action === 'equip') {
// manager.saveAttachedEntities();
@ -145,7 +142,14 @@ function AttachedEntitiesManager() {
return false;
}
this.checkIfWearable = function(grabbedEntity, releasedFromJoint) {
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
// if this is still equipped, just rewrite the position information.
var grabData = getEntityCustomData('grabKey', entityID, {});
if ("refCount" in grabData && grabData.refCount > 0) {
manager.updateRelativeOffsets(parsedMessage.grabbedEntity);
return;
}
var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints;
var props = Entities.getEntityProperties(grabbedEntity, ["position", "parentID", "parentJointIndex"]);

View file

@ -333,13 +333,9 @@ function MyController(hand) {
}
};
this.callEntityMethodOnGrabbed = function(entityMethodName, args) {
// print("Entity Method: " + entityMethodName + ", hand: " + this.hand);
if (args.length > 0) {
Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args);
} else {
Entities.callEntityMethod(this.grabbedEntity, entityMethodName);
}
this.callEntityMethodOnGrabbed = function(entityMethodName) {
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args);
}
this.setState = function(newState) {
@ -1080,7 +1076,7 @@ function MyController(hand) {
if (this.actionID !== null) {
this.setState(STATE_CONTINUE_DISTANCE_HOLDING);
this.activateEntity(this.grabbedEntity, grabbedProperties, false);
this.callSetupEntityMethods("startDistanceGrab");
this.callEntityMethodOnGrabbed("startDistanceGrab");
}
this.currentAvatarPosition = MyAvatar.position;
@ -1092,9 +1088,7 @@ function MyController(hand) {
this.continueDistanceHolding = function() {
if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []);
}
this.callEntityMethodOnGrabbed("releaseGrab");
return;
}
@ -1176,7 +1170,7 @@ function MyController(hand) {
this.handPreviousRotation = handRotation;
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
this.callEntityMethodOnGrabbed("continueDistantGrab", []);
this.callEntityMethodOnGrabbed("continueDistantGrab");
var defaultMoveWithHeadData = {
disableMoveWithHead: false
@ -1292,18 +1286,6 @@ function MyController(hand) {
return projection
};
this.callSetupEntityMethods = function(entityMethodName) {
if (this.isInitialGrab) {
if (this.hand === RIGHT_HAND) {
this.callEntityMethodOnGrabbed("setRightHand", []);
} else {
this.callEntityMethodOnGrabbed("setLeftHand", []);
}
this.callEntityMethodOnGrabbed("setHand", [this.hand]);
this.callEntityMethodOnGrabbed(entityMethodName, [JSON.stringify(this.hand)]);
}
}
this.hasPresetOffsets = function() {
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
if ("joints" in wearableData) {
@ -1340,9 +1322,7 @@ function MyController(hand) {
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []);
}
this.callEntityMethodOnGrabbed("releaseGrab");
return;
}
@ -1410,7 +1390,7 @@ function MyController(hand) {
}));
}
this.callSetupEntityMethods(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip");
this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip");
if (this.state == STATE_NEAR_GRABBING) {
// near grabbing
@ -1428,9 +1408,7 @@ function MyController(hand) {
this.continueNearGrabbing = function() {
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []);
}
this.callEntityMethodOnGrabbed("releaseGrab");
return;
}
if (this.state == STATE_CONTINUE_EQUIP_BD && this.bumperReleased()) {
@ -1439,15 +1417,13 @@ function MyController(hand) {
}
if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) {
this.setState(STATE_WAITING_FOR_BUMPER_RELEASE);
this.callEntityMethodOnGrabbed("releaseEquip", [JSON.stringify(this.hand)]);
this.callEntityMethodOnGrabbed("releaseEquip");
return;
}
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) {
this.setState(STATE_CONTINUE_EQUIP_BD);
if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", [JSON.stringify(this.hand)]);
this.callEntityMethodOnGrabbed("startEquip", [JSON.stringify(this.hand)]);
}
this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("startEquip");
return;
}
@ -1458,8 +1434,7 @@ function MyController(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)]);
this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip");
return;
}
@ -1480,15 +1455,11 @@ function MyController(hand) {
this.currentObjectTime = now;
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
if (this.isInitialGrab) {
if (this.state === STATE_CONTINUE_EQUIP) {
// this.callEntityMethodOnGrabbed("continueEquip", []);
Entities.callEntityMethod(this.grabbedEntity, "continueEquip");
}
if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
// this.callEntityMethodOnGrabbed("continueNearGrab", []);
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
}
if (this.state === STATE_CONTINUE_EQUIP) {
this.callEntityMethodOnGrabbed("continueEquip");
}
if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
this.callEntityMethodOnGrabbed("continueNearGrab");
}
if (this.actionID && this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) {
@ -1516,48 +1487,42 @@ function MyController(hand) {
this.waitingForBumperRelease = function() {
if (this.bumperReleased()) {
this.setState(STATE_RELEASE);
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
if (this.isInitialGrab) {
// TODO -- only one of these should be sent
this.callEntityMethodOnGrabbed("releaseGrab", []);
this.callEntityMethodOnGrabbed("unequip", []);
}
}
};
this.nearTrigger = function() {
if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger", []);
this.callEntityMethodOnGrabbed("stopNearTrigger");
return;
}
this.callSetupEntityMethods("startNearTrigger");
this.callEntityMethodOnGrabbed("startNearTrigger");
this.setState(STATE_CONTINUE_NEAR_TRIGGER);
};
this.farTrigger = function() {
if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []);
this.callEntityMethodOnGrabbed("stopFarTrigger");
return;
}
this.callSetupEntityMethods("startFarTrigger");
this.callEntityMethodOnGrabbed("startFarTrigger");
this.setState(STATE_CONTINUE_FAR_TRIGGER);
};
this.continueNearTrigger = function() {
if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger", []);
this.callEntityMethodOnGrabbed("stopNearTrigger");
return;
}
this.callEntityMethodOnGrabbed("continueNearTrigger", []);
this.callEntityMethodOnGrabbed("continueNearTrigger");
};
this.continueFarTrigger = function() {
if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []);
this.callEntityMethodOnGrabbed("stopFarTrigger");
return;
}
@ -1573,7 +1538,7 @@ function MyController(hand) {
this.lastPickTime = now;
if (intersection.entityID != this.grabbedEntity) {
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []);
this.callEntityMethodOnGrabbed("stopFarTrigger");
return;
}
}
@ -1581,7 +1546,7 @@ function MyController(hand) {
if (USE_ENTITY_LINES_FOR_MOVING === true) {
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
}
this.callEntityMethodOnGrabbed("continueFarTrigger", []);
this.callEntityMethodOnGrabbed("continueFarTrigger");
};
_this.allTouchedIDs = {};
@ -1641,16 +1606,15 @@ function MyController(hand) {
};
this.startTouch = function(entityID) {
this.callEntityMethodOnGrabbed("startTouch", []);
this.callEntityMethodOnGrabbed("startTouch");
};
this.continueTouch = function(entityID) {
// this.callEntityMethodOnGrabbed("continueTouch", []);
Entities.callEntityMethod(this.grabbedEntity, "continueTouch");
this.callEntityMethodOnGrabbed("continueTouch");
};
this.stopTouch = function(entityID) {
this.callEntityMethodOnGrabbed("stopTouch", []);
this.callEntityMethodOnGrabbed("stopTouch");
};
this.release = function() {
@ -1679,19 +1643,11 @@ function MyController(hand) {
this.actionID = null;
this.setState(STATE_OFF);
if (this.isInitialGrab) {
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'release',
grabbedEntity: this.grabbedEntity,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
}));
} else {
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'shared-release',
grabbedEntity: this.grabbedEntity,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
}));
}
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'release',
grabbedEntity: this.grabbedEntity,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
}));
this.grabbedEntity = null;
};
@ -1819,7 +1775,7 @@ function MyController(hand) {
this.grabbedEntity = loadedEntityID;
this.activateEntity(this.grabbedEntity, loadedProps, true);
this.isInitialGrab = true;
this.callSetupEntityMethods("startEquip");
this.callEntityMethodOnGrabbed("startEquip");
this.setState(STATE_CONTINUE_EQUIP);
}
}

View file

@ -33,7 +33,8 @@
};
var ARROW_MODEL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_textured.fbx";
var ARROW_COLLISION_HULL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj";
var ARROW_COLLISION_HULL_URL =
"http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj";
var ARROW_DIMENSIONS = {
x: 0.02,
@ -94,7 +95,6 @@
}
Bow.prototype = {
isGrabbed: false,
stringDrawn: false,
aiming: false,
arrowTipPosition: null,
@ -125,33 +125,13 @@
Entities.deleteEntity(this.arrow);
},
setLeftHand: function() {
if (this.isGrabbed === true) {
return false;
}
this.hand = 'left';
},
setRightHand: function() {
if (this.isGrabbed === true) {
return false;
}
this.hand = 'right';
},
startEquip: function() {
print('START BOW GRAB')
if (this.isGrabbed === true) {
return false;
}
this.isGrabbed = true;
this.initialHand = this.hand;
startEquip: function(entityID, args) {
this.hand = args[0];
avatarID = args[1];
//disable the opposite hand in handControllerGrab.js by message
var handToDisable = this.initialHand === 'right' ? 'left' : 'right';
var handToDisable = this.hand === 'right' ? 'left' : 'right';
print("disabling hand: " + handToDisable);
Messages.sendMessage('Hifi-Hand-Disabler', handToDisable);
var data = getEntityCustomData('grabbableKey', this.entityID, {});
@ -159,7 +139,7 @@
setEntityCustomData('grabbableKey', this.entityID, data);
},
continueEquip: function() {
continueEquip: function(entityID, args) {
this.deltaTime = checkInterval();
//debounce during debugging -- maybe we're updating too fast?
@ -188,25 +168,19 @@
this.checkStringHand();
},
releaseGrab: function() {
releaseEquip: function(entityID, args) {
// print('RELEASE GRAB EVENT')
if (this.isGrabbed === true && this.hand === this.initialHand) {
Messages.sendMessage('Hifi-Hand-Disabler', "none")
Messages.sendMessage('Hifi-Hand-Disabler', "none")
this.stringDrawn = false;
this.deleteStrings();
this.isGrabbed = false;
this.stringDrawn = false;
this.deleteStrings();
var data = getEntityCustomData('grabbableKey', this.entityID, {});
data.grabbable = true;
setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.hasArrowNotched = false;
}
var data = getEntityCustomData('grabbableKey', this.entityID, {});
data.grabbable = true;
setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.hasArrowNotched = false;
},
createArrow: function() {
@ -367,10 +341,10 @@
checkStringHand: function() {
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
var triggerLookup;
if (this.initialHand === 'left') {
if (this.hand === 'left') {
triggerLookup = 1;
this.getStringHandPosition = MyAvatar.getRightPalmPosition;
} else if (this.initialHand === 'right') {
} else if (this.hand === 'right') {
this.getStringHandPosition = MyAvatar.getLeftPalmPosition;
triggerLookup = 0;
}

View file

@ -119,7 +119,8 @@
//wait to make the bubbles collidable, so that they dont hit each other and the wand
Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2);
//release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble
//release the bubble -- when we create a new bubble, it will carry on and this update loop will
// affect the new bubble
this.createBubbleAtTipOfWand();
return;
} else {

View file

@ -24,15 +24,11 @@
Doll.prototype = {
audioInjector: null,
isGrabbed: false,
setLeftHand: function() {
this.hand = 'left';
},
setRightHand: function() {
this.hand = 'right';
},
startNearGrab: function(entityID, args) {
this.hand = args[0];
avatarID = args[1];
startNearGrab: function() {
Entities.editEntity(this.entityID, {
animation: {
url: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx",
@ -53,18 +49,18 @@
this.startNearGrab(id, params);
},
continueNearGrab: function() {
continueNearGrab: function(entityID, args) {
var props = Entities.getEntityProperties(this.entityID, ["position"]);
var audioOptions = {
position: props.position
};
this.audioInjector.options = audioOptions;
},
continueEquip: function() {
this.continueNearGrab();
continueEquip: function(entityID, args) {
this.continueNearGrab(entityID, args);
},
releaseGrab: function() {
releaseGrab: function(entityID, args) {
if (this.isGrabbed === true && this.hand === this.initialHand) {
this.audioInjector.stop();
Entities.editEntity(this.entityID, {
@ -79,8 +75,8 @@
this.isGrabbed = false;
}
},
releaseEquip: function() {
this.releaseGrab();
releaseEquip: function(entityID, args) {
this.releaseGrab(entityID, args);
},
preload: function(entityID) {

View file

@ -77,15 +77,10 @@
whichHand: null,
hasSpotlight: false,
spotlight: null,
setRightHand: function() {
this.hand = 'RIGHT';
},
setLeftHand: function() {
this.hand = 'LEFT';
},
startNearGrab: function(entityID, args) {
this.hand = args[0];
startNearGrab: function(entityID) {
print("FLASHLIGHT startNearGrab");
if (!this.hasSpotlight) {
@ -161,11 +156,11 @@
this.changeLightWithTriggerPressure(this.whichHand);
}
},
continueEquip: function() {
this.continueNearGrab();
continueEquip: function(entityID, args) {
this.continueNearGrab(entityID, args);
},
releaseGrab: function() {
releaseGrab: function(entityID, args) {
//delete the lights and reset state
if (this.hasSpotlight) {
Entities.deleteEntity(this.spotlight);
@ -177,8 +172,8 @@
this.lightOn = false;
}
},
releaseEquip: function() {
this.releaseGrab();
releaseEquip: function(entityID, args) {
this.releaseGrab(entityID, args);
},
changeLightWithTriggerPressure: function(flashLightHand) {

View file

@ -54,47 +54,26 @@
PingPongGun.prototype = {
hand: null,
whichHand: null,
gunTipPosition: null,
canShoot: false,
canShootTimeout: null,
setRightHand: function() {
this.hand = 1;
startEquip: function(entityID, args) {
this.hand = args[0] == "left" ? 0 : 1;
},
setLeftHand: function() {
this.hand = 0;
},
startEquip: function() {
this.setWhichHand();
},
setWhichHand: function() {
this.whichHand = this.hand;
},
continueEquip: function() {
if (this.whichHand === null) {
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
this.setWhichHand();
} else {
if (this.canShootTimeout !== null) {
Script.clearTimeout(this.canShootTimeout);
}
this.checkTriggerPressure(this.whichHand);
continueEquip: function(entityID, args) {
if (this.canShootTimeout !== null) {
Script.clearTimeout(this.canShootTimeout);
}
this.checkTriggerPressure(this.hand);
},
releaseEquip: function() {
releaseEquip: function(entityID, args) {
var _this = this;
if (this.whichHand === this.hand) {
this.whichHand = null;
this.canShootTimeout = Script.setTimeout(function() {
_this.canShoot = false;
}, 250);
}
this.canShootTimeout = Script.setTimeout(function() {
_this.canShoot = false;
}, 250);
},
checkTriggerPressure: function(gunHand) {
@ -102,7 +81,7 @@
if (this.triggerValue < RELOAD_THRESHOLD) {
// print('RELOAD');
this.canShoot = true;
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true && this.hand === this.whichHand) {
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) {
var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
this.shootBall(gunProperties);
this.canShoot = false;

View file

@ -49,10 +49,10 @@
startEquip: function(id, params) {
this.equipped = true;
this.hand = JSON.parse(params[0]);
this.hand = params[0] == "left" ? 0 : 1;
},
continueEquip: function() {
continueEquip: function(id, params) {
if (!this.equipped) {
return;
}
@ -111,7 +111,7 @@
});
},
unequip: function() {
releaseEquip: function(id, params) {
this.hand = null;
this.equipped = false;
Overlays.editOverlay(this.laser, {

View file

@ -38,20 +38,12 @@
Controller.Standard.RT,
];
this.setRightHand = function () {
this.hand = 1;
}
this.setLeftHand = function () {
this.hand = 0;
}
this.startNearGrab = function () {
this.whichHand = this.hand;
this.startNearGrab = function (entityID, args) {
this.hand = args[0] == "left" ? 0 : 1;
}
this.toggleWithTriggerPressure = function () {
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.whichHand]);
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]);
if (this.triggerValue < DISABLE_SPRAY_THRESHOLD && this.spraying === true) {
this.spraying = false;
this.disableStream();

View file

@ -412,7 +412,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
}
});
bool movingOrAnimating = isMoving() || isAnimatingSomething();
bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething();
if ((movingOrAnimating ||
_needsInitialSimulation ||
_model->getTranslation() != getPosition() ||

View file

@ -76,8 +76,8 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
_physicsInfo(nullptr),
_simulated(false)
{
setVelocity(ENTITY_ITEM_DEFAULT_VELOCITY);
setAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY);
setLocalVelocity(ENTITY_ITEM_DEFAULT_VELOCITY);
setLocalAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY);
// explicitly set transform parts to set dirty flags used by batch rendering
setScale(ENTITY_ITEM_DEFAULT_DIMENSIONS);
quint64 now = usecTimestampNow();
@ -244,8 +244,8 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
APPEND_ENTITY_PROPERTY(PROP_SIMULATION_OWNER, _simulationOwner.toByteArray());
APPEND_ENTITY_PROPERTY(PROP_POSITION, getLocalPosition());
APPEND_ENTITY_PROPERTY(PROP_ROTATION, getLocalOrientation());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getVelocity());
APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getAngularVelocity());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getLocalVelocity());
APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getLocalAngularVelocity());
APPEND_ENTITY_PROPERTY(PROP_ACCELERATION, getAcceleration());
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, getDimensions()); // NOTE: PROP_RADIUS obsolete
@ -1054,7 +1054,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper
COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensions); // NOTE: radius is obsolete
COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotation, getLocalOrientation);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(density, getDensity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getLocalVelocity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(acceleration, getAcceleration);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping);
@ -1066,7 +1066,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper
COPY_ENTITY_PROPERTY_TO_PROPERTIES(scriptTimestamp, getScriptTimestamp);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(collisionSoundURL, getCollisionSoundURL);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(registrationPoint, getRegistrationPoint);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getAngularVelocity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getLocalAngularVelocity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularDamping, getAngularDamping);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRenderAlpha, getLocalRenderAlpha);
@ -1562,7 +1562,7 @@ void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask
} else {
if (_dynamic) {
group = BULLET_COLLISION_GROUP_DYNAMIC;
} else if (isMoving() || hasActions()) {
} else if (isMovingRelativeToParent() || hasActions()) {
group = BULLET_COLLISION_GROUP_KINEMATIC;
} else {
group = BULLET_COLLISION_GROUP_STATIC;

View file

@ -81,6 +81,8 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
// TODO -- handle velocity and angularVelocity
scriptSideProperties.setPosition(worldPosition);
scriptSideProperties.setRotation(worldRotation);
@ -94,6 +96,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti
EntityItemProperties entitySideProperties = scriptSideProperties;
bool success;
// TODO -- handle velocity and angularVelocity
if (scriptSideProperties.localPositionChanged()) {
entitySideProperties.setPosition(scriptSideProperties.getLocalPosition());
} else if (scriptSideProperties.positionChanged()) {
@ -128,14 +132,14 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
auto newVelocity = propertiesWithSimID.getVelocity().length();
float cost = calculateCost(density * volume, 0, newVelocity);
cost *= costMultiplier;
if(cost > _currentAvatarEnergy) {
return QUuid();
} else {
//debit the avatar energy and continue
emit debitEnergySource(cost);
}
EntityItemID id = EntityItemID(QUuid::createUuid());
// If we have a local entity tree set, then also update it.

View file

@ -70,7 +70,7 @@ void EntitySimulation::prepareEntityForDelete(EntityItemPointer entity) {
}
void EntitySimulation::addEntityInternal(EntityItemPointer entity) {
if (entity->isMoving() && !entity->getPhysicsInfo()) {
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
QMutexLocker lock(&_mutex);
_simpleKinematicEntities.insert(entity);
}
@ -78,7 +78,7 @@ void EntitySimulation::addEntityInternal(EntityItemPointer entity) {
void EntitySimulation::changeEntityInternal(EntityItemPointer entity) {
QMutexLocker lock(&_mutex);
if (entity->isMoving() && !entity->getPhysicsInfo()) {
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
_simpleKinematicEntities.insert(entity);
} else {
_simpleKinematicEntities.remove(entity);

View file

@ -313,7 +313,11 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// pops to the next higher cell. So we want to check to see that the entity is large enough to be seen
// before we consider including it.
if (includeThisEntity) {
AABox entityBounds = entity->getAABox(success);
success = true;
// we can't cull a parent-entity by its dimensions because the child may be larger. we need to
// avoid sending details about a child but not the parent. the parent's queryAACube should have
// been adjusted to encompass the queryAACube of the child.
AABox entityBounds = entity->hasChildren() ? AABox(entityCube) : entity->getAABox(success);
if (!success) {
// if this entity is a child of an avatar, the entity-server wont be able to determine its
// AABox. If this happens, fall back to the queryAACube.

View file

@ -158,12 +158,12 @@ PhysicsMotionType EntityMotionState::computePhysicsMotionType() const {
}
return MOTION_TYPE_DYNAMIC;
}
return (_entity->isMoving() || _entity->hasActions()) ? MOTION_TYPE_KINEMATIC : MOTION_TYPE_STATIC;
return (_entity->isMovingRelativeToParent() || _entity->hasActions()) ? MOTION_TYPE_KINEMATIC : MOTION_TYPE_STATIC;
}
bool EntityMotionState::isMoving() const {
assert(entityTreeIsLocked());
return _entity && _entity->isMoving();
return _entity && _entity->isMovingRelativeToParent();
}
// This callback is invoked by the physics simulation in two cases:
@ -555,7 +555,7 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() {
}
// we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings
int bodyFlags = _body->getCollisionFlags();
bool isMoving = _entity->isMoving();
bool isMoving = _entity->isMovingRelativeToParent();
if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) ||
(bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) {
dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;

View file

@ -51,7 +51,7 @@ void PhysicalEntitySimulation::addEntityInternal(EntityItemPointer entity) {
if (!motionState) {
_entitiesToAddToPhysics.insert(entity);
}
} else if (entity->isMoving()) {
} else if (entity->isMovingRelativeToParent()) {
_simpleKinematicEntities.insert(entity);
}
}
@ -98,7 +98,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
_physicalObjects.remove(motionState);
_outgoingChanges.remove(motionState);
_entitiesToRemoveFromPhysics.insert(entity);
if (entity->isMoving()) {
if (entity->isMovingRelativeToParent()) {
_simpleKinematicEntities.insert(entity);
}
} else {
@ -109,7 +109,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
// Perhaps it's shape has changed and it can now be added?
_entitiesToAddToPhysics.insert(entity);
_simpleKinematicEntities.remove(entity); // just in case it's non-physical-kinematic
} else if (entity->isMoving()) {
} else if (entity->isMovingRelativeToParent()) {
_simpleKinematicEntities.insert(entity);
} else {
_simpleKinematicEntities.remove(entity); // just in case it's non-physical-kinematic
@ -209,7 +209,7 @@ void PhysicalEntitySimulation::getObjectsToAddToPhysics(VectorOfMotionStates& re
} else if (!entity->shouldBePhysical()) {
// this entity should no longer be on the internal _entitiesToAddToPhysics
entityItr = _entitiesToAddToPhysics.erase(entityItr);
if (entity->isMoving()) {
if (entity->isMovingRelativeToParent()) {
_simpleKinematicEntities.insert(entity);
}
} else if (entity->isReadyToComputeShape()) {

View file

@ -392,9 +392,15 @@ void SpatiallyNestable::setOrientation(const glm::quat& orientation) {
}
glm::vec3 SpatiallyNestable::getVelocity(bool& success) const {
glm::vec3 parentVelocity = getParentVelocity(success);
Transform parentTransform = getParentTransform(success);
glm::vec3 result;
glm::vec3 parentVelocity = getParentVelocity(success);
if (!success) {
return result;
}
Transform parentTransform = getParentTransform(success);
if (!success) {
return result;
}
_velocityLock.withReadLock([&] {
// TODO: take parent angularVelocity into account.
result = parentVelocity + parentTransform.getRotation() * _velocity;
@ -431,16 +437,25 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity) {
glm::vec3 SpatiallyNestable::getParentVelocity(bool& success) const {
glm::vec3 result;
SpatiallyNestablePointer parent = getParentPointer(success);
if (success && parent) {
if (!success) {
return result;
}
if (parent) {
result = parent->getVelocity(success);
}
return result;
}
glm::vec3 SpatiallyNestable::getAngularVelocity(bool& success) const {
glm::vec3 parentAngularVelocity = getParentAngularVelocity(success);
Transform parentTransform = getParentTransform(success);
glm::vec3 result;
glm::vec3 parentAngularVelocity = getParentAngularVelocity(success);
if (!success) {
return result;
}
Transform parentTransform = getParentTransform(success);
if (!success) {
return result;
}
_angularVelocityLock.withReadLock([&] {
result = parentAngularVelocity + parentTransform.getRotation() * _angularVelocity;
});
@ -475,7 +490,10 @@ void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity) {
glm::vec3 SpatiallyNestable::getParentAngularVelocity(bool& success) const {
glm::vec3 result;
SpatiallyNestablePointer parent = getParentPointer(success);
if (success && parent) {
if (!success) {
return result;
}
if (parent) {
result = parent->getAngularVelocity(success);
}
return result;
@ -672,6 +690,16 @@ QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
return children;
}
bool SpatiallyNestable::hasChildren() const {
bool result = false;
_childrenLock.withReadLock([&] {
if (_children.size() > 0) {
result = true;
}
});
return result;
}
const Transform SpatiallyNestable::getAbsoluteJointTransformInObjectFrame(int jointIndex) const {
Transform jointTransformInObjectFrame;
glm::vec3 position = getAbsoluteJointTranslationInObjectFrame(jointIndex);

View file

@ -116,6 +116,8 @@ public:
virtual void setLocalScale(const glm::vec3& scale);
QList<SpatiallyNestablePointer> getChildren() const;
bool hasChildren() const;
NestableType getNestableType() const { return _nestableType; }
// this object's frame