2024-12-30 09:47:23 +01:00
|
|
|
#!/bin/js
|
|
|
|
|
|
|
|
// Function to handle getattr command
|
2025-01-09 12:14:26 +01:00
|
|
|
function getattr(path,opts){
|
2024-12-30 09:47:23 +01:00
|
|
|
let size = 1
|
2025-01-09 12:14:26 +01:00
|
|
|
if (path === '/' || opts.obj ){
|
|
|
|
return "16877 2 0 0 4096 8\n"
|
2024-12-30 09:47:23 +01:00
|
|
|
} else {
|
2025-01-09 12:14:26 +01:00
|
|
|
return `33188 1 0 0 ${size} 1\n`
|
2024-12-30 09:47:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2025-01-09 12:14:26 +01:00
|
|
|
: scene.getObjectByName( name ) ||
|
|
|
|
scene.getObjectById( parseInt(name.substr(1)) )
|
|
|
|
console.dir({parent,name,obj})
|
|
|
|
|
|
|
|
return {obj,propname:name}
|
2024-12-30 09:47:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Main function to handle commands
|
|
|
|
function main(args) {
|
|
|
|
console.log( 'fs/THREE '+args.join(' ') )
|
|
|
|
let children = ''
|
2025-01-09 12:14:26 +01:00
|
|
|
let props = ['uuid','position','rotation']
|
2024-12-30 09:47:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
switch (args[0]) {
|
|
|
|
case 'readdir':{
|
2025-01-09 12:14:26 +01:00
|
|
|
const {obj} = getPath( args[1] )
|
2024-12-30 09:47:23 +01:00
|
|
|
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':{
|
2025-01-09 12:14:26 +01:00
|
|
|
const opts = getPath( args[1] )
|
|
|
|
return getattr(args[1],{...opts, args});
|
2024-12-30 09:47:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'read':{
|
2025-01-09 12:14:26 +01:00
|
|
|
const {obj,propname} = getPath( args[1] )
|
|
|
|
return obj[propname];
|
2024-12-30 09:47:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the main function
|
|
|
|
return main(args.slice(1));
|
|
|
|
|
2025-01-09 12:14:26 +01:00
|
|
|
|