assimp: add various config variables, change default winding order

This commit is contained in:
rdb 2018-08-12 22:22:25 +02:00
parent f84b0840f9
commit 00b5c9d168
3 changed files with 82 additions and 4 deletions

View File

@ -103,9 +103,34 @@ bool AssimpLoader::
read(const Filename &filename) {
_filename = filename;
// I really don't know why we need to flip the winding order, but otherwise
// the models I tested with are showing inside out.
_scene = _importer.ReadFile(_filename.c_str(), aiProcess_Triangulate | aiProcess_GenUVCoords | aiProcess_FlipWindingOrder);
unsigned int flags = aiProcess_Triangulate | aiProcess_GenUVCoords;
if (assimp_calc_tangent_space) {
flags |= aiProcess_CalcTangentSpace;
}
if (assimp_join_identical_vertices) {
flags |= aiProcess_JoinIdenticalVertices;
}
if (assimp_improve_cache_locality) {
flags |= aiProcess_ImproveCacheLocality;
}
if (assimp_remove_redundant_materials) {
flags |= aiProcess_RemoveRedundantMaterials;
}
if (assimp_fix_infacing_normals) {
flags |= aiProcess_FixInfacingNormals;
}
if (assimp_optimize_meshes) {
flags |= aiProcess_OptimizeMeshes;
}
if (assimp_optimize_graph) {
flags |= aiProcess_OptimizeGraph;
}
if (assimp_flip_winding_order) {
flags |= aiProcess_FlipWindingOrder;
}
_scene = _importer.ReadFile(_filename.c_str(), flags);
if (_scene == nullptr) {
_error = true;
return false;

View File

@ -25,6 +25,50 @@ ConfigureFn(config_assimp) {
init_libassimp();
}
ConfigVariableBool assimp_calc_tangent_space
("assimp-calc-tangent-space", false,
PRC_DESC("Calculates tangents and binormals for meshes imported via Assimp."));
ConfigVariableBool assimp_join_identical_vertices
("assimp-join-identical-vertices", true,
PRC_DESC("Merges duplicate vertices. Set this to false if you want each "
"vertex to only be in use on one triangle."));
ConfigVariableBool assimp_improve_cache_locality
("assimp-improve-cache-locality", true,
PRC_DESC("Improves rendering performance of the loaded meshes by reordering "
"triangles for better vertex cache locality. Set this to false if "
"you need geometry to be loaded in the exact order that it was "
"specified in the file, or to improve load performance."));
ConfigVariableBool assimp_remove_redundant_materials
("assimp-remove-redundant-materials", true,
PRC_DESC("Removes redundant/unreferenced materials from assets."));
ConfigVariableBool assimp_fix_infacing_normals
("assimp-fix-infacing-normals", false,
PRC_DESC("Determines which normal vectors are facing inward and inverts them "
"so that they are facing outward."));
ConfigVariableBool assimp_optimize_meshes
("assimp-optimize-meshes", true,
PRC_DESC("Removes the number of draw calls by unifying geometry with the same "
"materials. Especially effective in conjunction with "
"assimp-optimize-graph and assimp-remove-redundant-materials."));
ConfigVariableBool assimp_optimize_graph
("assimp-optimize-graph", false,
PRC_DESC("Optimizes the scene geometry by flattening the scene hierarchy. "
"This is very efficient (combined with assimp-optimize-meshes), but "
"it may result the hierarchy to become lost, so it is disabled by "
"default."));
ConfigVariableBool assimp_flip_winding_order
("assimp-flip-winding-order", false,
PRC_DESC("Set this true to flip the winding order of all models loaded via "
"the Assimp loader. Note that you may need to clear the model-cache "
"after changing this."));
/**
* Initializes the library. This must be called at least once before any of
* the functions or classes in this library can be used. Normally it will be

View File

@ -15,12 +15,21 @@
#define CONFIG_ASSIMP_H
#include "pandatoolbase.h"
#include "configVariableBool.h"
#include "dconfig.h"
ConfigureDecl(config_assimp, EXPCL_ASSIMP, EXPTP_ASSIMP);
NotifyCategoryDecl(assimp, EXPCL_ASSIMP, EXPTP_ASSIMP);
extern ConfigVariableBool assimp_calc_tangent_space;
extern ConfigVariableBool assimp_join_identical_vertices;
extern ConfigVariableBool assimp_improve_cache_locality;
extern ConfigVariableBool assimp_remove_redundant_materials;
extern ConfigVariableBool assimp_fix_infacing_normals;
extern ConfigVariableBool assimp_optimize_meshes;
extern ConfigVariableBool assimp_optimize_graph;
extern ConfigVariableBool assimp_flip_winding_order;
extern EXPCL_ASSIMP void init_libassimp();
#endif