From e1e5b907c105f227eeb2fedee43c949901f9ad4f Mon Sep 17 00:00:00 2001 From: tc Date: Fri, 11 Jan 2019 00:07:17 +0100 Subject: [PATCH] add aiProcess_GenNormals + aiProcess_GenSmoothNormals --- pandatool/src/assimp/assimpLoader.cxx | 10 ++++++++++ pandatool/src/assimp/config_assimp.cxx | 17 +++++++++++++++++ pandatool/src/assimp/config_assimp.h | 3 +++ 3 files changed, 30 insertions(+) diff --git a/pandatool/src/assimp/assimpLoader.cxx b/pandatool/src/assimp/assimpLoader.cxx index 8533fbaa64..ec0dc40b7d 100644 --- a/pandatool/src/assimp/assimpLoader.cxx +++ b/pandatool/src/assimp/assimpLoader.cxx @@ -129,6 +129,16 @@ read(const Filename &filename) { if (assimp_flip_winding_order) { flags |= aiProcess_FlipWindingOrder; } + if (assimp_gen_normals) { + if (assimp_smooth_normal_angle == 0.0) { + flags |= aiProcess_GenNormals; + } + else { + flags |= aiProcess_GenSmoothNormals; + _importer.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, + assimp_smooth_normal_angle); + } + } _scene = _importer.ReadFile(_filename.c_str(), flags); if (_scene == nullptr) { diff --git a/pandatool/src/assimp/config_assimp.cxx b/pandatool/src/assimp/config_assimp.cxx index 2dbf29fa16..2b84d2c63b 100644 --- a/pandatool/src/assimp/config_assimp.cxx +++ b/pandatool/src/assimp/config_assimp.cxx @@ -69,6 +69,23 @@ ConfigVariableBool assimp_flip_winding_order "the Assimp loader. Note that you may need to clear the model-cache " "after changing this.")); +ConfigVariableBool assimp_gen_normals +("assimp-gen-normals", false, + PRC_DESC("Set this true to generate normals (if absent from file) on import. " + "See assimp-smooth-normal-angle for more information. " + "Note that you may need to clear the model-cache after " + "changing this.")); + +ConfigVariableDouble assimp_smooth_normal_angle +("assimp-smooth-normal-angle", 0.0, + PRC_DESC("Set this to anything other than 0.0 in degrees (so 180.0 is PI) to " + "specify the maximum angle that may be between two face normals at " + "the same vertex position that are smoothed together. Sometimes " + "referred to as 'crease angle'. Only has effect if " + "assimp-gen-normals is set to true and the file does not contain " + "normals. 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 diff --git a/pandatool/src/assimp/config_assimp.h b/pandatool/src/assimp/config_assimp.h index 16efc8a754..898497eeb2 100644 --- a/pandatool/src/assimp/config_assimp.h +++ b/pandatool/src/assimp/config_assimp.h @@ -16,6 +16,7 @@ #include "pandatoolbase.h" #include "configVariableBool.h" +#include "configVariableDouble.h" #include "dconfig.h" ConfigureDecl(config_assimp, EXPCL_ASSIMP, EXPTP_ASSIMP); @@ -29,6 +30,8 @@ extern ConfigVariableBool assimp_fix_infacing_normals; extern ConfigVariableBool assimp_optimize_meshes; extern ConfigVariableBool assimp_optimize_graph; extern ConfigVariableBool assimp_flip_winding_order; +extern ConfigVariableBool assimp_gen_normals; +extern ConfigVariableDouble assimp_smooth_normal_angle; extern EXPCL_ASSIMP void init_libassimp();