Commit d570b0d3 authored by hybrid's avatar hybrid

Fixed 3ds support for normal maps.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1256 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 913ef64b
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "SMeshBuffer.h" #include "SMeshBuffer.h"
#include "SAnimatedMesh.h" #include "SAnimatedMesh.h"
#include "IReadFile.h" #include "IReadFile.h"
#include "IVideoDriver.h"
#include "IMeshManipulator.h"
namespace irr namespace irr
{ {
...@@ -38,6 +40,8 @@ const u16 C3DS_MATSPECULAR = 0xA030; ...@@ -38,6 +40,8 @@ const u16 C3DS_MATSPECULAR = 0xA030;
const u16 C3DS_MATSHININESS = 0xA040; const u16 C3DS_MATSHININESS = 0xA040;
const u16 C3DS_MATSHIN2PCT = 0xA041; const u16 C3DS_MATSHIN2PCT = 0xA041;
const u16 C3DS_TRANSPARENCY = 0xA050; const u16 C3DS_TRANSPARENCY = 0xA050;
const u16 C3DS_TRANSPARENCY_FALLOFF = 0xA052;
const u16 C3DS_REFL_BLUR = 0xA053;
const u16 C3DS_TWO_SIDE = 0xA081; const u16 C3DS_TWO_SIDE = 0xA081;
const u16 C3DS_WIRE = 0xA085; const u16 C3DS_WIRE = 0xA085;
const u16 C3DS_SHADING = 0xA100; const u16 C3DS_SHADING = 0xA100;
...@@ -102,20 +106,16 @@ const u16 C3DS_PERCENTAGE_F = 0x0031; ...@@ -102,20 +106,16 @@ const u16 C3DS_PERCENTAGE_F = 0x0031;
//! Constructor //! Constructor
C3DSMeshFileLoader::C3DSMeshFileLoader(IMeshManipulator* manip,io::IFileSystem* fs, video::IVideoDriver* driver) C3DSMeshFileLoader::C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs)
: FileSystem(fs), Driver(driver), Vertices(0), Indices(0), SmoothingGroups(0), TCoords(0), : SceneManager(smgr), FileSystem(fs), Vertices(0), Indices(0), SmoothingGroups(0), TCoords(0),
CountVertices(0), CountFaces(0), CountTCoords(0), Mesh(0), Manipulator(manip) CountVertices(0), CountFaces(0), CountTCoords(0), Mesh(0)
{ {
TransformationMatrix.makeIdentity(); TransformationMatrix.makeIdentity();
if (FileSystem) if (FileSystem)
FileSystem->grab(); FileSystem->grab();
if (Driver)
Driver->grab();
} }
//! destructor //! destructor
C3DSMeshFileLoader::~C3DSMeshFileLoader() C3DSMeshFileLoader::~C3DSMeshFileLoader()
{ {
...@@ -124,15 +124,11 @@ C3DSMeshFileLoader::~C3DSMeshFileLoader() ...@@ -124,15 +124,11 @@ C3DSMeshFileLoader::~C3DSMeshFileLoader()
if (FileSystem) if (FileSystem)
FileSystem->drop(); FileSystem->drop();
if (Driver)
Driver->drop();
if (Mesh) if (Mesh)
Mesh->drop(); Mesh->drop();
} }
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp") //! based on the file extension (e.g. ".bsp")
bool C3DSMeshFileLoader::isALoadableFileExtension(const c8* filename) const bool C3DSMeshFileLoader::isALoadableFileExtension(const c8* filename) const
...@@ -141,7 +137,6 @@ bool C3DSMeshFileLoader::isALoadableFileExtension(const c8* filename) const ...@@ -141,7 +137,6 @@ bool C3DSMeshFileLoader::isALoadableFileExtension(const c8* filename) const
} }
//! creates/loads an animated mesh from the file. //! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed. //! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). //! If you no longer need the mesh, you should call IAnimatedMesh::drop().
...@@ -181,7 +176,17 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -181,7 +176,17 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file)
mb->drop(); mb->drop();
} }
else else
{
mb->recalculateBoundingBox(); mb->recalculateBoundingBox();
if (mb->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID)
{
SMesh tmp;
tmp.addMeshBuffer(mb);
IMesh* tangentMesh = SceneManager->getMeshManipulator()->createMeshWithTangents(&tmp);
mb->drop();
Mesh->MeshBuffers[i]=tangentMesh->getMeshBuffer(0);
}
}
} }
Mesh->recalculateBoundingBox(); Mesh->recalculateBoundingBox();
...@@ -387,10 +392,22 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren ...@@ -387,10 +392,22 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren
case C3DS_MATBUMPMAP: case C3DS_MATBUMPMAP:
{ {
matSection=data.header.id; matSection=data.header.id;
#if 0 // Should contain a percentage chunk, but does not work with the meshes #if 1 // Should contain a percentage chunk, but does not work with the meshes
f32 percentage=0; switch (matSection)
if (matSection!=C3DS_MATREFLMAP) {
readPercentageChunk(file, &data, percentage); case C3DS_MATTEXMAP:
readPercentageChunk(file, &data, CurrentMaterial.Strength[0]);
break;
case C3DS_MATSPECMAP:
readPercentageChunk(file, &data, CurrentMaterial.Strength[1]);
break;
case C3DS_MATOPACMAP:
readPercentageChunk(file, &data, CurrentMaterial.Strength[2]);
break;
case C3DS_MATBUMPMAP:
readPercentageChunk(file, &data, CurrentMaterial.Strength[4]);
break;
}
#endif #endif
} }
break; break;
...@@ -928,7 +945,7 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc& ...@@ -928,7 +945,7 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc&
video::SMaterial* mat=0; video::SMaterial* mat=0;
u32 mbPos; u32 mbPos;
// -3 because we add three vertices at once // -3 because we add three vertices at once
u32 maxPrimitives = core::min_(Driver->getMaximalPrimitiveCount(), (u32)((1<<16)-1))-3; // currently hardcoded s16 max value for index pointers u32 maxPrimitives = core::min_(SceneManager->getVideoDriver()->getMaximalPrimitiveCount(), (u32)((1<<16)-1))-3; // currently hardcoded s16 max value for index pointers
// find mesh buffer for this group // find mesh buffer for this group
for (mbPos=0; mbPos<Materials.size(); ++mbPos) for (mbPos=0; mbPos<Materials.size(); ++mbPos)
...@@ -1050,13 +1067,13 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1050,13 +1067,13 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
m->getMaterial() = Materials[i].Material; m->getMaterial() = Materials[i].Material;
if (Materials[i].Filename[0].size()) if (Materials[i].Filename[0].size())
{ {
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[0].c_str()); video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[0].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( core::stringc fname = getTextureFileName(
Materials[i].Filename[0], modelFilename); Materials[i].Filename[0], modelFilename);
if (fname.size()) if (fname.size())
texture = Driver->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
...@@ -1068,14 +1085,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1068,14 +1085,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[2].size()) if (Materials[i].Filename[2].size())
{ {
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[2].c_str()); video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[2].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( core::stringc fname = getTextureFileName(
Materials[i].Filename[2], modelFilename); Materials[i].Filename[2], modelFilename);
if (fname.size()) if (fname.size())
texture = Driver->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
...@@ -1092,14 +1109,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1092,14 +1109,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[3].size()) if (Materials[i].Filename[3].size())
{ {
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[3].c_str()); video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[3].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( core::stringc fname = getTextureFileName(
Materials[i].Filename[3], modelFilename); Materials[i].Filename[3], modelFilename);
if (fname.size()) if (fname.size())
texture = Driver->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
...@@ -1117,14 +1134,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1117,14 +1134,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[4].size()) if (Materials[i].Filename[4].size())
{ {
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[4].c_str()); video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[4].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( core::stringc fname = getTextureFileName(
Materials[i].Filename[4], modelFilename); Materials[i].Filename[4], modelFilename);
if (fname.size()) if (fname.size())
texture = Driver->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
...@@ -1133,9 +1150,9 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1133,9 +1150,9 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
else else
{ {
m->getMaterial().setTexture(1, texture); m->getMaterial().setTexture(1, texture);
Driver->makeNormalMapTexture(texture, 9.0f); SceneManager->getVideoDriver()->makeNormalMapTexture(texture, Materials[i].Strength[4]);
m->getMaterial().MaterialType=video::EMT_PARALLAX_MAP_SOLID; m->getMaterial().MaterialType=video::EMT_PARALLAX_MAP_SOLID;
m->getMaterial().MaterialTypeParam=0.035f; m->getMaterial().MaterialTypeParam=.035f;
} }
} }
......
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
#include "IMeshLoader.h" #include "IMeshLoader.h"
#include "IFileSystem.h" #include "IFileSystem.h"
#include "IVideoDriver.h" #include "ISceneManager.h"
#include "irrString.h" #include "irrString.h"
#include "SMesh.h" #include "SMesh.h"
#include "IMeshManipulator.h"
#include "matrix4.h" #include "matrix4.h"
namespace irr namespace irr
...@@ -24,7 +23,7 @@ class C3DSMeshFileLoader : public IMeshLoader ...@@ -24,7 +23,7 @@ class C3DSMeshFileLoader : public IMeshLoader
public: public:
//! Constructor //! Constructor
C3DSMeshFileLoader(IMeshManipulator* manip,io::IFileSystem* fs, video::IVideoDriver* driver); C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs);
//! destructor //! destructor
virtual ~C3DSMeshFileLoader(); virtual ~C3DSMeshFileLoader();
...@@ -84,11 +83,17 @@ private: ...@@ -84,11 +83,17 @@ private:
Filename[2]=""; Filename[2]="";
Filename[3]=""; Filename[3]="";
Filename[4]=""; Filename[4]="";
Strength[0]=0.f;
Strength[1]=0.f;
Strength[2]=0.f;
Strength[3]=0.f;
Strength[4]=0.f;
} }
video::SMaterial Material; video::SMaterial Material;
core::stringc Name; core::stringc Name;
core::stringc Filename[5]; core::stringc Filename[5];
f32 Strength[5];
}; };
struct SMaterialGroup struct SMaterialGroup
...@@ -147,8 +152,8 @@ private: ...@@ -147,8 +152,8 @@ private:
void cleanUp(); void cleanUp();
core::stringc getTextureFileName(const core::stringc& texture, core::stringc& model); core::stringc getTextureFileName(const core::stringc& texture, core::stringc& model);
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem; io::IFileSystem* FileSystem;
video::IVideoDriver* Driver;
f32* Vertices; f32* Vertices;
u16* Indices; u16* Indices;
...@@ -166,8 +171,6 @@ private: ...@@ -166,8 +171,6 @@ private:
core::matrix4 TransformationMatrix; core::matrix4 TransformationMatrix;
SMesh* Mesh; SMesh* Mesh;
IMeshManipulator* Manipulator;
}; };
} // end namespace scene } // end namespace scene
......
...@@ -204,7 +204,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, ...@@ -204,7 +204,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
MeshLoaderList.push_back(new CMS3DMeshFileLoader(Driver)); MeshLoaderList.push_back(new CMS3DMeshFileLoader(Driver));
#endif #endif
#ifdef _IRR_COMPILE_WITH_3DS_LOADER_ #ifdef _IRR_COMPILE_WITH_3DS_LOADER_
MeshLoaderList.push_back(new C3DSMeshFileLoader(MeshManipulator,FileSystem, Driver)); MeshLoaderList.push_back(new C3DSMeshFileLoader(this, FileSystem));
#endif #endif
#ifdef _IRR_COMPILE_WITH_X_LOADER_ #ifdef _IRR_COMPILE_WITH_X_LOADER_
MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem)); MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem));
......
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