/// <summary>
        /// Reset the AutoUnwrapParameters of a set of faces to best match their current UV coordinates.
        /// </summary>
        /// <remarks>
        /// Auto UVs do not support distortion, so this conversion process cannot be loss-less. However as long as there
        /// is minimal skewing the results are usually very close.
        /// </remarks>
        internal static void SetAutoAndAlignUnwrapParamsToUVs(ProBuilderMesh mesh, IEnumerable <Face> facesToConvert)
        {
            var destinationTextures = mesh.textures.ToArray();
            var faces = facesToConvert as Face[] ?? facesToConvert.ToArray();

            foreach (var face in faces)
            {
                face.uv           = AutoUnwrapSettings.defaultAutoUnwrapSettings;
                face.elementGroup = -1;
                face.textureGroup = -1;
                face.manualUV     = false;
            }

            mesh.RefreshUV(faces);
            var unmodifiedProjection = mesh.texturesInternal;

            foreach (var face in faces)
            {
                var trs = CalculateDelta(unmodifiedProjection, face.indexesInternal, destinationTextures, face.indexesInternal);
                var uv  = face.uv;

                // offset is flipped for legacy reasons. people were confused that positive offsets moved the texture
                // in negative directions in the scene-view, but positive in UV window. if changed we would need to
                // write some way of upgrading the unwrap settings to account for this.
                uv.offset   = -trs.translation;
                uv.rotation = trs.rotation;
                uv.scale    = trs.scale;
                face.uv     = uv;
            }

            mesh.RefreshUV(faces);
        }
        // 2020/8/23 - scaled auto UV faces now have an offset applied to their projected coordinates so that they
        // remain static in UV space when the mesh geometry is modified
        internal static void UpgradeAutoUVScaleOffset(ProBuilderMesh mesh)
        {
            var original = mesh.textures.ToArray();

            mesh.RefreshUV(mesh.facesInternal);
            var textures = mesh.texturesInternal;

            foreach (var face in mesh.facesInternal)
            {
                if (face.manualUV)
                {
                    continue;
                }
                var utrs = CalculateDelta(original, face.indexesInternal, textures, face.indexesInternal);
                var auto = face.uv;
                auto.offset += utrs.translation;
                face.uv      = auto;
            }
        }