xrforge-webxr/lib/xrforge/index.js

62 lines
2.1 KiB
JavaScript
Raw Normal View History

2025-10-23 19:20:50 +02:00
import {widget as Widget} from './../widget.js'
2025-10-22 17:10:42 +02:00
import {inferSource} from './util.js'
2025-10-23 19:20:50 +02:00
// extensions
import {default as thumb} from './../widget/thumb.js'
import {default as play} from './../widget/play.js'
const widget = Widget()
2025-10-22 17:10:42 +02:00
2025-10-23 19:20:50 +02:00
// init extensions
thumb(widget)
play(widget)
// init xrforge extension
widget.ext.xrforge = {
2025-10-22 17:10:42 +02:00
}
2025-10-23 19:20:50 +02:00
// in case of Manyfold backend, a thumbnail is passed (not gltf src e.g.)
// so we will infer the source-url based on the thumbnail
widget.on('init.thumb', async (thumb) => {
let src = widget.src
const img = /\.(png|jpg|webp)/
if( src.match(img) ){
thumb.src = src
let inferredSrc = await inferSource(src)
widget.src = inferredSrc.replace(img,".glb")
}
2025-10-22 17:10:42 +02:00
2025-10-23 19:20:50 +02:00
})
widget.on("play", async () => {
// initialize a specialized build of THREE/AFRAME
const AFRAME = await import('aframe')
window.THREE.DRACOLoader = await import('three/examples/jsm/loaders/DRACOLoader.js')
window.THREE.FBXLoader = await import('three/examples/jsm/loaders/FBXLoader.js')
window.THREE.USDZLoader = await import('three/examples/jsm/loaders/USDZLoader.js')
window.THREE.ColladaLoader = await import('three/examples/jsm/loaders/ColladaLoader.js')
window.THREE.MTLLoader = await import('three/examples/jsm/loaders/MTLLoader.js')
window.THREE.GLTFExporter = await import('three/examples/jsm/exporters/GLTFExporter.js')
// optional utils
window.zipjs = await import("@zip.js/zip.js")
window.webdav = await import("webdav")
window.rs = await import("remotestoragejs")
window.trystero = await import("trystero")
// include xrsh (remote for now, until the final integration is more clear)
const script = document.createElement("script")
script.src = "https://xrsh.isvery.ninja/xrsh.js"
script.addEventListener("load", function(){
const ent = document.createElement("a-entity")
ent.setAttribute("isoterminal","minimized:true")
ent.setAttribute("position","0 1.6 -0.3")
document.querySelector("a-scene").appendChild(ent)
})
document.body.appendChild(script)
})
2025-10-22 17:10:42 +02:00
2025-10-23 19:20:50 +02:00
await widget.emit("init")
console.dir(widget)