From a179df29fbc4d0d0ac506598aac1e1b2aa9de709 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Tue, 10 Oct 2017 10:31:40 -0700 Subject: [PATCH] mouse grab non-dynamic entities --- scripts/system/controllers/grab.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/system/controllers/grab.js b/scripts/system/controllers/grab.js index 0e9b8569ae..40b1bfd23b 100644 --- a/scripts/system/controllers/grab.js +++ b/scripts/system/controllers/grab.js @@ -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 = Entities.getEntityProperties(this.entityID, ["dynamic", "localVelocity"]); + entityProps.dynamic = false; + entityProps.localVelocity = {x: 0, y: 0, z: 0}; + Entities.editEntity(this.entityID, entityProps); + } + this.actionID = null; LaserPointers.setRenderState(this.mouseRayEntities, "");