diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 2bf908ab57..711e64f938 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -23,5 +23,6 @@ Script.load("system/controllers/handControllerGrab.js"); Script.load("system/controllers/handControllerPointer.js"); Script.load("system/controllers/squeezeHands.js"); Script.load("system/controllers/grab.js"); +Script.load("system/controllers/teleport.js"); Script.load("system/dialTone.js"); Script.load("system/firstPersonHMD.js"); diff --git a/scripts/system/assets/models/teleportDestination.fbx b/scripts/system/assets/models/teleport.fbx similarity index 94% rename from scripts/system/assets/models/teleportDestination.fbx rename to scripts/system/assets/models/teleport.fbx index c850982f56..831f152add 100644 Binary files a/scripts/system/assets/models/teleportDestination.fbx and b/scripts/system/assets/models/teleport.fbx differ diff --git a/scripts/system/assets/models/teleportBeam.fbx b/scripts/system/assets/models/teleportBeam.fbx deleted file mode 100644 index 21b63d5843..0000000000 Binary files a/scripts/system/assets/models/teleportBeam.fbx and /dev/null differ diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 00e9b2c699..a2738396b6 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -49,8 +49,8 @@ var DROP_WITHOUT_SHAKE = false; var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position -var DISTANCE_HOLDING_UNITY_MASS = 1200; // The mass at which the distance holding action timeframe is unmodified -var DISTANCE_HOLDING_UNITY_DISTANCE = 6; // The distance at which the distance holding action timeframe is unmodified +var DISTANCE_HOLDING_UNITY_MASS = 1200; // The mass at which the distance holding action timeframe is unmodified +var DISTANCE_HOLDING_UNITY_DISTANCE = 6; // The distance at which the distance holding action timeframe is unmodified var MOVE_WITH_HEAD = true; // experimental head-control of distantly held objects var NO_INTERSECT_COLOR = { @@ -81,7 +81,7 @@ var EQUIP_RADIUS = 0.1; // radius used for palm vs equip-hotspot for equipping. var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position var NEAR_GRAB_RADIUS = 0.15; // radius used for palm vs object for near grabbing. -var NEAR_GRAB_MAX_DISTANCE = 1.0; // you cannot grab objects that are this far away from your hand +var NEAR_GRAB_MAX_DISTANCE = 1.0; // you cannot grab objects that are this far away from your hand var NEAR_GRAB_PICK_RADIUS = 0.25; // radius used for search ray vs object for near grabbing. @@ -251,13 +251,15 @@ function propsArePhysical(props) { // If another script is managing the reticle (as is done by HandControllerPointer), we should not be setting it here, // and we should not be showing lasers when someone else is using the Reticle to indicate a 2D minor mode. var EXTERNALLY_MANAGED_2D_MINOR_MODE = true; + function isIn2DMode() { // In this version, we make our own determination of whether we're aimed a HUD element, // because other scripts (such as handControllerPointer) might be using some other visualization // instead of setting Reticle.visible. return (EXTERNALLY_MANAGED_2D_MINOR_MODE && - (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position))); + (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position))); } + function restore2DMode() { if (!EXTERNALLY_MANAGED_2D_MINOR_MODE) { Reticle.setVisible(true); @@ -399,7 +401,6 @@ function MyController(hand) { this.updateSmoothedTrigger(); if (this.ignoreInput()) { - // print('in ignore input turn off') this.turnOffVisualizations(); return; } @@ -520,7 +521,7 @@ function MyController(hand) { visible: true }; this.searchSphere = Overlays.addOverlay("sphere", sphereProperties); - print('CREATED SEARCH OVERLAY : '+ this.searchSphere) + } else { Overlays.editOverlay(this.searchSphere, { @@ -529,7 +530,7 @@ function MyController(hand) { color: color, visible: true }); - print('EDITED SEARCH OVERLAY : '+ this.searchSphere) + } }; @@ -547,7 +548,6 @@ function MyController(hand) { alpha: 1 }; this.overlayLine = Overlays.addOverlay("line3d", lineProperties); - print('CREATED OVERLAY IT IS ' + this.overlayLine ) } else { Overlays.editOverlay(this.overlayLine, { @@ -560,9 +560,8 @@ function MyController(hand) { drawInFront: true, // Even when burried inside of something, show it. alpha: 1 }); - print('edited overlay line ' + this.overlayLine ) } - + }; this.searchIndicatorOn = function(distantPickRay) { @@ -577,12 +576,12 @@ function MyController(hand) { } var searchSphereLocation = Vec3.sum(distantPickRay.origin, - Vec3.multiply(distantPickRay.direction, this.searchSphereDistance)); + Vec3.multiply(distantPickRay.direction, this.searchSphereDistance)); this.searchSphereOn(searchSphereLocation, SEARCH_SPHERE_SIZE * this.searchSphereDistance, - (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); + (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); if ((USE_OVERLAY_LINES_FOR_SEARCHING === true) && PICK_WITH_HAND_RAY) { this.overlayLineOn(handPosition, searchSphereLocation, - (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); + (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); } }; @@ -766,13 +765,9 @@ function MyController(hand) { this.overlayLineOff = function() { if (_this.overlayLine !== null) { - Overlays.deleteOverlay(this.overlayLine); - print('REMOVING OVERLAY LINE' + this.overlayLine) - _this.overlayLine = null; + Overlays.deleteOverlay(this.overlayLine); + _this.overlayLine = null; } - - // print('overlay shoudl be null and is line is ' + this.overlayLine) - }; this.searchSphereOff = function() { @@ -805,27 +800,21 @@ function MyController(hand) { }; this.turnOffVisualizations = function(hand) { - // print('TURN OFF VISUALIZATIONS: ' + hand) if (USE_ENTITY_LINES_FOR_SEARCHING === true || USE_ENTITY_LINES_FOR_MOVING === true) { this.lineOff(); - // print('after line off') } if (USE_OVERLAY_LINES_FOR_SEARCHING === true || USE_OVERLAY_LINES_FOR_MOVING === true) { this.overlayLineOff(); - // print('after overlay line off') } if (USE_PARTICLE_BEAM_FOR_MOVING === true) { this.particleBeamOff(); - // print('after particle beam off') } this.searchSphereOff(); restore2DMode(); - // print('after all turn off calls') - }; this.triggerPress = function(value) { @@ -901,18 +890,34 @@ function MyController(hand) { this.createHotspots = function() { var _this = this; - var HAND_EQUIP_SPHERE_COLOR = { red: 90, green: 255, blue: 90 }; + var HAND_EQUIP_SPHERE_COLOR = { + red: 90, + green: 255, + blue: 90 + }; var HAND_EQUIP_SPHERE_ALPHA = 0.7; var HAND_EQUIP_SPHERE_RADIUS = 0.01; - var HAND_GRAB_SPHERE_COLOR = { red: 90, green: 90, blue: 255 }; + var HAND_GRAB_SPHERE_COLOR = { + red: 90, + green: 90, + blue: 255 + }; var HAND_GRAB_SPHERE_ALPHA = 0.3; var HAND_GRAB_SPHERE_RADIUS = NEAR_GRAB_RADIUS; - var EQUIP_SPHERE_COLOR = { red: 90, green: 255, blue: 90 }; + var EQUIP_SPHERE_COLOR = { + red: 90, + green: 255, + blue: 90 + }; var EQUIP_SPHERE_ALPHA = 0.3; - var GRAB_BOX_COLOR = { red: 90, green: 90, blue: 255 }; + var GRAB_BOX_COLOR = { + red: 90, + green: 90, + blue: 255 + }; var GRAB_BOX_ALPHA = 0.1; this.hotspotOverlays = []; @@ -936,7 +941,6 @@ function MyController(hand) { overlay: overlay, type: "hand" }); - print('ADDED HAND SPHERE OVERLAY : '+overlay) // add larger blue sphere around the palm. overlay = Overlays.addOverlay("sphere", { @@ -949,13 +953,16 @@ function MyController(hand) { ignoreRayIntersection: true, drawInFront: false }); - print('ADDED HAND SPHERE OVERLAY : '+overlay) this.hotspotOverlays.push({ entityID: undefined, overlay: overlay, type: "hand", - localPosition: {x: 0, y: 0, z: 0} + localPosition: { + x: 0, + y: 0, + z: 0 + } }); } @@ -979,13 +986,16 @@ function MyController(hand) { ignoreRayIntersection: true, drawInFront: false }); - print('ADDED GRAB BOX OVERLAY : '+ overlay) _this.hotspotOverlays.push({ entityID: entityID, overlay: overlay, type: "near", - localPosition: {x: 0, y: 0, z: 0} + localPosition: { + x: 0, + y: 0, + z: 0 + } }); } }); @@ -1007,7 +1017,6 @@ function MyController(hand) { ignoreRayIntersection: true, drawInFront: false }); - print('ADDED SPHERE HOTSTPOT OVERLAY : '+ overlay) _this.hotspotOverlays.push({ entityID: hotspot.entityID, @@ -1023,7 +1032,9 @@ function MyController(hand) { var props; this.hotspotOverlays.forEach(function(overlayInfo) { if (overlayInfo.type === "hand") { - Overlays.editOverlay(overlayInfo.overlay, { position: _this.getHandPosition() }); + Overlays.editOverlay(overlayInfo.overlay, { + position: _this.getHandPosition() + }); } else if (overlayInfo.type === "equip") { _this.entityPropertyCache.updateEntity(overlayInfo.entityID); props = _this.entityPropertyCache.getProps(overlayInfo.entityID); @@ -1035,15 +1046,16 @@ function MyController(hand) { } else if (overlayInfo.type === "near") { _this.entityPropertyCache.updateEntity(overlayInfo.entityID); props = _this.entityPropertyCache.getProps(overlayInfo.entityID); - Overlays.editOverlay(overlayInfo.overlay, { position: props.position, rotation: props.rotation }); + Overlays.editOverlay(overlayInfo.overlay, { + position: props.position, + rotation: props.rotation + }); } }); }; this.destroyHotspots = function() { this.hotspotOverlays.forEach(function(overlayInfo) { - print('deleting overlay hotspot ' + overlayInfo.overlay) - Overlays.deleteOverlay(overlayInfo.overlay); }); this.hotspotOverlays = []; @@ -1071,8 +1083,8 @@ function MyController(hand) { var pickRay = { origin: PICK_WITH_HAND_RAY ? worldHandPosition : Camera.position, direction: PICK_WITH_HAND_RAY ? Quat.getUp(worldHandRotation) : Vec3.mix(Quat.getUp(worldHandRotation), - Quat.getFront(Camera.orientation), - HAND_HEAD_MIX_RATIO), + Quat.getFront(Camera.orientation), + HAND_HEAD_MIX_RATIO), length: PICK_MAX_DISTANCE }; @@ -1157,7 +1169,11 @@ function MyController(hand) { if (wearableProps && wearableProps.joints) { result.push({ entityID: entityID, - localPosition: {x: 0, y: 0, z: 0}, + localPosition: { + x: 0, + y: 0, + z: 0 + }, worldPosition: entityXform.pos, radius: EQUIP_RADIUS, joints: wearableProps.joints @@ -1174,8 +1190,8 @@ function MyController(hand) { var refCount = ("refCount" in grabProps) ? grabProps.refCount : 0; var okToEquipFromOtherHand = ((this.getOtherHandController().state == STATE_NEAR_GRABBING || - this.getOtherHandController().state == STATE_DISTANCE_HOLDING) && - this.getOtherHandController().grabbedEntity == hotspot.entityID); + this.getOtherHandController().state == STATE_DISTANCE_HOLDING) && + this.getOtherHandController().grabbedEntity == hotspot.entityID); if (refCount > 0 && !okToEquipFromOtherHand) { if (debug) { print("equip is skipping '" + props.name + "': grabbed by someone else"); @@ -1423,8 +1439,8 @@ function MyController(hand) { // search line visualizations if (USE_ENTITY_LINES_FOR_SEARCHING === true) { this.lineOn(rayPickInfo.searchRay.origin, - Vec3.multiply(rayPickInfo.searchRay.direction, LINE_LENGTH), - NO_INTERSECT_COLOR); + Vec3.multiply(rayPickInfo.searchRay.direction, LINE_LENGTH), + NO_INTERSECT_COLOR); } this.searchIndicatorOn(rayPickInfo.searchRay); @@ -1515,7 +1531,7 @@ function MyController(hand) { // controller pose is in avatar frame var avatarControllerPose = Controller.getPoseValue((this.hand === RIGHT_HAND) ? - Controller.Standard.RightHand : Controller.Standard.LeftHand); + Controller.Standard.RightHand : Controller.Standard.LeftHand); // transform it into world frame var controllerPositionVSAvatar = Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation); @@ -1537,7 +1553,7 @@ function MyController(hand) { // scale delta controller hand movement by radius. var handMoved = Vec3.multiply(Vec3.subtract(controllerPositionVSAvatar, this.previousControllerPositionVSAvatar), - radius); + radius); /// double delta controller rotation // var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did @@ -1562,7 +1578,7 @@ function MyController(hand) { var lastVelocity = Vec3.subtract(controllerPositionVSAvatar, this.previousControllerPositionVSAvatar); lastVelocity = Vec3.multiply(lastVelocity, 1.0 / deltaObjectTime); var newRadialVelocity = Vec3.dot(lastVelocity, - Vec3.normalize(Vec3.subtract(grabbedProperties.position, controllerPosition))); + Vec3.normalize(Vec3.subtract(grabbedProperties.position, controllerPosition))); var VELOCITY_AVERAGING_TIME = 0.016; this.grabRadialVelocity = (deltaObjectTime / VELOCITY_AVERAGING_TIME) * newRadialVelocity + @@ -1571,7 +1587,7 @@ function MyController(hand) { var RADIAL_GRAB_AMPLIFIER = 10.0; if (Math.abs(this.grabRadialVelocity) > 0.0) { this.grabRadius = this.grabRadius + (this.grabRadialVelocity * deltaObjectTime * - this.grabRadius * RADIAL_GRAB_AMPLIFIER); + this.grabRadius * RADIAL_GRAB_AMPLIFIER); } var newTargetPosition = Vec3.multiply(this.grabRadius, Quat.getUp(controllerRotation)); @@ -1689,16 +1705,28 @@ function MyController(hand) { if (this.fastHandMoveTimer < 0) { this.fastHandMoveDetected = false; } - var FAST_HAND_SPEED_REST_TIME = 1; // sec + var FAST_HAND_SPEED_REST_TIME = 1; // sec var FAST_HAND_SPEED_THRESHOLD = 0.4; // m/sec if (Vec3.length(worldHandVelocity) > FAST_HAND_SPEED_THRESHOLD) { this.fastHandMoveDetected = true; this.fastHandMoveTimer = FAST_HAND_SPEED_REST_TIME; } - var localHandUpAxis = this.hand === RIGHT_HAND ? {x: 1, y: 0, z: 0} : {x: -1, y: 0, z: 0}; + var localHandUpAxis = this.hand === RIGHT_HAND ? { + x: 1, + y: 0, + z: 0 + } : { + x: -1, + y: 0, + z: 0 + }; var worldHandUpAxis = Vec3.multiplyQbyV(worldHandRotation, localHandUpAxis); - var DOWN = {x: 0, y: -1, z: 0}; + var DOWN = { + x: 0, + y: -1, + z: 0 + }; var ROTATION_THRESHOLD = Math.cos(Math.PI / 8); var handIsUpsideDown = false; @@ -1800,8 +1828,16 @@ function MyController(hand) { } Entities.editEntity(this.grabbedEntity, { - velocity: {x: 0, y: 0, z: 0}, - angularVelocity: {x: 0, y: 0, z: 0}, + velocity: { + x: 0, + y: 0, + z: 0 + }, + angularVelocity: { + x: 0, + y: 0, + z: 0 + }, dynamic: false }); @@ -1868,7 +1904,7 @@ function MyController(hand) { if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) { // for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip. print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + - props.parentID + " " + vec3toStr(props.position)); + props.parentID + " " + vec3toStr(props.position)); if (this.state == STATE_NEAR_GRABBING) { this.callEntityMethodOnGrabbed("releaseGrab"); @@ -2110,7 +2146,9 @@ function MyController(hand) { // people are holding something and one of them will be able (if the other releases at the right time) to // bootstrap themselves with the held object. This happens because the meaning of "otherAvatar" in // the collision mask hinges on who the physics simulation owner is. - Entities.editEntity(entityID, {"collidesWith": COLLIDES_WITH_WHILE_MULTI_GRABBED}); + Entities.editEntity(entityID, { + "collidesWith": COLLIDES_WITH_WHILE_MULTI_GRABBED + }); } } setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data); @@ -2124,7 +2162,9 @@ function MyController(hand) { var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, handJointIndex); children.forEach(function(childID) { print("disconnecting stray child of hand: (" + _this.hand + ") " + childID); - Entities.editEntity(childID, {parentID: NULL_UUID}); + Entities.editEntity(childID, { + parentID: NULL_UUID + }); }); }; @@ -2170,12 +2210,24 @@ function MyController(hand) { data["dynamic"] && data["parentID"] == NULL_UUID && !data["collisionless"]) { - deactiveProps["velocity"] = {x: 0.0, y: 0.1, z: 0.0}; + deactiveProps["velocity"] = { + x: 0.0, + y: 0.1, + z: 0.0 + }; doSetVelocity = false; } if (noVelocity) { - deactiveProps["velocity"] = {x: 0.0, y: 0.0, z: 0.0}; - deactiveProps["angularVelocity"] = {x: 0.0, y: 0.0, z: 0.0}; + deactiveProps["velocity"] = { + x: 0.0, + y: 0.0, + z: 0.0 + }; + deactiveProps["angularVelocity"] = { + x: 0.0, + y: 0.0, + z: 0.0 + }; doSetVelocity = false; } @@ -2188,7 +2240,7 @@ function MyController(hand) { // be fixed. Entities.editEntity(entityID, { velocity: this.currentVelocity - // angularVelocity: this.currentAngularVelocity + // angularVelocity: this.currentAngularVelocity }); } @@ -2198,14 +2250,32 @@ function MyController(hand) { deactiveProps = { parentID: this.previousParentID, parentJointIndex: this.previousParentJointIndex, - velocity: {x: 0.0, y: 0.0, z: 0.0}, - angularVelocity: {x: 0.0, y: 0.0, z: 0.0} + velocity: { + x: 0.0, + y: 0.0, + z: 0.0 + }, + angularVelocity: { + x: 0.0, + y: 0.0, + z: 0.0 + } }; Entities.editEntity(entityID, deactiveProps); } else if (noVelocity) { - Entities.editEntity(entityID, {velocity: {x: 0.0, y: 0.0, z: 0.0}, - angularVelocity: {x: 0.0, y: 0.0, z: 0.0}, - dynamic: data["dynamic"]}); + Entities.editEntity(entityID, { + velocity: { + x: 0.0, + y: 0.0, + z: 0.0 + }, + angularVelocity: { + x: 0.0, + y: 0.0, + z: 0.0 + }, + dynamic: data["dynamic"] + }); } } else { data = null; @@ -2261,20 +2331,20 @@ var handleHandMessages = function(channel, message, sender) { if (sender === MyAvatar.sessionUUID) { if (channel === 'Hifi-Hand-Disabler') { if (message === 'left') { - leftController.turnOffVisualizations('left'); - handToDisable = LEFT_HAND; + leftController.turnOffVisualizations('left'); + handToDisable = LEFT_HAND; } if (message === 'right') { - rightController.turnOffVisualizations('right'); - handToDisable = RIGHT_HAND; + rightController.turnOffVisualizations('right'); + handToDisable = RIGHT_HAND; } if (message === "both") { print('disable both') - leftController.turnOffVisualizations('left'); - rightController.turnOffVisualizations('right'); + leftController.turnOffVisualizations('left'); + rightController.turnOffVisualizations('right'); } if (message === 'both' || message === 'none') { - // handToDisable = message; + // handToDisable = message; } } else if (channel === 'Hifi-Hand-Grab') { try { @@ -2352,5 +2422,4 @@ function handleMenuItemEvent(menuItem) { } } -Menu.menuItemEvent.connect(handleMenuItemEvent); - +Menu.menuItemEvent.connect(handleMenuItemEvent); \ No newline at end of file diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index 8426780a7a..b92a85aaf4 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -39,7 +39,7 @@ var NUMBER_OF_STEPS = 6; // var NUMBER_OF_STEPS = 20; -var TARGET_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/teleporter/target.fbx'; +var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport.fbx"); var TARGET_MODEL_DIMENSIONS = { x: 1.15, y: 0.5, @@ -584,22 +584,18 @@ function registerMappings() { teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress); teleportMapping.from(Controller.Standard.LeftPrimaryThumb).when(leftTrigger.down).to(function(value) { - print('tel 1') teleporter.enterTeleportMode('left') return; }); teleportMapping.from(Controller.Standard.RightPrimaryThumb).when(rightTrigger.down).to(function(value) { - print('tel 2') teleporter.enterTeleportMode('right') return; }); teleportMapping.from(Controller.Standard.RT).when(Controller.Standard.RightPrimaryThumb).to(function(value) { - print('tel 3') teleporter.enterTeleportMode('right') return; }); teleportMapping.from(Controller.Standard.LT).when(Controller.Standard.LeftPrimaryThumb).to(function(value) { - print('tel 4') teleporter.enterTeleportMode('left') return; });