Further work on the IRR and IRRMESH loaders. IRR is still WIP, IRRMESH loads lightmaps correctly now.

Added lightmap viewing support to the viewer. Irrlicht's tone scaling is hardcoded for the moment, a proper implementation will follow with the new viewer.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@232 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2008-11-05 12:26:11 +00:00
parent 7c50899481
commit df9f4130eb
7 changed files with 234 additions and 18 deletions

View File

@@ -191,7 +191,9 @@ void ColorFromARGBPacked(uint32_t in, aiColor4D& clr)
int ConvertMappingMode(const std::string& mode)
{
if (mode == "texture_clamp_repeat")
{
return aiTextureMapMode_Wrap;
}
else if (mode == "texture_clamp_mirror")
return aiTextureMapMode_Mirror;
@@ -206,7 +208,8 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
aiColor4D clr;
aiString s;
matFlags = 0;
matFlags = 0; // zero output flags
int cnt = 0; // number of used texture channels
// Continue reading from the file
while (reader->read())
@@ -274,8 +277,6 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
{
StringProperty prop;
ReadStringProperty(prop);
int cnt = 0;
if (prop.value.length())
{
// material type (shader)
@@ -289,6 +290,10 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
{
matFlags = AI_IRRMESH_MAT_lightmap;
}
else if (prop.value == "solid_2layer")
{
matFlags = AI_IRRMESH_MAT_solid_2layer;
}
else if (prop.value == "lightmap_m2")
{
matFlags = AI_IRRMESH_MAT_lightmap_m2;
@@ -297,32 +302,90 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
{
matFlags = AI_IRRMESH_MAT_lightmap_m4;
}
else if (prop.value == "lightmap_light")
{
matFlags = AI_IRRMESH_MAT_lightmap_light;
}
else if (prop.value == "lightmap_light_m2")
{
matFlags = AI_IRRMESH_MAT_lightmap_light_m2;
}
else if (prop.value == "lightmap_light_m4")
{
matFlags = AI_IRRMESH_MAT_lightmap_light_m4;
}
else if (prop.value == "lightmap_add")
{
matFlags = AI_IRRMESH_MAT_lightmap_add;
}
// Normal and parallax maps are treated equally
else if (prop.value == "normalmap_solid" ||
prop.value == "parallaxmap_solid")
{
matFlags = AI_IRRMESH_MAT_normalmap_solid;
}
else if (prop.value == "normalmap_trans_vertex_alpha" ||
prop.value == "parallaxmap_trans_vertex_alpha")
{
matFlags = AI_IRRMESH_MAT_normalmap_tva;
}
else if (prop.value == "normalmap_trans_add" ||
prop.value == "parallaxmap_trans_add")
{
matFlags = AI_IRRMESH_MAT_normalmap_ta;
}
}
// Up to 4 texture channels are supported
else if (prop.name == "Texture1")
{
// Always accept the primary texture channel
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
}
else if (prop.name == "Texture2")
{
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(1));
// 2-layer material lightmapped?
if (matFlags & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap))
{
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(1));
// set the corresponding material flag
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
}
// alternatively: normal or parallax mapping
else if (matFlags & AI_IRRMESH_MAT_normalmap_solid)
{
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_NORMALS(1));
// set the corresponding material flag
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
}
}
else if (prop.name == "Texture3")
{
// We don't process the third texture channel as Irrlicht
// does not seem to use it.
#if 0
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(2));
#endif
}
else if (prop.name == "Texture4" )
{
// We don't process the fourth texture channel as Irrlicht
// does not seem to use it.
#if 0
++cnt;
s.Set(prop.value);
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(3));
#endif
}
// Texture mapping options
@@ -360,6 +423,47 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
if (/* IRRMESH */ !ASSIMP_stricmp(reader->getNodeName(),"material") ||
/* IRR */ !ASSIMP_stricmp(reader->getNodeName(),"attributes"))
{
// Now process lightmapping flags
// We should have at least one texture, however
// if there are multiple textures we assign the
// lightmap settings to the last texture.
if (cnt && matFlags & AI_IRRMESH_MAT_lightmap)
{
static const char* PropArray[4] =
{
AI_MATKEY_TEXBLEND_DIFFUSE(0),
AI_MATKEY_TEXBLEND_DIFFUSE(1),
AI_MATKEY_TEXBLEND_DIFFUSE(2),
AI_MATKEY_TEXBLEND_DIFFUSE(3)
};
static const char* PropArray2[4] =
{
AI_MATKEY_TEXOP_DIFFUSE(0),
AI_MATKEY_TEXOP_DIFFUSE(1),
AI_MATKEY_TEXOP_DIFFUSE(2),
AI_MATKEY_TEXOP_DIFFUSE(3)
};
float f = 1.f;
// Additive lightmap?
int op = (matFlags & AI_IRRMESH_MAT_lightmap_add
? aiTextureOp_Add : aiTextureOp_Multiply);
// Handle Irrlicht's lightmapping scaling factor
if (matFlags & AI_IRRMESH_MAT_lightmap_m2 ||
matFlags & AI_IRRMESH_MAT_lightmap_light_m2)
{
f = 2.f;
}
else if (matFlags & AI_IRRMESH_MAT_lightmap_m4 ||
matFlags & AI_IRRMESH_MAT_lightmap_light_m4)
{
f = 4.f;
}
mat->AddProperty( &f, 1, PropArray [cnt-1]);
mat->AddProperty( &op,1, PropArray2 [cnt-1]);
}
return mat;
}
default:
@@ -514,6 +618,27 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
{
curUV2s.reserve (num);
vertexFormat = 1;
if (curMatFlags & AI_IRRMESH_EXTRA_2ND_TEXTURE)
{
// *********************************************************
// We have a second texture! So use this UV channel
// for it. The 2nd texture can be either a normal
// texture (solid_2layer or lightmap_xxx) or a normal
// map (normal_..., parallax_...)
// *********************************************************
int idx = 1;
MaterialHelper* mat = ( MaterialHelper* ) curMat;
if (curMatFlags & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap))
{
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_DIFFUSE(0));
}
else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid)
{
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_NORMALS(0));
}
}
}
else if (!ASSIMP_stricmp("tangents", t))
{
@@ -789,11 +914,6 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
if (materials.empty())
throw new ImportErrorException("IRRMESH: Unable to read a mesh from this file");
if(needLightMap)
{
// Compute light map UV coordinates
// ComputeLightMapUVCoordinates(meshes,materials);
}
// now generate the output scene
pScene->mNumMeshes = (unsigned int)meshes.size();

View File

@@ -48,10 +48,36 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp {
#define AI_IRRMESH_MAT_trans_vertex_alpha 0x1
#define AI_IRRMESH_MAT_lightmap 0x2
#define AI_IRRMESH_MAT_lightmap_m2 (AI_IRRMESH_MAT_lightmap|0x4)
#define AI_IRRMESH_MAT_lightmap_m4 (AI_IRRMESH_MAT_lightmap|0x5)
// Default: 0 = solid, one texture
#define AI_IRRMESH_MAT_solid_2layer 0x10000
// Transparency flags
#define AI_IRRMESH_MAT_trans_vertex_alpha 0x1
#define AI_IRRMESH_MAT_trans_add 0x2
// Lightmapping flags
#define AI_IRRMESH_MAT_lightmap 0x2
#define AI_IRRMESH_MAT_lightmap_m2 (AI_IRRMESH_MAT_lightmap|0x4)
#define AI_IRRMESH_MAT_lightmap_m4 (AI_IRRMESH_MAT_lightmap|0x8)
#define AI_IRRMESH_MAT_lightmap_light (AI_IRRMESH_MAT_lightmap|0x10)
#define AI_IRRMESH_MAT_lightmap_light_m2 (AI_IRRMESH_MAT_lightmap|0x20)
#define AI_IRRMESH_MAT_lightmap_light_m4 (AI_IRRMESH_MAT_lightmap|0x40)
#define AI_IRRMESH_MAT_lightmap_add (AI_IRRMESH_MAT_lightmap|0x80)
// Standard NormalMap (or Parallax map, they're treated equally)
#define AI_IRRMESH_MAT_normalmap_solid (0x100)
// Normal map combined with vertex alpha
#define AI_IRRMESH_MAT_normalmap_tva \
(AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_vertex_alpha)
// Normal map combined with additive transparency
#define AI_IRRMESH_MAT_normalmap_ta \
(AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_add)
// Special flag. It indicates a second texture has been found
// Its type depends ... either a normal textue or a normal map
#define AI_IRRMESH_EXTRA_2ND_TEXTURE 0x100000
// ---------------------------------------------------------------------------