public void ProcessAnimation(AnimationStream stream) { float jobWeight = stream.GetInputWeight(0); if (jobWeight > 0f) { AffineTransform overrideTx; if (source.IsValid(stream)) { var sourceLocalTx = new AffineTransform(source.GetLocalPosition(stream), source.GetLocalRotation(stream)); var sourceToSpaceRot = cache.Get <Quaternion>(sourceToCurrSpaceRotIdx); overrideTx = Quaternion.Inverse(sourceToSpaceRot) * (sourceInvLocalBindTx * sourceLocalTx) * sourceToSpaceRot; } else { overrideTx = new AffineTransform(cache.Get <Vector3>(positionIdx), Quaternion.Euler(cache.Get <Vector3>(rotationIdx))); } Space overrideSpace = (Space)cache.GetRaw(spaceIdx); var posW = cache.GetRaw(positionWeightIdx) * jobWeight; var rotW = cache.GetRaw(rotationWeightIdx) * jobWeight; switch (overrideSpace) { case Space.World: driven.SetPosition(stream, Vector3.Lerp(driven.GetPosition(stream), overrideTx.translation, posW)); driven.SetRotation(stream, Quaternion.Lerp(driven.GetRotation(stream), overrideTx.rotation, rotW)); break; case Space.Local: driven.SetLocalPosition(stream, Vector3.Lerp(driven.GetLocalPosition(stream), overrideTx.translation, posW)); driven.SetLocalRotation(stream, Quaternion.Lerp(driven.GetLocalRotation(stream), overrideTx.rotation, rotW)); break; case Space.Pivot: var drivenLocalTx = new AffineTransform(driven.GetLocalPosition(stream), driven.GetLocalRotation(stream)); overrideTx = drivenLocalTx * overrideTx; driven.SetLocalPosition(stream, Vector3.Lerp(drivenLocalTx.translation, overrideTx.translation, posW)); driven.SetLocalRotation(stream, Quaternion.Lerp(drivenLocalTx.rotation, overrideTx.rotation, rotW)); break; default: break; } } else { AnimationRuntimeUtils.PassThrough(stream, driven); } }
public void ProcessAnimation(AnimationStream stream) { float jobWeight = stream.GetInputWeight(0); if (jobWeight > 0f) { float sumWeights = AnimationRuntimeUtils.Sum(cache, sourceWeightStartIdx, sources.Length); if (sumWeights < k_Epsilon) { return; } float weightScale = sumWeights > 1f ? 1f / sumWeights : 1f; Vector3 currentWPos = driven.GetPosition(stream); Quaternion currentWRot = driven.GetRotation(stream); var accumTx = new AffineTransform(currentWPos, currentWRot); for (int i = 0; i < sources.Length; ++i) { var normalizedWeight = cache.GetRaw(sourceWeightStartIdx, i) * weightScale; if (normalizedWeight < k_Epsilon) { continue; } var sourceTx = new AffineTransform(sources[i].GetPosition(stream), sources[i].GetRotation(stream)); sourceTx *= sourceOffsets[i]; accumTx.rotation = Quaternion.Lerp(accumTx.rotation, sourceTx.rotation, normalizedWeight); accumTx.translation += (sourceTx.translation - currentWPos) * normalizedWeight; } // Convert accumTx to local space if (drivenParent.IsValid(stream)) { var parentTx = new AffineTransform(drivenParent.GetPosition(stream), drivenParent.GetRotation(stream)); accumTx = parentTx.InverseMul(accumTx); } Vector3 currentLPos = driven.GetLocalPosition(stream); Quaternion currentLRot = driven.GetLocalRotation(stream); if (Vector3.Dot(positionAxesMask, positionAxesMask) < 3f) { accumTx.translation = AnimationRuntimeUtils.Lerp(currentLPos, accumTx.translation, positionAxesMask); } if (Vector3.Dot(rotationAxesMask, rotationAxesMask) < 3f) { accumTx.rotation = Quaternion.Euler(AnimationRuntimeUtils.Lerp(currentLRot.eulerAngles, accumTx.rotation.eulerAngles, rotationAxesMask)); } driven.SetLocalPosition(stream, Vector3.Lerp(currentLPos, accumTx.translation, jobWeight)); driven.SetLocalRotation(stream, Quaternion.Lerp(currentLRot, accumTx.rotation, jobWeight)); } else { AnimationRuntimeUtils.PassThrough(stream, driven); } }
public void ProcessAnimation(AnimationStream stream) { float jobWeight = stream.GetInputWeight(0); if (jobWeight > 0f) { float sumWeights = AnimationRuntimeUtils.Sum(cache, sourceWeightStartIdx, sources.Length); if (sumWeights < k_Epsilon) { return; } float weightScale = sumWeights > 1f ? 1f / sumWeights : 1f; Vector3 currentWPos = driven.GetPosition(stream); Vector3 accumPos = currentWPos; for (int i = 0; i < sources.Length; ++i) { var normalizedWeight = cache.GetRaw(sourceWeightStartIdx, i) * weightScale; if (normalizedWeight < k_Epsilon) { continue; } accumPos += (sources[i].GetPosition(stream) + sourceOffsets[i] - currentWPos) * normalizedWeight; } // Convert accumPos to local space if (drivenParent.IsValid(stream)) { var parentTx = new AffineTransform(drivenParent.GetPosition(stream), drivenParent.GetRotation(stream)); accumPos = parentTx.InverseTransform(accumPos); } Vector3 currentLPos = driven.GetLocalPosition(stream); if (Vector3.Dot(axesMask, axesMask) < 3f) { accumPos = AnimationRuntimeUtils.Lerp(currentLPos, accumPos, axesMask); } driven.SetLocalPosition(stream, Vector3.Lerp(currentLPos, accumPos + cache.Get <Vector3>(drivenOffsetIdx), jobWeight)); } else { AnimationRuntimeUtils.PassThrough(stream, driven); } }
public void ProcessAnimation(AnimationStream stream) { float jobWeight = stream.GetInputWeight(0); if (jobWeight > 0f) { var flags = (int)cache.GetRaw(optionsIdx); if ((flags & k_BlendTranslationMask) != 0) { Vector3 posBlend = Vector3.Lerp( sourceA.GetPosition(stream) + sourceAOffset.translation, sourceB.GetPosition(stream) + sourceBOffset.translation, cache.GetRaw(positionWeightIdx) ); driven.SetPosition(stream, Vector3.Lerp(driven.GetPosition(stream), posBlend, jobWeight)); } else { driven.SetLocalPosition(stream, driven.GetLocalPosition(stream)); } if ((flags & k_BlendRotationMask) != 0) { Quaternion rotBlend = Quaternion.Lerp( sourceA.GetRotation(stream) * sourceAOffset.rotation, sourceB.GetRotation(stream) * sourceBOffset.rotation, cache.GetRaw(rotationWeightIdx) ); driven.SetRotation(stream, Quaternion.Lerp(driven.GetRotation(stream), rotBlend, jobWeight)); } else { driven.SetLocalRotation(stream, driven.GetLocalRotation(stream)); } } else { AnimationRuntimeUtils.PassThrough(stream, driven); } }
public static void PassThrough(AnimationStream stream, TransformHandle handle) { handle.SetLocalPosition(stream, handle.GetLocalPosition(stream)); handle.SetLocalRotation(stream, handle.GetLocalRotation(stream)); handle.SetLocalScale(stream, handle.GetLocalScale(stream)); }