From af3d9d0eb3acb07dcb078ff23cf08e96ecec1caf Mon Sep 17 00:00:00 2001 From: Menotdan <32620310+Menotdan@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:28:47 -0400 Subject: [PATCH] Re-implement functionality for importing materials as instances. --- Source/Engine/Tools/ModelTool/ModelTool.cpp | 10 +++++++--- Source/Engine/Tools/ModelTool/ModelTool.h | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 13fc753af..dfc249c6a 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -385,6 +385,8 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj SERIALIZE(LODCount); SERIALIZE(TriangleReduction); SERIALIZE(ImportMaterials); + SERIALIZE(ImportMaterialsAsInstances); + SERIALIZE(InstanceToImportAs); SERIALIZE(ImportTextures); SERIALIZE(RestoreMaterialsOnReimport); SERIALIZE(GenerateSDF); @@ -426,6 +428,8 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi DESERIALIZE(LODCount); DESERIALIZE(TriangleReduction); DESERIALIZE(ImportMaterials); + DESERIALIZE(ImportMaterialsAsInstances); + DESERIALIZE(InstanceToImportAs); DESERIALIZE(ImportTextures); DESERIALIZE(RestoreMaterialsOnReimport); DESERIALIZE(GenerateSDF); @@ -977,17 +981,17 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op if (options.ImportMaterialsAsInstances) { AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialInstanceTag, assetPath, material.AssetID); - MaterialInstance* materialInstance = (MaterialInstance*) LoadAsset(assetPath, MaterialInstance::TypeInitializer); + MaterialInstance* materialInstance = (MaterialInstance*)LoadAsset(assetPath, MaterialInstance::TypeInitializer); if (materialInstance->WaitForLoaded()) { LOG(Error, "Failed to load material instance after creation. ({0})", assetPath); return true; } - MaterialBase* materialInstanceOf = (MaterialBase*) LoadAsset(options.InstanceToImportAs, MaterialBase::TypeInitializer); + MaterialBase* materialInstanceOf = options.InstanceToImportAs; if (materialInstanceOf->WaitForLoaded()) { - LOG(Error, "Failed to load material to create an instance of. ({0})", options.InstanceToImportAs); + LOG(Error, "Failed to load material to create an instance of. ({0})", options.InstanceToImportAs->GetID()); return true; } diff --git a/Source/Engine/Tools/ModelTool/ModelTool.h b/Source/Engine/Tools/ModelTool/ModelTool.h index 992a929ca..f6aaefa2b 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.h +++ b/Source/Engine/Tools/ModelTool/ModelTool.h @@ -12,6 +12,7 @@ #include "Engine/Graphics/Models/SkeletonData.h" #include "Engine/Animations/AnimationData.h" #include +#include class JsonWriter; @@ -329,6 +330,12 @@ public: // If checked, the importer will create materials for model meshes as specified in the file. API_FIELD(Attributes="EditorOrder(400), EditorDisplay(\"Materials\"), VisibleIf(nameof(ShowGeometry))") bool ImportMaterials = true; + // If checked, the importer will create the model's materials as instances of a base material. + API_FIELD(Attributes = "EditorOrder(401), EditorDisplay(\"Materials\"), VisibleIf(nameof(ImportMaterials))") + bool ImportMaterialsAsInstances = false; + // The material to import the model's materials as an instance of. + API_FIELD(Attributes = "EditorOrder(402), EditorDisplay(\"Materials\"), VisibleIf(nameof(ImportMaterialsAsInstances))") + AssetReference InstanceToImportAs = (Material*) GPUDevice::Instance->GetDefaultMaterial(); // If checked, the importer will import texture files used by the model and any embedded texture resources. API_FIELD(Attributes="EditorOrder(410), EditorDisplay(\"Materials\"), VisibleIf(nameof(ShowGeometry))") bool ImportTextures = true;