From f9953f151d219c085e4cab4d8830cdc0726476d8 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 3 May 2024 14:49:13 +0200 Subject: [PATCH] simplified teleportation zones in XR with single component, fixed on enter VR pressable bug --- index.html | 38 +++++++++++++++++++++----------------- jxr-core.js | 8 ++++++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 3578a26..80d1517 100644 --- a/index.html +++ b/index.html @@ -204,13 +204,20 @@ function spreadItemsFromCollection( generatorName, offset=1, step=1/10, depth=-. } AFRAME.registerComponent('onemptypinch', { // changed from ondrop to be coherent with event name + init: function(){ + AFRAME.scenes[0].addEventListener('enter-vr', e => { + console.log('entered vr') + document.querySelector("[cursor]").setAttribute("visible", "true") + document.querySelector("[camera]").setAttribute("cursor", "") + }) + }, // could support multi events: { emptypinch: function (e) { + // works with AFRAME.scenes[0].emit('emptypinch', {position:"0 0 0"}) let code = this.el.getAttribute('onemptypinch') // if multi, should also look for onreleased__ not just onreleased try { - console.log('emptypinch', e.detail.position) eval( code ) // should be jxr too e.g if (txt.match(prefix)) interpretJXR(txt) } catch (error) { console.error(`Evaluation failed with ${error}`); @@ -219,11 +226,10 @@ AFRAME.registerComponent('onemptypinch', { // changed from ondrop to be coherent } }) -function onHoveredChangeColor(){ - console.log( "onHoveredChangeOpacity" ) +function onHoveredTeleport(){ // iterate over targets - // see instead of teleportable https://aframe.io/docs/1.5.0/components/cursor.html#configuring-the-cursor-through-the-raycaster-component - Array.from( document.querySelectorAll(".teleportable") ).map( target => { + // see instead of teleportable https://aframe.io/docs/1.5.0/components/cursor.html#configuring-the-cursor-through-the-raycaster-component + Array.from( document.querySelectorAll("[teleporter]") ).map( target => { if ( target.states.includes( "cursor-hovered" ) ){ target.setAttribute("material", "color", "magenta") // visited document.getElementById('rig').setAttribute('position', target.getAttribute("position") ) @@ -231,17 +237,15 @@ function onHoveredChangeColor(){ }) } -AFRAME.registerComponent('highlight-on-gaze', { +AFRAME.registerComponent('teleporter', { init: function(){ this.el.setAttribute("opacity", .5) }, events: { - mouseenter: function (e) { - this.el.setAttribute("opacity", .8) - }, - mouseleave: function (e) { - this.el.setAttribute("opacity", .5) - } + mouseenter: function (e) { this.el.setAttribute("opacity", .8) }, + mouseleave: function (e) { this.el.setAttribute("opacity", .5) }, + click: function (e) { document.getElementById('rig').setAttribute('position', this.el.getAttribute("position") ) } + // makes it compatible with mouse on desktop ... but also somehow enable the wrist shortcut?! } }); @@ -262,7 +266,7 @@ setTimeout( _ => { - + @@ -335,14 +339,14 @@ setTimeout( _ => { - - - + + + - + diff --git a/jxr-core.js b/jxr-core.js index cdc3824..87b0592 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -569,8 +569,12 @@ AFRAME.registerComponent('wristattachsecondary',{ init: function () { var el = this.el this.worldPosition=new THREE.Vector3(); + this.skip = false + if (! this.data.target ) this.skip = true }, tick: function () { + if (this.skip) return + // could check if it exists first, or isn't 0 0 0... might re-attach fine, to test // somehow very far away... need to convert to local coordinate probably // localToWorld? @@ -620,11 +624,11 @@ AFRAME.registerComponent('pressable', { var distance; for(var i=0;i0 && distance