mirror of
				https://github.com/maxartz15/VertexAnimation.git
				synced 2025-11-04 02:15:59 +01:00 
			
		
		
		
	Interpolation
Smooth animations :)
This commit is contained in:
		@@ -15,8 +15,7 @@ namespace TAO.VertexAnimation
 | 
			
		||||
	public struct VA_AnimatorComponent : IComponentData
 | 
			
		||||
	{
 | 
			
		||||
		public int animationIndex;
 | 
			
		||||
		// TODO: Animation blending.
 | 
			
		||||
		//public int animationIndexSchedule;
 | 
			
		||||
		public int animationIndexNext;
 | 
			
		||||
		public float animationTime;
 | 
			
		||||
		public BlobAssetReference<VA_AnimationLibraryData> animationLibrary;
 | 
			
		||||
	}
 | 
			
		||||
@@ -38,7 +37,7 @@ namespace TAO.VertexAnimation
 | 
			
		||||
				VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
 | 
			
		||||
				{
 | 
			
		||||
					animationIndex = 0,
 | 
			
		||||
					//animationIndexSchedule = -1,
 | 
			
		||||
					animationIndexNext = -1,
 | 
			
		||||
					animationTime = 0,
 | 
			
		||||
					animationLibrary = animLib
 | 
			
		||||
				};
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using Unity.Entities;
 | 
			
		||||
using Unity.Transforms;
 | 
			
		||||
using Unity.Mathematics;
 | 
			
		||||
using UnityEngine.Animations;
 | 
			
		||||
 | 
			
		||||
namespace TAO.VertexAnimation
 | 
			
		||||
{
 | 
			
		||||
@@ -21,14 +22,31 @@ namespace TAO.VertexAnimation
 | 
			
		||||
					// Get the animation lib data.
 | 
			
		||||
					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
 | 
			
		||||
					{
 | 
			
		||||
						Value = new float4
 | 
			
		||||
						{
 | 
			
		||||
							x = ac.animationTime,
 | 
			
		||||
							y = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, ac.animationIndex),
 | 
			
		||||
							z = VA_AnimationLibraryUtils.GetColorMapIndex(ref animationsRef, ac.animationIndex),
 | 
			
		||||
							w = 0
 | 
			
		||||
							z = animationTimeNext,
 | 
			
		||||
							w = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, animationIndexNext)
 | 
			
		||||
						}
 | 
			
		||||
					};
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user