// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts,
// for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies.
// EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.WorldVertexUtil
using UnityEngine;

public class WorldVertexUtil
{
    public Vector3[] GetWorldVertices(SkinnedMeshRenderer smr)
    {
        Mesh bakedMesh = new Mesh();
        return this.GetWorldVertices(smr, ref bakedMesh);
    }

    public Vector3[] GetWorldVertices(SkinnedMeshRenderer smr, ref Mesh bakedMesh)
    {
        if (smr == null)
        {
            throw new AutoMorpherException("SkinnedMeshRenderer is Missing", "[SkinnedMeshWorldUtil] GetWorldVertices\n - smr is null");
        }
        if (bakedMesh == null)
        {
            bakedMesh = new Mesh();
        }
        else
        {
            bakedMesh.Clear();
        }
        smr.BakeMesh(bakedMesh);
        Transform transform = smr.transform;
        Vector3 lossyScale = transform.lossyScale;
        Vector3 vector = new Vector3(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f));
        Matrix4x4 matrix4x = transform.localToWorldMatrix * Matrix4x4.Scale(vector);
        Vector3[] vertices = bakedMesh.vertices;
        int num = vertices.Length;
        Vector3[] array = new Vector3[num];
        for (int i = 0; i < num; i++)
        {
            array[i] = matrix4x.MultiplyPoint3x4(vertices[i]);
        }
        return array;
    }

    public Vector3[] GetWorldVerticesWithBakedMesh(SkinnedMeshRenderer smr, Mesh bakedMesh)
    {
        if (smr == null)
        {
            throw new AutoMorpherException("SkinnedMeshRenderer is Missing", "[SkinnedMeshWorldUtil] GetWorldVerticesWithBakedMesh\n - smr is null");
        }
        if (bakedMesh == null)
        {
            return null;
        }
        Transform transform = smr.transform;
        Vector3 lossyScale = transform.lossyScale;
        Vector3 vector = new Vector3(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f));
        Matrix4x4 matrix4x = transform.localToWorldMatrix * Matrix4x4.Scale(vector);
        Vector3[] vertices = bakedMesh.vertices;
        int num = vertices.Length;
        Vector3[] array = new Vector3[num];
        for (int i = 0; i < num; i++)
        {
            array[i] = matrix4x.MultiplyPoint3x4(vertices[i]);
        }
        return array;
    }
}
