Commit fee87ba4 authored by irrlicht's avatar irrlicht

removed a bug which caused irrlicht to crash when using animated .x files as static meshes

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@706 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 401a1e10
...@@ -121,6 +121,8 @@ Changes in version 1.3.1 (?? Mar 2007) ...@@ -121,6 +121,8 @@ Changes in version 1.3.1 (?? Mar 2007)
deserializing the scene node. deserializing the scene node.
- Removed an array::erase from Octtrees and Octtree triangle selector. - Removed an array::erase from Octtrees and Octtree triangle selector.
- Removed a bug which caused irrlicht to crash when using animated .x files as static meshes.
GUI: GUI:
......
...@@ -24,6 +24,7 @@ CXAnimationPlayer::CXAnimationPlayer(CXFileReader* reader, ...@@ -24,6 +24,7 @@ CXAnimationPlayer::CXAnimationPlayer(CXFileReader* reader,
CurrentAnimationTime(-1.0f), LastAnimationTime(1.0f), CurrentAnimationTime(-1.0f), LastAnimationTime(1.0f),
CurrentAnimationSet(0), DebugSkeletonCrossSize(1.0f) CurrentAnimationSet(0), DebugSkeletonCrossSize(1.0f)
{ {
OriginalMesh = new scene::SMesh();
if (!Reader) if (!Reader)
return; return;
...@@ -44,6 +45,8 @@ CXAnimationPlayer::CXAnimationPlayer(CXFileReader* reader, ...@@ -44,6 +45,8 @@ CXAnimationPlayer::CXAnimationPlayer(CXFileReader* reader,
//! destructor //! destructor
CXAnimationPlayer::~CXAnimationPlayer() CXAnimationPlayer::~CXAnimationPlayer()
{ {
OriginalMesh->drop();
if (Reader) if (Reader)
Reader->drop(); Reader->drop();
...@@ -71,7 +74,7 @@ s32 CXAnimationPlayer::getFrameCount() ...@@ -71,7 +74,7 @@ s32 CXAnimationPlayer::getFrameCount()
IMesh* CXAnimationPlayer::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop) IMesh* CXAnimationPlayer::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop)
{ {
if (!IsAnimatedSkinnedMesh) if (!IsAnimatedSkinnedMesh)
return &OriginalMesh; return OriginalMesh;
if (CurrentAnimationTime != (f32)frame) if (CurrentAnimationTime != (f32)frame)
{ {
...@@ -122,7 +125,7 @@ void CXAnimationPlayer::createAnimationData() ...@@ -122,7 +125,7 @@ void CXAnimationPlayer::createAnimationData()
DebugSkeletonCrossSize = AnimatedMesh->getBoundingBox().getExtent().X / 20.0f; DebugSkeletonCrossSize = AnimatedMesh->getBoundingBox().getExtent().X / 20.0f;
} }
else else
DebugSkeletonCrossSize = OriginalMesh.getBoundingBox().getExtent().X / 20.0f; DebugSkeletonCrossSize = OriginalMesh->getBoundingBox().getExtent().X / 20.0f;
} }
} }
...@@ -138,17 +141,17 @@ void CXAnimationPlayer::createMeshData() ...@@ -138,17 +141,17 @@ void CXAnimationPlayer::createMeshData()
addFrameToMesh(pgRootFrames[i]); addFrameToMesh(pgRootFrames[i]);
// recalculate box // recalculate box
OriginalMesh.recalculateBoundingBox(); OriginalMesh->recalculateBoundingBox();
// store box (fix by jox, thnx) // store box (fix by jox, thnx)
Box = OriginalMesh.getBoundingBox(); Box = OriginalMesh->getBoundingBox();
// sort weights in joints // sort weights in joints
for (s32 j=0; j<(s32)Joints.size(); ++j) for (s32 j=0; j<(s32)Joints.size(); ++j)
Joints[j].Weights.sort(); Joints[j].Weights.sort();
// copy mesh // copy mesh
AnimatedMesh = Manipulator->createMeshCopy(&OriginalMesh); AnimatedMesh = Manipulator->createMeshCopy(OriginalMesh);
// create and link animation data // create and link animation data
prepareAnimationData(); prepareAnimationData();
...@@ -173,7 +176,7 @@ void CXAnimationPlayer::addFrameToMesh(CXFileReader::SXFrame& frame) ...@@ -173,7 +176,7 @@ void CXAnimationPlayer::addFrameToMesh(CXFileReader::SXFrame& frame)
{ {
// create buffer // create buffer
SMeshBuffer *buf = new SMeshBuffer(); SMeshBuffer *buf = new SMeshBuffer();
OriginalMesh.addMeshBuffer(buf); OriginalMesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
// new weights buffer // new weights buffer
...@@ -184,7 +187,7 @@ void CXAnimationPlayer::addFrameToMesh(CXFileReader::SXFrame& frame) ...@@ -184,7 +187,7 @@ void CXAnimationPlayer::addFrameToMesh(CXFileReader::SXFrame& frame)
frame.Meshes[m].MaterialList.Materials[mt]); frame.Meshes[m].MaterialList.Materials[mt]);
// add all faces of this material // add all faces of this material
addFacesToBuffer(OriginalMesh.MeshBuffers.size()-1, addFacesToBuffer(OriginalMesh->MeshBuffers.size()-1,
frame.Meshes[m], mt, frame); frame.Meshes[m], mt, frame);
buf->recalculateBoundingBox(); buf->recalculateBoundingBox();
} }
...@@ -219,7 +222,7 @@ video::SMaterial CXAnimationPlayer::getMaterialFromXMaterial(const CXFileReader: ...@@ -219,7 +222,7 @@ video::SMaterial CXAnimationPlayer::getMaterialFromXMaterial(const CXFileReader:
void CXAnimationPlayer::addFacesToBuffer(s32 meshbuffernr, CXFileReader::SXMesh& mesh, s32 matnr, const CXFileReader::SXFrame& frame) void CXAnimationPlayer::addFacesToBuffer(s32 meshbuffernr, CXFileReader::SXMesh& mesh, s32 matnr, const CXFileReader::SXFrame& frame)
{ {
scene::SMeshBuffer* buf = (SMeshBuffer*)OriginalMesh.MeshBuffers[meshbuffernr]; scene::SMeshBuffer* buf = (SMeshBuffer*)OriginalMesh->MeshBuffers[meshbuffernr];
u32 tcnt = mesh.TextureCoords.size(); u32 tcnt = mesh.TextureCoords.size();
u32 ncnt = mesh.Normals.size(); u32 ncnt = mesh.Normals.size();
...@@ -659,7 +662,7 @@ void CXAnimationPlayer::modifySkin() ...@@ -659,7 +662,7 @@ void CXAnimationPlayer::modifySkin()
for (u32 mb=0; mb<AnimatedMesh->getMeshBufferCount(); ++mb) for (u32 mb=0; mb<AnimatedMesh->getMeshBufferCount(); ++mb)
{ {
video::S3DVertex* av = (video::S3DVertex*)AnimatedMesh->getMeshBuffer(mb)->getVertices(); video::S3DVertex* av = (video::S3DVertex*)AnimatedMesh->getMeshBuffer(mb)->getVertices();
video::S3DVertex* ov = (video::S3DVertex*)OriginalMesh.getMeshBuffer(mb)->getVertices(); video::S3DVertex* ov = (video::S3DVertex*)OriginalMesh->getMeshBuffer(mb)->getVertices();
const u32 c = AnimatedMesh->getMeshBuffer(mb)->getVertexCount(); const u32 c = AnimatedMesh->getMeshBuffer(mb)->getVertexCount();
for (u32 vt=0; vt<c; ++vt) for (u32 vt=0; vt<c; ++vt)
{ {
......
...@@ -163,7 +163,7 @@ namespace scene ...@@ -163,7 +163,7 @@ namespace scene
CXFileReader* Reader; CXFileReader* Reader;
video::IVideoDriver* Driver; video::IVideoDriver* Driver;
scene::SMesh OriginalMesh; scene::SMesh *OriginalMesh;
scene::SMesh *AnimatedMesh; scene::SMesh *AnimatedMesh;
core::aabbox3df Box; core::aabbox3df Box;
core::stringc FileName; core::stringc FileName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment