diff --git a/index.html b/index.html index 46eba6e..e2c6df7 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + @@ -219,6 +219,19 @@ AFRAME.registerComponent('onemptypinch', { // changed from ondrop to be coherent } }) +function onHoveredChangeColor(){ + console.log( "onHoveredChangeOpacity" ) + let target = document.getElementById('testboxpinch') + // could iterate over targets, see https://aframe.io/docs/1.5.0/components/cursor.html#configuring-the-cursor-through-the-raycaster-component + console.log ( "cursor-hovered?", target.states.includes( "cursor-hovered" ) ) + if ( target.states.includes( "cursor-hovered" ) ){ + console.log ( "yes, cursor-hovered" ) + target.setAttribute("material", "color", "green") + //target.setAttribute("color", "red") + document.getElementById('rig').setAttribute('position', "4 0 -3") + // bug on hand pinch, even while checking on world position, might have to see older commit + } + } let page = "Wiki.VirtualRealityInterface"; // should do then only once graph loaded instead, should emit event @@ -237,16 +250,22 @@ setTimeout( _ => { - + + + + @@ -260,6 +279,7 @@ setTimeout( _ => { + { - - @@ -303,6 +321,10 @@ setTimeout( _ => { + + + + diff --git a/jxr-core.js b/jxr-core.js index 4ea28a2..d23274a 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -36,14 +36,26 @@ AFRAME.registerComponent('target', { }) function getClosestTargetElements( pos, threshold=0.05 ){ + // assumes pos has now no offset // TODO Bbox intersects rather than position - return targets.filter( e => e.getAttribute("visible") == true).map( t => { return { el: t, dist : pos.distanceTo(t.getAttribute("position") ) } }) + return targets.filter( e => e.getAttribute("visible") == true) + .map( t => { + let posTarget = new THREE.Vector3() + t.object3D.getWorldPosition( posTarget ) + let d = pos.distanceTo( posTarget ) + return { el: t, dist : d } + }) .filter( t => t.dist < threshold && t.dist > 0 ) .sort( (a,b) => a.dist > b.dist) } function getClosestTargetElement( pos, threshold=0.05 ){ // 10x lower threshold for flight mode var res = null + // assumes both hands have the same (single) parent, if any + let parentPos = document.getElementById('rig').getAttribute('position') + pos.add( parentPos ) + console.log( "from getClosestTargetElements, pos:", pos ) // relative pos, should thus remove rig position, even though it makes assumptions + const matches = getClosestTargetElements( pos, threshold) if (matches.length > 0) res = matches[0].el return res @@ -151,7 +163,10 @@ 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 closests = getClosestTargetElements( event.detail.position ) + let pos = event.detail.position + let parentPos = document.getElementById('rig').getAttribute('position') + pos.add( parentPos ) + var closests = getClosestTargetElements( pos ) //if (closests && closests.length > 0) // avoiding self reference // setFeedbackHUD("close enough, could stack with "+ closests[1].el.getAttribute("value") ) var dist = event.detail.position.distanceTo( document.querySelector("#box").object3D.position ) @@ -189,7 +204,10 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o selectionBox.update(); } if (selectedElement && !groupingMode) { - selectedElement.setAttribute("position", event.detail.position) + let pos = event.detail.position + let parentPos = document.getElementById('rig').getAttribute('position') + pos.add( parentPos ) + selectedElement.setAttribute("position", pos ) document.querySelector("#rightHand").object3D.traverse( e => { if (e.name == "ring-finger-tip"){ selectedElement.object3D.rotation.copy( e.rotation )