Fixed crashes when loading character models (hopefully)

This commit is contained in:
shlainn 2008-04-06 12:19:43 +00:00
parent 9d330665f3
commit 50e83549ee
3 changed files with 14 additions and 10 deletions

View File

@ -8,7 +8,7 @@ namespace irr
namespace scene
{
CM2MeshFileLoader::CM2MeshFileLoader(IrrlichtDevice* device, c8* basedir):Device(device), Basedir(basedir)
CM2MeshFileLoader::CM2MeshFileLoader(IrrlichtDevice* device, c8* texdir):Device(device), Texdir(texdir)
{
}
@ -248,9 +248,10 @@ IMB->recalculateBoundingBox();
//IMB->getMaterial().DiffuseColor.set(255,(M2MSubmeshes[i].meshpartId==0?0:255),(M2MSubmeshes[i].meshpartId==0?255:0),0);
std::string TexName=Basedir.c_str();
std::string TexName=Texdir.c_str();
TexName+="/";
TexName+=M2MTextureFiles[M2MTextureUnit[i].textureIndex].c_str();
if(i<M2MTextureUnit.size())
TexName+=M2MTextureFiles[M2MTextureUnit[i].textureIndex].c_str();
while(TexName.find('\\')<TexName.size())//Replace \ by /
{
@ -263,10 +264,13 @@ while(TexName.find(' ')<TexName.size())//Replace space by _
std::transform(TexName.begin(), TexName.end(), TexName.begin(), tolower);
IMB->getMaterial().setTexture(0,Device->getVideoDriver()->getTexture(TexName.c_str()));
std::cout<<M2MRenderFlags[i].flags<<"--"<<M2MRenderFlags[i].blending<<"\n";
IMB->getMaterial().BackfaceCulling=(M2MRenderFlags[i].flags & 0x04)?false:true;
if(M2MRenderFlags[i].blending==1)
IMB->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
if(i<M2MRenderFlags.size())
{
std::cout<<M2MRenderFlags[i].flags<<"--"<<M2MRenderFlags[i].blending<<"\n";
IMB->getMaterial().BackfaceCulling=(M2MRenderFlags[i].flags & 0x04)?false:true;
if(M2MRenderFlags[i].blending==1)
IMB->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
}
Mesh->addMeshBuffer(IMB);
IMB->drop();
//std::cout << "Mesh now has "<<Mesh->getMeshBufferCount()<<" Buffers\n";

View File

@ -105,7 +105,7 @@ class CM2MeshFileLoader : public IMeshLoader
public:
//! Constructor
CM2MeshFileLoader(IrrlichtDevice* device, c8* basedir);
CM2MeshFileLoader(IrrlichtDevice* device, c8* texdir);
//! destructor
virtual ~CM2MeshFileLoader();
@ -175,7 +175,7 @@ struct RenderFlags{
IrrlichtDevice* Device;
// scene::IMeshManipulator* Manipulator;
core::stringc M2MeshName;
core::stringc Basedir;
core::stringc Texdir;
SAnimatedMesh* aniMesh;
SMesh* Mesh;
SMeshBuffer* IMB;

View File

@ -121,7 +121,7 @@ void PseuGUI::_Init(void)
//...
// register external loaders for not supported filetypes
scene::CM2MeshFileLoader* m2loader = new scene::CM2MeshFileLoader(_device, "data");
scene::CM2MeshFileLoader* m2loader = new scene::CM2MeshFileLoader(_device, "./data/textures");
_smgr->addExternalMeshLoader(m2loader);
_initialized = true;