diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index db22130c2c..50fdf3353c 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -116,6 +116,11 @@ var DEFAULT_GRABBABLE_DATA = { invertSolidWhileHeld: false }; + +// sometimes we want to exclude objects from being picked +var USE_BLACKLIST = true; +var blacklist = []; + //we've created various ways of visualizing looking for and moving distant objects var USE_ENTITY_LINES_FOR_SEARCHING = false; var USE_OVERLAY_LINES_FOR_SEARCHING = false; @@ -774,9 +779,19 @@ function MyController(hand) { }) } - var intersection = Entities.findRayIntersection(pickRayBacked, true); Messages.sendMessage('Hifi-Light-Overlay-Ray-Check', JSON.stringify(pickRayBacked)); + + var intersection; + + if (USE_BLACKLIST === true && blacklist.length !== 0) { + intersection = Entities.findRayIntersection(pickRayBacked, true, [], blacklist); + } else { + intersection = Entities.findRayIntersection(pickRayBacked, true); + } + + if (intersection.intersects) { + // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); @@ -1714,6 +1729,7 @@ function update() { Messages.subscribe('Hifi-Hand-Disabler'); Messages.subscribe('Hifi-Hand-Grab'); +Messages.subscribe('Hifi-Hand-RayPick-Blacklist'); handleHandMessages = function(channel, message, sender) { if (sender === MyAvatar.sessionUUID) { @@ -1738,6 +1754,24 @@ handleHandMessages = function(channel, message, sender) { } catch (e) {} } + else if (channel === 'Hifi-Hand-RayPick-Blacklist') { + try { + var data = JSON.parse(message); + var action = data.action; + var id = data.id; + var index = blacklist.indexOf(id); + + if (action === 'add' && index ===-1) { + blacklist.push(id); + } + if (action === 'remove') { + if (index > -1) { + blacklist.splice(index, 1); + } + } + + } catch (e) {} + } } } diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 3ead989d6d..08271fa7a8 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -21,6 +21,7 @@ var VISIBLE_PANEL = true; var USE_LABELS = true; var LEFT_LABELS = false; var RIGHT_LABELS = true; +var ROTATE_CLOSE_BUTTON = false; //variables for managing overlays var selectionDisplay; @@ -65,6 +66,7 @@ var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); var TRANSPARENT_PANEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/transparent_box_alpha_15.fbx'; +var VISIBLE_PANEL_SCRIPT_URL = Script.resolvePath('visiblePanel.js?' + Math.random(0, 100)); var RED = { red: 255, @@ -137,7 +139,7 @@ var slidersRef = { var light = null; var basePosition; -var avatarRotation; +var avatarRotation; function entitySlider(light, color, sliderType, displayText, row) { this.light = light; @@ -150,7 +152,7 @@ function entitySlider(light, color, sliderType, displayText, row) { this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); this.basePosition.y += 1; - basePosition=this.basePosition; + basePosition = this.basePosition; avatarRot = this.avatarRot; var message = { @@ -261,7 +263,7 @@ entitySlider.prototype = { blue: 255 }, position: this.endOfAxis, - parentID:this.axis, + parentID: this.axis, visible: false } @@ -312,7 +314,7 @@ entitySlider.prototype = { blue: 0 }, position: position, - rotation:this.avatarRot, + rotation: this.avatarRot, } print('BEFORE CREATE LABEL' + JSON.stringify(labelProperties)) this.label = Entities.addEntity(labelProperties); @@ -499,7 +501,7 @@ function makeSliders(light) { sliders.push(slidersRef.exponent); } - createCloseButton(slidersRef.exponent.endOfAxis); + createCloseButton(slidersRef.color_red.axisStart); subscribeToSliderMessages(); @@ -566,28 +568,28 @@ function createPanelEntity(position) { function createVisiblePanel() { var totalOffset = -PER_ROW_OFFSET.y * sliders.length; - var moveRight =Vec3.sum(basePosition,Vec3.multiply(AXIS_SCALE/2,Quat.getRight(avatarRot))); + var moveRight = Vec3.sum(basePosition, Vec3.multiply(AXIS_SCALE / 2, Quat.getRight(avatarRot))); - var moveDown = Vec3.sum(moveRight,Vec3.multiply((sliders.length+1)/2,PER_ROW_OFFSET)) + var moveDown = Vec3.sum(moveRight, Vec3.multiply((sliders.length + 1) / 2, PER_ROW_OFFSET)) var panelProperties = { name: 'Hifi-Visible-Transparent-Panel', type: 'Model', modelURL: TRANSPARENT_PANEL_URL, dimensions: { - x: AXIS_SCALE+0.1, + x: AXIS_SCALE + 0.1, y: totalOffset, - z: SLIDER_DIMENSIONS.z/4 + z: SLIDER_DIMENSIONS.z / 4 }, visible: true, collisionsWillMove: false, ignoreForCollisions: true, position: moveDown, - rotation:avatarRot + rotation: avatarRot, + script: VISIBLE_PANEL_SCRIPT_URL } var panel = Entities.addEntity(panelProperties); - var data = {action:'add', id:panel}; - Messages.sendMessage ('Hifi-Hand-RayPick-Blacklist',JSON.stringify(data)) + return panel } @@ -617,19 +619,25 @@ function createLightModel(position, rotation) { var closeButtons = []; -function createCloseButton(endOfAxis) { +function createCloseButton(axisStart) { + var MARGIN = 0.10; + var VERTICAL_OFFFSET = { + x: 0, + y: 0.15, + z: 0 + }; + var leftVector = Vec3.multiply(-1, Quat.getRight(avatarRot)); + var extension = Vec3.multiply(MARGIN, leftVector); + var position = Vec3.sum(axisStart, extension); var buttonProperties = { name: 'Hifi-Close-Button', type: 'Model', modelURL: CLOSE_BUTTON_MODEL_URL, dimensions: CLOSE_BUTTON_DIMENSIONS, - position: Vec3.sum(endOfAxis, { - x: 0, - y: -0.15, - z: 0 - }), - rotation: Quat.fromPitchYawRollDegrees(0, 45, 90), + position: Vec3.sum(position, VERTICAL_OFFFSET), + rotation: Quat.multiply(avatarRot,Quat.fromPitchYawRollDegrees(90, 0, 45)), + //rotation: Quat.fromPitchYawRollDegrees(0, 0, 90), collisionsWillMove: false, ignoreForCollisions: true, script: CLOSE_BUTTON_SCRIPT_URL, @@ -644,7 +652,9 @@ function createCloseButton(endOfAxis) { closeButtons.push(button); - Script.update.connect(rotateCloseButtons); + if(ROTATE_CLOSE_BUTTON===true){ + Script.update.connect(rotateCloseButtons); + } } function rotateCloseButtons() { @@ -732,7 +742,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { var lightID = doesIntersect.entityID; if (currentLight === lightID) { - print('ALREADY HAVE A BLOCK, EXIT') + // print('ALREADY HAVE A BLOCK, EXIT') return; } @@ -828,7 +838,7 @@ function cleanup(fromMessage) { id: visiblePanel }; Messages.sendMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data)) - + selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); if (hasParent === false) { diff --git a/examples/light_modifier/visiblePanel.js b/examples/light_modifier/visiblePanel.js new file mode 100644 index 0000000000..cf6875fc59 --- /dev/null +++ b/examples/light_modifier/visiblePanel.js @@ -0,0 +1,40 @@ +// +// visiblePanel.js +// +// Created by James Pollack @imgntn on 12/15/2015 +// Copyright 2015 High Fidelity, Inc. +// +// Entity script that disables picking on this panel. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + function VisiblePanel() { + return this; + } + + VisiblePanel.prototype = { + preload: function(entityID) { + this.entityID = entityID; + + var data = { + action: 'add', + id: this.entityID + }; + Messages.sendMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data)) + }, + unload: function() { + var data = { + action: 'remove', + id: this.entityID + }; + Messages.sendMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data)) + } + + }; + + return new VisiblePanel(); +}); \ No newline at end of file