Added support for compressed x files (all files from dx sdk, except car2.x, work, no further tests yet).

Added a working makefile for mingw, provides more configs now. Not perfect yet.
Added decompression part of zlib (inflate).
Moved IrrXML to ./contrib dir.
Moved some IRR/IRRmesh shared code.
FIXME: makefile for gnu/linux is untested yet.
Code cleanup.
Unified #ifndef ASSIMP_BUILD_nnn_IMPORTER directives.
OBJ loader supports map_bump, map_ka, map_ks, map_ns now.
Endianess conversion in the ply loader is correct now.
Changed IRR/IRRMESH coordinate system conversion. Not absolutely right now, but better than before.


git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@305 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2009-01-18 23:48:25 +00:00
parent 9b83f3b3eb
commit d41f570dc0
84 changed files with 7534 additions and 1280 deletions

View File

@@ -43,433 +43,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AssimpPCH.h"
#include "IRRMeshLoader.h"
#include "ParsingUtils.h"
#include "fast_atof.h"
using namespace Assimp;
/**** AT FIRST: IrrlightBase, base class for IrrMesh and Irr *******/
// ------------------------------------------------------------------------------------------------
// read a property in hexadecimal format (i.e. ffffffff)
void IrrlichtBase::ReadHexProperty (HexProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// parse the hexadecimal value
out.value = strtol16(reader->getAttributeValue(i));
}
}
}
// ------------------------------------------------------------------------------------------------
// read a decimal property
void IrrlichtBase::ReadIntProperty (IntProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// parse the ecimal value
out.value = strtol10s(reader->getAttributeValue(i));
}
}
}
// ------------------------------------------------------------------------------------------------
// read a string property
void IrrlichtBase::ReadStringProperty (StringProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// simple copy the string
out.value = std::string (reader->getAttributeValue(i));
}
}
}
// ------------------------------------------------------------------------------------------------
// read a boolean property
void IrrlichtBase::ReadBoolProperty (BoolProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// true or false, case insensitive
out.value = (ASSIMP_stricmp( reader->getAttributeValue(i),
"true") ? false : true);
}
}
}
// ------------------------------------------------------------------------------------------------
// read a float property
void IrrlichtBase::ReadFloatProperty (FloatProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// just parse the float
out.value = fast_atof( reader->getAttributeValue(i) );
}
}
}
// ------------------------------------------------------------------------------------------------
// read a vector property
void IrrlichtBase::ReadVectorProperty (VectorProperty& out)
{
for (int i = 0; i < reader->getAttributeCount();++i)
{
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
{
out.name = std::string( reader->getAttributeValue(i) );
}
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
{
// three floats, separated with commas
const char* ptr = reader->getAttributeValue(i);
SkipSpaces(&ptr);
ptr = fast_atof_move( ptr,(float&)out.value.x );
SkipSpaces(&ptr);
if (',' != *ptr)
{
DefaultLogger::get()->error("IRR(MESH): Expected comma in vector definition");
}
else SkipSpaces(ptr+1,&ptr);
ptr = fast_atof_move( ptr,(float&)out.value.y );
SkipSpaces(&ptr);
if (',' != *ptr)
{
DefaultLogger::get()->error("IRR(MESH): Expected comma in vector definition");
}
else SkipSpaces(ptr+1,&ptr);
ptr = fast_atof_move( ptr,(float&)out.value.z );
}
}
}
// ------------------------------------------------------------------------------------------------
void ColorFromARGBPacked(uint32_t in, aiColor4D& clr)
{
clr.a = ((in >> 24) & 0xff) / 255.f;
clr.r = ((in >> 16) & 0xff) / 255.f;
clr.g = ((in >> 8) & 0xff) / 255.f;
clr.b = ((in ) & 0xff) / 255.f;
}
// ------------------------------------------------------------------------------------------------
int ConvertMappingMode(const std::string& mode)
{
if (mode == "texture_clamp_repeat")
{
return aiTextureMapMode_Wrap;
}
else if (mode == "texture_clamp_mirror")
return aiTextureMapMode_Mirror;
return aiTextureMapMode_Clamp;
}
// ------------------------------------------------------------------------------------------------
// Parse a material from the XML file
aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
{
MaterialHelper* mat = new MaterialHelper();
aiColor4D clr;
aiString s;
matFlags = 0; // zero output flags
int cnt = 0; // number of used texture channels
// Continue reading from the file
while (reader->read())
{
switch (reader->getNodeType())
{
case EXN_ELEMENT:
// Hex properties
if (!ASSIMP_stricmp(reader->getNodeName(),"color"))
{
HexProperty prop;
ReadHexProperty(prop);
if (prop.name == "Diffuse")
{
ColorFromARGBPacked(prop.value,clr);
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE);
}
else if (prop.name == "Ambient")
{
ColorFromARGBPacked(prop.value,clr);
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_AMBIENT);
}
else if (prop.name == "Specular")
{
ColorFromARGBPacked(prop.value,clr);
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_SPECULAR);
}
// NOTE: The 'emissive' property causes problems. It is
// often != 0, even if there is obviously no light
// emitted by the described surface. In fact I think
// IRRLICHT ignores this property, too.
#if 0
else if (prop.name == "Emissive")
{
ColorFromARGBPacked(prop.value,clr);
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_EMISSIVE);
}
#endif
}
// Float properties
else if (!ASSIMP_stricmp(reader->getNodeName(),"float"))
{
FloatProperty prop;
ReadFloatProperty(prop);
if (prop.name == "Shininess")
{
mat->AddProperty(&prop.value,1,AI_MATKEY_SHININESS);
}
}
// Bool properties
else if (!ASSIMP_stricmp(reader->getNodeName(),"bool"))
{
BoolProperty prop;
ReadBoolProperty(prop);
if (prop.name == "Wireframe")
{
int val = (prop.value ? true : false);
mat->AddProperty(&val,1,AI_MATKEY_ENABLE_WIREFRAME);
}
else if (prop.name == "GouraudShading")
{
int val = (prop.value ? aiShadingMode_Gouraud
: aiShadingMode_NoShading);
mat->AddProperty(&val,1,AI_MATKEY_SHADING_MODEL);
}
}
// String properties - textures and texture related properties
else if (!ASSIMP_stricmp(reader->getNodeName(),"texture") ||
!ASSIMP_stricmp(reader->getNodeName(),"enum"))
{
StringProperty prop;
ReadStringProperty(prop);
if (prop.value.length())
{
// material type (shader)
if (prop.name == "Type")
{
if (prop.value == "trans_vertex_alpha")
{
matFlags = AI_IRRMESH_MAT_trans_vertex_alpha;
}
else if (prop.value == "lightmap")
{
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;
}
else if (prop.value == "lightmap_m4")
{
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")
{
// 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
if (prop.name == "TextureWrap1" && cnt >= 1)
{
int map = ConvertMappingMode(prop.value);
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0));
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0));
}
else if (prop.name == "TextureWrap2" && cnt >= 2)
{
int map = ConvertMappingMode(prop.value);
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(1));
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(1));
}
else if (prop.name == "TextureWrap3" && cnt >= 3)
{
int map = ConvertMappingMode(prop.value);
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(2));
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(2));
}
else if (prop.name == "TextureWrap4" && cnt >= 4)
{
int map = ConvertMappingMode(prop.value);
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(3));
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(3));
}
}
}
break;
case EXN_ELEMENT_END:
/* Assume there are no further nested nodes in <material> elements
*/
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)
{
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, AI_MATKEY_TEXBLEND_DIFFUSE(cnt-1));
mat->AddProperty( &op,1, AI_MATKEY_TEXOP_DIFFUSE(cnt-1));
}
return mat;
}
default:
// GCC complains here ...
break;
}
}
DefaultLogger::get()->error("IRRMESH: Unexpected end of file. Material is not complete");
return mat;
}
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
IRRMeshImporter::IRRMeshImporter()
@@ -959,9 +538,9 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
pScene->mRootNode->mMeshes[i] = i;
// transformation matrix to convert from IRRMESH to ASSIMP coordinates
pScene->mRootNode->mTransformation *= aiMatrix4x4(
1.0f, 0.0f, 0.0f, 0.f, 0.0f, 0.0f, -1.0f, 0.f, 0.0f, 1.0f, 0.0f, 0.f, 0.f, 0.f, 0.f, 1.f);
pScene->mRootNode->mTransformation *= AI_TO_IRR_MATRIX;
// clean up and return
delete reader;
AI_DEBUG_INVALIDATE_PTR(reader);
}