public void ProcessAnimation(AnimationStream stream) { if (weightA == 0 && weightB == 0) { return; } var A = stream.GetInputStream(0); var B = stream.GetInputStream(1); if (weightB == 0) { if (weightA == 1) { SMixerUtility.StreamSet(handles, stream, A); } else { SMixerUtility.StreamMix(handles, stream, stream, A, weightA); // blend-in transition to A from stream } } else { if (weightA == 1) { SMixerUtility.StreamMix(handles, stream, A, B, weightB); // blend-in transition to B from A } else { SMixerUtility.StreamMixMix(handles, stream, stream, A, B, weightA, weightB); } } }
public void ProcessRootMotion(AnimationStream stream) { if (clipA >= 0 && clipB >= 0) { var streamA = stream.GetInputStream(clipA); var streamB = stream.GetInputStream(clipB); if (streamA.isValid && streamB.isValid) { var velocity = Vector3.Lerp(streamA.velocity, streamB.velocity, weight); var angularVelocity = Vector3.Lerp(streamA.angularVelocity, streamB.angularVelocity, weight); stream.velocity = velocity; stream.angularVelocity = angularVelocity; } } else if (clipA >= 0) { var streamA = stream.GetInputStream(clipA); if (streamA.isValid) { ProcessMotion(stream, streamA); } } else if (clipB > 0) { var streamB = stream.GetInputStream(clipB); if (streamB.isValid) { ProcessMotion(stream, streamB); } } }
public void ProcessRootMotion(AnimationStream stream) { var streamA = stream.GetInputStream(0); var streamB = stream.GetInputStream(1); var velocity = Vector3.Lerp(streamA.velocity, streamB.velocity, weight); var angularVelocity = Vector3.Lerp(streamA.angularVelocity, streamB.angularVelocity, weight); stream.velocity = velocity; stream.angularVelocity = angularVelocity; }
public static void ProcessRootMotion(AnimationStream stream, float weightA, float weightB) { if (weightA == 0 && weightB == 0) { return; } var A = stream.GetInputStream(0); var B = stream.GetInputStream(1); if (weightB != 0) { if (weightB == 1) { stream.velocity = B.velocity; stream.angularVelocity = B.angularVelocity; } else if (weightA == 1) { // crossfade stream.velocity = Vector3.Lerp(A.velocity, B.velocity, weightB); stream.angularVelocity = Vector3.Lerp(A.angularVelocity, B.angularVelocity, weightB); } else { // blend-in var velocity = Vector3.Lerp(stream.velocity, A.velocity, weightA); var angularVelocity = Vector3.Lerp(stream.angularVelocity, A.angularVelocity, weightA); // crossfade stream.velocity = Vector3.Lerp(velocity, B.velocity, weightB); stream.angularVelocity = Vector3.Lerp(angularVelocity, B.angularVelocity, weightB); } } else { if (weightA == 1) { stream.velocity = A.velocity; stream.angularVelocity = A.angularVelocity; } else { // blend-in stream.velocity = Vector3.Lerp(stream.velocity, A.velocity, weightA); stream.angularVelocity = Vector3.Lerp(stream.angularVelocity, A.angularVelocity, weightA); } } }
public void ProcessRootMotion(AnimationStream stream) { AnimationStream inputStream = stream.GetInputStream(0); stream.velocity = inputStream.velocity; stream.angularVelocity = inputStream.angularVelocity; }
public void ProcessAnimation(AnimationStream stream) { if (stream.inputStreamCount == 0) { return; } if (stream.inputStreamCount == 1) { var streamA = stream.GetInputStream(poseAIndex); var numHandles = handles.Length; for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamA); handle.SetLocalPosition(stream, posA); var rotA = handle.GetLocalRotation(streamA); handle.SetLocalRotation(stream, rotA); } } else { var streamA = stream.GetInputStream(poseAIndex); var streamB = stream.GetInputStream(poseBIndex); // Debug.Log($"Process animation {stream.inputStreamCount} {weight} {streamA.isValid} {streamB.isValid}"); var numHandles = handles.Length; for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamA); var posB = handle.GetLocalPosition(streamB); handle.SetLocalPosition(stream, Vector3.Lerp(posA, posB, weight * boneWeights[i])); // if (posA.x > 0 || posA.y > 0 || posA.z > 0) Debug.Log($"{posA.ToString("F4")} {posB.ToString("F4")} {handle.GetLocalPosition(stream).ToString("F4")} {boneWeights[i]} {weight} {weight * boneWeights[i]}"); var rotA = handle.GetLocalRotation(streamA); var rotB = handle.GetLocalRotation(streamB); handle.SetLocalRotation(stream, Quaternion.Slerp(rotA, rotB, weight * boneWeights[i])); } } }
public void ProcessAnimation(AnimationStream stream) { AnimationStream inputStream = stream.GetInputStream(0); if (BlendActive) { for (int i = 0; i < TargetAnimationTransforms.Length; ++i) { TransformStreamHandle TargetTransform = TargetAnimationTransforms[i]; TransformSceneHandle CurrentTransform = CurrentAnimationTransforms[i]; TransformData PreviousTransform = PreviousAnimationTransforms[i]; float3 currentPos = float3.zero; if (i == 0) { float3 targetPos = TargetTransform.GetLocalPosition(inputStream); currentPos = CurrentTransform.GetLocalPosition(stream); float3 pos = Inertialize(PreviousTransform.Position, currentPos, targetPos, DeltaTime, RemainingTime, DeltaTime); TargetTransform.SetLocalPosition(stream, pos); } quaternion targetRot = TargetTransform.GetLocalRotation(inputStream); quaternion currentRot = CurrentTransform.GetLocalRotation(stream); quaternion rot = Inertialize(PreviousTransform.Rotation, currentRot, targetRot, DeltaTime, RemainingTime, DeltaTime); TargetTransform.SetLocalRotation(stream, rot); PreviousAnimationTransforms[i] = new TransformData(currentPos, currentRot); } } else { for (int i = 0; i < TargetAnimationTransforms.Length; ++i) { TransformStreamHandle TargetTransform = TargetAnimationTransforms[i]; TransformSceneHandle CurrentTransform = CurrentAnimationTransforms[i]; if (i == 0) { TargetTransform.SetLocalPosition(stream, TargetTransform.GetLocalPosition(inputStream)); } TargetTransform.SetLocalRotation(stream, TargetTransform.GetLocalRotation(inputStream)); PreviousAnimationTransforms[i] = new TransformData(CurrentTransform.GetLocalPosition(stream), CurrentTransform.GetLocalRotation(stream)); } } }
public void ProcessAnimation(AnimationStream stream) { var streamA = stream.GetInputStream(0); var streamB = stream.GetInputStream(1); var numHandles = handles.Length; for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamA); var posB = handle.GetLocalPosition(streamB); handle.SetLocalPosition(stream, Vector3.Lerp(posA, posB, weight * boneWeights[i])); var rotA = handle.GetLocalRotation(streamA); var rotB = handle.GetLocalRotation(streamB); handle.SetLocalRotation(stream, Quaternion.Slerp(rotA, rotB, weight * boneWeights[i])); } }
public void ProcessAnimation(AnimationStream stream) { if (clipA >= 0 && clipB >= 0) { var streamA = stream.GetInputStream(clipA); var streamB = stream.GetInputStream(clipB); var numHandles = handles.Length; if (streamA.isValid && streamB.isValid) { for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamA); var posB = handle.GetLocalPosition(streamB); handle.SetLocalPosition(stream, Vector3.Lerp(posA, posB, weight)); var rotA = handle.GetLocalRotation(streamA); var rotB = handle.GetLocalRotation(streamB); handle.SetLocalRotation(stream, Quaternion.Slerp(rotA, rotB, weight)); } } } else if (clipA >= 0) { var streamA = stream.GetInputStream(clipA); if (streamA.isValid) { ProcessAnimation(stream, streamA); } } else if (clipB > 0) { var streamB = stream.GetInputStream(clipB); if (streamB.isValid) { ProcessAnimation(stream, streamB); } } }
public void ProcessAnimation(AnimationStream stream) { // Debug.Log($"Process animation {stream.isValid}"); if (stream.inputStreamCount == 0) { return; } var streamA = stream.GetInputStream(0); var streamB = stream.GetInputStream(1); var numHandles = handles.Length; if (useBonesLastAsFirst && streamA.isValid) { if (!isTransitioning) { isTransitioning = true; bonesLastFrame.CopyTo(bonesLastState); // Debug.LogError("Start new mixer transition"); } for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = bonesLastState[i].position; var posB = handle.GetLocalPosition(streamA); var pos = Vector3Blend[blendMode](posA, posB, weight *boneWeights[i]); handle.SetLocalPosition(stream, pos); var rotA = bonesLastState[i].rotation; var rotB = handle.GetLocalRotation(streamA); var rot = QuaternionBlend[blendMode](rotA, rotB, weight *boneWeights[i]); handle.SetLocalRotation(stream, rot); bonesLastFrame[i] = new BoneLocation(pos, rot); } return; } if (!streamA.isValid && !streamB.isValid) { return; } if (stream.inputStreamCount < 2 || !streamB.isValid) { for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamA); handle.SetLocalPosition(stream, posA); var rotA = handle.GetLocalRotation(streamA); handle.SetLocalRotation(stream, rotA); bonesLastFrame[i] = new BoneLocation(posA, rotA); } return; } for (var i = 0; i < numHandles; ++i) { var handle = handles[i]; var posA = handle.GetLocalPosition(streamB); var posB = handle.GetLocalPosition(streamA); var pos = Vector3Blend[blendMode](posA, posB, weight *boneWeights[i]); handle.SetLocalPosition(stream, pos); var rotA = handle.GetLocalRotation(streamB); var rotB = handle.GetLocalRotation(streamA); var rot = QuaternionBlend[blendMode](rotA, rotB, weight *boneWeights[i]); handle.SetLocalRotation(stream, rot); bonesLastFrame[i] = new BoneLocation(pos, rot); } }