mouse grab non-dynamic entities

This commit is contained in:
druiz17 2017-10-10 10:31:40 -07:00
parent d0eb6a3ad0
commit a179df29fb

View file

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