bugfix: now works with non-rect, 3D with flattening