- Home /
 
Is it possible to add blendshape animation through script?
Hi. I have been trying to add some animation to my blendshapes through a text document that is separated through commas. I have been able to read the lines and everything just fine. the only thing is that I can not reference the blendshapes on the skinned mesh.

So I guess my problem is that I am not able to reference to the correct mesh renderer. Or that it is the meta file that does not work.
Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;
 public class ReadLines : EditorWindow {
 
     
     public Object csvFile;
     public string text;
     public GameObject animobject;
     public AnimationClip anim_obj;
     public Keyframe[] ks;
     public string[] bs_name;
 
     [MenuItem("Window/Import Blendshapes")]
     public static void ShowWindow()
     {
         GetWindow<ReadLines>("Import Blendshapes");
     }
 
     void OnGUI()
     {
         GUILayout.Label("Insert text here.", EditorStyles.boldLabel);
         csvFile = EditorGUILayout.ObjectField(csvFile, typeof(TextAsset), true);
         anim_obj = EditorGUILayout.ObjectField("Animation", anim_obj, typeof(AnimationClip), true) as AnimationClip;
         animobject = EditorGUILayout.ObjectField("Mesh to get blendshapes", animobject, typeof(GameObject), true) as GameObject;
         AnimationClip anim = anim_obj;
        
         if(GUILayout.Button("Read Lines"))
         {
             AnimationCurve curve;
             AnimationClip clip = anim;
             clip.legacy = false;
             text = csvFile.ToString();
             string[] lines = text.Split("\n"[0]);
             bs_name = new string[lines.Length];
             ks = new Keyframe[lines.Length];
             int y = 0;
             
             foreach (var i in lines)
             {
                 string[] parts = i.Split(","[0]);
                 foreach(var x in parts)
                 {
                     //Debug.Log(parts[1]);
                     //Debug.Log(parts[2]);
                     //Debug.Log(parts[3]);
                     float kf = float.Parse(parts[0]);
                     
                     string timestamp = parts[1];
                     
                     bs_name[y] = "Blend Shape." + parts[2];
                     
                     float bs_amount = float.Parse(parts[3]);
                     
                     ks[y] = new Keyframe(kf, bs_amount);
                     
                     
                 }
                 y++;
             }
             curve = new AnimationCurve(ks);
             
             foreach (string bs in bs_name)
             {
                 
                 clip.SetCurve(animobject.name, typeof(SkinnedMeshRenderer), bs, curve);
             }
             
         }
         
     }
 
 }
 
              https://docs.unity3d.com/$$anonymous$$anual/BlendShapes.html
Did you read this page?
yes. But i do not need to set the value in runtime. I need to set the animation curve of a keyframe in the animation clip through an editor script. And the animation clip does not find my blendshape. it says it is missing.
Answer by emilche123 · Feb 05, 2018 at 12:26 PM
This has been solved. The problem was the "Blend Shape." reference. It has to be "blendShape."
Answer by huanzhang · Sep 14, 2018 at 02:40 AM
I want to know what documents you read. Can I see the contents?
Your answer
 
             Follow this Question
Related Questions
How to add Animation with C# 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Animations one by one 0 Answers
animation clip wont play 1 Answer