Skip to content

Commit

Permalink
Integrate fbx producer/consumer
Browse files Browse the repository at this point in the history
Integrate fbx producer/consumer
  • Loading branch information
T-rvw authored Mar 22, 2024
2 parents c01ef2d + a19e317 commit 18b8ac0
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 95 deletions.
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/%{cfg.buildcfg}/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-*-mt*.*").."\" \""..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
11 changes: 8 additions & 3 deletions Engine/Source/Editor/ECWorld/ECWorldConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,20 @@ void ECWorldConsumer::AddAnimation(engine::Entity entity, const cd::Animation& a

void ECWorldConsumer::AddMaterial(engine::Entity entity, const cd::Material* pMaterial, engine::MaterialType* pMaterialType, const cd::SceneDatabase* pSceneDatabase)
{
std::set<uint8_t> compiledTextureSlot;
std::vector<std::tuple<cd::MaterialTextureType, std::string, const cd::Texture*>> outputTypeToData;

engine::MaterialComponent& materialComponent = m_pSceneWorld->GetWorld()->CreateComponent<engine::MaterialComponent>(entity);
materialComponent.Init();
materialComponent.SetMaterialType(pMaterialType);
materialComponent.SetMaterialData(pMaterial);
materialComponent.ActivateShaderFeature(engine::GetSkyTypeShaderFeature(m_pSceneWorld->GetSkyComponent(m_pSceneWorld->GetSkyEntity())->GetSkyType()));

if (!pMaterial)
{
return;
}

std::set<uint8_t> compiledTextureSlot;
std::vector<std::tuple<cd::MaterialTextureType, std::string, const cd::Texture*>> outputTypeToData;

// Expected textures are ready to build. Add more optional texture data.
for (cd::MaterialTextureType optionalTextureType : pMaterialType->GetOptionalTextureTypes())
{
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 @@ -14,15 +17,17 @@
#include "Material/MaterialType.h"
#include "Producers/CDProducer/CDProducer.h"
#include "Producers/EffekseerProducer/EffekseerProducer.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 @@ -942,15 +947,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 @@ -963,16 +981,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
10 changes: 6 additions & 4 deletions Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
if (ImGui::MenuItem("Add Cube Mesh"))
{
engine::Entity entity = AddNamedEntity("CubeMesh");
// TODO : manage temp asset.
static std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Box(cd::Point(-10.0f), cd::Point(10.0f)), pPBRMaterialType->GetRequiredVertexFormat());
std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Box(cd::Point(-10.0f), cd::Point(10.0f)), pPBRMaterialType->GetRequiredVertexFormat());
assert(optMesh.has_value());
optMesh->SetName(pSceneWorld->GetNameComponent(entity)->GetName());
CreateShapeComponents(entity, cd::MoveTemp(optMesh.value()), pPBRMaterialType);
}

Expand All @@ -110,15 +110,16 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
engine::Entity entity = AddNamedEntity("Celluloid Cube");
std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Box(cd::Point(-10.0f), cd::Point(10.0f)), pCelluloidMaterialType->GetRequiredVertexFormat());
assert(optMesh.has_value());
optMesh->SetName(pSceneWorld->GetNameComponent(entity)->GetName());
CreateShapeComponents(entity, cd::MoveTemp(optMesh.value()), pCelluloidMaterialType);
}

else if (ImGui::MenuItem("Add Sphere Mesh"))
{
engine::Entity entity = AddNamedEntity("Sphere");
// TODO : manage temp asset.
static std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Sphere(cd::Point(0.0f), 10.0f), 100U, 100U, pPBRMaterialType->GetRequiredVertexFormat());
std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Sphere(cd::Point(0.0f), 10.0f), 100U, 100U, pPBRMaterialType->GetRequiredVertexFormat());
assert(optMesh.has_value());
optMesh->SetName(pSceneWorld->GetNameComponent(entity)->GetName());
CreateShapeComponents(entity, cd::MoveTemp(optMesh.value()), pPBRMaterialType);
}

Expand All @@ -127,6 +128,7 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
engine::Entity entity = AddNamedEntity("Celluloid Sphere");
std::optional<cd::Mesh> optMesh = cd::MeshGenerator::Generate(cd::Sphere(cd::Point(0.0f), 10.0f), 100U, 100U, pCelluloidMaterialType->GetRequiredVertexFormat());
assert(optMesh.has_value());
optMesh->SetName(pSceneWorld->GetNameComponent(entity)->GetName());
CreateShapeComponents(entity, cd::MoveTemp(optMesh.value()), pCelluloidMaterialType);
}
else if (ImGui::MenuItem("Add Terrain Mesh"))
Expand Down

0 comments on commit 18b8ac0

Please sign in to comment.