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

View File

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

View File

@ -77,7 +77,6 @@ struct aiFace
//! Default destructor. Delete the index array
~aiFace()
{
if (mNumIndices)
delete [] mIndices;
}
@ -198,7 +197,7 @@ struct aiBone
//! Destructor - deletes the array of vertex weights
~aiBone()
{
if (mNumWeights)delete [] mWeights;
delete [] mWeights;
}
#endif // __cplusplus
};
@ -438,8 +437,6 @@ 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;
@ -449,40 +446,33 @@ struct aiMesh
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;
}
}
//! 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;
}
if (mNumMaterials && mMaterials)
{
for( unsigned int a = 0; a < mNumMaterials; a++)
delete mMaterials[a];
delete [] mMaterials;
}
if (mNumAnimations && mAnimations)
{
for( unsigned int a = 0; a < mNumAnimations; a++)
delete mAnimations[a];
delete [] mAnimations;
}
if (mNumTextures && mTextures)
{
for( unsigned int a = 0; a < mNumTextures; a++)
delete mTextures[a];
delete [] mTextures;
}
if (mNumLights && mLights)
{
for( unsigned int a = 0; a < mNumLights; a++)
delete mLights[a];
delete [] mLights;
}
if (mNumCameras && mCameras)
{
for( unsigned int a = 0; a < mNumCameras; a++)
delete mCameras[a];
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,7 +1972,9 @@ 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())
{
if( helper->piEffect)
{
static float matrices[4*4*60];
float* tempmat = matrices;
@ -1998,6 +2000,16 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
g_piDefaultEffect->CommitChanges();
}
}
} else
{
// upload identity matrices instead. Only the first is ever going to be used in meshes without bones
if( !g_sOptions.bRenderMats)
{
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();
}
}
// now setup the material
if (g_sOptions.bRenderMats)