Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

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()
Expand Down
37 changes: 28 additions & 9 deletions Editor/Scripts/ModelBaker/AnimationPrefab.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using UnityEngine;
using UnityEditor;

Expand All @@ -19,25 +20,38 @@ public static GameObject Create(string path, string name, Mesh[] meshes, Materia
parent.AddComponent<LODGroup>();
}

if (!parent.TryGetComponent(out VA_AnimatorComponentAuthoring _))
if (!parent.TryGetComponent(out AnimationLibraryComponentAuthoring _))
{
parent.AddComponent<VA_AnimatorComponentAuthoring>();
parent.AddComponent<AnimationLibraryComponentAuthoring>();
}

if (!parent.TryGetComponent(out Unity.Entities.ConvertToEntity _))
{
parent.AddComponent<Unity.Entities.ConvertToEntity>();
}
//if (!parent.TryGetComponent(out Unity.Entities.ConvertToEntity _))
//{
// parent.AddComponent<Unity.Entities.ConvertToEntity>();
//}
}
else
{
// Create parent.
parent = new GameObject(name, typeof(LODGroup), typeof(VA_AnimatorComponentAuthoring), typeof(Unity.Entities.ConvertToEntity));
parent = new GameObject(name, typeof(LODGroup), typeof(AnimationLibraryComponentAuthoring));
}

// Create all LODs.
LOD[] lods = new LOD[meshes.Length];

//string meshPath = "Assets/Mesh" + parent.name;
//int index = 0;
//foreach ( Mesh mesh in meshes )
//{
// if ( !AssetDatabaseUtils.HasAsset( meshPath + index + ".asset", typeof( Mesh ) ) )
// {
// AssetDatabase.CreateAsset( mesh, meshPath + index + ".asset" );
// }
//
// index++;
//}

AssetDatabase.SaveAssets();
for (int i = 0; i < meshes.Length; i++)
{
string childName = string.Format("{0}_LOD{1}", name, i);
Expand All @@ -51,10 +65,15 @@ public static GameObject Create(string path, string name, Mesh[] meshes, Materia
}
else
{
child = new GameObject(childName, typeof(MeshFilter), typeof(MeshRenderer));
child = new GameObject(childName, typeof(MeshFilter), typeof(MeshRenderer), typeof(AnimationDataComponentAuthoring));
}
}

if (!child.TryGetComponent(out AnimationDataComponentAuthoring ad))
{
child.AddComponent<AnimationDataComponentAuthoring>();
}

if (child.TryGetComponent(out MeshFilter mf))
{
mf.sharedMesh = meshes[i];
Expand All @@ -75,7 +94,7 @@ public static GameObject Create(string path, string name, Mesh[] meshes, Materia

// Create prefab.
GameObject prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(parent, path, InteractionMode.AutomatedAction);
GameObject.DestroyImmediate(parent);
//GameObject.DestroyImmediate(parent);

return prefab;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
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.
Expand All @@ -30,8 +31,8 @@ public class VA_ModelBaker : ScriptableObject
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
Expand Down Expand Up @@ -99,7 +100,7 @@ public void Bake()
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);
Expand All @@ -125,7 +126,9 @@ private void SaveAssets(AnimationBaker.BakedData bakedData)
}

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);
Expand Down Expand Up @@ -155,6 +158,9 @@ private void GeneratePrefab(AnimationBaker.BakedData bakedData)
// Get info.
NamingConventionUtils.PositionMapInfo info = bakedData.GetPositionMap.name.GetTextureInfo();

//bakedData.mesh.SetTriangles( bakedData.mesh.triangles, 0 );
//meshes = new[] { bakedData.mesh };

// Generate Material
if (!AssetDatabaseUtils.HasChildAsset(this, material))
{
Expand All @@ -175,12 +181,12 @@ private void GenerateBook(AnimationBaker.BakedData bakedData)
// 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.
Expand All @@ -203,13 +209,13 @@ private void GenerateBook(AnimationBaker.BakedData bakedData)
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);
Expand All @@ -225,7 +231,7 @@ private void GenerateBook(AnimationBaker.BakedData bakedData)
}
}

private bool TryGetAnimationWithName(string name, out VA_Animation animation)
private bool TryGetAnimationWithName(string name, out Animation animation)
{
foreach (var a in animations)
{
Expand Down Expand Up @@ -265,7 +271,7 @@ public void DeleteSavedAssets()
material = null;
meshes = null;
book = null;
animations = new List<VA_Animation>();
animations = new List<Animation>();

AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Vertex Animation
## This works with Entities 1.0

This is a a animation system for skinned meshes in ECS, it includes a baking tool and the shaders to render the data.

It is based on this framework https://github.com/maxartz15/VertexAnimation


I forked this framework and fixed it for Entities 1.0

Here you can find a video of it in action:
https://youtu.be/yOddkGkct8w



Original Readme:
# TECH ART OUTSOURCE - Vertex Animation

![](Documentation~/Images/ProjectCastle_01.gif)
Expand Down
49 changes: 49 additions & 0 deletions Runtime/Scripts/AnimatedPrefabSpawner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using UnityEngine;

namespace TAO.VertexAnimation
{

public class AnimatedPrefabSpawner : MonoBehaviour
{
public GameObject Prefab;

public Transform BottomLeftCorner;

public Transform Parent;

public int Width;
public int Height;

public float Distance;

[ContextMenu("Test")]
public void SetAllSeeds()
{

Vector3 currentPosition = BottomLeftCorner.position;
Vector3 startPosition = currentPosition;
for ( int i = 0; i < Width; i++ )
{
for ( int j = 0; j < Height; j++ )
{
GameObject instance = Instantiate( Prefab, Parent, true );
instance.transform.position = currentPosition;
currentPosition = new Vector3( currentPosition.x + Distance, currentPosition.y, currentPosition.z );
}
currentPosition = new Vector3( startPosition.x , currentPosition.y, currentPosition.z + Distance );
}
AnimationLibraryComponentAuthoring[] vaAnimationLibraryComponentAuthorings = Parent.GetComponentsInChildren < AnimationLibraryComponentAuthoring >();

foreach ( AnimationLibraryComponentAuthoring authoring in vaAnimationLibraryComponentAuthorings )
{
var test = Guid.NewGuid().GetHashCode().ToString();
Debug.Log( test );
test = test.Substring( test.Length - 4 );
Debug.Log( UInt32.Parse( test ) );
authoring.Seed = UInt32.Parse( test );
}
}
}

}
3 changes: 3 additions & 0 deletions Runtime/Scripts/AnimatedPrefabSpawner.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TAO.VertexAnimation
{
public class VA_Animation : ScriptableObject
public class Animation : ScriptableObject
{
public VA_AnimationData Data;

Expand All @@ -16,13 +16,13 @@ public void SetData(VA_AnimationData a_data)
public VA_AnimationData GetData()
{
// TODO: Fix data name, FixedString32 doesn't transfer from editor?
Data.name = new FixedString64(name);
Data.name = new FixedString64Bytes(name);
return Data;
}

public FixedString64 GetName()
public FixedString64Bytes GetName()
{
return new FixedString64(this.name);
return new FixedString64Bytes(this.name);
}
}
}
File renamed without changes.
37 changes: 37 additions & 0 deletions Runtime/Scripts/AnimationBakingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;

namespace TAO.VertexAnimation
{

[RequireMatchingQueriesForUpdate]
public partial class AnimationBakingSystem : SystemBase
{
protected override void OnUpdate()
{
EntityCommandBuffer entityCommandBuffer = new EntityCommandBuffer( Allocator.Temp );
foreach (var (animator, wait) in
SystemAPI.Query<RefRW<AnimatorComponent>, RefRW<AnimatorWaitingForBaking>>())
{
DynamicBuffer<Child> children = EntityManager.GetBuffer < Child >( wait.ValueRO.AnimatorEntity );
Debug.Log( children.Length );
animator.ValueRW.SkinnedMeshes = new NativeArray < Entity >( children.Length, Allocator.Persistent );
int i = 0;
foreach ( Child child in children )
{
animator.ValueRW.SkinnedMeshes[i] = child.Value;
i++;
}

wait.ValueRW.IsInitialized = true;
entityCommandBuffer.RemoveComponent<AnimatorWaitingForBaking>( wait.ValueRO.AnimatorEntity );
//EntityManager.RemoveComponent < AnimatorWaitingForBaking >( wait.AnimatorEntity );
}

entityCommandBuffer.Playback( EntityManager );
}
}

}
3 changes: 3 additions & 0 deletions Runtime/Scripts/AnimationBakingSystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading