Fixed 3ds support for normal maps.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1256 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
913ef64b5e
commit
d570b0d356
|
@ -10,6 +10,8 @@
|
|||
#include "SMeshBuffer.h"
|
||||
#include "SAnimatedMesh.h"
|
||||
#include "IReadFile.h"
|
||||
#include "IVideoDriver.h"
|
||||
#include "IMeshManipulator.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -38,6 +40,8 @@ const u16 C3DS_MATSPECULAR = 0xA030;
|
|||
const u16 C3DS_MATSHININESS = 0xA040;
|
||||
const u16 C3DS_MATSHIN2PCT = 0xA041;
|
||||
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_WIRE = 0xA085;
|
||||
const u16 C3DS_SHADING = 0xA100;
|
||||
|
@ -102,20 +106,16 @@ const u16 C3DS_PERCENTAGE_F = 0x0031;
|
|||
|
||||
|
||||
//! Constructor
|
||||
C3DSMeshFileLoader::C3DSMeshFileLoader(IMeshManipulator* manip,io::IFileSystem* fs, video::IVideoDriver* driver)
|
||||
: FileSystem(fs), Driver(driver), Vertices(0), Indices(0), SmoothingGroups(0), TCoords(0),
|
||||
CountVertices(0), CountFaces(0), CountTCoords(0), Mesh(0), Manipulator(manip)
|
||||
C3DSMeshFileLoader::C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs)
|
||||
: SceneManager(smgr), FileSystem(fs), Vertices(0), Indices(0), SmoothingGroups(0), TCoords(0),
|
||||
CountVertices(0), CountFaces(0), CountTCoords(0), Mesh(0)
|
||||
{
|
||||
TransformationMatrix.makeIdentity();
|
||||
if (FileSystem)
|
||||
FileSystem->grab();
|
||||
|
||||
if (Driver)
|
||||
Driver->grab();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! destructor
|
||||
C3DSMeshFileLoader::~C3DSMeshFileLoader()
|
||||
{
|
||||
|
@ -124,15 +124,11 @@ C3DSMeshFileLoader::~C3DSMeshFileLoader()
|
|||
if (FileSystem)
|
||||
FileSystem->drop();
|
||||
|
||||
if (Driver)
|
||||
Driver->drop();
|
||||
|
||||
if (Mesh)
|
||||
Mesh->drop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! returns true if the file maybe is able to be loaded by this class
|
||||
//! based on the file extension (e.g. ".bsp")
|
||||
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.
|
||||
//! \return Pointer to the created mesh. Returns 0 if loading failed.
|
||||
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
|
||||
|
@ -181,7 +176,17 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file)
|
|||
mb->drop();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
|
@ -387,10 +392,22 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren
|
|||
case C3DS_MATBUMPMAP:
|
||||
{
|
||||
matSection=data.header.id;
|
||||
#if 0 // Should contain a percentage chunk, but does not work with the meshes
|
||||
f32 percentage=0;
|
||||
if (matSection!=C3DS_MATREFLMAP)
|
||||
readPercentageChunk(file, &data, percentage);
|
||||
#if 1 // Should contain a percentage chunk, but does not work with the meshes
|
||||
switch (matSection)
|
||||
{
|
||||
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
|
||||
}
|
||||
break;
|
||||
|
@ -928,7 +945,7 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc&
|
|||
video::SMaterial* mat=0;
|
||||
u32 mbPos;
|
||||
// -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
|
||||
for (mbPos=0; mbPos<Materials.size(); ++mbPos)
|
||||
|
@ -1050,13 +1067,13 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
|
|||
m->getMaterial() = Materials[i].Material;
|
||||
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)
|
||||
{
|
||||
core::stringc fname = getTextureFileName(
|
||||
Materials[i].Filename[0], modelFilename);
|
||||
if (fname.size())
|
||||
texture = Driver->getTexture(fname.c_str());
|
||||
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
|
||||
}
|
||||
|
||||
if (!texture)
|
||||
|
@ -1068,14 +1085,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
|
|||
|
||||
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)
|
||||
{
|
||||
core::stringc fname = getTextureFileName(
|
||||
Materials[i].Filename[2], modelFilename);
|
||||
if (fname.size())
|
||||
texture = Driver->getTexture(fname.c_str());
|
||||
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
|
||||
}
|
||||
|
||||
if (!texture)
|
||||
|
@ -1092,14 +1109,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
|
|||
|
||||
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)
|
||||
{
|
||||
core::stringc fname = getTextureFileName(
|
||||
Materials[i].Filename[3], modelFilename);
|
||||
if (fname.size())
|
||||
texture = Driver->getTexture(fname.c_str());
|
||||
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
|
||||
}
|
||||
|
||||
if (!texture)
|
||||
|
@ -1117,14 +1134,14 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
|
|||
|
||||
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)
|
||||
{
|
||||
core::stringc fname = getTextureFileName(
|
||||
Materials[i].Filename[4], modelFilename);
|
||||
if (fname.size())
|
||||
texture = Driver->getTexture(fname.c_str());
|
||||
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
|
||||
}
|
||||
|
||||
if (!texture)
|
||||
|
@ -1133,9 +1150,9 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
|
|||
else
|
||||
{
|
||||
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().MaterialTypeParam=0.035f;
|
||||
m->getMaterial().MaterialTypeParam=.035f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
#include "IMeshLoader.h"
|
||||
#include "IFileSystem.h"
|
||||
#include "IVideoDriver.h"
|
||||
#include "ISceneManager.h"
|
||||
#include "irrString.h"
|
||||
#include "SMesh.h"
|
||||
#include "IMeshManipulator.h"
|
||||
#include "matrix4.h"
|
||||
|
||||
namespace irr
|
||||
|
@ -24,7 +23,7 @@ class C3DSMeshFileLoader : public IMeshLoader
|
|||
public:
|
||||
|
||||
//! Constructor
|
||||
C3DSMeshFileLoader(IMeshManipulator* manip,io::IFileSystem* fs, video::IVideoDriver* driver);
|
||||
C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs);
|
||||
|
||||
//! destructor
|
||||
virtual ~C3DSMeshFileLoader();
|
||||
|
@ -84,11 +83,17 @@ private:
|
|||
Filename[2]="";
|
||||
Filename[3]="";
|
||||
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;
|
||||
core::stringc Name;
|
||||
core::stringc Filename[5];
|
||||
f32 Strength[5];
|
||||
};
|
||||
|
||||
struct SMaterialGroup
|
||||
|
@ -147,8 +152,8 @@ private:
|
|||
void cleanUp();
|
||||
core::stringc getTextureFileName(const core::stringc& texture, core::stringc& model);
|
||||
|
||||
scene::ISceneManager* SceneManager;
|
||||
io::IFileSystem* FileSystem;
|
||||
video::IVideoDriver* Driver;
|
||||
|
||||
f32* Vertices;
|
||||
u16* Indices;
|
||||
|
@ -166,8 +171,6 @@ private:
|
|||
core::matrix4 TransformationMatrix;
|
||||
|
||||
SMesh* Mesh;
|
||||
|
||||
IMeshManipulator* Manipulator;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
|
|
@ -204,7 +204,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
|
|||
MeshLoaderList.push_back(new CMS3DMeshFileLoader(Driver));
|
||||
#endif
|
||||
#ifdef _IRR_COMPILE_WITH_3DS_LOADER_
|
||||
MeshLoaderList.push_back(new C3DSMeshFileLoader(MeshManipulator,FileSystem, Driver));
|
||||
MeshLoaderList.push_back(new C3DSMeshFileLoader(this, FileSystem));
|
||||
#endif
|
||||
#ifdef _IRR_COMPILE_WITH_X_LOADER_
|
||||
MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem));
|
||||
|
|
Loading…
Reference in New Issue