Browse Source

Add scripts to convert .blend to glT

Goodbye Makefile, hello tup!
master
Fabien Freling 4 years ago
parent
commit
1ce9621ec6
  1. 0
      Tupfile.ini
  2. 3
      models/Tupfile
  3. 39
      scripts/bpy/blend2glb.py
  4. 41
      scripts/bpy/blend2gltf.py

0
Tupfile.ini

3
models/Tupfile

@ -0,0 +1,3 @@
MODELS = hedgehog.blend \
flag.blend
: foreach $(MODELS) |> blender %f --background --python ../scripts/bpy/blend2glb.py -- --output %o > /dev/null |> %B.glb

39
scripts/bpy/blend2glb.py

@ -0,0 +1,39 @@
import sys
import os
import argparse
import bpy
# get all args after "--"
argv = sys.argv
argv = argv[argv.index("--") + 1:]
parser = argparse.ArgumentParser()
parser.add_argument('-o','--output')
args = parser.parse_args(argv)
basedir = os.path.dirname(args.output)
if basedir is not '':
os.makedirs(basedir, exist_ok=True)
# You can read the documentation at:
# https://github.com/KhronosGroup/glTF-Blender-Exporter/blob/master/docs/user.md
bpy.ops.export_scene.glb(filepath=args.output,
# Embedding
export_copyright="Zenly",
# Nodes
export_selected=False,
export_layers=True,
export_extras=True,
# Mesh
export_apply=True,
# Attributes
export_texcoords=True,
export_normals=True,
export_tangents=True,
export_colors=True,
# Objects
export_materials=True,
export_cameras=True,
export_camera_infinite=False,
# Animation
export_animations=True)

41
scripts/bpy/blend2gltf.py

@ -0,0 +1,41 @@
import sys
import os
import argparse
import bpy
# get all args after "--"
argv = sys.argv
argv = argv[argv.index("--") + 1:]
parser = argparse.ArgumentParser()
parser.add_argument('-o','--output')
args = parser.parse_args(argv)
basedir = os.path.dirname(args.output)
os.makedirs(basedir, exist_ok=True)
# You can read the documentation at:
# https://github.com/KhronosGroup/glTF-Blender-Exporter/blob/master/docs/user.md
bpy.ops.export_scene.gltf(filepath=args.output,
# Embedding
export_copyright="Zenly",
export_embed_buffers=False, # leave binary data in .bin
export_embed_images=False,
export_strip=False, # JSON not striped
# Nodes
export_selected=False,
export_layers=True,
export_extras=True,
# Mesh
export_apply=False,
# Attributes
export_texcoords=True,
export_normals=True,
export_tangents=True,
export_colors=True,
# Objects
export_materials=True,
export_cameras=True,
export_camera_infinite=False,
# Animation
export_animations=True)
Loading…
Cancel
Save