浏览代码

Add first CopyLocation constraint exercise

/main
Olivier Dionne 5 年前
当前提交
c9529601
共有 4 个文件被更改,包括 106 次插入21 次删除
  1. 37
      Assets/Scenes/CopyLocation.unity
  2. 2
      Packages/manifest.json
  3. 77
      Assets/Constraints/CopyLocationStep0.cs
  4. 11
      Assets/Constraints/CopyLocationStep0.cs.meta

37
Assets/Scenes/CopyLocation.unity


m_Component:
- component: {fileID: 1512901161}
- component: {fileID: 1512901163}
- component: {fileID: 1512901162}
- component: {fileID: 1512901164}
m_Layer: 0
m_Name: LeftArm
m_TagString: Untagged

m_Father: {fileID: 1219760734}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1512901162
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1512901160}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 500a29b409189a5449ac7b3fe6d98a88, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Weight: 1
m_Data:
constrainedObject: {fileID: 81240929}
sourceObject: {fileID: 965827090}
xInvert: 1
yInvert: 0
zInvert: 0
--- !u!114 &1512901163
MonoBehaviour:
m_ObjectHideFlags: 0

m_MaintainTargetRotationOffset: 0
m_SourceObjectsGUIToggle: 1
m_SettingsGUIToggle: 0
--- !u!114 &1512901164
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1512901160}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 18bfd3261384fc9479894a4e72ffd52f, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Weight: 1
m_Data:
constrainedObject: {fileID: 81240929}
sourceObject: {fileID: 965827090}
--- !u!1 &1676387290
GameObject:
m_ObjectHideFlags: 0

2
Packages/manifest.json


{
"dependencies": {
"com.unity.animation.rigging": "file:../../com.unity.animation.rigging",
"com.unity.animation.rigging": "file:../../animation-rigging-package-siggraph2019",
"com.unity.collab-proxy": "1.2.16",
"com.unity.ext.nunit": "1.0.0",
"com.unity.ide.rider": "1.0.8",

77
Assets/Constraints/CopyLocationStep0.cs


using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.Experimental.Animations;
using Unity.Burst;
using Unity.Mathematics;
[BurstCompile]
public struct CopyLocationStep0Job : IWeightedAnimationJob
{
public ReadWriteTransformHandle constrained;
public ReadOnlyTransformHandle source;
// TODO : Add invert axis mask
public FloatProperty jobWeight { get; set; }
public void ProcessRootMotion(AnimationStream stream) { }
public void ProcessAnimation(AnimationStream stream)
{
float w = jobWeight.Get(stream);
if (w > 0f)
{
// TODO : Change code to consider inverted axis positions instead
constrained.SetPosition(
stream,
math.lerp(constrained.GetPosition(stream), -source.GetPosition(stream), w)
);
}
}
}
[System.Serializable]
public struct CopyLocationStep0Data : IAnimationJobData
{
public Transform constrainedObject;
[SyncSceneToStream] public Transform sourceObject;
// TODO : Add invert axis booleans
public bool IsValid()
{
return !(constrainedObject == null || sourceObject == null);
}
public void SetDefaultValues()
{
constrainedObject = null;
sourceObject = null;
// TODO : Set initial values to invert booleans
}
}
public class CopyLocationStep0Binder : AnimationJobBinder<CopyLocationStep0Job, CopyLocationStep0Data>
{
public override CopyLocationStep0Job Create(Animator animator, ref CopyLocationStep0Data data, Component component)
{
return new CopyLocationStep0Job()
{
constrained = ReadWriteTransformHandle.Bind(animator, data.constrainedObject),
source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject)
};
}
public override void Destroy(CopyLocationStep0Job job) { }
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Copy Location (Step 0)")]
public class CopyLocationStep0 : RigConstraint<
CopyLocationStep0Job,
CopyLocationStep0Data,
CopyLocationStep0Binder
>
{
}

11
Assets/Constraints/CopyLocationStep0.cs.meta


fileFormatVersion: 2
guid: 18bfd3261384fc9479894a4e72ffd52f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存