Update viveHandsv2 to hide on equip

This commit is contained in:
Ryan Huffman 2016-09-30 16:56:53 -07:00
parent 4ba637edf1
commit a463a3e608
3 changed files with 172 additions and 48 deletions

View file

@ -17,12 +17,23 @@ createControllerDisplay = function(config) {
},
mappingName: "mapping-display",
setVisible: function(visible) {
print("CONTROLLER_DISPLAY::Setting visible", this.overlays.length);
for (var i = 0; i < this.overlays.length; ++i) {
print("i", i, this.overlays[i]);
Overlays.editOverlay(this.overlays[i], {
visible: visible
});
}
},
setPartVisible: function(partName, visible) {
return;
if (partName in this.partOverlays) {
debug("Setting part visible", partName, visible);
for (var i = 0; i < this.partOverlays[partName].length; ++i) {
Overlays.editOverlay(this.partOverlays[partName][i], {
visible: visible
//visible: visible
});
}
}

View file

@ -43,7 +43,7 @@ var viveNaturalPosition = {
var viveModelURL = "atp:/controller/vive_body.fbx";
var viveTipsModelURL = "atp:/controller/vive_tips.fbx"
VIVE_CONTROLLER_CONFIGURATION = {
VIVE_CONTROLLER_CONFIGURATION_LEFT = {
name: "Vive",
controllers: [
{
@ -154,10 +154,14 @@ VIVE_CONTROLLER_CONFIGURATION = {
},
},
},
]
};
VIVE_CONTROLLER_CONFIGURATION_RIGHT = {
name: "Vive Right",
controllers: [
{
modelURL: viveModelURL,
jointIndex: MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND"),
@ -273,5 +277,5 @@ VIVE_CONTROLLER_CONFIGURATION = {
},
}
]
}
};

View file

@ -1,3 +1,33 @@
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
if (this.prototype) {
// Function.prototype doesn't have a prototype property
fNOP.prototype = this.prototype;
}
fBound.prototype = new fNOP();
return fBound;
};
}
Script.setTimeout(function() { print('timeout') }, 100);
Script.include("controllerDisplay.js");
Script.include("viveControllerConfiguration.js");
@ -15,16 +45,37 @@ var zeroRotation = { x: 0, y: 0, z: 0, w: 1 };
// Management of controller display //
///////////////////////////////////////////////////////////////////////////////
ControllerDisplayManager = function() {
var controllerDisplay = null;
var activeController = null;
var self = this;
var controllerLeft = null;
var controllerRight = null;
var controllerCheckerIntervalID = null;
this.setLeftVisible = function(visible) {
print("settings controller display to visible");
if (controllerLeft) {
print("doign it...", visible);
controllerLeft.setVisible(visible);
}
};
this.setRightVisible = function(visible) {
print("settings controller display to visible");
if (controllerRight) {
print("doign it...", visible);
controllerRight.setVisible(visible);
}
};
function updateControllers() {
if (HMD.active) {
if ("Vive" in Controller.Hardware) {
if (!activeController) {
debug("Found vive!");
activeController = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION);
if (!controllerLeft) {
debug("Found vive left!");
controllerLeft = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_LEFT);
}
if (!controllerRight) {
debug("Found vive right!");
controllerRight = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_RIGHT);
}
// We've found the controllers, we no longer need to look for active controllers
if (controllerCheckerIntervalID) {
@ -33,10 +84,7 @@ ControllerDisplayManager = function() {
}
} else {
debug("HMD active, but no controllers found");
if (activeController) {
deleteControllerDisplay(activeController);
activeController = null;
}
self.deleteControllerDisplays();
if (controllerCheckerIntervalID == null) {
controllerCheckerIntervalID = Script.setInterval(updateControllers, 1000);
}
@ -49,36 +97,38 @@ ControllerDisplayManager = function() {
Script.clearInterval(controllerCheckerIntervalID);
controllerCheckerIntervalID = null;
}
if (activeController) {
debug("Deleting controller");
deleteControllerDisplay(activeController);
activeController = null;
}
self.deleteControllerDisplays();
}
}
HMD.displayModeChanged.connect(updateControllers);
updateControllers();
Messages.subscribe('Controller-Display');
var handleMessages = function(channel, message, sender) {
if (!activeController) {
if (!controllerLeft && !controllerRight) {
return;
}
if (sender === MyAvatar.sessionUUID) {
if (channel === 'Controller-Display') {
debug('here');
var data = JSON.parse(message);
var name = data.name;
var visible = data.visible;
//c.setDisplayAnnotation(name, visible);
if (name in activeController.annotations) {
debug("hiding");
for (var i = 0; i < activeController.annotations[name].length; ++i) {
debug("hiding", i);
Overlays.editOverlay(activeController.annotations[name][i], { visible: visible });
if (controllerLeft) {
if (name in controllerLeft.annotations) {
debug("hiding");
for (var i = 0; i < controllerLeft.annotations[name].length; ++i) {
debug("hiding", i);
Overlays.editOverlay(controllerLeft.annotations[name][i], { visible: visible });
}
}
}
if (controllerRight) {
if (name in controllerRight.annotations) {
debug("hiding");
for (var i = 0; i < controllerRight.annotations[name].length; ++i) {
debug("hiding", i);
Overlays.editOverlay(controllerRight.annotations[name][i], { visible: visible });
}
}
}
} else if (channel === 'Controller-Display-Parts') {
@ -86,39 +136,98 @@ ControllerDisplayManager = function() {
var data = JSON.parse(message);
for (var name in data) {
var visible = data[name];
activeController.setPartVisible(name, visible);
if (controllerLeft) {
controllerLeft.setPartVisible(name, visible);
}
if (controllerRight) {
controllerRight.setPartVisible(name, visible);
}
}
} else if (channel === 'Controller-Set-Part-Layer') {
var data = JSON.parse(message);
for (var name in data) {
var layer = data[name];
activeController.setLayerForPart(name, layer);
if (controllerLeft) {
controllerLeft.setLayerForPart(name, layer);
}
if (controllerRight) {
controllerRight.setLayerForPart(name, layer);
}
}
} else if (channel == 'Hifi-Object-Manipulation') {// && sender == MyAvatar.sessionUUID) {
//print("got manip");
var data = JSON.parse(message);
//print("post data", data);
var visible = data.action != 'equip';
//print("Calling...");
if (data.joint == "LeftHand") {
self.setLeftVisible(visible);
} else if (data.joint == "RightHand") {
self.setRightVisible(visible);
}
}
}
}
Messages.messageReceived.connect(handleMessages);
this.destroy = function() {
print("Destroying controller display");
Messages.messageReceived.disconnect(handleMessages);
if (activeController) {
deleteControllerDisplay(activeController);
this.deleteControllerDisplays = function() {
if (controllerLeft) {
deleteControllerDisplay(controllerLeft);
controllerLeft = null;
}
if (controllerRight) {
deleteControllerDisplay(controllerRight);
controllerRight = null;
}
};
this.destroy = function() {
print("Destroying controller display");
Messages.messageReceived.disconnect(handleMessages);
self.deleteControllerDisplays();
};
HMD.displayModeChanged.connect(updateControllers);
updateControllers();
}
//var c = setupController(TOUCH_CONTROLLER_CONFIGURATION);
//var c = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION);
//c.setPartVisible("touchpad", false);
//c.setPartVisible("touchpad_teleport", false);
//layers = ["blank", "teleport", 'arrows'];
//num = 0;
//Script.setInterval(function() {
// print('num', num);
// num = (num + 1) % layers.length;
// c.setLayerForPart("touchpad", layers[num]);
//}, 2000);
//
/*
var controllerDisplayManager = new ControllerDisplayManager();
Messages.subscribe('Hifi-Object-Manipulation');
function onMessageReceived(channel, message, sender) {
print(channel, message, sender);
if (channel == 'Hifi-Object-Manipulation') {// && sender == MyAvatar.sessionUUID) {
print("got manip");
var data = JSON.parse(message);
print("post data", data);
var visible = data.action != 'equip';
print("Calling...");
if (data.joint == "LeftHand") {
controllerDisplayManager.setLeftVisible(visible);
} else if (data.joint == "RightHand") {
controllerDisplayManager.setRightVisible(visible);
}
}
}
Messages.messageReceived.connect(onMessageReceived);
var visible = false;
print("SETTING IT UP");
print("done");
function toggleVis() {
print("toggling");
visible = !visible;
controllerDisplayManager.setVisible(visible);
}
//toggleVis();
//Script.setInterval(toggleVis, 1000);
Script.scriptEnding.connect(function() {
print("destorying...");
controllerDisplayManager.destroy();
controllerDisplayManager = null;
});
*/