From 9dd35eb462a8db290b64a2a6cfcc607df491c2ad Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 10 Nov 2023 22:53:16 +0100 Subject: [PATCH] working example --- index.html | 4 ++-- jxr.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 99a8847..26b4e57 100644 --- a/index.html +++ b/index.html @@ -112,7 +112,7 @@ AFRAME.registerComponent('odometer',{ positions.push( pos ) if (positions.length > 20) { let dist = pos.distanceTo( positions[positions.length-20] ) - console.log(dist) // could be done via setFeedbackHUD() instead + //console.log(dist) // could be done via setFeedbackHUD() instead el.setAttribute('value', dist.toFixed(2)) } }}) @@ -303,7 +303,7 @@ AFRAME.registerComponent('wristright',{ - + diff --git a/jxr.js b/jxr.js index fbdada0..ac42c89 100644 --- a/jxr.js +++ b/jxr.js @@ -3564,7 +3564,7 @@ AFRAME.registerComponent('changeover', { .map( t => { return { el: t, dist : pos.distanceTo(t.getAttribute("position") ) } }) .filter( t => t.dist < 0.02 ) .sort( (a,b) => a.dist > b.dist) - console.log(hits.length) + //console.log(hits.length) if (hits.length>0) { setFeedbackHUD('touching cone') console.log('touching cone') @@ -3609,6 +3609,41 @@ AFRAME.registerComponent('pull', { }, }); +AFRAME.registerComponent('control-points', { + init: function () { + let cPoints = this.el.getAttribute("path").split(",") + if (!this.el.id) this.el.id = 'control-point-target' + Date.now() + cPoints.map( (p,n) => { + let controlSphere = document.createElement("a-sphere") + controlSphere.setAttribute("radius", 0.05) + controlSphere.setAttribute("color", "red") + controlSphere.setAttribute("wireframe", "true") + controlSphere.setAttribute("segments-width", 8) + controlSphere.setAttribute("segments-height", 8) + controlSphere.setAttribute("target", '') + controlSphere.setAttribute("move-target-point", 'target:'+this.el.id+';number:'+n) + controlSphere.setAttribute("position", p) + controlSphere.setAttribute("value", '') + AFRAME.scenes[0].appendChild(controlSphere) + }) + }, +}); + +AFRAME.registerComponent('move-target-point', { + schema: { + target: {type: 'string'}, + number: {type: 'number'}, + }, + events: { + moved: function (evt) { + let targetEl = document.getElementById(this.data.target) + let newPath = targetEl.getAttribute("path").split(",") + newPath[this.data.number] = AFRAME.utils.coordinates.stringify( this.el.getAttribute('position') ) + targetEl.setAttribute( 'path', newPath.join(',') ) + }, + }, +}); + // used for testing, now that jxr.js is outside of index.html, could consider putting this back in index.html instead to keep behavior one would expect from a library // does indeed create problems, namely other pages relying on it do get this testing behavior AFRAME.registerComponent('startfunctions', {