mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 21:35:04 +02:00
Update viveHandsv2 to hide on equip
This commit is contained in:
parent
4ba637edf1
commit
a463a3e608
3 changed files with 172 additions and 48 deletions
|
@ -17,12 +17,23 @@ createControllerDisplay = function(config) {
|
||||||
},
|
},
|
||||||
mappingName: "mapping-display",
|
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) {
|
setPartVisible: function(partName, visible) {
|
||||||
|
return;
|
||||||
if (partName in this.partOverlays) {
|
if (partName in this.partOverlays) {
|
||||||
debug("Setting part visible", partName, visible);
|
debug("Setting part visible", partName, visible);
|
||||||
for (var i = 0; i < this.partOverlays[partName].length; ++i) {
|
for (var i = 0; i < this.partOverlays[partName].length; ++i) {
|
||||||
Overlays.editOverlay(this.partOverlays[partName][i], {
|
Overlays.editOverlay(this.partOverlays[partName][i], {
|
||||||
visible: visible
|
//visible: visible
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ var viveNaturalPosition = {
|
||||||
var viveModelURL = "atp:/controller/vive_body.fbx";
|
var viveModelURL = "atp:/controller/vive_body.fbx";
|
||||||
var viveTipsModelURL = "atp:/controller/vive_tips.fbx"
|
var viveTipsModelURL = "atp:/controller/vive_tips.fbx"
|
||||||
|
|
||||||
VIVE_CONTROLLER_CONFIGURATION = {
|
VIVE_CONTROLLER_CONFIGURATION_LEFT = {
|
||||||
name: "Vive",
|
name: "Vive",
|
||||||
controllers: [
|
controllers: [
|
||||||
{
|
{
|
||||||
|
@ -154,10 +154,14 @@ VIVE_CONTROLLER_CONFIGURATION = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
VIVE_CONTROLLER_CONFIGURATION_RIGHT = {
|
||||||
|
name: "Vive Right",
|
||||||
|
controllers: [
|
||||||
{
|
{
|
||||||
modelURL: viveModelURL,
|
modelURL: viveModelURL,
|
||||||
jointIndex: MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND"),
|
jointIndex: MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND"),
|
||||||
|
@ -273,5 +277,5 @@ VIVE_CONTROLLER_CONFIGURATION = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
|
@ -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("controllerDisplay.js");
|
||||||
Script.include("viveControllerConfiguration.js");
|
Script.include("viveControllerConfiguration.js");
|
||||||
|
|
||||||
|
@ -15,16 +45,37 @@ var zeroRotation = { x: 0, y: 0, z: 0, w: 1 };
|
||||||
// Management of controller display //
|
// Management of controller display //
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
ControllerDisplayManager = function() {
|
ControllerDisplayManager = function() {
|
||||||
var controllerDisplay = null;
|
var self = this;
|
||||||
var activeController = null;
|
var controllerLeft = null;
|
||||||
|
var controllerRight = null;
|
||||||
var controllerCheckerIntervalID = 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() {
|
function updateControllers() {
|
||||||
if (HMD.active) {
|
if (HMD.active) {
|
||||||
if ("Vive" in Controller.Hardware) {
|
if ("Vive" in Controller.Hardware) {
|
||||||
if (!activeController) {
|
if (!controllerLeft) {
|
||||||
debug("Found vive!");
|
debug("Found vive left!");
|
||||||
activeController = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION);
|
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
|
// We've found the controllers, we no longer need to look for active controllers
|
||||||
if (controllerCheckerIntervalID) {
|
if (controllerCheckerIntervalID) {
|
||||||
|
@ -33,10 +84,7 @@ ControllerDisplayManager = function() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug("HMD active, but no controllers found");
|
debug("HMD active, but no controllers found");
|
||||||
if (activeController) {
|
self.deleteControllerDisplays();
|
||||||
deleteControllerDisplay(activeController);
|
|
||||||
activeController = null;
|
|
||||||
}
|
|
||||||
if (controllerCheckerIntervalID == null) {
|
if (controllerCheckerIntervalID == null) {
|
||||||
controllerCheckerIntervalID = Script.setInterval(updateControllers, 1000);
|
controllerCheckerIntervalID = Script.setInterval(updateControllers, 1000);
|
||||||
}
|
}
|
||||||
|
@ -49,36 +97,38 @@ ControllerDisplayManager = function() {
|
||||||
Script.clearInterval(controllerCheckerIntervalID);
|
Script.clearInterval(controllerCheckerIntervalID);
|
||||||
controllerCheckerIntervalID = null;
|
controllerCheckerIntervalID = null;
|
||||||
}
|
}
|
||||||
if (activeController) {
|
self.deleteControllerDisplays();
|
||||||
debug("Deleting controller");
|
|
||||||
deleteControllerDisplay(activeController);
|
|
||||||
activeController = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HMD.displayModeChanged.connect(updateControllers);
|
|
||||||
|
|
||||||
updateControllers();
|
|
||||||
|
|
||||||
Messages.subscribe('Controller-Display');
|
Messages.subscribe('Controller-Display');
|
||||||
var handleMessages = function(channel, message, sender) {
|
var handleMessages = function(channel, message, sender) {
|
||||||
if (!activeController) {
|
if (!controllerLeft && !controllerRight) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender === MyAvatar.sessionUUID) {
|
if (sender === MyAvatar.sessionUUID) {
|
||||||
if (channel === 'Controller-Display') {
|
if (channel === 'Controller-Display') {
|
||||||
debug('here');
|
|
||||||
var data = JSON.parse(message);
|
var data = JSON.parse(message);
|
||||||
var name = data.name;
|
var name = data.name;
|
||||||
var visible = data.visible;
|
var visible = data.visible;
|
||||||
//c.setDisplayAnnotation(name, visible);
|
//c.setDisplayAnnotation(name, visible);
|
||||||
if (name in activeController.annotations) {
|
if (controllerLeft) {
|
||||||
debug("hiding");
|
if (name in controllerLeft.annotations) {
|
||||||
for (var i = 0; i < activeController.annotations[name].length; ++i) {
|
debug("hiding");
|
||||||
debug("hiding", i);
|
for (var i = 0; i < controllerLeft.annotations[name].length; ++i) {
|
||||||
Overlays.editOverlay(activeController.annotations[name][i], { visible: visible });
|
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') {
|
} else if (channel === 'Controller-Display-Parts') {
|
||||||
|
@ -86,39 +136,98 @@ ControllerDisplayManager = function() {
|
||||||
var data = JSON.parse(message);
|
var data = JSON.parse(message);
|
||||||
for (var name in data) {
|
for (var name in data) {
|
||||||
var visible = data[name];
|
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') {
|
} else if (channel === 'Controller-Set-Part-Layer') {
|
||||||
var data = JSON.parse(message);
|
var data = JSON.parse(message);
|
||||||
for (var name in data) {
|
for (var name in data) {
|
||||||
var layer = data[name];
|
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);
|
Messages.messageReceived.connect(handleMessages);
|
||||||
|
|
||||||
this.destroy = function() {
|
this.deleteControllerDisplays = function() {
|
||||||
print("Destroying controller display");
|
if (controllerLeft) {
|
||||||
Messages.messageReceived.disconnect(handleMessages);
|
deleteControllerDisplay(controllerLeft);
|
||||||
if (activeController) {
|
controllerLeft = null;
|
||||||
deleteControllerDisplay(activeController);
|
}
|
||||||
|
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);
|
var controllerDisplayManager = new ControllerDisplayManager();
|
||||||
//c.setPartVisible("touchpad", false);
|
|
||||||
//c.setPartVisible("touchpad_teleport", false);
|
Messages.subscribe('Hifi-Object-Manipulation');
|
||||||
//layers = ["blank", "teleport", 'arrows'];
|
function onMessageReceived(channel, message, sender) {
|
||||||
//num = 0;
|
print(channel, message, sender);
|
||||||
//Script.setInterval(function() {
|
if (channel == 'Hifi-Object-Manipulation') {// && sender == MyAvatar.sessionUUID) {
|
||||||
// print('num', num);
|
print("got manip");
|
||||||
// num = (num + 1) % layers.length;
|
var data = JSON.parse(message);
|
||||||
// c.setLayerForPart("touchpad", layers[num]);
|
print("post data", data);
|
||||||
//}, 2000);
|
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;
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
Loading…
Reference in a new issue