From 539cf35f30970c031ea0ccc48aa8cadf206b2fd3 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 3 Nov 2017 17:14:27 -0700 Subject: [PATCH] saving work --- interface/src/raypick/LaserPointer.cpp | 2 +- interface/src/raypick/LaserPointer.h | 2 +- .../controllerModules/farActionGrabEntity.js | 44 ++++++++++++++++++- .../libraries/controllerDispatcherUtils.js | 29 ++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 75b43a251b..9da8ff34ac 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -233,7 +233,7 @@ void LaserPointer::setLaserLength(const float laserLength) { }); } -void LaserPointer::setLockEndUUID(QUuid objectID, const bool isOverlay) { +void LaserPointer::setLockEndUUID(QUuid objectID, const bool isOverlay, const glm::mat4& offset) { withWriteLock([&] { _objectLockEnd = std::pair(objectID, isOverlay); }); diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index f2350c7199..a80f9d447d 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -74,7 +74,7 @@ public: void setPrecisionPicking(const bool precisionPicking); void setLaserLength(const float laserLength); - void setLockEndUUID(QUuid objectID, const bool isOverlay); + void setLockEndUUID(QUuid objectID, const bool isOverlay, const glm::mat4& offset = glm::mat4()); void setIgnoreItems(const QVector& ignoreItems) const; void setIncludeItems(const QVector& includeItems) const; diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index e34855d521..e63d7c7c35 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -19,6 +19,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllers.js"); +Script.include("/~/system/libraries/Xform.hs"); (function() { var PICK_WITH_HAND_RAY = true; @@ -113,10 +114,42 @@ Script.include("/~/system/libraries/controllers.js"); ]; var MARGIN = 25; + + function TargetObject(entityID) { + this.entityID = entityID; + this.entityProps = null; + this.parentID = null; + this.parentProps = []; + this.childrenProps = []; + this.parentsCollisionStatus = []; + this.childrenCollisionStatus = []; + this.madeDynamic = null; + this.parentEntityProps = null; + + this.makeDynamic = function() { + }; + + this.saveCollisionStatus = function() { + }; + + this.restoreEntitiesProperties = function() { + }; + + this.getTargetEntity = function() { + var parentPropsLength = this.parentProps.length; + if (parentPropsLength !== 0) { + return this.parentProps[parentPropsLength].id; + } + return this.entityID; + }; + } + function FarActionGrabEntity(hand) { this.hand = hand; this.grabbedThingID = null; + this.targetObject = null; this.actionID = null; // action this script created... + this.entityToLockOnto = null; this.entityWithContextOverlay = false; this.contextOverlayTimer = false; this.previousCollisionStatus = false; @@ -158,7 +191,8 @@ Script.include("/~/system/libraries/controllers.js"); LaserPointers.enableLaserPointer(laserPointerID); LaserPointers.setRenderState(laserPointerID, mode); if (this.distanceHolding || this.distanceRotating) { - LaserPointers.setLockEndUUID(laserPointerID, this.grabbedThingID, this.grabbedIsOverlay); + // calculate offset + LaserPointers.setLockEndUUID(laserPointerID, this.entityToLockOnto, this.grabbedIsOverlay); } else { LaserPointers.setLockEndUUID(laserPointerID, null, false); } @@ -351,6 +385,7 @@ Script.include("/~/system/libraries/controllers.js"); } this.actionID = null; this.grabbedThingID = null; + this.entityToLockOnto = null; }; this.updateRecommendedArea = function() { @@ -497,17 +532,24 @@ Script.include("/~/system/libraries/controllers.js"); if (rayPickInfo.type === RayPick.INTERSECTED_ENTITY) { if (controllerData.triggerClicks[this.hand]) { var entityID = rayPickInfo.objectID; + this.entityToLockOnto = entityID; var targetProps = Entities.getEntityProperties(entityID, [ "dynamic", "shapeType", "position", "rotation", "dimensions", "density", "userData", "locked", "type" ]); + this.targetObject = new TargetObject(entityID); if (entityID !== this.entityWithContextOverlay) { this.destroyContextOverlay(); } if (entityIsGrabbable(targetProps)) { + var groupRootProps = findGroupParent(controllerData, targetProps); + if (entityIsGrabbable(groupRootProps)) { + targetProps = groupRootProps; + entityID = targetProps.id; + } if (!entityIsDistanceGrabbable(targetProps)) { targetProps.dynamic = true; this.previousCollisionStatus = targetProps.collisionless; diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index cd3f1a711f..148530c5ec 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -35,12 +35,14 @@ propsArePhysical:true, controllerDispatcherPluginsNeedSort:true, projectOntoXYPlane:true, + getChildrenProps:true, projectOntoEntityXYPlane:true, projectOntoOverlayXYPlane:true, entityHasActions:true, ensureDynamic:true, findGroupParent:true, BUMPER_ON_VALUE:true, + getEntityParents:true, findHandChildEntities:true, TEAR_AWAY_DISTANCE:true, TEAR_AWAY_COUNT:true, @@ -306,6 +308,33 @@ findGroupParent = function (controllerData, targetProps) { return targetProps; }; +getChildrenProps = function(entityID) { + var childrenProps = []; + var childrenIDs = Entities.getChildrenIDs(entityID); + for (var index = 0; index < childrenIDs.length; index++) { + var childProps = Entities.getEntityProperties(childrenIDs[index]); + childrenProps.push(childProps); + } + return childrenProps; +}; + +getEntityParents = function(targetProps) { + var parentProperties = []; + while (targetProps.parentID && + targetProps.parentID !== Uuid.NULL && + Entities.getNestableType(targetProps.parentID) == "entity") { + var parentProps = Entities.getEntityProperties(targetProps.parentID, DISPATCHER_PROPERTIES); + if (!parentProps) { + break; + } + parentProps.id = targetProps.parentID; + targetProps = parentProps; + parentProperties.push(parentProps); + } + + return parentProperties; +}; + findHandChildEntities = function(hand) { // find children of avatar's hand joint