diff --git a/index.html b/index.html index f52f80a..9cd3182 100644 --- a/index.html +++ b/index.html @@ -4,214 +4,34 @@ - - +
@@ -315,7 +166,7 @@ setTimeout( _ => {
- + @@ -358,36 +209,6 @@ setTimeout( _ => { - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/jxr-core.js b/jxr-core.js index 8a26ce1..d0254ce 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -35,10 +35,12 @@ AFRAME.registerComponent('target', { } }) -function getClosestTargetElements( pos, threshold=0.05 ){ +// note that set is an array of elements from e.g getArrayFromClass(classname) + // it is NOT a selector! +function getClosestElements( pos, threshold=0.05, set ){ // assumes pos has now no offset // TODO Bbox intersects rather than position - return targets.filter( e => e.getAttribute("visible") == true) + return set.filter( e => e.getAttribute("visible") == true) .map( t => { let posTarget = new THREE.Vector3() t.object3D.getWorldPosition( posTarget ) @@ -49,18 +51,20 @@ function getClosestTargetElements( pos, threshold=0.05 ){ .sort( (a,b) => a.dist > b.dist) } -function getClosestTargetElement( pos, threshold=0.05 ){ // 10x lower threshold for flight mode +function getClosestElement( pos, threshold=0.05, set ){ // 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) + const matches = getClosestElements( pos, threshold, set) if (matches.length > 0) res = matches[0].el return res } +function getClosestTargetElement( pos, threshold=0.05 ){ // 10x lower threshold for flight mode + return getClosestElement( pos, threshold, targets) +} + // ==================================== HUD ====================================================== var keyboardInputTarget = 'hud' @@ -169,7 +173,7 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o let pos = event.detail.position let parentPos = document.getElementById('rig').getAttribute('position') pos.add( parentPos ) - var closests = getClosestTargetElements( pos ) + //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 ) @@ -180,6 +184,8 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o if (selectedElement){ let content = selectedElement.getAttribute("value") selectedElement.emit('released', {element:selectedElement, timestamp:Date.now(), primary:true}) + } else { + AFRAME.scenes[0].emit('emptypinchreleased', {position:event.detail.position, timestamp:Date.now() }) } // unselect current target if any selectedElement = null; @@ -219,7 +225,11 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o }) // rotation isn't ideal with the wrist as tend not have wrist flat as we pinch } - if (selectedElement) selectedElement.emit("moved") + if (selectedElement) { + selectedElement.emit("moved") + } else { + AFRAME.scenes[0].emit('emptypinchmoved', {position:event.detail.position, timestamp:Date.now() }) + } }); this.el.addEventListener('pinchstarted', function (event) { primaryPinchStarted = true