Skip to content

Commit

Permalink
Consolidate output style for all exporters (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duttenheim authored Nov 23, 2023
1 parent 557652b commit 1ada938
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 56 deletions.
10 changes: 5 additions & 5 deletions toolkit/toolkitutil/asset/assetexporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ AssetExporter::ExportFolder(const Util::String& assetPath, const Util::String& c
// save models and physics

String modelPath = String::Sprintf("mdl:%s.n3", modelName.AsCharPtr());
this->logger->Print("%s -> %s\n", Text(URI(assetPath + files[fileIndex]).LocalPath()).Color(TextColor::Blue).AsCharPtr(), Text(modelPath).Color(TextColor::Green).AsCharPtr());
this->logger->Print("%s -> %s\n", Text(URI(assetPath + files[fileIndex]).LocalPath()).Color(TextColor::Blue).AsCharPtr(), Text(URI(modelPath).LocalPath()).Color(TextColor::Green).AsCharPtr());
this->modelBuilder->SaveN3(modelPath, this->platform);

String physicsPath = String::Sprintf("phys:%s.actor", modelName.AsCharPtr());
Expand Down Expand Up @@ -278,7 +278,7 @@ AssetExporter::ExportFolder(const Util::String& assetPath, const Util::String& c
{
console->Clear();
Util::String dstFile = Util::String::Sprintf("%s/%s", dstDir.AsCharPtr(), files[fileIndex].AsCharPtr());
this->logger->Print("%s -> %s\n", Text(URI(assetPath + files[fileIndex]).LocalPath()).Color(TextColor::Blue).AsCharPtr(), Text(dstFile).Color(TextColor::Green).AsCharPtr());
this->logger->Print("%s -> %s\n", Text(URI(assetPath + files[fileIndex]).LocalPath()).Color(TextColor::Blue).AsCharPtr(), Text(URI(dstFile).LocalPath()).Color(TextColor::Green).AsCharPtr());
ioServer->CopyFile(assetPath + files[fileIndex], dstFile);
log.AddEntry(console, "Audio", files[fileIndex]);
}
Expand All @@ -299,16 +299,16 @@ AssetExporter::ExportFolder(const Util::String& assetPath, const Util::String& c
for (auto const& file : files)
{
Util::String dstFile = Util::String::Sprintf("%s/%s", dstDir.AsCharPtr(), file.ExtractFileName().AsCharPtr());
this->logger->Print("%s %s... ", "Exporting physics:", Text(Format("%s", file.AsCharPtr())).Color(TextColor::Blue).AsCharPtr());

if (this->mode & ExportModes::ForcePhysics || NeedsConversion(file, dstFile))
{
Flat::FlatbufferInterface::Compile(file, dstDir, "ACTO");
log.AddEntry(console, "Physics", file);
this->logger->Print("done\n"_text.Color(TextColor::Green).AsCharPtr());
this->logger->Print("%s -> %s\n", Text(Format("%s", file.AsCharPtr())).Color(TextColor::Blue).AsCharPtr(), Text(URI(dstFile).LocalPath()).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr());
}
else
{
this->logger->Print("skipped\n"_text.Color(TextColor::Cyan).AsCharPtr());
this->logger->Print("Skipping %s\n", Text(file).Color(TextColor::Blue).AsCharPtr());
}
}
}
Expand Down
58 changes: 28 additions & 30 deletions toolkit/toolkitutil/model/import/base/modelexporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "modelexporter.h"
#include "io/ioserver.h"
#include "io/filestream.h"
#include "io/uri.h"
#include "timing/timer.h"

#include "model/animutil/animbuildersaver.h"
Expand All @@ -21,6 +22,7 @@

#include "model/scenewriter.h"


#include "toolkit-common/text.h"

using namespace Util;
Expand Down Expand Up @@ -68,25 +70,22 @@ ModelExporter::ExportFile(const IO::URI& file)

this->path = file;
String localPath = file.GetHostAndLocalPath();
if (!this->NeedsConversion(localPath))
{
this->logger->Print("Skipping %s\n", Text(localPath).Color(TextColor::Blue).AsCharPtr());
return;
}
this->file = localPath.ExtractFileName();
this->file.StripFileExtension();
this->category = localPath.ExtractLastDirName();
logger.Print("%s\n", Text(localPath).Color(TextColor::Blue).AsCharPtr());
logger.Indent();
this->logger->Print("%s\n", Text(localPath).Color(TextColor::Blue).AsCharPtr());
this->logger->Indent();

// Get animations from scene
Ptr<ModelAttributes> attributes = ModelDatabase::Instance()->LookupAttributes(this->category + "/" + this->file);
this->exportFlags = attributes->GetExportFlags();
this->sceneScale = attributes->GetScale();

// we want to see if the model file exists, because that's the only way to know if ALL the resources are old or new...
if (!this->NeedsConversion(localPath))
{
logger.Print("File not changed, ignoring...\n\n");
logger.Unindent();
//n_printf(" [File has not changed, ignoring export]\n\n", localPath.AsCharPtr());
return;
}
Timing::Timer timer;
Timing::Timer totalTime;
totalTime.Start();
Expand All @@ -97,7 +96,7 @@ ModelExporter::ExportFile(const IO::URI& file)
if (!this->ParseScene())
return;

this->logger.Print("%s %s (%.2f ms)\n", "Parsing...", Text("done").Color(TextColor::Green).AsCharPtr(), timer.GetTime() * 1000.0f);
this->logger->Print("%s %s (%.2f ms)\n", "Parsing...", Text("done").Color(TextColor::Green).AsCharPtr(), timer.GetTime() * 1000.0f);
//n_printf(" [Parsed source] (%.2f ms)\n", timer.GetTime() * 1000.0f);
timer.Stop();

Expand All @@ -117,12 +116,13 @@ ModelExporter::ExportFile(const IO::URI& file)
Util::Array<MeshBuilder*> mergedMeshes;
this->scene->OptimizeGraphics(mergedMeshNodes, mergedCharacterNodes, mergedGroups, mergedMeshes);

String destinationFiles[] =
Util::String physicsMeshExportName = String::Sprintf("msh:%s/%s_ph.nvx", this->category.AsCharPtr(), this->file.AsCharPtr());
IO::URI destinationFiles[] =
{
String::Sprintf("msh:%s/%s.nvx", this->category.AsCharPtr(), this->file.AsCharPtr()) // mesh
, "" // physics
, String::Sprintf("ani:%s/%s.nax", this->category.AsCharPtr(), this->file.AsCharPtr()) // animation
, String::Sprintf("ske:%s/%s.nsk", this->category.AsCharPtr(), this->file.AsCharPtr())
IO::URI(String::Sprintf("msh:%s/%s.nvx", this->category.AsCharPtr(), this->file.AsCharPtr())) // mesh
, IO::URI(physicsMeshExportName) // physics
, IO::URI(String::Sprintf("ani:%s/%s.nax", this->category.AsCharPtr(), this->file.AsCharPtr())) // animation
, IO::URI(String::Sprintf("ske:%s/%s.nsk", this->category.AsCharPtr(), this->file.AsCharPtr())) // skeleton
};

enum DestinationFile
Expand All @@ -136,7 +136,7 @@ ModelExporter::ExportFile(const IO::URI& file)
// save mesh to file
if (!MeshBuilderSaver::Save(destinationFiles[DestinationFile::Mesh], mergedMeshes, mergedGroups, this->platform))
{
this->logger.Error("Failed to save NVX file : % s\n", destinationFiles[DestinationFile::Mesh].AsCharPtr());
this->logger->Error("Failed to save NVX file : % s\n", destinationFiles[DestinationFile::Mesh].LocalPath().AsCharPtr());
}

// Delete merged meshes after export
Expand All @@ -146,7 +146,7 @@ ModelExporter::ExportFile(const IO::URI& file)
timer.Stop();

// print info
this->logger.Print("%s %s\n", Format("Generated mesh: %s", Text(destinationFiles[DestinationFile::Mesh]).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
this->logger->Print("%s %s\n", Format("Generated mesh: %s", Text(destinationFiles[DestinationFile::Mesh].LocalPath()).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());

// get physics mesh
Util::Array<SceneNode*> physicsNodes;
Expand All @@ -157,8 +157,6 @@ ModelExporter::ExportFile(const IO::URI& file)
// only save physics mesh if it exists
if (physicsMesh && physicsMesh->GetNumTriangles() > 0)
{
destinationFiles[DestinationFile::Physics] = String::Sprintf("msh:%s/%s_ph.nvx", this->category.AsCharPtr(), this->file.AsCharPtr());

timer.Reset();
timer.Start();

Expand All @@ -167,13 +165,13 @@ ModelExporter::ExportFile(const IO::URI& file)
group.SetNumTriangles(physicsMesh->GetNumTriangles());
if (!MeshBuilderSaver::Save(destinationFiles[DestinationFile::Physics], { physicsMesh }, { group }, this->platform))
{
this->logger.Error("Failed to save physics NVX file : % s\n", destinationFiles[DestinationFile::Physics].AsCharPtr());
this->logger->Error("Failed to save physics NVX file : % s\n", destinationFiles[DestinationFile::Physics].LocalPath().AsCharPtr());
}

timer.Stop();

// print info
this->logger.Print("%s %s\n", Format("Generated physics: %s", Text(destinationFiles[DestinationFile::Physics]).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
this->logger->Print("%s %s\n", Format("Generated physics: %s", Text(destinationFiles[DestinationFile::Physics].LocalPath()).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());

}

Expand All @@ -191,11 +189,11 @@ ModelExporter::ExportFile(const IO::URI& file)
// now save actual animation
if (!AnimBuilderSaver::Save(destinationFiles[DestinationFile::Animation], this->scene->animations, this->platform))
{
this->logger.Error("Failed to save animation file: %s\n", destinationFiles[DestinationFile::Animation].AsCharPtr());
this->logger->Error("Failed to save animation file: %s\n", destinationFiles[DestinationFile::Animation].LocalPath().AsCharPtr());
}

timer.Stop();
this->logger.Print("%s %s\n", Format("Generated animation: %s", Text(destinationFiles[DestinationFile::Animation]).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
this->logger->Print("%s %s\n", Format("Generated animation: %s", Text(destinationFiles[DestinationFile::Animation].LocalPath()).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
}

if (this->scene->skeletons.Size() > 0)
Expand All @@ -205,11 +203,11 @@ ModelExporter::ExportFile(const IO::URI& file)

if (!SkeletonBuilderSaver::Save(destinationFiles[DestinationFile::Skeleton], this->scene->skeletons, this->platform))
{
this->logger.Error("Failed to save skeleton file: %s\n", destinationFiles[DestinationFile::Skeleton].AsCharPtr());
this->logger->Error("Failed to save skeleton file: %s\n", destinationFiles[DestinationFile::Skeleton].LocalPath().AsCharPtr());
}

timer.Stop();
this->logger.Print("%s %s\n", Format("Generated skeleton: %s", Text(destinationFiles[DestinationFile::Skeleton]).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
timer.Stop();
this->logger->Print("%s %s\n", Format("Generated skeleton: %s", Text(destinationFiles[DestinationFile::Skeleton].LocalPath()).Color(TextColor::Green).Style(FontMode::Underline).AsCharPtr()).AsCharPtr(), Format("(%.2f ms)", timer.GetTime() * 1000.0f).AsCharPtr());
}

// Finally, output model hierarchy to n3
Expand All @@ -220,13 +218,13 @@ ModelExporter::ExportFile(const IO::URI& file)
, mergedMeshNodes
, physicsNodes
, mergedCharacterNodes
, destinationFiles[DestinationFile::Physics]
, physicsMeshExportName
, this->exportFlags
);

totalTime.Stop();
this->logger.Unindent();
this->logger.Print("%s %s\n\n", "Done"_text.Color(TextColor::Green).Style(FontMode::Bold).AsCharPtr(), Format("(%.2f ms)", totalTime.GetTime() * 1000).AsCharPtr());
this->logger->Unindent();
this->logger->Print("%s %s\n\n", "Done"_text.Color(TextColor::Green).Style(FontMode::Bold).AsCharPtr(), Format("(%.2f ms)", totalTime.GetTime() * 1000).AsCharPtr());

delete this->scene;
this->scene = nullptr;
Expand Down
13 changes: 12 additions & 1 deletion toolkit/toolkitutil/model/import/base/modelexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ModelExporter : public Base::ExporterBase
/// Run implementation scene parse
virtual bool ParseScene();

/// Set logger
void SetLogger(ToolkitUtil::Logger* logger);
/// exports a single file
void ExportFile(const IO::URI& file);
/// set texture converter
Expand All @@ -49,7 +51,7 @@ class ModelExporter : public Base::ExporterBase
Scene* scene;
TextureConverter* texConverter;

ToolkitUtil::Logger logger;
ToolkitUtil::Logger* logger;
};

//------------------------------------------------------------------------------
Expand All @@ -70,4 +72,13 @@ ModelExporter::SetTextureConverter(TextureConverter* texConv)
this->texConverter = texConv;
}

//------------------------------------------------------------------------------
/**
*/
inline void
ModelExporter::SetLogger(ToolkitUtil::Logger* logger)
{
this->logger = logger;
}

} // namespace ToolkitUtil
6 changes: 3 additions & 3 deletions toolkit/toolkitutil/model/import/fbx/nfbxexporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ NFbxExporter::ParseScene()
importStatus = importer->Import(scene);
if (!importStatus)
{
n_error(" [Could not open %s for reading! Something went terribly wrong!]\n\n", this->file.AsCharPtr());
this->logger->Error("FBX - Failed to open\n");
this->SetHasErrors(true);
return false;
}
}
else
{
n_error(" [Could not initialize %s! Something went terribly wrong!]\n\n", this->file.AsCharPtr());
this->logger->Error("FBX - Failed to initialize\n");
this->SetHasErrors(true);
return false;
}
Expand All @@ -85,7 +85,7 @@ NFbxExporter::ParseScene()
auto fbxScene = new NFbxScene();
fbxScene->SetName(this->file);
fbxScene->SetCategory(this->category);
fbxScene->Setup(scene, this->exportFlags, attributes, this->sceneScale);
fbxScene->Setup(scene, this->exportFlags, attributes, this->sceneScale, this->logger);
this->scene = fbxScene;

scene->Destroy(true);
Expand Down
14 changes: 5 additions & 9 deletions toolkit/toolkitutil/model/import/fbx/node/nfbxscene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,27 @@ NFbxScene::Setup(
, const ExportFlags& exportFlags
, const Ptr<ModelAttributes>& attributes
, float scale
, ToolkitUtil::Logger* logger
)
{
n_assert(scene);

// set export settings
this->flags = exportFlags;
this->logger = logger;

// set scale
SceneScale = scale;
AdjustedScale = SceneScale;

Timing::Timer timer;

float fps = TimeModeToFPS(scene->GetGlobalSettings().GetTimeMode());

auto axisSystem = scene->GetGlobalSettings().GetAxisSystem();
FbxAxisSystem newSystem(FbxAxisSystem::eOpenGL);
if (axisSystem != newSystem)
{
timer.Start();
newSystem.DeepConvertScene(scene);
timer.Stop();
n_printf(" [FBX - Converting coordinate system (%.2f ms)]\n", timer.GetTime() * 1000);
this->logger->Print("FBX - Converting coordinate system\n");

}

Expand All @@ -134,15 +132,13 @@ NFbxScene::Setup(
AnimationFrameRate = fps;

// split meshes based on material
timer.Reset();
timer.Start();
FbxGeometryConverter* converter = new FbxGeometryConverter(sdkManager);
bool triangulated = converter->Triangulate(scene, true);
converter->RemoveBadPolygonsFromMeshes(scene);
n_assert(triangulated);
delete converter;
timer.Stop();
n_printf(" [FBX - Triangulation done (%.2f ms)]\n", timer.GetTime() * 1000);

this->logger->Print("FBX - Triangulating\n");


// Okay so we want to do this, we really do, but if we do,
Expand Down
4 changes: 4 additions & 0 deletions toolkit/toolkitutil/model/import/fbx/node/nfbxscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "model/import/base/scene.h"
#include "model/meshutil/meshbuilder.h"
#include "toolkit-common/base/exporttypes.h"
#include "toolkit-common/logger.h"

#include <fbxsdk/core/base/fbxtime.h>

Expand All @@ -37,6 +38,7 @@ class NFbxScene : public Scene
, const ToolkitUtil::ExportFlags& exportFlags
, const Ptr<ModelAttributes>& attributes
, float scale
, ToolkitUtil::Logger* logger
);

private:
Expand All @@ -50,6 +52,8 @@ class NFbxScene : public Scene
);
/// converts FBX time mode to FPS
float TimeModeToFPS(const fbxsdk::FbxTime::EMode& timeMode);

ToolkitUtil::Logger* logger;
};

} // namespace ToolkitUtil
Expand Down
12 changes: 6 additions & 6 deletions toolkit/toolkitutil/model/import/gltf/ngltfexporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ NglTFExporter::ParseScene()

if (!res)
{
this->logger.Warning("Failed to import '%s'\n\n", this->file.AsCharPtr());
this->logger->Warning("Failed to import '%s'\n\n", this->file.AsCharPtr());
return false;
}

auto scene = new NglTFScene();
scene->SetName(this->file);
scene->SetCategory(this->category);
scene->Setup(&this->gltfScene, this->exportFlags, this->sceneScale);
this->texConverter->SetLogger(&this->logger);
this->texConverter->SetLogger(this->logger);
this->scene = scene;

String fileExtension = this->path.LocalPath().GetFileExtension();
{
// Extract materials into .sur files
// Always do this before exporting textures, since the texture names may be changed in the extractor.
NglTFMaterialExtractor extractor;
extractor.SetLogger(&this->logger);
extractor.SetLogger(this->logger);
extractor.SetCategoryName(this->category);
extractor.SetDocument(&this->gltfScene);
extractor.SetExportSubDirectory(this->file);
Expand Down Expand Up @@ -165,7 +165,7 @@ NglTFExporter::ParseScene()
{
// delete all previously generated images
if (!IO::IoServer::Instance()->DeleteDirectory(embeddedPath))
this->logger.Warning("glTF - Could not delete old directory for embedded gltf images\n");
this->logger->Warning("glTF - Could not delete old directory for embedded gltf images\n");
}

if (hasEmbedded)
Expand Down Expand Up @@ -204,7 +204,7 @@ NglTFExporter::ParseScene()
imageJob.category = &this->category;
imageJob.converter = this->texConverter;
imageJob.baseDir = &this->file;
imageJob.logger = &this->logger;
imageJob.logger = this->logger;
imageJob.intermediateDir = &intermediateDir;

auto job = [](SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void* ctx)
Expand Down Expand Up @@ -266,7 +266,7 @@ NglTFExporter::ParseScene()
if (IO::IoServer::Instance()->DirectoryExists(tmpDir))
{
if (!IO::IoServer::Instance()->DeleteDirectory(tmpDir))
this->logger.Warning("glTF - Could not delete temporary texconverter directory\n");
this->logger->Warning("glTF - Could not delete temporary texconverter directory\n");
}

// Reset scratch memory
Expand Down
Loading

0 comments on commit 1ada938

Please sign in to comment.