Skip to content

Commit

Permalink
Sort filenames in natural numerical order (#15)
Browse files Browse the repository at this point in the history
* sort in numerical order

* improve efficiency and code style

* update README

* Update README.md
  • Loading branch information
xchern authored and neverhood311 committed Mar 29, 2019
1 parent 6ada248 commit 82bb824
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Bitcoin wallet: 16Bbv5jmKJ2T3dqw2rbaiL6vsoZvyNvaU1
PayPal: https://www.paypal.me/justinj

### IMPORTANT
- File numbers must be zero-padded
- Like this: file001, file002, file003
- NOT like this: ~~file1, file2, file3~~
- You MUST restart Blender after enabling the add-on

### Features
Expand All @@ -29,7 +26,9 @@ PayPal: https://www.paypal.me/justinj

### Limitations
- Only absolute filepaths are supported (for now)
- File numbers must be zero-padded
- ~~File numbers must be zero-padded~~
- Sorting file with correct order is added in [this PR](https://github.com/neverhood311/Stop-motion-OBJ/pull/15)
- Files like file1, file2, file3 will be loaded in correct order, and zero-padded filenames still work, too.
- No motion blur
- ~~Doesn't work with physics~~
- (It actually works with rigid body physics. In Rigid Body Collisions set Shape to 'Mesh' and Source to 'Base')
Expand Down
13 changes: 11 additions & 2 deletions mesh_sequence_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@

import bpy
import os
import re
import glob
from bpy.app.handlers import persistent

def alphanumKey(string):
""" Turn a string into a list of string and number chunks.
"z23a" -> ["z", 23, "a"]
"""
return [int(c) if c.isdigit() else c for c in re.split('([0-9]+)', string)]

#global variable for the MeshSequenceController
MSC = None

Expand Down Expand Up @@ -165,7 +172,9 @@ def loadSequenceFromFile(self, _obj, _dir, _file):
print(full_filepath)
numFrames = 0
unsortedFiles = glob.glob(full_filepath)
sortedFiles = sorted(unsortedFiles)
# Sort the given list in the way that humans expect.
sortedFiles = sorted(unsortedFiles, key=alphanumKey)

#for each file that matches the glob query:
for file in sortedFiles:
#import the mesh file
Expand Down Expand Up @@ -617,4 +626,4 @@ def unregister():
bpy.types.INFO_MT_mesh_add.remove(menu_func)

if __name__ == "__main__":
register()
register()

0 comments on commit 82bb824

Please sign in to comment.