enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
243 stars 33 forks source link

LIVENODING 1286 / AN CODING NODING Natural Sort Order --- FLIPBOOK STOP MOTION #726

Open enzyme69 opened 4 years ago

enzyme69 commented 4 years ago

Collections Flipbook Animation ON and OFF using Animation Nodes.

Screen Shot 2020-03-20 at 1 20 09 pm

https://www.xormedia.com/natural-sort-order-with-zero-padding/

LOOOM_import_005.blend.zip

enzyme69 commented 4 years ago
import bpy
import sys

from sys import maxsize
import re

# optional '-' to support negative numbers
_num_re = re.compile(r'-?\d+')
# number of chars in the largest possible int
_maxint_digits = len(str(maxsize))
# format for zero padding positive integers
_zero_pad_int_fmt = '{{0:0{0}d}}'.format(_maxint_digits)
# / is 0 - 1, so that negative numbers will come before positive
_zero_pad_neg_int_fmt = '/{{0:0{0}d}}'.format(_maxint_digits)

def _zero_pad(match):
    n = int(match.group(0))
    # if n is negative, we'll use the negative format and flip the number using
    # maxint so that -2 comes before -1, ...
    return _zero_pad_int_fmt.format(n) \
        if n > -1 else _zero_pad_neg_int_fmt.format(n + maxint)

def zero_pad_numbers(s):
    return _num_re.sub(_zero_pad, s)

# unordered = ['f0.svg', 'f1.svg', 'f5.svg','f12.svg', 'f10.svg']
ordered = sorted(unordered, key=zero_pad_numbers)

print(ordered)
# ordered
#    ['file1.txt', 'file3.txt', 'file12.txt']
enzyme69 commented 4 years ago

Animation Nodes help trigger drivers ON and OFF frame of COLLECTIONS to make an animation.

Screen Shot 2020-03-21 at 8 58 01 am
foguetes commented 4 years ago

@enzyme69 I watched your youtube video about this. At 2:08 you mention a website, photop.com or something. I can't find it. Could you tell me what it is? Also, you don't explain how you import the SVG sequence into Blender. Did you import it one by one? Ever since I watched this presentation I wanted to the same in blender https://youtu.be/WvaZoOGHmzQ?t=590 In that case they used imported an .ai file sequence and converted it into an alembic file.

enzyme69 commented 3 years ago

@foguetes it's Photopea

And I believe I keep the sequence in Layers and each layer become a single object.