Merge branch 'master' into kimkulling-dev-1

pull/2311/head
Kim Kulling 2019-01-28 14:40:10 +01:00 committed by GitHub
commit 6b8514ba93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 72 deletions

View File

@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// internal headers // internal headers
#include "FindInvalidDataProcess.h" #include "FindInvalidDataProcess.h"
#include "ProcessHelper.h" #include "ProcessHelper.h"
#include <assimp/Macros.h> #include <assimp/Macros.h>
#include <assimp/Exceptional.h> #include <assimp/Exceptional.h>
#include <assimp/qnan.h> #include <assimp/qnan.h>
@ -60,37 +61,34 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
FindInvalidDataProcess::FindInvalidDataProcess() FindInvalidDataProcess::FindInvalidDataProcess()
: configEpsilon(0.0) : configEpsilon(0.0)
{ , mIgnoreTexCoods( false ){
// nothing to do here // nothing to do here
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor, private as well // Destructor, private as well
FindInvalidDataProcess::~FindInvalidDataProcess() FindInvalidDataProcess::~FindInvalidDataProcess() {
{
// nothing to do here // nothing to do here
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the processing step is present in the given flag field. // Returns whether the processing step is present in the given flag field.
bool FindInvalidDataProcess::IsActive( unsigned int pFlags) const bool FindInvalidDataProcess::IsActive( unsigned int pFlags) const {
{
return 0 != (pFlags & aiProcess_FindInvalidData); return 0 != (pFlags & aiProcess_FindInvalidData);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Setup import configuration // Setup import configuration
void FindInvalidDataProcess::SetupProperties(const Importer* pImp) void FindInvalidDataProcess::SetupProperties(const Importer* pImp) {
{
// Get the current value of AI_CONFIG_PP_FID_ANIM_ACCURACY // Get the current value of AI_CONFIG_PP_FID_ANIM_ACCURACY
configEpsilon = (0 != pImp->GetPropertyFloat(AI_CONFIG_PP_FID_ANIM_ACCURACY,0.f)); configEpsilon = (0 != pImp->GetPropertyFloat(AI_CONFIG_PP_FID_ANIM_ACCURACY,0.f));
mIgnoreTexCoods = pImp->GetPropertyBool(AI_CONFIG_PP_FID_IGNORE_TEXTURECOORDS, false);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Update mesh references in the node graph // Update mesh references in the node graph
void UpdateMeshReferences(aiNode* node, const std::vector<unsigned int>& meshMapping) void UpdateMeshReferences(aiNode* node, const std::vector<unsigned int>& meshMapping) {
{
if (node->mNumMeshes) { if (node->mNumMeshes) {
unsigned int out = 0; unsigned int out = 0;
for (unsigned int a = 0; a < node->mNumMeshes;++a) { for (unsigned int a = 0; a < node->mNumMeshes;++a) {
@ -116,8 +114,7 @@ void UpdateMeshReferences(aiNode* node, const std::vector<unsigned int>& meshMap
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data. // Executes the post processing step on the given imported data.
void FindInvalidDataProcess::Execute( aiScene* pScene) void FindInvalidDataProcess::Execute( aiScene* pScene) {
{
ASSIMP_LOG_DEBUG("FindInvalidDataProcess begin"); ASSIMP_LOG_DEBUG("FindInvalidDataProcess begin");
bool out = false; bool out = false;
@ -171,17 +168,18 @@ void FindInvalidDataProcess::Execute( aiScene* pScene)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
inline const char* ValidateArrayContents(const T* /*arr*/, unsigned int /*size*/, inline
const std::vector<bool>& /*dirtyMask*/, bool /*mayBeIdentical = false*/, bool /*mayBeZero = true*/) const char* ValidateArrayContents(const T* /*arr*/, unsigned int /*size*/,
const std::vector<bool>& /*dirtyMask*/, bool /*mayBeIdentical = false*/, bool /*mayBeZero = true*/)
{ {
return NULL; return nullptr;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <> template <>
inline const char* ValidateArrayContents<aiVector3D>(const aiVector3D* arr, unsigned int size, inline
const std::vector<bool>& dirtyMask, bool mayBeIdentical , bool mayBeZero ) const char* ValidateArrayContents<aiVector3D>(const aiVector3D* arr, unsigned int size,
{ const std::vector<bool>& dirtyMask, bool mayBeIdentical , bool mayBeZero ) {
bool b = false; bool b = false;
unsigned int cnt = 0; unsigned int cnt = 0;
for (unsigned int i = 0; i < size;++i) { for (unsigned int i = 0; i < size;++i) {
@ -203,14 +201,14 @@ inline const char* ValidateArrayContents<aiVector3D>(const aiVector3D* arr, unsi
if (cnt > 1 && !b && !mayBeIdentical) { if (cnt > 1 && !b && !mayBeIdentical) {
return "All vectors are identical"; return "All vectors are identical";
} }
return NULL; return nullptr;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
inline bool ProcessArray(T*& in, unsigned int num,const char* name, inline
const std::vector<bool>& dirtyMask, bool mayBeIdentical = false, bool mayBeZero = true) bool ProcessArray(T*& in, unsigned int num,const char* name,
{ const std::vector<bool>& dirtyMask, bool mayBeIdentical = false, bool mayBeZero = true) {
const char* err = ValidateArrayContents(in,num,dirtyMask,mayBeIdentical,mayBeZero); const char* err = ValidateArrayContents(in,num,dirtyMask,mayBeIdentical,mayBeZero);
if (err) { if (err) {
ASSIMP_LOG_ERROR_F( "FindInvalidDataProcess fails on mesh ", name, ": ", err); ASSIMP_LOG_ERROR_F( "FindInvalidDataProcess fails on mesh ", name, ": ", err);
@ -251,23 +249,20 @@ bool EpsilonCompare<aiQuatKey>(const aiQuatKey& n, const aiQuatKey& s, ai_real e
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
inline bool AllIdentical(T* in, unsigned int num, ai_real epsilon) inline
{ bool AllIdentical(T* in, unsigned int num, ai_real epsilon) {
if (num <= 1) { if (num <= 1) {
return true; return true;
} }
if (epsilon > 0.f) { if (fabs(epsilon) > 0.f) {
for (unsigned int i = 0; i < num-1;++i) { for (unsigned int i = 0; i < num-1;++i) {
if (!EpsilonCompare(in[i],in[i+1],epsilon)) { if (!EpsilonCompare(in[i],in[i+1],epsilon)) {
return false; return false;
} }
} }
} } else {
else {
for (unsigned int i = 0; i < num-1;++i) { for (unsigned int i = 0; i < num-1;++i) {
if (in[i] != in[i+1]) { if (in[i] != in[i+1]) {
return false; return false;
} }
@ -278,27 +273,24 @@ inline bool AllIdentical(T* in, unsigned int num, ai_real epsilon)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Search an animation for invalid content // Search an animation for invalid content
void FindInvalidDataProcess::ProcessAnimation (aiAnimation* anim) void FindInvalidDataProcess::ProcessAnimation (aiAnimation* anim) {
{
// Process all animation channels // Process all animation channels
for (unsigned int a = 0; a < anim->mNumChannels;++a) { for ( unsigned int a = 0; a < anim->mNumChannels; ++a ) {
ProcessAnimationChannel( anim->mChannels[a]); ProcessAnimationChannel( anim->mChannels[a]);
} }
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim) void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim) {
{ ai_assert( 0 != anim->mPositionKeys );
int i = 0; ai_assert( 0 != anim->mRotationKeys );
ai_assert( 0 != anim->mScalingKeys );
// ScenePreprocessor's work ...
ai_assert((0 != anim->mPositionKeys && 0 != anim->mRotationKeys && 0 != anim->mScalingKeys));
// Check whether all values in a tracks are identical - in this case // Check whether all values in a tracks are identical - in this case
// we can remove al keys except one. // we can remove al keys except one.
// POSITIONS // POSITIONS
if (anim->mNumPositionKeys > 1 && AllIdentical(anim->mPositionKeys,anim->mNumPositionKeys,configEpsilon)) int i = 0;
{ if (anim->mNumPositionKeys > 1 && AllIdentical(anim->mPositionKeys,anim->mNumPositionKeys,configEpsilon)) {
aiVectorKey v = anim->mPositionKeys[0]; aiVectorKey v = anim->mPositionKeys[0];
// Reallocate ... we need just ONE element, it makes no sense to reuse the array // Reallocate ... we need just ONE element, it makes no sense to reuse the array
@ -309,8 +301,7 @@ void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim)
} }
// ROTATIONS // ROTATIONS
if (anim->mNumRotationKeys > 1 && AllIdentical(anim->mRotationKeys,anim->mNumRotationKeys,configEpsilon)) if (anim->mNumRotationKeys > 1 && AllIdentical(anim->mRotationKeys,anim->mNumRotationKeys,configEpsilon)) {
{
aiQuatKey v = anim->mRotationKeys[0]; aiQuatKey v = anim->mRotationKeys[0];
// Reallocate ... we need just ONE element, it makes no sense to reuse the array // Reallocate ... we need just ONE element, it makes no sense to reuse the array
@ -321,8 +312,7 @@ void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim)
} }
// SCALINGS // SCALINGS
if (anim->mNumScalingKeys > 1 && AllIdentical(anim->mScalingKeys,anim->mNumScalingKeys,configEpsilon)) if (anim->mNumScalingKeys > 1 && AllIdentical(anim->mScalingKeys,anim->mNumScalingKeys,configEpsilon)) {
{
aiVectorKey v = anim->mScalingKeys[0]; aiVectorKey v = anim->mScalingKeys[0];
// Reallocate ... we need just ONE element, it makes no sense to reuse the array // Reallocate ... we need just ONE element, it makes no sense to reuse the array
@ -331,8 +321,9 @@ void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim)
anim->mScalingKeys[0] = v; anim->mScalingKeys[0] = v;
i = 1; i = 1;
} }
if (1 == i) if ( 1 == i ) {
ASSIMP_LOG_WARN("Simplified dummy tracks with just one key"); ASSIMP_LOG_WARN("Simplified dummy tracks with just one key");
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -360,18 +351,20 @@ int FindInvalidDataProcess::ProcessMesh (aiMesh* pMesh)
} }
// process texture coordinates // process texture coordinates
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS && pMesh->mTextureCoords[i]; ++i) { if (!mIgnoreTexCoods) {
if (ProcessArray(pMesh->mTextureCoords[i], pMesh->mNumVertices, "uvcoords", dirtyMask)) { for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS && pMesh->mTextureCoords[i]; ++i) {
pMesh->mNumUVComponents[i] = 0; if (ProcessArray(pMesh->mTextureCoords[i], pMesh->mNumVertices, "uvcoords", dirtyMask)) {
pMesh->mNumUVComponents[i] = 0;
// delete all subsequent texture coordinate sets. // delete all subsequent texture coordinate sets.
for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) { for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
delete[] pMesh->mTextureCoords[a]; delete[] pMesh->mTextureCoords[a];
pMesh->mTextureCoords[a] = NULL; pMesh->mTextureCoords[a] = NULL;
pMesh->mNumUVComponents[a] = 0; pMesh->mNumUVComponents[a] = 0;
}
ret = true;
} }
ret = true;
} }
} }
@ -388,13 +381,11 @@ int FindInvalidDataProcess::ProcessMesh (aiMesh* pMesh)
aiPrimitiveType_POLYGON & pMesh->mPrimitiveTypes) aiPrimitiveType_POLYGON & pMesh->mPrimitiveTypes)
{ {
// We need to update the lookup-table // We need to update the lookup-table
for (unsigned int m = 0; m < pMesh->mNumFaces;++m) for (unsigned int m = 0; m < pMesh->mNumFaces;++m) {
{ const aiFace& f = pMesh->mFaces[ m ];
const aiFace& f = pMesh->mFaces[m];
if (f.mNumIndices < 3) { if (f.mNumIndices < 3) {
dirtyMask[f.mIndices[0]] = true; dirtyMask[f.mIndices[0]] = true;
if (f.mNumIndices == 2) { if (f.mNumIndices == 2) {
dirtyMask[f.mIndices[1]] = true; dirtyMask[f.mIndices[1]] = true;
} }
@ -403,7 +394,9 @@ int FindInvalidDataProcess::ProcessMesh (aiMesh* pMesh)
} }
// Normals, tangents and bitangents are undefined for // Normals, tangents and bitangents are undefined for
// the whole mesh (and should not even be there) // the whole mesh (and should not even be there)
else return ret; else {
return ret;
}
} }
// Process mesh normals // Process mesh normals
@ -426,5 +419,4 @@ int FindInvalidDataProcess::ProcessMesh (aiMesh* pMesh)
return ret ? 1 : 0; return ret ? 1 : 0;
} }
#endif // !! ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS #endif // !! ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS

View File

@ -41,7 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** @file Defines a post processing step to search an importer's output /** @file Defines a post processing step to search an importer's output
for data that is obviously invalid */ * for data that is obviously invalid
*/
#ifndef AI_FINDINVALIDDATA_H_INC #ifndef AI_FINDINVALIDDATA_H_INC
#define AI_FINDINVALIDDATA_H_INC #define AI_FINDINVALIDDATA_H_INC
@ -50,7 +51,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/anim.h> #include <assimp/anim.h>
struct aiMesh; struct aiMesh;
class FindInvalidDataProcessTest; class FindInvalidDataProcessTest;
namespace Assimp { namespace Assimp {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -59,15 +62,11 @@ namespace Assimp {
* *
* Originally this was a workaround for some models written by Blender * Originally this was a workaround for some models written by Blender
* which have zero normal vectors. */ * which have zero normal vectors. */
class ASSIMP_API FindInvalidDataProcess : public BaseProcess class ASSIMP_API FindInvalidDataProcess : public BaseProcess {
{
public: public:
FindInvalidDataProcess(); FindInvalidDataProcess();
~FindInvalidDataProcess(); ~FindInvalidDataProcess();
public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// //
bool IsActive( unsigned int pFlags) const; bool IsActive( unsigned int pFlags) const;
@ -80,26 +79,25 @@ public:
// Run the step // Run the step
void Execute( aiScene* pScene); void Execute( aiScene* pScene);
public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Executes the postprocessing step on the given mesh /** Executes the post-processing step on the given mesh
* @param pMesh The mesh to process. * @param pMesh The mesh to process.
* @return 0 - nothing, 1 - removed sth, 2 - please delete me */ * @return 0 - nothing, 1 - removed sth, 2 - please delete me */
int ProcessMesh( aiMesh* pMesh); int ProcessMesh( aiMesh* pMesh);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Executes the postprocessing step on the given animation /** Executes the post-processing step on the given animation
* @param anim The animation to process. */ * @param anim The animation to process. */
void ProcessAnimation (aiAnimation* anim); void ProcessAnimation (aiAnimation* anim);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Executes the postprocessing step on the given anim channel /** Executes the post-processing step on the given anim channel
* @param anim The animation channel to process.*/ * @param anim The animation channel to process.*/
void ProcessAnimationChannel (aiNodeAnim* anim); void ProcessAnimationChannel (aiNodeAnim* anim);
private: private:
ai_real configEpsilon; ai_real configEpsilon;
bool mIgnoreTexCoods;
}; };
} // end of namespace Assimp } // end of namespace Assimp

View File

@ -498,6 +498,13 @@ enum aiComponent
#define AI_CONFIG_PP_FID_ANIM_ACCURACY \ #define AI_CONFIG_PP_FID_ANIM_ACCURACY \
"PP_FID_ANIM_ACCURACY" "PP_FID_ANIM_ACCURACY"
// ---------------------------------------------------------------------------
/** @brief Input parameter to the #aiProcess_FindInvalidData step:
* Set to true to ignore texture coordinates. This may be useful if you have
* to assign different kind of textures like one for the summer or one for the winter.
*/
#define AI_CONFIG_PP_FID_IGNORE_TEXTURECOORDS \
"PP_FID_IGNORE_TEXTURECOORDS"
// TransformUVCoords evaluates UV scalings // TransformUVCoords evaluates UV scalings
#define AI_UVTRAFO_SCALING 0x1 #define AI_UVTRAFO_SCALING 0x1