11// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
22
33#include " Import_Factory.h"
4- #include " AssetRegistryModule.h"
5- #include " Editor/UnrealEd/Public/Editor.h"
6- #include " Misc/FeedbackContext.h"
7- #include " Logging/LogMacros.h"
8- #include " Logging/TokenizedMessage.h"
9- #include " MessageLogModule.h"
10- #include " Serialization/JsonTypes.h"
11- #include " Dom/JsonObject.h"
12- #include " Serialization/JsonReader.h"
13- #include " Serialization/JsonSerializer.h"
14- #include " Misc/FileHelper.h"
15- #include " ContentBrowserModule.h"
16- #include " Factories/MaterialFactoryNew.h"
17- #include " Materials/MaterialExpressionTextureSample.h"
18- #include " Materials/Material.h"
19- #include " Materials/MaterialExpressionConstant.h"
4+ #include " Import_Processer.h"
205
216#define LOCTEXT_NAMESPACE " FBlender_ImporterModule"
227
238UImport_Factory::UImport_Factory (const FObjectInitializer& ObjectInitializer)
249 : Super(ObjectInitializer)
2510{
2611
27- bCreateNew = true ;
12+ bCreateNew = false ;
2813 bEditorImport = true ;
2914 bEditAfterNew = false ;
3015 bText = true ;
@@ -42,117 +27,26 @@ bool UImport_Factory::FactoryCanImport(const FString& Filename)
4227
4328 if (JSON_Filename == TEXT (" blender_addon_ue_data.json" ))
4429 {
45-
46- FString JsonString;
47- FFileHelper::LoadFileToString (JsonString, *Filename);
48- TSharedPtr<FJsonObject> JsonObject = MakeShareable (new FJsonObject ());
49- TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create (JsonString);
50-
51- if (FJsonSerializer::Deserialize (JsonReader, JsonObject) && JsonObject.IsValid ())
52- {
53- const FString data_path = JsonObject->GetStringField (TEXT (" path" ));
54-
55- TArray<TSharedPtr<FJsonValue>> objArray = JsonObject->GetArrayField (TEXT (" materials" ));
56- for (int32 i = 0 ; i < objArray.Num (); i++)
57- {
58- TSharedPtr<FJsonValue> value = objArray[i];
59- TSharedPtr<FJsonObject> json = value->AsObject ();
60-
61- const FString data_name = json->GetStringField (TEXT (" name" ));
62- const FString data_base_color = json->GetStringField (TEXT (" base_color" ));
63- const FString data_orm = json->GetStringField (TEXT (" orm" ));
64- const FString data_normal = json->GetStringField (TEXT (" normal" ));
65-
66- FString PackageName = TEXT (" /Game/" ) + data_path + data_name;
67-
68- UPackage* Package = CreatePackage (NULL , *PackageName);
69-
70- auto MaterialFactory = NewObject<UMaterialFactoryNew>();
71- UMaterial* UnrealMaterial = (UMaterial*)MaterialFactory->FactoryCreateNew (UMaterial::StaticClass (), Package, *data_name, RF_Standalone | RF_Public, NULL , GWarn);
72- FAssetRegistryModule::AssetCreated (UnrealMaterial);
73- Package->FullyLoad ();
74- Package->SetDirtyFlag (true );
75-
76- // Base Color
77-
78- if (data_base_color != " " ) {
79-
80- FStringAssetReference AssetPath_Basecolor (TEXT (" /Game/" ) + data_path + data_base_color);
81- UTexture* Texture_Basecolor = Cast<UTexture>(AssetPath_Basecolor.TryLoad ());
82- if (Texture_Basecolor)
83- {
84- UMaterialExpressionTextureSample* TextureExpression = NewObject<UMaterialExpressionTextureSample>(UnrealMaterial);
85- TextureExpression->Texture = Texture_Basecolor;
86- TextureExpression->SamplerType = SAMPLERTYPE_Color;
87- UnrealMaterial->Expressions .Add (TextureExpression);
88- UnrealMaterial->BaseColor .Expression = TextureExpression;
89- }
90-
91- }
92-
93- // ORM
94-
95- if (data_orm != " " ) {
96-
97- FStringAssetReference AssetPath_ORM (TEXT (" /Game/" ) + data_path + data_orm);
98- UTexture* Texture_ORM = Cast<UTexture>(AssetPath_ORM.TryLoad ());
99- if (Texture_ORM)
100- {
101- UMaterialExpressionTextureSample* TextureExpression = NewObject<UMaterialExpressionTextureSample>(UnrealMaterial);
102- TextureExpression->Texture = Texture_ORM;
103- TextureExpression->SamplerType = SAMPLERTYPE_Color;
104- UnrealMaterial->Expressions .Add (TextureExpression);
105-
106- UnrealMaterial->AmbientOcclusion .Connect (1 , TextureExpression);
107- UnrealMaterial->Roughness .Connect (2 , TextureExpression);
108- UnrealMaterial->Metallic .Connect (3 , TextureExpression);
109-
110- }
111-
112- }
113-
114- // Normal
115-
116- if (data_normal != " " ) {
117-
118- FStringAssetReference AssetPath_Normal (TEXT (" /Game/" ) + data_path + data_normal);
119- UTexture* Texture_Normal = Cast<UTexture>(AssetPath_Normal.TryLoad ());
120- if (Texture_Normal)
121- {
122- UMaterialExpressionTextureSample* TextureExpression = NewObject<UMaterialExpressionTextureSample>(UnrealMaterial);
123- TextureExpression->Texture = Texture_Normal;
124- TextureExpression->SamplerType = SAMPLERTYPE_Normal;
125- UnrealMaterial->Expressions .Add (TextureExpression);
126- UnrealMaterial->Normal .Expression = TextureExpression;
127- }
128-
129- }
130-
131- }
132-
133- } else {
134-
135- FText DialogText = FText::Format (
136- LOCTEXT (" Error deserializing/processing " , " [{0}]" ),
137- FText::FromString (Filename)
138- );
139- FMessageDialog::Open (EAppMsgType::Ok, DialogText);
140-
141- }
14230
14331 return true ;
14432
145- } else {
146-
147- return false ;
148-
14933 }
15034
35+ return false ;
36+
15137}
15238
15339UObject* UImport_Factory::FactoryCreateFile (UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, const FString& Filename, const TCHAR* Parms, FFeedbackContext* Warn, bool & bOutOperationCanceled)
15440{
41+
42+ UObject* ImportedObject = nullptr ;
43+
44+ bool processed = FImport_Processer::Process_JSON_Data (Filename);
45+
46+ remove (TCHAR_TO_ANSI (*Filename));
47+
15548 return nullptr ;
49+
15650}
15751
15852#undef LOCTEXT_NAMESPACE
0 commit comments