Original patch by Guillaume, modifications by Brecht. Differential Revision: https://developer.blender.org/D3102