Fixed a bug in the validation step - animation channels weren't validated correctly in every case.

Further work on LWO materials, writes wrap amount to UV transform property now.
NFFLoader generates spherical UV coordinates now (for spheres and all platonic solids except hexahedrons)
Importer doesn't catch exceptions in debug builds.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@252 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2008-11-26 22:03:14 +00:00
parent 85a487f6b8
commit 9fc698bb2f
9 changed files with 93 additions and 68 deletions

View File

@ -548,43 +548,43 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
} }
} }
//if (pcIn->aTargetPositionKeys.size() > 1) if (pcIn->aTargetPositionKeys.size() > 1)
//{ {
// DefaultLogger::get()->debug("3DS: Converting target track ..."); DefaultLogger::get()->debug("3DS: Converting target track ...");
// // Camera or spot light - need to convert the separate // Camera or spot light - need to convert the separate
// // target position channel to our representation // target position channel to our representation
// TargetAnimationHelper helper; TargetAnimationHelper helper;
// if (pcIn->aPositionKeys.empty()) if (pcIn->aPositionKeys.empty())
// { {
// // We can just pass zero here ... // We can just pass zero here ...
// helper.SetFixedMainAnimationChannel(aiVector3D()); helper.SetFixedMainAnimationChannel(aiVector3D());
// } }
// else helper.SetMainAnimationChannel(&pcIn->aPositionKeys); else helper.SetMainAnimationChannel(&pcIn->aPositionKeys);
// helper.SetTargetAnimationChannel(&pcIn->aTargetPositionKeys); helper.SetTargetAnimationChannel(&pcIn->aTargetPositionKeys);
// // Do the conversion // Do the conversion
// std::vector<aiVectorKey> distanceTrack; std::vector<aiVectorKey> distanceTrack;
// helper.Process(&distanceTrack); helper.Process(&distanceTrack);
// // Now add a new node as child, name it <ourName>.Target // Now add a new node as child, name it <ourName>.Target
// // and assign the distance track to it. This is that the // and assign the distance track to it. This is that the
// // information where the target is and how it moves is // information where the target is and how it moves is
// // not lost // not lost
// D3DS::Node* nd = new D3DS::Node(); D3DS::Node* nd = new D3DS::Node();
// pcIn->push_back(nd); pcIn->push_back(nd);
// nd->mName = pcIn->mName + ".Target"; nd->mName = pcIn->mName + ".Target";
// aiNodeAnim* nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim(); aiNodeAnim* nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();
// nda->mNodeName.Set(nd->mName); nda->mNodeName.Set(nd->mName);
// nda->mNumPositionKeys = (unsigned int)distanceTrack.size(); nda->mNumPositionKeys = (unsigned int)distanceTrack.size();
// nda->mPositionKeys = new aiVectorKey[nda->mNumPositionKeys]; nda->mPositionKeys = new aiVectorKey[nda->mNumPositionKeys];
// ::memcpy(nda->mPositionKeys,&distanceTrack[0], ::memcpy(nda->mPositionKeys,&distanceTrack[0],
// sizeof(aiVectorKey)*nda->mNumPositionKeys); sizeof(aiVectorKey)*nda->mNumPositionKeys);
//} }
// Allocate a new nda, increment the nda index // Allocate a new nda, increment the nda index
aiNodeAnim* nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim(); aiNodeAnim* nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();

View File

@ -334,7 +334,6 @@ void ComputeUVMappingProcess::ComputePlaneMapping(aiMesh* mesh,aiAxis axis, aiVe
{ {
DefaultLogger::get()->error("Can't compute plane mapping, the mesh is " DefaultLogger::get()->error("Can't compute plane mapping, the mesh is "
"flat in the requested axis"); "flat in the requested axis");
return; return;
} }

View File

@ -129,7 +129,7 @@ private:
{ {
MappingInfo(aiTextureMapping _type) MappingInfo(aiTextureMapping _type)
: type (_type) : type (_type)
, axis (aiAxis_X) , axis (aiAxis_Y)
, uv (0u) , uv (0u)
{} {}

View File

@ -547,8 +547,10 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
// put a large try block around everything to catch all std::exception's // put a large try block around everything to catch all std::exception's
// that might be thrown by STL containers or by new(). // that might be thrown by STL containers or by new().
// ImportErrorException's are throw by ourselves and caught elsewhere. // ImportErrorException's are throw by ourselves and caught elsewhere.
#ifndef _DEBUG
try try
{ {
#endif
// check whether this Importer instance has already loaded // check whether this Importer instance has already loaded
// a scene. In this case we need to delete the old one // a scene. In this case we need to delete the old one
if (this->mScene) if (this->mScene)
@ -648,11 +650,11 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
// clear any data allocated by post-process steps // clear any data allocated by post-process steps
mPPShared->Clean(); mPPShared->Clean();
#ifndef _DEBUG
} }
catch (std::exception &e) catch (std::exception &e)
{ {
#if (defined _MSC_VER) && (defined _CPPRTTI) && (defined _DEBUG) #if (defined _MSC_VER) && (defined _CPPRTTI)
// if we have RTTI get the full name of the exception that occured // if we have RTTI get the full name of the exception that occured
mErrorString = std::string(typeid( e ).name()) + ": " + e.what(); mErrorString = std::string(typeid( e ).name()) + ": " + e.what();
@ -663,6 +665,7 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
DefaultLogger::get()->error(mErrorString); DefaultLogger::get()->error(mErrorString);
delete mScene;mScene = NULL; delete mScene;mScene = NULL;
} }
#endif
// either successful or failure - the pointer expresses it anyways // either successful or failure - the pointer expresses it anyways
return mScene; return mScene;

View File

@ -138,11 +138,19 @@ bool LWOImporter::HandleTextures(MaterialHelper* pcMat, const TextureList& in, a
if (mapping != aiTextureMapping_UV) if (mapping != aiTextureMapping_UV)
{ {
// Setup the main axis (the enum values map one to one) // Setup the main axis (the enum values map one to one)
ai_assert(aiAxis_X == Texture::AXIS_X);
pcMat->AddProperty<int>((int*)&(*it).majorAxis,1,AI_MATKEY_TEXMAP_AXIS(type,cur)); pcMat->AddProperty<int>((int*)&(*it).majorAxis,1,AI_MATKEY_TEXMAP_AXIS(type,cur));
// Setup UV scalings for cylindric and spherical projections
if (mapping == aiTextureMapping_CYLINDER || mapping == aiTextureMapping_SPHERE)
{
aiUVTransform trafo;
trafo.mScaling.x = (*it).wrapAmountW;
trafo.mScaling.y = (*it).wrapAmountH;
}
DefaultLogger::get()->debug("LWO2: Setting up non-UV mapping"); DefaultLogger::get()->debug("LWO2: Setting up non-UV mapping");
} }
// The older LWOB format does not use indirect references to clips. // The older LWOB format does not use indirect references to clips.
// The file name of a texture is directly specified in the tex chunk. // The file name of a texture is directly specified in the tex chunk.
if (mIsLWO2) if (mIsLWO2)

View File

@ -835,6 +835,11 @@ void NFFImporter::InternReadFile( const std::string& pFile,
currentMeshWithUVCoords->shader = s; currentMeshWithUVCoords->shader = s;
} }
} }
// 'shader' - other way to specify a texture
else if (TokenMatch(sz,"shader",6))
{
// todo
}
// 'l' - light source // 'l' - light source
else if (TokenMatch(sz,"l",1)) else if (TokenMatch(sz,"l",1))
{ {
@ -851,6 +856,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshesLocked.back(); MeshInfo& currentMesh = meshesLocked.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_SPHERE;
AI_NFF_PARSE_SHAPE_INFORMATION(); AI_NFF_PARSE_SHAPE_INFORMATION();
@ -867,6 +873,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshesLocked.back(); MeshInfo& currentMesh = meshesLocked.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_SPHERE;
AI_NFF_PARSE_SHAPE_INFORMATION(); AI_NFF_PARSE_SHAPE_INFORMATION();
@ -884,6 +891,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshesLocked.back(); MeshInfo& currentMesh = meshesLocked.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_SPHERE;
AI_NFF_PARSE_SHAPE_INFORMATION(); AI_NFF_PARSE_SHAPE_INFORMATION();
@ -901,6 +909,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshesLocked.back(); MeshInfo& currentMesh = meshesLocked.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_SPHERE;
AI_NFF_PARSE_SHAPE_INFORMATION(); AI_NFF_PARSE_SHAPE_INFORMATION();
@ -918,6 +927,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshesLocked.back(); MeshInfo& currentMesh = meshesLocked.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_SPHERE;
AI_NFF_PARSE_SHAPE_INFORMATION(); AI_NFF_PARSE_SHAPE_INFORMATION();
@ -934,6 +944,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
meshesLocked.push_back(MeshInfo(PatchType_Simple,true)); meshesLocked.push_back(MeshInfo(PatchType_Simple,true));
MeshInfo& currentMesh = meshes.back(); MeshInfo& currentMesh = meshes.back();
currentMesh.shader = s; currentMesh.shader = s;
s.mapping = aiTextureMapping_CYLINDER;
aiVector3D center1, center2; float radius1, radius2; aiVector3D center1, center2; float radius1, radius2;
AI_NFF_PARSE_TRIPLE(center1); AI_NFF_PARSE_TRIPLE(center1);
@ -1207,6 +1218,11 @@ void NFFImporter::InternReadFile( const std::string& pFile,
pcMat->AddProperty(&s,AI_MATKEY_NAME); pcMat->AddProperty(&s,AI_MATKEY_NAME);
} }
if (aiTextureMapping_UV != src.shader.mapping)
{
pcMat->AddProperty((int*)&src.shader.mapping, 1,AI_MATKEY_MAPPING_DIFFUSE(0));
}
// setup some more material properties that are specific to NFF2 // setup some more material properties that are specific to NFF2
int i; int i;
if (src.shader.twoSided) if (src.shader.twoSided)

View File

@ -109,6 +109,7 @@ private:
, shaded (true) // for NFF2 , shaded (true) // for NFF2
, opacity (1.f) , opacity (1.f)
, shininess (0.f) , shininess (0.f)
, mapping (aiTextureMapping_UV)
{} {}
aiColor3D color,diffuse,specular,ambient,emissive; aiColor3D color,diffuse,specular,ambient,emissive;
@ -123,6 +124,11 @@ private:
std::string name; std::string name;
// texture mapping to be generated for the mesh - uv is the default
// it means: use UV if there, nothing otherwise. This property is
// used for locked meshes.
aiTextureMapping mapping;
// shininess is ignored for the moment // shininess is ignored for the moment
bool operator == (const ShadingInfo& other) const bool operator == (const ShadingInfo& other) const
{ {

View File

@ -82,7 +82,7 @@ KeyIterator::KeyIterator(const std::vector<aiVectorKey>* _objPos,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <class T> template <class T>
T Interpolate(const T& one, const T& two, float val) inline T Interpolate(const T& one, const T& two, float val)
{ {
return one + (two-one)*val; return one + (two-one)*val;
} }
@ -93,19 +93,13 @@ void KeyIterator::operator ++()
// If we are already at the end of all keyframes, return // If we are already at the end of all keyframes, return
if (reachedEnd)return; if (reachedEnd)return;
int breakThisUglyStuff = 0;
// Now search in all arrays for the time value closest // Now search in all arrays for the time value closest
// to our current position on the time line // to our current position on the time line
double d0,d1; double d0,d1;
d0 = objPos->at(nextObjPos).mTime; d0 = objPos->at ( std::min ( nextObjPos, objPos->size()-1) ).mTime;
if (nextObjPos == objPos->size()-1) d1 = targetObjPos->at( std::min ( nextTargetObjPos, targetObjPos->size()-1) ).mTime;
++breakThisUglyStuff;
d1 = targetObjPos->at(nextTargetObjPos).mTime;
if (nextTargetObjPos == targetObjPos->size()-1)
++breakThisUglyStuff;
// Easiest case - all are identical. In this // Easiest case - all are identical. In this
// case we don't need to interpolate so we can // case we don't need to interpolate so we can
@ -116,11 +110,14 @@ void KeyIterator::operator ++()
curPosition = objPos->at(nextObjPos).mValue; curPosition = objPos->at(nextObjPos).mValue;
curTargetPosition = targetObjPos->at(nextTargetObjPos).mValue; curTargetPosition = targetObjPos->at(nextTargetObjPos).mValue;
// Increment all counters, regardless whether // increment counters
// the corresponding arrays are there if (objPos->size() != nextObjPos-1)
++nextObjPos; ++nextObjPos;
++nextTargetObjPos;
if (targetObjPos->size() != nextTargetObjPos-1)
++nextTargetObjPos;
} }
// An object position key is closest to us // An object position key is closest to us
else if (d0 < d1) else if (d0 < d1)
{ {
@ -140,12 +137,8 @@ void KeyIterator::operator ++()
(curTime-first.mTime) / (last.mTime-first.mTime) )); (curTime-first.mTime) / (last.mTime-first.mTime) ));
} }
// increment counters
if (objPos->size() != nextObjPos-1) if (objPos->size() != nextObjPos-1)
++nextObjPos; ++nextObjPos;
if (targetObjPos->size() != nextTargetObjPos-1)
++nextTargetObjPos;
} }
// A target position key is closest to us // A target position key is closest to us
else else
@ -165,9 +158,13 @@ void KeyIterator::operator ++()
curPosition = Interpolate(first.mValue, last.mValue, (float) ( curPosition = Interpolate(first.mValue, last.mValue, (float) (
(curTime-first.mTime) / (last.mTime-first.mTime))); (curTime-first.mTime) / (last.mTime-first.mTime)));
} }
if (targetObjPos->size() != nextTargetObjPos-1)
++nextTargetObjPos;
} }
if (2 == breakThisUglyStuff) if (nextObjPos >= objPos->size()-1 &&
nextTargetObjPos >= targetObjPos->size()-1)
{ {
// We reached the very last keyframe // We reached the very last keyframe
reachedEnd = true; reachedEnd = true;
@ -226,13 +223,7 @@ void TargetAnimationHelper::Process(std::vector<aiVectorKey>* distanceTrack)
// diff vector // diff vector
aiVector3D diff = tposition - position; aiVector3D diff = tposition - position;
float f = diff.SquareLength(); float f = diff.Length();
if (!f)
{
DefaultLogger::get()->error("Target position equals object position");
continue;
}
f = ::sqrt(f);
// output distance vector // output distance vector
if (fill) if (fill)
@ -243,6 +234,8 @@ void TargetAnimationHelper::Process(std::vector<aiVectorKey>* distanceTrack)
v.mValue = aiVector3D (0.f,0.f,f); v.mValue = aiVector3D (0.f,0.f,f);
} }
diff /= f; diff /= f;
// diff is now the vector in which our camera is pointing
} }
if (real.size()) if (real.size())

View File

@ -869,7 +869,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
this->ReportError("aiNodeAnim::mPositionKeys is NULL (aiNodeAnim::mNumPositionKeys is %i)", this->ReportError("aiNodeAnim::mPositionKeys is NULL (aiNodeAnim::mNumPositionKeys is %i)",
pNodeAnim->mNumPositionKeys); pNodeAnim->mNumPositionKeys);
} }
double dLast = -0.1; double dLast = -10e10;
for (unsigned int i = 0; i < pNodeAnim->mNumPositionKeys;++i) for (unsigned int i = 0; i < pNodeAnim->mNumPositionKeys;++i)
{ {
if (pNodeAnim->mPositionKeys[i].mTime > pAnimation->mDuration) if (pNodeAnim->mPositionKeys[i].mTime > pAnimation->mDuration)
@ -879,7 +879,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
(float)pNodeAnim->mPositionKeys[i].mTime, (float)pNodeAnim->mPositionKeys[i].mTime,
(float)pAnimation->mDuration); (float)pAnimation->mDuration);
} }
if (pNodeAnim->mPositionKeys[i].mTime <= dLast) if (i && pNodeAnim->mPositionKeys[i].mTime <= dLast)
{ {
ReportWarning("aiNodeAnim::mPositionKeys[%i].mTime (%.5f) is smaller " ReportWarning("aiNodeAnim::mPositionKeys[%i].mTime (%.5f) is smaller "
"than aiAnimation::mPositionKeys[%i] (which is %.5f)",i, "than aiAnimation::mPositionKeys[%i] (which is %.5f)",i,
@ -897,7 +897,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
this->ReportError("aiNodeAnim::mRotationKeys is NULL (aiNodeAnim::mNumRotationKeys is %i)", this->ReportError("aiNodeAnim::mRotationKeys is NULL (aiNodeAnim::mNumRotationKeys is %i)",
pNodeAnim->mNumRotationKeys); pNodeAnim->mNumRotationKeys);
} }
double dLast = -0.1; double dLast = -10e10;
for (unsigned int i = 0; i < pNodeAnim->mNumRotationKeys;++i) for (unsigned int i = 0; i < pNodeAnim->mNumRotationKeys;++i)
{ {
if (pNodeAnim->mRotationKeys[i].mTime > pAnimation->mDuration) if (pNodeAnim->mRotationKeys[i].mTime > pAnimation->mDuration)
@ -907,7 +907,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
(float)pNodeAnim->mRotationKeys[i].mTime, (float)pNodeAnim->mRotationKeys[i].mTime,
(float)pAnimation->mDuration); (float)pAnimation->mDuration);
} }
if (pNodeAnim->mRotationKeys[i].mTime <= dLast) if (i && pNodeAnim->mRotationKeys[i].mTime <= dLast)
{ {
ReportWarning("aiNodeAnim::mRotationKeys[%i].mTime (%.5f) is smaller " ReportWarning("aiNodeAnim::mRotationKeys[%i].mTime (%.5f) is smaller "
"than aiAnimation::mRotationKeys[%i] (which is %.5f)",i, "than aiAnimation::mRotationKeys[%i] (which is %.5f)",i,
@ -925,7 +925,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
this->ReportError("aiNodeAnim::mScalingKeys is NULL (aiNodeAnim::mNumScalingKeys is %i)", this->ReportError("aiNodeAnim::mScalingKeys is NULL (aiNodeAnim::mNumScalingKeys is %i)",
pNodeAnim->mNumScalingKeys); pNodeAnim->mNumScalingKeys);
} }
double dLast = -0.1; double dLast = -10e10;
for (unsigned int i = 0; i < pNodeAnim->mNumScalingKeys;++i) for (unsigned int i = 0; i < pNodeAnim->mNumScalingKeys;++i)
{ {
if (pNodeAnim->mScalingKeys[i].mTime > pAnimation->mDuration) if (pNodeAnim->mScalingKeys[i].mTime > pAnimation->mDuration)
@ -935,7 +935,7 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
(float)pNodeAnim->mScalingKeys[i].mTime, (float)pNodeAnim->mScalingKeys[i].mTime,
(float)pAnimation->mDuration); (float)pAnimation->mDuration);
} }
if (pNodeAnim->mScalingKeys[i].mTime <= dLast) if (i && pNodeAnim->mScalingKeys[i].mTime <= dLast)
{ {
ReportWarning("aiNodeAnim::mScalingKeys[%i].mTime (%.5f) is smaller " ReportWarning("aiNodeAnim::mScalingKeys[%i].mTime (%.5f) is smaller "
"than aiAnimation::mScalingKeys[%i] (which is %.5f)",i, "than aiAnimation::mScalingKeys[%i] (which is %.5f)",i,