Added basic blending and refactored some files

This commit is contained in:
Maximilian Winter 2022-12-10 15:02:53 +01:00
parent ee0fa7a5fa
commit 9f8a7fb7d8
43 changed files with 13583 additions and 345 deletions

View File

@ -3,14 +3,14 @@ using UnityEditor;
namespace TAO.VertexAnimation.Editor
{
[CustomEditor(typeof(VA_AnimationBook))]
public class VA_AnimationBookEditor : UnityEditor.Editor
[CustomEditor(typeof(AnimationBook))]
public class AnimationBookEditor : UnityEditor.Editor
{
private VA_AnimationBook animationBook = null;
private AnimationBook animationBook = null;
void OnEnable()
{
animationBook = target as VA_AnimationBook;
animationBook = target as AnimationBook;
}
public override void OnInspectorGUI()

View File

@ -3,14 +3,14 @@ using UnityEditor;
namespace TAO.VertexAnimation.Editor
{
[CustomEditor(typeof(VA_AnimationLibrary))]
public class VA_AnimationLibraryEditor : UnityEditor.Editor
[CustomEditor(typeof(AnimationLibrary))]
public class AnimationLibraryEditor : UnityEditor.Editor
{
private VA_AnimationLibrary library = null;
private AnimationLibrary library = null;
void OnEnable()
{
library = target as VA_AnimationLibrary;
library = target as AnimationLibrary;
}
public override void OnInspectorGUI()

View File

@ -20,9 +20,9 @@ namespace TAO.VertexAnimation.Editor
parent.AddComponent<LODGroup>();
}
if (!parent.TryGetComponent(out VA_AnimationLibraryComponentAuthoring _))
if (!parent.TryGetComponent(out AnimationLibraryComponentAuthoring _))
{
parent.AddComponent<VA_AnimationLibraryComponentAuthoring>();
parent.AddComponent<AnimationLibraryComponentAuthoring>();
}
//if (!parent.TryGetComponent(out Unity.Entities.ConvertToEntity _))
@ -33,7 +33,7 @@ namespace TAO.VertexAnimation.Editor
else
{
// Create parent.
parent = new GameObject(name, typeof(LODGroup), typeof(VA_AnimationLibraryComponentAuthoring));
parent = new GameObject(name, typeof(LODGroup), typeof(AnimationLibraryComponentAuthoring));
}
// Create all LODs.
@ -65,13 +65,13 @@ namespace TAO.VertexAnimation.Editor
}
else
{
child = new GameObject(childName, typeof(MeshFilter), typeof(MeshRenderer), typeof(VA_AnimationDataComponentAuthoring));
child = new GameObject(childName, typeof(MeshFilter), typeof(MeshRenderer), typeof(AnimationDataComponentAuthoring));
}
}
if (!child.TryGetComponent(out VA_AnimationDataComponentAuthoring ad))
if (!child.TryGetComponent(out AnimationDataComponentAuthoring ad))
{
child.AddComponent<VA_AnimationDataComponentAuthoring>();
child.AddComponent<AnimationDataComponentAuthoring>();
}
if (child.TryGetComponent(out MeshFilter mf))

View File

@ -3,14 +3,14 @@ using UnityEditor;
namespace TAO.VertexAnimation.Editor
{
[CustomEditor(typeof(VA_ModelBaker))]
public class VA_ModelBakerEditor : UnityEditor.Editor
[CustomEditor(typeof(VertexAnimationModelBaker))]
public class VertexAnimationModelBakerEditor : UnityEditor.Editor
{
private VA_ModelBaker modelBaker = null;
private VertexAnimationModelBaker modelBaker = null;
void OnEnable()
{
modelBaker = target as VA_ModelBaker;
modelBaker = target as VertexAnimationModelBaker;
}
public override void OnInspectorGUI()

View File

@ -6,7 +6,7 @@ using UnityEngine.Experimental.Rendering;
namespace TAO.VertexAnimation.Editor
{
[CreateAssetMenu(fileName = "new ModelBaker", menuName = "TAO/VertexAnimation/ModelBaker", order = 400)]
public class VA_ModelBaker : ScriptableObject
public class VertexAnimationModelBaker : ScriptableObject
{
#if UNITY_EDITOR
// Input.
@ -31,8 +31,8 @@ namespace TAO.VertexAnimation.Editor
public Texture2DArray positionMap = null;
public Material material = null;
public Mesh[] meshes = null;
public VA_AnimationBook book = null;
public List<VA_Animation> animations = new List<VA_Animation>();
public AnimationBook book = null;
public List<Animation> animations = new List<Animation>();
[System.Serializable]
public class LODSettings
@ -100,7 +100,7 @@ namespace TAO.VertexAnimation.Editor
target.ConbineAndConvertGameObject(includeInactive);
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);
positionMap = 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());
DestroyImmediate(target);
@ -126,7 +126,9 @@ namespace TAO.VertexAnimation.Editor
}
meshes[i].Finalize();
AssetDatabase.AddObjectToAsset(meshes[i], this);
SerializedObject s = new SerializedObject(meshes[i]);
s.FindProperty("m_IsReadable").boolValue = true;
AssetDatabase.AddObjectToAsset(s.targetObject, this);
}
AssetDatabase.AddObjectToAsset(positionMap, this);
@ -179,12 +181,12 @@ namespace TAO.VertexAnimation.Editor
// Create book.
if (!book)
{
book = CreateInstance<VA_AnimationBook>();
book = CreateInstance<AnimationBook>();
}
book.name = string.Format("{0}_Book", name);
book.positionMap = positionMap;
book.animations = new List<VA_Animation>();
book.animations = new List<Animation>();
book.TryAddMaterial(material);
// Save book.
@ -207,13 +209,13 @@ namespace TAO.VertexAnimation.Editor
VA_AnimationData newData = new VA_AnimationData(animationName, info[i].frames, info[i].maxFrames, info[i].fps, i, -1);
// Either update existing animation or create a new one.
if (TryGetAnimationWithName(animationName, out VA_Animation animation))
if (TryGetAnimationWithName(animationName, out Animation animation))
{
animation.SetData(newData);
}
else
{
animation = CreateInstance<VA_Animation>();
animation = CreateInstance<Animation>();
animation.name = animationName;
animation.SetData(newData);
animations.Add(animation);
@ -229,7 +231,7 @@ namespace TAO.VertexAnimation.Editor
}
}
private bool TryGetAnimationWithName(string name, out VA_Animation animation)
private bool TryGetAnimationWithName(string name, out Animation animation)
{
foreach (var a in animations)
{
@ -269,7 +271,7 @@ namespace TAO.VertexAnimation.Editor
material = null;
meshes = null;
book = null;
animations = new List<VA_Animation>();
animations = new List<Animation>();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

View File

@ -33,9 +33,9 @@ public class AnimatedPrefabSpawner : MonoBehaviour
}
currentPosition = new Vector3( startPosition.x , currentPosition.y, currentPosition.z + Distance );
}
VA_AnimationLibraryComponentAuthoring[] vaAnimationLibraryComponentAuthorings = Parent.GetComponentsInChildren < VA_AnimationLibraryComponentAuthoring >();
AnimationLibraryComponentAuthoring[] vaAnimationLibraryComponentAuthorings = Parent.GetComponentsInChildren < AnimationLibraryComponentAuthoring >();
foreach ( VA_AnimationLibraryComponentAuthoring authoring in vaAnimationLibraryComponentAuthorings )
foreach ( AnimationLibraryComponentAuthoring authoring in vaAnimationLibraryComponentAuthorings )
{
var test = Guid.NewGuid().GetHashCode().ToString();
Debug.Log( test );

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
public class VA_Animation : ScriptableObject
public class Animation : ScriptableObject
{
public VA_AnimationData Data;

View File

@ -4,14 +4,14 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "TAO/VertexAnimation/AnimationBook", order = 400)]
public class VA_AnimationBook : ScriptableObject
public class AnimationBook : ScriptableObject
{
public VA_AnimationBook(Texture2DArray a_positionMap)
public AnimationBook(Texture2DArray a_positionMap)
{
positionMap = a_positionMap;
}
public VA_AnimationBook(Texture2DArray a_positionMap, List<VA_Animation> a_animations)
public AnimationBook(Texture2DArray a_positionMap, List<Animation> a_animations)
{
positionMap = a_positionMap;
@ -24,10 +24,10 @@ namespace TAO.VertexAnimation
public int MaxFrames { get; private set; } = 0;
public Texture2DArray positionMap = null;
public List<VA_Animation> animations = new List<VA_Animation>();
public List<Animation> animations = new List<Animation>();
public List<Material> materials = new List<Material>();
public bool TryAddAnimation(VA_Animation animation)
public bool TryAddAnimation(Animation animation)
{
if (animations != null && animations.Count != 0)
{

View File

@ -0,0 +1,25 @@
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace TAO.VertexAnimation
{
public class AnimationDataComponentAuthoring : MonoBehaviour
{
public float4 AnimationDataOne;
public float4 AnimationDataTwo;
public float BlendFactor;
}
public class AnimationDataComponentBaker : Baker < AnimationDataComponentAuthoring >
{
public override void Bake( AnimationDataComponentAuthoring authoring )
{
//Entity parent = GetEntity( authoring.RootParent );
AddComponent( new FirstAnimationDataComponent{ Value = authoring.AnimationDataOne} );
AddComponent( new SecondAnimationDataComponent{ Value = authoring.AnimationDataTwo} );
AddComponent( new BlendingAnimationDataComponent{ Value = authoring.BlendFactor} );
}
}
}

View File

@ -5,30 +5,30 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "TAO/VertexAnimation/AnimationLibrary", order = 400)]
public class VA_AnimationLibrary : ScriptableObject
public class AnimationLibrary : ScriptableObject
{
[SerializeField]
private List<VA_AnimationBook> animationBooks = new List<VA_AnimationBook>();
private List<AnimationBook> animationBooks = new List<AnimationBook>();
[HideInInspector]
public List<VA_AnimationData> animationData = null;
#if UNITY_EDITOR
[SerializeField]
private List<VA_Animation> loadedAnimationsPreview = null;
private List<Animation> loadedAnimationsPreview = null;
#endif
public void Init()
{
animationData = new List<VA_AnimationData>();
foreach (VA_AnimationBook book in animationBooks)
foreach (AnimationBook book in animationBooks)
{
book.UpdateMaterials();
if (book != null)
{
foreach (VA_Animation animation in book.animations)
foreach (Animation animation in book.animations)
{
// TODO: Fix data name, FixedString32 doesn't transfer from editor?
//animation.Data.name = new FixedString32(animation.name);
@ -40,13 +40,13 @@ namespace TAO.VertexAnimation
public void OnValidate()
{
Dictionary<string, VA_Animation> usedNames = new Dictionary<string, VA_Animation>();
Dictionary<string, Animation> usedNames = new Dictionary<string, Animation>();
foreach (VA_AnimationBook book in animationBooks)
foreach (AnimationBook book in animationBooks)
{
if (book != null)
{
foreach (VA_Animation animation in book.animations)
foreach (Animation animation in book.animations)
{
if (!usedNames.ContainsKey(animation.name))
{
@ -61,7 +61,7 @@ namespace TAO.VertexAnimation
}
#if UNITY_EDITOR
loadedAnimationsPreview = new List<VA_Animation>();
loadedAnimationsPreview = new List<Animation>();
foreach (var un in usedNames)
{
loadedAnimationsPreview.Add(un.Value);

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Collections;
using Unity.Mathematics;
@ -9,9 +10,9 @@ using Random = Unity.Mathematics.Random;
namespace TAO.VertexAnimation
{
[UnityEngine.DisallowMultipleComponent]
public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour
public class AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour
{
public VA_AnimationLibrary AnimationLibrary;
public AnimationLibrary AnimationLibrary;
public bool DebugMode = false;
public uint Seed;
}
@ -21,18 +22,18 @@ internal struct SkinnedMeshEntity : IBufferElementData
public Entity Value;
}
public struct VA_AnimationLibraryComponent : IComponentData
public struct AnimationLibraryComponent : IComponentData
{
public BlobAssetReference<VA_AnimationLibraryData> AnimLibAssetRef;
public BlobAssetStore BlobAssetStore;
}
public class VA_AnimationLibraryComponentBaker : Baker < VA_AnimationLibraryComponentAuthoring >
public class AnimationLibraryComponentBaker : Baker < AnimationLibraryComponentAuthoring >
{
public override void Bake( VA_AnimationLibraryComponentAuthoring authoring )
public override void Bake( AnimationLibraryComponentAuthoring authoring )
{
authoring.AnimationLibrary.Init();
VA_AnimationLibraryComponent animationLibrary = new VA_AnimationLibraryComponent();
AnimationLibraryComponent animationLibrary = new AnimationLibraryComponent();
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
{
// Construct the root.
@ -71,60 +72,59 @@ public class VA_AnimationLibraryComponentBaker : Baker < VA_AnimationLibraryComp
BlobAssetReference<VA_AnimationLibraryData> animLib = animationLibrary.AnimLibAssetRef;
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref animLib.Value;
Random random = new Random( authoring.Seed );
Random random = new Random( authoring.Seed != 0 ? authoring.Seed : 42 );
int index = random.NextInt( 20 );
// Add animator to 'parent'.
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
{
Enabled = true,
AnimationName = animationsRef.animations[index].name,
animationIndex = index,
animationIndexNext = -1,
animationTime = 0,
animationLibrary = animLib
AnimationIndex = 2,
AnimationIndexNext = -1,
AnimationTime = 0,
AnimationLibrary = animLib
};
AddComponent(animatorComponent);
VA_AnimatorStateComponent animatorStateComponent = new VA_AnimatorStateComponent
VA_AnimatorBlendStateComponent animatorStateComponent = new VA_AnimatorBlendStateComponent
{
Enabled = true,
CurrentAnimationName = animationsRef.animations[index].name,
AnimationIndex = index,
BlendingEnabled = true,
AnimationIndex = 1,
AnimationIndexNext = -1,
AnimationTime = 0
};
AddComponent( animatorStateComponent );
var boneEntityArray = AddBuffer<SkinnedMeshEntity>();
MeshRenderer[] skinnedMeshRenderers =
MeshRenderer[] meshRenderers =
authoring.transform.GetComponentsInChildren < MeshRenderer >();
boneEntityArray.ResizeUninitialized(skinnedMeshRenderers.Length);
for (int boneIndex = 0; boneIndex < skinnedMeshRenderers.Length; ++boneIndex)
boneEntityArray.ResizeUninitialized(meshRenderers.Length);
for (int meshIndex = 0; meshIndex < meshRenderers.Length; ++meshIndex)
{
var boneEntity = GetEntity(skinnedMeshRenderers[boneIndex]);
boneEntityArray[boneIndex] = new SkinnedMeshEntity {Value = boneEntity};
var meshEntity = GetEntity(meshRenderers[meshIndex]);
boneEntityArray[meshIndex] = new SkinnedMeshEntity {Value = meshEntity};
}
}
}
//[GenerateAuthoringComponent]
public struct VA_AnimatorComponent : IComponentData
{
public FixedString64Bytes AnimationName;
public int animationIndex;
public int animationIndexNext;
public float animationTime;
public BlobAssetReference<VA_AnimationLibraryData> animationLibrary;
}
public struct VA_AnimatorStateComponent : IComponentData
{
public bool Enabled;
public FixedString64Bytes CurrentAnimationName;
public FixedString64Bytes AnimationName;
public int AnimationIndex;
public int AnimationIndexNext;
public Random Rand;
public float AnimationTime;
public BlobAssetReference<VA_AnimationLibraryData> AnimationLibrary;
}
public struct VA_AnimatorBlendStateComponent : IComponentData
{
public bool BlendingEnabled;
public int AnimationIndex;
public int AnimationIndexNext;
public float AnimationTime;
}
}

View File

@ -0,0 +1,155 @@
using Unity.Entities;
using Unity.Mathematics;
namespace TAO.VertexAnimation
{
public readonly partial struct AnimatorAspect : IAspect
{
private readonly RefRW < VA_AnimatorComponent > m_Animator;
private readonly RefRW < VA_AnimatorBlendStateComponent > m_AnimatorBlendState;
private readonly DynamicBuffer < SkinnedMeshEntity > m_SkinnedMeshEntities;
public void UpdateAnimator(float deltaTime, EntityCommandBuffer.ParallelWriter ecb, ref int startIndex)
{
if ( m_Animator.ValueRO.Enabled )
{
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref m_Animator.ValueRO.AnimationLibrary.Value;
//if ( m_Animator.ValueRO.AnimationName != vaAnimatorStateComponent.CurrentAnimationName )
//{
// // Set the animation index on the AnimatorComponent to play this animation.
// m_Animator.ValueRO.AnimationIndexNext = VA_AnimationLibraryUtils.GetAnimation(ref animationsRef, vaAnimatorStateComponent.CurrentAnimationName);
// m_Animator.ValueRO.AnimationName = vaAnimatorStateComponent.CurrentAnimationName;
//}
// 'Play' the actual animation.
m_Animator.ValueRW.AnimationTime += deltaTime * animationsRef.animations[m_Animator.ValueRO.AnimationIndex].frameTime;
if ( m_Animator.ValueRO.AnimationTime > animationsRef.animations[m_Animator.ValueRO.AnimationIndex].duration )
{
// Set time. Using the difference to smoothen out animations when looping.
m_Animator.ValueRW.AnimationTime -= animationsRef.animations[m_Animator.ValueRO.AnimationIndex].duration;
//m_Animator.ValueRW.animationIndexNext = vaAnimatorStateComponent.Rand.NextInt( 20 );
}
// Lerp animations.
// Set animation for lerp.
int animationIndexNext = m_Animator.ValueRO.AnimationIndexNext;
if ( animationIndexNext < 0 )
{
animationIndexNext = m_Animator.ValueRO.AnimationIndex;
//m_Animator.ValueRO.animationIndexNext = animationIndexNext + 1;
}
// Calculate next frame time for lerp.
float animationTimeNext = m_Animator.ValueRO.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 -= m_Animator.ValueRO.AnimationTime;
}
int animationIndexNextBlend = 0;
float animationTimeNextBlend = 0.0f;
if ( m_AnimatorBlendState.ValueRO.BlendingEnabled )
{
// 'Play' the actual animation.
m_AnimatorBlendState.ValueRW.AnimationTime += deltaTime *
animationsRef.
animations[m_AnimatorBlendState.ValueRO.AnimationIndex].
frameTime;
if ( m_AnimatorBlendState.ValueRO.AnimationTime >
animationsRef.animations[m_AnimatorBlendState.ValueRO.AnimationIndex].duration )
{
// Set time. Using the difference to smoothen out animations when looping.
m_AnimatorBlendState.ValueRW.AnimationTime -=
animationsRef.animations[m_AnimatorBlendState.ValueRO.AnimationIndex].duration;
//m_Animator.ValueRO.animationIndexNext = vaAnimatorStateComponent.Rand.NextInt( 20 );
}
// Lerp animations.
// Set animation for lerp.
animationIndexNextBlend = m_AnimatorBlendState.ValueRO.AnimationIndexNext;
if ( animationIndexNextBlend < 0 )
{
animationIndexNextBlend = m_AnimatorBlendState.ValueRO.AnimationIndex;
//m_Animator.ValueRO.animationIndexNext = animationIndexNext + 1;
}
// Calculate next frame time for lerp.
animationTimeNextBlend = m_AnimatorBlendState.ValueRO.AnimationTime +
( 1.0f / animationsRef.animations[animationIndexNextBlend].maxFrames );
if ( animationTimeNextBlend > animationsRef.animations[animationIndexNextBlend].duration )
{
// Set time. Using the difference to smooth out animations when looping.
animationTimeNextBlend -= m_AnimatorBlendState.ValueRO.AnimationTime;
}
}
for ( int i = 0; i < m_SkinnedMeshEntities.Length; i++ )
{
FirstAnimationDataComponent animationDataComponent = new FirstAnimationDataComponent();
animationDataComponent.Value = new float4
{
x = m_Animator.ValueRO.AnimationTime,
y = VA_AnimationLibraryUtils.GetAnimationMapIndex(
ref animationsRef,
m_Animator.ValueRO.AnimationIndex ),
z = animationTimeNext,
w = VA_AnimationLibraryUtils.GetAnimationMapIndex( ref animationsRef, animationIndexNext )
};
ecb.SetComponent < FirstAnimationDataComponent >(startIndex,
m_SkinnedMeshEntities[i].Value,
animationDataComponent );
startIndex++;
if ( m_AnimatorBlendState.ValueRO.BlendingEnabled )
{
SecondAnimationDataComponent animationDataComponent2 = new SecondAnimationDataComponent();
animationDataComponent2.Value = new float4
{
x = m_AnimatorBlendState.ValueRO.AnimationTime,
y = VA_AnimationLibraryUtils.GetAnimationMapIndex(
ref animationsRef,
m_AnimatorBlendState.ValueRO.AnimationIndex ),
z = animationTimeNextBlend,
w = VA_AnimationLibraryUtils.GetAnimationMapIndex(
ref animationsRef,
animationIndexNextBlend )
};
ecb.SetComponent < SecondAnimationDataComponent >(startIndex,
m_SkinnedMeshEntities[i].Value,
animationDataComponent2 );
startIndex++;
}
}
if ( m_Animator.ValueRO.AnimationIndexNext >= 0 )
{
m_Animator.ValueRW.AnimationIndex = animationIndexNext;
m_Animator.ValueRW.AnimationIndexNext = -1;
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 116de67f78e741cb93a39dc3de9449a3
timeCreated: 1670678206

View File

@ -0,0 +1,36 @@
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
namespace TAO.VertexAnimation
{
// System to update all the animations.
public partial struct AnimatorSystem : ISystem
{
public void OnCreate( ref SystemState state )
{
}
public void OnDestroy( ref SystemState state )
{
}
public void OnUpdate( ref SystemState state )
{
float deltaTime = SystemAPI.Time.DeltaTime;
EntityCommandBuffer ecb = new EntityCommandBuffer( Allocator.Temp );
int i = 0;
foreach ( var animatorAspect in SystemAPI.
Query < AnimatorAspect >() )
{
animatorAspect.UpdateAnimator( deltaTime, ecb.AsParallelWriter(), ref i );
}
ecb.Playback( state.EntityManager );
}
}
}

View File

@ -0,0 +1,28 @@
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
namespace TAO.VertexAnimation
{
[MaterialProperty("_AnimationDataOne")] //, MaterialPropertyFormat.Float4
public struct FirstAnimationDataComponent : IComponentData
{
// animationTime, animationIndex, colorIndex, nan.
public float4 Value;
}
[MaterialProperty("_AnimationDataTwo")] //, MaterialPropertyFormat.Float4
public struct SecondAnimationDataComponent : IComponentData
{
// animationTime, animationIndex, colorIndex, nan.
public float4 Value;
}
[MaterialProperty("_AnimationDataBlend")] //, MaterialPropertyFormat.Float4
public struct BlendingAnimationDataComponent : IComponentData
{
// animationTime, animationIndex, colorIndex, nan.
public float Value;
}
}

View File

@ -128,7 +128,7 @@ namespace TAO.VertexAnimation
// Bake mesh for a copy and to apply the new UV's to.
SkinnedMeshRenderer skinnedMeshRenderer = model.GetComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.BakeMesh(mesh);
mesh = model.GetComponent<SkinnedMeshRenderer>().sharedMesh.Copy();
mesh.RecalculateBounds();
mesh.uv3 = mesh.BakePositionUVs(animationInfo);

View File

@ -7,11 +7,10 @@ namespace TAO.VertexAnimation
public static Mesh[] GenerateLOD(this Mesh mesh, int lods, float[] quality)
{
Mesh[] lodMeshes = new Mesh[lods];
for (int lm = 0; lm < lodMeshes.Length; lm++)
{
lodMeshes[lm] = mesh.Copy();
// Only simplify when needed.
if (quality[lm] < 1.0f)
{

View File

@ -24,7 +24,7 @@ namespace TAO.VertexAnimation
uv5 = mesh.uv5,
uv6 = mesh.uv6,
uv7 = mesh.uv7,
uv8 = mesh.uv8
uv8 = mesh.uv8,
};
return copy;
@ -35,6 +35,7 @@ namespace TAO.VertexAnimation
{
mesh.Optimize();
mesh.UploadMeshData(true);
}
}
}

View File

@ -2,7 +2,7 @@
namespace TAO.VertexAnimation
{
public static class VA_Texture2DArrayUtils
public static class Texture2DArrayUtils
{
public static Texture2DArray CreateTextureArray(Texture2D[] a_textures, bool a_useMipChain, bool a_isLinear,
TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "", bool a_makeNoLongerReadable = true)

View File

@ -1,21 +0,0 @@
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace TAO.VertexAnimation
{
public class VA_AnimationDataComponentAuthoring : MonoBehaviour
{
public float4 Color;
}
public class VA_AnimationDataBaker : Baker < VA_AnimationDataComponentAuthoring >
{
public override void Bake( VA_AnimationDataComponentAuthoring authoring )
{
//Entity parent = GetEntity( authoring.RootParent );
AddComponent( new VaAnimationDataComponent{ Value = authoring.Color} );
}
}
}

View File

@ -1,9 +0,0 @@
using Unity.Entities;
using Unity.Transforms;
using Unity.Collections;
using UnityEngine;
namespace TAO.VertexAnimation
{
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 29deecb09ead9e74aa32f9d265f1e7ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,74 +0,0 @@
using System.Collections.Generic;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
namespace TAO.VertexAnimation
{
// System to update all the animations.
public partial class VA_AnimatorSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = SystemAPI.Time.DeltaTime;
// This is only executed if we have a valid skinning setup
Entities
.ForEach((ref VA_AnimatorComponent animator, in VA_AnimatorStateComponent vaAnimatorStateComponent, in DynamicBuffer<SkinnedMeshEntity> bones) =>
{
if ( vaAnimatorStateComponent.Enabled )
{
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref animator.animationLibrary.Value;
//if ( animator.AnimationName != vaAnimatorStateComponent.CurrentAnimationName )
//{
// // Set the animation index on the AnimatorComponent to play this animation.
// animator.animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationsRef, vaAnimatorStateComponent.CurrentAnimationName);
// animator.AnimationName = vaAnimatorStateComponent.CurrentAnimationName;
//}
// 'Play' the actual animation.
animator.animationTime += deltaTime * animationsRef.animations[animator.animationIndex].frameTime;
if (animator.animationTime > animationsRef.animations[animator.animationIndex].duration)
{
// Set time. Using the difference to smoothen out animations when looping.
animator.animationTime -= animationsRef.animations[animator.animationIndex].duration;
}
// Lerp animations.
// Set animation for lerp.
int animationIndexNext = animator.animationIndexNext;
if (animator.animationIndexNext < 0)
{
animationIndexNext = animator.animationIndex;
//animator.animationIndexNext = animationIndexNext + 1;
}
// Calculate next frame time for lerp.
float animationTimeNext = animator.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 -= animator.animationTime;
}
for ( int i = 0; i < bones.Length; i++ )
{
VaAnimationDataComponent vaAnimationDataComponent = new VaAnimationDataComponent();
vaAnimationDataComponent.Value = new float4
{
x = animator.animationTime,
y = VA_AnimationLibraryUtils.GetAnimationMapIndex( ref animationsRef, animator.animationIndex ),
z = animationTimeNext,
w = VA_AnimationLibraryUtils.GetAnimationMapIndex( ref animationsRef, animationIndexNext )
};
SystemAPI.SetComponent<VaAnimationDataComponent>( bones[i].Value, vaAnimationDataComponent );
}
}
}).Run();
}
}
}

View File

@ -1,15 +0,0 @@
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
namespace TAO.VertexAnimation
{
[MaterialProperty("_AnimationData")] //, MaterialPropertyFormat.Float4
public struct VaAnimationDataComponent : IComponentData
{
// animationTime, animationIndex, colorIndex, nan.
public float4 Value;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,12 @@
},
{
"m_Id": "a26112f7a84a474fb5edbe1546f1d72b"
},
{
"m_Id": "4c4eb2d44969485d822ccfa7b1d6cc34"
},
{
"m_Id": "aa41514a3f3a48c49f0dd3f567b7b3a0"
}
],
"m_Keywords": [
@ -1510,10 +1516,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2042.0001220703125,
"y": 84.00004577636719,
"width": 206.0,
"height": 132.0
"x": -3039.33349609375,
"y": 172.00001525878907,
"width": 207.333251953125,
"height": 134.6666717529297
}
},
"m_Slots": [
@ -1559,10 +1565,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3783.999755859375,
"y": -110.0,
"width": 154.0,
"height": 34.0
"x": -4781.33349609375,
"y": -21.999975204467775,
"width": 176.0,
"height": 35.9999885559082
}
},
"m_Slots": [
@ -1720,7 +1726,7 @@
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "0c91d07b837049389e484be61d32c114",
"m_Id": 0,
"m_DisplayName": "AnimationData",
"m_DisplayName": "AnimationDataOne",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
@ -1897,10 +1903,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3320.999755859375,
"y": -307.0,
"width": 55.999996185302737,
"height": 24.0
"x": -4318.66748046875,
"y": -219.3333282470703,
"width": 56.00048828125,
"height": 23.999923706054689
}
},
"m_Slots": [
@ -1933,10 +1939,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2528.0,
"y": -488.0000305175781,
"width": 237.33349609375,
"height": 400.0
"x": -3525.33349609375,
"y": -400.00006103515627,
"width": 237.333251953125,
"height": 400.0000305175781
}
},
"m_Slots": [
@ -2358,10 +2364,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2264.000244140625,
"y": -2.9999754428863527,
"width": 208.0,
"height": 278.0
"x": -3261.33349609375,
"y": 84.6666030883789,
"width": 209.33349609375,
"height": 280.0000305175781
}
},
"m_Slots": [
@ -2436,8 +2442,8 @@
"m_ObjectId": "28a570460d5d456da389318b319381ee",
"m_Title": "Lerp",
"m_Position": {
"x": -3550.999755859375,
"y": 228.00010681152345
"x": -4548.6669921875,
"y": 315.99993896484377
}
}
@ -2819,10 +2825,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2263.000244140625,
"y": -409.99993896484377,
"width": 208.0,
"height": 278.0
"x": -3260.666748046875,
"y": -321.9999694824219,
"width": 209.333251953125,
"height": 280.0000305175781
}
},
"m_Slots": [
@ -3071,10 +3077,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2695.0,
"y": 68.00005340576172,
"width": 136.0,
"height": 34.0
"x": -3692.666748046875,
"y": 156.0,
"width": 137.33349609375,
"height": 35.99998474121094
}
},
"m_Slots": [
@ -3215,6 +3221,34 @@
}
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector4ShaderProperty",
"m_ObjectId": "4c4eb2d44969485d822ccfa7b1d6cc34",
"m_Guid": {
"m_GuidSerialized": "fcf14bb9-c18a-45b4-9a24-b993443a8346"
},
"m_Name": "AnimationDataTwo",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "AnimationDataTwo",
"m_DefaultReferenceName": "_AnimationDataTwo",
"m_OverrideReferenceName": "",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_DismissedVersion": 0,
"m_Precision": 0,
"overrideHLSLDeclaration": true,
"hlslDeclarationOverride": 3,
"m_Hidden": false,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot",
@ -3268,10 +3302,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3455.999755859375,
"y": -355.0,
"width": 55.999996185302737,
"height": 24.0
"x": -4453.333984375,
"y": -267.3333740234375,
"width": 56.00048828125,
"height": 23.999908447265626
}
},
"m_Slots": [
@ -3327,7 +3361,7 @@
"m_CastShadows": true,
"m_ReceiveShadows": true,
"m_SupportsLODCrossFade": false,
"m_CustomEditorGUI": "TAO.VertexAnimation.Editor.LitGUI",
"m_CustomEditorGUI": "",
"m_SupportVFX": false
}
@ -3343,10 +3377,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1428.0,
"y": -370.9999694824219,
"width": 130.0,
"height": 142.0
"x": -2425.333251953125,
"y": -283.3334045410156,
"width": 131.332763671875,
"height": 143.9999542236328
}
},
"m_Slots": [
@ -3466,10 +3500,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3318.999755859375,
"y": 45.999961853027347,
"width": 55.999996185302737,
"height": 24.0
"x": -4316.6669921875,
"y": 134.0000457763672,
"width": 56.0,
"height": 23.999923706054689
}
},
"m_Slots": [
@ -3954,10 +3988,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2702.000244140625,
"y": -434.9999694824219,
"width": 158.0,
"height": 34.0
"x": -3699.33349609375,
"y": -347.333251953125,
"width": 156.666748046875,
"height": 35.999969482421878
}
},
"m_Slots": [
@ -3990,10 +4024,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3608.999755859375,
"y": -150.00001525878907,
"width": 120.0,
"height": 149.0
"x": -4606.6669921875,
"y": -62.00012969970703,
"width": 120.66650390625,
"height": 150.66668701171876
}
},
"m_Slots": [
@ -4091,10 +4125,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2876.0,
"y": -42.99996566772461,
"width": 145.0,
"height": 130.0
"x": -3873.33349609375,
"y": 44.666664123535159,
"width": 147.333251953125,
"height": 131.9998779296875
}
},
"m_Slots": [
@ -4184,10 +4218,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1644.0,
"y": 332.0000305175781,
"width": 55.999996185302737,
"height": 24.0
"x": -2641.33349609375,
"y": 419.9999694824219,
"width": 56.0,
"height": 23.99993896484375
}
},
"m_Slots": [
@ -4646,10 +4680,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2528.000244140625,
"y": -67.99991607666016,
"width": 239.99998474121095,
"height": 398.0
"x": -3525.33349609375,
"y": 19.99993896484375,
"width": 237.333251953125,
"height": 400.0000305175781
}
},
"m_Slots": [
@ -4786,9 +4820,6 @@
{
"m_Id": "b8ee11fe1178410a95b7b678347777ae"
},
{
"m_Id": "d8e6dd9d0f5b4f75a95867330e06f4e6"
},
{
"m_Id": "a26112f7a84a474fb5edbe1546f1d72b"
},
@ -4806,6 +4837,15 @@
},
{
"m_Id": "cc15912931794ae79993f81f6f7efd62"
},
{
"m_Id": "d8e6dd9d0f5b4f75a95867330e06f4e6"
},
{
"m_Id": "4c4eb2d44969485d822ccfa7b1d6cc34"
},
{
"m_Id": "aa41514a3f3a48c49f0dd3f567b7b3a0"
}
]
}
@ -5445,10 +5485,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2719.0,
"y": -26.99995994567871,
"width": 158.0,
"height": 34.0
"x": -3716.666748046875,
"y": 60.66667938232422,
"width": 156.66650390625,
"height": 35.99999237060547
}
},
"m_Slots": [
@ -5522,10 +5562,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1638.0,
"y": -430.0000305175781,
"width": 56.000003814697269,
"height": 24.0
"x": -2635.33349609375,
"y": -342.0001525878906,
"width": 56.0,
"height": 24.000152587890626
}
},
"m_Slots": [
@ -5664,10 +5704,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3525.999755859375,
"y": 327.0,
"width": 136.0,
"height": 34.0
"x": -4523.333984375,
"y": 414.6666564941406,
"width": 137.333984375,
"height": 35.999969482421878
}
},
"m_Slots": [
@ -6053,6 +6093,34 @@
"m_SerializedDescriptor": "SurfaceDescription.Smoothness"
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_ObjectId": "aa41514a3f3a48c49f0dd3f567b7b3a0",
"m_Guid": {
"m_GuidSerialized": "2b414016-34fd-4dd6-b7db-03ece39f7fb7"
},
"m_Name": "AnimationDataBlend",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "AnimationDataBlend",
"m_DefaultReferenceName": "_AnimationDataBlend",
"m_OverrideReferenceName": "",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_DismissedVersion": 0,
"m_Precision": 0,
"overrideHLSLDeclaration": true,
"hlslDeclarationOverride": 3,
"m_Hidden": false,
"m_Value": 0.0,
"m_FloatType": 0,
"m_RangeValues": {
"x": 0.0,
"y": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Texture2DInputMaterialSlot",
@ -6192,10 +6260,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3230.999755859375,
"y": 287.0,
"width": 128.0,
"height": 94.0
"x": -4228.6669921875,
"y": 374.6667175292969,
"width": 129.3330078125,
"height": 95.9998779296875
}
},
"m_Slots": [
@ -6324,10 +6392,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1275.0,
"y": -499.0,
"width": 139.0,
"height": 118.00000762939453
"x": -2272.66650390625,
"y": -411.3333435058594,
"width": 141.3330078125,
"height": 120.00003051757813
}
},
"m_Slots": [
@ -6520,10 +6588,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1812.0001220703125,
"y": -408.0000305175781,
"width": 139.0,
"height": 118.00000762939453
"x": -2809.33349609375,
"y": -319.9999694824219,
"width": 140.0,
"height": 120.00003051757813
}
},
"m_Slots": [
@ -6586,10 +6654,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2041.0001220703125,
"y": -322.99993896484377,
"width": 206.0,
"height": 132.0
"x": -3038.666748046875,
"y": -235.33334350585938,
"width": 207.333251953125,
"height": 134.66665649414063
}
},
"m_Slots": [
@ -6654,9 +6722,9 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2695.333251953125,
"y": -349.33331298828127,
"width": 137.333251953125,
"x": -3692.666748046875,
"y": -261.3334655761719,
"width": 137.33349609375,
"height": 36.0
}
},
@ -6730,10 +6798,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -2858.0,
"y": -451.0,
"width": 145.0,
"height": 130.0
"x": -3855.33349609375,
"y": -363.3332824707031,
"width": 147.333251953125,
"height": 131.99989318847657
}
},
"m_Slots": [
@ -6898,10 +6966,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3455.999755859375,
"y": 100.0000228881836,
"width": 55.999996185302737,
"height": 24.0
"x": -4453.333984375,
"y": 188.00003051757813,
"width": 56.00048828125,
"height": 23.999923706054689
}
},
"m_Slots": [
@ -7047,10 +7115,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1276.0001220703125,
"y": -131.0,
"width": 139.0,
"height": 118.00000762939453
"x": -2273.33349609375,
"y": -43.333335876464847,
"width": 141.333251953125,
"height": 120.00003814697266
}
},
"m_Slots": [
@ -7314,10 +7382,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -3369.999755859375,
"y": 287.0,
"width": 126.0,
"height": 117.99999237060547
"x": -4367.333984375,
"y": 374.6667175292969,
"width": 127.333984375,
"height": 120.00003051757813
}
},
"m_Slots": [
@ -7601,11 +7669,11 @@
"m_Guid": {
"m_GuidSerialized": "1ae6efb7-4b10-4256-8b3d-b26b7ccccde1"
},
"m_Name": "AnimationData",
"m_Name": "AnimationDataOne",
"m_DefaultRefNameVersion": 0,
"m_RefNameGeneratedByDisplayName": "",
"m_DefaultReferenceName": "Vector4_d8e6dd9d0f5b4f75a95867330e06f4e6",
"m_OverrideReferenceName": "_AnimationData",
"m_OverrideReferenceName": "_AnimationDataOne",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
@ -7862,10 +7930,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1813.0001220703125,
"y": -3.999986410140991,
"width": 139.0,
"height": 118.00000762939453
"x": -2810.666748046875,
"y": 84.00001525878906,
"width": 140.0,
"height": 120.00003051757813
}
},
"m_Slots": [
@ -8082,8 +8150,8 @@
"m_ObjectId": "e6214d379a71458b86eeb08aceb126e3",
"m_Title": "R = AnimationTime, G = AnimationIndex, B = AnimationTimeNext, A = AnimationIndexNext",
"m_Position": {
"x": -3808.999755859375,
"y": -209.0
"x": -4806.6669921875,
"y": -120.66667175292969
}
}
@ -8212,10 +8280,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1429.0,
"y": -33.00001907348633,
"width": 130.0,
"height": 142.0
"x": -2426.666748046875,
"y": 54.66653823852539,
"width": 131.333251953125,
"height": 144.00018310546876
}
},
"m_Slots": [
@ -8313,10 +8381,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1639.0,
"y": -64.00001525878906,
"width": 56.000003814697269,
"height": 24.0
"x": -2636.666748046875,
"y": 23.999889373779298,
"width": 56.0,
"height": 24.000137329101564
}
},
"m_Slots": [

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6b66d2d1b13d1ad4b94d13a1b1cca665
ScriptedImporter:
fileIDToRecycleName:
4800000: MainAsset
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

View File

@ -9,7 +9,7 @@
"GUID:a5baed0c9693541a5bd947d336ec7659",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:e0cd26848372d4e5c891c569017e11f1",
"GUID:c6266fb6386056f4b9e71740697607ca"
"GUID:77ccaf49895b0d64e87cd4b4faf83c49"
],
"includePlatforms": [],
"excludePlatforms": [],