mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-28 19:10:20 +02:00
away.js now shows hand controllers in away mode.
* controllerDisplayManager is now part of default scripts. * Also tutorial and away.js communicate with controllerDisplayManager via HMD.requestShowHandControllers, HMD.requestHideHandControllers and sendLocalMessage. * removed previous version of controllerDisplayManger from tutorial.
This commit is contained in:
parent
5d7f79ab00
commit
60f728585a
9 changed files with 45 additions and 682 deletions
|
@ -57,6 +57,20 @@ bool HMDScriptingInterface::isHandControllerAvailable() {
|
||||||
return PluginUtils::isHandControllerAvailable();
|
return PluginUtils::isHandControllerAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HMDScriptingInterface::requestShowHandControllers() {
|
||||||
|
_showHandControllersCount++;
|
||||||
|
emit shouldShowHandControllersChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HMDScriptingInterface::requestHideHandControllers() {
|
||||||
|
_showHandControllersCount--;
|
||||||
|
emit shouldShowHandControllersChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HMDScriptingInterface::shouldShowHandControllers() const {
|
||||||
|
return _showHandControllersCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) {
|
QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) {
|
||||||
glm::vec3 hudIntersection;
|
glm::vec3 hudIntersection;
|
||||||
auto instance = DependencyManager::get<HMDScriptingInterface>();
|
auto instance = DependencyManager::get<HMDScriptingInterface>();
|
||||||
|
|
|
@ -41,6 +41,10 @@ public:
|
||||||
Q_INVOKABLE bool isHMDAvailable();
|
Q_INVOKABLE bool isHMDAvailable();
|
||||||
Q_INVOKABLE bool isHandControllerAvailable();
|
Q_INVOKABLE bool isHandControllerAvailable();
|
||||||
|
|
||||||
|
Q_INVOKABLE void requestShowHandControllers();
|
||||||
|
Q_INVOKABLE void requestHideHandControllers();
|
||||||
|
Q_INVOKABLE bool shouldShowHandControllers() const;
|
||||||
|
|
||||||
Q_INVOKABLE bool setHandLasers(int hands, bool enabled, const glm::vec4& color, const glm::vec3& direction) const;
|
Q_INVOKABLE bool setHandLasers(int hands, bool enabled, const glm::vec4& color, const glm::vec3& direction) const;
|
||||||
|
|
||||||
Q_INVOKABLE void disableHandLasers(int hands) const;
|
Q_INVOKABLE void disableHandLasers(int hands) const;
|
||||||
|
@ -61,6 +65,9 @@ public:
|
||||||
// rotate the overlay UI sphere so that it is centered about the the current HMD position and orientation
|
// rotate the overlay UI sphere so that it is centered about the the current HMD position and orientation
|
||||||
Q_INVOKABLE void centerUI();
|
Q_INVOKABLE void centerUI();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
bool shouldShowHandControllersChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HMDScriptingInterface();
|
HMDScriptingInterface();
|
||||||
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
||||||
|
@ -77,6 +84,7 @@ private:
|
||||||
|
|
||||||
bool getHUDLookAtPosition3D(glm::vec3& result) const;
|
bool getHUDLookAtPosition3D(glm::vec3& result) const;
|
||||||
glm::mat4 getWorldHMDMatrix() const;
|
glm::mat4 getWorldHMDMatrix() const;
|
||||||
|
std::atomic<int> _showHandControllersCount { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_HMDScriptingInterface_h
|
#endif // hifi_HMDScriptingInterface_h
|
||||||
|
|
|
@ -23,6 +23,7 @@ var DEFAULT_SCRIPTS = [
|
||||||
"system/mod.js",
|
"system/mod.js",
|
||||||
"system/selectAudioDevice.js",
|
"system/selectAudioDevice.js",
|
||||||
"system/notifications.js",
|
"system/notifications.js",
|
||||||
|
"system/controllers/controllerDisplayManager.js",
|
||||||
"system/controllers/handControllerGrab.js",
|
"system/controllers/handControllerGrab.js",
|
||||||
"system/controllers/handControllerPointer.js",
|
"system/controllers/handControllerPointer.js",
|
||||||
"system/controllers/squeezeHands.js",
|
"system/controllers/squeezeHands.js",
|
||||||
|
@ -125,4 +126,4 @@ Script.scriptEnding.connect(function() {
|
||||||
removeMenuItem();
|
removeMenuItem();
|
||||||
});
|
});
|
||||||
|
|
||||||
Menu.menuItemEvent.connect(menuItemEvent);
|
Menu.menuItemEvent.connect(menuItemEvent);
|
||||||
|
|
|
@ -178,6 +178,8 @@ function goAway(fromStartup) {
|
||||||
playAwayAnimation(); // animation is still seen by others
|
playAwayAnimation(); // animation is still seen by others
|
||||||
showOverlay();
|
showOverlay();
|
||||||
|
|
||||||
|
HMD.requestShowHandControllers();
|
||||||
|
|
||||||
// remember the View > Overlays state...
|
// remember the View > Overlays state...
|
||||||
wasOverlaysVisible = Menu.isOptionChecked("Overlays");
|
wasOverlaysVisible = Menu.isOptionChecked("Overlays");
|
||||||
|
|
||||||
|
@ -222,6 +224,8 @@ function goActive() {
|
||||||
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
|
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
|
||||||
stopAwayAnimation();
|
stopAwayAnimation();
|
||||||
|
|
||||||
|
HMD.requestHideHandControllers();
|
||||||
|
|
||||||
// update the UI sphere to be centered about the current HMD orientation.
|
// update the UI sphere to be centered about the current HMD orientation.
|
||||||
HMD.centerUI();
|
HMD.centerUI();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
/* globals ControllerDisplayManager:true createControllerDisplay deleteControllerDisplay
|
/* globals ControllerDisplayManager:true createControllerDisplay deleteControllerDisplay
|
||||||
VIVE_CONTROLLER_CONFIGURATION_LEFT VIVE_CONTROLLER_CONFIGURATION_RIGHT */
|
VIVE_CONTROLLER_CONFIGURATION_LEFT VIVE_CONTROLLER_CONFIGURATION_RIGHT */
|
||||||
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
|
||||||
Script.include("controllerDisplay.js");
|
Script.include("controllerDisplay.js");
|
||||||
Script.include("viveControllerConfiguration.js");
|
Script.include("viveControllerConfiguration.js");
|
||||||
|
@ -35,7 +38,7 @@ ControllerDisplayManager = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateControllers() {
|
function updateControllers() {
|
||||||
if (HMD.active) {
|
if (HMD.active && HMD.shouldShowHandControllers()) {
|
||||||
if ("Vive" in Controller.Hardware) {
|
if ("Vive" in Controller.Hardware) {
|
||||||
if (!controllerLeft) {
|
if (!controllerLeft) {
|
||||||
controllerLeft = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_LEFT);
|
controllerLeft = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_LEFT);
|
||||||
|
@ -139,12 +142,23 @@ ControllerDisplayManager = function() {
|
||||||
|
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
Messages.messageReceived.disconnect(handleMessages);
|
Messages.messageReceived.disconnect(handleMessages);
|
||||||
|
|
||||||
|
HMD.displayModeChanged.disconnect(updateControllers);
|
||||||
|
HMD.shouldShowHandControllersChanged.disconnect(updateControllers);
|
||||||
|
|
||||||
self.deleteControllerDisplays();
|
self.deleteControllerDisplays();
|
||||||
};
|
};
|
||||||
|
|
||||||
HMD.displayModeChanged.connect(updateControllers);
|
HMD.displayModeChanged.connect(updateControllers);
|
||||||
|
HMD.shouldShowHandControllersChanged.connect(updateControllers);
|
||||||
|
|
||||||
updateControllers();
|
updateControllers();
|
||||||
};
|
};
|
||||||
|
|
||||||
var controllerDisplayManager = new ControllerDisplayManager();
|
var controllerDisplayManager = new ControllerDisplayManager();
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function () {
|
||||||
|
controllerDisplayManager.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
|
@ -1,195 +0,0 @@
|
||||||
var VISIBLE_BY_DEFAULT = false;
|
|
||||||
var PARENT_ID = "{00000000-0000-0000-0000-000000000001}";
|
|
||||||
|
|
||||||
var DEBUG = false;
|
|
||||||
function debug() {
|
|
||||||
if (DEBUG) {
|
|
||||||
print.apply(self, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createControllerDisplay = function(config) {
|
|
||||||
var controllerDisplay = {
|
|
||||||
overlays: [],
|
|
||||||
partOverlays: {
|
|
||||||
},
|
|
||||||
parts: {
|
|
||||||
},
|
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
setLayerForPart: function(partName, layerName) {
|
|
||||||
if (partName in this.parts) {
|
|
||||||
debug("Setting layer...", partName, layerName);
|
|
||||||
var part = this.parts[partName];
|
|
||||||
if (part.textureLayers && layerName in part.textureLayers) {
|
|
||||||
var layer = part.textureLayers[layerName];
|
|
||||||
var textures = {};
|
|
||||||
if (layer.defaultTextureURL) {
|
|
||||||
textures[part.textureName] = layer.defaultTextureURL;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < this.partOverlays[partName].length; ++i) {
|
|
||||||
Overlays.editOverlay(this.partOverlays[partName][i], {
|
|
||||||
textures: textures
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var mapping = Controller.newMapping(controllerDisplay.mappingName);
|
|
||||||
for (var i = 0; i < config.controllers.length; ++i) {
|
|
||||||
var controller = config.controllers[i];
|
|
||||||
var position = controller.position;
|
|
||||||
|
|
||||||
if (controller.naturalPosition) {
|
|
||||||
position = Vec3.sum(Vec3.multiplyQbyV(
|
|
||||||
controller.rotation, controller.naturalPosition), position);
|
|
||||||
}
|
|
||||||
|
|
||||||
var overlayID = Overlays.addOverlay("model", {
|
|
||||||
url: controller.modelURL,
|
|
||||||
dimensions: controller.dimensions,
|
|
||||||
localRotation: controller.rotation,
|
|
||||||
localPosition: position,
|
|
||||||
parentID: PARENT_ID,
|
|
||||||
parentJointIndex: controller.jointIndex,
|
|
||||||
ignoreRayIntersection: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
controllerDisplay.overlays.push(overlayID);
|
|
||||||
overlayID = null;
|
|
||||||
|
|
||||||
function clamp(value, min, max) {
|
|
||||||
if (value < min) {
|
|
||||||
return min;
|
|
||||||
} else if (value > max) {
|
|
||||||
return max
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (controller.parts) {
|
|
||||||
for (var partName in controller.parts) {
|
|
||||||
var part = controller.parts[partName];
|
|
||||||
var partPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, part.naturalPosition));
|
|
||||||
var innerRotation = controller.rotation
|
|
||||||
|
|
||||||
controllerDisplay.parts[partName] = controller.parts[partName];
|
|
||||||
|
|
||||||
var properties = {
|
|
||||||
url: part.modelURL,
|
|
||||||
localPosition: partPosition,
|
|
||||||
localRotation: innerRotation,
|
|
||||||
parentID: PARENT_ID,
|
|
||||||
parentJointIndex: controller.jointIndex,
|
|
||||||
ignoreRayIntersection: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (part.defaultTextureLayer) {
|
|
||||||
var textures = {};
|
|
||||||
textures[part.textureName] = part.textureLayers[part.defaultTextureLayer].defaultTextureURL;
|
|
||||||
properties['textures'] = textures;
|
|
||||||
}
|
|
||||||
|
|
||||||
var overlayID = Overlays.addOverlay("model", properties);
|
|
||||||
|
|
||||||
if (part.type == "rotational") {
|
|
||||||
var range = part.maxValue - part.minValue;
|
|
||||||
mapping.from([part.input]).peek().to(function(controller, overlayID, part) {
|
|
||||||
return function(value) {
|
|
||||||
value = clamp(value, part.minValue, part.maxValue);
|
|
||||||
|
|
||||||
var pct = (value - part.minValue) / part.maxValue;
|
|
||||||
var angle = pct * part.maxAngle;
|
|
||||||
var rotation = Quat.angleAxis(angle, part.axis);
|
|
||||||
|
|
||||||
var offset = { x: 0, y: 0, z: 0 };
|
|
||||||
if (part.origin) {
|
|
||||||
var offset = Vec3.multiplyQbyV(rotation, part.origin);
|
|
||||||
offset = Vec3.subtract(offset, part.origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
var partPosition = Vec3.sum(controller.position,
|
|
||||||
Vec3.multiplyQbyV(controller.rotation, Vec3.sum(offset, part.naturalPosition)));
|
|
||||||
|
|
||||||
Overlays.editOverlay(overlayID, {
|
|
||||||
localPosition: partPosition,
|
|
||||||
localRotation: Quat.multiply(controller.rotation, rotation)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}(controller, overlayID, part));
|
|
||||||
} else if (part.type == "touchpad") {
|
|
||||||
function resolveHardware(path) {
|
|
||||||
var parts = path.split(".");
|
|
||||||
function resolveInner(base, path, i) {
|
|
||||||
if (i >= path.length) {
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
return resolveInner(base[path[i]], path, ++i);
|
|
||||||
}
|
|
||||||
return resolveInner(Controller.Hardware, parts, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
var visibleInput = resolveHardware(part.visibleInput);
|
|
||||||
var xinput = resolveHardware(part.xInput);
|
|
||||||
var yinput = resolveHardware(part.yInput);
|
|
||||||
|
|
||||||
// TODO: Touchpad inputs are currently only working for half
|
|
||||||
// of the touchpad. When that is fixed, it would be useful
|
|
||||||
// to update these to display the current finger position.
|
|
||||||
mapping.from([visibleInput]).peek().to(function(value) {
|
|
||||||
});
|
|
||||||
mapping.from([xinput]).peek().to(function(value) {
|
|
||||||
});
|
|
||||||
mapping.from([yinput]).peek().invert().to(function(value) {
|
|
||||||
});
|
|
||||||
} else if (part.type == "static") {
|
|
||||||
} else {
|
|
||||||
print("TYPE NOT SUPPORTED: ", part.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
controllerDisplay.overlays.push(overlayID);
|
|
||||||
if (!(partName in controllerDisplay.partOverlays)) {
|
|
||||||
controllerDisplay.partOverlays[partName] = [];
|
|
||||||
}
|
|
||||||
controllerDisplay.partOverlays[partName].push(overlayID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Controller.enableMapping(controllerDisplay.mappingName);
|
|
||||||
return controllerDisplay;
|
|
||||||
}
|
|
||||||
|
|
||||||
ControllerDisplay = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
deleteControllerDisplay = function(controllerDisplay) {
|
|
||||||
print("Deleting controller display");
|
|
||||||
for (var i = 0; i < controllerDisplay.overlays.length; ++i) {
|
|
||||||
Overlays.deleteOverlay(controllerDisplay.overlays[i]);
|
|
||||||
}
|
|
||||||
Controller.disableMapping(controllerDisplay.mappingName);
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
Script.include("entityData.js");
|
Script.include("entityData.js");
|
||||||
Script.include("viveHandsv2.js");
|
|
||||||
Script.include("lighter/createButaneLighter.js");
|
Script.include("lighter/createButaneLighter.js");
|
||||||
Script.include("tutorialEntityIDs.js");
|
Script.include("tutorialEntityIDs.js");
|
||||||
|
|
||||||
|
@ -235,7 +234,7 @@ var stepDisableControllers = function(name) {
|
||||||
}
|
}
|
||||||
stepDisableControllers.prototype = {
|
stepDisableControllers.prototype = {
|
||||||
start: function(onFinish) {
|
start: function(onFinish) {
|
||||||
controllerDisplayManager = new ControllerDisplayManager();
|
HMD.requestShowHandControllers();
|
||||||
disableEverything();
|
disableEverything();
|
||||||
|
|
||||||
onFinish();
|
onFinish();
|
||||||
|
@ -276,10 +275,7 @@ function reenableEverything() {
|
||||||
setControllerPartLayer('touchpad', 'blank');
|
setControllerPartLayer('touchpad', 'blank');
|
||||||
setControllerPartLayer('tips', 'blank');
|
setControllerPartLayer('tips', 'blank');
|
||||||
MyAvatar.shouldRenderLocally = true;
|
MyAvatar.shouldRenderLocally = true;
|
||||||
if (controllerDisplayManager) {
|
HMD.requestHideHandControllers();
|
||||||
controllerDisplayManager.destroy();
|
|
||||||
controllerDisplayManager = null;
|
|
||||||
}
|
|
||||||
setAwayEnabled(true);
|
setAwayEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,285 +0,0 @@
|
||||||
var LEFT_JOINT_INDEX = MyAvatar.getJointIndex("_CONTROLLER_LEFTHAND");
|
|
||||||
var RIGHT_JOINT_INDEX = MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND");
|
|
||||||
|
|
||||||
var leftBaseRotation = Quat.multiply(
|
|
||||||
Quat.fromPitchYawRollDegrees(0, 0, 45),
|
|
||||||
Quat.multiply(
|
|
||||||
Quat.fromPitchYawRollDegrees(90, 0, 0),
|
|
||||||
Quat.fromPitchYawRollDegrees(0, 0, 90)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
var rightBaseRotation = Quat.multiply(
|
|
||||||
Quat.fromPitchYawRollDegrees(0, 0, -45),
|
|
||||||
Quat.multiply(
|
|
||||||
Quat.fromPitchYawRollDegrees(90, 0, 0),
|
|
||||||
Quat.fromPitchYawRollDegrees(0, 0, -90)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// keep these in sync with the values from plugins/openvr/src/OpenVrHelpers.cpp:303
|
|
||||||
var CONTROLLER_LATERAL_OFFSET = 0.0381;
|
|
||||||
var CONTROLLER_VERTICAL_OFFSET = 0.0495;
|
|
||||||
var CONTROLLER_FORWARD_OFFSET = 0.1371;
|
|
||||||
var leftBasePosition = {
|
|
||||||
x: CONTROLLER_VERTICAL_OFFSET,
|
|
||||||
y: CONTROLLER_FORWARD_OFFSET,
|
|
||||||
z: CONTROLLER_LATERAL_OFFSET
|
|
||||||
};
|
|
||||||
var rightBasePosition = {
|
|
||||||
x: -CONTROLLER_VERTICAL_OFFSET,
|
|
||||||
y: CONTROLLER_FORWARD_OFFSET,
|
|
||||||
z: CONTROLLER_LATERAL_OFFSET
|
|
||||||
};
|
|
||||||
|
|
||||||
var viveNaturalDimensions = {
|
|
||||||
x: 0.1174320001155138,
|
|
||||||
y: 0.08361100335605443,
|
|
||||||
z: 0.21942697931081057
|
|
||||||
};
|
|
||||||
|
|
||||||
var viveNaturalPosition = {
|
|
||||||
x: 0,
|
|
||||||
y: -0.034076502197422087,
|
|
||||||
z: 0.06380049744620919
|
|
||||||
};
|
|
||||||
|
|
||||||
var viveModelURL = "atp:/controller/vive_body.fbx";
|
|
||||||
var viveTipsModelURL = "atp:/controller/vive_tips.fbx"
|
|
||||||
|
|
||||||
VIVE_CONTROLLER_CONFIGURATION_LEFT = {
|
|
||||||
name: "Vive",
|
|
||||||
controllers: [
|
|
||||||
{
|
|
||||||
modelURL: viveModelURL,
|
|
||||||
jointIndex: MyAvatar.getJointIndex("_CONTROLLER_LEFTHAND"),
|
|
||||||
naturalPosition: viveNaturalPosition,
|
|
||||||
rotation: leftBaseRotation,
|
|
||||||
position: Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 0, 45), leftBasePosition),
|
|
||||||
|
|
||||||
dimensions: viveNaturalDimensions,
|
|
||||||
|
|
||||||
parts: {
|
|
||||||
tips: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: viveTipsModelURL,
|
|
||||||
naturalPosition: {"x":-0.004377640783786774,"y":-0.034371938556432724,"z":0.06769277155399323},
|
|
||||||
|
|
||||||
textureName: "Tex.Blank",
|
|
||||||
|
|
||||||
defaultTextureLayer: "blank",
|
|
||||||
textureLayers: {
|
|
||||||
blank: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Blank.png",
|
|
||||||
},
|
|
||||||
trigger: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Trigger.png",
|
|
||||||
},
|
|
||||||
arrows: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Rotate.png",
|
|
||||||
},
|
|
||||||
grip: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Grip.png",
|
|
||||||
},
|
|
||||||
teleport: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Teleport.png",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// The touchpad type draws a dot indicating the current touch/thumb position
|
|
||||||
// and swaps in textures based on the thumb position.
|
|
||||||
touchpad: {
|
|
||||||
type: "touchpad",
|
|
||||||
modelURL: "atp:/controller/vive_trackpad.fbx",
|
|
||||||
visibleInput: "Vive.RSTouch",
|
|
||||||
xInput: "Vive.LX",
|
|
||||||
yInput: "Vive.LY",
|
|
||||||
naturalPosition: {"x":0,"y":0.000979491975158453,"z":0.04872849956154823},
|
|
||||||
minValue: 0.0,
|
|
||||||
maxValue: 1.0,
|
|
||||||
minPosition: { x: -0.035, y: 0.004, z: -0.005 },
|
|
||||||
maxPosition: { x: -0.035, y: 0.004, z: -0.005 },
|
|
||||||
disable_textureName: "Tex.touchpad-blank",
|
|
||||||
|
|
||||||
disable_defaultTextureLayer: "blank",
|
|
||||||
disable_textureLayers: {
|
|
||||||
blank: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-blank.jpg",
|
|
||||||
},
|
|
||||||
teleport: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-teleport-active-LG.jpg",
|
|
||||||
},
|
|
||||||
arrows: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-look-arrows.jpg",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
trigger: {
|
|
||||||
type: "rotational",
|
|
||||||
modelURL: "atp:/controller/vive_trigger.fbx",
|
|
||||||
input: Controller.Standard.LT,
|
|
||||||
naturalPosition: {"x":0.000004500150680541992,"y":-0.027690507471561432,"z":0.04830199480056763},
|
|
||||||
origin: { x: 0, y: -0.015, z: -0.00 },
|
|
||||||
minValue: 0.0,
|
|
||||||
maxValue: 1.0,
|
|
||||||
axis: { x: -1, y: 0, z: 0 },
|
|
||||||
maxAngle: 20,
|
|
||||||
},
|
|
||||||
|
|
||||||
l_grip: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_l_grip.fbx",
|
|
||||||
naturalPosition: {"x":-0.01720449887216091,"y":-0.014324013143777847,"z":0.08714400231838226},
|
|
||||||
},
|
|
||||||
|
|
||||||
r_grip: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_r_grip.fbx",
|
|
||||||
naturalPosition: {"x":0.01720449887216091,"y":-0.014324013143777847,"z":0.08714400231838226},
|
|
||||||
},
|
|
||||||
|
|
||||||
sys_button: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_sys_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.0020399854984134436,"z":0.08825899660587311},
|
|
||||||
},
|
|
||||||
|
|
||||||
button: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.005480996798723936,"z":0.019918499514460564}
|
|
||||||
},
|
|
||||||
button2: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.005480996798723936,"z":0.019918499514460564}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VIVE_CONTROLLER_CONFIGURATION_RIGHT = {
|
|
||||||
name: "Vive Right",
|
|
||||||
controllers: [
|
|
||||||
{
|
|
||||||
modelURL: viveModelURL,
|
|
||||||
jointIndex: MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND"),
|
|
||||||
|
|
||||||
rotation: rightBaseRotation,
|
|
||||||
position: Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 0, -45), rightBasePosition),
|
|
||||||
|
|
||||||
dimensions: viveNaturalDimensions,
|
|
||||||
|
|
||||||
naturalPosition: {
|
|
||||||
x: 0,
|
|
||||||
y: -0.034076502197422087,
|
|
||||||
z: 0.06380049744620919
|
|
||||||
},
|
|
||||||
|
|
||||||
parts: {
|
|
||||||
tips: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: viveTipsModelURL,
|
|
||||||
naturalPosition: {"x":-0.004377640783786774,"y":-0.034371938556432724,"z":0.06769277155399323},
|
|
||||||
|
|
||||||
textureName: "Tex.Blank",
|
|
||||||
|
|
||||||
defaultTextureLayer: "blank",
|
|
||||||
textureLayers: {
|
|
||||||
blank: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Blank.png",
|
|
||||||
},
|
|
||||||
trigger: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Trigger.png",
|
|
||||||
},
|
|
||||||
arrows: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Rotate.png",
|
|
||||||
},
|
|
||||||
grip: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Grip.png",
|
|
||||||
},
|
|
||||||
teleport: {
|
|
||||||
defaultTextureURL: viveTipsModelURL + "/Controller-Tips.fbm/Teleport.png",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// The touchpad type draws a dot indicating the current touch/thumb position
|
|
||||||
// and swaps in textures based on the thumb position.
|
|
||||||
touchpad: {
|
|
||||||
type: "touchpad",
|
|
||||||
modelURL: "atp:/controller/vive_trackpad.fbx",
|
|
||||||
visibleInput: "Vive.RSTouch",
|
|
||||||
xInput: "Vive.RX",
|
|
||||||
yInput: "Vive.RY",
|
|
||||||
naturalPosition: { x: 0, y: 0.000979491975158453, z: 0.04872849956154823 },
|
|
||||||
minValue: 0.0,
|
|
||||||
maxValue: 1.0,
|
|
||||||
minPosition: { x: -0.035, y: 0.004, z: -0.005 },
|
|
||||||
maxPosition: { x: -0.035, y: 0.004, z: -0.005 },
|
|
||||||
disable_textureName: "Tex.touchpad-blank",
|
|
||||||
|
|
||||||
disable_defaultTextureLayer: "blank",
|
|
||||||
disable_textureLayers: {
|
|
||||||
blank: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-blank.jpg",
|
|
||||||
},
|
|
||||||
teleport: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-teleport-active-LG.jpg",
|
|
||||||
},
|
|
||||||
arrows: {
|
|
||||||
defaultTextureURL: "atp:/controller/vive_trackpad.fbx/Touchpad.fbm/touchpad-look-arrows-active.jpg",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
trigger: {
|
|
||||||
type: "rotational",
|
|
||||||
modelURL: "atp:/controller/vive_trigger.fbx",
|
|
||||||
input: Controller.Standard.RT,
|
|
||||||
naturalPosition: {"x":0.000004500150680541992,"y":-0.027690507471561432,"z":0.04830199480056763},
|
|
||||||
origin: { x: 0, y: -0.015, z: -0.00 },
|
|
||||||
minValue: 0.0,
|
|
||||||
maxValue: 1.0,
|
|
||||||
axis: { x: -1, y: 0, z: 0 },
|
|
||||||
maxAngle: 25,
|
|
||||||
},
|
|
||||||
|
|
||||||
l_grip: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_l_grip.fbx",
|
|
||||||
naturalPosition: {"x":-0.01720449887216091,"y":-0.014324013143777847,"z":0.08714400231838226},
|
|
||||||
},
|
|
||||||
|
|
||||||
r_grip: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_r_grip.fbx",
|
|
||||||
naturalPosition: {"x":0.01720449887216091,"y":-0.014324013143777847,"z":0.08714400231838226},
|
|
||||||
},
|
|
||||||
|
|
||||||
sys_button: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_sys_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.0020399854984134436,"z":0.08825899660587311},
|
|
||||||
},
|
|
||||||
|
|
||||||
button: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.005480996798723936,"z":0.019918499514460564}
|
|
||||||
},
|
|
||||||
button2: {
|
|
||||||
type: "static",
|
|
||||||
modelURL: "atp:/controller/vive_button.fbx",
|
|
||||||
naturalPosition: {"x":0,"y":0.005480996798723936,"z":0.019918499514460564}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,194 +0,0 @@
|
||||||
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");
|
|
||||||
|
|
||||||
function debug() {
|
|
||||||
var args = Array.prototype.slice.call(arguments);
|
|
||||||
args.unshift("CONTROLLER DEBUG:");
|
|
||||||
print.apply(this, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
var zeroPosition = { x: 0, y: 0, z: 0 };
|
|
||||||
var zeroRotation = { x: 0, y: 0, z: 0, w: 1 };
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Management of controller display //
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
ControllerDisplayManager = function() {
|
|
||||||
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 (!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) {
|
|
||||||
Script.clearInterval(controllerCheckerIntervalID);
|
|
||||||
controllerCheckerIntervalID = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug("HMD active, but no controllers found");
|
|
||||||
self.deleteControllerDisplays();
|
|
||||||
if (controllerCheckerIntervalID == null) {
|
|
||||||
controllerCheckerIntervalID = Script.setInterval(updateControllers, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug("HMD inactive");
|
|
||||||
// We aren't in HMD mode, we no longer need to look for active controllers
|
|
||||||
if (controllerCheckerIntervalID) {
|
|
||||||
debug("Clearing controller checker interval");
|
|
||||||
Script.clearInterval(controllerCheckerIntervalID);
|
|
||||||
controllerCheckerIntervalID = null;
|
|
||||||
}
|
|
||||||
self.deleteControllerDisplays();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Messages.subscribe('Controller-Display');
|
|
||||||
var handleMessages = function(channel, message, sender) {
|
|
||||||
if (!controllerLeft && !controllerRight) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender === MyAvatar.sessionUUID) {
|
|
||||||
if (channel === 'Controller-Display') {
|
|
||||||
var data = JSON.parse(message);
|
|
||||||
var name = data.name;
|
|
||||||
var visible = data.visible;
|
|
||||||
//c.setDisplayAnnotation(name, 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') {
|
|
||||||
debug('here part');
|
|
||||||
var data = JSON.parse(message);
|
|
||||||
for (var name in data) {
|
|
||||||
var visible = data[name];
|
|
||||||
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];
|
|
||||||
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.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();
|
|
||||||
}
|
|
Loading…
Reference in a new issue