Skip to content

Commit

Permalink
Added new model conversion options
Browse files Browse the repository at this point in the history
  • Loading branch information
kraifpatrik committed Nov 17, 2020
1 parent aa71037 commit 639faad
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 76 deletions.
9 changes: 9 additions & 0 deletions BBMOD.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cpp/include/BBMOD/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ struct SConfig
/** Flip normal vectors. */
bool FlipNormals = false;

/** Removes redundant/unreferenced materials. */
bool OptimizeMaterials = true;

/** Optimizes node hierarchy by joining multiple nodes into one. */
bool OptimizeNodes = true;

/** Reduces number of meshes. */
bool OptimizeMeshes = true;

/**
* Configures generation of normal vectors.
*
Expand Down
25 changes: 21 additions & 4 deletions cpp/src/BBMOD/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ int ConvertToBBMOD(const char* fin, const char* fout, const SConfig& config)
//importer->SetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, false);

int flags = (0
// aiProcessPreset_TargetRealtime_Quality
//aiProcessPreset_TargetRealtime_Quality
| aiProcess_CalcTangentSpace
//| aiProcess_GenSmoothNormals
| aiProcess_JoinIdenticalVertices
| aiProcess_ImproveCacheLocality
| aiProcess_LimitBoneWeights
| aiProcess_RemoveRedundantMaterials
//| aiProcess_RemoveRedundantMaterials
| aiProcess_SplitLargeMeshes
| aiProcess_Triangulate
| aiProcess_GenUVCoords
Expand All @@ -86,8 +87,9 @@ int ConvertToBBMOD(const char* fin, const char* fout, const SConfig& config)
| aiProcess_FindInvalidData
//
| aiProcess_TransformUVCoords
| aiProcess_OptimizeGraph
| aiProcess_OptimizeMeshes);
//| aiProcess_OptimizeGraph
//| aiProcess_OptimizeMeshes
);

if (config.GenNormals == BBMOD_NORMALS_FLAT)
{
Expand All @@ -98,6 +100,21 @@ int ConvertToBBMOD(const char* fin, const char* fout, const SConfig& config)
flags |= aiProcess_GenSmoothNormals;
}

if (config.OptimizeMaterials)
{
flags |= aiProcess_RemoveRedundantMaterials;
}

if (config.OptimizeNodes)
{
flags |= aiProcess_OptimizeGraph;
}

if (config.OptimizeMeshes)
{
flags |= aiProcess_OptimizeMeshes;
}

if (config.LeftHanded)
{
flags |= aiProcess_ConvertToLeftHanded;
Expand Down
33 changes: 33 additions & 0 deletions cpp/src/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,39 @@ GM_EXPORT gmreal_t bbmod_dll_set_disable_bone(gmreal_t disable)
return BBMOD_SUCCESS;
}

GM_EXPORT gmreal_t bbmod_dll_get_optimize_materials()
{
return (gmreal_t)gConfig.OptimizeMaterials;
}

GM_EXPORT gmreal_t bbmod_dll_set_optimize_materials(gmreal_t optimize)
{
gConfig.OptimizeMaterials = (bool)optimize;
return BBMOD_SUCCESS;
}

GM_EXPORT gmreal_t bbmod_dll_get_optimize_meshes()
{
return (gmreal_t)gConfig.OptimizeMeshes;
}

GM_EXPORT gmreal_t bbmod_dll_set_optimize_meshes(gmreal_t optimize)
{
gConfig.OptimizeMeshes = (bool)optimize;
return BBMOD_SUCCESS;
}

GM_EXPORT gmreal_t bbmod_dll_get_optimize_nodes()
{
return (gmreal_t)gConfig.OptimizeNodes;
}

GM_EXPORT gmreal_t bbmod_dll_set_optimize_nodes(gmreal_t optimize)
{
gConfig.OptimizeNodes = (bool)optimize;
return BBMOD_SUCCESS;
}

GM_EXPORT gmreal_t bbmod_dll_convert(gmstring_t fin, gmstring_t fout)
{
return ConvertToBBMOD(fin, fout, gConfig);
Expand Down
82 changes: 51 additions & 31 deletions cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <regex>
#include <cstdlib>

// TODO: Implement class for argument parsing

const char* gUsage = "Usage: BBMOD.exe [-h] input_file [output_file] [args...]";

#define PRINT_BOOL(b) (b ? "true" : "false")
Expand All @@ -21,37 +23,43 @@ void PrintHelp()
<< std::endl
<< "Arguments:" << std::endl
<< std::endl
<< " -h Show this help message and exit." << std::endl
<< " input_file Path to the model to convert." << std::endl
<< " output_file Where to save the converted model. If not specified, " << std::endl
<< " then the input file path is used. Extensions .bbmod" << std::endl
<< " and .bbanim are added automatically." << std::endl
<< " -db|--disable-bone=true|false Enable/disable saving bones and animations." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableBones) << "." << std::endl
<< " -dc|--disable-color=true|false Enable/disable saving vertex colors." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableVertexColors) << "." << std::endl
<< " -dn|--disable-normal=true|false Enable/disable saving normal vectors. This also automatically" << std::endl
<< " applies --disable-tangent." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableNormals) << "." << std::endl
<< " -dt|--disable-tangent=true|false Enable/disable saving tangent vectors and bitangent signs." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableTangentW) << "." << std::endl
<< " -duv|--disable-uv=true|false Enable/disable saving texture coordinates." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableTextureCoords) << "." << std::endl
<< " -fn|--flip-normal=true|false Enable/disable flipping normal vectors." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipNormals) << "." << std::endl
<< " -fuvx|--flip-uv-x=true|false Enable/disable flipping texture coordinates horizontally." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipTextureHorizontally) << "." << std::endl
<< " -fuvy|--flip-uv-y=true|false Enable/disable flipping texture coordinates vertically." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipTextureVertically) << "." << std::endl
<< " -gn|--gen-normal=0|1|2 Enable/disable generating normal vectors if the model doesn't have any." << std::endl
<< " * 0 - Do not generate any normal vectors." << std::endl
<< " * 1 - Generate flat normal vectors." << std::endl
<< " * 2 - Generate smooth normal vectors." << std::endl
<< " Default is " << config.GenNormals << "." << std::endl
<< " -iw|--invert-winding=true|false Invert winding order of vertices." << std::endl
<< " Default is " << PRINT_BOOL(config.InvertWinding) << "." << std::endl
<< " -lh|--left-handed=true|false Convert to left-handed coordinate system." << std::endl
<< " Default is " << PRINT_BOOL(config.LeftHanded) << "." << std::endl
<< " -h Show this help message and exit." << std::endl
<< " input_file Path to the model to convert." << std::endl
<< " output_file Where to save the converted model. If not specified, " << std::endl
<< " then the input file path is used. Extensions .bbmod" << std::endl
<< " and .bbanim are added automatically." << std::endl
<< " -db|--disable-bone=true|false Enable/disable saving bones and animations." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableBones) << "." << std::endl
<< " -dc|--disable-color=true|false Enable/disable saving vertex colors." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableVertexColors) << "." << std::endl
<< " -dn|--disable-normal=true|false Enable/disable saving normal vectors. This also automatically" << std::endl
<< " applies --disable-tangent." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableNormals) << "." << std::endl
<< " -dt|--disable-tangent=true|false Enable/disable saving tangent vectors and bitangent signs." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableTangentW) << "." << std::endl
<< " -duv|--disable-uv=true|false Enable/disable saving texture coordinates." << std::endl
<< " Default is " << PRINT_BOOL(config.DisableTextureCoords) << "." << std::endl
<< " -fn|--flip-normal=true|false Enable/disable flipping normal vectors." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipNormals) << "." << std::endl
<< " -fuvx|--flip-uv-x=true|false Enable/disable flipping texture coordinates horizontally." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipTextureHorizontally) << "." << std::endl
<< " -fuvy|--flip-uv-y=true|false Enable/disable flipping texture coordinates vertically." << std::endl
<< " Default is " << PRINT_BOOL(config.FlipTextureVertically) << "." << std::endl
<< " -gn|--gen-normal=0|1|2 Enable/disable generating normal vectors if the model doesn't have any." << std::endl
<< " * 0 - Do not generate any normal vectors." << std::endl
<< " * 1 - Generate flat normal vectors." << std::endl
<< " * 2 - Generate smooth normal vectors." << std::endl
<< " Default is " << config.GenNormals << "." << std::endl
<< " -iw|--invert-winding=true|false Invert winding order of vertices." << std::endl
<< " Default is " << PRINT_BOOL(config.InvertWinding) << "." << std::endl
<< " -lh|--left-handed=true|false Convert to left-handed coordinate system." << std::endl
<< " Default is " << PRINT_BOOL(config.LeftHanded) << "." << std::endl
<< " -on|--optimize-nodes=true|false Join multiple nodes (without animations, bones, ...) into one." << std::endl
<< " Default is " << PRINT_BOOL(config.OptimizeNodes) << "." << std::endl
<< " -ome|--optimize-meshes=true|false Join multiple meshes with the same material into one." << std::endl
<< " Default is " << PRINT_BOOL(config.OptimizeMeshes) << "." << std::endl
<< " -oma|--optimize-materials=true|false Join redundant materials into one and remove unused materials." << std::endl
<< " Default is " << PRINT_BOOL(config.OptimizeMaterials) << "." << std::endl
<< std::endl;
}

Expand Down Expand Up @@ -130,6 +138,18 @@ int main(int argc, const char* argv[])
{
config.DisableBones = b;
}
else if (o == "-on" || o == "--optimize-nodes")
{
config.OptimizeNodes = b;
}
else if (o == "-ome" || o == "--optimize-meshes")
{
config.OptimizeMeshes = b;
}
else if (o == "-oma" || o == "--optimize-materials")
{
config.OptimizeMaterials = b;
}
else
{
PRINT_ERROR("Unrecognized option %s!", argv[i]);
Expand Down
Binary file modified datafiles/BBMOD/BBMOD.dll
Binary file not shown.
Binary file modified datafiles/BBMOD/BBMOD.exe
Binary file not shown.
Loading

0 comments on commit 639faad

Please sign in to comment.