You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
285 lines
11 KiB
C++
285 lines
11 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "BoneControllers/AnimNode_BoneDrivenController.h"
|
|
|
|
#include "Curves/CurveFloat.h"
|
|
#include "Animation/AnimInstanceProxy.h"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// FAnimNode_BoneDrivenController
|
|
|
|
FAnimNode_BoneDrivenController::FAnimNode_BoneDrivenController()
|
|
: SourceComponent(EComponentType::None)
|
|
, Multiplier(1.0f)
|
|
, bUseRange(false)
|
|
, RangeMin(-1.0f)
|
|
, RangeMax(1.0f)
|
|
, RemappedMin(0.0f)
|
|
, RemappedMax(1.0f)
|
|
, DestinationMode(EDrivenDestinationMode::Bone)
|
|
, TargetComponent_DEPRECATED(EComponentType::None)
|
|
, bAffectTargetTranslationX(false)
|
|
, bAffectTargetTranslationY(false)
|
|
, bAffectTargetTranslationZ(false)
|
|
, bAffectTargetRotationX(false)
|
|
, bAffectTargetRotationY(false)
|
|
, bAffectTargetRotationZ(false)
|
|
, bAffectTargetScaleX(false)
|
|
, bAffectTargetScaleY(false)
|
|
, bAffectTargetScaleZ(false)
|
|
, ModificationMode(EDrivenBoneModificationMode::AddToInput)
|
|
{
|
|
}
|
|
|
|
void FAnimNode_BoneDrivenController::GatherDebugData(FNodeDebugData& DebugData)
|
|
{
|
|
FString DebugLine = DebugData.GetNodeName(this);
|
|
DebugLine += "(";
|
|
AddDebugNodeData(DebugLine);
|
|
if (DestinationMode == EDrivenDestinationMode::Bone)
|
|
{
|
|
DebugLine += FString::Printf(TEXT(" DrivingBone: %s\nDrivenBone: %s"), *SourceBone.BoneName.ToString(), *TargetBone.BoneName.ToString());
|
|
}
|
|
else
|
|
{
|
|
DebugLine += FString::Printf(TEXT(" DrivingBone: %s\nDrivenParameter: %s"), *SourceBone.BoneName.ToString(), *ParameterName.ToString());
|
|
}
|
|
|
|
DebugData.AddDebugItem(DebugLine);
|
|
|
|
ComponentPose.GatherDebugData(DebugData);
|
|
}
|
|
|
|
void FAnimNode_BoneDrivenController::EvaluateBoneTransforms(USkeletalMeshComponent* SkelComp, FCSPose<FCompactPose>& MeshBases, TArray<FBoneTransform>& OutCSBoneTransforms)
|
|
{
|
|
check(OutCSBoneTransforms.Num() == 0);
|
|
|
|
// Early out if we're not driving from or to anything
|
|
if (SourceComponent == EComponentType::None || DestinationMode != EDrivenDestinationMode::Bone)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Get the Local space transform and the ref pose transform to see how the transform for the source bone has changed
|
|
const FBoneContainer& BoneContainer = MeshBases.GetPose().GetBoneContainer();
|
|
const FTransform& SourceRefPoseBoneTransform = BoneContainer.GetRefPoseArray()[SourceBone.BoneIndex];
|
|
const FTransform SourceCurrentBoneTransform = MeshBases.GetLocalSpaceTransform(SourceBone.GetCompactPoseIndex(BoneContainer));
|
|
|
|
const float FinalDriverValue = ExtractSourceValue(SourceCurrentBoneTransform, SourceRefPoseBoneTransform);
|
|
|
|
|
|
// Calculate a new local-space bone position by adding or replacing target components in the current local space position
|
|
const FCompactPoseBoneIndex TargetBoneIndex = TargetBone.GetCompactPoseIndex(BoneContainer);
|
|
|
|
const FTransform OriginalLocalTM = MeshBases.GetLocalSpaceTransform(TargetBoneIndex);
|
|
FVector NewTrans(OriginalLocalTM.GetTranslation());
|
|
FVector NewScale(OriginalLocalTM.GetScale3D());
|
|
FQuat NewRot(OriginalLocalTM.GetRotation());
|
|
|
|
if (ModificationMode == EDrivenBoneModificationMode::AddToInput)
|
|
{
|
|
// Add the mapped value to the target components
|
|
if (bAffectTargetTranslationX) { NewTrans.X += FinalDriverValue; }
|
|
if (bAffectTargetTranslationY) { NewTrans.Y += FinalDriverValue; }
|
|
if (bAffectTargetTranslationZ) { NewTrans.Z += FinalDriverValue; }
|
|
|
|
if (bAffectTargetRotationX || bAffectTargetRotationY || bAffectTargetRotationZ)
|
|
{
|
|
FVector NewRotDeltaEuler(ForceInitToZero);
|
|
if (bAffectTargetRotationX) { NewRotDeltaEuler.X = FinalDriverValue; }
|
|
if (bAffectTargetRotationY) { NewRotDeltaEuler.Y = FinalDriverValue; }
|
|
if (bAffectTargetRotationZ) { NewRotDeltaEuler.Z = FinalDriverValue; }
|
|
NewRot = NewRot * FQuat::MakeFromEuler(NewRotDeltaEuler);
|
|
}
|
|
|
|
if (bAffectTargetScaleX) { NewScale.X += FinalDriverValue; }
|
|
if (bAffectTargetScaleY) { NewScale.Y += FinalDriverValue; }
|
|
if (bAffectTargetScaleZ) { NewScale.Z += FinalDriverValue; }
|
|
}
|
|
else if (ModificationMode == EDrivenBoneModificationMode::ReplaceComponent)
|
|
{
|
|
// Replace the target components with the mapped value
|
|
if (bAffectTargetTranslationX) { NewTrans.X = FinalDriverValue; }
|
|
if (bAffectTargetTranslationY) { NewTrans.Y = FinalDriverValue; }
|
|
if (bAffectTargetTranslationZ) { NewTrans.Z = FinalDriverValue; }
|
|
|
|
if (bAffectTargetRotationX || bAffectTargetRotationY || bAffectTargetRotationZ)
|
|
{
|
|
FVector NewRotEuler(NewRot.Euler());
|
|
if (bAffectTargetRotationX) { NewRotEuler.X = FinalDriverValue; }
|
|
if (bAffectTargetRotationY) { NewRotEuler.Y = FinalDriverValue; }
|
|
if (bAffectTargetRotationZ) { NewRotEuler.Z = FinalDriverValue; }
|
|
NewRot = FQuat::MakeFromEuler(NewRotEuler);
|
|
}
|
|
|
|
if (bAffectTargetScaleX) { NewScale.X = FinalDriverValue; }
|
|
if (bAffectTargetScaleY) { NewScale.Y = FinalDriverValue; }
|
|
if (bAffectTargetScaleZ) { NewScale.Z = FinalDriverValue; }
|
|
}
|
|
else if (ModificationMode == EDrivenBoneModificationMode::AddToRefPose)
|
|
{
|
|
const FTransform RefPoseTransform = MeshBases.GetPose().GetRefPose(TargetBoneIndex);
|
|
|
|
// Add the mapped value to the ref pose components
|
|
if (bAffectTargetTranslationX) { NewTrans.X = RefPoseTransform.GetTranslation().X + FinalDriverValue; }
|
|
if (bAffectTargetTranslationY) { NewTrans.Y = RefPoseTransform.GetTranslation().Y + FinalDriverValue; }
|
|
if (bAffectTargetTranslationZ) { NewTrans.Z = RefPoseTransform.GetTranslation().Z + FinalDriverValue; }
|
|
|
|
if (bAffectTargetRotationX || bAffectTargetRotationY || bAffectTargetRotationZ)
|
|
{
|
|
const FVector RefPoseRotEuler(RefPoseTransform.GetRotation().Euler());
|
|
|
|
// Replace any components that are being driven with their ref pose value first and create a delta rotation as well
|
|
FVector SourceRotationEuler(NewRot.Euler());
|
|
FVector NewRotDeltaEuler(ForceInitToZero);
|
|
if (bAffectTargetRotationX) { SourceRotationEuler.X = RefPoseRotEuler.X; NewRotDeltaEuler.X = FinalDriverValue; }
|
|
if (bAffectTargetRotationY) { SourceRotationEuler.Y = RefPoseRotEuler.Y; NewRotDeltaEuler.Y = FinalDriverValue; }
|
|
if (bAffectTargetRotationZ) { SourceRotationEuler.Z = RefPoseRotEuler.Z; NewRotDeltaEuler.Z = FinalDriverValue; }
|
|
|
|
// Combine the (modified) source and the delta rotation
|
|
NewRot = FQuat::MakeFromEuler(SourceRotationEuler) * FQuat::MakeFromEuler(NewRotDeltaEuler);
|
|
}
|
|
|
|
if (bAffectTargetScaleX) { NewScale.X = RefPoseTransform.GetScale3D().X + FinalDriverValue; }
|
|
if (bAffectTargetScaleY) { NewScale.Y = RefPoseTransform.GetScale3D().Y + FinalDriverValue; }
|
|
if (bAffectTargetScaleZ) { NewScale.Z = RefPoseTransform.GetScale3D().Z + FinalDriverValue; }
|
|
}
|
|
else
|
|
{
|
|
ensureMsgf(false, TEXT("Unknown entry in EDrivenBoneModificationMode"));
|
|
}
|
|
|
|
const FTransform ModifiedLocalTM(NewRot, NewTrans, NewScale);
|
|
|
|
// If we have a parent, concatenate the transform, otherwise just take the new transform
|
|
const FCompactPoseBoneIndex ParentIndex = MeshBases.GetPose().GetParentBoneIndex(TargetBoneIndex);
|
|
|
|
if (ParentIndex != INDEX_NONE)
|
|
{
|
|
const FTransform& ParentTM = MeshBases.GetComponentSpaceTransform(ParentIndex);
|
|
|
|
OutCSBoneTransforms.Add(FBoneTransform(TargetBoneIndex, ModifiedLocalTM * ParentTM));
|
|
}
|
|
else
|
|
{
|
|
OutCSBoneTransforms.Add(FBoneTransform(TargetBoneIndex, ModifiedLocalTM));
|
|
}
|
|
}
|
|
|
|
void FAnimNode_BoneDrivenController::EvaluateComponentSpaceInternal(FComponentSpacePoseContext& Context)
|
|
{
|
|
// Early out if we're not driving from or to anything
|
|
if (SourceComponent == EComponentType::None || DestinationMode == EDrivenDestinationMode::Bone)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Get the Local space transform and the ref pose transform to see how the transform for the source bone has changed
|
|
const FBoneContainer& BoneContainer = Context.Pose.GetPose().GetBoneContainer();
|
|
const FTransform& SourceRefPoseBoneTransform = BoneContainer.GetRefPoseArray()[SourceBone.BoneIndex];
|
|
const FTransform SourceCurrentBoneTransform = Context.Pose.GetLocalSpaceTransform(SourceBone.GetCompactPoseIndex(BoneContainer));
|
|
|
|
const float FinalDriverValue = ExtractSourceValue(SourceCurrentBoneTransform, SourceRefPoseBoneTransform);
|
|
|
|
if (DestinationMode == EDrivenDestinationMode::MorphTarget || DestinationMode == EDrivenDestinationMode::MaterialParameter)
|
|
{
|
|
// Morph target and Material parameter curves
|
|
USkeleton* Skeleton = Context.AnimInstanceProxy->GetSkeleton();
|
|
SmartName::UID_Type NameUID = Skeleton->GetUIDByName(USkeleton::AnimCurveMappingName, ParameterName);
|
|
if (NameUID != SmartName::MaxUID)
|
|
{
|
|
Context.Curve.Set(NameUID, FinalDriverValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
const float FAnimNode_BoneDrivenController::ExtractSourceValue(const FTransform &InCurrentBoneTransform, const FTransform &InRefPoseBoneTransform)
|
|
{
|
|
// Resolve source value
|
|
float SourceValue = 0.0f;
|
|
if (SourceComponent < EComponentType::RotationX)
|
|
{
|
|
const FVector TranslationDiff = InCurrentBoneTransform.GetLocation() - InRefPoseBoneTransform.GetLocation();
|
|
SourceValue = TranslationDiff[(int32)(SourceComponent - EComponentType::TranslationX)];
|
|
}
|
|
else if (SourceComponent < EComponentType::Scale)
|
|
{
|
|
const FVector RotationDiff = (InCurrentBoneTransform.GetRotation() * InRefPoseBoneTransform.GetRotation().Inverse()).Euler();
|
|
SourceValue = RotationDiff[(int32)(SourceComponent - EComponentType::RotationX)];
|
|
}
|
|
else if (SourceComponent == EComponentType::Scale)
|
|
{
|
|
const FVector CurrentScale = InCurrentBoneTransform.GetScale3D();
|
|
const FVector RefScale = InRefPoseBoneTransform.GetScale3D();
|
|
const float ScaleDiff = FMath::Max3(CurrentScale[0], CurrentScale[1], CurrentScale[2]) - FMath::Max3(RefScale[0], RefScale[1], RefScale[2]);
|
|
SourceValue = ScaleDiff;
|
|
}
|
|
else
|
|
{
|
|
const FVector ScaleDiff = InCurrentBoneTransform.GetScale3D() - InRefPoseBoneTransform.GetScale3D();
|
|
SourceValue = ScaleDiff[(int32)(SourceComponent - EComponentType::ScaleX)];
|
|
}
|
|
|
|
// Determine the resulting value
|
|
float FinalDriverValue = SourceValue;
|
|
if (DrivingCurve != nullptr)
|
|
{
|
|
// Remap thru the curve if set
|
|
FinalDriverValue = DrivingCurve->GetFloatValue(FinalDriverValue);
|
|
}
|
|
else
|
|
{
|
|
// Apply the fixed function remapping/clamping
|
|
if (bUseRange)
|
|
{
|
|
const float ClampedAlpha = FMath::Clamp(FMath::GetRangePct(RangeMin, RangeMax, FinalDriverValue), 0.0f, 1.0f);
|
|
FinalDriverValue = FMath::Lerp(RemappedMin, RemappedMax, ClampedAlpha);
|
|
}
|
|
|
|
FinalDriverValue *= Multiplier;
|
|
}
|
|
|
|
return FinalDriverValue;
|
|
}
|
|
|
|
bool FAnimNode_BoneDrivenController::IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones)
|
|
{
|
|
return SourceBone.IsValid(RequiredBones) && ( TargetBone.IsValid(RequiredBones) || DestinationMode != EDrivenDestinationMode::Bone );
|
|
}
|
|
|
|
void FAnimNode_BoneDrivenController::ConvertTargetComponentToBits()
|
|
{
|
|
switch (TargetComponent_DEPRECATED)
|
|
{
|
|
case EComponentType::TranslationX:
|
|
bAffectTargetTranslationX = true;
|
|
break;
|
|
case EComponentType::TranslationY:
|
|
bAffectTargetTranslationY = true;
|
|
break;
|
|
case EComponentType::TranslationZ:
|
|
bAffectTargetTranslationZ = true;
|
|
break;
|
|
case EComponentType::RotationX:
|
|
bAffectTargetRotationX = true;
|
|
break;
|
|
case EComponentType::RotationY:
|
|
bAffectTargetRotationY = true;
|
|
break;
|
|
case EComponentType::RotationZ:
|
|
bAffectTargetRotationZ = true;
|
|
break;
|
|
case EComponentType::Scale:
|
|
bAffectTargetScaleX = true;
|
|
bAffectTargetScaleY = true;
|
|
bAffectTargetScaleZ = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void FAnimNode_BoneDrivenController::InitializeBoneReferences(const FBoneContainer& RequiredBones)
|
|
{
|
|
SourceBone.Initialize(RequiredBones);
|
|
TargetBone.Initialize(RequiredBones);
|
|
}
|