From 52dd9d4b3cb36062ae6cf821c3a63a27d5441740 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 9 Dec 2020 18:36:32 +0100 Subject: [PATCH] AnimationLibrary start, AnimatorSystem parallel Base setup animation library. AnimatorSystem now runs in parallel. TextureImporter preset. --- Editor/Presets.meta | 8 + .../VertexAnimationTextureImporter.preset | 535 ++++++++++++++++++ ...VertexAnimationTextureImporter.preset.meta | 8 + Runtime/Scripts/VA_AnimationBookSO.cs | 30 + Runtime/Scripts/VA_AnimationBookSO.cs.meta | 11 + Runtime/Scripts/VA_AnimationLibrary.cs | 47 +- .../VA_AnimationLibraryComponentAuthoring.cs | 49 ++ ...AnimationLibraryComponentAuthoring.cs.meta | 11 + Runtime/Scripts/VA_AnimationLibrarySO.cs | 46 ++ Runtime/Scripts/VA_AnimationLibrarySO.cs.meta | 11 + .../Scripts/VA_AnimatorComponentAuthoring.cs | 8 +- Runtime/Scripts/VA_AnimatorSystem.cs | 127 +---- Runtime/TAO.VertexAnimation.asmdef | 3 +- 13 files changed, 760 insertions(+), 134 deletions(-) create mode 100644 Editor/Presets.meta create mode 100644 Editor/Presets/VertexAnimationTextureImporter.preset create mode 100644 Editor/Presets/VertexAnimationTextureImporter.preset.meta create mode 100644 Runtime/Scripts/VA_AnimationBookSO.cs create mode 100644 Runtime/Scripts/VA_AnimationBookSO.cs.meta create mode 100644 Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs create mode 100644 Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs.meta create mode 100644 Runtime/Scripts/VA_AnimationLibrarySO.cs create mode 100644 Runtime/Scripts/VA_AnimationLibrarySO.cs.meta diff --git a/Editor/Presets.meta b/Editor/Presets.meta new file mode 100644 index 0000000..4fc86d1 --- /dev/null +++ b/Editor/Presets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 58cbb5e6d3dfc7e41a4832f8880928ea +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Presets/VertexAnimationTextureImporter.preset b/Editor/Presets/VertexAnimationTextureImporter.preset new file mode 100644 index 0000000..b463a10 --- /dev/null +++ b/Editor/Presets/VertexAnimationTextureImporter.preset @@ -0,0 +1,535 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!181963792 &2655988077585873504 +Preset: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: VertexAnimationTextureImporter + m_TargetType: + m_NativeTypeID: 1006 + m_ManagedTypePPtr: {fileID: 0} + m_ManagedTypeFallback: + m_Properties: + - target: {fileID: 0} + propertyPath: m_ExternalObjects.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MipMapMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_EnableMipMap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_sRGBTexture + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LinearTexture + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_FadeOut + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_BorderMipMap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MipMapsPreserveCoverage + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AlphaTestReferenceValue + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MipMapFadeDistanceStart + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MipMapFadeDistanceEnd + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ConvertToNormalMap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ExternalNormalMap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HeightScale + value: 0.25 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_NormalMapFilter + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_IsReadable + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_StreamingMipmaps + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_StreamingMipmapsPriority + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_VTOnly + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_GrayScaleToAlpha + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_GenerateCubemap + value: 6 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_CubemapConvolution + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SeamlessCubemap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureFormat + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaxTextureSize + value: 2048 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_FilterMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_Aniso + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_MipBias + value: -100 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_WrapU + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_WrapV + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureSettings.m_WrapW + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_NPOTScale + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_Lightmap + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteExtrude + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteMeshType + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_Alignment + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpritePivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpritePivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpritePixelsToUnits + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteBorder.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteBorder.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteBorder.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteBorder.w + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteGenerateFallbackPhysicsShape + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AlphaUsage + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AlphaIsTransparency + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteTessellationDetail + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureType + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureShape + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SingleChannelComponent + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaxTextureSizeSet + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_CompressionQualitySet + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_TextureFormatSet + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_IgnorePngGamma + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ApplyGammaDecoding + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.size + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_BuildTarget + value: DefaultTexturePlatform + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_MaxTextureSize + value: 8192 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_ResizeAlgorithm + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_TextureFormat + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_TextureCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_CrunchedCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_AllowsAlphaSplitting + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_Overridden + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_AndroidETC2FallbackOverride + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[0].m_ForceMaximumCompressionQuality_BC6H_BC7 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_BuildTarget + value: Standalone + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_MaxTextureSize + value: 8192 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_ResizeAlgorithm + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_TextureFormat + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_TextureCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_CrunchedCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_AllowsAlphaSplitting + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_Overridden + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_AndroidETC2FallbackOverride + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[1].m_ForceMaximumCompressionQuality_BC6H_BC7 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_BuildTarget + value: iPhone + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_MaxTextureSize + value: 8192 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_ResizeAlgorithm + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_TextureFormat + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_TextureCompression + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_CrunchedCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_AllowsAlphaSplitting + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_Overridden + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_AndroidETC2FallbackOverride + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[2].m_ForceMaximumCompressionQuality_BC6H_BC7 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_BuildTarget + value: Android + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_MaxTextureSize + value: 8192 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_ResizeAlgorithm + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_TextureFormat + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_TextureCompression + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_CrunchedCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_AllowsAlphaSplitting + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_Overridden + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_AndroidETC2FallbackOverride + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[3].m_ForceMaximumCompressionQuality_BC6H_BC7 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_BuildTarget + value: Windows Store Apps + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_MaxTextureSize + value: 8192 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_ResizeAlgorithm + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_TextureFormat + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_TextureCompression + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_CompressionQuality + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_CrunchedCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_AllowsAlphaSplitting + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_Overridden + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_AndroidETC2FallbackOverride + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PlatformSettings.Array.data[4].m_ForceMaximumCompressionQuality_BC6H_BC7 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Sprites.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Outline.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_PhysicsShape.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Bones.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_SpriteID + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_InternalID + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Vertices.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Indices.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Edges.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_Weights.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpriteSheet.m_SecondaryTextures.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SpritePackingTag + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PSDRemoveMatte + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PSDShowRemoveMatteOption + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UserData + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AssetBundleName + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AssetBundleVariant + value: + objectReference: {fileID: 0} + m_ExcludedProperties: [] diff --git a/Editor/Presets/VertexAnimationTextureImporter.preset.meta b/Editor/Presets/VertexAnimationTextureImporter.preset.meta new file mode 100644 index 0000000..f78a481 --- /dev/null +++ b/Editor/Presets/VertexAnimationTextureImporter.preset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0f7881a0354329b46aab70076cbffd97 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimationBookSO.cs b/Runtime/Scripts/VA_AnimationBookSO.cs new file mode 100644 index 0000000..0ab1f89 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationBookSO.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace TAO.VertexAnimation +{ + [CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)] + public class VA_AnimationBookSO : ScriptableObject + { + public int maxFrames; + public Material[] materials; + public VA_AnimationPage[] animationPages; + + private void Setup() + { + // TODO: ... + // GenerateTextures. + // SetupMaterials. + } + } + + [System.Serializable] + public struct VA_AnimationPage + { + public string name; + public int frames; + public Texture2D texture2D; + } + +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationBookSO.cs.meta b/Runtime/Scripts/VA_AnimationBookSO.cs.meta new file mode 100644 index 0000000..f9264f0 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationBookSO.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 97cdf8b194bcb83459d952b3cb008113 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs b/Runtime/Scripts/VA_AnimationLibrary.cs index 5c791f2..800d3d2 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs +++ b/Runtime/Scripts/VA_AnimationLibrary.cs @@ -6,46 +6,33 @@ namespace TAO.VertexAnimation [System.Serializable] public struct VA_AnimationData { + public FixedString32 name; public int frames; public int maxFrames; + // 1.0f / maxFrames. + public float frameTime; + // frameTime * frames. + public float duration; } - public struct VA_AnimationDataBlobAsset + public struct VA_AnimationLibrary { public BlobArray animations; } - public class VA_AnimationDataBlobAssetConversionSystem : GameObjectConversionSystem + public static class VA_AnimationLibraryUtils { - protected override void OnUpdate() + public static int GetAnimation(ref VA_AnimationLibrary animationsRef, FixedString32 animationName) { - BlobAssetReference animationDataBlobAssetRef; + for (int i = 0; i < animationsRef.animations.Length; i++) + { + if (animationsRef.animations[i].name == animationName) + { + return i; + } + } - // Blob builder to build. - using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp)) - { - // Construct the root. - ref VA_AnimationDataBlobAsset animationDataBlobAsset = ref blobBuilder.ConstructRoot(); - - // Set all the data. - BlobBuilderArray animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, 2); - for (int i = 0; i < animationDataArray.Length; i++) - { - animationDataArray[i] = new VA_AnimationData - { - frames = 36, - maxFrames = 43 - }; - } - - // Construct blob asset reference. - animationDataBlobAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); - - UnityEngine.Debug.Log("Created: " + animationDataBlobAssetRef.Value.animations.Length.ToString()); - } - - // TODO: Generate Hash based on Guid. - BlobAssetStore.TryAdd(new Hash128("AnimationLib"), animationDataBlobAssetRef); - } + return -1; + } } } \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs new file mode 100644 index 0000000..c20fd74 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs @@ -0,0 +1,49 @@ +using Unity.Entities; +using Unity.Collections; + +namespace TAO.VertexAnimation +{ + [UnityEngine.RequireComponent(typeof(ConvertToEntity))] + [UnityEngine.DisallowMultipleComponent] + public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour + { + public VA_AnimationLibrarySO animationLibrary; + } + + public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem + { + protected override void OnUpdate() + { + Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) => + { + // Blob builder to build. + using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp)) + { + // Construct the root. + ref VA_AnimationLibrary animationDataBlobAsset = ref blobBuilder.ConstructRoot(); + + // Set all the data. + BlobBuilderArray animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animations.Count); + + for (int i = 0; i < animationDataArray.Length; i++) + { + // Copy data. + animationDataArray[i] = animationLib.animationLibrary.animations[i]; + } + + // Construct blob asset reference. + BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); + + // Add it to the asset store. + // TODO: Generate Hash based on Guid. + BlobAssetStore.TryAdd(new Hash128("AnimationLib"), animLibAssetRef); + + UnityEngine.Debug.Log("VA_AnimationLibrary has " + animLibAssetRef.Value.animations.Length.ToString() + " animations."); + } + + // Remove the entity since we don't need it anymore. + DstEntityManager.DestroyEntity(GetPrimaryEntity(animationLib)); + }); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs.meta b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs.meta new file mode 100644 index 0000000..418e1ef --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4900528f6fface444826347ebac032b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimationLibrarySO.cs b/Runtime/Scripts/VA_AnimationLibrarySO.cs new file mode 100644 index 0000000..1af284c --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibrarySO.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace TAO.VertexAnimation +{ + [CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)] + public class VA_AnimationLibrarySO : ScriptableObject + { + [SerializeField] + private VA_AnimationBookSO[] animationBooks; + + [HideInInspector] + public List animations = null; + + private void OnValidate() + { + SetupAnimations(); + } + + private void SetupAnimations() + { + animations = new List(); + + if (animationBooks != null) + { + for (int b = 0; b < animationBooks.Length; b++) + { + if(animationBooks[b].animationPages != null) + { + for (int p = 0; p < animationBooks[b].animationPages.Length; p++) + { + animations.Add(new VA_AnimationData + { + name = new Unity.Collections.FixedString32(animationBooks[b].animationPages[p].name), + maxFrames = animationBooks[b].maxFrames, + frames = animationBooks[b].animationPages[p].frames, + frameTime = 1.0f / animationBooks[b].maxFrames, + duration = 1.0f / animationBooks[b].maxFrames * animationBooks[b].animationPages[p].frames + }); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibrarySO.cs.meta b/Runtime/Scripts/VA_AnimationLibrarySO.cs.meta new file mode 100644 index 0000000..8e82ab2 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibrarySO.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0d1625f26e651894b954faf1934378dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs index 862e45c..b71aa92 100644 --- a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs @@ -17,15 +17,15 @@ namespace TAO.VertexAnimation public int animationIndex; public int animationIndexSchedule; public float animationTime; - public BlobAssetReference animationsRef; + public BlobAssetReference animationLibrary; } - [UpdateAfter(typeof(VA_AnimationDataBlobAssetConversionSystem))] + [UpdateAfter(typeof(VA_AnimationLibraryConversionSystem))] public class VA_AnimatorConversionSystem : GameObjectConversionSystem { protected override void OnUpdate() { - BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference assetReference); + BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference animLib); Entities.ForEach((VA_AnimatorComponentAuthoring animator) => { @@ -37,7 +37,7 @@ namespace TAO.VertexAnimation animationIndex = 0, animationIndexSchedule = -1, animationTime = 0, - animationsRef = assetReference + animationLibrary = animLib }; DstEntityManager.AddComponentData(entity, animatorComponent); diff --git a/Runtime/Scripts/VA_AnimatorSystem.cs b/Runtime/Scripts/VA_AnimatorSystem.cs index 9b8897f..7af742f 100644 --- a/Runtime/Scripts/VA_AnimatorSystem.cs +++ b/Runtime/Scripts/VA_AnimatorSystem.cs @@ -6,45 +6,6 @@ using Unity.Mathematics; namespace TAO.VertexAnimation { - //TODO: SetComponent. - //TODO: Disable thread safety. - //TODO: Blob data for static animation data. - - - //public class VA_AnimatorSystem : SystemBase - //{ - // private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem; - - // protected override void OnCreate() - // { - // base.OnCreate(); - - // endSimulationEntityCommandBufferSystem = World.GetExistingSystem(); - // } - - // protected override void OnUpdate() - // { - // var ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter(); - - // Entities.ForEach((Entity entity, int entityInQueryIndex, in VA_AnimatorComponent ac, in DynamicBuffer children) => - // { - // for (int i = 0; i < children.Length; i++) - // { - // // Get child. - // Entity child = children[i].Value; - - // // Overwrite existing component. - // ecb.AddComponent(entityInQueryIndex, child, new VA_AnimationTimeComponent { Value = ac.animationTime }); - // ecb.AddComponent(entityInQueryIndex, child, new VA_AnimationIndexComponent { Value = ac.animationIndex }); - // } - // }) - // .ScheduleParallel(); - - // endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency); - // } - //} - - //[UpdateBefore(typeof(HybridRendererSystem))] public class VA_AnimatorSystem : SystemBase { protected override void OnUpdate() @@ -59,59 +20,29 @@ namespace TAO.VertexAnimation // Get child. Entity child = children[i].Value; - // Get a copy of the time Component of the child. - VA_AnimationTimeComponent atcCopy = atc[child]; - // Set new value. - atcCopy.Value = ac.animationTime; - // Update original. - atc[child] = atcCopy; + atc[child] = new VA_AnimationTimeComponent { Value = ac.animationTime }; - VA_AnimationIndexComponent aicCopy = aic[child]; - aicCopy.Value = ac.animationIndex; - aic[child] = aicCopy; + //// Get a copy of the time Component of the child. + //VA_AnimationTimeComponent atcCopy = atc[child]; + //// Set new value. + //atcCopy.Value = ac.animationTime; + //// Update original. + //atc[child] = atcCopy; + + aic[child] = new VA_AnimationIndexComponent { Value = ac.animationIndex }; + + //VA_AnimationIndexComponent aicCopy = aic[child]; + //aicCopy.Value = ac.animationIndex; + //aic[child] = aicCopy; } }) - .Run(); + .WithNativeDisableContainerSafetyRestriction(atc) + .WithNativeDisableContainerSafetyRestriction(aic) + .ScheduleParallel(); } } - //public class VA_AnimatorSystem2 : SystemBase - //{ - // protected override void OnCreate() - // { - // base.OnCreate(); - - // Enabled = false; - // } - - // protected override void OnUpdate() - // { - // Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer children) => - // { - // for (int i = 0; i < children.Length; i++) - // { - // // Get child. - // Entity child = children[i].Value; - - // //if(HasComponent(child)) - // //{ - // var atc = GetComponent(child); - // atc.Value = ac.animationTime; - // SetComponent(child, atc); - // //} - - // //if(HasComponent(child)) - // //{ - // var aic = GetComponent(child); - // aic.Value = ac.animationIndex; - // SetComponent(child, aic); - // //} - // } - // }) - // .Run(); - // } - //} - + // Example systems to update animation parameters. [UpdateBefore(typeof(VA_AnimatorSystem))] public class VA_AnimationTimeSystem : SystemBase { @@ -122,20 +53,13 @@ namespace TAO.VertexAnimation Entities.ForEach((ref VA_AnimatorComponent ac) => { // Get the animation lib data. - ref VA_AnimationDataBlobAsset animationsRef = ref ac.animationsRef.Value; - int aFrames = animationsRef.animations[ac.animationIndex].frames; - int aMaxFrames = animationsRef.animations[ac.animationIndex].maxFrames; + ref VA_AnimationLibrary animationsRef = ref ac.animationLibrary.Value; ac.animationTime += deltaTime; - // Time per frame. - float fTime = 1.0f / aMaxFrames; - // Animation time. - float cTime = fTime * (aFrames); - - if (ac.animationTime > cTime) + if (ac.animationTime > animationsRef.animations[ac.animationIndex].duration) { - ac.animationTime = ac.animationTime - cTime; + ac.animationTime = ac.animationTime - animationsRef.animations[ac.animationIndex].duration; } }).ScheduleParallel(); @@ -149,9 +73,14 @@ namespace TAO.VertexAnimation { Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) => { - //int index = entity.Index % 2; - //ac.animationIndex = index; - ac.animationIndex = 0; + // Get the animation lib data. + ref VA_AnimationLibrary animationLib = ref ac.animationLibrary.Value; + + int animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationLib, "Shoot"); + + //int index = entity.Index % 2; + //ac.animationIndex = index; + ac.animationIndex = animationIndex; }).ScheduleParallel(); } } diff --git a/Runtime/TAO.VertexAnimation.asmdef b/Runtime/TAO.VertexAnimation.asmdef index dfc4c45..e1e37b1 100644 --- a/Runtime/TAO.VertexAnimation.asmdef +++ b/Runtime/TAO.VertexAnimation.asmdef @@ -6,7 +6,8 @@ "GUID:8819f35a0fc84499b990e90a4ca1911f", "GUID:7a450cf7ca9694b5a8bfa3fd83ec635a", "GUID:a5baed0c9693541a5bd947d336ec7659", - "GUID:d8b63aba1907145bea998dd612889d6b" + "GUID:d8b63aba1907145bea998dd612889d6b", + "GUID:e0cd26848372d4e5c891c569017e11f1" ], "includePlatforms": [], "excludePlatforms": [],