Skip to content

Commit 9263e4e

Browse files
committed
0_2_0
1 parent 52ec9cc commit 9263e4e

12 files changed

Lines changed: 236 additions & 128 deletions

File tree

Binary file not shown.
Binary file not shown.

Blender_Importer/Blender_Importer.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "0.1",
4+
"VersionName": "0.2.0",
55
"FriendlyName": "Blender Importer",
66
"Description": "Blender Addon UE Importer",
77
"Category": "Importers",

Blender_Importer/Intermediate/Build/Win64/UE4Editor/Inc/Blender_Importer/Blender_Importer.init.gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void EmptyLinkFunctionForGeneratedCodeBlender_Importer_init() {}
2121
nullptr,
2222
0,
2323
PKG_CompiledIn | 0x00000040,
24-
0x3D50620E,
24+
0x9A7AEB84,
2525
0x374559E1,
2626
METADATA_PARAMS(nullptr, 0)
2727
};

Blender_Importer/Intermediate/Build/Win64/UE4Editor/Inc/Blender_Importer/Import_Factory.gen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void EmptyLinkFunctionForGeneratedCodeImport_Factory() {}
4040
};
4141
#if WITH_METADATA
4242
const UE4CodeGen_Private::FMetaDataPairParam Z_Construct_UClass_UImport_Factory_Statics::Class_MetaDataParams[] = {
43-
{ "HideCategories", "Object" },
4443
{ "IncludePath", "Import_Factory.h" },
4544
{ "ModuleRelativePath", "Public/Import_Factory.h" },
4645
};
@@ -60,7 +59,7 @@ void EmptyLinkFunctionForGeneratedCodeImport_Factory() {}
6059
0,
6160
0,
6261
0,
63-
0x000000A0u,
62+
0x000000A8u,
6463
METADATA_PARAMS(Z_Construct_UClass_UImport_Factory_Statics::Class_MetaDataParams, ARRAY_COUNT(Z_Construct_UClass_UImport_Factory_Statics::Class_MetaDataParams))
6564
};
6665
UClass* Z_Construct_UClass_UImport_Factory()
@@ -72,7 +71,7 @@ void EmptyLinkFunctionForGeneratedCodeImport_Factory() {}
7271
}
7372
return OuterClass;
7473
}
75-
IMPLEMENT_CLASS(UImport_Factory, 3054864883);
74+
IMPLEMENT_CLASS(UImport_Factory, 1763245714);
7675
template<> BLENDER_IMPORTER_API UClass* StaticClass<UImport_Factory>()
7776
{
7877
return UImport_Factory::StaticClass();

Blender_Importer/Intermediate/Build/Win64/UE4Editor/Inc/Blender_Importer/Import_Factory.generated.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private: \
2020
static void StaticRegisterNativesUImport_Factory(); \
2121
friend struct Z_Construct_UClass_UImport_Factory_Statics; \
2222
public: \
23-
DECLARE_CLASS(UImport_Factory, UFactory, COMPILED_IN_FLAGS(0), CASTCLASS_None, TEXT("/Script/Blender_Importer"), NO_API) \
23+
DECLARE_CLASS(UImport_Factory, UFactory, COMPILED_IN_FLAGS(0 | CLASS_Transient), CASTCLASS_None, TEXT("/Script/Blender_Importer"), NO_API) \
2424
DECLARE_SERIALIZER(UImport_Factory)
2525

2626

@@ -29,7 +29,7 @@ private: \
2929
static void StaticRegisterNativesUImport_Factory(); \
3030
friend struct Z_Construct_UClass_UImport_Factory_Statics; \
3131
public: \
32-
DECLARE_CLASS(UImport_Factory, UFactory, COMPILED_IN_FLAGS(0), CASTCLASS_None, TEXT("/Script/Blender_Importer"), NO_API) \
32+
DECLARE_CLASS(UImport_Factory, UFactory, COMPILED_IN_FLAGS(0 | CLASS_Transient), CASTCLASS_None, TEXT("/Script/Blender_Importer"), NO_API) \
3333
DECLARE_SERIALIZER(UImport_Factory)
3434

3535

Lines changed: 12 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
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

238
UImport_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

15339
UObject* 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

Comments
 (0)