diff --git a/interface/resources/meshes/controller/touch/Oculus-Labels-L.fbx b/interface/resources/meshes/controller/touch/Oculus-Labels-L.fbx new file mode 100644 index 0000000000..e27d90ad5d Binary files /dev/null and b/interface/resources/meshes/controller/touch/Oculus-Labels-L.fbx differ diff --git a/interface/resources/meshes/controller/touch/Oculus-Labels-R.fbx b/interface/resources/meshes/controller/touch/Oculus-Labels-R.fbx new file mode 100644 index 0000000000..cbcd18e7e5 Binary files /dev/null and b/interface/resources/meshes/controller/touch/Oculus-Labels-R.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l.fbx b/interface/resources/meshes/controller/touch/touch_l.fbx new file mode 100644 index 0000000000..da1064ab26 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_body.fbx b/interface/resources/meshes/controller/touch/touch_l_body.fbx new file mode 100644 index 0000000000..3c927fd086 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_body.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_bumper.fbx b/interface/resources/meshes/controller/touch/touch_l_bumper.fbx new file mode 100644 index 0000000000..c0ad77fd45 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_bumper.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_button_x.fbx b/interface/resources/meshes/controller/touch/touch_l_button_x.fbx new file mode 100644 index 0000000000..6107eeb3ac Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_button_x.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_button_y.fbx b/interface/resources/meshes/controller/touch/touch_l_button_y.fbx new file mode 100644 index 0000000000..5f8bd53627 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_button_y.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_joystick.fbx b/interface/resources/meshes/controller/touch/touch_l_joystick.fbx new file mode 100644 index 0000000000..f9b5ee89ba Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_joystick.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_l_trigger.fbx b/interface/resources/meshes/controller/touch/touch_l_trigger.fbx new file mode 100644 index 0000000000..7638d73593 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_l_trigger.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r.fbx b/interface/resources/meshes/controller/touch/touch_r.fbx new file mode 100644 index 0000000000..4c8c880e19 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_body.fbx b/interface/resources/meshes/controller/touch/touch_r_body.fbx new file mode 100644 index 0000000000..1d9ce36bb8 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_body.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_bumper.fbx b/interface/resources/meshes/controller/touch/touch_r_bumper.fbx new file mode 100644 index 0000000000..cd9c28c37f Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_bumper.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_button_a.fbx b/interface/resources/meshes/controller/touch/touch_r_button_a.fbx new file mode 100644 index 0000000000..e614a166a1 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_button_a.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_button_b.fbx b/interface/resources/meshes/controller/touch/touch_r_button_b.fbx new file mode 100644 index 0000000000..a56e0ff36c Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_button_b.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_joystick.fbx b/interface/resources/meshes/controller/touch/touch_r_joystick.fbx new file mode 100644 index 0000000000..7749dbf498 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_joystick.fbx differ diff --git a/interface/resources/meshes/controller/touch/touch_r_trigger.fbx b/interface/resources/meshes/controller/touch/touch_r_trigger.fbx new file mode 100644 index 0000000000..2c89a11c68 Binary files /dev/null and b/interface/resources/meshes/controller/touch/touch_r_trigger.fbx differ diff --git a/scripts/system/controllers/controllerDisplay.js b/scripts/system/controllers/controllerDisplay.js index 48fea400af..ab555b441e 100644 --- a/scripts/system/controllers/controllerDisplay.js +++ b/scripts/system/controllers/controllerDisplay.js @@ -169,6 +169,73 @@ createControllerDisplay = function(config) { }); mapping.from([yinput]).peek().invert().to(function(value) { }); + } else if (part.type === "joystick") { + (function(controller, overlayID, part) { + const xinput = resolveHardware(part.xInput); + const yinput = resolveHardware(part.yInput); + + var xvalue = 0; + var yvalue = 0; + + function calculatePositionAndRotation(xValue, yValue) { + var rotation = Quat.fromPitchYawRollDegrees(yValue * part.xHalfAngle, 0, xValue * part.yHalfAngle); + + var offset = { x: 0, y: 0, z: 0 }; + if (part.originOffset) { + offset = Vec3.multiplyQbyV(rotation, part.originOffset); + offset = Vec3.subtract(part.originOffset, offset); + } + + var partPosition = Vec3.sum(controller.position, + Vec3.multiplyQbyV(controller.rotation, Vec3.sum(offset, part.naturalPosition))); + + var partRotation = Quat.multiply(controller.rotation, rotation) + + return { + position: partPosition, + rotation: partRotation + } + } + + mapping.from([xinput]).peek().to(function(value) { + xvalue = value; + //print(overlayID, xvalue.toFixed(3), yvalue.toFixed(3)); + var posRot = calculatePositionAndRotation(xvalue, yvalue); + Overlays.editOverlay(overlayID, { + localPosition: posRot.position, + localRotation: posRot.rotation + }); + }); + + mapping.from([yinput]).peek().to(function(value) { + yvalue = value; + var posRot = calculatePositionAndRotation(xvalue, yvalue); + Overlays.editOverlay(overlayID, { + localPosition: posRot.position, + localRotation: posRot.rotation + }); + }); + })(controller, overlayID, part); + + } else if (part.type === "linear") { + (function(controller, overlayID, part) { + const input = resolveHardware(part.input); + + mapping.from([input]).peek().to(function(value) { + //print(value); + var axis = Vec3.multiplyQbyV(controller.rotation, part.axis); + var offset = Vec3.multiply(part.maxTranslation * value, axis); + + var partPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, part.naturalPosition)); + var position = Vec3.sum(partPosition, offset); + + Overlays.editOverlay(overlayID, { + localPosition: position + }); + }); + + })(controller, overlayID, part); + } else if (part.type === "static") { // do nothing } else { diff --git a/scripts/system/controllers/controllerDisplayManager.js b/scripts/system/controllers/controllerDisplayManager.js index 550357d659..266729bd3b 100644 --- a/scripts/system/controllers/controllerDisplayManager.js +++ b/scripts/system/controllers/controllerDisplayManager.js @@ -13,8 +13,9 @@ (function () { -Script.include("controllerDisplay.js"); +Script.include("controllerDisplay.js?" + Date.now()); Script.include("viveControllerConfiguration.js"); +Script.include("touchControllerConfiguration.js?" + Date.now()); var HIDE_CONTROLLERS_ON_EQUIP = false; @@ -40,13 +41,29 @@ ControllerDisplayManager = function() { }; function updateControllers() { - if (HMD.active && HMD.shouldShowHandControllers()) { + if (HMD.active && true) { //HMD.shouldShowHandControllers()) { + var leftConfig = null; + var rightConfig = null; + if ("Vive" in Controller.Hardware) { - if (!controllerLeft) { - controllerLeft = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_LEFT); + leftConfig = VIVE_CONTROLLER_CONFIGURATION_LEFT; + rightConfig = VIVE_CONTROLLER_CONFIGURATION_RIGHT; + } + + if ("OculusTouch" in Controller.Hardware) { + leftConfig = TOUCH_CONTROLLER_CONFIGURATION_LEFT; + rightConfig = TOUCH_CONTROLLER_CONFIGURATION_RIGHT; + } + + if (leftConfig !== null && rightConfig !== null) { + print("Loading controllers"); + if (controllerLeft === null) { + controllerLeft = createControllerDisplay(leftConfig); + controllerLeft.setVisible(true); } - if (!controllerRight) { - controllerRight = createControllerDisplay(VIVE_CONTROLLER_CONFIGURATION_RIGHT); + if (controllerRight === null) { + controllerRight = createControllerDisplay(rightConfig); + controllerRight.setVisible(true); } // We've found the controllers, we no longer need to look for active controllers if (controllerCheckerIntervalID) { diff --git a/scripts/system/controllers/touchControllerConfiguration.js b/scripts/system/controllers/touchControllerConfiguration.js new file mode 100644 index 0000000000..a81c667e06 --- /dev/null +++ b/scripts/system/controllers/touchControllerConfiguration.js @@ -0,0 +1,369 @@ + +// +// viveControllerConfiguration.js +// +// Created by Ryan Huffman on 12/06/16 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +/* globals TOUCH_CONTROLLER_CONFIGURATION_LEFT:true TOUCH_CONTROLLER_CONFIGURATION_RIGHT:true */ +/* eslint camelcase: ["error", { "properties": "never" }] */ + +var leftBaseRotation = Quat.multiply( + Quat.fromPitchYawRollDegrees(0, 0, 45), + Quat.multiply( + Quat.fromPitchYawRollDegrees(-90, 0, 0), + Quat.fromPitchYawRollDegrees(0, 0, 90) + ) +); +//var leftBaseRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + +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 +}; +rightBasePosition = { + x: CONTROLLER_FORWARD_OFFSET, + y: CONTROLLER_VERTICAL_OFFSET, + z: CONTROLLER_LATERAL_OFFSET +}; + +var BASE_URL = "file:///C:/Users/Ryan/dev/hifi/interface/resources/meshes/controller/touch/"; +//var BASE_URL = Script.resourcesPath() + "meshes/controller/touch/"; + +TOUCH_CONTROLLER_CONFIGURATION_LEFT = { + name: "Touch", + controllers: [ + { + modelURL: BASE_URL + "touch_l_body.fbx", + jointIndex: MyAvatar.getJointIndex("_CONTROLLER_LEFTHAND"), + naturalPosition: { x: 0.01648625358939171, y: -0.03551870584487915, z: -0.018527675420045853 }, + dimensions: { x: 0.11053799837827682, y: 0.0995776429772377, z: 0.10139888525009155 }, + rotation: leftBaseRotation, + position: Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 0, 45), leftBasePosition), + + parts: { + tips: { + type: "static", + modelURL: BASE_URL + "Oculus-Labels-L.fbx", + naturalPosition: { x: -0.022335469722747803, y: 0.00022516027092933655, z: 0.020340695977211 }, + + textureName: "blank", + defaultTextureLayer: "blank", + textureLayers: { + all: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Controller-All.png" + }, + blank: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Blank.png" + }, + trigger: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Trigger-oculus.png" + }, + arrows: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Rotate.png" + }, + grip: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Grip-oculus.png" + }, + teleport: { + defaultTextureURL: BASE_URL + "Oculus-Labels-L.fbx/Oculus-Labels-L.fbm/Teleport-oculus.png" + }, + } + }, + + trigger: { + type: "rotational", + modelURL: BASE_URL + "touch_l_trigger.fbx", + naturalPosition: { x: 0.0008544912561774254, y: -0.019867943599820137, z: 0.018800459802150726 }, + + // rotational + input: Controller.Standard.LT, + origin: { x: 0, y: -0.015, z: -0.00 }, + minValue: 0.0, + maxValue: 1.0, + axis: { x: 1, y: 0, z: 0 }, + maxAngle: 17, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_l_trigger.fbx/touch_l_trigger.fbm/L_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_l_trigger.fbx/touch_l_trigger.fbm/L_controller-highlight_DIF.jpg", + } + } + }, + + grip: { + type: "linear", + modelURL: BASE_URL + "touch_l_bumper.fbx", + naturalPosition: { x: 0.00008066371083259583, y: -0.02715788595378399, z: -0.02448512241244316 }, + + // linear properties + // Offset from origin = 0.36470, 0.11048, 0.11066 + input: "OculusTouch.LeftGrip", + axis: { x: 1, y: 0.302933918, z: 0.302933918 }, + maxTranslation: 0.003967, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_l_bumper.fbx/touch_l_bumper.fbm/L_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_l_bumper.fbx/touch_l_bumper.fbm/L_controller-highlight_DIF.jpg", + } + } + }, + + joystick: { + type: "joystick", + modelURL: BASE_URL + "touch_l_joystick.fbx", + naturalPosition: { x: 0.0075613949447870255, y: -0.008225866593420506, z: 0.004792703315615654 }, + + // joystick + xInput: "OculusTouch.LX", + yInput: "OculusTouch.LY", + originOffset: { x: 0, y: -0.0028564, z: -0.00 }, + xHalfAngle: 20, + yHalfAngle: 20, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_l_joystick.fbx/touch_l_joystick.fbm/L_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_l_joystick.fbx/touch_l_joystick.fbm/L_controller-highlight_DIF.jpg", + } + } + }, + + button_a: { + type: "linear", + modelURL: BASE_URL + "touch_l_button_x.fbx", + naturalPosition: { x: -0.009307309985160828, y: -0.00005015172064304352, z: -0.012594521045684814 }, + + input: "OculusTouch.X", + axis: { x: 0, y: -1, z: 0 }, + maxTranslation: 0.001, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_l_button_x.fbx/touch_l_button_x.fbm/L_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_l_button_x.fbx/touch_l_button_x.fbm/L_controller-highlight_DIF.jpg", + } + } + }, + + button_b: { + type: "linear", + modelURL: BASE_URL + "touch_l_button_y.fbx", + naturalPosition: { x: -0.01616849936544895, y: -0.000050364527851343155, z: 0.0017703399062156677 }, + + input: "OculusTouch.Y", + axis: { x: 0, y: -1, z: 0 }, + maxTranslation: 0.001, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_l_button_y.fbx/touch_l_button_y.fbm/L_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_l_button_y.fbx/touch_l_button_y.fbm/L_controller-highlight_DIF.jpg", + } + } + }, + } + } + ] +}; + +TOUCH_CONTROLLER_CONFIGURATION_RIGHT = { + name: "Touch", + controllers: [ + { + modelURL: BASE_URL + "touch_r_body.fbx", + jointIndex: MyAvatar.getJointIndex("_CONTROLLER_RIGHTHAND"), + naturalPosition: { x: -0.016486231237649918, y: -0.03551865369081497, z: -0.018527653068304062 }, + dimensions: { x: 0.11053784191608429, y: 0.09957750141620636, z: 0.10139875113964081 }, + rotation: rightBaseRotation, + position: Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 0, 45), rightBasePosition), + + parts: { + tips: { + type: "static", + modelURL: BASE_URL + "Oculus-Labels-R.fbx", + naturalPosition: { x: 0.009739525616168976, y: -0.0017818436026573181, z: 0.016794726252555847 }, + + textureName: "blank", + defaultTextureLayer: "blank", + textureLayers: { + blank: { + defaultTextureURL: BASE_URL + "Oculus-Labels-R.fbx/Oculus-Labels-R.fbm/Blank.png" + }, + trigger: { + defaultTextureURL: BASE_URL + "Oculus-Labels-R.fbx/Oculus-Labels-R.fbm/Trigger-oculus.png" + }, + arrows: { + defaultTextureURL: BASE_URL + "Oculus-Labels-R.fbx/Oculus-Labels-R.fbm/Rotate.png" + }, + grip: { + defaultTextureURL: BASE_URL + "Oculus-Labels-R.fbx/Oculus-Labels-R.fbm/Grip-oculus.png" + }, + teleport: { + defaultTextureURL: BASE_URL + "Oculus-Labels-R.fbx/Oculus-Labels-R.fbm/Teleport-oculus.png" + }, + } + }, + + trigger: { + type: "rotational", + modelURL: BASE_URL + "touch_r_trigger.fbx", + naturalPosition: { x: -0.0008544912561774254, y: -0.019867943599820137, z: 0.018800459802150726 }, + + // rotational + input: "OculusTouch.RT", + origin: { x: 0, y: -0.015, z: 0 }, + minValue: 0.0, + maxValue: 1.0, + axis: { x: 1, y: 0, z: 0 }, + maxAngle: 17, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_r_trigger.fbx/touch_r_trigger.fbm/R_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_r_trigger.fbx/touch_r_trigger.fbm/R_controller-highlight_DIF.jpg", + } + } + }, + + grip: { + type: "linear", + modelURL: BASE_URL + "touch_r_bumper.fbx", + naturalPosition: { x: -0.0000806618481874466, y: -0.027157839387655258, z: -0.024485092610120773 }, + + // linear properties + // Offset from origin = 0.36470, 0.11048, 0.11066 + input: "OculusTouch.RightGrip", + axis: { x: -1, y: 0.302933918, z: 0.302933918 }, + maxTranslation: 0.003967, + + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_r_bumper.fbx/touch_r_bumper.fbm/R_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_r_bumper.fbx/touch_r_bumper.fbm/R_controller-highlight_DIF.jpg", + } + } + }, + + joystick: { + type: "joystick", + modelURL: BASE_URL + "touch_r_joystick.fbx", + naturalPosition: { x: -0.007561382371932268, y: -0.008225853554904461, z: 0.00479268841445446 }, + + // joystick + xInput: "OculusTouch.RX", + yInput: "OculusTouch.RY", + originOffset: { x: 0, y: -0.0028564, z: 0 }, + xHalfAngle: 20, + yHalfAngle: 20, + + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_r_joystick.fbx/touch_r_joystick.fbm/R_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_r_joystick.fbx/touch_r_joystick.fbm/R_controller-highlight_DIF.jpg", + } + } + }, + + button_a: { + type: "linear", + modelURL: BASE_URL + "touch_r_button_a.fbx", + naturalPosition: { x: 0.009307296946644783, y: -0.00005015172064304352, z: -0.012594504281878471 }, + + input: "OculusTouch.A", + axis: { x: 0, y: -1, z: 0 }, + maxTranslation: 0.001, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_r_button_a.fbx/touch_r_button_a.fbm/R_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_r_button_a.fbx/touch_r_button_a.fbm/R_controller-highlight_DIF.jpg", + } + } + }, + + button_b: { + type: "linear", + modelURL: BASE_URL + "touch_r_button_b.fbx", + naturalPosition: { x: 0.01616847701370716, y: -0.000050364527851343155, z: 0.0017703361809253693 }, + + input: "OculusTouch.B", + axis: { x: 0, y: -1, z: 0 }, + maxTranslation: 0.001, + + textureName: "psdFileTex2", + defaultTextureLayer: "normal", + textureLayers: { + normal: { + defaultTextureURL: BASE_URL + "touch_r_button_b.fbx/touch_r_button_b.fbm/R_controller_DIF.jpg", + }, + highlight: { + defaultTextureURL: BASE_URL + "touch_r_button_b.fbx/touch_r_button_b.fbm/R_controller-highlight_DIF.jpg", + } + } + }, + } + } + ] +};