diff --git a/jxr-core.js b/jxr-core.js index 7554347..cdc3824 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -207,8 +207,8 @@ 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 ) + pos.sub( selectedElements.at(-1).startingPosition ) selectedElement.setAttribute("position", pos ) - // TODO get the world position of the selectedElement on pinchstarted then offset by that document.querySelector("#rightHand").object3D.traverse( e => { if (e.name == "ring-finger-tip"){ selectedElement.object3D.rotation.copy( e.rotation ) @@ -230,7 +230,9 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o selectedElement = getClosestTargetElement( event.detail.position ) if (selectedElement) { - selectedElements.push({element:selectedElement, timestamp:Date.now(), primary:true}) + let startingPosition = new THREE.Vector3() + selectedElement.parentEl.object3D.getWorldPosition( startingPosition ) + selectedElements.push({element:selectedElement, timestamp:Date.now(), startingPosition: startingPosition, primary:true}) selectedElement.emit("picked") } else { AFRAME.scenes[0].emit('emptypinch', {position:event.detail.position, timestamp:Date.now() })