2008-10-13 16:45:48 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-10-13 16:45:48 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2008-10-13 16:45:48 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2015-04-15 23:00:17 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2010-05-10 10:22:24 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// internal headers
|
|
|
|
#include "FindInvalidDataProcess.h"
|
2015-04-15 23:00:17 +00:00
|
|
|
#include "ProcessHelper.h"
|
|
|
|
#include "Macros.h"
|
|
|
|
#include "Exceptional.h"
|
|
|
|
#include "qnan.h"
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
FindInvalidDataProcess::FindInvalidDataProcess()
|
2015-05-16 19:13:22 +00:00
|
|
|
: configEpsilon(0.0f)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2009-09-21 17:41:57 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Setup import configuration
|
|
|
|
void FindInvalidDataProcess::SetupProperties(const Importer* pImp)
|
|
|
|
{
|
|
|
|
// Get the current value of AI_CONFIG_PP_FID_ANIM_ACCURACY
|
|
|
|
configEpsilon = (0 != pImp->GetPropertyFloat(AI_CONFIG_PP_FID_ANIM_ACCURACY,0.f));
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-09-21 17:41:57 +00:00
|
|
|
if (node->mNumMeshes) {
|
2008-10-13 16:45:48 +00:00
|
|
|
unsigned int out = 0;
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int a = 0; a < node->mNumMeshes;++a) {
|
|
|
|
|
2015-03-02 22:44:02 +00:00
|
|
|
unsigned int ref = node->mMeshes[a];
|
2011-04-22 21:29:18 +00:00
|
|
|
if (UINT_MAX != (ref = meshMapping[ref])) {
|
2008-10-13 16:45:48 +00:00
|
|
|
node->mMeshes[out++] = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// just let the members that are unused, that's much cheaper
|
|
|
|
// than a full array realloc'n'copy party ...
|
2009-09-21 17:41:57 +00:00
|
|
|
if(!(node->mNumMeshes = out)) {
|
|
|
|
|
2008-10-19 11:32:33 +00:00
|
|
|
delete[] node->mMeshes;
|
|
|
|
node->mMeshes = NULL;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
// recursively update all children
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int i = 0; i < node->mNumChildren;++i) {
|
2008-10-13 16:45:48 +00:00
|
|
|
UpdateMeshReferences(node->mChildren[i],meshMapping);
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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);
|
2009-03-06 12:37:08 +00:00
|
|
|
unsigned int real = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Process meshes
|
2009-09-21 17:41:57 +00:00
|
|
|
for( unsigned int a = 0; a < pScene->mNumMeshes; a++) {
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
int result;
|
2009-09-21 17:41:57 +00:00
|
|
|
if ((result = ProcessMesh( pScene->mMeshes[a]))) {
|
2008-10-13 16:45:48 +00:00
|
|
|
out = true;
|
2009-09-21 17:41:57 +00:00
|
|
|
|
|
|
|
if (2 == result) {
|
2008-10-13 16:45:48 +00:00
|
|
|
// remove this mesh
|
|
|
|
delete pScene->mMeshes[a];
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(pScene->mMeshes[a]);
|
|
|
|
|
2011-04-22 21:29:18 +00:00
|
|
|
meshMapping[a] = UINT_MAX;
|
2008-10-13 16:45:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pScene->mMeshes[real] = pScene->mMeshes[a];
|
|
|
|
meshMapping[a] = real++;
|
|
|
|
}
|
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Process animations
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int a = 0; a < pScene->mNumAnimations;++a) {
|
2008-11-02 16:58:31 +00:00
|
|
|
ProcessAnimation( pScene->mAnimations[a]);
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
|
|
|
|
|
2009-09-21 17:41:57 +00:00
|
|
|
if (out) {
|
|
|
|
if ( real != pScene->mNumMeshes) {
|
|
|
|
if (!real) {
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("No meshes remaining");
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// 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;
|
2009-01-12 22:06:54 +00:00
|
|
|
unsigned int cnt = 0;
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int i = 0; i < size;++i) {
|
|
|
|
|
|
|
|
if (dirtyMask.size() && dirtyMask[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-12 22:06:54 +00:00
|
|
|
++cnt;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
const aiVector3D& v = arr[i];
|
2009-09-21 17:41:57 +00:00
|
|
|
if (is_special_float(v.x) || is_special_float(v.y) || is_special_float(v.z)) {
|
2008-10-13 16:45:48 +00:00
|
|
|
return "INF/NAN was found in a vector component";
|
|
|
|
}
|
2009-09-21 17:41:57 +00:00
|
|
|
if (!mayBeZero && !v.x && !v.y && !v.z ) {
|
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
|
|
|
return "Found zero-length vector";
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
if (i && v != arr[i-1])b = true;
|
|
|
|
}
|
2009-09-21 17:41:57 +00:00
|
|
|
if (cnt > 1 && !b && !mayBeIdentical) {
|
2008-10-19 11:32:33 +00:00
|
|
|
return "All vectors are identical";
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
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
|
|
|
{
|
2009-09-21 17:41:57 +00:00
|
|
|
const char* err = ValidateArrayContents(in,num,dirtyMask,mayBeIdentical,mayBeZero);
|
|
|
|
if (err) {
|
2008-10-13 16:45:48 +00:00
|
|
|
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>
|
2009-09-21 17:41:57 +00:00
|
|
|
AI_FORCE_INLINE bool EpsilonCompare(const T& n, const T& s, float epsilon);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
AI_FORCE_INLINE bool EpsilonCompare(float n, float s, float epsilon) {
|
2014-09-22 22:42:32 +00:00
|
|
|
return std::fabs(n-s)>epsilon;
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
bool EpsilonCompare<aiVectorKey>(const aiVectorKey& n, const aiVectorKey& s, float epsilon) {
|
|
|
|
return
|
|
|
|
EpsilonCompare(n.mValue.x,s.mValue.x,epsilon) &&
|
|
|
|
EpsilonCompare(n.mValue.y,s.mValue.y,epsilon) &&
|
|
|
|
EpsilonCompare(n.mValue.z,s.mValue.z,epsilon);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
bool EpsilonCompare<aiQuatKey>(const aiQuatKey& n, const aiQuatKey& s, float epsilon) {
|
|
|
|
return
|
|
|
|
EpsilonCompare(n.mValue.x,s.mValue.x,epsilon) &&
|
|
|
|
EpsilonCompare(n.mValue.y,s.mValue.y,epsilon) &&
|
|
|
|
EpsilonCompare(n.mValue.z,s.mValue.z,epsilon) &&
|
|
|
|
EpsilonCompare(n.mValue.w,s.mValue.w,epsilon);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
inline bool AllIdentical(T* in, unsigned int num, float epsilon)
|
2008-10-31 19:32:00 +00:00
|
|
|
{
|
2009-09-21 17:41:57 +00:00
|
|
|
if (num <= 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (epsilon > 0.f) {
|
|
|
|
for (unsigned int i = 0; i < num-1;++i) {
|
|
|
|
|
|
|
|
if (!EpsilonCompare(in[i],in[i+1],epsilon)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (unsigned int i = 0; i < num-1;++i) {
|
|
|
|
|
|
|
|
if (in[i] != in[i+1]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
|
|
|
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
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int a = 0; a < anim->mNumChannels;++a) {
|
2008-11-02 16:58:31 +00:00
|
|
|
ProcessAnimationChannel( anim->mChannels[a]);
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
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
|
2009-09-21 17:41:57 +00:00
|
|
|
if (anim->mNumPositionKeys > 1 && AllIdentical(anim->mPositionKeys,anim->mNumPositionKeys,configEpsilon))
|
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
|
2009-09-21 17:41:57 +00:00
|
|
|
if (anim->mNumRotationKeys > 1 && AllIdentical(anim->mRotationKeys,anim->mNumRotationKeys,configEpsilon))
|
2008-11-02 16:58:31 +00:00
|
|
|
{
|
|
|
|
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
|
2009-09-21 17:41:57 +00:00
|
|
|
if (anim->mNumScalingKeys > 1 && AllIdentical(anim->mScalingKeys,anim->mNumScalingKeys,configEpsilon))
|
2008-11-02 16:58:31 +00:00
|
|
|
{
|
|
|
|
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;
|
2009-01-12 22:06:54 +00:00
|
|
|
std::vector<bool> dirtyMask(pMesh->mNumVertices,(pMesh->mNumFaces ? true : false));
|
2008-11-16 21:56:45 +00:00
|
|
|
|
|
|
|
// Ignore elements that are not referenced by vertices.
|
|
|
|
// (they are, for example, caused by the FindDegenerates step)
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int m = 0; m < pMesh->mNumFaces;++m) {
|
2008-11-16 21:56:45 +00:00
|
|
|
const aiFace& f = pMesh->mFaces[m];
|
2009-09-21 17:41:57 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < f.mNumIndices;++i) {
|
2008-11-16 21:56:45 +00:00
|
|
|
dirtyMask[f.mIndices[i]] = false;
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// Process vertex positions
|
2009-09-21 17:41:57 +00:00
|
|
|
if(pMesh->mVertices && ProcessArray(pMesh->mVertices,pMesh->mNumVertices,"positions",dirtyMask)) {
|
2008-10-13 16:45:48 +00:00
|
|
|
DefaultLogger::get()->error("Deleting mesh: Unable to continue without vertex positions");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// process texture coordinates
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS && pMesh->mTextureCoords[i];++i) {
|
|
|
|
if (ProcessArray(pMesh->mTextureCoords[i],pMesh->mNumVertices,"uvcoords",dirtyMask)) {
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
// delete all subsequent texture coordinate sets.
|
2009-09-21 17:41:57 +00:00
|
|
|
for (unsigned int a = i+1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) {
|
2008-10-13 16:45:48 +00:00
|
|
|
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.
|
2009-09-21 17:41:57 +00:00
|
|
|
if (pMesh->mNormals || pMesh->mTangents) {
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
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];
|
2009-01-12 22:06:54 +00:00
|
|
|
|
2009-09-21 17:41:57 +00:00
|
|
|
if (f.mNumIndices < 3) {
|
2009-01-12 22:06:54 +00:00
|
|
|
dirtyMask[f.mIndices[0]] = true;
|
2009-09-21 17:41:57 +00:00
|
|
|
|
|
|
|
if (f.mNumIndices == 2) {
|
2009-01-12 22:06:54 +00:00
|
|
|
dirtyMask[f.mIndices[1]] = true;
|
2009-09-21 17:41:57 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
2009-09-21 17:41:57 +00:00
|
|
|
if (pMesh->mTangents && ProcessArray(pMesh->mTangents,pMesh->mNumVertices,"tangents",dirtyMask)) {
|
2009-01-12 22:06:54 +00:00
|
|
|
delete[] pMesh->mBitangents; pMesh->mBitangents = NULL;
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Process mesh bitangents
|
2009-09-21 17:41:57 +00:00
|
|
|
if (pMesh->mBitangents && ProcessArray(pMesh->mBitangents,pMesh->mNumVertices,"bitangents",dirtyMask)) {
|
2009-01-12 22:06:54 +00:00
|
|
|
delete[] pMesh->mTangents; pMesh->mTangents = NULL;
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-10 10:22:24 +00:00
|
|
|
#endif // !! ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS
|