This commit is contained in:
James B. Pollack 2015-12-28 14:50:35 -08:00
commit f0a12e0251
3 changed files with 107 additions and 23 deletions

View file

@ -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) {}
}
}
}

View file

@ -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,
@ -499,7 +501,7 @@ function makeSliders(light) {
sliders.push(slidersRef.exponent);
}
createCloseButton(slidersRef.exponent.endOfAxis);
createCloseButton(slidersRef.color_red.axisStart);
subscribeToSliderMessages();
@ -582,12 +584,12 @@ function createVisiblePanel() {
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,8 +652,10 @@ function createCloseButton(endOfAxis) {
closeButtons.push(button);
if(ROTATE_CLOSE_BUTTON===true){
Script.update.connect(rotateCloseButtons);
}
}
function rotateCloseButtons() {
closeButtons.forEach(function(button) {
@ -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;
}

View file

@ -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();
});