Skip to content

Instantly share code, notes, and snippets.

@exelotl
Created March 12, 2020 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save exelotl/9bb34717e9d67ae608ac0b510f4e3079 to your computer and use it in GitHub Desktop.
Save exelotl/9bb34717e9d67ae608ac0b510f4e3079 to your computer and use it in GitHub Desktop.
Remove materials, textures and images from GLTF files
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)
@marcio121
Copy link

Como usar isso

@exelotl
Copy link
Author

exelotl commented Mar 19, 2023

  1. Install Nim: https://nim-lang.org/
  2. Install docopt dependency: nimble install docopt
  3. Compile: nim c gltfstrip.nim
  4. Run ./gltfstrip file1 file2 file3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment