Skip to content

280: Remove heavy use of frame_set #569

@tngreene

Description

@tngreene

One of the largest current time sucks in the exporter is the stupidly inefficient use of bpy.context.scene.frame_set(frame=self.frame) inside XPlaneKeyframe's constructor. In order to get the location/rotation at each Blender Keyframe we currently do:

for every animated object,
    go through each frame of it's action that has a keyframe,
    call frame_set
    get the location and rotation
    and (removed by PR #465) set the frame back (which is useless)

With the BD-5J, this is currently taking 7 to 10 seconds on my computer repeatedly setting the current frame to frames 1-10!

It would be far better to call frame_set only 1-10 times instead thousands, using this simple algorithm:

  1. Before collectionAnimations is called on each bone, find every frame referenced by every Action block in the scene
  2. Make a Dict[BlenderObjectInTree,List[Tuple[FrameIndex, LocRotAnimationData]]]
  3. Visit each frame once, and fill the dictionary with all the values you would need to find were you searching per frame per object like we currently do
  4. Search that dictionary inside collectAnimations, instead of calling frame_set a billion times

This would be a massive performance boost for any project that uses lots of keyframes.

See #462 for more discussion about where this idea came from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementOptimizationBugs that are related to unoptimized or slow codegood first issueBugs in one or two easy plces that can be fixed quicklypriority high

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions