(原)Unreal源码搬山-动画篇 自定义动画节点(一)

@author:黑袍小道

太忙了,来更新下,嘿嘿

前言:

本文是接着上文 Unreal搬山之动画模块_Unreal动画流程和框架,进行简单入门如何自定义动画图标的AnimNode。

正文:

一、AnimNode

Unreal 4的AnimNode负责的骨骼动画的单项计算,最后汇总到AnimGraph有,然后交付给AnimInstance统一收集和处理。

下图未AnimNode相关的结构

二、CustomAnimNode

该例子实现修改指定的一系列骨骼,并再AnimGraphy预览和编辑

三、Unreal4 AnimNode的结构和使用套路(流程)

四、案例源码

DZAnimStudio.uplugin

------------------------------------------------------------------------------------------------------------------------------------------------------

{

"FileVersion": 3,

"Version": 1,

"VersionName": "1.0",

"FriendlyName": "DZAnimStudio",

"Description": "This is Anim Studio",

"Category": "Other",

"CreatedBy": "BaiPao_XD",

"CreatedByURL": "https://www.cnblogs.com/BaiPao-XD/",

"DocsURL": "",

"MarketplaceURL": "",

"SupportURL": "",

"CanContainContent": true,

"IsBetaVersion": false,

"Installed": false,

"Modules": [

{

"Name": "DZAnimStudio",

"Type": "Runtime",

"LoadingPhase": "PreDefault",

"WhitelistPlatforms": [

"Android",

"Mac",

"Win32",

"Win64",

"PS4",

"XboxOne"

]

},

{

"Name": "DZAnimStudioEditor",

"Type": "Editor",//这里最好选着Developer这样在stand模式下启动也会加载

"LoadingPhase": "Default",

"WhitelistPlatforms": [

"Win32",

"Win64",

"Mac"

]

}

]

}

DZAnimStudioEditor.h

------------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

#include "ModuleManager.h"

class FDZAnimStudioEditorModule : public IModuleInterface

{

public:

virtual void StartupModule() override;

virtual void ShutdownModule() override;

};

DZAnimStudioEditor.cpp

------------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimStudioEditor.h"

#include "DZAnimStudio.h"

#include "DZAnimStudioEditorPrivatePCH.h"

#include "EditMode/DZAnimNode_ScaleBoneEditMode.h"

#define LOCTEXT_NAMESPACE "FAnimGraphIKModule"

void FDZAnimStudioEditorModule::StartupModule()

{

FEditorModeRegistry::Get().RegisterMode<FDZAnimNode_ScaleBoneEditMode>(DZAnimNodeEditModes::ScaleBone, LOCTEXT("DZAnimNode_ScaleBoneEditMode", "DZAnimNode_ScaleBone"), FSlateIcon(), false);

}

void FDZAnimStudioEditorModule::ShutdownModule()

{

FEditorModeRegistry::Get().UnregisterMode(DZAnimNodeEditModes::ScaleBone);

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FDZAnimStudioEditorModule, DZAnimStudioEditor)

DZAnimStudioEditor.Build.cs

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 2018 azhecheng, Inc. All Rights Reserved.

using UnrealBuildTool;

using System.IO;

public class AnimGraphIK : ModuleRules

{

#if WITH_FORWARDED_MODULE_RULES_CTOR

public AnimGraphIK(ReadOnlyTargetRules Target) : base(Target)

#else

public AnimGraphIK(TargetInfo Target)

#endif

{

PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));

PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "../AnimIK/Public"));

PublicIncludePaths.Add(ModuleDirectory);

PublicIncludePaths.AddRange(

new string[] {

"Editor/AnimGraph/Public",

"Editor/AdvancedPreviewScene/Public"

// "Editor/AnimGraph/Classes",

// ... add public include paths required here ...

}

);

PrivateIncludePaths.AddRange(

new string[] {

"AnimGraphIK/Private",

"AnimIK/Private"

// ... add other private include paths required here ...

}

);

PublicDependencyModuleNames.AddRange(

new string[]

{

"Core",

"CoreUObject",

"Engine",

"Slate",

"AnimGraphRuntime",

"BlueprintGraph",

"AnimIK",

// ... add other public dependencies that you statically link with here ...

}

);

PrivateDependencyModuleNames.AddRange(

new string[]

{

"CoreUObject",

"Engine",

"Slate",

"SlateCore",

"InputCore",

"UnrealEd",

"GraphEditor",

"PropertyEditor",

"EditorStyle",

"AnimGraph",

// ... add private dependencies that you statically link with here ...

}

);

PrivateIncludePathModuleNames.AddRange(

new string[] {

"Persona",

"SkeletonEditor",

#if WITH_FORWARDED_MODULE_RULES_CTOR

"AdvancedPreviewScene",

#endif

}

);

DynamicallyLoadedModuleNames.AddRange(

new string[]

{

// ... add any modules that your module loads dynamically here ...

}

);

}

}

DZAnimStudioEditor.Build.cs

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 2018 azhecheng, Inc. All Rights Reserved.

#pragma once

#include "AnimGraphNode_SkeletalControlBase.h"

#include "DZAnimNode_ScaleBone.h"

#include "EdGraph/EdGraphNodeUtils.h"

#include "DZAnimNode_ScaleBoneEdit.generated.h"

UCLASS(MinimalAPI)

class UDZAnimNode_ScaleBoneEdit : public UAnimGraphNode_SkeletalControlBase

{

GENERATED_UCLASS_BODY()

UPROPERTY(EditAnywhere, Category = Settings)

FDZAnimNode_ScaleBone Node;

public:

virtual FText GetTooltipText() const override;

virtual void CopyNodeDataToPreviewNode(FAnimNode_Base* AnimNode) override;

virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;

virtual FEditorModeID GetEditorMode() const override;

virtual void Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent * PreviewSkelMeshComp) const override;

void SetDefaultValue(const FString& InDefaultValueName, const FTransform& InValue);

protected:

virtual FText GetControllerDescription() const override;

virtual const FAnimNode_SkeletalControlBase* GetNode() const override { return &Node; }

};

DZAnimNode_ScaleBoneEdit.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimNode_ScaleBoneEdit.h"

#include "DZAnimStudioEditorPrivatePCH.h"

#include "EditMode/DZAnimNode_ScaleBoneEditMode.h"

#define LOCTEXT_NAMESPACE "DZAnimBaseNodeEditMode"

UDZAnimNode_ScaleBoneEdit::UDZAnimNode_ScaleBoneEdit(const FObjectInitializer& ObjectInitializer)

: Super(ObjectInitializer)

{

}

FText UDZAnimNode_ScaleBoneEdit::GetTooltipText() const

{

return LOCTEXT("AnimGraphNode_DZAnNo_ScaleBodyBone_Tooltip", "The DZAnNode ScaleBodyBone");

}

void UDZAnimNode_ScaleBoneEdit::CopyNodeDataToPreviewNode(FAnimNode_Base* AnimNode)

{

}

FText UDZAnimNode_ScaleBoneEdit::GetNodeTitle(ENodeTitleType::Type TitleType) const

{

return GetControllerDescription();

}

FEditorModeID UDZAnimNode_ScaleBoneEdit::GetEditorMode() const

{

return DZAnimNodeEditModes::ScaleBone;

}

void UDZAnimNode_ScaleBoneEdit::Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent * PreviewSkelMeshComp) const

{

}

void UDZAnimNode_ScaleBoneEdit::SetDefaultValue(const FString& InDefaultValueName, const FTransform& InValue)

{

}

FText UDZAnimNode_ScaleBoneEdit::GetControllerDescription() const

{

return LOCTEXT("DZAnimNode_ScaleBodyBone", "DZAnimNode ScaleBodyBone");

}

DZAnimNode_ScaleBoneEditMode.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

#include "CoreMinimal.h"

#include "UnrealWidget.h"

#include "AnimNodeEditMode.h"

#include "DZAnimNode_ScaleBoneEdit.h"

#include "DZAimBaseNodeEditMode.h"

class FEditorViewportClient;

class FPrimitiveDrawInterface;

class USkeletalMeshComponent;

struct FViewportClick;

class FDZAnimNode_ScaleBoneEditMode : public FDZAnimBaseNodeEditMode

{

public:

FDZAnimNode_ScaleBoneEditMode();

};

DZAnimNode_ScaleBoneEditMode.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimNode_ScaleBoneEditMode.h"

#include "DZAnimStudioEditorPrivatePCH.h"

#include "SceneManagement.h"

#include "EngineUtils.h"

#include "IPersonaPreviewScene.h"

#include "Animation/DebugSkelMeshComponent.h"

FDZAnimNode_ScaleBoneEditMode::FDZAnimNode_ScaleBoneEditMode()

{

}

DZAimBaseNodeEditMode.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

#include "CoreMinimal.h"

#include "InputCoreTypes.h"

#include "UnrealWidget.h"

#include "IAnimNodeEditMode.h"

#include "BonePose.h"

#include "Animation/AnimNodeBase.h"

class FCanvas;

class FEditorViewportClient;

class FPrimitiveDrawInterface;

class USkeletalMeshComponent;

struct FViewportClick;

struct DZANIMSTUDIO_API DZAnimNodeEditModes

{

const static FEditorModeID ScaleBone;

};

class FDZAnimBaseNodeEditMode : public IAnimNodeEditMode

{

public:

FDZAnimBaseNodeEditMode();

/** IAnimNodeEditMode interface */

virtual ECoordSystem GetWidgetCoordinateSystem() const override;

virtual FWidget::EWidgetMode GetWidgetMode() const override;

virtual FWidget::EWidgetMode ChangeToNextWidgetMode(FWidget::EWidgetMode CurWidgetMode) override;

virtual bool SetWidgetMode(FWidget::EWidgetMode InWidgetMode) override;

virtual FName GetSelectedBone() const override;

virtual void DoTranslation(FVector& InTranslation) override;

virtual void DoRotation(FRotator& InRotation) override;

virtual void DoScale(FVector& InScale) override;

virtual void EnterMode(class UAnimGraphNode_Base* InEditorNode, struct FAnimNode_Base* InRuntimeNode) override;

virtual void ExitMode() override;

/** IPersonaEditMode interface */

virtual bool GetCameraTarget(FSphere& OutTarget) const override;

virtual class IPersonaPreviewScene& GetAnimPreviewScene() const override;

virtual void GetOnScreenDebugInfo(TArray<FText>& OutDebugInfo) const override;

/** FEdMode interface */

virtual void Render(const FSceneView* View, FViewport* Viewport, FPrimitiveDrawInterface* PDI) override;

virtual void DrawHUD(FEditorViewportClient* ViewportClient, FViewport* Viewport, const FSceneView* View, FCanvas* Canvas) override;

virtual bool HandleClick(FEditorViewportClient* InViewportClient, HHitProxy* HitProxy, const FViewportClick& Click) override;

virtual FVector GetWidgetLocation() const override;

virtual bool StartTracking(FEditorViewportClient* InViewportClient, FViewport* InViewport) override;

virtual bool EndTracking(FEditorViewportClient* InViewportClient, FViewport* InViewport) override;

virtual bool InputKey(FEditorViewportClient* InViewportClient, FViewport* InViewport, FKey InKey, EInputEvent InEvent) override;

virtual bool InputDelta(FEditorViewportClient* InViewportClient, FViewport* InViewport, FVector& InDrag, FRotator& InRot, FVector& InScale) override;

virtual bool GetCustomDrawingCoordinateSystem(FMatrix& InMatrix, void* InData) override;

virtual bool GetCustomInputCoordinateSystem(FMatrix& InMatrix, void* InData) override;

virtual bool ShouldDrawWidget() const override;

virtual void Tick(FEditorViewportClient* ViewportClient, float DeltaTime) override;

};

DZAimBaseNodeEditMode.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 2018 azhecheng, Inc. All Rights Reserved.

#include "DZAimBaseNodeEditMode.h"

#include "DZAnimStudioEditorPrivatePCH.h"

#include "EditorViewportClient.h"

#include "IPersonaPreviewScene.h"

#include "Animation/DebugSkelMeshComponent.h"

#include "BoneControllers/AnimNode_SkeletalControlBase.h"

#include "EngineUtils.h"

#include "AnimGraphNode_SkeletalControlBase.h"

#include "AssetEditorModeManager.h"

const FEditorModeID DZAnimNodeEditModes::ScaleBone("AnimGraph.SkeletalControl.ScaleBone");

#define LOCTEXT_NAMESPACE "DZAnimBaseNodeEditMode"

FDZAnimBaseNodeEditMode::FAnimIKNodeEditMode()

{

}

bool FDZAnimBaseNodeEditMode::GetCameraTarget(FSphere& OutTarget) const

{

return true;

}

IPersonaPreviewScene& FDZAnimBaseNodeEditMode::GetAnimPreviewScene() const

{

return *static_cast<IPersonaPreviewScene*>(static_cast<FAssetEditorModeManager*>(Owner)->GetPreviewScene());

}

void FDZAnimBaseNodeEditMode::GetOnScreenDebugInfo(TArray<FText>& OutDebugInfo) const

{

}

ECoordSystem FDZAnimBaseNodeEditMode::GetWidgetCoordinateSystem() const

{

return ECoordSystem::COORD_None;

}

FWidget::EWidgetMode FDZAnimBaseNodeEditMode::GetWidgetMode() const

{

return FWidget::EWidgetMode::WM_None;

}

FWidget::EWidgetMode FDZAnimBaseNodeEditMode::ChangeToNextWidgetMode(FWidget::EWidgetMode CurWidgetMode)

{

return FWidget::EWidgetMode::WM_None;

}

bool FDZAnimBaseNodeEditMode::SetWidgetMode(FWidget::EWidgetMode InWidgetMode)

{

return false;

}

FName FDZAnimBaseNodeEditMode::GetSelectedBone() const

{

return NAME_None;

}

void FDZAnimBaseNodeEditMode::EnterMode(UAnimGraphNode_Base* InEditorNode, FAnimNode_Base* InRuntimeNode)

{

}

void FDZAnimBaseNodeEditMode::ExitMode()

{

}

void FDZAnimBaseNodeEditMode::Render(const FSceneView* View, FViewport* Viewport, FPrimitiveDrawInterface* PDI)

{

}

void FDZAnimBaseNodeEditMode::DrawHUD(FEditorViewportClient* ViewportClient, FViewport* Viewport, const FSceneView* View, FCanvas* Canvas)

{

}

bool FDZAnimBaseNodeEditMode::HandleClick(FEditorViewportClient* InViewportClient, HHitProxy* HitProxy, const FViewportClick& Click)

{

}

FVector FDZAnimBaseNodeEditMode::GetWidgetLocation() const

{

return FVector::ZeroVector;

}

bool FDZAnimBaseNodeEditMode::StartTracking(FEditorViewportClient* InViewportClient, FViewport* InViewport)

{

return true;

}

bool FDZAnimBaseNodeEditMode::EndTracking(FEditorViewportClient* InViewportClient, FViewport* InViewport)

{

return true;

}

bool FDZAnimBaseNodeEditMode::InputKey(FEditorViewportClient* InViewportClient, FViewport* InViewport, FKey InKey, EInputEvent InEvent)

{

bool bHandled = false;

return bHandled;

}

bool FDZAnimBaseNodeEditMode::InputDelta(FEditorViewportClient* InViewportClient, FViewport* InViewport, FVector& InDrag, FRotator& InRot, FVector& InScale)

{

bool bHandled = false;

return bHandled;

}

bool FDZAnimBaseNodeEditMode::GetCustomDrawingCoordinateSystem(FMatrix& InMatrix, void* InData)

{

return false;

}

bool FDZAnimBaseNodeEditMode::GetCustomInputCoordinateSystem(FMatrix& InMatrix, void* InData)

{

return GetCustomDrawingCoordinateSystem(InMatrix, InData);

}

bool FDZAnimBaseNodeEditMode::ShouldDrawWidget() const

{

return true;

}

void FDZAnimBaseNodeEditMode::DoTranslation(FVector& InTranslation)

{

}

void FDZAnimBaseNodeEditMode::DoRotation(FRotator& InRotation)

{

}

void FDZAnimBaseNodeEditMode::DoScale(FVector& InScale)

{

}

void FDZAnimBaseNodeEditMode::Tick(FEditorViewportClient* ViewportClient, float DeltaTime)

{

}

void FDZAnimBaseNodeEditMode::ConvertToComponentSpaceTransform(const USkeletalMeshComponent* SkelComp, const FTransform & InTransform, FTransform & OutCSTransform, int32 BoneIndex, EBoneControlSpace Space)

{

}

void FDZAnimBaseNodeEditMode::ConvertToBoneSpaceTransform(const USkeletalMeshComponent* SkelComp, const FTransform & InCSTransform, FTransform & OutBSTransform, int32 BoneIndex, EBoneControlSpace Space)

{

}

FVector FDZAnimBaseNodeEditMode::ConvertCSVectorToBoneSpace(const USkeletalMeshComponent* SkelComp, FVector& InCSVector, FCSPose<FCompactHeapPose>& MeshBases, const FName& BoneName, const EBoneControlSpace Space)

{

FVector OutVector = InCSVector;

return OutVector;

}

FQuat FDZAnimBaseNodeEditMode::ConvertCSRotationToBoneSpace(const USkeletalMeshComponent* SkelComp, FRotator& InCSRotator, FCSPose<FCompactHeapPose>& MeshBases, const FName& BoneName, const EBoneControlSpace Space)

{

FQuat OutQuat = FQuat::Identity;

return OutQuat;

}

FVector FDZAnimBaseNodeEditMode::ConvertWidgetLocation(const USkeletalMeshComponent* SkelComp, FCSPose<FCompactHeapPose>& MeshBases, const FName& BoneName, const FVector& Location, const EBoneControlSpace Space)

{

FVector WidgetLoc = FVector::ZeroVector;

return WidgetLoc;

}

#undef LOCTEXT_NAMESPACE

DZAnimStudioPrivatePCH.h

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 2018 azhecheng, Inc. All Rights Reserved.

#ifndef __DZAnimStudioPrivatePCH_h__

#define __DZAnimStudioPrivatePCH_h__

#include "Engine.h"

#include "Runtime/Launch/Resources/Version.h"

#include "DZAnimStudio.h"

#endif

DZAnimStudio.Build.cs

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

using System.IO;

public class DZAnimStudio : ModuleRules

{

#if WITH_FORWARDED_MODULE_RULES_CTOR

public DZAnimStudio(ReadOnlyTargetRules Target) : base(Target)

#else

public DZAnimStudio(TargetInfo Target)

#endif

{

PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));

PublicIncludePaths.Add(ModuleDirectory);

PublicIncludePaths.AddRange(

new string[] {

"Runtime/Core/Public/Modules",

"Runtime/AnimGraphRuntime/Public/BoneControllers",

// ... add other public include paths required here ...

}

);

PrivateIncludePaths.AddRange(

new string[] {

"DZAnimStudio/Private",

// ... add other private include paths required here ...

}

);

PublicDependencyModuleNames.AddRange(

new string[]

{

"Core",

"CoreUObject",

"Engine",

"Slate",

"AnimGraphRuntime",

// ... add other public dependencies that you statically link with here ...

}

);

}

}

DZ_AnimNode_SnapIK.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "Misc/CoreMisc.h"

#include "Stats/Stats.h"

#include "Engine/EngineTypes.h"

#include "EngineDefines.h"

#include "AnimNode_SkeletalControlBase.h"

#include "DZ_AnimNode_SnapIK.generated.h"

USTRUCT(BlueprintInternalUseOnly)

struct DZANIMSTUDIO_API FDZ_AnimNode_SnapIK : public FAnimNode_SkeletalControlBase

{

GENERATED_USTRUCT_BODY()

// Called to gather on-screen debug data. This is called on the game thread.

virtual void GatherDebugData(FNodeDebugData& DebugData) override;

// Evaluate the new component-space transforms for the affected bones.

virtual void EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext& Output, TArray<FBoneTransform>& OutBoneTransforms) override;

// Return true if it is valid to Evaluate

virtual bool IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones) override;

private:

// Initialize any bone references you have

virtual void InitializeBoneReferences(const FBoneContainer& RequiredBones) override;

};

DZAnimNode_ScaleBone.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimStudioCore.h"

#include "AnimNode_SkeletalControlBase.h"

#include "DZAnimNode_ScaleBone.generated.h"

USTRUCT()

struct DZANIMSTUDIO_API FDZAnimNode_ScaleBone : public FAnimNode_SkeletalControlBase

{

GENERATED_USTRUCT_BODY()

public:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BodyBone)

TArray<FDZScaleBoneData> mEdBoneList;

// FAnimNode_Base interface

virtual void GatherDebugData(FNodeDebugData& DebugData) override;

// End of FAnimNode_Base interface

#if ENGINE_MINOR_VERSION >= 16

virtual void EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext& Output, TArray<FBoneTransform>& OutBoneTransforms) override;

#else

virtual void EvaluateBoneTransforms(USkeletalMeshComponent* SkelComp, FCSPose<FCompactPose>& MeshBases, TArray<FBoneTransform>& OutBoneTransforms) override;

#endif

virtual bool IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones) override;

private:

// FAnimNode_SkeletalControlBase interface

virtual void InitializeBoneReferences(const FBoneContainer& RequiredBones) override;

};

DZAnimStudio.h

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

#include "Modules/ModuleManager.h"

class FDZAnimStudioModule : public IModuleInterface

{

public:

/** IModuleInterface implementation */

virtual void StartupModule() override;

virtual void ShutdownModule() override;

};

DZAnimStudio_Check_BluprintFunction.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

//#include "CoreMinimal.h"

//#include "Kismet/BlueprintFunctionLibrary.h"

//#include "DZAnimStudio_Check_BluprintFunction.generated.h"

//

//

//class DZANIMSTUDIO_API UDZAnimStudio_CheckAnim_BluprintFuntion :public UBlueprintFunctionLibrary

//{

//        GENERATED_BODY();

//public:

//

//        UFUNCTION(BlueprintCallable, Category = "DZAnimStudio|PlayAnimBluprintFuntion", meta = (WorldContext = "WorldContextObject"))

//        static void DZ_PlayAnimtionMontage();

//};

DZAnimStudioCore.h

---------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

#include "Misc/CoreMisc.h"

#include "Stats/Stats.h"

#include "Engine/EngineTypes.h"

#include "EngineDefines.h"

#include "AnimNode_SkeletalControlBase.h"

#include "Runtime/Launch/Resources/Version.h"

#include "DZAnimStudioCore.generated.h"

UENUM()

enum EDZBoneModificationMode

{

/** The modifier ignores this channel (keeps the existing bone translation, rotation, or scale). */

DZBMM_Ignore UMETA(DisplayName = "Ignore"),

/** The modifier replaces the existing translation, rotation, or scale. */

DZBMM_Replace UMETA(DisplayName = "Replace Existing"),

/** The modifier adds to the existing translation, rotation, or scale. */

DZBMM_Additive UMETA(DisplayName = "Add to Existing")

};

/************************************************************************/

/* *Editer Bone Item Config Data

*@Author: BaiPaoXD * /

/************************************************************************/

USTRUCT(BlueprintType)

struct FDZScaleBoneData

{

GENERATED_USTRUCT_BODY()

public:

UPROPERTY(EditAnywhere, Category = EDITBOBE)

FBoneReference mEd_Bone;

UPROPERTY(EditAnywhere, Category = EDITBOBE)

TEnumAsByte<EDZBoneModificationMode> ScaleMode;

UPROPERTY(EditAnywhere, Category = EDITBOBE)

TEnumAsByte<enum EBoneControlSpace> ScaleSpace;

/** New Scale of bone to apply. This is only worldspace. */

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = EDITBOBE, meta = (PinShownByDefault))

FVector Scale;

};

USTRUCT()

struct FDZAnimStudioBoneTransform

{

GENERATED_USTRUCT_BODY()

UPROPERTY()

int32 BoneIndex;

UPROPERTY()

FTransform Transform;

};

struct DZANIMSTUDIO_API FDZAnimStudioCore

{

static FVector GetCurrentLocation(FCSPose<FCompactPose>& MeshBases, const FCompactPoseBoneIndex& BoneIndex);

};

DZ_AnimNode_SnapIK.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZ_AnimNode_SnapIK.h"

#include "AnimationRuntime.h"

#include "Animation/AnimInstanceProxy.h"

void FDZ_AnimNode_SnapIK::GatherDebugData(FNodeDebugData& DebugData)

{

}

void FDZ_AnimNode_SnapIK::EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext& Output, TArray<FBoneTransform>& OutBoneTransforms)

{

}

bool FDZ_AnimNode_SnapIK::IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones)

{

return false;

}

void FDZ_AnimNode_SnapIK::InitializeBoneReferences(const FBoneContainer& RequiredBones)

{

}

DZAnimNode_ScaleBone.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimNode_ScaleBone.h"

#include "DZAnimStudioPrivatePCH.h"

#include "AnimationRuntime.h"

#include "Animation/AnimInstanceProxy.h"

//FDZAnimNode_ScaleBone::FDZAnimNode_ScaleBone()

//{

//

//}

void FDZAnimNode_ScaleBone::GatherDebugData(FNodeDebugData& DebugData)

{

}

/************************************************************************/

/* 白袍小道 骨骼节点缩放 */

/************************************************************************/

#if ENGINE_MINOR_VERSION >= 16

void FDZAnimNode_ScaleBone::EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext & Output, TArray<FBoneTransform>& OutBoneTransforms)

{

const FBoneContainer& BoneContainer = Output.Pose.GetPose().GetBoneContainer();

#else

void FDZAnimNode_ScaleBone::EvaluateBoneTransforms(USkeletalMeshComponent * SkelComp, FCSPose<FCompactPose>& MeshBases, TArray<FBoneTransform>& OutBoneTransforms)

{

const FBoneContainer& BoneContainer = MeshBases.GetPose().GetBoneContainer();

#endif

for (int i = 0; i < this->mEdBoneList.Num(); i++)

{

FCompactPoseBoneIndex CompactPoseBoneToModify = this->mEdBoneList[i].mEd_Bone.GetCompactPoseIndex(BoneContainer);

FTransform NewBoneTM = Output.Pose.GetComponentSpaceTransform(CompactPoseBoneToModify);

FTransform ComponentTransform = Output.AnimInstanceProxy->GetComponentTransform();

if (this->mEdBoneList[i].ScaleMode != DZBMM_Ignore)

{

// Convert to Bone Space.

FAnimationRuntime::ConvertCSTransformToBoneSpace(ComponentTransform, Output.Pose, NewBoneTM, CompactPoseBoneToModify, this->mEdBoneList[i].ScaleSpace);

if (this->mEdBoneList[i].ScaleMode == DZBMM_Additive)

{

NewBoneTM.SetScale3D(NewBoneTM.GetScale3D() * this->mEdBoneList[i].Scale);

}

else

{

NewBoneTM.SetScale3D(this->mEdBoneList[i].Scale);

}

// Convert back to Component Space.

FAnimationRuntime::ConvertBoneSpaceTransformToCS(ComponentTransform, Output.Pose, NewBoneTM, CompactPoseBoneToModify, this->mEdBoneList[i].ScaleSpace);

}

OutBoneTransforms.Add(FBoneTransform(this->mEdBoneList[i].mEd_Bone.GetCompactPoseIndex(BoneContainer), NewBoneTM));

}

}

bool FDZAnimNode_ScaleBone::IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones)

{

for (int i = 0; i < this->mEdBoneList.Num(); i++)

{

if (!this->mEdBoneList[i].mEd_Bone.IsValidToEvaluate(RequiredBones)) {

return false;

}

}

// if both bones are valid

return true;

}

void FDZAnimNode_ScaleBone::InitializeBoneReferences(const FBoneContainer& RequiredBones)

{

for (int i = 0; i < this->mEdBoneList.Num(); i++)

{

this->mEdBoneList[i].mEd_Bone.Initialize(RequiredBones);

}

}

DZAnimStudio.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.

#include "DZAnimStudio.h"

#define LOCTEXT_NAMESPACE "FDZAnimStudioModule"

void FDZAnimStudioModule::StartupModule()

{

// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

}

void FDZAnimStudioModule::ShutdownModule()

{

// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,

// we call this function before unloading the module.

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FDZAnimStudioModule, DZAnimStudio)

DZAnimStudio_Check_BluprintFunction.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

//#include "DZAnimStudio_Check_BluprintFunction.h"

//

//void UDZAnimStudio_CheckAnim_BluprintFuntion::DZ_PlayAnimtionMontage()

//{

//

//}

DZAnimStudioCore.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------

#include "DZAnimStudioCore.h"

#include "DZAnimStudioPrivatePCH.h"

#include "AnimationRuntime.h"

#include "Animation/AnimCompress.h"

#include "Components/SkeletalMeshComponent.h"

#include "Animation/AnimNotifies/AnimNotify.h"

FVector FDZAnimStudioCore::GetCurrentLocation(FCSPose<FCompactPose>& MeshBases, const FCompactPoseBoneIndex& BoneIndex)

{

return MeshBases.GetComponentSpaceTransform(BoneIndex).GetLocation();

}

原文地址:https://www.cnblogs.com/BaiPao-XD/p/10350587.html

时间: 2025-01-05 06:58:51

(原)Unreal源码搬山-动画篇 自定义动画节点(一)的相关文章

jQuery-4.动画篇---自定义动画

jQuery中动画animate(上) 有些复杂的动画通过之前学到的几个动画函数是不能够实现,这时候就需要强大的animate方法了 操作一个元素执行3秒的淡入动画,对比一下2组动画设置的区别 $(elem).fadeOut(3000) $(elem).animate({ opacity:0 },3000) 显而易见,animate方法更加灵活了,可以精确的控制样式属性从而执行动画 语法: .animate( properties ,[ duration ], [ easing ], [ com

JDK源码分析之String篇

------------------------------String在内存中的存储情况(一下内容摘自参考资料1)----------------------------------- 前提:先了解下什么是声明,什么时候才算是产生了对象实例 其中x并未看到内存分配,变量在使用前必须先声明,再赋值,然后才可以使用.java基础数据类型会用对应的默认值进行初始化 一.首先看看Java虚拟机JVM的内存块及其变量.对象内存空间是怎么存储分配的 1.栈:存放基本数据类型及对象变量的引用,对象本身不存放

Android触摸屏事件派发机制详解与源码分析二(ViewGroup篇)

1 背景 还记得前一篇<Android触摸屏事件派发机制详解与源码分析一(View篇)>中关于透过源码继续进阶实例验证模块中存在的点击Button却触发了LinearLayout的事件疑惑吗?当时说了,在那一篇咱们只讨论View的触摸事件派发机制,这个疑惑留在了这一篇解释,也就是ViewGroup的事件派发机制. PS:阅读本篇前建议先查看前一篇<Android触摸屏事件派发机制详解与源码分析一(View篇)>,这一篇承接上一篇. 关于View与ViewGroup的区别在前一篇的A

Hadoop2源码分析-准备篇

1.概述 我们已经能够搭建一个高可用的Hadoop平台了,也熟悉并掌握了一个项目在Hadoop平台下的开发流程,基于Hadoop的一些套件我们也能够使用,并且能利用这些套件进行一些任务的开发.在Hadoop的应用级别上,我们接着往后面去研究学习,那就是Hadoop的源码了,作为Hadoop开发人员,我们得去学习和研究Hadoop得实现原理,底层框架的设计,编码的实现过程等等,下面就开始我们今天的Hadoop源码分析之旅. 2.准备 在分析源码之前,我们需要准备好分析源码的环境,以及如何去分析(分

Monkey源码分析番外篇之Android注入事件的三种方法比较

原文:http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.VEoIoIuUcaV 往下分析monkey事件注入源码之前先了解下在android系统下事件注入的方式,翻译一篇国外文章如下. Method 1: Using internal APIs 方法1:使用内部APIs This approach has its risks, like it is always with intern

Android View 事件分发机制源码详解(View篇)

前言 在Android View 事件分发机制源码详解(ViewGroup篇)一文中,主要对ViewGroup#dispatchTouchEvent的源码做了相应的解析,其中说到在ViewGroup把事件传递给子View的时候,会调用子View的dispatchTouchEvent,这时分两种情况,如果子View也是一个ViewGroup那么再执行同样的流程继续把事件分发下去,即调用ViewGroup#dispatchTouchEvent:如果子View只是单纯的一个View,那么调用的是Vie

Mongoose源码剖析:外篇之web服务器

转 http://www.cnblogs.com/skynet/archive/2010/07/24/1784110.html 这个博主里面很多关于mongoose的剖析 引言 在深入Mongoose源码剖析之前,我们应该清楚web服务器是什么?它提供什么服务?怎样提供服务?使用什么协议?客户端如何唯一标识web服务器的资源?下面我们抛开Mongoose,来介绍一个web服务的这些通性. web服务器:通常是指一个计算机程序(web服务器是什么?),在World Wide Web上提供诸如web

Android触摸屏事件派发机制详解与源码分析三(Activity篇)

PS一句:最终还是选择CSDN来整理发表这几年的知识点,该文章平行迁移到CSDN.因为CSDN也支持MarkDown语法了,牛逼啊! [工匠若水 http://blog.csdn.net/yanbober] 该篇承接上一篇<Android触摸屏事件派发机制详解与源码分析二(ViewGroup篇)>,阅读本篇之前建议先阅读. 1 背景 还记得前面两篇从Android的基础最小元素控件(View)到ViewGroup控件的触摸屏事件分发机制分析吗?你可能看完会有疑惑,View的事件是ViewGro

Matrix源码分析之第一篇

Matrix源码分析之第一篇 概述 前几天腾讯将一款Android应用性能监控的框架matrix开源了,源码地址在https://github.com/Tencent/matrix,作者是微信终端团队.matrix到底是什么?据官方说法如下:Matrix 是一款微信研发并日常使用的 APM(Application Performance Manage),当前主要运行在 Android 平台上. Matrix 的目标是建立统一的应用性能接入框架,通过各种性能监控方案,对性能监控项的异常数据进行采集