Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Last active November 28, 2022 14:19
Show Gist options
  • Save Utopiah/273ca366149f0a36c75674dd230980ea to your computer and use it in GitHub Desktop.
Save Utopiah/273ca366149f0a36c75674dd230980ea to your computer and use it in GitHub Desktop.
// see the alternative that fetch directly from the room to clone
// https://gist.github.com/Utopiah/8eb0d83e467d13994fd69c4631130561
function getObjects(){
var myObjects = []
for (var media of document.querySelectorAll("[media-loader]")){
if (media.components.pinnable && media.components.pinnable.attrValue.pinned)
myObjects.push({
src:media.components['media-loader'].attrValue.src,
position: media.getAttribute('position'),
rotation: media.getAttribute('rotation'),
scale: media.getAttribute('scale'),
})
}
return myObjects
}
var savedAsJSON = getObjects()
console.log(savedAsJSON)
console.log('Use "Copy Object" then in the target room with the same scene use loadObjectsFromJSON() on it')
function loadObjectsFromJSON(objectsToLoad){
document.querySelector('*[networked-counter]').setAttribute('networked-counter', {max: 100})
// to raise the 20 items limit
for (var media of objectsToLoad){
var el = document.createElement("a-entity")
AFRAME.scenes[0].appendChild(el)
el.setAttribute("media-loader", { src: media.src, fitToBox: true, resolve: true })
el.setAttribute("networked", { template: "#interactable-media" } )
el.setAttribute('position', media.position)
el.setAttribute('rotation', media.rotation)
el.setAttribute('scale', media.scale)
el.setAttribute("pinnable", {pinned: true} )
}
console.log('All',objectsToLoad.length,'objects loaded')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment