skybrush-io / studio-blender

Skybrush Studio for Blender - a Blender addon for designing and validating drone shows
https://skybrush.io
GNU General Public License v3.0
40 stars 27 forks source link

Unused constraint F-curves sometimes remain in the drone animation data #8

Open ntamas opened 1 year ago

ntamas commented 1 year ago

While investigating one of the Blender project files sent to us in private, I've found several F-curves in the animation data of drones where the target data path of the F-curve does not exist any more. I think this happens when formations are removed from the project after the user has already created transitions from them.

The easiest way to detect these stale F-curves (which appear with a red outline in the Dope Sheet) is with scripting. Assume that drone is a drone object:

action = drone.animation_data.action
for fcurve in action.fcurves:
    try:
        drone.path_resolve(fcurve.data_path)
    except ValueError:
        print(f"{fcurve.data_path} is invalid")

These should be cleaned up regularly. We should probably also filter in data paths whose name matches /constraints["Skybrush.Entry.*"].influence/ to avoid deleting something that we did not create ourselves.

ntamas commented 1 year ago

Finding all occurrences of constraints.remove in our codebase gives us all locations where we ever remove a constraint. We should cater for the removals of stale F-curves near these places, but when we are deleting many constraints in a loop, it's best to leave the cleanup to after the end of the loop.