- Bugfix: XFileLoader does not generate dummy bone arrays anymore. Had screwed HasBones()-Test in the viewer, making bone-less objects vanish from view

- made HasFooBar()-checks more precise on the way
- cleared up everyone's destructors to also delete arrays if the corresponding mNumFoo member was zero. This hopefully does not break all too much
- Bugfix: meshes without bones now properly show up with DisableMaterials enabled

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@230 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
ulfjorensen 2008-11-04 17:21:08 +00:00
parent 562050cf6d
commit 195d9a9cb1
5 changed files with 80 additions and 87 deletions

View File

@ -371,9 +371,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
// store the bones in the mesh // store the bones in the mesh
mesh->mNumBones = (unsigned int)newBones.size(); mesh->mNumBones = (unsigned int)newBones.size();
mesh->mBones = new aiBone*[mesh->mNumBones]; if( newBones.size() > 0)
for( unsigned int c = 0; c < newBones.size(); c++) {
mesh->mBones[c] = newBones[c]; mesh->mBones = new aiBone*[mesh->mNumBones];
std::copy( newBones.begin(), newBones.end(), mesh->mBones);
}
} }
} }

View File

@ -184,12 +184,9 @@ struct aiNodeAnim
~aiNodeAnim() ~aiNodeAnim()
{ {
if (mNumPositionKeys) delete [] mPositionKeys;
delete [] mPositionKeys; delete [] mRotationKeys;
if (mNumRotationKeys) delete [] mScalingKeys;
delete [] mRotationKeys;
if (mNumScalingKeys)
delete [] mScalingKeys;
} }
#endif // __cplusplus #endif // __cplusplus
}; };
@ -234,11 +231,10 @@ struct aiAnimation
~aiAnimation() ~aiAnimation()
{ {
if (mNumChannels) if (mNumChannels)
{
for( unsigned int a = 0; a < mNumChannels; a++) for( unsigned int a = 0; a < mNumChannels; a++)
delete mChannels[a]; delete mChannels[a];
delete [] mChannels;
} delete [] mChannels;
} }
#endif // __cplusplus #endif // __cplusplus
}; };

View File

@ -77,8 +77,7 @@ struct aiFace
//! Default destructor. Delete the index array //! Default destructor. Delete the index array
~aiFace() ~aiFace()
{ {
if (mNumIndices) delete [] mIndices;
delete [] mIndices;
} }
//! Copy constructor. Copy the index array //! Copy constructor. Copy the index array
@ -198,7 +197,7 @@ struct aiBone
//! Destructor - deletes the array of vertex weights //! Destructor - deletes the array of vertex weights
~aiBone() ~aiBone()
{ {
if (mNumWeights)delete [] mWeights; delete [] mWeights;
} }
#endif // __cplusplus #endif // __cplusplus
}; };
@ -439,50 +438,41 @@ struct aiMesh
//! Deletes all storage allocated for the mesh //! Deletes all storage allocated for the mesh
~aiMesh() ~aiMesh()
{ {
if ( mNumVertices ) // fix to make this work for invalid scenes, too delete [] mVertices;
{ delete [] mNormals;
delete [] mVertices; delete [] mTangents;
delete [] mNormals; delete [] mBitangents;
delete [] mTangents; for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++)
delete [] mBitangents; delete [] mTextureCoords[a];
for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++)
delete [] mTextureCoords[a]; delete [] mColors[a];
for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) for( unsigned int a = 0; a < mNumBones; a++)
delete [] mColors[a]; delete mBones[a];
} delete [] mBones;
if ( mNumBones && mBones) // fix to make this work for invalid scenes, too delete [] mFaces;
{
for( unsigned int a = 0; a < mNumBones; a++)
delete mBones[a];
delete [] mBones;
}
if ( mNumFaces) // fix to make this work for invalid scenes, too
{
delete [] mFaces;
}
} }
//! Check whether the mesh contains positions. If no special scene flags //! Check whether the mesh contains positions. If no special scene flags
//! (such as AI_SCENE_FLAGS_ANIM_SKELETON_ONLY) are set this MUST //! (such as AI_SCENE_FLAGS_ANIM_SKELETON_ONLY) are set this MUST
//! always return true //! always return true
inline bool HasPositions() const inline bool HasPositions() const
{ return mVertices != NULL; } { return mVertices != NULL && mNumVertices > 0; }
//! Check whether the mesh contains faces. If no special scene flags //! Check whether the mesh contains faces. If no special scene flags
//! are set this should always return true //! are set this should always return true
inline bool HasFaces() const inline bool HasFaces() const
{ return mFaces != NULL; } { return mFaces != NULL && mNumFaces > 0; }
//! Check whether the mesh contains normal vectors //! Check whether the mesh contains normal vectors
inline bool HasNormals() const inline bool HasNormals() const
{ return mNormals != NULL; } { return mNormals != NULL && mNumVertices > 0; }
//! Check whether the mesh contains tangent and bitangent vectors //! Check whether the mesh contains tangent and bitangent vectors
//! It is not possible that it contains tangents and no bitangents //! It is not possible that it contains tangents and no bitangents
//! (or the other way round). The existence of one of them //! (or the other way round). The existence of one of them
//! implies that the second is there, too. //! implies that the second is there, too.
inline bool HasTangentsAndBitangents() const inline bool HasTangentsAndBitangents() const
{ return mTangents != NULL && mBitangents != NULL; } { return mTangents != NULL && mBitangents != NULL && mNumVertices > 0; }
//! Check whether the mesh contains a vertex color set //! Check whether the mesh contains a vertex color set
//! \param pIndex Index of the vertex color set //! \param pIndex Index of the vertex color set
@ -491,7 +481,7 @@ struct aiMesh
if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS)
return false; return false;
else else
return mColors[pIndex] != NULL; return mColors[pIndex] != NULL && mNumVertices > 0;
} }
//! Check whether the mesh contains a texture coordinate set //! Check whether the mesh contains a texture coordinate set
@ -501,11 +491,11 @@ struct aiMesh
if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS)
return false; return false;
else else
return mTextureCoords[pIndex] != NULL; return mTextureCoords[pIndex] != NULL && mNumVertices > 0;
} }
//! Check whether the mesh contains bones //! Check whether the mesh contains bones
inline bool HasBones() const inline bool HasBones() const
{ return mBones != NULL; } { return mBones != NULL && mNumBones > 0; }
#endif // __cplusplus #endif // __cplusplus
}; };

View File

@ -121,8 +121,8 @@ struct aiNode
{ {
for( unsigned int a = 0; a < mNumChildren; a++) for( unsigned int a = 0; a < mNumChildren; a++)
delete mChildren[a]; delete mChildren[a];
delete [] mChildren;
} }
delete [] mChildren;
delete [] mMeshes; delete [] mMeshes;
} }
@ -317,68 +317,61 @@ struct aiScene
// mich better to check whether both mNumXXX and mXXX are // mich better to check whether both mNumXXX and mXXX are
// valid instead of relying on just one of them. // valid instead of relying on just one of them.
if (mNumMeshes && mMeshes) if (mNumMeshes && mMeshes)
{
for( unsigned int a = 0; a < mNumMeshes; a++) for( unsigned int a = 0; a < mNumMeshes; a++)
delete mMeshes[a]; delete mMeshes[a];
delete [] mMeshes; delete [] mMeshes;
}
if (mNumMaterials && mMaterials) if (mNumMaterials && mMaterials)
{
for( unsigned int a = 0; a < mNumMaterials; a++) for( unsigned int a = 0; a < mNumMaterials; a++)
delete mMaterials[a]; delete mMaterials[a];
delete [] mMaterials; delete [] mMaterials;
}
if (mNumAnimations && mAnimations) if (mNumAnimations && mAnimations)
{
for( unsigned int a = 0; a < mNumAnimations; a++) for( unsigned int a = 0; a < mNumAnimations; a++)
delete mAnimations[a]; delete mAnimations[a];
delete [] mAnimations; delete [] mAnimations;
}
if (mNumTextures && mTextures) if (mNumTextures && mTextures)
{
for( unsigned int a = 0; a < mNumTextures; a++) for( unsigned int a = 0; a < mNumTextures; a++)
delete mTextures[a]; delete mTextures[a];
delete [] mTextures; delete [] mTextures;
}
if (mNumLights && mLights) if (mNumLights && mLights)
{
for( unsigned int a = 0; a < mNumLights; a++) for( unsigned int a = 0; a < mNumLights; a++)
delete mLights[a]; delete mLights[a];
delete [] mLights; delete [] mLights;
}
if (mNumCameras && mCameras) if (mNumCameras && mCameras)
{
for( unsigned int a = 0; a < mNumCameras; a++) for( unsigned int a = 0; a < mNumCameras; a++)
delete mCameras[a]; delete mCameras[a];
delete [] mCameras; delete [] mCameras;
}
} }
//! Check whether the scene contains meshes //! Check whether the scene contains meshes
//! Unless no special scene flags are set this will always be true. //! Unless no special scene flags are set this will always be true.
inline bool HasMeshes() const inline bool HasMeshes() const
{ return mMeshes != NULL; } { return mMeshes != NULL && mNumMeshes > 0; }
//! Check whether the scene contains materials //! Check whether the scene contains materials
//! Unless no special scene flags are set this will always be true. //! Unless no special scene flags are set this will always be true.
inline bool HasMaterials() const inline bool HasMaterials() const
{ return mMaterials != NULL; } { return mMaterials != NULL && mNumMaterials > 0; }
//! Check whether the scene contains lights //! Check whether the scene contains lights
inline bool HasLights() const inline bool HasLights() const
{ return mLights != NULL; } { return mLights != NULL && mNumLights > 0; }
//! Check whether the scene contains textures //! Check whether the scene contains textures
inline bool HasTextures() const inline bool HasTextures() const
{ return mTextures != NULL; } { return mTextures != NULL && mNumTextures > 0; }
//! Check whether the scene contains cameras //! Check whether the scene contains cameras
inline bool HasCameras() const inline bool HasCameras() const
{ return mCameras != NULL; } { return mCameras != NULL && mNumCameras > 0; }
//! Check whether the scene contains animations //! Check whether the scene contains animations
inline bool HasAnimations() const inline bool HasAnimations() const
{ return mAnimations != NULL; } { return mAnimations != NULL && mNumAnimations > 0; }
#endif // __cplusplus #endif // __cplusplus
}; };

View File

@ -1972,29 +1972,41 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
else if (bAlpha)continue; else if (bAlpha)continue;
// Upload bone matrices. This maybe is the wrong place to do it, but for the heck of it I don't understand this code flow // Upload bone matrices. This maybe is the wrong place to do it, but for the heck of it I don't understand this code flow
if( mesh->HasBones() && helper->piEffect) if( mesh->HasBones())
{ {
static float matrices[4*4*60]; if( helper->piEffect)
float* tempmat = matrices;
const std::vector<aiMatrix4x4>& boneMats = g_pcAsset->mAnimator->GetBoneMatrices( piNode, i);
ai_assert( boneMats.size() == mesh->mNumBones);
for( unsigned int a = 0; a < mesh->mNumBones; a++)
{ {
const aiMatrix4x4& mat = boneMats[a]; static float matrices[4*4*60];
*tempmat++ = mat.a1; *tempmat++ = mat.a2; *tempmat++ = mat.a3; *tempmat++ = mat.a4; float* tempmat = matrices;
*tempmat++ = mat.b1; *tempmat++ = mat.b2; *tempmat++ = mat.b3; *tempmat++ = mat.b4; const std::vector<aiMatrix4x4>& boneMats = g_pcAsset->mAnimator->GetBoneMatrices( piNode, i);
*tempmat++ = mat.c1; *tempmat++ = mat.c2; *tempmat++ = mat.c3; *tempmat++ = mat.c4; ai_assert( boneMats.size() == mesh->mNumBones);
*tempmat++ = mat.d1; *tempmat++ = mat.d2; *tempmat++ = mat.d3; *tempmat++ = mat.d4;
//tempmat += 4; for( unsigned int a = 0; a < mesh->mNumBones; a++)
{
const aiMatrix4x4& mat = boneMats[a];
*tempmat++ = mat.a1; *tempmat++ = mat.a2; *tempmat++ = mat.a3; *tempmat++ = mat.a4;
*tempmat++ = mat.b1; *tempmat++ = mat.b2; *tempmat++ = mat.b3; *tempmat++ = mat.b4;
*tempmat++ = mat.c1; *tempmat++ = mat.c2; *tempmat++ = mat.c3; *tempmat++ = mat.c4;
*tempmat++ = mat.d1; *tempmat++ = mat.d2; *tempmat++ = mat.d3; *tempmat++ = mat.d4;
//tempmat += 4;
}
if( g_sOptions.bRenderMats)
{
helper->piEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
} else
{
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
g_piDefaultEffect->CommitChanges();
}
} }
} else
if( g_sOptions.bRenderMats) {
// upload identity matrices instead. Only the first is ever going to be used in meshes without bones
if( !g_sOptions.bRenderMats)
{ {
helper->piEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60); D3DXMATRIX identity( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
} else g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", &identity, 1);
{
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
g_piDefaultEffect->CommitChanges(); g_piDefaultEffect->CommitChanges();
} }
} }