From dfc0ca05715e6d8524edc5d3cac7f195b1a34a76 Mon Sep 17 00:00:00 2001 From: T-rvw <429601557@qq.com> Date: Mon, 4 Mar 2024 13:11:34 +0800 Subject: [PATCH] integrate fbx workflow --- Engine/Auto/Scripts/editor.lua | 25 ++-- Engine/Auto/Scripts/premake5.lua | 123 ++++++++---------- .../Source/Editor/UILayers/AssetBrowser.cpp | 43 ++++-- 3 files changed, 104 insertions(+), 87 deletions(-) diff --git a/Engine/Auto/Scripts/editor.lua b/Engine/Auto/Scripts/editor.lua index 2b4b8486..74568e8e 100644 --- a/Engine/Auto/Scripts/editor.lua +++ b/Engine/Auto/Scripts/editor.lua @@ -112,18 +112,15 @@ project("Editor") staticruntime "on" filter { "configurations:Debug" } runtime "Debug" -- /MTd - libdirs { - BinariesPath, - path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug"), - } filter { "configurations:Release" } runtime "Release" -- /MT - libdirs { - BinariesPath, - path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release"), - } filter {} + libdirs { + BinariesPath, + path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}"), + } + links { "Engine", "AssetPipelineCore", @@ -141,6 +138,18 @@ project("Editor") } end + if ENABLE_FBX_WORKFLOW then + links { + "FbxConsumer", + "FbxProducer", + } + + defines { + "ENABLE_FBX_CONSUMER", + "ENABLE_FBX_PRODUCER", + } + end + -- Disable these options can reduce the size of compiled binaries. justmycode("Off") editAndContinue("Off") diff --git a/Engine/Auto/Scripts/premake5.lua b/Engine/Auto/Scripts/premake5.lua index d74e1c53..b4fad34c 100644 --- a/Engine/Auto/Scripts/premake5.lua +++ b/Engine/Auto/Scripts/premake5.lua @@ -25,24 +25,6 @@ function IsIOSPlatform() return ChoosePlatform == "IOS" end -USE_CLANG_TOOLSET = false -if os.getenv("USE_CLANG_TOOLSET") then - USE_CLANG_TOOLSET = true -end - -DDGI_SDK_PATH = os.getenv("DDGI_SDK_PATH") or "" -if not os.isdir(DDGI_SDK_PATH) then - DDGI_SDK_PATH = "" -end - -ENABLE_FREETYPE = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() -ENABLE_SPDLOG = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() -ENABLE_SUBPROCESS = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() -ENABLE_TRACY = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() -ENABLE_DDGI = DDGI_SDK_PATH ~= "" - -ShouldTreatWaringAsError = not (ENABLE_DDGI or USE_CLANG_TOOLSET) - PlatformSettings = {} PlatformSettings["Windows"] = { DisplayName = "Win64", @@ -77,6 +59,33 @@ function GetPlatformMacroName() return PlatformSettings[ChoosePlatform].MacroName end +dofile("path.lua") + +-------------------------------------------------------------------------------------------------------- +-- Build Options +-------------------------------------------------------------------------------------------------------- +USE_CLANG_TOOLSET = false +if os.getenv("USE_CLANG_TOOLSET") then + USE_CLANG_TOOLSET = true +end + +DDGI_SDK_PATH = os.getenv("DDGI_SDK_PATH") or "" +if not os.isdir(DDGI_SDK_PATH) then + DDGI_SDK_PATH = "" +end + +FBX_SDK_DEBUG_PATH = path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/libfbxsdk.dll") +FBX_SDK_RELEASE_PATH = path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/libfbxsdk.dll") + +ENABLE_DDGI = DDGI_SDK_PATH ~= "" +ENABLE_FBX_WORKFLOW = os.isfile(FBX_SDK_DEBUG_PATH) and os.isfile(FBX_SDK_RELEASE_PATH) +ENABLE_FREETYPE = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() +ENABLE_SPDLOG = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() +ENABLE_SUBPROCESS = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() +ENABLE_TRACY = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform() + +ShouldTreatWaringAsError = not (ENABLE_DDGI or USE_CLANG_TOOLSET) + IDEConfigs = {} IDEConfigs.BuildIDEName = os.getenv("BUILD_IDE_NAME") @@ -92,8 +101,7 @@ function SetLanguageAndToolset(projectName) targetdir(BinariesPath) end --- Parse folder path -dofile("path.lua") +-- Information about make print("================================================================") print("EngineBuildLibKind = "..EngineBuildLibKind) print("CurrentWorkingDirectory = "..CurrentWorkingDirectory) @@ -105,7 +113,12 @@ print("EngineSourcePath = "..EngineSourcePath) print("GameSourcePath = "..GameSourcePath) print("RuntimeSourcePath = "..RuntimeSourcePath) print("IDEConfigs.BuildIDEName = "..IDEConfigs.BuildIDEName) -print("DDGI_SDK_PATH = "..DDGI_SDK_PATH) +print("================================================================") +print("ENABLE_FBX_WORKFLOW = "..tostring(ENABLE_FBX_WORKFLOW)) +print("ENABLE_FREETYPE = "..tostring(ENABLE_FREETYPE)) +print("ENABLE_SPDLOG = "..tostring(ENABLE_SPDLOG)) +print("ENABLE_SUBPROCESS = "..tostring(ENABLE_SUBPROCESS)) +print("ENABLE_TRACY = "..tostring(ENABLE_TRACY)) print("================================================================") -- workspace means solution in Visual Studio @@ -156,53 +169,27 @@ function CopyDllAutomatically() end -- copy dll into binary folder automatically. - filter { "configurations:Debug" } - if IsAndroidPlatform() then - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Debug/SDL2d.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/AssetPipelineCore.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/CDProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/CDConsumer.*").."\" \""..BinariesPath.."\"", - } - else - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Debug/SDL2d.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/AssetPipelineCore.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/CDProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/CDConsumer.*").."\" \""..BinariesPath.."\"", - } - end - - if not USE_CLANG_TOOLSET then - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/GenericProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/assimp-*-mtd.*").."\" \""..BinariesPath.."\"", - } - end - filter { "configurations:Release" } - if IsAndroidPlatform() then - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Release/SDL2.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/AssetPipelineCore.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/CDProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/CDConsumer.*").."\" \""..BinariesPath.."\"", - } - else - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Release/SDL2.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/AssetPipelineCore.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/CDProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/CDConsumer.*").."\" \""..BinariesPath.."\"", - } - end - - if not USE_CLANG_TOOLSET then - postbuildcommands { - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/GenericProducer.*").."\" \""..BinariesPath.."\"", - "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/assimp-*-mt.*").."\" \""..BinariesPath.."\"", - } - end - filter {} + postbuildcommands { + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Debug/SDL2*.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/AssetPipelineCore.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/CDProducer.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/CDConsumer.*").."\" \""..BinariesPath.."\"", + } + + if not USE_CLANG_TOOLSET then + postbuildcommands { + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/GenericProducer.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/assimp-*-mtd.*").."\" \""..BinariesPath.."\"", + } + end + + if ENABLE_FBX_WORKFLOW then + postbuildcommands { + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/FbxConsumer.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/FbxProducer.*").."\" \""..BinariesPath.."\"", + "{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/libfbxsdk.*").."\" \""..BinariesPath.."\"", + } + end if ENABLE_DDGI then postbuildcommands { diff --git a/Engine/Source/Editor/UILayers/AssetBrowser.cpp b/Engine/Source/Editor/UILayers/AssetBrowser.cpp index 908d0ac4..530ab789 100644 --- a/Engine/Source/Editor/UILayers/AssetBrowser.cpp +++ b/Engine/Source/Editor/UILayers/AssetBrowser.cpp @@ -1,6 +1,9 @@ #include "AssetBrowser.h" #include "Consumers/CDConsumer/CDConsumer.h" +#ifdef ENABLE_FBX_CONSUMER +#include "Consumers/FbxConsumer/FbxConsumer.h" +#endif #include "ECWorld/ECWorldConsumer.h" #include "ECWorld/MaterialComponent.h" #include "ECWorld/SceneWorld.h" @@ -13,15 +16,17 @@ #include "Log/Log.h" #include "Material/MaterialType.h" #include "Producers/CDProducer/CDProducer.h" +#ifdef ENABLE_FBX_PRODUCER +#include "Producers/FbxProducer/FbxProducer.h" +#endif +#ifdef ENABLE_GENERIC_PRODUCER +#include "Producers/GenericProducer/GenericProducer.h" +#endif #include "Rendering/WorldRenderer.h" #include "Rendering/RenderContext.h" #include "Resources/ResourceBuilder.h" #include "Resources/ResourceLoader.h" -#ifdef ENABLE_GENERIC_PRODUCER -#include "Producers/GenericProducer/GenericProducer.h" -#endif - #include #include @@ -909,15 +914,28 @@ void AssetBrowser::ImportModelFile(const char* pFilePath) // Step 1 : Convert model file to cd::SceneDatabase std::filesystem::path inputFilePath(pFilePath); std::filesystem::path inputFileExtension = inputFilePath.extension(); + bool importedModel = false; + auto newSceneDatabase = std::make_unique(); if (0 == inputFileExtension.compare(".cdbin")) { cdtools::CDProducer cdProducer(pFilePath); - cd::SceneDatabase newSceneDatabase; - cdtools::Processor processor(&cdProducer, nullptr, &newSceneDatabase); + cdtools::Processor processor(&cdProducer, nullptr, newSceneDatabase.get()); processor.Run(); - pSceneDatabase->Merge(cd::MoveTemp(newSceneDatabase)); + importedModel = true; } - else + else if (0 == inputFileExtension.compare(".fbx")) + { +#ifdef ENABLE_FBX_PRODUCER + cdtools::FbxProducer fbxProducer(pFilePath); + fbxProducer.EnableOption(cdtools::FbxProducerOptions::Triangulate); + cdtools::Processor processor(&fbxProducer, nullptr, newSceneDatabase.get()); + processor.Run(); + importedModel = true; +#endif + } + + // Try generic producer only if specialized import workflow is not ready. + if (!importedModel) { #ifdef ENABLE_GENERIC_PRODUCER cdtools::GenericProducer genericProducer(pFilePath); @@ -930,16 +948,19 @@ void AssetBrowser::ImportModelFile(const char* pFilePath) genericProducer.EnableOption(cdtools::GenericProducerOptions::FlattenTransformHierarchy); } - cd::SceneDatabase newSceneDatabase; - cdtools::Processor processor(&genericProducer, nullptr, &newSceneDatabase); + cdtools::Processor processor(&genericProducer, nullptr, newSceneDatabase.get()); processor.EnableOption(cdtools::ProcessorOptions::Dump); processor.Run(); - pSceneDatabase->Merge(cd::MoveTemp(newSceneDatabase)); #else assert("Unable to import this file format."); + return; #endif } + // Move contents in temp scene database to SceneWorld. + pSceneDatabase->Merge(cd::MoveTemp(*newSceneDatabase)); + newSceneDatabase.reset(); + // Step 2 : Process generated cd::SceneDatabase ProcessSceneDatabase(pSceneDatabase, m_importOptions.ImportMesh, m_importOptions.ImportMaterial, m_importOptions.ImportTexture, m_importOptions.ImportCamera, m_importOptions.ImportLight);