pythonanimationmathnuke

a lil bit of programming math


Just wondering if anyone can help me with a little programming math i'm having trouble with.

What I am trying to create is a submit script (using python and .bat) for Nuke (vfx). The issue I am having is I can't figure out how to add the remainder of frames to the already calculated stack.

To be more clear...

In Nuke, i have to render 20 frames. I have 16 threads. Nuke only uses 1 thread. I want to write a script that takes the number of frames and divide it by the number of threads and write out a bat file using python. The issue come is when I have a remainder. I want to take the remainder and apply it back in the render stack.

example (first loop)

thread1 = 1 frame
thread2 = 1 frame
thread3 = 1 frame
thread4 = 1 frame
thread5 = 1 frame
thread6 = 1 frame
...
thread16 = 1 frame

Once it has done this...the remainder is 4. I want the remainder to be distributed among the threads. so...

example (second loops)

thread1 = 2 frame
thread2 = 2 frame
thread3 = 2 frame
thread4 = 2 frame
thread5 = 1 frame
thread6 = 1 frame
...
thread16 = 1 frame

the 4 gets added among the first few threads totalling 20 frames.

I will greatly appreciate any help, tips, comments that anyone has to offer. :)

Thanks


Solution

  • frames can be a list of any object, eg dict or "Frame" object. Here I have just used ints

    >>> frames = range(20)
    >>> threads = 16
    >>> [frames[x::threads] for x in range(threads)]
    [[0, 16], [1, 17], [2, 18], [3, 19], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15]]
    

    I think you may be better off putting the frames in a Queue though, since some frames may render faster than others