aframe: allow empty init

This commit is contained in:
Leon van Kammen 2023-06-27 09:42:49 +02:00
parent 5bc67f2b6b
commit 436ed610d1

View file

@ -3,7 +3,7 @@ window.AFRAME.registerComponent('xrf', {
},
init: function () {
if( !AFRAME.XRF ) this.initXRFragments()
if( this.data ){
if( typeof this.data == "string" ){
if( document.location.search || document.location.hash.length > 1 ){ // override url
this.data = `${document.location.search.substr(1)}${document.location.hash}`
}
@ -22,22 +22,22 @@ window.AFRAME.registerComponent('xrf', {
// enable XR fragments
let aScene = document.querySelector('a-scene')
let XRF = AFRAME.XRF = xrf.init({
let XRF = AFRAME.XRF = xrf.init({
THREE,
camera: aScene.camera,
camera: aScene.camera,
scene: aScene.object3D,
renderer: aScene.renderer,
debug: true,
loaders: { gltf: THREE.GLTFLoader } // which 3D assets (exts) to check for XR fragments?
})
if( !XRF.camera ) throw 'xrfragment: no camera detected, please declare <a-entity camera..> ABOVE entities with xrf-attributes'
// override the camera-related XR Fragments so the camera-rig is affected
// override the camera-related XR Fragments so the camera-rig is affected
let camOverride = (xrf,v,opts) => {
opts.camera = document.querySelector('[camera]').object3D.parent
opts.camera = document.querySelector('[camera]').object3D.parent
xrf(v,opts)
}
xrf.pos = camOverride
// in order to set the rotation programmatically
@ -47,15 +47,15 @@ window.AFRAME.registerComponent('xrf', {
let look = document.querySelector('[look-controls]')
if( look ) look.removeAttribute("look-controls")
camOverride(xrf,v,opts)
// *TODO* make look-controls compatible, because simply
// *TODO* make look-controls compatible, because simply
// adding the look-controls will revert to the old rotation (cached somehow?)
//setTimeout( () => look.setAttribute("look-controls",""), 100 )
}
// convert portal to a-entity so AFRAME
// raycaster can find & execute it
xrf.href = (xrf,v,opts) => {
camOverride(xrf,v,opts)
xrf.href = (xrf,v,opts) => {
camOverride(xrf,v,opts)
let {mesh,camera} = opts;
let el = document.createElement("a-entity")
el.setAttribute("xrf-get",mesh.name )
@ -71,7 +71,7 @@ window.AFRAME.registerComponent('xrf', {
let els = [...document.querySelectorAll('[xrf-get]')]
els.map( (el) => document.querySelector('a-scene').removeChild(el) )
})(XRF.reset)
// undo lookup-control shenanigans (which blocks updating camerarig position in VR)
aScene.addEventListener('enter-vr', () => document.querySelector('[camera]').object3D.parent.matrixAutoUpdate = true )
},