mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2025-06-13 14:56:18 +02:00
AnimatorSystems test.
P4 sync: - LOD testing. - AnimatorSystems test setup. - AnimationTime and AnimationIndex per mesh. - Vector encoding/decoding.
This commit is contained in:
53
Runtime/Scripts/VA_AnimatorComponentAuthoring.cs
Normal file
53
Runtime/Scripts/VA_AnimatorComponentAuthoring.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Transforms;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class VA_AnimatorComponentAuthoring : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//[GenerateAuthoringComponent]
|
||||
public struct VA_AnimatorComponent : IComponentData
|
||||
{
|
||||
public int animationIndex;
|
||||
public int animationIndexSchedule;
|
||||
public float animationTime;
|
||||
}
|
||||
|
||||
public class VA_AnimatorConversionSystem : GameObjectConversionSystem
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
|
||||
{
|
||||
Entity entity = GetPrimaryEntity(animator);
|
||||
|
||||
// Add animator to 'parent'.
|
||||
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
|
||||
{
|
||||
animationIndex = 0,
|
||||
animationIndexSchedule = -1,
|
||||
animationTime = 0,
|
||||
};
|
||||
DstEntityManager.AddComponentData(entity, animatorComponent);
|
||||
|
||||
// Add the Material data to the children.
|
||||
var children = animator.GetComponentsInChildren<MeshRenderer>();
|
||||
for (int i = 0; i < children.Length; i++)
|
||||
{
|
||||
Entity ent = GetPrimaryEntity(children[i]);
|
||||
|
||||
VA_AnimationIndexComponent animationIndex = new VA_AnimationIndexComponent { Value = 0 };
|
||||
DstEntityManager.AddComponentData(ent, animationIndex);
|
||||
VA_AnimationTimeComponent animationTime = new VA_AnimationTimeComponent { Value = 0 };
|
||||
DstEntityManager.AddComponentData(ent, animationTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0cb46ae92466054da17b75956297486
|
||||
guid: 29deecb09ead9e74aa32f9d265f1e7ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
136
Runtime/Scripts/VA_AnimatorSystem.cs
Normal file
136
Runtime/Scripts/VA_AnimatorSystem.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using Unity.Rendering;
|
||||
using Unity.Transforms;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
//public class VA_AnimatorSystem : SystemBase
|
||||
//{
|
||||
// private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem;
|
||||
|
||||
// protected override void OnCreate()
|
||||
// {
|
||||
// base.OnCreate();
|
||||
|
||||
// endSimulationEntityCommandBufferSystem = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();
|
||||
// }
|
||||
|
||||
// protected override void OnUpdate()
|
||||
// {
|
||||
// var ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
|
||||
|
||||
// Entities.ForEach((Entity entity, int entityInQueryIndex, in VA_AnimatorComponent ac, in DynamicBuffer<Child> 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()
|
||||
{
|
||||
var atc = GetComponentDataFromEntity<VA_AnimationTimeComponent>(false);
|
||||
var aic = GetComponentDataFromEntity<VA_AnimationIndexComponent>(false);
|
||||
|
||||
Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
||||
{
|
||||
for (int i = 0; i < children.Length; i++)
|
||||
{
|
||||
// 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;
|
||||
|
||||
VA_AnimationIndexComponent aicCopy = aic[child];
|
||||
aicCopy.Value = ac.animationIndex;
|
||||
aic[child] = aicCopy;
|
||||
}
|
||||
})
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
|
||||
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<Child> children) =>
|
||||
{
|
||||
for (int i = 0; i < children.Length; i++)
|
||||
{
|
||||
// Get child.
|
||||
Entity child = children[i].Value;
|
||||
|
||||
//if(HasComponent<VA_AnimationTimeComponent>(child))
|
||||
//{
|
||||
var atc = GetComponent<VA_AnimationTimeComponent>(child);
|
||||
atc.Value = ac.animationTime;
|
||||
SetComponent(child, atc);
|
||||
//}
|
||||
|
||||
//if(HasComponent<VA_AnimationIndexComponent>(child))
|
||||
//{
|
||||
var aic = GetComponent<VA_AnimationIndexComponent>(child);
|
||||
aic.Value = ac.animationIndex;
|
||||
SetComponent(child, aic);
|
||||
//}
|
||||
}
|
||||
})
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
|
||||
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
||||
public class VA_AnimationTimeSystem : SystemBase
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
float time = UnityEngine.Time.deltaTime;
|
||||
|
||||
Entities.ForEach((ref VA_AnimatorComponent ac) =>
|
||||
{
|
||||
ac.animationTime += time;
|
||||
}).ScheduleParallel();
|
||||
}
|
||||
}
|
||||
|
||||
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
||||
public class VA_AnimationIndexSystem : SystemBase
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) =>
|
||||
{
|
||||
int index = entity.Index % 2;
|
||||
ac.animationIndex = index;
|
||||
}).ScheduleParallel();
|
||||
}
|
||||
}
|
||||
}
|
11
Runtime/Scripts/VA_AnimatorSystem.cs.meta
Normal file
11
Runtime/Scripts/VA_AnimatorSystem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e392c661a124f746b7a3c7a1f04f72c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Runtime/Scripts/VA_MaterialComponentData.cs
Normal file
17
Runtime/Scripts/VA_MaterialComponentData.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Rendering;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[MaterialProperty("_AnimationIndex", MaterialPropertyFormat.Float)]
|
||||
public struct VA_AnimationIndexComponent : IComponentData
|
||||
{
|
||||
public float Value;
|
||||
}
|
||||
|
||||
[MaterialProperty("_AnimationTime", MaterialPropertyFormat.Float)]
|
||||
public struct VA_AnimationTimeComponent : IComponentData
|
||||
{
|
||||
public float Value;
|
||||
}
|
||||
}
|
11
Runtime/Scripts/VA_MaterialComponentData.cs.meta
Normal file
11
Runtime/Scripts/VA_MaterialComponentData.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a25e66c24d9e3b4da1013acc6710f5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,57 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace tech_art_outsource.vertex_animation
|
||||
{
|
||||
public class VA_MaterialSetup : MonoBehaviour
|
||||
{
|
||||
public TextAsset m_animationJson = null;
|
||||
[HideInInspector]
|
||||
public AnimationData m_animationData = null;
|
||||
|
||||
private Material m_material = null;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
m_animationData = JsonUtility.FromJson<AnimationData>(m_animationJson.text);
|
||||
|
||||
m_material = GetComponent<MeshRenderer>().material;
|
||||
|
||||
m_material.SetInt("_numOfFrames", int.Parse(m_animationData.vertex_animation_textures1[0]._numOfFrames));
|
||||
m_material.SetFloat("_paddedX", float.Parse(m_animationData.vertex_animation_textures1[0]._paddedX));
|
||||
m_material.SetFloat("_paddedY", float.Parse(m_animationData.vertex_animation_textures1[0]._paddedY));
|
||||
m_material.SetFloat("_pivMax", float.Parse(m_animationData.vertex_animation_textures1[0]._pivMax));
|
||||
m_material.SetFloat("_pivMin", float.Parse(m_animationData.vertex_animation_textures1[0]._pivMin));
|
||||
m_material.SetFloat("_posMax", float.Parse(m_animationData.vertex_animation_textures1[0]._posMax));
|
||||
m_material.SetFloat("_posMin", float.Parse(m_animationData.vertex_animation_textures1[0]._posMin));
|
||||
m_material.SetFloat("_speed", float.Parse(m_animationData.vertex_animation_textures1[0]._speed));
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AnimationData
|
||||
{
|
||||
public AnimData[] vertex_animation_textures1;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AnimData
|
||||
{
|
||||
public string _doubleTex;
|
||||
public string _height;
|
||||
public string _normData;
|
||||
public string _numOfFrames;
|
||||
public string _packNorm;
|
||||
public string _packPscale;
|
||||
public string _paddedX;
|
||||
public string _paddedY;
|
||||
public string _pivMax;
|
||||
public string _pivMin;
|
||||
public string _posMax;
|
||||
public string _posMin;
|
||||
public string _scaleMax;
|
||||
public string _scaleMin;
|
||||
public string _speed;
|
||||
public string _width;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user