Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Last active May 22, 2021 16:05
Show Gist options
  • Save Utopiah/e993403d27f2ac83367cff9794c2ece0 to your computer and use it in GitHub Desktop.
Save Utopiah/e993403d27f2ac83367cff9794c2ece0 to your computer and use it in GitHub Desktop.
// change YOURID with... YOUR ngrok id ;)
var lastModelTimestamp = null
var intervalCheck = setInterval(newModelReady, 500)
function newModelReady(){
fetch('http://YOURID.ngrok.io/timestamp.txt').then( response => { return response.json() } )
.then( timestamp => checkIfNovelModelAvailable(timestamp) )
}
function checkIfNovelModelAvailable(timestamp){
if (lastModelTimestamp != timestamp){
lastModelTimestamp = timestamp
refreshModel()
}
}
function loadAssetsFromURLs(URLs){
var elements = []
for (var url of URLs){
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" } )
el.setAttribute("uploadedAssets")
elements.push(el)
}
return elements
}
function refreshModel(){
for (var e of AFRAME.scenes[0].querySelectorAll("[uploadedAssets]")) e.remove()
var el = loadAssetsFromURLs([
"http://YOURID.ngrok.io/model.glb#" + +new Date()
])
el[0].setAttribute("position", "0 1 0")
}
/*
# Blender script :
# (could be threaded or with shortcut)
def saveForLiveLoad():
import time
import bpy
with open('/home/fabien/Prototypes/modellingSync/timestamp.txt', 'w') as out:
out.write( str( time.time()) )
bpy.ops.export_scene.gltf(filepath='/home/fabien/Prototypes/modellingSync/model.glb')
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment