Merge pull request #11560 from druiz17/far-grab-nondynamic

Far grab non-dynamic entities
This commit is contained in:
Seth Alves 2017-10-10 12:29:38 -07:00 committed by GitHub
commit 4a3b59ea61
2 changed files with 37 additions and 6 deletions

View file

@ -119,6 +119,7 @@ Script.include("/~/system/libraries/controllers.js");
this.reticleMaxX;
this.reticleMinY = MARGIN;
this.reticleMaxY;
this.madeDynamic = false;
var ACTION_TTL = 15; // seconds
@ -344,6 +345,13 @@ Script.include("/~/system/libraries/controllers.js");
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.grabbedThingID, "releaseGrab", args);
if (this.madeDynamic) {
var props = {};
props.dynamic = false;
props.localVelocity = {x: 0, y: 0, z: 0};
Entities.editEntity(this.grabbedThingID, props);
this.madeDynamic = false;
}
this.actionID = null;
this.grabbedThingID = null;
};
@ -503,7 +511,13 @@ Script.include("/~/system/libraries/controllers.js");
this.destroyContextOverlay();
}
if (entityIsDistanceGrabbable(targetProps)) {
if (entityIsGrabbable(targetProps)) {
if (!entityIsDistanceGrabbable(targetProps)) {
targetProps.dynamic = true;
Entities.editEntity(entityID, targetProps);
this.madeDynamic = true;
}
if (!this.distanceRotating) {
this.grabbedThingID = entityID;
this.grabbedDistance = rayPickInfo.distance;

View file

@ -15,12 +15,13 @@
//
/* global MyAvatar, Entities, Script, Camera, Vec3, Reticle, Overlays, getEntityCustomData, Messages, Quat, Controller,
isInEditMode, HMD */
isInEditMode, HMD entityIsGrabbable*/
(function() { // BEGIN LOCAL_SCOPE
Script.include("/~/system/libraries/utils.js");
Script.include("/~/system/libraries/utils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
var MAX_SOLID_ANGLE = 0.01; // objects that appear smaller than this can't be grabbed
var DELAY_FOR_30HZ = 33; // milliseconds
@ -330,9 +331,11 @@ Grabber.prototype.pressEvent = function(event) {
return;
}
var isDynamic = Entities.getEntityProperties(pickResults.objectID, "dynamic").dynamic;
if (!isDynamic) {
// only grab dynamic objects
var props = Entities.getEntityProperties(pickResults.objectID, ["dynamic", "userData", "locked", "type"]);
var isDynamic = props.dynamic;
var isGrabbable = props.grabbable;
if (!entityIsGrabbable(props)) {
// only grab grabbable objects
return;
}
@ -350,6 +353,7 @@ Grabber.prototype.pressEvent = function(event) {
var entityProperties = Entities.getEntityProperties(clickedEntity);
this.startPosition = entityProperties.position;
this.lastRotation = entityProperties.rotation;
this.madeDynamic = false;
var cameraPosition = Camera.getPosition();
var objectBoundingDiameter = Vec3.length(entityProperties.dimensions);
@ -361,6 +365,11 @@ Grabber.prototype.pressEvent = function(event) {
return;
}
if (entityIsGrabbable(props) && !isDynamic) {
entityProperties.dynamic = true;
Entities.editEntity(clickedEntity, entityProperties);
this.madeDynamic = true;
}
// this.activateEntity(clickedEntity, entityProperties);
this.isGrabbing = true;
@ -416,6 +425,14 @@ Grabber.prototype.releaseEvent = function(event) {
if (this.actionID) {
Entities.deleteAction(this.entityID, this.actionID);
}
if (this.madeDynamic) {
var entityProps = {};
entityProps.dynamic = false;
entityProps.localVelocity = {x: 0, y: 0, z: 0};
Entities.editEntity(this.entityID, entityProps);
}
this.actionID = null;
LaserPointers.setRenderState(this.mouseRayEntities, "");