Unity Animation: Shape Blend\IK\Film Textures

Three animations that are not common but can greatly enhance the user's game experience:

①Shape blending based on deformation animation: such as lips and facial animation

②Inverse dynamics: that is, the positioning method of the character's hands and feet during the running period

③ Movie texture: Play the video file rendered in the pre-rendering stage as a texture on the 3D surface

1. Shape mix

Facial animation, including face changes and lip animation, usually requires the use of Blend Shape or deformation animation. This type of animation is usually done by designers or 3D software, and then imported into Unity, and Import BlendShapes is activated in the panel.

For the build process, morphing animations require two processing steps:

The designer defines the limit position of the panel mesh, that is, the vertices of all face meshes are positioned and arranged in a certain limit position, and a Shape Key or Blend Shape is created to record the mesh state of the corresponding pose.

By recording a series of different poses, a weighted average blend of the different poses can be generated to generate the final facial animation, Animations.

2. Inverse dynamics

IK is supported in most 3D applications, but such data cannot usually be converted to Unity

All IK animations will be imported into Unity as Forward Kinematics (FK), which requires manual configuration of Unity's IK for data access

Mecanim Avatar system required to start IK \

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ArmIK : MonoBehaviour {
 
    public float leftHandPositionWeight;
    public float leftHandRotationWeight;
 
    public float rightHandPositionWeight;
    public float rightHandRotationWeight;
 
    public Transform leftHandObj;
    public Transform rightHandObj;
    private Animator animator; 
 
    // Use this for initialization
    void Start () {
        animator = GetComponent<Animator>();
 
	}
	
	// Update is called once per frame
	void Update () {
		
	}
 
    private void OnAnimatorIK(int layerIndex)
    {
        animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, leftHandPositionWeight);
        animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, leftHandRotationWeight);
        animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandObj.position);
        animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandObj.rotation);
 
        animator.SetIKPositionWeight(AvatarIKGoal.RightHand, rightHandPositionWeight);
        animator.SetIKRotationWeight(AvatarIKGoal.RightHand, rightHandRotationWeight);
        animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
        animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
    }
}

3. Film texture

Audio Source component, responsible for playing audio content in movies

Create a Material, for the shader type, select Unlit | Texture

Play the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent(typeof(AudioSource))]
 
public class PlayVideo1 : MonoBehaviour {
 
    public bool loop1 = true;
    public bool playFromStart1 = true;
    public MovieTexture video1;
    public AudioClip audioClip1;
    private AudioSource audio1;
 
	// Use this for initialization
	void Start () {
        audio1 = GetComponent<AudioSource>();
 
        if (!video1)
            video1 = GetComponent<Renderer>().material.mainTexture as MovieTexture;
        if (!audioClip1)
            audioClip1 = audio1.clip;
 
        video1.Stop();
        audio1.Stop();
        video1.loop = loop1;
        audio1.loop = loop1;
 
        if (playFromStart1)
            ControlMovie1();
		
	}
 
    private void OnMouseUp()
    {
        ControlMovie1();
    }
 
    public void ControlMovie1()
    {
        if (video1.isPlaying)
        { 
             video1.Pause();
             audio1.Pause();
        }
        else {
            video1.Play();
            audio1.Play();
        }
    }
    // Update is called once per frame
    void Update () {
		
	}
}

 Model Animation Basics: Unity Quick Start Part 4 - Unity Model Animation Related - Programmer Sought

https://blog.csdn.net/Dylan_Day/article/details/80589765

Guess you like

Origin blog.csdn.net/qq_42672770/article/details/123888843