Skip to content

Instantly share code, notes, and snippets.

@serverhiccups
Created January 29, 2021 22:37
Show Gist options
  • Save serverhiccups/0a476a78b321fceb9dd487a9dd2b93ed to your computer and use it in GitHub Desktop.
Save serverhiccups/0a476a78b321fceb9dd487a9dd2b93ed to your computer and use it in GitHub Desktop.
Extract geometry from a .obj file into a format suitable for Scratch.
let fs = require("fs")
let filename = process.argv[2]
let obj = fs.readFileSync(filename).toString();
let v = obj.split("\n").filter((line) => {
return line.split(" ")[0] == "v"
}).map((line) => {
return line.split(" ");
})
let f = obj.split("\n").filter((line) => {
return line.split(" ")[0] == "f"
}).map((line) => {
return line.split(" ");
})
if(process.argv[3] == "v") {
v.map((line) => {
line.splice(0, 1);
line.map(point => console.log(point))
})
} else {
f.map((line) => {
line.splice(0, 1);
line.map((point) => {
console.log(point.split("/")[0])
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment