Updated
This commit is contained in:
195
Source/FLESHEditor/Private/FLESHGraph/FLESHExecutor.cpp
Normal file
195
Source/FLESHEditor/Private/FLESHGraph/FLESHExecutor.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
#include "FLESHGraph/FLESHExecutor.h"
|
||||
#include "Engine/SkeletalMesh.h"
|
||||
#include "Components/SkeletalMeshComponent.h"
|
||||
#include "NiagaraSystem.h"
|
||||
#include "NiagaraComponent.h"
|
||||
#include "NiagaraFunctionLibrary.h"
|
||||
#include "Components/DecalComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "PhysicalMaterials/PhysicalMaterial.h"
|
||||
#include "Logging/LogMacros.h"
|
||||
|
||||
// Define log category
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogFLESHExecutor, Log, All);
|
||||
|
||||
UFLESHExecutor::UFLESHExecutor()
|
||||
{
|
||||
// Initialize default values
|
||||
Compiler = nullptr;
|
||||
TargetActor = nullptr;
|
||||
TargetSkeletalMesh = nullptr;
|
||||
|
||||
// Create boolean cut tool
|
||||
CutTool = CreateDefaultSubobject<UBooleanCutTool>(TEXT("CutTool"));
|
||||
}
|
||||
|
||||
void UFLESHExecutor::Initialize(UFLESHCompiler* InCompiler)
|
||||
{
|
||||
// Set compiler reference
|
||||
Compiler = InCompiler;
|
||||
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH Executor initialized with compiler: %s"),
|
||||
Compiler ? TEXT("Valid") : TEXT("Invalid"));
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::Execute(AActor* InTargetActor)
|
||||
{
|
||||
// Set target actor
|
||||
TargetActor = InTargetActor;
|
||||
|
||||
// Find skeletal mesh component
|
||||
if (!FindTargetSkeletalMesh())
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Cannot execute FLESH graph, skeletal mesh component not found"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if compiler is valid
|
||||
if (!Compiler)
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Cannot execute FLESH graph, invalid compiler"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if compilation was successful
|
||||
if (!Compiler->IsCompilationSuccessful())
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Cannot execute FLESH graph, compilation failed: %s"),
|
||||
*Compiler->GetErrorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get execution order from compiler
|
||||
TArray<int32> ExecutionOrder = Compiler->GetExecutionOrder();
|
||||
|
||||
// Get compiled node data
|
||||
TArray<FFLESHNodeData> CompiledNodeData = Compiler->GetCompiledNodeData();
|
||||
|
||||
// Execute nodes in order
|
||||
for (int32 NodeIndex : ExecutionOrder)
|
||||
{
|
||||
// Check if node index is valid
|
||||
if (!CompiledNodeData.IsValidIndex(NodeIndex))
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Invalid node index in execution order: %d"), NodeIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Execute node
|
||||
if (!ExecuteNode(CompiledNodeData[NodeIndex]))
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Failed to execute node: %s"),
|
||||
*CompiledNodeData[NodeIndex].NodeName.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Graph executed successfully on actor: %s"),
|
||||
TargetActor ? *TargetActor->GetName() : TEXT("Invalid"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UFLESHExecutor::SetCutTool(UBooleanCutTool* InCutTool)
|
||||
{
|
||||
CutTool = InCutTool;
|
||||
}
|
||||
|
||||
UBooleanCutTool* UFLESHExecutor::GetCutTool() const
|
||||
{
|
||||
return CutTool;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::FindTargetSkeletalMesh()
|
||||
{
|
||||
// Check if target actor is valid
|
||||
if (!TargetActor)
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Invalid target actor"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find skeletal mesh component
|
||||
TargetSkeletalMesh = TargetActor->FindComponentByClass<USkeletalMeshComponent>();
|
||||
|
||||
// Check if skeletal mesh component is valid
|
||||
if (!TargetSkeletalMesh)
|
||||
{
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Target actor does not have a skeletal mesh component"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// Execute node based on type
|
||||
switch (NodeData.NodeType)
|
||||
{
|
||||
case EFLESHNodeType::Cut:
|
||||
return ExecuteCutNode(NodeData);
|
||||
|
||||
case EFLESHNodeType::BloodEffect:
|
||||
return ExecuteBloodEffectNode(NodeData);
|
||||
|
||||
case EFLESHNodeType::Physics:
|
||||
return ExecutePhysicsNode(NodeData);
|
||||
|
||||
case EFLESHNodeType::Organ:
|
||||
return ExecuteOrganNode(NodeData);
|
||||
|
||||
case EFLESHNodeType::Wound:
|
||||
return ExecuteWoundNode(NodeData);
|
||||
|
||||
case EFLESHNodeType::BoneSelection:
|
||||
return ExecuteBoneSelectionNode(NodeData);
|
||||
|
||||
default:
|
||||
UE_LOG(LogFLESHExecutor, Warning, TEXT("FLESH: Unknown node type for node: %s"),
|
||||
*NodeData.NodeName.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteCutNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement cut node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing cut node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteBloodEffectNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement blood effect node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing blood effect node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecutePhysicsNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement physics node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing physics node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteOrganNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement organ node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing organ node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteWoundNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement wound node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing wound node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UFLESHExecutor::ExecuteBoneSelectionNode(const FFLESHNodeData& NodeData)
|
||||
{
|
||||
// TODO: Implement bone selection node execution
|
||||
UE_LOG(LogFLESHExecutor, Log, TEXT("FLESH: Executing bone selection node: %s"), *NodeData.NodeName.ToString());
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user