Last active
August 15, 2022 13:35
-
-
Save Utopiah/8eb0d83e467d13994fd69c4631130561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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