first commit

This commit is contained in:
lethanhsonvsp
2025-11-17 15:16:36 +07:00
commit a40d0921eb
17012 changed files with 2652386 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
using Unity.Collections;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The MultiAim inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct MultiAimInverseConstraintJob : IWeightedAnimationJob
{
const float k_Epsilon = 1e-5f;
/// <summary>The Transform handle for the constrained object Transform.</summary>
public ReadOnlyTransformHandle driven;
/// <summary>The Transform handle for the constrained object parent Transform.</summary>
public ReadOnlyTransformHandle drivenParent;
/// <summary>The post-rotation offset applied to the constrained object.</summary>
public Vector3Property drivenOffset;
/// <summary>List of Transform handles for the source objects.</summary>
public NativeArray<ReadWriteTransformHandle> sourceTransforms;
/// <summary>List of weights for the source objects.</summary>
public NativeArray<PropertyStreamHandle> sourceWeights;
/// <summary>List of offsets to apply to source rotations if maintainOffset is enabled.</summary>
public NativeArray<Quaternion> sourceOffsets;
/// <summary>Buffer used to store weights during job execution.</summary>
public NativeArray<float> weightBuffer;
/// <summary>Local axis of the constrained object Transform.</summary>
public Vector3 aimAxis;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
var lRot = driven.GetLocalRotation(stream);
var offset = drivenOffset.Get(stream);
if (Vector3.Dot(offset, offset) > 0f)
lRot *= Quaternion.Inverse(Quaternion.Euler(offset));
var localToWorld = Quaternion.identity;
var wPos = driven.GetPosition(stream);
if (drivenParent.IsValid(stream))
localToWorld = drivenParent.GetRotation(stream);
for (int i = 0; i < sourceTransforms.Length; ++i)
{
sourceWeights[i].SetFloat(stream, 1f);
var sourceTransform = sourceTransforms[i];
sourceTransform.SetPosition(stream, wPos + localToWorld * sourceOffsets[i] * lRot * aimAxis);
// Required to update handles with binding info.
sourceTransforms[i] = sourceTransform;
}
}
}
/// <summary>
/// The MultiAim inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class MultiAimInverseConstraintJobBinder<T> : AnimationJobBinder<MultiAimInverseConstraintJob, T>
where T : struct, IAnimationJobData, IMultiAimConstraintData
{
/// <inheritdoc />
public override MultiAimInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new MultiAimInverseConstraintJob();
job.driven = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);
job.aimAxis = data.aimAxis;
WeightedTransformArray sourceObjects = data.sourceObjects;
WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);
job.sourceOffsets = new NativeArray<Quaternion>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
for (int i = 0; i < sourceObjects.Count; ++i)
{
if (data.maintainOffset)
{
var aimDirection = data.constrainedObject.rotation * data.aimAxis;
var dataToSource = sourceObjects[i].transform.position - data.constrainedObject.position;
var rot = QuaternionExt.FromToRotation(dataToSource, aimDirection);
job.sourceOffsets[i] = Quaternion.Inverse(rot);
}
else
{
job.sourceOffsets[i] = Quaternion.identity;
}
}
job.weightBuffer = new NativeArray<float>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
return job;
}
/// <inheritdoc />
public override void Destroy(MultiAimInverseConstraintJob job)
{
job.sourceTransforms.Dispose();
job.sourceWeights.Dispose();
job.sourceOffsets.Dispose();
job.weightBuffer.Dispose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 05face438934c204d87b0e772c7c0a71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,116 @@
using Unity.Collections;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The MultiParent inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct MultiParentInverseConstraintJob : IWeightedAnimationJob
{
const float k_Epsilon = 1e-5f;
/// <summary>The Transform handle for the constrained object Transform.</summary>
public ReadOnlyTransformHandle driven;
/// <summary>The Transform handle for the constrained object parent Transform.</summary>
public ReadOnlyTransformHandle drivenParent;
/// <summary>List of Transform handles for the source objects.</summary>
public NativeArray<ReadWriteTransformHandle> sourceTransforms;
/// <summary>List of weights for the source objects.</summary>
public NativeArray<PropertyStreamHandle> sourceWeights;
/// <summary>List of offsets to apply to source rotations if maintainOffset is enabled.</summary>
public NativeArray<AffineTransform> sourceOffsets;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
driven.GetGlobalTR(stream, out Vector3 currentWPos, out Quaternion currentWRot);
var drivenTx = new AffineTransform(currentWPos, currentWRot);
for (int i = 0; i < sourceTransforms.Length; ++i)
{
sourceWeights[i].SetFloat(stream, 1f);
var sourceTransform = sourceTransforms[i];
sourceTransform.GetGlobalTR(stream, out var sourcePosition, out var sourceRotation);
var result = drivenTx;
result *= sourceOffsets[i];
sourceTransform.SetGlobalTR(stream, result.translation, result.rotation);
sourceTransforms[i] = sourceTransform;
}
}
}
/// <summary>
/// The MultiParent inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class MultiParentInverseConstraintJobBinder<T> : AnimationJobBinder<MultiParentInverseConstraintJob, T>
where T : struct, IAnimationJobData, IMultiParentConstraintData
{
/// <inheritdoc />
public override MultiParentInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new MultiParentInverseConstraintJob();
job.driven = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
WeightedTransformArray sourceObjects = data.sourceObjects;
WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);
job.sourceOffsets = new NativeArray<AffineTransform>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
var drivenTx = new AffineTransform(data.constrainedObject.position, data.constrainedObject.rotation);
for (int i = 0; i < sourceObjects.Count; ++i)
{
var sourceTransform = sourceObjects[i].transform;
var srcTx = new AffineTransform(sourceTransform.position, sourceTransform.rotation);
var srcOffset = AffineTransform.identity;
var tmp = srcTx.InverseMul(drivenTx);
if (data.maintainPositionOffset)
srcOffset.translation = tmp.translation;
if (data.maintainRotationOffset)
srcOffset.rotation = tmp.rotation;
srcOffset = srcOffset.Inverse();
job.sourceOffsets[i] = srcOffset;
}
return job;
}
/// <inheritdoc />
public override void Destroy(MultiParentInverseConstraintJob job)
{
job.sourceTransforms.Dispose();
job.sourceWeights.Dispose();
job.sourceOffsets.Dispose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 288c55302720e3e498d76fcd7909373d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,116 @@
using Unity.Collections;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The MultiPosition inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct MultiPositionInverseConstraintJob : IWeightedAnimationJob
{
const float k_Epsilon = 1e-5f;
/// <summary>The Transform handle for the constrained object Transform.</summary>
public ReadOnlyTransformHandle driven;
/// <summary>The Transform handle for the constrained object parent Transform.</summary>
public ReadOnlyTransformHandle drivenParent;
/// <summary>The post-translation offset applied to the constrained object.</summary>
public Vector3Property drivenOffset;
/// <summary>List of Transform handles for the source objects.</summary>
public NativeArray<ReadWriteTransformHandle> sourceTransforms;
/// <summary>List of weights for the source objects.</summary>
public NativeArray<PropertyStreamHandle> sourceWeights;
/// <summary>List of offsets to apply to source rotations if maintainOffset is enabled.</summary>
public NativeArray<Vector3> sourceOffsets;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
var parentTx = new AffineTransform();
if (drivenParent.IsValid(stream))
{
drivenParent.GetGlobalTR(stream, out Vector3 parentWPos, out Quaternion parentWRot);
parentTx = new AffineTransform(parentWPos, parentWRot);
}
var drivenPos = driven.GetPosition(stream);
drivenPos = parentTx.InverseTransform(drivenPos);
var offset = drivenOffset.Get(stream);
var lPos = drivenPos - offset;
var wPos = parentTx.Transform(lPos);
for (int i = 0; i < sourceTransforms.Length; ++i)
{
sourceWeights[i].SetFloat(stream, 1f);
ReadWriteTransformHandle sourceTransform = sourceTransforms[i];
sourceTransform.SetPosition(stream, wPos - sourceOffsets[i]);
// Required to update handles with binding info.
sourceTransforms[i] = sourceTransform;
}
}
}
/// <summary>
/// The MultiPosition inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class MultiPositionInverseConstraintJobBinder<T> : AnimationJobBinder<MultiPositionInverseConstraintJob, T>
where T : struct, IAnimationJobData, IMultiPositionConstraintData
{
/// <inheritdoc />
public override MultiPositionInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new MultiPositionInverseConstraintJob();
job.driven = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);
WeightedTransformArray sourceObjects = data.sourceObjects;
WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);
job.sourceOffsets = new NativeArray<Vector3>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
Vector3 drivenPos = data.constrainedObject.position;
for (int i = 0; i < sourceObjects.Count; ++i)
{
job.sourceOffsets[i] = data.maintainOffset ? (drivenPos - sourceObjects[i].transform.position) : Vector3.zero;
}
return job;
}
/// <inheritdoc />
public override void Destroy(MultiPositionInverseConstraintJob job)
{
job.sourceTransforms.Dispose();
job.sourceWeights.Dispose();
job.sourceOffsets.Dispose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd9bd1ef777641d4b8ec163f15579bf2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,96 @@
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
using Unity.Collections;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The MultiReferential inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct MultiReferentialInverseConstraintJob : IWeightedAnimationJob
{
/// <summary>The list of Transforms that are affected by the specified driver.</summary>
public NativeArray<ReadWriteTransformHandle> sources;
/// <summary>List of AffineTransform to apply to driven source objects.</summary>
public NativeArray<AffineTransform> offsetTx;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
sources[0].GetGlobalTR(stream, out Vector3 driverWPos, out Quaternion driverWRot);
var driverTx = new AffineTransform(driverWPos, driverWRot);
int offset = 0;
for (int i = 1; i < sources.Length; ++i)
{
var tx = driverTx * offsetTx[offset];
var src = sources[i];
src.GetGlobalTR(stream, out Vector3 srcWPos, out Quaternion srcWRot);
src.SetGlobalTR(stream, tx.translation, tx.rotation);
offset++;
sources[i] = src;
}
}
}
/// <summary>
/// The MultiReferential inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class MultiReferentialInverseConstraintJobBinder<T> : AnimationJobBinder<MultiReferentialInverseConstraintJob, T>
where T : struct, IAnimationJobData, IMultiReferentialConstraintData
{
/// <inheritdoc />
public override MultiReferentialInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new MultiReferentialInverseConstraintJob();
var sources = data.sourceObjects;
job.sources = new NativeArray<ReadWriteTransformHandle>(sources.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
job.offsetTx = new NativeArray<AffineTransform>(sources.Length - 1, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
var sourceBindTx = new AffineTransform[sources.Length];
for (int i = 0; i < sources.Length; ++i)
{
job.sources[i] = ReadWriteTransformHandle.Bind(animator, sources[i].transform);
sourceBindTx[i] = new AffineTransform(sources[i].position, sources[i].rotation);
}
int offset = 0;
var invDriverTx = sourceBindTx[0].Inverse();
for (int i = 1; i < sourceBindTx.Length; ++i)
{
job.offsetTx[offset] = invDriverTx * sourceBindTx[i];
offset++;
}
return job;
}
/// <inheritdoc />
public override void Destroy(MultiReferentialInverseConstraintJob job)
{
job.sources.Dispose();
job.offsetTx.Dispose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 07e9ec99cb928a0428b3391e587dfa9c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
using Unity.Collections;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The MultiRotation inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct MultiRotationInverseConstraintJob : IWeightedAnimationJob
{
const float k_Epsilon = 1e-5f;
/// <summary>The Transform handle for the constrained object Transform.</summary>
public ReadOnlyTransformHandle driven;
/// <summary>The Transform handle for the constrained object parent Transform.</summary>
public ReadOnlyTransformHandle drivenParent;
/// <summary>The post-rotation offset applied to the constrained object.</summary>
public Vector3Property drivenOffset;
/// <summary>List of Transform handles for the source objects.</summary>
public NativeArray<ReadWriteTransformHandle> sourceTransforms;
/// <summary>List of weights for the source objects.</summary>
public NativeArray<PropertyStreamHandle> sourceWeights;
/// <summary>List of offsets to apply to source rotations if maintainOffset is enabled.</summary>
public NativeArray<Quaternion> sourceOffsets;
/// <summary>Buffer used to store weights during job execution.</summary>
public NativeArray<float> weightBuffer;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
var lRot = driven.GetLocalRotation(stream);
var offset = drivenOffset.Get(stream);
if (Vector3.Dot(offset, offset) > 0f)
lRot *= Quaternion.Inverse(Quaternion.Euler(offset));
var wRot = lRot;
if (drivenParent.IsValid(stream))
{
wRot = drivenParent.GetRotation(stream) * wRot;
}
for (int i = 0; i < sourceTransforms.Length; ++i)
{
sourceWeights[i].SetFloat(stream, 1f);
ReadWriteTransformHandle sourceTransform = sourceTransforms[i];
sourceTransform.SetRotation(stream, wRot * sourceOffsets[i]);
// Required to update handles with binding info.
sourceTransforms[i] = sourceTransform;
}
}
}
/// <summary>
/// The MultiRotation inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class MultiRotationInverseConstraintJobBinder<T> : AnimationJobBinder<MultiRotationInverseConstraintJob, T>
where T : struct, IAnimationJobData, IMultiRotationConstraintData
{
/// <inheritdoc />
public override MultiRotationInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new MultiRotationInverseConstraintJob();
job.driven = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);
WeightedTransformArray sourceObjects = data.sourceObjects;
WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);
job.sourceOffsets = new NativeArray<Quaternion>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
job.weightBuffer = new NativeArray<float>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
Quaternion drivenRotInv = Quaternion.Inverse(data.constrainedObject.rotation);
for (int i = 0; i < sourceObjects.Count; ++i)
{
job.sourceOffsets[i] = data.maintainOffset ?
(drivenRotInv * sourceObjects[i].transform.rotation) : Quaternion.identity;
}
return job;
}
/// <inheritdoc />
public override void Destroy(MultiRotationInverseConstraintJob job)
{
job.sourceTransforms.Dispose();
job.sourceWeights.Dispose();
job.sourceOffsets.Dispose();
job.weightBuffer.Dispose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e68f0e2daa979074da79ea4fa6e40660
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The TwistChain inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct TwistChainInverseConstraintJob : IWeightedAnimationJob
{
/// <summary>The Transform handle for the root Transform of the chain.</summary>
public ReadOnlyTransformHandle root;
/// <summary>The Transform handle for the tip Transform of the chain.</summary>
public ReadOnlyTransformHandle tip;
/// <summary>The Transform handle for the root target Transform.</summary>
public ReadWriteTransformHandle rootTarget;
/// <summary>The Transform handle for the tip target Transform.</summary>
public ReadWriteTransformHandle tipTarget;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
rootTarget.SetPosition(stream, root.GetPosition(stream));
rootTarget.SetRotation(stream, root.GetRotation(stream));
tipTarget.SetPosition(stream, tip.GetPosition(stream));
tipTarget.SetRotation(stream, tip.GetRotation(stream));
}
}
/// <summary>
/// The TwistChain inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class TwistChainInverseConstraintJobBinder<T> : AnimationJobBinder<TwistChainInverseConstraintJob, T>
where T : struct, IAnimationJobData, ITwistChainConstraintData
{
/// <inheritdoc />
public override TwistChainInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new TwistChainInverseConstraintJob();
job.root = ReadOnlyTransformHandle.Bind(animator, data.root);
job.tip = ReadOnlyTransformHandle.Bind(animator, data.tip);
job.rootTarget = ReadWriteTransformHandle.Bind(animator, data.rootTarget);
job.tipTarget = ReadWriteTransformHandle.Bind(animator, data.tipTarget);
return job;
}
/// <inheritdoc />
public override void Destroy(TwistChainInverseConstraintJob job)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c669908f1bcf4a829cb78b6398d008f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,99 @@
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
/// <summary>
/// The TwoBoneIK inverse constraint job.
/// </summary>
[Unity.Burst.BurstCompile]
public struct TwoBoneIKInverseConstraintJob : IWeightedAnimationJob
{
const float k_SqrEpsilon = 1e-8f;
/// <summary>The transform handle for the root transform.</summary>
public ReadOnlyTransformHandle root;
/// <summary>The transform handle for the mid transform.</summary>
public ReadOnlyTransformHandle mid;
/// <summary>The transform handle for the tip transform.</summary>
public ReadOnlyTransformHandle tip;
/// <summary>The transform handle for the hint transform.</summary>
public ReadWriteTransformHandle hint;
/// <summary>The transform handle for the target transform.</summary>
public ReadWriteTransformHandle target;
/// <summary>The offset applied to the target transform if maintainTargetPositionOffset or maintainTargetRotationOffset is enabled.</summary>
public AffineTransform targetOffset;
/// <summary>The weight for which target position has an effect on IK calculations. This is a value in between 0 and 1.</summary>
public FloatProperty targetPositionWeight;
/// <summary>The weight for which target rotation has an effect on IK calculations. This is a value in between 0 and 1.</summary>
public FloatProperty targetRotationWeight;
/// <summary>The weight for which hint transform has an effect on IK calculations. This is a value in between 0 and 1.</summary>
public FloatProperty hintWeight;
/// <inheritdoc />
public FloatProperty jobWeight { get; set; }
/// <summary>
/// Defines what to do when processing the root motion.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessRootMotion(AnimationStream stream) { }
/// <summary>
/// Defines what to do when processing the animation.
/// </summary>
/// <param name="stream">The animation stream to work on.</param>
public void ProcessAnimation(AnimationStream stream)
{
jobWeight.Set(stream, 1f);
AnimationRuntimeUtils.InverseSolveTwoBoneIK(stream, root, mid, tip, target, hint,
targetPositionWeight.Get(stream),
targetRotationWeight.Get(stream),
hintWeight.Get(stream), targetOffset);
}
}
/// <summary>
/// The TwoBoneIK inverse constraint job binder.
/// </summary>
/// <typeparam name="T">The constraint data type</typeparam>
public class TwoBoneIKInverseConstraintJobBinder<T> : AnimationJobBinder<TwoBoneIKInverseConstraintJob, T>
where T : struct, IAnimationJobData, ITwoBoneIKConstraintData
{
/// <inheritdoc />
public override TwoBoneIKInverseConstraintJob Create(Animator animator, ref T data, Component component)
{
var job = new TwoBoneIKInverseConstraintJob();
job.root = ReadOnlyTransformHandle.Bind(animator, data.root);
job.mid = ReadOnlyTransformHandle.Bind(animator, data.mid);
job.tip = ReadOnlyTransformHandle.Bind(animator, data.tip);
job.target = ReadWriteTransformHandle.Bind(animator, data.target);
if (data.hint != null)
job.hint = ReadWriteTransformHandle.Bind(animator, data.hint);
job.targetOffset = AffineTransform.identity;
if (data.maintainTargetPositionOffset)
job.targetOffset.translation = -(data.tip.position - data.target.position);
if (data.maintainTargetRotationOffset)
job.targetOffset.rotation = Quaternion.Inverse(data.tip.rotation) * data.target.rotation;
job.targetPositionWeight = FloatProperty.Bind(animator, component, data.targetPositionWeightFloatProperty);
job.targetRotationWeight = FloatProperty.Bind(animator, component, data.targetRotationWeightFloatProperty);
job.hintWeight = FloatProperty.Bind(animator, component, data.hintWeightFloatProperty);
return job;
}
/// <inheritdoc />
public override void Destroy(TwoBoneIKInverseConstraintJob job)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 97b56b4e0dccdff47b19d995fcc12954
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: