2009-01-18 23:48:25 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2009-01-18 23:48:25 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2009-01-18 23:48:25 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file IRRShared.cpp
|
|
|
|
* @brief Shared utilities for the IRR and IRRMESH loaders
|
|
|
|
*/
|
|
|
|
|
2015-04-15 23:00:17 +00:00
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2013-10-07 23:40:21 +00:00
|
|
|
//This section should be excluded only if both the Irrlicht AND the Irrlicht Mesh importers were omitted.
|
|
|
|
#if !(defined(ASSIMP_BUILD_NO_IRR_IMPORTER) && defined(ASSIMP_BUILD_NO_IRRMESH_IMPORTER))
|
2012-12-20 11:43:09 +00:00
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
#include "IRRShared.h"
|
|
|
|
#include "ParsingUtils.h"
|
|
|
|
#include "fast_atof.h"
|
2015-04-15 23:00:17 +00:00
|
|
|
#include "../include/assimp/DefaultLogger.hpp"
|
|
|
|
#include "../include/assimp/material.h"
|
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
2009-03-03 15:43:26 +00:00
|
|
|
using namespace irr;
|
|
|
|
using namespace irr::io;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
// Transformation matrix to convert from Assimp to IRR space
|
|
|
|
const aiMatrix4x4 Assimp::AI_TO_IRR_MATRIX = aiMatrix4x4 (
|
|
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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
|
2011-03-23 14:26:19 +00:00
|
|
|
out.value = strtoul16(reader->getAttributeValue(i));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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
|
2011-03-23 14:26:19 +00:00
|
|
|
out.value = strtol10(reader->getAttributeValue(i));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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);
|
2012-01-31 16:18:32 +00:00
|
|
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.x );
|
2009-01-18 23:48:25 +00:00
|
|
|
SkipSpaces(&ptr);
|
|
|
|
if (',' != *ptr)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("IRR(MESH): Expected comma in vector definition");
|
|
|
|
}
|
|
|
|
else SkipSpaces(ptr+1,&ptr);
|
2012-01-31 16:18:32 +00:00
|
|
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.y );
|
2009-01-18 23:48:25 +00:00
|
|
|
SkipSpaces(&ptr);
|
|
|
|
if (',' != *ptr)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("IRR(MESH): Expected comma in vector definition");
|
|
|
|
}
|
|
|
|
else SkipSpaces(ptr+1,&ptr);
|
2012-01-31 16:18:32 +00:00
|
|
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.z );
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Convert a string to a proper aiMappingMode
|
|
|
|
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)
|
|
|
|
{
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial* mat = new aiMaterial();
|
2009-01-18 23:48:25 +00:00
|
|
|
aiColor4D clr;
|
|
|
|
aiString s;
|
|
|
|
|
|
|
|
matFlags = 0; // zero output flags
|
|
|
|
int cnt = 0; // number of used texture channels
|
2009-05-03 21:49:34 +00:00
|
|
|
unsigned int nd = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2009-02-11 22:24:17 +00:00
|
|
|
else if (prop.name == "BackfaceCulling")
|
|
|
|
{
|
|
|
|
int val = (!prop.value);
|
|
|
|
mat->AddProperty(&val,1,AI_MATKEY_TWOSIDED);
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
// 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")
|
|
|
|
{
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
if (prop.value == "solid")
|
|
|
|
{
|
|
|
|
// default material ...
|
|
|
|
}
|
|
|
|
else if (prop.value == "trans_vertex_alpha")
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2009-02-11 22:24:17 +00:00
|
|
|
else {
|
|
|
|
DefaultLogger::get()->warn("IRRMat: Unrecognized material type: " + prop.value);
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Up to 4 texture channels are supported
|
2009-02-11 20:56:05 +00:00
|
|
|
if (prop.name == "Texture1")
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
|
|
|
// Always accept the primary texture channel
|
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
|
|
|
}
|
2009-05-03 21:49:34 +00:00
|
|
|
else if (prop.name == "Texture2" && cnt == 1)
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
|
|
|
// 2-layer material lightmapped?
|
2009-02-11 22:24:17 +00:00
|
|
|
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
2009-01-18 23:48:25 +00:00
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
2009-02-11 20:56:05 +00:00
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_LIGHTMAP(0));
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
// set the corresponding material flag
|
|
|
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
|
|
|
}
|
|
|
|
// alternatively: normal or parallax mapping
|
2009-02-11 22:24:17 +00:00
|
|
|
else if (matFlags & AI_IRRMESH_MAT_normalmap_solid) {
|
2009-01-18 23:48:25 +00:00
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
2009-02-11 20:56:05 +00:00
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_NORMALS(0));
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
// set the corresponding material flag
|
|
|
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
|
|
|
}
|
2009-02-11 22:24:17 +00:00
|
|
|
// or just as second diffuse texture
|
|
|
|
else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {
|
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(1));
|
2009-05-03 21:49:34 +00:00
|
|
|
++nd;
|
2009-02-11 22:24:17 +00:00
|
|
|
|
|
|
|
// set the corresponding material flag
|
|
|
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
|
|
|
}
|
2009-02-11 20:56:05 +00:00
|
|
|
else DefaultLogger::get()->warn("IRRmat: Skipping second texture");
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
2009-05-03 21:49:34 +00:00
|
|
|
|
|
|
|
else if (prop.name == "Texture3" && cnt == 2)
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
2009-02-11 20:56:05 +00:00
|
|
|
// Irrlicht does not seem to use these channels.
|
2009-01-18 23:48:25 +00:00
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
2009-05-03 21:49:34 +00:00
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(nd+1));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
2009-05-03 21:49:34 +00:00
|
|
|
else if (prop.name == "Texture4" && cnt == 3)
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
2009-02-11 20:56:05 +00:00
|
|
|
// Irrlicht does not seem to use these channels.
|
2009-01-18 23:48:25 +00:00
|
|
|
++cnt;
|
|
|
|
s.Set(prop.value);
|
2009-05-03 21:49:34 +00:00
|
|
|
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(nd+2));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2009-02-11 22:24:17 +00:00
|
|
|
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(0));
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(0));
|
2009-02-11 20:56:05 +00:00
|
|
|
}
|
|
|
|
else if (matFlags & (AI_IRRMESH_MAT_normalmap_solid)) {
|
2009-02-11 22:24:17 +00:00
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_NORMALS(0));
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_NORMALS(0));
|
|
|
|
}
|
|
|
|
else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(1));
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(1));
|
2009-02-11 20:56:05 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
else if (prop.name == "TextureWrap3" && cnt >= 3)
|
|
|
|
{
|
|
|
|
int map = ConvertMappingMode(prop.value);
|
2009-05-03 21:49:34 +00:00
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd+1));
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd+1));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
else if (prop.name == "TextureWrap4" && cnt >= 4)
|
|
|
|
{
|
|
|
|
int map = ConvertMappingMode(prop.value);
|
2009-05-03 21:49:34 +00:00
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd+2));
|
|
|
|
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd+2));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2009-05-03 21:49:34 +00:00
|
|
|
// We should have at least one textur to do that ..
|
2009-01-18 23:48:25 +00:00
|
|
|
if (cnt && matFlags & AI_IRRMESH_MAT_lightmap)
|
|
|
|
{
|
|
|
|
float f = 1.f;
|
2009-05-03 21:49:34 +00:00
|
|
|
unsigned int unmasked = matFlags&~AI_IRRMESH_MAT_lightmap;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
// Additive lightmap?
|
2009-05-03 21:49:34 +00:00
|
|
|
int op = (unmasked & AI_IRRMESH_MAT_lightmap_add
|
2009-01-18 23:48:25 +00:00
|
|
|
? aiTextureOp_Add : aiTextureOp_Multiply);
|
|
|
|
|
|
|
|
// Handle Irrlicht's lightmapping scaling factor
|
2009-05-03 21:49:34 +00:00
|
|
|
if (unmasked & AI_IRRMESH_MAT_lightmap_m2 ||
|
|
|
|
unmasked & AI_IRRMESH_MAT_lightmap_light_m2)
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
|
|
|
f = 2.f;
|
|
|
|
}
|
2009-05-03 21:49:34 +00:00
|
|
|
else if (unmasked & AI_IRRMESH_MAT_lightmap_m4 ||
|
|
|
|
unmasked & AI_IRRMESH_MAT_lightmap_light_m4)
|
2009-01-18 23:48:25 +00:00
|
|
|
{
|
|
|
|
f = 4.f;
|
|
|
|
}
|
2009-02-11 20:56:05 +00:00
|
|
|
mat->AddProperty( &f, 1, AI_MATKEY_TEXBLEND_LIGHTMAP(0));
|
|
|
|
mat->AddProperty( &op,1, AI_MATKEY_TEXOP_LIGHTMAP(0));
|
2009-01-18 23:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mat;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
|
|
|
|
// GCC complains here ...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->error("IRRMESH: Unexpected end of file. Material is not complete");
|
|
|
|
return mat;
|
|
|
|
}
|
2012-12-20 11:43:09 +00:00
|
|
|
|
2013-10-07 23:40:21 +00:00
|
|
|
#endif // !(defined(ASSIMP_BUILD_NO_IRR_IMPORTER) && defined(ASSIMP_BUILD_NO_IRRMESH_IMPORTER))
|