Created
January 29, 2021 22:37
-
-
Save serverhiccups/0a476a78b321fceb9dd487a9dd2b93ed to your computer and use it in GitHub Desktop.
Extract geometry from a .obj file into a format suitable for Scratch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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