-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathCopyLocationStep0.cs
79 lines (64 loc) · 2.12 KB
/
CopyLocationStep0.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.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)
// TODO : Update binder code to add our new toggles
};
}
public override void Destroy(CopyLocationStep0Job job) { }
}
[DisallowMultipleComponent, AddComponentMenu("SIGGRAPH 2019/Copy Location (Step 0)")]
public class CopyLocationStep0 : RigConstraint<
CopyLocationStep0Job,
CopyLocationStep0Data,
CopyLocationStep0Binder
>
{
}