Commit 3d46ce96 authored by hybrid's avatar hybrid

Reenabled the vertex alpha mode if fx&32 set, as necessary for the terrain blending from xDan.

Changed texture loading order to original place, mesh directory, working directory.
Replaced file handling method by FileSystem versions. Changed readString to use a reference instead of return by value.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2475 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ba3024f0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "CB3DMeshFileLoader.h" #include "CB3DMeshFileLoader.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "IFileSystem.h"
#include "os.h" #include "os.h"
#ifdef _DEBUG #ifdef _DEBUG
...@@ -153,10 +154,11 @@ bool CB3DMeshFileLoader::load() ...@@ -153,10 +154,11 @@ bool CB3DMeshFileLoader::load()
bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *InJoint) bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *InJoint)
{ {
const core::stringc JointName = readString(); CSkinnedMesh::SJoint *Joint = AnimatedMesh->createJoint(InJoint);
readString(Joint->Name);
#ifdef _B3D_READER_DEBUG #ifdef _B3D_READER_DEBUG
os::Printer::log("read ChunkNODE", JointName.c_str()); os::Printer::log("read ChunkNODE", Joint->Name.c_str());
#endif #endif
f32 position[3], scale[3], rotation[4]; f32 position[3], scale[3], rotation[4];
...@@ -165,9 +167,6 @@ bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *InJoint) ...@@ -165,9 +167,6 @@ bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *InJoint)
readFloats(scale, 3); readFloats(scale, 3);
readFloats(rotation, 4); readFloats(rotation, 4);
CSkinnedMesh::SJoint *Joint = AnimatedMesh->createJoint(InJoint);
Joint->Name = JointName;
Joint->Animatedposition = core::vector3df(position[0],position[1],position[2]) ; Joint->Animatedposition = core::vector3df(position[0],position[1],position[2]) ;
Joint->Animatedscale = core::vector3df(scale[0],scale[1],scale[2]); Joint->Animatedscale = core::vector3df(scale[0],scale[1],scale[2]);
Joint->Animatedrotation = core::quaternion(rotation[1], rotation[2], rotation[3], rotation[0]); Joint->Animatedrotation = core::quaternion(rotation[1], rotation[2], rotation[3], rotation[0]);
...@@ -508,7 +507,7 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 M ...@@ -508,7 +507,7 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 M
if (B3dMaterial) if (B3dMaterial)
{ {
// Apply Material/Colour/etc... // Apply Material/Color/etc...
video::S3DVertex *Vertex=MeshBuffer->getVertex(MeshBuffer->getVertexCount()-1); video::S3DVertex *Vertex=MeshBuffer->getVertex(MeshBuffer->getVertexCount()-1);
if (Vertex->Color.getAlpha() == 255) if (Vertex->Color.getAlpha() == 255)
...@@ -672,8 +671,7 @@ bool CB3DMeshFileLoader::readChunkTEXS() ...@@ -672,8 +671,7 @@ bool CB3DMeshFileLoader::readChunkTEXS()
Textures.push_back(SB3dTexture()); Textures.push_back(SB3dTexture());
SB3dTexture& B3dTexture = Textures.getLast(); SB3dTexture& B3dTexture = Textures.getLast();
B3dTexture.TextureName=readString(); readString(B3dTexture.TextureName);
B3dTexture.TextureName=stripPathFromString(B3DFile->getFileName(),true) + stripPathFromString(B3dTexture.TextureName,false);
#ifdef _B3D_READER_DEBUG #ifdef _B3D_READER_DEBUG
os::Printer::log("read Texture", B3dTexture.TextureName.c_str()); os::Printer::log("read Texture", B3dTexture.TextureName.c_str());
#endif #endif
...@@ -722,7 +720,8 @@ bool CB3DMeshFileLoader::readChunkBRUS() ...@@ -722,7 +720,8 @@ bool CB3DMeshFileLoader::readChunkBRUS()
{ {
// This is what blitz basic calls a brush, like a Irrlicht Material // This is what blitz basic calls a brush, like a Irrlicht Material
readString(); //name core::stringc name;
readString(name);
#ifdef _B3D_READER_DEBUG #ifdef _B3D_READER_DEBUG
os::Printer::log("read Material"); os::Printer::log("read Material");
#endif #endif
...@@ -878,11 +877,11 @@ bool CB3DMeshFileLoader::readChunkBRUS() ...@@ -878,11 +877,11 @@ bool CB3DMeshFileLoader::readChunkBRUS()
if (B3dMaterial.fx & 16) //disable backface culling if (B3dMaterial.fx & 16) //disable backface culling
B3dMaterial.Material.BackfaceCulling = false; B3dMaterial.Material.BackfaceCulling = false;
// if (B3dMaterial.fx & 32) //force vertex alpha-blending if (B3dMaterial.fx & 32) //force vertex alpha-blending
// { {
// B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
// B3dMaterial.Material.ZWriteEnable = false; B3dMaterial.Material.ZWriteEnable = false;
// } }
B3dMaterial.Material.Shininess = B3dMaterial.shininess; B3dMaterial.Material.Shininess = B3dMaterial.shininess;
} }
...@@ -909,7 +908,18 @@ void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const ...@@ -909,7 +908,18 @@ void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const
{ {
if (!SceneManager->getParameters()->getAttributeAsBool(B3D_LOADER_IGNORE_MIPMAP_FLAG)) if (!SceneManager->getParameters()->getAttributeAsBool(B3D_LOADER_IGNORE_MIPMAP_FLAG))
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, (B3dTexture->Flags & 0x8) ? true:false); SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, (B3dTexture->Flags & 0x8) ? true:false);
material.Material.setTexture(i, SceneManager->getVideoDriver()->getTexture( B3dTexture->TextureName )); {
video::ITexture* tex = 0;
io::IFileSystem* fs = SceneManager->getFileSystem();
if (fs->existFile(B3dTexture->TextureName))
tex = SceneManager->getVideoDriver()->getTexture(B3dTexture->TextureName);
else if (fs->existFile(fs->getFileDir(B3DFile->getFileName()) + fs->getFileBasename(B3dTexture->TextureName)))
tex = SceneManager->getVideoDriver()->getTexture(fs->getFileDir(B3DFile->getFileName()) + fs->getFileBasename(B3dTexture->TextureName));
else
tex = SceneManager->getVideoDriver()->getTexture(fs->getFileBasename(B3dTexture->TextureName));
material.Material.setTexture(i, tex);
}
if (material.Textures[i]->Flags & 0x10) // Clamp U if (material.Textures[i]->Flags & 0x10) // Clamp U
material.Material.TextureLayer[i].TextureWrap=video::ETC_CLAMP; material.Material.TextureLayer[i].TextureWrap=video::ETC_CLAMP;
if (material.Textures[i]->Flags & 0x20) // Clamp V if (material.Textures[i]->Flags & 0x20) // Clamp V
...@@ -922,42 +932,20 @@ void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const ...@@ -922,42 +932,20 @@ void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const
} }
core::stringc CB3DMeshFileLoader::readString() void CB3DMeshFileLoader::readString(core::stringc& newstring)
{ {
core::stringc newstring; newstring="";
while (B3DFile->getPos() <= B3DFile->getSize()) while (B3DFile->getPos() <= B3DFile->getSize())
{ {
c8 character; c8 character;
B3DFile->read(&character, sizeof(character)); B3DFile->read(&character, sizeof(character));
if (character==0) if (character==0)
break; return;
newstring.append(character); newstring.append(character);
} }
return newstring;
} }
core::stringc CB3DMeshFileLoader::stripPathFromString(const core::stringc& string, bool returnPath) const
{
s32 slashIndex=string.findLast('/'); // forward slash
s32 backSlash=string.findLast('\\'); // back slash
if (backSlash>slashIndex) slashIndex=backSlash;
if (slashIndex==-1)//no slashes found
{
if (returnPath)
return core::stringc(); //no path to return
else
return string;
}
if (returnPath)
return string.subString(0, slashIndex + 1);
else
return string.subString(slashIndex+1, string.size() - (slashIndex+1));
}
void CB3DMeshFileLoader::readFloats(f32* vec, u32 count) void CB3DMeshFileLoader::readFloats(f32* vec, u32 count)
{ {
B3DFile->read(vec, count*sizeof(f32)); B3DFile->read(vec, count*sizeof(f32));
......
...@@ -105,8 +105,7 @@ private: ...@@ -105,8 +105,7 @@ private:
void loadTextures(SB3dMaterial& material) const; void loadTextures(SB3dMaterial& material) const;
core::stringc readString(); void readString(core::stringc& newstring);
core::stringc stripPathFromString(const core::stringc& string, bool returnPath=false) const;
void readFloats(f32* vec, u32 count); void readFloats(f32* vec, u32 count);
core::array<SB3dChunk> B3dStack; core::array<SB3dChunk> B3dStack;
......
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