#!/bin/js // Function to handle getattr command function getattr(path,obj) { let size = 1 if (path === '/' || path.match(/\/[0-9]+$/) ) { return "16877 2 1000 1000 4096 8\n" } else { return `33188 1 1000 1000 ${size} 1\n` } return '' } function getPath(str){ const scene = document.querySelector('a-scene').object3D const path = str.split("/") const name = path.pop() const parent = path.pop() let obj = name == "" ? scene : scene.getObjectById( parseInt(name.substr(1)) ) const propvalue = "" if( obj && obj[ name ] ) propvalue = obj[name] return {obj,propname:name,propvalue} } // Main function to handle commands function main(args) { console.log( 'fs/THREE '+args.join(' ') ) let children = '' let props = ['name','uuid','position','rotation'] switch (args[0]) { case 'readdir':{ const {obj,propvalue,propname} = getPath( args[1] ) if( obj && obj.children ){ children = obj.children.map( (n) => n.name || n.id ) .join("\n") } return `${children}\n${props.join('\n')}\n` break; } case 'getattr':{ const {obj,propvalue,propname} = getPath( args[1] ) return getattr(args[1],{args,obj,propvalue,propname}); break; } case 'read':{ const {propvalue,propname} = getPath( args[1] ) return propvalue; break; } default: return '' } } // Run the main function return main(args.slice(1));