working example

level-loader
Fabien Benetou 6 months ago
parent 9dd35eb462
commit 93c1d0ccb0
  1. 5
      index.html
  2. 30
      jxr.js

@ -304,6 +304,11 @@ AFRAME.registerComponent('wristright',{
<a-entity gltf-model="url(../content/PlayerSkater_Animations2.glb)" position="0 0 -2" animation-mixer="clip: *Hawk"></a-entity>
<a-tube control-points path="0 1 0,-5 1 -7,-20 1 -12,-25 1 0,-25 1 10,0 1 10,25 1 12,25 1 -12,-5 1 -12" radius="1" material="color: red;wireframe:true"></a-tube>
<a-entity levels-to-load>
<a-tube path="0 1 0,-5 1 -7,-20 1 -12,-25 1 0,-25 1 10,0 1 10,25 1 12,25 1 -12,-5 1 -12" radius="1" material="color: red;wireframe:true"></a-tube>
<a-tube path="0 1 0,-5 1 -7,-20 1 -12,-25 1 0,-5 1 10,0 1 10,25 1 12,25 1 -12,-5 1 -12" radius="1" material="color: green;wireframe:true"></a-tube>
<a-tube path="0 1 0,-5 1 -7,-20 1 -12,-25 1 0,-25 1 10,0 1 10,25 1 12,5 1 -2,-5 1 -12" radius="1" material="color: blue;wireframe:true"></a-tube>
</a-entity>
</a-scene>
</body>
</script>

@ -3644,6 +3644,36 @@ AFRAME.registerComponent('move-target-point', {
},
});
AFRAME.registerComponent('levels-to-load', {
init: function () {
const generatorName = this.attrName
Array.from( this.el.children ).map( (l,n) => {
l.id = 'level_'+n
let pos = '1 '+ (1+n/5) +' -.5'
addNewNote( 'jxr loadLevel("'+l.id+'")', pos, ".1 .1 .1", null, generatorName)
unloadLevel(l, pos)
})
},
});
function unloadLevel(el, pos){
const scale = .02
el.setAttribute('position', pos)
el.setAttribute('scale', scale + ' ' +scale + ' ' +scale )
console.log('unloading', el.id)
}
function loadLevel(elementIdName){
const el = document.getElementById(elementIdName)
Array.from( document.querySelector('[levels-to-load]').children ).map( (l) => {
let n = l.id.replace('level_','')
let pos = '1 '+ (1+n/5) +' -.5'
unloadLevel(l, pos)
})
el.setAttribute('scale', '1 1 1')
el.setAttribute('position', '0 0 0')
}
// 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', {

Loading…
Cancel
Save