From f6fb9ae4d1a7278e9acccf82981418e061d1a01e Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 27 Mar 2023 14:48:54 +0200 Subject: [PATCH] meshing that can be stopped, restarted and content moved --- index.html | 68 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index a067e6f..a61c485 100644 --- a/index.html +++ b/index.html @@ -2501,14 +2501,25 @@ function makeAnchorsVisibleOnTargets(){ function startMesher(){ let meshPoints = [] let meshEl = document.createElement("a-entity") + meshEl.className += "meshed" AFRAME.scenes[0].appendChild( meshEl ) + let elSecondary = document.querySelector('[pinchsecondary]') + elSecondary.addEventListener('pinchended', endedSecondary ); + function endedSecondary(){ + applyToClass("meshvertex", (e, val ) => e.setAttribute("visible", val), "false") + el.removeEventListener('pinchended', end) + elSecondary.removeEventListener('pinchended', endedSecondary ); + } + let el = document.querySelector('[pinchprimary]') - el.addEventListener('pinchended', function end(event) { + el.addEventListener('pinchended', end) + + function end(event) { if (selectedElement) return let currentPos = AFRAME.utils.coordinates.stringify( event.detail.position) let controlSphere = document.createElement("a-sphere") - controlSphere.class = "meshvertex" + controlSphere.className += "meshvertex" controlSphere.setAttribute("radius", 0.01) controlSphere.setAttribute("color", "green") controlSphere.setAttribute("wireframe", "true") @@ -2517,28 +2528,27 @@ function startMesher(){ controlSphere.setAttribute("position", currentPos) meshEl.appendChild( controlSphere ) meshPoints.push(controlSphere) - if (meshPoints.length>1){ + if (meshPoints.length==2){ let previousPos = AFRAME.utils.coordinates.stringify( meshPoints[meshPoints.length-2].getAttribute("position") ) - meshEl.setAttribute("line__l"+meshPoints.length, - `start: ${previousPos}; end : ${currentPos}; opacity: 1; color:white;`) - if (meshPoints.length>2){ - let ranked = meshPoints - .slice(0,-1) - .map( t => { return { el: t, dist : event.detail.position.distanceTo(t.getAttribute("position") ) } }) - .sort( (a,b) => a.dist - b.dist) - let triangle = document.createElement("a-triangle") - triangle.setAttribute("vertex-a", currentPos) - triangle.setAttribute("vertex-b", - AFRAME.utils.coordinates.stringify( ranked[0].el.getAttribute("position") )) - triangle.setAttribute("vertex-c", - AFRAME.utils.coordinates.stringify( ranked[1].el.getAttribute("position") )) - triangle.setAttribute("material", "side:double") - meshEl.appendChild( triangle ) - - } + meshEl.setAttribute("line", `start: ${previousPos}; end : ${currentPos}; opacity: 1; color:white;`) } - }) + if (meshPoints.length>2){ + meshEl.removeAttribute("line") + let ranked = meshPoints + .slice(0,-1) + .map( t => { return { el: t, dist : event.detail.position.distanceTo(t.getAttribute("position") ) } }) + .sort( (a,b) => a.dist - b.dist) + let triangle = document.createElement("a-triangle") + triangle.setAttribute("vertex-a", currentPos) + triangle.setAttribute("vertex-b", + AFRAME.utils.coordinates.stringify( ranked[0].el.getAttribute("position") )) + triangle.setAttribute("vertex-c", + AFRAME.utils.coordinates.stringify( ranked[1].el.getAttribute("position") )) + triangle.setAttribute("material", "side:double") + meshEl.appendChild( triangle ) + } + } } // used for testing @@ -2607,14 +2617,14 @@ AFRAME.registerComponent('startfunctions', { - - - - - - - - + + + + + + + +