- 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
mesh->mNumBones = (unsigned int)newBones.size();
mesh->mBones = new aiBone*[mesh->mNumBones];
for( unsigned int c = 0; c < newBones.size(); c++)
mesh->mBones[c] = newBones[c];
if( newBones.size() > 0)
{
mesh->mBones = new aiBone*[mesh->mNumBones];
std::copy( newBones.begin(), newBones.end(), mesh->mBones);
}
}
}

View File

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

View File

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

View File

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

View File

@ -1972,29 +1972,41 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
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
if( mesh->HasBones() && helper->piEffect)
if( mesh->HasBones())
{
static float matrices[4*4*60];
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++)
if( helper->piEffect)
{
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;
static float matrices[4*4*60];
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];
*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();
}
}
if( g_sOptions.bRenderMats)
} else
{
// 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);
} else
{
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
D3DXMATRIX identity( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", &identity, 1);
g_piDefaultEffect->CommitChanges();
}
}