Working on editing MG
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "K2Node_VariableGet.h"
|
||||
#include "K2Node_CallFunction.h"
|
||||
#include "K2Node_FunctionEntry.h"
|
||||
#include "MaterialGraph/MaterialGraphNode.h"
|
||||
|
||||
static FString WrapText(const FString& Text, int32 ColLimit, const FString& Prefix)
|
||||
{
|
||||
@@ -47,7 +48,7 @@ FlxBlueprintExporter::FlxBlueprintExporter(UEdGraph* InGraph)
|
||||
: Graph(InGraph)
|
||||
{
|
||||
SortNodes();
|
||||
EmitLocalVariables();
|
||||
EmitLocalVariables();
|
||||
EmitDetails();
|
||||
EmitGraph();
|
||||
EmitComments();
|
||||
@@ -232,6 +233,9 @@ void FlxBlueprintExporter::EmitNode(UEdGraphNode* Node)
|
||||
|
||||
Output.Appendf(TEXT("\nnode %s: %s\n"), *MCPUtils::FormatName(Node), *MCPUtils::FormatNodeTitle(Node));
|
||||
|
||||
// Emit material expression properties (if applicable).
|
||||
EmitMaterialProperties(Node, Output, true);
|
||||
|
||||
// Emit input data pins.
|
||||
for (UEdGraphPin* Pin : FilterPins(Node, EGPD_Input))
|
||||
{
|
||||
@@ -274,6 +278,39 @@ void FlxBlueprintExporter::EmitNode(UEdGraphNode* Node)
|
||||
}
|
||||
}
|
||||
|
||||
void FlxBlueprintExporter::EmitMaterialProperty(UMaterialExpression* Expression, FProperty* Prop, FStringBuilderBase& Out)
|
||||
{
|
||||
FString ValueStr = MCPUtils::GetPropertyValueText(Expression, Prop);
|
||||
ValueStr.ReplaceInline(TEXT("\r\n"), TEXT(" "));
|
||||
ValueStr.ReplaceInline(TEXT("\n"), TEXT(" "));
|
||||
if (ValueStr.Len() > 80)
|
||||
ValueStr = ValueStr.Left(80) + TEXT("...");
|
||||
|
||||
bool bEditable = !Prop->HasAnyPropertyFlags(CPF_EditConst);
|
||||
Out.Appendf(TEXT(" %s %s %s = %s\n"),
|
||||
bEditable ? TEXT("editable") : TEXT("readonly"),
|
||||
*MCPUtils::FormatPropertyType(Prop),
|
||||
*MCPUtils::FormatName(Prop),
|
||||
*ValueStr);
|
||||
}
|
||||
|
||||
void FlxBlueprintExporter::EmitMaterialProperties(UEdGraphNode* Node, FStringBuilderBase& Out, bool bPrimary)
|
||||
{
|
||||
UMaterialGraphNode* MatNode = Cast<UMaterialGraphNode>(Node);
|
||||
if (!MatNode || !MatNode->MaterialExpression) return;
|
||||
|
||||
UMaterialExpression* Expression = MatNode->MaterialExpression;
|
||||
FString PrimaryCategory = Expression->GetClass()->GetName();
|
||||
TArray<FProperty*> Props = MCPUtils::SearchProperties(Expression, FString(), CPF_Edit, false);
|
||||
|
||||
for (FProperty* Prop : Props)
|
||||
{
|
||||
FString Category = Prop->HasMetaData(TEXT("Category")) ? Prop->GetMetaData(TEXT("Category")) : FString();
|
||||
if ((Category == PrimaryCategory) == bPrimary)
|
||||
EmitMaterialProperty(Expression, Prop, Out);
|
||||
}
|
||||
}
|
||||
|
||||
void FlxBlueprintExporter::EmitLocalVariables()
|
||||
{
|
||||
for (UEdGraphNode* Node : Graph->Nodes)
|
||||
@@ -312,6 +349,8 @@ void FlxBlueprintExporter::EmitDetails()
|
||||
if (Node->IsA<UK2Node_VariableGet>()) continue;
|
||||
Details.Appendf(TEXT("details %s\n"), *MCPUtils::FormatName(Node));
|
||||
Details.Appendf(TEXT(" pos %d, %d\n"), Node->NodePosX, Node->NodePosY);
|
||||
|
||||
EmitMaterialProperties(Node, Details, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +366,7 @@ void FlxBlueprintExporter::EmitComments()
|
||||
int32 CH = CommentNode->NodeHeight;
|
||||
|
||||
// Emit header.
|
||||
Output.Append(TEXT("\ncomment:\n"));
|
||||
Output.Appendf(TEXT("\ncomment %s:\n"), *MCPUtils::FormatName(CommentNode));
|
||||
|
||||
// Emit wrapped, indented body.
|
||||
Output.Append(WrapText(CommentNode->NodeComment, 70, TEXT(" - ")));
|
||||
|
||||
@@ -267,6 +267,42 @@ MCPFetcher& MCPFetcher::Template()
|
||||
return *this;
|
||||
}
|
||||
|
||||
MCPFetcher& MCPFetcher::ToBlueprint()
|
||||
{
|
||||
if (bError) return *this;
|
||||
if (::Cast<UBlueprint>(Obj)) return *this;
|
||||
|
||||
if (UWorld* World = ::Cast<UWorld>(Obj))
|
||||
{
|
||||
if (!World->PersistentLevel)
|
||||
return SetError(TEXT("ToBlueprint: World has no PersistentLevel"));
|
||||
ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(true);
|
||||
if (!LevelBP)
|
||||
return SetError(TEXT("ToBlueprint: World has no level blueprint"));
|
||||
SetObj(LevelBP);
|
||||
return *this;
|
||||
}
|
||||
|
||||
return TypeMismatch(TEXT("ToBlueprint"), TEXT("Blueprint or World"));
|
||||
}
|
||||
|
||||
MCPFetcher& MCPFetcher::ToGraph()
|
||||
{
|
||||
if (bError) return *this;
|
||||
if (::Cast<UEdGraph>(Obj)) return *this;
|
||||
|
||||
if (UMaterial* Mat = ::Cast<UMaterial>(Obj))
|
||||
{
|
||||
MCPUtils::EnsureMaterialGraph(Mat);
|
||||
if (!Mat->MaterialGraph)
|
||||
return SetError(FString::Printf(TEXT("ToGraph: Material '%s' has no material graph"), *Mat->GetName()));
|
||||
SetObj(Mat->MaterialGraph);
|
||||
return *this;
|
||||
}
|
||||
|
||||
return TypeMismatch(TEXT("ToGraph"), TEXT("Graph or Material"));
|
||||
}
|
||||
|
||||
MCPFetcher& MCPFetcher::MatExp(const FString& Value)
|
||||
{
|
||||
if (bError) return *this;
|
||||
|
||||
Reference in New Issue
Block a user