Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var yourSceneURL = 'https://hubs.mozilla.com/LHzDxae/' // no trailing room name, only ID.
// Also works on Hubs Cloud servers but assets have to remain available (i.e no CORS, 404, etc)
// example of grabbing a local copy of assets hosted with the proxy
// curl https://hubs.mozilla.com/LHzDxae/objects.gltf | jq .nodes[].extensions.HUBS_components.media.src -r | grep uploads-prod.reticulum.io
function populateSceneFromMozGLTF(scene){
document.querySelector('*[networked-counter]').setAttribute('networked-counter', {max: 100})
for (var node of scene.nodes){
console.log(node)
var el = document.createElement("a-entity")
AFRAME.scenes[0].appendChild(el)
el.setAttribute("media-loader", { src: node.extensions.HUBS_components.media.src, fitToBox: true, resolve: true })
el.setAttribute("networked", { template: "#interactable-media" } )
if (node.translation) el.object3D.position.fromArray(node.translation)
if (node.scale) el.object3D.scale.fromArray(node.scale)
if (node.rotation) el.object3D.quaternion.fromArray(node.rotation)
// somehow doesn't seem to be applied right, might be xyzw/wxyz or translating to origin first?
el.setAttribute("pinnable", {pinned: true} )
}
console.log('All',scene.nodes.length,'objects loaded')
}
fetch(yourSceneURL+'objects.gltf')
.then( response => { return response.json() } )
.then( scene => populateSceneFromMozGLTF( scene ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment