Interpolation

Smooth animations :)
This commit is contained in:
max 2021-02-09 17:21:42 +01:00
parent c928f6daae
commit f7fc4434d5
6 changed files with 2898 additions and 599 deletions

View File

@ -45,6 +45,9 @@ namespace TAO.VertexAnimation.Editor
EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent("")); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent(""));
} }
EditorGUILayout.PropertyField(serializedObject.FindProperty("useNormalA"), new GUIContent("Use Normal (A)"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("useInterpolation"));
if (GUILayout.Button("Bake", GUILayout.Height(32))) if (GUILayout.Button("Bake", GUILayout.Height(32)))
{ {
modelBaker.Bake(); modelBaker.Bake();

View File

@ -22,6 +22,8 @@ namespace TAO.VertexAnimation.Editor
public bool generateAnimationBook = true; public bool generateAnimationBook = true;
public bool generatePrefab = true; public bool generatePrefab = true;
public Shader materialShader = null; public Shader materialShader = null;
public bool useInterpolation = true;
public bool useNormalA = true;
// Output. // Output.
public GameObject prefab = null; public GameObject prefab = null;
@ -153,6 +155,24 @@ namespace TAO.VertexAnimation.Editor
material.SetTexture("_PositionMap", positionMap); material.SetTexture("_PositionMap", positionMap);
material.SetInt("_MaxFrames", bakedData.maxFrames); material.SetInt("_MaxFrames", bakedData.maxFrames);
if (useNormalA)
{
material.EnableKeyword("USE_NORMALA_ON");
}
else
{
material.DisableKeyword("USE_NORMALA_ON");
}
if(useInterpolation)
{
material.EnableKeyword("USE_INTERPOLATION_ON");
}
else
{
material.DisableKeyword("USE_INTERPOLATION_ON");
}
// Generate Prefab // Generate Prefab
prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings()); prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings());
} }

View File

@ -15,8 +15,7 @@ namespace TAO.VertexAnimation
public struct VA_AnimatorComponent : IComponentData public struct VA_AnimatorComponent : IComponentData
{ {
public int animationIndex; public int animationIndex;
// TODO: Animation blending. public int animationIndexNext;
//public int animationIndexSchedule;
public float animationTime; public float animationTime;
public BlobAssetReference<VA_AnimationLibraryData> animationLibrary; public BlobAssetReference<VA_AnimationLibraryData> animationLibrary;
} }
@ -38,7 +37,7 @@ namespace TAO.VertexAnimation
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
{ {
animationIndex = 0, animationIndex = 0,
//animationIndexSchedule = -1, animationIndexNext = -1,
animationTime = 0, animationTime = 0,
animationLibrary = animLib animationLibrary = animLib
}; };

View File

@ -1,6 +1,7 @@
using Unity.Entities; using Unity.Entities;
using Unity.Transforms; using Unity.Transforms;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine.Animations;
namespace TAO.VertexAnimation namespace TAO.VertexAnimation
{ {
@ -21,14 +22,31 @@ namespace TAO.VertexAnimation
// Get the animation lib data. // Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value; ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;
// Lerp animations.
// Set animation for lerp.
int animationIndexNext = ac.animationIndexNext;
if (ac.animationIndexNext < 0)
{
animationIndexNext = ac.animationIndex;
}
// Calculate next frame time for lerp.
float animationTimeNext = ac.animationTime + (1.0f / animationsRef.animations[animationIndexNext].maxFrames);
if (animationTimeNext > animationsRef.animations[animationIndexNext].duration)
{
// Set time. Using the difference to smooth out animations when looping.
animationTimeNext -= ac.animationTime;
}
// Set material data.
animationData[child] = new VA_AnimationDataComponent animationData[child] = new VA_AnimationDataComponent
{ {
Value = new float4 Value = new float4
{ {
x = ac.animationTime, x = ac.animationTime,
y = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, ac.animationIndex), y = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, ac.animationIndex),
z = VA_AnimationLibraryUtils.GetColorMapIndex(ref animationsRef, ac.animationIndex), z = animationTimeNext,
w = 0 w = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, animationIndexNext)
} }
}; };
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc1ccacb918e10a43bc1d707ec935205
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: