* Temporary fix for the MemoryDataHolder

This commit is contained in:
shlainn 2011-10-27 23:38:24 +02:00
parent bc09fcf3d2
commit d58622352b
3 changed files with 31 additions and 40 deletions

View File

@ -21,7 +21,15 @@ CM2MeshFileLoader::~CM2MeshFileLoader()
} }
core::vector3df fixCoordSystem(core::vector3df v)
{
return core::vector3df(v.X, v.Z, v.Y);
}
core::quaternion fixQuaternion(core::quaternion q)
{
return core::quaternion(q.X, q.Z, q.Y, q.W);
}
bool CM2MeshFileLoader::isALoadableFileExtension(const c8* filename)const bool CM2MeshFileLoader::isALoadableFileExtension(const c8* filename)const
{ {
return strstr(filename, ".m2")!=0; return strstr(filename, ".m2")!=0;
@ -58,12 +66,13 @@ void CM2MeshFileLoader::ReadVertices()
M2MVertices.clear(); M2MVertices.clear();
ModelVertex tempM2MVert; ModelVertex tempM2MVert;
f32 tempYZ;
MeshFile->seek(header.ofsVertices); MeshFile->seek(header.ofsVertices);
for(u32 i =0;i<header.nVertices;i++) for(u32 i =0;i<header.nVertices;i++)
{ {
MeshFile->read(&tempM2MVert,sizeof(ModelVertex)); MeshFile->read(&tempM2MVert,sizeof(ModelVertex));
tempM2MVert.pos = fixCoordSystem(tempM2MVert.pos);
tempM2MVert.normal = fixCoordSystem(tempM2MVert.normal);
M2MVertices.push_back(tempM2MVert); M2MVertices.push_back(tempM2MVert);
} }
DEBUG(logdebug("Read %u/%u Vertices",M2MVertices.size(),header.nVertices)); DEBUG(logdebug("Read %u/%u Vertices",M2MVertices.size(),header.nVertices));
@ -205,42 +214,16 @@ for(u32 i=0;i<header.nBones;i++)
MeshFile->read(&tempBone.rotation.header,sizeof(AnimBlockHead)); MeshFile->read(&tempBone.rotation.header,sizeof(AnimBlockHead));
MeshFile->read(&tempBone.scaling.header,sizeof(AnimBlockHead)); MeshFile->read(&tempBone.scaling.header,sizeof(AnimBlockHead));
MeshFile->read(&tempBone.PivotPoint,sizeof(core::vector3df)); MeshFile->read(&tempBone.PivotPoint,sizeof(core::vector3df));
tempBone.PivotPoint=fixCoordSystem(tempBone.PivotPoint);
M2MBones.push_back(tempBone); M2MBones.push_back(tempBone);
DEBUG(logdebug("Bone %u Parent %u PP %f %f %f",i,tempBone.parentBone,tempBone.PivotPoint.X,tempBone.PivotPoint.Y,tempBone.PivotPoint.Z)); DEBUG(logdebug("Bone %u Parent %u PP %f %f %f",i,tempBone.parentBone,tempBone.PivotPoint.X,tempBone.PivotPoint.Y,tempBone.PivotPoint.Z));
} }
//Fill in values referenced in Bones. local to each bone //Fill in values referenced in Bones. local to each bone
InterpolationRange tempBoneIR; //Interpolation Ranges are not used
u32 tempBoneTS; u32 tempBoneTS;
float tempBoneValue; float tempBoneValue;
for(u32 i=0; i<M2MBones.size(); i++) for(u32 i=0; i<M2MBones.size(); i++)
{ {
if(M2MBones[i].translation.header.nInterpolationRange>0)
{
MeshFile->seek(M2MBones[i].translation.header.ofsInterpolationRange);
for(u32 j=0; j<M2MBones[i].translation.header.nInterpolationRange;j++)
{
MeshFile->read(&tempBoneIR, sizeof(InterpolationRange));
M2MBones[i].translation.keyframes.push_back(tempBoneIR);
}
}
if(M2MBones[i].rotation.header.nInterpolationRange>0)
{
MeshFile->seek(M2MBones[i].rotation.header.ofsInterpolationRange);
for(u32 j=0; j<M2MBones[i].rotation.header.nInterpolationRange;j++)
{
MeshFile->read(&tempBoneIR, sizeof(InterpolationRange));
M2MBones[i].rotation.keyframes.push_back(tempBoneIR);
}
}
if(M2MBones[i].scaling.header.nInterpolationRange>0)
{
MeshFile->seek(M2MBones[i].scaling.header.ofsInterpolationRange);
for(u32 j=0; j<M2MBones[i].scaling.header.nInterpolationRange;j++)
{
MeshFile->read(&tempBoneIR, sizeof(InterpolationRange));
M2MBones[i].scaling.keyframes.push_back(tempBoneIR);
}
}
if(M2MBones[i].translation.header.nTimeStamp>0) if(M2MBones[i].translation.header.nTimeStamp>0)
{ {
@ -282,12 +265,20 @@ for(u32 i=0; i<M2MBones.size(); i++)
{ {
MeshFile->seek(M2MBones[i].rotation.header.ofsValues); MeshFile->seek(M2MBones[i].rotation.header.ofsValues);
for(u32 j=0; j<M2MBones[i].rotation.header.nValues*4;j++) for(u32 j=0; j<M2MBones[i].rotation.header.nValues*4;j++)
{
if(header.version>=0x104)
{ {
s16 tempBoneShort; s16 tempBoneShort;
MeshFile->read(&tempBoneShort, sizeof(s16)); MeshFile->read(&tempBoneShort, sizeof(s16));
tempBoneValue=(tempBoneShort>0?tempBoneShort-32767:tempBoneShort+32767)/32767.0f; tempBoneValue=(tempBoneShort>0?tempBoneShort-32767:tempBoneShort+32767)/32767.0f;
M2MBones[i].rotation.values.push_back(tempBoneValue); M2MBones[i].rotation.values.push_back(tempBoneValue);
} }
else
{
MeshFile->read(&tempBoneValue, sizeof(f32));
M2MBones[i].rotation.values.push_back(tempBoneValue);
}
}
} }
if(M2MBones[i].scaling.header.nValues>0) if(M2MBones[i].scaling.header.nValues>0)
{ {
@ -435,7 +426,7 @@ for(u32 i=0;i<M2MBones.size();i++)
{ {
scene::CM2Mesh::SPositionKey* pos=AnimatedMesh->createPositionKey(Joint); scene::CM2Mesh::SPositionKey* pos=AnimatedMesh->createPositionKey(Joint);
pos->frame=M2MBones[i].translation.timestamps[j]; pos->frame=M2MBones[i].translation.timestamps[j];
pos->position=core::vector3df(M2MBones[i].translation.values[j*3],M2MBones[i].translation.values[j*3+1],M2MBones[i].translation.values[j*3+2]); pos->position=fixCoordSystem(core::vector3df(M2MBones[i].translation.values[j*3],M2MBones[i].translation.values[j*3+1],M2MBones[i].translation.values[j*3+2]));
} }
} }
if(M2MBones[i].rotation.header.nValues>0) if(M2MBones[i].rotation.header.nValues>0)
@ -444,7 +435,8 @@ for(u32 i=0;i<M2MBones.size();i++)
{ {
scene::CM2Mesh::SRotationKey* rot=AnimatedMesh->createRotationKey(Joint); scene::CM2Mesh::SRotationKey* rot=AnimatedMesh->createRotationKey(Joint);
rot->frame=M2MBones[i].rotation.timestamps[j]; rot->frame=M2MBones[i].rotation.timestamps[j];
core::quaternion tempQ=core::quaternion(-M2MBones[i].rotation.values[j*4+0],-M2MBones[i].rotation.values[j*4+1],-M2MBones[i].rotation.values[j*4+2],M2MBones[i].rotation.values[j*4+3]); core::quaternion tempQ=core::quaternion(M2MBones[i].rotation.values[j*4+0],M2MBones[i].rotation.values[j*4+1],M2MBones[i].rotation.values[j*4+2],M2MBones[i].rotation.values[j*4+3]);
tempQ = fixQuaternion(tempQ);
tempQ.normalize(); tempQ.normalize();
rot->rotation=tempQ; rot->rotation=tempQ;
} }
@ -544,9 +536,9 @@ for(u32 i=0; i < currentView.nSub;i++)//
MeshBuffer->getMaterial().BackfaceCulling=(M2MRenderFlags[M2MTextureUnit[j].renderFlagsIndex].flags & 0x04)?false:true; MeshBuffer->getMaterial().BackfaceCulling=(M2MRenderFlags[M2MTextureUnit[j].renderFlagsIndex].flags & 0x04)?false:true;
switch(M2MRenderFlags[M2MTextureUnit[j].renderFlagsIndex].blending) switch(M2MRenderFlags[M2MTextureUnit[j].renderFlagsIndex].blending)
{ {
case 1: case 1://This
case 2: case 2://be
case 4: case 4://HACK
MeshBuffer->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL; MeshBuffer->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
DEBUG(logdebug("Alpha Channel Transparency on")); DEBUG(logdebug("Alpha Channel Transparency on"));
break; break;
@ -562,7 +554,7 @@ for(u32 i=0; i < currentView.nSub;i++)//
MeshBuffer->setHardwareMappingHint(EHM_STREAM); MeshBuffer->setHardwareMappingHint(EHM_STREAM);
} }
Device->getSceneManager()->getMeshManipulator()->flipSurfaces(AnimatedMesh);
// SkinFile->drop(); // SkinFile->drop();
M2MTriangles.clear(); M2MTriangles.clear();

View File

@ -32,7 +32,7 @@ namespace MemoryDataHolder
void Shutdown(void) void Shutdown(void)
{ {
//ZThread::Guard<ZThread::FastMutex> g(mutex); //ZThread::Guard<ZThread::FastMutex> g(mutex);
logdev("MDH: Interrupting work..."); // logdev("MDH: Interrupting work..."); //@ FG: This line was causing segfaults
executor->cancel(); // stop accepting new threads executor->cancel(); // stop accepting new threads
executor->interrupt(); // interrupt all working threads executor->interrupt(); // interrupt all working threads
// executor will delete itself automatically // executor will delete itself automatically

View File

@ -206,7 +206,6 @@ void loadModel(const c8* fn)
Model->setMaterialFlag(video::EMF_LIGHTING, true); Model->setMaterialFlag(video::EMF_LIGHTING, true);
// Model->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); // Model->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
Model->setDebugDataVisible(scene::EDS_OFF); Model->setDebugDataVisible(scene::EDS_OFF);
Model->setRotation(core::vector3df(-90,0,0));
// we need to uncheck the menu entries. would be cool to fake a menu event, but // we need to uncheck the menu entries. would be cool to fake a menu event, but
// that's not so simple. so we do it brute force // that's not so simple. so we do it brute force
for(int id = GUI_ID_DEBUG_BOUNDING_BOX; id <= GUI_ID_DEBUG_WIRE_OVERLAY; ++id) for(int id = GUI_ID_DEBUG_BOUNDING_BOX; id <= GUI_ID_DEBUG_WIRE_OVERLAY; ++id)
@ -219,7 +218,7 @@ void loadModel(const c8* fn)
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText(L"1.0"); toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText(L"1.0");
} }
FILE* f = fopen("./viewer_last.txt","w"); FILE* f = fopen("viewer_last.txt","w");
fwrite(filename.c_str(),1,filename.size(),f); fwrite(filename.c_str(),1,filename.size(),f);
fclose(f); fclose(f);
@ -647,7 +646,7 @@ int main(int argc, char* argv[])
MemoryDataHolder::SetUseMPQ("enUS"); MemoryDataHolder::SetUseMPQ("enUS");
FILE* f; FILE* f;
f = fopen("./viewer_last.txt","r"); f = fopen("viewer_last.txt","r");
if(f!=NULL) if(f!=NULL)
{ {
log("Loading last used mesh"); log("Loading last used mesh");