General refactoring
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "Materials/Material.h"
|
||||
#include "MaterialGraph/MaterialGraph.h"
|
||||
#include "MaterialGraph/MaterialGraphNode.h"
|
||||
#include "IMaterialEditor.h"
|
||||
#include "Engine/LevelScriptBlueprint.h"
|
||||
#include "Subsystems/AssetEditorSubsystem.h"
|
||||
|
||||
@@ -40,7 +41,6 @@ const TArray<MCPFetcher::FWalker>& MCPFetcher::GetWalkerTable()
|
||||
{ TEXT("pin"), TEXT("Find a named UEdGraphPin on a node"), &MCPFetcher::Pin },
|
||||
{ TEXT("component"), TEXT("Find a named component in a Blueprint's SCS"), &MCPFetcher::Component },
|
||||
{ TEXT("levelblueprint"), TEXT("Get the level blueprint from a UWorld"), &MCPFetcher::LevelBlueprint },
|
||||
// { TEXT("matexp"), TEXT("Get the UMaterialExpression from a UMaterialGraphNode"), &MCPFetcher::MatExp },
|
||||
};
|
||||
return Table;
|
||||
}
|
||||
@@ -100,12 +100,28 @@ MCPFetcher& MCPFetcher::Asset(const FString& PackagePath)
|
||||
if (!Editor)
|
||||
return SetError(FString::Printf(TEXT("Could not find editor instance for '%s'"), *PackagePath));
|
||||
|
||||
// If this is a material open in the editor, use the editor's transient copy.
|
||||
// If this is a material, use the editor's transient copy.
|
||||
if (UMaterial* Mat = ::Cast<UMaterial>(Obj))
|
||||
SetObj(MCPUtils::ReplaceMaterialWithTransientCopy(Mat));
|
||||
{
|
||||
IMaterialEditor *MatEditor = static_cast<IMaterialEditor*>(Editor);
|
||||
SetObj(MatEditor->GetMaterialInterface()->GetBaseMaterial());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool MCPFetcher::CheckAssetIsA(UClass* StaticClass)
|
||||
{
|
||||
if (bError) return false;
|
||||
if (!OriginalAsset || !OriginalAsset->IsA(StaticClass))
|
||||
{
|
||||
SetError(FString::Printf(TEXT("Asset is %s, expected %s"),
|
||||
OriginalAsset ? *OriginalAsset->GetClass()->GetName() : TEXT("null"),
|
||||
*StaticClass->GetName()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const MCPFetcher::FWalker* MCPFetcher::GetWalker(const FString& Key)
|
||||
{
|
||||
for (const FWalker& W : GetWalkerTable())
|
||||
@@ -314,18 +330,3 @@ MCPFetcher& MCPFetcher::ToGraph()
|
||||
|
||||
return TypeMismatch(TEXT("ToGraph"), TEXT("Graph or Material"));
|
||||
}
|
||||
|
||||
MCPFetcher& MCPFetcher::MatExp(const FString& Value)
|
||||
{
|
||||
if (bError) return *this;
|
||||
|
||||
UMaterialGraphNode* MatNode = ::Cast<UMaterialGraphNode>(Obj);
|
||||
if (!MatNode)
|
||||
return TypeMismatch(TEXT("matexp"), TEXT("UMaterialGraphNode"));
|
||||
|
||||
if (!MatNode->MaterialExpression)
|
||||
return SetError(FString::Printf(TEXT("Node '%s' has no MaterialExpression"), *MCPUtils::FormatName(MatNode)));
|
||||
|
||||
SetObj(MatNode->MaterialExpression);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user