From 5544b53244f75d52325f8ed23e2228f214aa70ca Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 6 May 2024 19:04:23 +0200 Subject: [PATCH] event details and shortened poses for voxelpaint --- index.html | 17 +++++++++++++---- jxr-core.js | 5 +++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 4bbe10e..81bf9d0 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,8 @@ /* TODO : - refactor to use emit('eventname', {eventdata:'data'}) for onreleased and onpicked rather than latest element e.g newEl.setAttribute("onreleased", 'document.querySelector("['+generatorName+']").emit("check",{color:"'+color+'"})') + let latest = selectedElements[selectedElements.length-1].element + check for this pattern and replace by event.detail.element instead - insure scene setup, e.g starting position and orientation of environment and main character (until now assumed unchanged) - isolate emit('eventname', {test:0}) versus same with onreleased (which does NOT work) and same without event detail (which works) - add audio instructions @@ -52,8 +54,8 @@ AFRAME.registerComponent('startfunctions', { let newEl = document.createElement('a-entity') //let gamename = "checkers" //let gamename = "carcassone" - let gamename = "simon" - //let gamename = "voxelpaint" + //let gamename = "simon" + let gamename = "voxelpaint" newEl.id = gamename newEl.setAttribute(gamename, "") newEl.classList.add( "game" ) @@ -168,8 +170,8 @@ AFRAME.registerComponent('voxelpaint', { let poses = [] Array.from( this.el.querySelectorAll(".voxel") ).map( el => { poses.push( { - position: el.getAttribute("position"), - rotation: el.getAttribute("rotation"), + position: this.shortenVector3( el.getAttribute("position") ), + rotation: this.shortenVector3( el.getAttribute("rotation") ), color: el.getAttribute("color") } ) }) @@ -178,6 +180,13 @@ AFRAME.registerComponent('voxelpaint', { window.location.hash = JSON.stringify(data) // prefixed by generatorName in order to support saving/sharing of the state of other games } + }, + shortenVector3: function ( v ){ + let o = new THREE.Vector3() + o.x = v.x.toFixed(3) + o.y = v.y.toFixed(3) + o.z = v.z.toFixed(3) + return o } }) diff --git a/jxr-core.js b/jxr-core.js index c9c64fc..ae229d6 100644 --- a/jxr-core.js +++ b/jxr-core.js @@ -190,7 +190,8 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o }) // rotation isn't ideal with the wrist as tend not have wrist flat as we pinch } - if (selectedElement) selectedElement.emit("moved") // consider adding as data selectedElement + if (selectedElement) selectedElement.emit("moved", {element:selectedElement, timestamp:Date.now(), primary:true}) + // might be costly... }, pinchstarted: function (event) { primaryPinchStarted = true @@ -199,7 +200,7 @@ 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}) - selectedElement.emit("picked") + selectedElement.emit("picked", {element:selectedElement, timestamp:Date.now(), primary:true}) } } }