Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate fbx workflow #487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions Engine/Auto/Scripts/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand Down
123 changes: 55 additions & 68 deletions Engine/Auto/Scripts/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 32 additions & 11 deletions Engine/Source/Editor/UILayers/AssetBrowser.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 <json/json.hpp>

#include <imgui/imgui.h>
Expand Down Expand Up @@ -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<cd::SceneDatabase>();
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);
Expand All @@ -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);
Expand Down
Loading