event details and shortened poses for voxelpaint

in-situ-instructions
Fabien Benetou 8 months ago
parent c7e76c8efc
commit 5544b53244
  1. 17
      index.html
  2. 5
      jxr-core.js

@ -16,6 +16,8 @@
/* TODO : /* TODO :
- refactor to use emit('eventname', {eventdata:'data'}) for onreleased and onpicked rather than latest element - 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+'"})') 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) - 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) - isolate emit('eventname', {test:0}) versus same with onreleased (which does NOT work) and same without event detail (which works)
- add audio instructions - add audio instructions
@ -52,8 +54,8 @@ AFRAME.registerComponent('startfunctions', {
let newEl = document.createElement('a-entity') let newEl = document.createElement('a-entity')
//let gamename = "checkers" //let gamename = "checkers"
//let gamename = "carcassone" //let gamename = "carcassone"
let gamename = "simon" //let gamename = "simon"
//let gamename = "voxelpaint" let gamename = "voxelpaint"
newEl.id = gamename newEl.id = gamename
newEl.setAttribute(gamename, "") newEl.setAttribute(gamename, "")
newEl.classList.add( "game" ) newEl.classList.add( "game" )
@ -168,8 +170,8 @@ AFRAME.registerComponent('voxelpaint', {
let poses = [] let poses = []
Array.from( this.el.querySelectorAll(".voxel") ).map( el => { Array.from( this.el.querySelectorAll(".voxel") ).map( el => {
poses.push( { poses.push( {
position: el.getAttribute("position"), position: this.shortenVector3( el.getAttribute("position") ),
rotation: el.getAttribute("rotation"), rotation: this.shortenVector3( el.getAttribute("rotation") ),
color: el.getAttribute("color") color: el.getAttribute("color")
} ) } )
}) })
@ -178,6 +180,13 @@ AFRAME.registerComponent('voxelpaint', {
window.location.hash = JSON.stringify(data) window.location.hash = JSON.stringify(data)
// prefixed by generatorName in order to support saving/sharing of the state of other games // 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
} }
}) })

@ -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 // 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) { pinchstarted: function (event) {
primaryPinchStarted = true primaryPinchStarted = true
@ -199,7 +200,7 @@ AFRAME.registerComponent('pinchprimary', { // currently only 1 hand, the right o
selectedElement = getClosestTargetElement( event.detail.position ) selectedElement = getClosestTargetElement( event.detail.position )
if (selectedElement) { if (selectedElement) {
selectedElements.push({element:selectedElement, timestamp:Date.now(), primary:true}) selectedElements.push({element:selectedElement, timestamp:Date.now(), primary:true})
selectedElement.emit("picked") selectedElement.emit("picked", {element:selectedElement, timestamp:Date.now(), primary:true})
} }
} }
} }

Loading…
Cancel
Save