Created
March 12, 2020 14:49
-
-
Save exelotl/9bb34717e9d67ae608ac0b510f4e3079 to your computer and use it in GitHub Desktop.
Remove materials, textures and images from GLTF files
This file contains 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
import docopt | |
import json | |
let doc = """ | |
gltfstrip | |
Remove materials, textures and images from GLTF files | |
Usage: | |
gltfstrip [-b] <file>... | |
gltfstrip (-h | --help) | |
Options: | |
-h --help Show this screen. | |
-b --buffers Also remove meshes, accessors and buffers | |
""" | |
let args = docopt(doc) | |
var files = @(args["<file>"]) | |
proc gltfstrip(input: string): string | |
for f in files: | |
let str = readFile(f) | |
let res = gltfstrip(str) | |
writeFile(f, res) | |
echo "stripped " & f | |
proc gltfstrip(input:string): string = | |
var json = parseJson(input) | |
template safeDelete(j, k) = | |
if j.hasKey(k): | |
j.delete(k) | |
if json.hasKey("meshes"): | |
for mesh in json["meshes"]: | |
for primitive in mesh["primitives"]: | |
primitive.safeDelete("material") | |
json.safeDelete("textures") | |
json.safeDelete("images") | |
if args["--buffers"]: | |
if json.hasKey("nodes"): | |
for node in json["nodes"]: | |
node.safeDelete("mesh") | |
json.safeDelete("meshes") | |
json.safeDelete("accessors") | |
json.safeDelete("bufferViews") | |
json.safeDelete("buffers") | |
pretty(json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nimble install docopt
nim c gltfstrip.nim
./gltfstrip file1 file2 file3