Hi everyone,
I created a “game” where the user is able to control the expression (face) of the character. when he wants to save the current expression, I need to save it into an animation clip so that the user will be able to see the resulting animation of interpolating between the poses he created.
I have three lists to store info of bones of a model. these are string, vector3 and quaternion, that store the name, position and rotation (respectively) of each bone.
my idea is to (when after the second expression ( and thereafter) is saved) create an animation clip that consists on the interpolation between the previous pose and the current pose. This will allow me to just play the clips one after the other when the “play” button is pressed.
This is the code to create the animation clips:
public void addAnimation(){
//you can ignore all this "litter", skip to the last comment :)
if(linkToLogic.framesSketched.Count >= 2){
AnimationClip clip = new AnimationClip();
int lastAnim = linkToLogic.framesSketched.Count -1;
//For every bone, create a clip with its' rotation and position
for(int i = 0; i< linkToLogic.framesSketched[lastAnim-1].posePos.Count -1; i++){
string _bone_name = linkToLogic.framesSketched[lastAnim-1].name[i];
Vector3 _pos_from = linkToLogic.framesSketched[lastAnim-1].posePos[i];
Quaternion _rot_from = linkToLogic.framesSketched[lastAnim-1].poseRot[i];
Vector3 _pos_to = linkToLogic.framesSketched[lastAnim].posePos[i];
Quaternion _rot_to = linkToLogic.framesSketched[lastAnim].poseRot[i];
//this is the crucial part, what am I doing wrong?
clip.SetCurve(_bone_name, typeof(Transform), "m_localposition.x", AnimationCurve.Linear(0,_pos_from.x , 1, _pos_to.x));
clip.SetCurve(_bone_name, typeof(Transform), "m_localposition.y", AnimationCurve.Linear(0,_pos_from.y , 1, _pos_to.y));
clip.SetCurve(_bone_name, typeof(Transform), "m_localposition.z", AnimationCurve.Linear(0,_pos_from.z , 1, _pos_to.z));
clip.SetCurve(_bone_name, typeof(Transform), "m_localRotation.z", AnimationCurve.Linear(0,_rot_from.z , 1, _rot_to.z));
clip.SetCurve(_bone_name, typeof(Transform), "m_localRotation.y", AnimationCurve.Linear(0,_rot_from.y , 1, _rot_to.y));
clip.SetCurve(_bone_name, typeof(Transform), "m_localRotation.x", AnimationCurve.Linear(0,_rot_from.x , 1, _rot_to.x));
clip.SetCurve(_bone_name, typeof(Transform), "m_localRotation.w", AnimationCurve.Linear(0,_rot_from.w , 1, _rot_to.w));
}
animation.AddClip(clip, numAnims.ToString());
numAnims++;
}
when i debug the script, I see that there are no clips in the animation, although animation.AddClip(clip, numAnims.ToString()); is called.
The bones have, of course, an hierarchy. When i try to add manually an animation to a specific bone in the hierarchy, Unity asks me to create a new animation for each bone i try to animate. Is it not possible to create a single AnimationClip to animate multiple bones?
I’ve been searching for a while and I can’t find anything related to this problem :
Thanks
edit: ok one problem is im not setting the path to the object. but that doesnt fix it
clip.SetCurve(__bonePath(_bone_name)…