浏览代码

Merge branch 'master' of github.com:Unity-Technologies/animation-rigging-workshop-siggraph2019

/main
Dave Hunt 5 年前
当前提交
146127c8
共有 14 个文件被更改,包括 1156 次插入58 次删除
  1. 14
      Assets/AnimationRiggingWorkshop/Constraints/TwistChain.cs
  2. 2
      Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep0.cs
  3. 31
      Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep1.cs
  4. 2
      Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep1.cs.meta
  5. 8
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep1.unity
  6. 2
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep1.unity.meta
  7. 30
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep2.unity
  8. 2
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep2.unity.meta
  9. 104
      Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep2.cs
  10. 11
      Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep2.cs.meta
  11. 1001
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainFinal.unity
  12. 7
      Assets/AnimationRiggingWorkshop/Scenes/TwistChainFinal.unity.meta
  13. 0
      /Assets/AnimationRiggingWorkshop/Scenes/TwistChainExtra.unity.meta
  14. 0
      /Assets/AnimationRiggingWorkshop/Scenes/TwistChainExtra.unity

14
Assets/AnimationRiggingWorkshop/Constraints/TwistChain.cs


// Retrieve chain in-between root and tip transforms.
Transform[] chain = ConstraintsUtils.ExtractChain(data.root, data.tip);
// Extract steps from chain.
float[] steps = ConstraintsUtils.ExtractSteps(chain);
// Build Job.
var job = new TwistChainJob();
job.chain = new NativeArray<ReadWriteTransformHandle>(chain.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

job.tipTarget = ReadWriteTransformHandle.Bind(animator, data.tipTarget);
// Set values in NativeArray.
}
// Extract steps from chain.
float[] steps = ConstraintsUtils.ExtractSteps(chain);
// Update weights based on curve.
for (int i = 0; i < steps.Length; ++i)
{
job.steps[i] = steps[i];
job.weights[i] = Mathf.Clamp01(data.curve.Evaluate(steps[i]));
}

}
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Twist Chain")]
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Twist Chain Final")]
public class TwistChain : RigConstraint<
TwistChainJob,
TwistChainData,

2
Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep0.cs


public NativeArray<ReadWriteTransformHandle> chain;
public NativeArray<float> steps;
public FloatProperty jobWeight { get; set; }
public void ProcessRootMotion(AnimationStream stream) {}

31
Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep1.cs


public NativeArray<ReadWriteTransformHandle> chain;
public NativeArray<float> steps;
public FloatProperty jobWeight { get; set; }
public void ProcessRootMotion(AnimationStream stream) {}

// Retrieve root and tip rotation.
Quaternion rootRotation = rootTarget.GetRotation(stream);
Quaternion tipRotation = tipTarget.GetRotation(stream);
// 1. Retrieve root and tip rotation.
// ...
float mainWeight = jobWeight.Get(stream);
// 2. Interpolate rotation on chain.
// ...
// 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));
// 3. Update position of tip handle for easier visualization.
// ...
}
}

// Retrieve chain in-between root and tip transforms.
Transform[] chain = ConstraintsUtils.ExtractChain(data.root, data.tip);
// Extract steps from chain.
float[] steps = ConstraintsUtils.ExtractSteps(chain);
job.steps = new NativeArray<float>(chain.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
// Set values in NativeArray.
{
job.steps[i] = steps[i];
}
return job;
}

job.chain.Dispose();
}
public override void Update(TwistChainStep1Job job, ref TwistChainStep1Data data)

2
Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep1.cs.meta


fileFormatVersion: 2
guid: 4b3181e1d19db44d2ac12062bbe9637a
guid: 214e6c409b6044a21b37069da349a342
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep1.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 2138677392}
m_IndirectSpecularColor: {r: 0.28502664, g: 0.37139288, b: 0.4960104, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

serializedVersion: 6
m_Component:
- component: {fileID: 1799980151}
- component: {fileID: 1799980153}
- component: {fileID: 1799980152}
m_Layer: 0
m_Name: Twist
m_TagString: Untagged

m_Father: {fileID: 404418314}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1799980153
--- !u!114 &1799980152
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4b3181e1d19db44d2ac12062bbe9637a, type: 3}
m_Script: {fileID: 11500000, guid: 214e6c409b6044a21b37069da349a342, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Weight: 1

2
Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep1.unity.meta


fileFormatVersion: 2
guid: b79fd49596d1243ce932098d72141bc5
guid: d369f59a4b18c47d8991e7fb8fbcbed3
DefaultImporter:
externalObjects: {}
userData:

30
Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep2.unity


serializedVersion: 6
m_Component:
- component: {fileID: 1799980151}
- component: {fileID: 1799980152}
- component: {fileID: 1799980153}
m_Layer: 0
m_Name: Twist
m_TagString: Untagged

m_Father: {fileID: 404418314}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1799980152
--- !u!114 &1799980153
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4fcd34ca23da4161af706723275104f, type: 3}
m_Script: {fileID: 11500000, guid: 4b3181e1d19db44d2ac12062bbe9637a, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Weight: 1

rootTarget: {fileID: 854090494}
tipTarget: {fileID: 212552606}
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 1
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
inSlope: 1
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &1849984684
GameObject:
m_ObjectHideFlags: 0

2
Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep2.unity.meta


fileFormatVersion: 2
guid: 691e854e5e9cf4ef19eac00eadc7eccc
guid: b79fd49596d1243ce932098d72141bc5
DefaultImporter:
externalObjects: {}
userData:

104
Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep2.cs


using System.Collections.Generic;
using Unity.Collections;
namespace UnityEngine.Animations.Rigging
{
using Experimental.Animations;
[Unity.Burst.BurstCompile]
public struct TwistChainStep2Job : IWeightedAnimationJob
{
public ReadWriteTransformHandle rootTarget;
public ReadWriteTransformHandle tipTarget;
public NativeArray<ReadWriteTransformHandle> chain;
public NativeArray<float> steps;
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)
{
chain[i].SetRotation(stream, Quaternion.Lerp(chain[i].GetRotation(stream), Quaternion.Lerp(rootRotation, tipRotation, steps[i]), 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 TwistChainStep2Data : 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 = tip = rootTarget = tipTarget = null;
}
}
public class TwistChainStep2JobBinder : AnimationJobBinder<TwistChainStep2Job, TwistChainStep2Data>
{
public override TwistChainStep2Job Create(Animator animator, ref TwistChainStep2Data data, Component component)
{
// Retrieve chain in-between root and tip transforms.
Transform[] chain = ConstraintsUtils.ExtractChain(data.root, data.tip);
// Extract steps from chain.
float[] steps = ConstraintsUtils.ExtractSteps(chain);
// Build Job.
var job = new TwistChainStep2Job();
job.chain = new NativeArray<ReadWriteTransformHandle>(chain.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
job.steps = new NativeArray<float>(chain.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
job.rootTarget = ReadWriteTransformHandle.Bind(animator, data.rootTarget);
job.tipTarget = ReadWriteTransformHandle.Bind(animator, data.tipTarget);
// Set values in NativeArray.
for (int i = 0; i < chain.Length; ++i)
{
job.chain[i] = ReadWriteTransformHandle.Bind(animator, chain[i]);
job.steps[i] = steps[i];
}
return job;
}
public override void Destroy(TwistChainStep2Job job)
{
job.chain.Dispose();
}
public override void Update(TwistChainStep2Job job, ref TwistChainStep2Data data)
{
}
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Twist Chain Step 2")]
public class TwistChainStep2 : RigConstraint<
TwistChainStep2Job,
TwistChainStep2Data,
TwistChainStep2JobBinder
>
{
}
}

11
Assets/AnimationRiggingWorkshop/Constraints/TwistChainStep2.cs.meta


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

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

7
Assets/AnimationRiggingWorkshop/Scenes/TwistChainFinal.unity.meta


fileFormatVersion: 2
guid: 691e854e5e9cf4ef19eac00eadc7eccc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep3.unity.meta → /Assets/AnimationRiggingWorkshop/Scenes/TwistChainExtra.unity.meta

/Assets/AnimationRiggingWorkshop/Scenes/TwistChainStep3.unity → /Assets/AnimationRiggingWorkshop/Scenes/TwistChainExtra.unity

正在加载...
取消
保存