It’s a tricky challenge, especially if you want to also be able to handle curved developable surfaces, not just flat facets.
A couple of previous related discussions that might be helpful though: