浏览代码

Added step by step constraints for TwistChain.

Also added step by step scenes mapping to these constraints.
/main
Simon Bouvier-Zappa 5 年前
当前提交
c4245549
共有 12 个文件被更改,包括 3239 次插入0 次删除
  1. 28
      Assets/Constraints/ConstraintsUtils.cs
  2. 11
      Assets/Constraints/ConstraintsUtils.cs.meta
  3. 55
      Assets/Constraints/TwistChainStep0.cs
  4. 11
      Assets/Constraints/TwistChainStep0.cs.meta
  5. 99
      Assets/Constraints/TwistChainStep1.cs
  6. 11
      Assets/Constraints/TwistChainStep1.cs.meta
  7. 1001
      Assets/Scenes/TwistChainFinal.unity
  8. 7
      Assets/Scenes/TwistChainFinal.unity.meta
  9. 1001
      Assets/Scenes/TwistChainSetup0.unity
  10. 7
      Assets/Scenes/TwistChainSetup0.unity.meta
  11. 1001
      Assets/Scenes/TwistChainSetup1.unity
  12. 7
      Assets/Scenes/TwistChainSetup1.unity.meta

28
Assets/Constraints/ConstraintsUtils.cs


using System.Collections.Generic;
using UnityEditor;
using Unity.Collections;
namespace UnityEngine.Animations.Rigging
{
static class ConstraintsUtils
{
public static List<Transform> ExtractChain(Transform root, Transform tip)
{
var chain = new List<Transform>();
if (!tip.IsChildOf(root))
return chain;
Transform tmp = tip;
while (tmp != root)
{
chain.Add(tmp);
tmp = tmp.parent;
}
chain.Add(root);
chain.Reverse();
return chain;
}
}
}

11
Assets/Constraints/ConstraintsUtils.cs.meta


fileFormatVersion: 2
guid: 2205d78c6d39142e38ee34cfba251d5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

55
Assets/Constraints/TwistChainStep0.cs


using System.Collections.Generic;
using UnityEditor;
using Unity.Collections;
namespace UnityEngine.Animations.Rigging
{
using Experimental.Animations;
[Unity.Burst.BurstCompile]
public struct TwistChainStep0Job : IWeightedAnimationJob
{
public FloatProperty jobWeight { get; set; }
public void ProcessRootMotion(AnimationStream stream) {}
public void ProcessAnimation(AnimationStream stream) {}
}
[System.Serializable]
public struct TwistChainStep0Data : IAnimationJobData
{
bool IAnimationJobData.IsValid() => true;
void IAnimationJobData.SetDefaultValues()
{
}
}
public class TwistChainStep0JobBinder : AnimationJobBinder<TwistChainStep0Job, TwistChainStep0Data>
{
public override TwistChainStep0Job Create(Animator animator, ref TwistChainStep0Data data, Component component)
{
// Build Job.
var job = new TwistChainStep0Job();
return job;
}
public override void Destroy(TwistChainStep0Job job)
{
}
public override void Update(TwistChainStep0Job job, ref TwistChainStep0Data data)
{
}
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Twist Chain Step 0")]
public class TwistChainStep0 : RigConstraint<
TwistChainStep0Job,
TwistChainStep0Data,
TwistChainStep0JobBinder
>
{
}
}

11
Assets/Constraints/TwistChainStep0.cs.meta


fileFormatVersion: 2
guid: 997c9c37e3f8542ecbd12eaf123b9e49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

99
Assets/Constraints/TwistChainStep1.cs


using System.Collections.Generic;
using UnityEditor;
using Unity.Collections;
namespace UnityEngine.Animations.Rigging
{
using Experimental.Animations;
[Unity.Burst.BurstCompile]
public struct TwistChainStep1Job : IWeightedAnimationJob
{
public NativeArray<ReadWriteTransformHandle> chain;
public ReadWriteTransformHandle rootTarget;
public ReadWriteTransformHandle tipTarget;
public FloatProperty jobWeight { get; set; }
public void ProcessRootMotion(AnimationStream stream) {}
public void ProcessAnimation(AnimationStream stream)
{
// Retrieve root and tip rotation.
Quaternion rootRotation = rootTarget.GetRotation(stream);
Quaternion tipRotation = tipTarget.GetRotation(stream);
float mainWeight = jobWeight.Get(stream);
// Interpolate rotation on chain.
for (int i = 0; i < chain.Length; ++i)
{
float weight = Mathf.InverseLerp(0, chain.Length - 1, i);
chain[i].SetRotation(stream, Quaternion.Lerp(chain[i].GetRotation(stream), Quaternion.Lerp(rootRotation, tipRotation, weight), mainWeight));
}
// Update position of tip handle for easier visualization.
rootTarget.SetPosition(stream, chain[0].GetPosition(stream));
tipTarget.SetPosition(stream, chain[chain.Length - 1].GetPosition(stream));
}
}
[System.Serializable]
public struct TwistChainStep1Data : IAnimationJobData
{
public Transform root;
public Transform tip;
[SyncSceneToStream] public Transform rootTarget;
[SyncSceneToStream] public Transform tipTarget;
bool IAnimationJobData.IsValid() => !(root == null || tip == null || !tip.IsChildOf(root) || rootTarget == null || tipTarget == null);
void IAnimationJobData.SetDefaultValues()
{
root = null;
tip = null;
rootTarget = null;
tipTarget = null;
}
}
public class TwistChainStep1JobBinder : AnimationJobBinder<TwistChainStep1Job, TwistChainStep1Data>
{
public override TwistChainStep1Job Create(Animator animator, ref TwistChainStep1Data data, Component component)
{
// Retrieve chain in-between root and tip transforms.
List<Transform> chain = ConstraintsUtils.ExtractChain(data.root, data.tip);
// Build Job.
var job = new TwistChainStep1Job();
job.chain = new NativeArray<ReadWriteTransformHandle>(chain.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
job.rootTarget = ReadWriteTransformHandle.Bind(animator, data.rootTarget);
job.tipTarget = ReadWriteTransformHandle.Bind(animator, data.tipTarget);
for (int i = 0; i < chain.Count; ++i)
job.chain[i] = ReadWriteTransformHandle.Bind(animator, chain[i]);
return job;
}
public override void Destroy(TwistChainStep1Job job)
{
job.chain.Dispose();
}
public override void Update(TwistChainStep1Job job, ref TwistChainStep1Data data)
{
}
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Twist Chain Step 1")]
public class TwistChainStep1 : RigConstraint<
TwistChainStep1Job,
TwistChainStep1Data,
TwistChainStep1JobBinder
>
{
}
}

11
Assets/Constraints/TwistChainStep1.cs.meta


fileFormatVersion: 2
guid: 4b3181e1d19db44d2ac12062bbe9637a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/TwistChainFinal.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/TwistChainFinal.unity.meta


fileFormatVersion: 2
guid: 0cb16aa3c5c8648c8816017d2d05c90c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/TwistChainSetup0.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/TwistChainSetup0.unity.meta


fileFormatVersion: 2
guid: c1f3da45704824609b1ccab1a39e7ce1
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/TwistChainSetup1.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/TwistChainSetup1.unity.meta


fileFormatVersion: 2
guid: 754d363654e3a445cb3b895e7dd301f3
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存