From 21c74453f216fba04a127f9b3cf73be2a6dbd63c Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 30 Jan 2023 09:15:26 +0100 Subject: [PATCH] drop zone as a sphere --- index.html | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 06866ec..88fa1e2 100644 --- a/index.html +++ b/index.html @@ -2223,7 +2223,6 @@ function changeColorNextPinch(){ // should link to the right code already written // see also cloneAndDistribute() & observe() but there is another one... between pinches // observe being a shortcut to bindVariableValueToNewNote(variableName) - let pointsFromMovement = [] function nextMovementToPoints(){ pointsFromMovement = [] // could also add them to a larger array with timestamps @@ -2249,6 +2248,33 @@ function nextMovementToPoints(){ */ } +function addDropZone(position="0 1.4 -0.6", callback=setFeedbackHUD, radius=0.11){ + let el = document.createElement("a-sphere") + el.setAttribute("wireframe", true) + el.setAttribute("radius", radius) + el.setAttribute("position", position) + el.id = "dropzone_"+Date.now() + AFRAME.scenes[0].appendChild( el ) + let sphere = new THREE.Sphere( AFRAME.utils.coordinates.parse( position ), radius ) + // could become movable but would then need to move the matching sphere too + // could be a child of that entity + let pincher = document.querySelector('[pinchprimary]') + pincher.addEventListener('pinchended', function (event) { + if (selectedElements.length){ + let lastDrop = selectedElements[selectedElements.length-1] + if ((Date.now() - lastDrop.timestamp) < 1000){ + if (sphere.containsPoint( lastDrop.element.getAttribute("position"))){ + // should be a threejs sphere proper, not a mesh + console.log("called back" ) + callback( lastDrop.selectedElement ) + } + } + } + }) + // never unregister + return el +} + /* generalize selector to pick last Nth rather than very last @@ -2332,6 +2358,7 @@ consider pick then apply, i.e changeColorLastId() but for next Id +