improve code when saving sdf into mesh