[Bf-committers] bpy.context.scene.frame_set(i) issue

Campbell Barton ideasman42 at gmail.com
Sat Jan 21 11:54:13 CET 2012


frame_set() updates all layers of the scene which I expect is the problem here,

there could be an optional argument to pass a layer list to
frame_set()  but this doesn't necessarily help if the current scene
layers are not setup efficiently.

looking into this you could update only the objects you want like this...

# objects to update
objects = bpy.context.selected_objects
scene = bpy.context.scene
start = scene.frame_start
end = scene.frame_end
for frame in range (start, end + 1):
    scene.frame_current = frame
    for obj in objects:
        obj.update_tag(refresh={'OBJECT'})  # 'DATA' too if you care
about geometry
    scene.update()
    '''
    .... all the magic that needs data for each frame ....
    '''


On Sat, Jan 21, 2012 at 7:56 PM, Bartek Skorupa
<bartekskorupa at bartekskorupa.com> wrote:
> 1. Take any scene that plays back 1 frame per second or so. (I can't
> upload any example now, but I'm sure everybody has such scene
> somewhere). Many objects (2000?, 3000?), constraints, shapekeys,
> armatures, curves etc.
> 2. No matter if the layers are active or not, no matter what the draw
> mode is etc - it is slow. I can place all of my obs in layer 2,
> activate only empty layer 1, and it doesn't influence the speed.
> 3. Even if frame_set() is as fast as playback - I'm not happy. 250
> frames - 1 frame per second = 250sec. = 4 minutes. Who wants to wait 4
> minutes?
>
> Bartek Skorupa
>
> www.bartekskorupa.com
>
>
> On 2012-01-21, at 00:58, Campbell Barton wrote:
>
>> Hi Bartek,
>>
>> Would you be able to upload a test scene which is unusably slow?
>> can't see why this would be any slower then playing back the animation
>> (if anything should be faster since it doesn't have to draw).
>>
>> On Sat, Jan 21, 2012 at 9:58 AM, Bartek Skorupa
>> <bartekskorupa at bartekskorupa.com> wrote:
>>> Hi,
>>>
>>> I'd like to draw your attention to frame_set(i) method.
>>> In many scripts we have to refresh the scene several times, sometimes
>>> we need to collect some data for every frame in the whole animation.
>>> In such cases the only way I know in blender's python is to set the
>>> frame using bpy.context.scene.frame_set(frame)
>>> Almost every exporter that base on baking the data and exporting them
>>> as "keyframe for every frame" use this kind of loop:
>>>
>>> start = bpy.context.scene.frame_start
>>> end = bpy.context.scene.frame_end
>>> for frame in range (start, end + 1):
>>>     bpy.context.scene.frame_set(frame)
>>>     '''
>>>     .... all the magic that needs data for each frame ....
>>>     '''
>>>
>>> My exporter to Adobe After Effects (io_export_after_effects.py) does
>>> exactly the same.
>>>
>>> The issue here is that setting the frame sometimes takes ages.
>>> I was once advised to use bpy.context.frame_current = frame
>>> Well... It's very fast, but doesn't do the trick. It sets the frame,
>>> but doesn't update the scene and in most cases - this is what we want
>>> - We want to have our scene refreshed for every frame.
>>>
>>> bpy.context.scene.frame_set(frame) method is so slow, that many
>>> exporters become almost useless or if not useless - very badly
>>> perceived because of their performance.
>>> The process of simple export to After Effects can sometimes take
>>> several minutes and this is definitely not the performance we are
>>> looking for.
>>> I looked through many existing exporters and they all use this
>>> method,
>>> so I suppose I'm not the only one facing "frame_set" speed issue.
>>> Does anyone know other method to achieve refreshing the scene for
>>> every frame, but not that slow?
>>>
>>> Isn't this performance a bug of some kind?
>>>
>>> I'd appreciate any help.
>>>
>>> Cheers,
>>> Bartek Skorupa
>>>
>>> www.bartekskorupa.com
>>>
>>> _______________________________________________
>>> Bf-committers mailing list
>>> Bf-committers at blender.org
>>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
>>
>>
>> --
>> - Campbell
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers



-- 
- Campbell


More information about the Bf-committers mailing list