Triplanar mapping from Local Space - problem when scaling. How to make it work?

Nice gimmick, could be quite useful but works ONLY with planes unfortunately.