From 565e74c7be8ab5209db2b302b49068cf90a8b5cd Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Sat, 1 Oct 2022 16:10:35 +0200 Subject: [PATCH] bind shortcut to wrist --- index.html | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 8259cff..3afc7f8 100644 --- a/index.html +++ b/index.html @@ -77,6 +77,18 @@ setTimeout( _ => // could add a dedicated MakeyMakey mode with a fixed camera, e.g bird eye view, and an action based on some physical input that others, thanks to NAF, could see or even use. // ?inputmode=makeymakey +AFRAME.registerComponent('enable-components-via-url', { + init: function () { + var src = AFRAME.utils.getUrlParameter('enable-components-via-url') + if (src && src != "") { + src.split(",").map( c => { + this.el.setAttribute(c, "") + }) + } + } +}) + + AFRAME.registerComponent('disable-components-via-url', { init: function () { var src = AFRAME.utils.getUrlParameter('disable-components-via-url') @@ -795,6 +807,7 @@ AFRAME.registerComponent('wristattachsecondary',{ } }); +var primaryPinchStarted = false AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right one // consider instead https://github.com/AdaRoseCannon/handy-work/blob/main/README-AFRAME.md for specific poses @@ -807,6 +820,12 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o // see own trigger-box component. Could use dedicated threejs helpers instead. // https://github.com/Utopiah/aframe-triggerbox-component/blob/master/aframe-triggerbox-component.js#L66 // could make trigger zones visible as debug mode + var dist = event.detail.position.distanceTo( document.querySelector("#box").object3D.position ) + if (dist < .1){ + setHUD("close enough, replaced shortcut with "+ selectedElement.getAttribute("value") ) + wristShortcut = selectedElement.getAttribute("value") + setTimeout( _ => setHUD(""), 2000) + } // unselect current target if any selectedElement = null; save() @@ -825,6 +844,7 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o bbox.min.copy( zeroVector3 ) bbox.man.copy( zeroVector3 ) */ + setTimeout( _ => primaryPinchStarted = false, 200) // delay otherwise still activate on release }); this.el.addEventListener('pinchmoved', function (event) { // move current target if any @@ -840,6 +860,7 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o } }); this.el.addEventListener('pinchstarted', function (event) { + primaryPinchStarted = true if (!selectionPinchMode) bbox.max.copy( zeroVector3 ) //var clone = getClosestTargetElement( event.detail.position ).cloneNode() @@ -856,7 +877,7 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o // testing on desktop var visible = true -function tst(){ +function switchToWireframe(){ visible = !visible targets.map( e => { scale = 50// should be a variable instead @@ -878,7 +899,7 @@ function tst(){ // add (JXR) shortcuts as PIM function from e.g https://observablehq.com/@utopiah/from-pim-to-2d-to-3d-to-xr-explorations // allowing to search within PIM then show manipulable pages as preview. -// note that can be tested in VR also as jxr tst() +// note that can be tested in VR also as jxr switchToWireframe() // could make for nice in VR testing setup as eved notes var setupMode = false @@ -889,11 +910,13 @@ function enterSetupMode(){ setupMode = true } -AFRAME.registerComponent('changecoloronpress', { +var wristShortcut = "jxr switchToWireframe()" +AFRAME.registerComponent('start-on-press', { + // should become a property of the component instead to be more flexible. init: function(){ var el = this.el this.el.addEventListener('pressedended', function (event) { - tst() + if (!primaryPinchStarted && wristShortcut.match(/^jxr /)) interpretJXR(wristShortcut) // other action could possibly based on position relative to zones instead, i.e a list of bbox/functions pairs }) } @@ -1002,6 +1025,7 @@ AFRAME.registerComponent('hud', { init: function(){ var el = this.el var e = document.createElement("a-text") //could be hardcoded instead... arguable. + // should also be troika e.setAttribute("value", startingText) //e.setAttribute("font", "sw-test/Roboto-msdf.json") e.setAttribute("position", "-0.05 0 -0.2") @@ -1176,28 +1200,25 @@ function interpretJXR( code ){ // opt re-run it by moving the corresponding text in target volume } -AFRAME.registerComponent('toolbox', { +AFRAME.registerComponent('toolbox', { // ununsed init: function(){ var el = this.el var e = document.createElement("a-sphere") e.setAttribute("scale", "0.1 0.1 0.1") e.setAttribute("color", "lightblue") e.setAttribute("pressable") - e.setAttribute("changecoloronpress") e.id = "toolboxsphere" el.appendChild( e ) var e = document.createElement("a-cylinder") e.setAttribute("scale", "0.1 0.1 0.1") e.setAttribute("color", "darkred") e.setAttribute("pressable") - e.setAttribute("changecoloronpress") e.id = "toolboxcylinder" el.appendChild( e ) var e = document.createElement("a-box") e.setAttribute("scale", "0.1 0.1 0.1") e.setAttribute("color", "pink") e.setAttribute("pressable") - e.setAttribute("changecoloronpress") e.id = "toolbox" el.appendChild( e ) }, @@ -1274,6 +1295,7 @@ AFRAME.registerComponent('fot', { init:function(){ let generatorName = this.attrName setInterval( _ => fetch("https://fabien.benetou.fr/PIMVRdata/FoT?action=source#" + Date.now()).then(res => res.text() ).then(res => { + // consider tick() instead res.split("\n").slice(0,maxItemsFromSources).map( (n,i) => { found = added.find((str) => str === n) if (typeof found === 'undefined'){ @@ -1450,9 +1472,9 @@ var generators = "line-link-entities link screenstack dynamic-view selectionboxo
+ capturegesture toolbox disable-components-via-url enable-components-via-url commands-from-external-json + networked-scene="serverURL: https://naf.benetou.fr/; adapter: easyrtc; audio: true;"> + @@ -1481,7 +1503,7 @@ var generators = "line-link-entities link screenstack dynamic-view selectionboxo - +