Skip to content

Commit

Permalink
converter: Add option to save animations to separate files
Browse files Browse the repository at this point in the history
This is can be accessed via the CLI using `--animations separate`
  • Loading branch information
Moguri committed Oct 14, 2020
1 parent f5570ee commit 585275a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
12 changes: 12 additions & 0 deletions gltf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ def main():
help='convert imported PBR materials to legacy materials'
)

parser.add_argument(
'--animations',
choices=[
'embed',
'separate',
'skip',
],
default='embed',
help='control what to do with animation data'
)

args = parser.parse_args()

settings = gltf.GltfSettings(
Expand All @@ -71,6 +82,7 @@ def main():
no_srgb=args.no_srgb,
textures=args.textures,
legacy_materials=args.legacy_materials,
animations=args.animations
)

gltf.converter.convert(args.src, args.dst, settings)
Expand Down
22 changes: 17 additions & 5 deletions gltf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'no_srgb',
'textures',
'legacy_materials',
'animations',
))
GltfSettings.__new__.__defaults__ = (
'builtin', # physics engine
Expand All @@ -44,6 +45,7 @@
False, # do not load textures as sRGB
'ref', # reference external textures
False, # use PBR materials
'embed', # keep animations in the same BAM file
)


Expand Down Expand Up @@ -1054,11 +1056,14 @@ def build_character(self, char, nodeid, jvtmap, cvsmap, gltf_data, recurse=True)

# Find animations that affect the collected nodes.
#print("Looking for actions for", skinname, node_ids)
anims = [
(animid, anim)
for animid, anim in enumerate(gltf_data.get('animations', []))
if affected_nodeids & {chan['target']['node'] for chan in anim['channels']}
]
if self.settings.animations != 'skip':
anims = [
(animid, anim)
for animid, anim in enumerate(gltf_data.get('animations', []))
if affected_nodeids & {chan['target']['node'] for chan in anim['channels']}
]
else:
anims = []

for animid, gltf_anim in anims:
anim_name = gltf_anim.get('name', 'anim'+str(animid))
Expand Down Expand Up @@ -1711,6 +1716,13 @@ def convert(src, dst, settings=None):
if settings.print_scene:
converter.active_scene.ls()

if settings.animations == 'separate':
for bundlenode in converter.active_scene.find_all_matches('**/+AnimBundleNode'):
anim_name = bundlenode.node().bundle.name
anim_dst = dst.get_fullpath_wo_extension() \
+ f'_{anim_name}.' \
+ dst.get_extension()
bundlenode.write_bam_file(anim_dst)
converter.active_scene.write_bam_file(dst)


Expand Down

0 comments on commit 585275a

Please sign in to comment.