Optimize and unify mesh processing (#7851)