mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-11-12 15:35:30 +01:00
Apply root motion option.
Added option to apply root motion.
This commit is contained in:
parent
468d1472c2
commit
1c9ab36bd8
@ -28,6 +28,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("model"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("applyRootMotion"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("fps"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("textureWidth"));
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
// Input.
|
||||
public GameObject model;
|
||||
public AnimationClip[] animationClips;
|
||||
public bool applyRootMotion = false;
|
||||
[Range(1, 60)]
|
||||
public int fps = 24;
|
||||
public int textureWidth = 512;
|
||||
@ -97,7 +98,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
target.name = model.name;
|
||||
|
||||
target.ConbineAndConvertGameObject();
|
||||
AnimationBaker.BakedData bakedData = target.Bake(animationClips, fps, textureWidth);
|
||||
AnimationBaker.BakedData bakedData = target.Bake(animationClips, applyRootMotion, fps, textureWidth);
|
||||
|
||||
positionMap = VA_Texture2DArrayUtils.CreateTextureArray(bakedData.positionMaps.ToArray(), false, true, TextureWrapMode.Repeat, FilterMode.Point, 1, string.Format("{0}_PositionMap", name), true);
|
||||
meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings());
|
||||
|
@ -25,6 +25,7 @@ namespace TAO.VertexAnimation
|
||||
[System.Serializable]
|
||||
public struct AnimationInfo
|
||||
{
|
||||
public bool applyRootMotion;
|
||||
public int rawFrameHeight;
|
||||
public int frameHeight;
|
||||
public int frameSpacing;
|
||||
@ -35,8 +36,9 @@ namespace TAO.VertexAnimation
|
||||
public int fps;
|
||||
|
||||
// Create animation info and calculate values.
|
||||
public AnimationInfo(Mesh mesh, int frames, int textureWidth, int fps)
|
||||
public AnimationInfo(Mesh mesh, bool applyRootMotion, int frames, int textureWidth, int fps)
|
||||
{
|
||||
this.applyRootMotion = applyRootMotion;
|
||||
this.frames = frames;
|
||||
this.textureWidth = textureWidth;
|
||||
this.fps = fps;
|
||||
@ -51,7 +53,7 @@ namespace TAO.VertexAnimation
|
||||
}
|
||||
}
|
||||
|
||||
public static BakedData Bake(this GameObject model, AnimationClip[] animationClips, int fps, int textureWidth)
|
||||
public static BakedData Bake(this GameObject model, AnimationClip[] animationClips, bool applyRootMotion, int fps, int textureWidth)
|
||||
{
|
||||
BakedData bakedData = new BakedData()
|
||||
{
|
||||
@ -75,7 +77,7 @@ namespace TAO.VertexAnimation
|
||||
Mesh mesh = model.GetComponent<SkinnedMeshRenderer>().sharedMesh;
|
||||
|
||||
// Get the info for the biggest animation.
|
||||
AnimationInfo animationInfo = new AnimationInfo(mesh, maxFrames, textureWidth, fps);
|
||||
AnimationInfo animationInfo = new AnimationInfo(mesh, applyRootMotion, maxFrames, textureWidth, fps);
|
||||
|
||||
foreach (AnimationClip ac in animationClips)
|
||||
{
|
||||
@ -98,6 +100,12 @@ namespace TAO.VertexAnimation
|
||||
name = string.Format("{0}", model.name)
|
||||
};
|
||||
|
||||
// Set root motion options.
|
||||
if (model.TryGetComponent(out Animator animator))
|
||||
{
|
||||
animator.applyRootMotion = animationInfo.applyRootMotion;
|
||||
}
|
||||
|
||||
// Bake mesh for a copy and to apply the new UV's to.
|
||||
SkinnedMeshRenderer skinnedMeshRenderer = model.GetComponent<SkinnedMeshRenderer>();
|
||||
skinnedMeshRenderer.BakeMesh(mesh);
|
||||
|
Loading…
Reference in New Issue
Block a user