event details and shortened poses for voxelpaint

game-multiple-levels
Fabien Benetou 2 weeks ago
parent c7e76c8efc
commit 5544b53244
  1. 17
      index.html
  2. 5
      jxr-core.js

@ -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
}
})

@ -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})
}
}
}

Loading…
Cancel
Save