2008-10-13 16:45:48 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Defines a post processing step to search an importer's output
|
|
|
|
for data that is obviously invalid */
|
|
|
|
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
|
|
|
#ifndef AI_BUILD_NO_FINDINVALIDDATA_PROCESS
|
|
|
|
|
|
|
|
// internal headers
|
|
|
|
#include "FindInvalidDataProcess.h"
|
|
|
|
#include "ProcessHelper.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
FindInvalidDataProcess::FindInvalidDataProcess()
|
|
|
|
{
|
|
|
|
// nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
FindInvalidDataProcess::~FindInvalidDataProcess()
|
|
|
|
{
|
|
|
|
// nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the processing step is present in the given flag field.
|
|
|
|
bool FindInvalidDataProcess::IsActive( unsigned int pFlags) const
|
|
|
|
{
|
2008-10-22 20:06:16 +00:00
|
|
|
return 0 != (pFlags & aiProcess_FindInvalidData);
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Update mesh references in the node graph
|
|
|
|
void UpdateMeshReferences(aiNode* node, const std::vector<unsigned int>& meshMapping)
|
|
|
|
{
|
|
|
|
if (node->mNumMeshes)
|
|
|
|
{
|
|
|
|
unsigned int out = 0;
|
|
|
|
for (unsigned int a = 0; a < node->mNumMeshes;++a)
|
|
|
|
{
|
|
|
|
register unsigned int ref = node->mMeshes[a];
|
|
|
|
if (0xffffffff != (ref = meshMapping[ref]))
|
|
|
|
{
|
|
|
|
node->mMeshes[out++] = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// just let the members that are unused, that's much cheaper
|
|
|
|
// than a full array realloc'n'copy party ...
|
2008-10-19 11:32:33 +00:00
|
|
|
if(!(node->mNumMeshes = out))
|
|
|
|
{
|
|
|
|
delete[] node->mMeshes;
|
|
|
|
node->mMeshes = NULL;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
// recursively update all children
|
|
|
|
for (unsigned int i = 0; i < node->mNumChildren;++i)
|
|
|
|
UpdateMeshReferences(node->mChildren[i],meshMapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Executes the post processing step on the given imported data.
|
|
|
|
void FindInvalidDataProcess::Execute( aiScene* pScene)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("FindInvalidDataProcess begin");
|
|
|
|
|
|
|
|
bool out = false;
|
|
|
|
std::vector<unsigned int> meshMapping(pScene->mNumMeshes);
|
2008-10-31 19:32:00 +00:00
|
|
|
unsigned int real = 0, realAnimations = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Process meshes
|
2008-10-13 16:45:48 +00:00
|
|
|
for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
if ((result = ProcessMesh( pScene->mMeshes[a])))
|
|
|
|
{
|
|
|
|
out = true;
|
|
|
|
if (2 == result)
|
|
|
|
{
|
|
|
|
// remove this mesh
|
|
|
|
delete pScene->mMeshes[a];
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(pScene->mMeshes[a]);
|
|
|
|
|
|
|
|
meshMapping[a] = 0xffffffff;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pScene->mMeshes[real] = pScene->mMeshes[a];
|
|
|
|
meshMapping[a] = real++;
|
|
|
|
}
|
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Process animations
|
|
|
|
for (unsigned int a = 0; a < pScene->mNumAnimations;++a)
|
2008-11-02 16:58:31 +00:00
|
|
|
ProcessAnimation( pScene->mAnimations[a]);
|
2008-10-31 19:32:00 +00:00
|
|
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
if ( real != pScene->mNumMeshes)
|
|
|
|
{
|
|
|
|
if (!real)
|
|
|
|
throw new ImportErrorException("No meshes remaining");
|
|
|
|
|
|
|
|
|
|
|
|
// we need to remove some meshes.
|
|
|
|
// therefore we'll also need to remove all references
|
|
|
|
// to them from the scenegraph
|
|
|
|
UpdateMeshReferences(pScene->mRootNode,meshMapping);
|
|
|
|
pScene->mNumMeshes = real;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultLogger::get()->info("FindInvalidDataProcess finished. Found issues ...");
|
|
|
|
}
|
|
|
|
else DefaultLogger::get()->debug("FindInvalidDataProcess finished. Everything seems to be OK.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
inline const char* ValidateArrayContents(const T* arr, unsigned int size,
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
const std::vector<bool>& dirtyMask, bool mayBeIdentical = false, bool mayBeZero = true)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
inline const char* ValidateArrayContents<aiVector3D>(const aiVector3D* arr, unsigned int size,
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
const std::vector<bool>& dirtyMask, bool mayBeIdentical , bool mayBeZero )
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
|
|
|
bool b = false;
|
|
|
|
for (unsigned int i = 0; i < size;++i)
|
|
|
|
{
|
|
|
|
if (dirtyMask.size() && dirtyMask[i])continue;
|
|
|
|
|
|
|
|
const aiVector3D& v = arr[i];
|
|
|
|
if (is_special_float(v.x) || is_special_float(v.y) || is_special_float(v.z))
|
|
|
|
{
|
|
|
|
return "INF/NAN was found in a vector component";
|
|
|
|
}
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
if (!mayBeZero && !v.x && !v.y && !v.z )
|
|
|
|
{
|
|
|
|
return "Found zero-length vector";
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
if (i && v != arr[i-1])b = true;
|
|
|
|
}
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
if (!b && !mayBeIdentical)
|
2008-10-19 11:32:33 +00:00
|
|
|
return "All vectors are identical";
|
2008-10-13 16:45:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
inline bool ProcessArray(T*& in, unsigned int num,const char* name,
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
const std::vector<bool>& dirtyMask, bool mayBeIdentical = false, bool mayBeZero = true)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
const char* err = ValidateArrayContents(in,num,dirtyMask,
|
|
|
|
mayBeIdentical,mayBeZero);
|
2008-10-13 16:45:48 +00:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error(std::string("FindInvalidDataProcess fails on mesh ") + name + ": " + err);
|
|
|
|
|
|
|
|
delete[] in;
|
|
|
|
in = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-31 19:32:00 +00:00
|
|
|
template <typename T>
|
|
|
|
inline bool AllIdentical(T* in, unsigned int num)
|
|
|
|
{
|
2008-11-02 22:30:37 +00:00
|
|
|
if (num <= 1)return true;
|
2008-10-31 19:32:00 +00:00
|
|
|
for (unsigned int i = 0; i < num-1;++i)
|
|
|
|
{
|
|
|
|
if (in[i] != in[i+1])return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Search an animation for invalid content
|
2008-11-02 16:58:31 +00:00
|
|
|
void FindInvalidDataProcess::ProcessAnimation (aiAnimation* anim)
|
2008-10-31 19:32:00 +00:00
|
|
|
{
|
|
|
|
// Process all animation channels
|
|
|
|
for (unsigned int a = 0; a < anim->mNumChannels;++a)
|
2008-11-02 16:58:31 +00:00
|
|
|
ProcessAnimationChannel( anim->mChannels[a]);
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-11-02 16:58:31 +00:00
|
|
|
void FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim)
|
2008-10-31 19:32:00 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2008-11-02 16:58:31 +00:00
|
|
|
// ScenePreprocessor's work ...
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
ai_assert((0 != anim->mPositionKeys && 0 != anim->mRotationKeys && 0 != anim->mScalingKeys));
|
2008-11-02 16:58:31 +00:00
|
|
|
|
|
|
|
// Check whether all values in a tracks are identical - in this case
|
|
|
|
// we can remove al keys except one.
|
|
|
|
// POSITIONS
|
|
|
|
if (anim->mNumPositionKeys > 1 && AllIdentical(anim->mPositionKeys,anim->mNumPositionKeys))
|
2008-10-31 19:32:00 +00:00
|
|
|
{
|
2008-11-02 16:58:31 +00:00
|
|
|
aiVectorKey v = anim->mPositionKeys[0];
|
|
|
|
|
|
|
|
// Reallocate ... we need just ONE element, it makes no sense to reuse the array
|
|
|
|
delete[] anim->mPositionKeys;
|
|
|
|
anim->mPositionKeys = new aiVectorKey[anim->mNumPositionKeys = 1];
|
|
|
|
anim->mPositionKeys[0] = v;
|
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ROTATIONS
|
|
|
|
if (anim->mNumRotationKeys > 1 && AllIdentical(anim->mRotationKeys,anim->mNumRotationKeys))
|
|
|
|
{
|
|
|
|
aiQuatKey v = anim->mRotationKeys[0];
|
|
|
|
|
|
|
|
// Reallocate ... we need just ONE element, it makes no sense to reuse the array
|
|
|
|
delete[] anim->mRotationKeys;
|
|
|
|
anim->mRotationKeys = new aiQuatKey[anim->mNumRotationKeys = 1];
|
|
|
|
anim->mRotationKeys[0] = v;
|
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SCALINGS
|
|
|
|
if (anim->mNumScalingKeys > 1 && AllIdentical(anim->mScalingKeys,anim->mNumScalingKeys))
|
|
|
|
{
|
|
|
|
aiVectorKey v = anim->mScalingKeys[0];
|
|
|
|
|
|
|
|
// Reallocate ... we need just ONE element, it makes no sense to reuse the array
|
|
|
|
delete[] anim->mScalingKeys;
|
|
|
|
anim->mScalingKeys = new aiVectorKey[anim->mNumScalingKeys = 1];
|
|
|
|
anim->mScalingKeys[0] = v;
|
|
|
|
i = 1;
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
2008-11-02 16:58:31 +00:00
|
|
|
if (1 == i)
|
|
|
|
DefaultLogger::get()->warn("Simplified dummy tracks with just one key");
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Search a mesh for invalid contents
|
2008-10-13 16:45:48 +00:00
|
|
|
int FindInvalidDataProcess::ProcessMesh (aiMesh* pMesh)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
2008-11-16 21:56:45 +00:00
|
|
|
std::vector<bool> dirtyMask(pMesh->mNumVertices,true);
|
|
|
|
|
|
|
|
// Ignore elements that are not referenced by vertices.
|
|
|
|
// (they are, for example, caused by the FindDegenerates step)
|
|
|
|
for (unsigned int m = 0; m < pMesh->mNumFaces;++m)
|
|
|
|
{
|
|
|
|
const aiFace& f = pMesh->mFaces[m];
|
|
|
|
for (unsigned int i = 0; i < f.mNumIndices;++i)
|
|
|
|
dirtyMask[f.mIndices[i]] = false;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// process vertex positions
|
|
|
|
if(pMesh->mVertices && ProcessArray(pMesh->mVertices,pMesh->mNumVertices,"positions",dirtyMask))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("Deleting mesh: Unable to continue without vertex positions");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// process texture coordinates
|
|
|
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i)
|
|
|
|
{
|
|
|
|
if (!pMesh->mTextureCoords[i])break;
|
|
|
|
if (ProcessArray(pMesh->mTextureCoords[i],pMesh->mNumVertices,"uvcoords",dirtyMask))
|
|
|
|
{
|
|
|
|
// delete all subsequent texture coordinate sets.
|
|
|
|
for (unsigned int a = i+1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
|
|
|
|
{
|
|
|
|
delete[] pMesh->mTextureCoords[a]; pMesh->mTextureCoords[a] = NULL;
|
|
|
|
}
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- we don't validate vertex colors, it's difficult to say whether
|
|
|
|
// they are invalid or not.
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Normals and tangents are undefined for point and line faces.
|
2008-10-13 16:45:48 +00:00
|
|
|
if (pMesh->mNormals || pMesh->mTangents)
|
|
|
|
{
|
|
|
|
if (aiPrimitiveType_POINT & pMesh->mPrimitiveTypes ||
|
|
|
|
aiPrimitiveType_LINE & pMesh->mPrimitiveTypes)
|
|
|
|
{
|
|
|
|
if (aiPrimitiveType_TRIANGLE & pMesh->mPrimitiveTypes ||
|
|
|
|
aiPrimitiveType_POLYGON & pMesh->mPrimitiveTypes)
|
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
// We need to update the lookup-table
|
2008-10-13 16:45:48 +00:00
|
|
|
for (unsigned int m = 0; m < pMesh->mNumFaces;++m)
|
|
|
|
{
|
|
|
|
const aiFace& f = pMesh->mFaces[m];
|
|
|
|
if (2 == f.mNumIndices)
|
|
|
|
{
|
|
|
|
dirtyMask[f.mIndices[0]] = dirtyMask[f.mIndices[1]] = true;
|
|
|
|
}
|
|
|
|
else if (1 == f.mNumIndices)dirtyMask[f.mIndices[0]] = true;
|
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
// Normals, tangents and bitangents are undefined for
|
|
|
|
// the whole mesh (and should not even be there)
|
2008-10-13 16:45:48 +00:00
|
|
|
else return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Process mesh normals
|
2008-10-22 20:06:16 +00:00
|
|
|
if (pMesh->mNormals && ProcessArray(pMesh->mNormals,pMesh->mNumVertices,
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
"normals",dirtyMask,true,false))
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = true;
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Process mesh tangents
|
2008-10-22 20:06:16 +00:00
|
|
|
if (pMesh->mTangents && ProcessArray(pMesh->mTangents,pMesh->mNumVertices,
|
|
|
|
"tangents",dirtyMask))
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
delete[] pMesh->mTangents; pMesh->mTangents = NULL;
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Process mesh bitangents
|
2008-10-22 20:06:16 +00:00
|
|
|
if (pMesh->mBitangents && ProcessArray(pMesh->mBitangents,pMesh->mNumVertices,
|
|
|
|
"bitangents",dirtyMask))
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
delete[] pMesh->mBitangents; pMesh->mBitangents = NULL;
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !! AI_BUILD_NO_FINDINVALIDDATA_PROCESS
|