Files
UnrealEngineUWP/Engine/Source/Editor/AnimGraph/Private/AnimGraphNode_ModifyBone.cpp
Marc Audy b612760508 Copying //UE4/Dev-Framework to //UE4/Main @ 2830052
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2807479 on 2015/12/17 by Zak.Middleton

	#ue4 - Optimize allocations in FFinalPostProcessSettings. Fix bug skipping an element when updating the ContributingCubemaps array if one is removed during an iteration.

	#rb Aaron.Mcleran
	#codereview Martin.Mittring
	#jira UE-24485

Change 2807695 on 2015/12/17 by Aaron.McLeran

	Changing the VolumeScale sound concurrency implementation to be a volume scalar on older sounds in a concurrency group rather than scale new sounds.

	#rb zak.middleton

Change 2808628 on 2015/12/18 by Thomas.Sarkanen

	Minor optimization: Dont call GetWorld() 3 times in a row in USceneComponent::ShouldRender()

	#rb Martin.Wilson

Change 2810090 on 2015/12/21 by Ori.Cohen

	Allow collision and trail particles to run off the game thread.
	Clean up missing marshelled AsyncComponentToWorld

Change 2814518 on 2016/01/04 by Marc.Audy

	Use Reset instead of Empty

Change 2814530 on 2016/01/04 by James.Golding

	UE-2689 Hook up lots of new icons for component classes
	#rb thomas.sarkanen

Change 2814665 on 2016/01/04 by Marc.Audy

	PR #1860:Fix ChildActorComponent linking issue when extended from game (Contributed by lion03)

Change 2814686 on 2016/01/04 by Benn.Gallagher

	Fix for radial force components applying impulses multiple times to destructible components
	#rb Ori.Cohen

Change 2815221 on 2016/01/04 by Aaron.McLeran

	UE-24528 Fixing focus-distance scaling and focus priority scaling working with concurrency settings.

	USoundAttenuation:
	- Added methods to SoundAttenuation to get focus, attenuation, and distance scale based on focus factor.
	- Added NonFocusDistanceScale parameter to attenuation settings customization so its setable by users

	USoundBase:
	- Added function on USoundBase which checks IsLooping, which checks the duration
	- Removed functions IsAudible and IsAudibleSimple from USoundBase since that functionality is accomplished differently and takes into account focus-distance scaling now.

	FActiveSound:
	- Caching values of FocusPriorityScale and FocusDistanceScale to Active sound so that can be used for audibility checks
	- Included FocusDistanceScale when computing bIsAudible in Active sound
	- Moved GetAttenuationListenerData and the accompanying private struct FAttenuationListenerData to FAudioDevice since the audio device and moved code which computes focus factor and geometry into FAudioDevice::GetFocusFactor since it needs to be computed before an active sound exist

	FAudioDevice:
	- Added SoundIsAudible function which queries a particular sound if its audible based on attenuation settings, focus factor, etc. Will optionally return computed MaxDistance to avoid recomputing it in certain cases.
	- Added a few helper functions: FindClosestListenerIndex, GetAttenuationListenerData
	- Added GetFocusFactor, which performs the vector math to determine focus factor (0.0 is in-focus, 1.0 is out of focus) for a given sound and listener and attenuation focus settings.
	- Updated CreateComponent and PlaySoundAtLocation functions to use the new SoundIsAudible function rather than the old IsAudibleSimple

	#rb zak.middleton

Change 2815694 on 2016/01/05 by thomas.sarkanen

	Added test texture

Change 2815695 on 2016/01/05 by thomas.sarkanen

	Modified test texture

Change 2815709 on 2016/01/05 by James.Golding

	PR #1778 : New BP-callablle function AActor::WasRecentlyRendered, with optional tolerance in seconds
	https://github.com/EpicGames/UnrealEngine/pull/1778
	#github 1778
	#jira UE-23674
	#rb jurre.debaare

Change 2815711 on 2016/01/05 by James.Golding

	PR #1534 : Add missing default tolerance value for FVector2D::Equal
	https://github.com/EpicGames/UnrealEngine/pull/1534
	#github 1534
	#jira UE-20838
	#rb jurre.debaare

Change 2815714 on 2016/01/05 by James.Golding

	PR #1887 : Added 'Thickness' Parameter to all valid options in Draw Debug Helper
	https://github.com/EpicGames/UnrealEngine/pull/1887
	#github 1887
	#jira UE-24802
	#rb jurre.debaare

Change 2815725 on 2016/01/05 by James.Golding

	Added comment that USkeletalMeshComponent::bEnablePhysicsOnDedicatedServer cannot be changed at runtime
	#jira UE-20439

Change 2815813 on 2016/01/05 by Marc.Audy

	Move dispatch of transition functions to new OnMatchStateSet virtual which is called from SetMatchState allowing subclasses to insert their own handling between the set of the variable and dispatch to GameState and Blueprints rather than having to override the entire function.
	#codereview Peter.Knepley

Change 2815884 on 2016/01/05 by James.Golding

	- Avoid PSC iterating over all particle emitters each tick to check for changes in DetailMode. Now remember global DetailMode when we last checked, and only iterate again if that has changed.
	- Add 'WarmupTime' and 'CPUCollision' to Asset Registry Tags for Particle Systems
	#rb simon.tovey
	#codereview gil.gribb

Change 2816306 on 2016/01/05 by Marc.Audy

	(4.11) Pass boolean to OnComponentDestroyed that indicates if the entire Actor's hierarchy is being destroyed. If so we can avoid doing a lot of expensive tear down, particularly detaching each component one at a time from the hierarchy and causing massive position/bounds updates.
	#rb Zak.Middleton, James.Golding
2016-01-15 13:01:30 -05:00

324 lines
10 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "AnimGraphPrivatePCH.h"
#include "AnimGraphNode_ModifyBone.h"
#include "CompilerResultsLog.h"
/////////////////////////////////////////////////////
// UAnimGraphNode_ModifyBone
#define LOCTEXT_NAMESPACE "A3Nodes"
UAnimGraphNode_ModifyBone::UAnimGraphNode_ModifyBone(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
CurWidgetMode = (int32)FWidget::WM_Rotate;
}
void UAnimGraphNode_ModifyBone::ValidateAnimNodeDuringCompilation(USkeleton* ForSkeleton, FCompilerResultsLog& MessageLog)
{
if (ForSkeleton->GetReferenceSkeleton().FindBoneIndex(Node.BoneToModify.BoneName) == INDEX_NONE)
{
MessageLog.Warning(*LOCTEXT("NoBoneToModify", "@@ - You must pick a bone to modify").ToString(), this);
}
if ((Node.TranslationMode == BMM_Ignore) && (Node.RotationMode == BMM_Ignore) && (Node.ScaleMode == BMM_Ignore))
{
MessageLog.Warning(*LOCTEXT("NothingToModify", "@@ - No components to modify selected. Either Rotation, Translation, or Scale should be set to something other than Ignore").ToString(), this);
}
Super::ValidateAnimNodeDuringCompilation(ForSkeleton, MessageLog);
}
FText UAnimGraphNode_ModifyBone::GetControllerDescription() const
{
return LOCTEXT("TransformModifyBone", "Transform (Modify) Bone");
}
FText UAnimGraphNode_ModifyBone::GetTooltipText() const
{
return LOCTEXT("AnimGraphNode_ModifyBone_Tooltip", "The Transform Bone node alters the transform - i.e. Translation, Rotation, or Scale - of the bone");
}
FText UAnimGraphNode_ModifyBone::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if ((TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle) && (Node.BoneToModify.BoneName == NAME_None))
{
return GetControllerDescription();
}
// @TODO: the bone can be altered in the property editor, so we have to
// choose to mark this dirty when that happens for this to properly work
else //if (!CachedNodeTitles.IsTitleCached(TitleType, this))
{
FFormatNamedArguments Args;
Args.Add(TEXT("ControllerDescription"), GetControllerDescription());
Args.Add(TEXT("BoneName"), FText::FromName(Node.BoneToModify.BoneName));
// FText::Format() is slow, so we cache this to save on performance
if (TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle)
{
CachedNodeTitles.SetCachedTitle(TitleType, FText::Format(LOCTEXT("AnimGraphNode_ModifyBone_ListTitle", "{ControllerDescription} - Bone: {BoneName}"), Args), this);
}
else
{
CachedNodeTitles.SetCachedTitle(TitleType, FText::Format(LOCTEXT("AnimGraphNode_ModifyBone_Title", "{ControllerDescription}\nBone: {BoneName}"), Args), this);
}
}
return CachedNodeTitles[TitleType];
}
int32 UAnimGraphNode_ModifyBone::GetWidgetCoordinateSystem(const USkeletalMeshComponent* SkelComp)
{
EBoneControlSpace Space = BCS_BoneSpace;
switch (CurWidgetMode)
{
case FWidget::WM_Rotate:
Space = Node.RotationSpace;
break;
case FWidget::WM_Translate:
Space = Node.TranslationSpace;
break;
case FWidget::WM_Scale:
Space = Node.ScaleSpace;
break;
}
switch (Space)
{
default:
case BCS_ParentBoneSpace:
//@TODO: No good way of handling this one
return COORD_World;
case BCS_BoneSpace:
return COORD_Local;
case BCS_ComponentSpace:
case BCS_WorldSpace:
return COORD_World;
}
}
FVector UAnimGraphNode_ModifyBone::GetWidgetLocation(const USkeletalMeshComponent* SkelComp, FAnimNode_SkeletalControlBase* AnimNode)
{
USkeleton* Skeleton = SkelComp->SkeletalMesh->Skeleton;
FVector WidgetLoc = FVector::ZeroVector;
// if the current widget mode is translate, then shows the widget according to translation space
if (CurWidgetMode == FWidget::WM_Translate)
{
FCSPose<FCompactHeapPose>& MeshBases = AnimNode->ForwardedPose;
WidgetLoc = ConvertWidgetLocation(SkelComp, MeshBases, Node.BoneToModify.BoneName, GetNodeValue(FString("Translation"), Node.Translation), Node.TranslationSpace);
if (MeshBases.GetPose().IsValid() && Node.TranslationMode == BMM_Additive)
{
if(Node.TranslationSpace == EBoneControlSpace::BCS_WorldSpace ||
Node.TranslationSpace == EBoneControlSpace::BCS_ComponentSpace)
{
const FMeshPoseBoneIndex MeshBoneIndex(SkelComp->GetBoneIndex(Node.BoneToModify.BoneName));
const FCompactPoseBoneIndex BoneIndex = MeshBases.GetPose().GetBoneContainer().MakeCompactPoseIndex(MeshBoneIndex);
if (BoneIndex != INDEX_NONE)
{
const FTransform& BoneTM = MeshBases.GetComponentSpaceTransform(BoneIndex);
WidgetLoc += BoneTM.GetLocation();
}
}
}
}
else // if the current widget mode is not translate mode, then show the widget on the bone to modify
{
int32 MeshBoneIndex = SkelComp->GetBoneIndex(Node.BoneToModify.BoneName);
if (MeshBoneIndex != INDEX_NONE)
{
const FTransform BoneTM = SkelComp->GetBoneTransform(MeshBoneIndex);
WidgetLoc = BoneTM.GetLocation();
}
}
return WidgetLoc;
}
EBoneModificationMode UAnimGraphNode_ModifyBone::GetBoneModificationMode(int32 InWidgetMode)
{
FWidget::EWidgetMode InMode = (FWidget::EWidgetMode)InWidgetMode;
switch (InMode)
{
case FWidget::WM_Translate:
return Node.TranslationMode;
break;
case FWidget::WM_Rotate:
return Node.RotationMode;
break;
case FWidget::WM_Scale:
return Node.ScaleMode;
break;
case FWidget::WM_TranslateRotateZ:
case FWidget::WM_2D:
break;
}
return EBoneModificationMode::BMM_Ignore;
}
int32 UAnimGraphNode_ModifyBone::GetNextWidgetMode(int32 InWidgetMode)
{
FWidget::EWidgetMode InMode = (FWidget::EWidgetMode)InWidgetMode;
switch (InMode)
{
case FWidget::WM_Translate:
return FWidget::WM_Rotate;
case FWidget::WM_Rotate:
return FWidget::WM_Scale;
case FWidget::WM_Scale:
return FWidget::WM_Translate;
case FWidget::WM_TranslateRotateZ:
case FWidget::WM_2D:
break;
}
return (int32)FWidget::WM_None;
}
int32 UAnimGraphNode_ModifyBone::FindValidWidgetMode(int32 InWidgetMode)
{
FWidget::EWidgetMode InMode = (FWidget::EWidgetMode)InWidgetMode;
FWidget::EWidgetMode ValidMode = InMode;
if (InMode == FWidget::WM_None)
{ // starts from Rotate mode
ValidMode = FWidget::WM_Rotate;
}
// find from current widget mode and loop 1 cycle until finding a valid mode
for (int32 Index = 0; Index < 3; Index++)
{
if (GetBoneModificationMode(ValidMode) != BMM_Ignore)
{
return ValidMode;
}
ValidMode = (FWidget::EWidgetMode)GetNextWidgetMode(ValidMode);
}
// if couldn't find a valid mode, returns None
ValidMode = FWidget::WM_None;
return (int32)ValidMode;
}
int32 UAnimGraphNode_ModifyBone::GetWidgetMode(const USkeletalMeshComponent* SkelComp)
{
int32 BoneIndex = SkelComp->GetBoneIndex(Node.BoneToModify.BoneName);
if (BoneIndex != INDEX_NONE)
{
CurWidgetMode = FindValidWidgetMode(CurWidgetMode);
return CurWidgetMode;
}
return (int32)FWidget::WM_None;
}
int32 UAnimGraphNode_ModifyBone::ChangeToNextWidgetMode(const USkeletalMeshComponent* SkelComp, int32 InCurWidgetMode)
{
int32 NextWidgetMode = GetNextWidgetMode(InCurWidgetMode);
CurWidgetMode = FindValidWidgetMode(NextWidgetMode);
return CurWidgetMode;
}
bool UAnimGraphNode_ModifyBone::SetWidgetMode(const USkeletalMeshComponent* SkelComp, int32 InWidgetMode)
{
// if InWidgetMode is available
if (FindValidWidgetMode(InWidgetMode) == InWidgetMode)
{
CurWidgetMode = InWidgetMode;
return true;
}
return false;
}
FName UAnimGraphNode_ModifyBone::FindSelectedBone()
{
return Node.BoneToModify.BoneName;
}
void UAnimGraphNode_ModifyBone::DoTranslation(const USkeletalMeshComponent* SkelComp, FVector& Drag, FAnimNode_Base* InOutAnimNode)
{
FAnimNode_ModifyBone* ModifyBone = static_cast<FAnimNode_ModifyBone*>(InOutAnimNode);
if (ModifyBone->TranslationMode != EBoneModificationMode::BMM_Ignore)
{
FVector Offset = ConvertCSVectorToBoneSpace(SkelComp, Drag, ModifyBone->ForwardedPose, Node.BoneToModify.BoneName, Node.TranslationSpace);
ModifyBone->Translation += Offset;
Node.Translation = ModifyBone->Translation;
}
}
void UAnimGraphNode_ModifyBone::DoRotation(const USkeletalMeshComponent* SkelComp, FRotator& Rotation, FAnimNode_Base* InOutAnimNode)
{
FAnimNode_ModifyBone* ModifyBone = static_cast<FAnimNode_ModifyBone*>(InOutAnimNode);
if (Node.RotationMode != EBoneModificationMode::BMM_Ignore)
{
FQuat DeltaQuat = ConvertCSRotationToBoneSpace(SkelComp, Rotation, ModifyBone->ForwardedPose, Node.BoneToModify.BoneName, Node.RotationSpace);
FQuat PrevQuat(ModifyBone->Rotation);
FQuat NewQuat = DeltaQuat * PrevQuat;
ModifyBone->Rotation = NewQuat.Rotator();
Node.Rotation = ModifyBone->Rotation;
}
}
void UAnimGraphNode_ModifyBone::DoScale(const USkeletalMeshComponent* SkelComp, FVector& Scale, FAnimNode_Base* InOutAnimNode)
{
FAnimNode_ModifyBone* ModifyBone = static_cast<FAnimNode_ModifyBone*>(InOutAnimNode);
if (Node.ScaleMode != EBoneModificationMode::BMM_Ignore)
{
FVector Offset = Scale;
ModifyBone->Scale += Offset;
Node.Scale = ModifyBone->Scale;
}
}
void UAnimGraphNode_ModifyBone::CopyNodeDataTo(FAnimNode_Base* OutAnimNode)
{
FAnimNode_ModifyBone* ModifyBone = static_cast<FAnimNode_ModifyBone*>(OutAnimNode);
// copies Pin values from the internal node to get data which are not compiled yet
ModifyBone->Translation = GetNodeValue(FString("Translation"), Node.Translation);
ModifyBone->Rotation = GetNodeValue(FString("Rotation"), Node.Rotation);
ModifyBone->Scale = GetNodeValue(FString("Scale"), Node.Scale);
// copies Modes
ModifyBone->TranslationMode = Node.TranslationMode;
ModifyBone->RotationMode = Node.RotationMode;
ModifyBone->ScaleMode = Node.ScaleMode;
// copies Spaces
ModifyBone->TranslationSpace = Node.TranslationSpace;
ModifyBone->RotationSpace = Node.RotationSpace;
ModifyBone->ScaleSpace = Node.ScaleSpace;
}
void UAnimGraphNode_ModifyBone::CopyNodeDataFrom(const FAnimNode_Base* InNewAnimNode)
{
const FAnimNode_ModifyBone* ModifyBone = static_cast<const FAnimNode_ModifyBone*>(InNewAnimNode);
switch (CurWidgetMode)
{
case FWidget::WM_Translate:
SetNodeValue(FString("Translation"), Node.Translation, ModifyBone->Translation);
break;
case FWidget::WM_Rotate:
SetNodeValue(FString("Rotation"), Node.Rotation, ModifyBone->Rotation);
break;
case FWidget::WM_Scale:
SetNodeValue(FString("Scale"), Node.Scale, ModifyBone->Scale);
break;
}
}
#undef LOCTEXT_NAMESPACE