From 1835def7c451b88aca1508e31c31cdec956276db Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 2 May 2024 17:09:01 +0200 Subject: [PATCH] supporting parented entity after teleportation --- jxr-core.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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() })