Last active
November 23, 2020 22:12
-
-
Save mattrossman/7dd2b990820c4753685d34f4ab8c1094 to your computer and use it in GitHub Desktop.
Hubs stash and unstash
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
/* Usage: | |
let data = stash() | |
// Or in the (Firefox) console, right click on the output array -> "Copy Object" to move data across scenes. | |
let elements = unstash(data) | |
*/ | |
function getAllMedia() { | |
return document.querySelectorAll("[media-loader][networked]") | |
} | |
function loadMedia(url) { | |
var el = document.createElement("a-entity") | |
AFRAME.scenes[0].appendChild(el) | |
el.setAttribute("media-loader", { src: url, fitToBox: true, resolve: true }) | |
el.setAttribute("networked", { template: "#interactable-media" } ) | |
return el | |
} | |
function stash() { | |
const out = [] | |
getAllMedia().forEach(el => { | |
out.push({ | |
src: el.getAttribute('media-loader').src, | |
position: el.getAttribute('position'), | |
rotation: el.getAttribute('rotation'), | |
scale: el.getAttribute('scale'), | |
}) | |
}) | |
return out | |
} | |
function unstash(data) { | |
const out = [] | |
data.forEach(obj => { | |
el = loadMedia(obj.src) | |
el.setAttribute('position', obj.position) | |
el.setAttribute('rotation', obj.rotation) | |
el.setAttribute('scale', obj.scale) | |
out.push(el) | |
}) | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment