meshtool.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. let fs = require("fs");
  2. let path = require("path");
  3. function readFile(name) {
  4. var data = fs.readFileSync(name, 'utf-8');
  5. let obj = JSON.parse(data);
  6. delete obj.materials
  7. if (obj.meshes.length != 1) {
  8. console.error("================", name)
  9. return
  10. } else {
  11. console.log(name)
  12. }
  13. obj.meshes[0].name = "mesh"
  14. fs.writeFile(name, JSON.stringify(obj), function(err) {
  15. if (err) return console.error(err);
  16. });
  17. }
  18. function travel(dir, callback) {
  19. fs.readdirSync(dir).forEach(function(file) {
  20. var pathname = path.join(dir, file);
  21. if (fs.statSync(pathname).isDirectory()) {
  22. travel(pathname, callback);
  23. } else {
  24. callback(pathname);
  25. }
  26. });
  27. }
  28. names = []
  29. travel('assets/meshes', function(pathname) {
  30. if (pathname.endsWith(".gltf")) {
  31. readFile(pathname);
  32. // pathname = pathname.replace("assets\\meshes\\", "")
  33. // pathname = pathname.replace(".gltf", "")
  34. // names.push(pathname)
  35. }
  36. });
  37. console.log(JSON.stringify(names))