public void ProcessAnimation(AnimationStream stream) { float w = jobWeight.Get(stream); if (w > 0f) { AnimationStreamHandleUtility.ReadFloats(stream, sourceWeights, weightBuffer); float sumWeights = AnimationRuntimeUtils.Sum(weightBuffer); if (sumWeights < k_Epsilon) { AnimationRuntimeUtils.PassThrough(stream, driven); return; } float weightScale = sumWeights > 1f ? 1f / sumWeights : 1f; Vector2 minMaxAngles = new Vector2(minLimit.Get(stream), maxLimit.Get(stream)); var drivenWPos = driven.GetPosition(stream); var drivenLRot = driven.GetLocalRotation(stream); var drivenParentInvRot = Quaternion.Inverse(drivenParent.GetRotation(stream)); Quaternion accumDeltaRot = QuaternionExt.zero; var fromDir = drivenLRot * aimAxis; float accumWeights = 0f; for (int i = 0; i < sourceTransforms.Length; ++i) { var normalizedWeight = weightBuffer[i] * weightScale; if (normalizedWeight < k_Epsilon) { continue; } ReadOnlyTransformHandle sourceTransform = sourceTransforms[i]; var toDir = drivenParentInvRot * (sourceTransform.GetPosition(stream) - drivenWPos); if (toDir.sqrMagnitude < k_Epsilon) { continue; } var crossDir = Vector3.Cross(fromDir, toDir).normalized; if (Vector3.Dot(axesMask, axesMask) < 3f) { crossDir = AnimationRuntimeUtils.Select(Vector3.zero, crossDir, axesMask).normalized; if (Vector3.Dot(crossDir, crossDir) > k_Epsilon) { fromDir = AnimationRuntimeUtils.ProjectOnPlane(fromDir, crossDir); toDir = AnimationRuntimeUtils.ProjectOnPlane(toDir, crossDir); } else { toDir = fromDir; } } var rotToSource = Quaternion.AngleAxis( Mathf.Clamp(Vector3.Angle(fromDir, toDir), minMaxAngles.x, minMaxAngles.y), crossDir ); accumDeltaRot = QuaternionExt.Add( accumDeltaRot, QuaternionExt.Scale(sourceOffsets[i] * rotToSource, normalizedWeight) ); // Required to update handles with binding info. sourceTransforms[i] = sourceTransform; accumWeights += normalizedWeight; } accumDeltaRot = QuaternionExt.NormalizeSafe(accumDeltaRot); if (accumWeights < 1f) { accumDeltaRot = Quaternion.Lerp(Quaternion.identity, accumDeltaRot, accumWeights); } Quaternion newRot = accumDeltaRot * drivenLRot; if (Vector3.Dot(axesMask, axesMask) < 3f) { newRot = Quaternion.Euler(AnimationRuntimeUtils.Select(drivenLRot.eulerAngles, newRot.eulerAngles, axesMask)); } var offset = drivenOffset.Get(stream); if (Vector3.Dot(offset, offset) > 0f) { newRot *= Quaternion.Euler(offset); } driven.SetLocalRotation(stream, Quaternion.Lerp(drivenLRot, newRot, w)); } else { AnimationRuntimeUtils.PassThrough(stream, driven); } }