// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.profile.ProfileBakedBodyMesh
using UnityEngine;

public class ProfileBakedBodyMesh
{
    public SkinnedMeshRenderer smr;

    public Mesh bakedMesh;

    public Vector3[] worldVertices;

    public BoneWeight[] boneWeights
    {
        get
        {
            if (!(this.smr != null))
            {
                return null;
            }
            return this.smr.sharedMesh.boneWeights;
        }
    }

    public Transform[] bones
    {
        get
        {
            if (!(this.smr != null))
            {
                return null;
            }
            return this.smr.bones;
        }
    }

    public ProfileBakedBodyMesh(SkinnedMeshRenderer _smr)
    {
        if (_smr == null)
        {
            Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " is null");
        }
        this.smr = _smr;
        if (_smr.sharedMesh == null)
        {
            Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] BakeBodyMesh Init : SkinnedMeshRenderer " + _smr.gameObject.name + " has null sharedMesh.");
        }
        this.bakedMesh = new Mesh();
        this.smr.BakeMesh(this.bakedMesh);
        this.worldVertices = this.CalculateWorldVertices(this.smr, this.bakedMesh);
    }

    public void ReBakeMesh()
    {
        this.smr.BakeMesh(this.bakedMesh);
        this.worldVertices = this.CalculateWorldVertices(this.smr, this.bakedMesh);
    }

    ~ProfileBakedBodyMesh()
    {
        this.smr = null;
        this.bakedMesh = null;
    }

    private Vector3[] CalculateWorldVertices(SkinnedMeshRenderer smr, Mesh bakedMesh)
    {
        if (smr == null)
        {
            Debug.LogError("[ProfileUtil - ProfileBakedBodyMesh] CalculateWorldVertices: smr " + smr.gameObject.name + " == null");
            return 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;
    }
}
