diff --git a/README.md b/README.md index 59be8fd..b505853 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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') diff --git a/mesh_sequence_controller.py b/mesh_sequence_controller.py index a1e8bdb..1a31c42 100644 --- a/mesh_sequence_controller.py +++ b/mesh_sequence_controller.py @@ -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 @@ -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 @@ -617,4 +626,4 @@ def unregister(): bpy.types.INFO_MT_mesh_add.remove(menu_func) if __name__ == "__main__": - register() \ No newline at end of file + register()