function filterTapestryJSON( contentFilename ){ let file = filesWithMetadata[contentFilename] if (!file) return let contentType = file.contentType // TODO support zipped version directly, cf e.g. mapvisualmeta.jsons.zip.js /* // example of zip support fetch( contentFilename ).then( r => r.blob(r) ).then( file => zip.loadAsync(file) ).then( f => { console.log(f.files) let filenameFromZip = Object.entries( f.files ).filter( i => i[0].includes("partialfilename.ext") ).map( i => i[0] )[0] f.files[filenameFromZip].async("string").then( dyn_content => { json = JSON.parse( dyn_content ) }) }) */ if ( contentType.includes("json") && contentFilename.startsWith("tapestry/") && contentFilename.endsWith("root.json")) { console.log('it is a tapestry export file', contentFilename) fetch( contentFilename ).then( r => r.json() ).then( json => { // console.log( json ) let thumbnailPath = json.thumbnail.replace("file:/","/tapestry/") let el = document.createElement("a-image") el.setAttribute("position", "0 1.5 0.7") el.setAttribute("rotation", "0 180 0") el.setAttribute("src", thumbnailPath) el.setAttribute("width", json.startView.size.width/10000) el.setAttribute("height", json.startView.size.height/10000) AFRAME.scenes[0].appendChild(el) let positioned = {} json.items.map( i => { let x = 1-i.position.x/1000 let y = 2-i.position.y/1000 let el = null if (i.type == "text") { el = addNewNoteAsPostItNote( i.text, x + " " + y + " 1", ".1 .1 .1", "tapestry_"+i.id, "tapestry_text", true, "0 180 0") // addNewNoteAsPostItNote( text, position=`-0.2 1.1 -0.1`, scale= "0.1 0.1 0.1", id=null, classes="notes", visible="true", rotation="0 0 0" ){ } if (i.thumbnail) { let thumbnailPath = i.thumbnail.source.replace("file:/","/tapestry/") el = document.createElement("a-image") el.setAttribute("position", x + " " + y + " 1") el.setAttribute("rotation", "0 180 0") el.setAttribute("src", thumbnailPath) el.setAttribute("width", i.size.width/1000) el.setAttribute("height", i.size.height/1000) AFRAME.scenes[0].appendChild(el) } positioned[i.id] = el if ( el ) el.setAttribute("target", "") }) setTimeout( _ => { // must be done after the items are positioned json.rels.map( i => { let el = document.createElement("a-tube") console.log( i.from.itemId, i.to.itemId ) let start = positioned[i.from.itemId].getAttribute("position") let end = positioned[i.to.itemId].getAttribute("position") let mid = new THREE.Vector3() mid.copy ( start ) mid.add ( end ) mid.divideScalar(2) mid.z += 0.3 let path = [start, mid, end].map( p => AFRAME.utils.coordinates.stringify( p ) ).join(", ") el.setAttribute("radius", 0.01) el.setAttribute("path", path) AFRAME.scenes[0].appendChild(el) }) }, 1000 ) AFRAME.scenes[0].emit('tapestryjsonloaded', contentFilename) // to use the event consider : //AFRAME.scenes[0].addEventListener("visualmetajsonloaded", e => console.log(e)) }) } applyNextFilter( contentFilename ) } sequentialFilters.push( filterTapestryJSON )