public static void UpdateStream(TransformStreamHandle handle, AnimationStream stream, AnimationStream A, AnimationStream B, float w) { var posA = handle.GetLocalPosition(A); var posB = handle.GetLocalPosition(B); var pos = Vector3.Lerp(posA, posB, w); var rotA = handle.GetLocalRotation(A); var rotB = handle.GetLocalRotation(B); var rot = Quaternion.Slerp(rotA, rotB, w); handle.SetLocalPosition(stream, pos); handle.SetLocalRotation(stream, rot); }
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)); } } }
/// <summary> /// Gets the position of the transform relative to the parent. /// </summary> /// <param name="stream">The AnimationStream that holds the animated values.</param> /// <returns>The position of the transform relative to the parent.</returns> public Vector3 GetLocalPosition(AnimationStream stream) => m_InStream == 1 ? m_StreamHandle.GetLocalPosition(stream) : m_SceneHandle.GetLocalPosition(stream);
/// <summary> /// Gets the position of the transform relative to the parent. /// </summary> /// <param name="stream">The AnimationStream that holds the animated values.</param> /// <returns>The position of the transform relative to the parent.</returns> public Vector3 GetLocalPosition(AnimationStream stream) => m_Handle.GetLocalPosition(stream);
public void ProcessAnimation(AnimationStream stream) { if (math.abs(bankAmount) < 0.001f) { return; } var bankPosition = new Vector3( settings.position.x * bankAmount * 0.01f, settings.position.y * bankAmount * 0.01f, settings.position.z * bankAmount * 0.01f); var weightedBankRotation = Quaternion.Euler(new Vector3( settings.rotation.x * bankAmount * (1 - settings.spineMultiplier), settings.rotation.y * bankAmount * (1 - settings.spineMultiplier), settings.rotation.z * bankAmount) * (1 - settings.spineMultiplier)); var bankRotation = Quaternion.Euler(new Vector3( settings.rotation.x * bankAmount, settings.rotation.y * bankAmount, settings.rotation.z * bankAmount)); var footPosition = new Vector3( settings.position.x * bankAmount * 0.01f * settings.footMultiplier, settings.position.y * bankAmount * 0.01f * settings.footMultiplier, settings.position.z * bankAmount * 0.01f * settings.footMultiplier); //TODO: A multiplier here?? var footRotation = Quaternion.Euler(new Vector3( settings.rotation.x * bankAmount * settings.footMultiplier, settings.rotation.y * bankAmount * settings.footMultiplier, settings.rotation.z * bankAmount * settings.footMultiplier)); // Humanoid if (stream.isHumanStream) { var humanStream = stream.AsHuman(); var position = humanStream.bodyLocalPosition; humanStream.bodyLocalRotation = weightedBankRotation * humanStream.bodyLocalRotation; humanStream.bodyLocalPosition = bankRotation * position + bankPosition; var numHandles = m_HeadLeftRightMuscles.Length; var multiplier = bankAmount * 0.075f * settings.headMultiplier / numHandles; for (var i = 0; i < numHandles; i++) { var headLeftRight = humanStream.GetMuscle(m_HeadLeftRightMuscles[i]); humanStream.SetMuscle(m_HeadLeftRightMuscles[i], headLeftRight + multiplier); } numHandles = m_SpineLeftRightMuscles.Length; multiplier = bankAmount * 0.075f * settings.spineMultiplier / numHandles; for (var i = 0; i < numHandles; i++) { var spineLeftRight = humanStream.GetMuscle(m_SpineLeftRightMuscles[i]); humanStream.SetMuscle(m_SpineLeftRightMuscles[i], spineLeftRight + multiplier); } humanStream.SetGoalLocalPosition(AvatarIKGoal.LeftFoot, humanStream.GetGoalLocalPosition(AvatarIKGoal.LeftFoot) + footPosition); humanStream.SetGoalRotation(AvatarIKGoal.LeftFoot, humanStream.GetGoalRotation(AvatarIKGoal.LeftFoot) * footRotation); humanStream.SetGoalLocalPosition(AvatarIKGoal.RightFoot, humanStream.GetGoalLocalPosition(AvatarIKGoal.RightFoot) + footPosition); humanStream.SetGoalRotation(AvatarIKGoal.RightFoot, humanStream.GetGoalRotation(AvatarIKGoal.RightFoot) * footRotation); } // Generic else // TODO: Flesh this path out or consider loosing it { m_SkeletonHandle.SetLocalPosition(stream, m_SkeletonHandle.GetLocalPosition(stream) + bankPosition); m_SkeletonHandle.SetLocalRotation(stream, m_SkeletonHandle.GetLocalRotation(stream) * bankRotation); } }