Exemplo n.º 1
0
    /// <summary>
    /// Initialize
    /// </summary>
    public void Awake()
    {
        // build the hashtable of targets
        foreach (BlendShape.Target t in targets)
        {
            _targetsByName.Add(t.name, t);
        }

        // acquire the _outMesh based on the type of renderer
        bool isSkin = renderer.GetType() == typeof(SkinnedMeshRenderer);

        if (_outMesh == null)
        {
            if (isSkin)
            {
                _outMesh = (meshRenderer as SkinnedMeshRenderer).sharedMesh;
            }
            else
            {
                _outMesh = GetComponent <MeshFilter>().mesh;
            }
        }

        // duplicate _outMesh to avoid modifying source asset
        _outMesh = MeshHelpers.DuplicateMesh(_outMesh, string.Format("{0} (Duplicate)", _outMesh.name));
        if (isSkin)
        {
            (meshRenderer as SkinnedMeshRenderer).sharedMesh = _outMesh;
        }
        else
        {
            GetComponent <MeshFilter>().mesh = _outMesh;
        }
        // duplicate seamlessBaseMesh to avoid modifying source asset
        seamlessBaseMesh = MeshHelpers.DuplicateMesh(seamlessBaseMesh, string.Format("{0} (Duplicate)", seamlessBaseMesh.name));

        // store necessary vertex and normal arrays
        _defaultNormals   = _outMesh.normals;
        _seamlessNormals  = seamlessBaseMesh.normals;
        _seamlessVertices = seamlessBaseMesh.vertices;
        _outNormals       = _outMesh.normals;
        _outVertices      = _outMesh.vertices;
    }