xml-migration: migrate shared code from irr-loader.
parent
bd2ffc8d58
commit
1a8d5667b6
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -56,13 +54,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
using namespace irr;
|
|
||||||
using namespace irr::io;
|
|
||||||
|
|
||||||
// Transformation matrix to convert from Assimp to IRR space
|
// Transformation matrix to convert from Assimp to IRR space
|
||||||
const aiMatrix4x4 Assimp::AI_TO_IRR_MATRIX = aiMatrix4x4 (
|
static const aiMatrix4x4 Assimp::AI_TO_IRR_MATRIX = aiMatrix4x4 (
|
||||||
1.0f, 0.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
0.0f, 1.0f, 0.0f, 0.0f,
|
0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
@ -70,125 +65,94 @@ const aiMatrix4x4 Assimp::AI_TO_IRR_MATRIX = aiMatrix4x4 (
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a property in hexadecimal format (i.e. ffffffff)
|
// read a property in hexadecimal format (i.e. ffffffff)
|
||||||
void IrrlichtBase::ReadHexProperty (HexProperty& out)
|
void IrrlichtBase::ReadHexProperty(HexProperty &out ) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")) {
|
||||||
{
|
out.name = std::string( attrib.value() );
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.name(),"value")) {
|
||||||
{
|
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// parse the hexadecimal value
|
// parse the hexadecimal value
|
||||||
out.value = strtoul16(reader->getAttributeValue(i));
|
out.value = strtoul16(attrib.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a decimal property
|
// read a decimal property
|
||||||
void IrrlichtBase::ReadIntProperty (IntProperty& out)
|
void IrrlichtBase::ReadIntProperty(IntProperty & out) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")) {
|
||||||
{
|
out.name = std::string(attrib.value());
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.value(),"value")) {
|
||||||
{
|
// parse the int value
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
out.value = strtol10(attrib.name());
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// parse the ecimal value
|
|
||||||
out.value = strtol10(reader->getAttributeValue(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a string property
|
// read a string property
|
||||||
void IrrlichtBase::ReadStringProperty (StringProperty& out)
|
void IrrlichtBase::ReadStringProperty (StringProperty& out) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")) {
|
||||||
{
|
out.name = std::string(attrib.value());
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.name(), "value")) {
|
||||||
{
|
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// simple copy the string
|
// simple copy the string
|
||||||
out.value = std::string (reader->getAttributeValue(i));
|
out.value = std::string(attrib.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a boolean property
|
// read a boolean property
|
||||||
void IrrlichtBase::ReadBoolProperty (BoolProperty& out)
|
void IrrlichtBase::ReadBoolProperty(BoolProperty &out) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")){
|
||||||
{
|
out.name = std::string(attrib.value());
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.name(), "value")) {
|
||||||
{
|
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// true or false, case insensitive
|
// true or false, case insensitive
|
||||||
out.value = (ASSIMP_stricmp( reader->getAttributeValue(i),
|
out.value = (ASSIMP_stricmp(attrib.value(), "true") ? false : true);
|
||||||
"true") ? false : true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a float property
|
// read a float property
|
||||||
void IrrlichtBase::ReadFloatProperty (FloatProperty& out)
|
void IrrlichtBase::ReadFloatProperty(FloatProperty &out) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")) {
|
||||||
{
|
out.name = std::string(attrib.value());
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.name(), "value")) {
|
||||||
{
|
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// just parse the float
|
// just parse the float
|
||||||
out.value = fast_atof( reader->getAttributeValue(i) );
|
out.value = fast_atof(attrib.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// read a vector property
|
// read a vector property
|
||||||
void IrrlichtBase::ReadVectorProperty (VectorProperty& out)
|
void IrrlichtBase::ReadVectorProperty( VectorProperty &out ) {
|
||||||
{
|
for (pugi::xml_attribute attrib : mNode.attributes()) {
|
||||||
for (int i = 0; i < reader->getAttributeCount();++i)
|
if (!ASSIMP_stricmp(attrib.name(), "name")) {
|
||||||
{
|
out.name = std::string(attrib.value());
|
||||||
if (!ASSIMP_stricmp(reader->getAttributeName(i),"name"))
|
} else if (!ASSIMP_stricmp(attrib.name(), "value")) {
|
||||||
{
|
|
||||||
out.name = std::string( reader->getAttributeValue(i) );
|
|
||||||
}
|
|
||||||
else if (!ASSIMP_stricmp(reader->getAttributeName(i),"value"))
|
|
||||||
{
|
|
||||||
// three floats, separated with commas
|
// three floats, separated with commas
|
||||||
const char* ptr = reader->getAttributeValue(i);
|
const char *ptr = attrib.value();
|
||||||
|
|
||||||
SkipSpaces(&ptr);
|
SkipSpaces(&ptr);
|
||||||
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.x );
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.x );
|
||||||
SkipSpaces(&ptr);
|
SkipSpaces(&ptr);
|
||||||
if (',' != *ptr)
|
if (',' != *ptr) {
|
||||||
{
|
|
||||||
ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition");
|
ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition");
|
||||||
}
|
} else {
|
||||||
else SkipSpaces(ptr+1,&ptr);
|
SkipSpaces(ptr + 1, &ptr);
|
||||||
|
}
|
||||||
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.y );
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.y );
|
||||||
SkipSpaces(&ptr);
|
SkipSpaces(&ptr);
|
||||||
if (',' != *ptr)
|
if (',' != *ptr) {
|
||||||
{
|
|
||||||
ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition");
|
ASSIMP_LOG_ERROR("IRR(MESH): Expected comma in vector definition");
|
||||||
}
|
} else {
|
||||||
else SkipSpaces(ptr+1,&ptr);
|
SkipSpaces(ptr + 1, &ptr);
|
||||||
|
}
|
||||||
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.z );
|
ptr = fast_atoreal_move<float>( ptr,(float&)out.value.z );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,22 +160,19 @@ void IrrlichtBase::ReadVectorProperty (VectorProperty& out)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Convert a string to a proper aiMappingMode
|
// Convert a string to a proper aiMappingMode
|
||||||
int ConvertMappingMode(const std::string& mode)
|
int ConvertMappingMode(const std::string& mode) {
|
||||||
{
|
if (mode == "texture_clamp_repeat") {
|
||||||
if (mode == "texture_clamp_repeat")
|
|
||||||
{
|
|
||||||
return aiTextureMapMode_Wrap;
|
return aiTextureMapMode_Wrap;
|
||||||
}
|
} else if (mode == "texture_clamp_mirror") {
|
||||||
else if (mode == "texture_clamp_mirror")
|
return aiTextureMapMode_Mirror;
|
||||||
return aiTextureMapMode_Mirror;
|
}
|
||||||
|
|
||||||
return aiTextureMapMode_Clamp;
|
return aiTextureMapMode_Clamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Parse a material from the XML file
|
// Parse a material from the XML file
|
||||||
aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
|
aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags) {
|
||||||
{
|
|
||||||
aiMaterial* mat = new aiMaterial();
|
aiMaterial* mat = new aiMaterial();
|
||||||
aiColor4D clr;
|
aiColor4D clr;
|
||||||
aiString s;
|
aiString s;
|
||||||
|
@ -220,244 +181,170 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
|
||||||
int cnt = 0; // number of used texture channels
|
int cnt = 0; // number of used texture channels
|
||||||
unsigned int nd = 0;
|
unsigned int nd = 0;
|
||||||
|
|
||||||
// Continue reading from the file
|
for (pugi::xml_node child : mNode.children()) {
|
||||||
while (reader->read())
|
if (!ASSIMP_stricmp(child.name(), "color")) { // Hex properties
|
||||||
{
|
HexProperty prop;
|
||||||
switch (reader->getNodeType())
|
ReadHexProperty(prop);
|
||||||
{
|
if (prop.name == "Diffuse") {
|
||||||
case EXN_ELEMENT:
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// Hex properties
|
// NOTE: The 'emissive' property causes problems. It is
|
||||||
if (!ASSIMP_stricmp(reader->getNodeName(),"color"))
|
// often != 0, even if there is obviously no light
|
||||||
{
|
// emitted by the described surface. In fact I think
|
||||||
HexProperty prop;
|
// IRRLICHT ignores this property, too.
|
||||||
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
|
#if 0
|
||||||
else if (prop.name == "Emissive")
|
else if (prop.name == "Emissive") {
|
||||||
{
|
ColorFromARGBPacked(prop.value,clr);
|
||||||
ColorFromARGBPacked(prop.value,clr);
|
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_EMISSIVE);
|
||||||
mat->AddProperty(&clr,1,AI_MATKEY_COLOR_EMISSIVE);
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (!ASSIMP_stricmp(child.name(), "float")) { // Float properties
|
||||||
// Float properties
|
FloatProperty prop;
|
||||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"float"))
|
ReadFloatProperty(prop);
|
||||||
{
|
if (prop.name == "Shininess") {
|
||||||
FloatProperty prop;
|
mat->AddProperty(&prop.value, 1, AI_MATKEY_SHININESS);
|
||||||
ReadFloatProperty(prop);
|
}
|
||||||
if (prop.name == "Shininess")
|
} else if (!ASSIMP_stricmp(child.name(), "bool")) { // Bool properties
|
||||||
{
|
BoolProperty prop;
|
||||||
mat->AddProperty(&prop.value,1,AI_MATKEY_SHININESS);
|
ReadBoolProperty(prop);
|
||||||
}
|
if (prop.name == "Wireframe") {
|
||||||
}
|
int val = (prop.value ? true : false);
|
||||||
// Bool properties
|
mat->AddProperty(&val, 1, AI_MATKEY_ENABLE_WIREFRAME);
|
||||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"bool"))
|
} else if (prop.name == "GouraudShading") {
|
||||||
{
|
int val = (prop.value ? aiShadingMode_Gouraud : aiShadingMode_NoShading);
|
||||||
BoolProperty prop;
|
mat->AddProperty(&val, 1, AI_MATKEY_SHADING_MODEL);
|
||||||
ReadBoolProperty(prop);
|
} else if (prop.name == "BackfaceCulling") {
|
||||||
if (prop.name == "Wireframe")
|
int val = (!prop.value);
|
||||||
{
|
mat->AddProperty(&val, 1, AI_MATKEY_TWOSIDED);
|
||||||
int val = (prop.value ? true : false);
|
}
|
||||||
mat->AddProperty(&val,1,AI_MATKEY_ENABLE_WIREFRAME);
|
} else if (!ASSIMP_stricmp(child.name(), "texture") ||
|
||||||
}
|
!ASSIMP_stricmp(child.name(), "enum")) { // String properties - textures and texture related properties
|
||||||
else if (prop.name == "GouraudShading")
|
StringProperty prop;
|
||||||
{
|
ReadStringProperty(prop);
|
||||||
int val = (prop.value ? aiShadingMode_Gouraud
|
if (prop.value.length()) {
|
||||||
: aiShadingMode_NoShading);
|
// material type (shader)
|
||||||
mat->AddProperty(&val,1,AI_MATKEY_SHADING_MODEL);
|
if (prop.name == "Type") {
|
||||||
}
|
if (prop.value == "solid") {
|
||||||
else if (prop.name == "BackfaceCulling")
|
// default material ...
|
||||||
{
|
} else if (prop.value == "trans_vertex_alpha") {
|
||||||
int val = (!prop.value);
|
matFlags = AI_IRRMESH_MAT_trans_vertex_alpha;
|
||||||
mat->AddProperty(&val,1,AI_MATKEY_TWOSIDED);
|
} else if (prop.value == "lightmap") {
|
||||||
}
|
matFlags = AI_IRRMESH_MAT_lightmap;
|
||||||
}
|
} else if (prop.value == "solid_2layer") {
|
||||||
// String properties - textures and texture related properties
|
matFlags = AI_IRRMESH_MAT_solid_2layer;
|
||||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"texture") ||
|
} else if (prop.value == "lightmap_m2") {
|
||||||
!ASSIMP_stricmp(reader->getNodeName(),"enum"))
|
matFlags = AI_IRRMESH_MAT_lightmap_m2;
|
||||||
{
|
} else if (prop.value == "lightmap_m4") {
|
||||||
StringProperty prop;
|
matFlags = AI_IRRMESH_MAT_lightmap_m4;
|
||||||
ReadStringProperty(prop);
|
} else if (prop.value == "lightmap_light") {
|
||||||
if (prop.value.length())
|
matFlags = AI_IRRMESH_MAT_lightmap_light;
|
||||||
{
|
} else if (prop.value == "lightmap_light_m2") {
|
||||||
// material type (shader)
|
matFlags = AI_IRRMESH_MAT_lightmap_light_m2;
|
||||||
if (prop.name == "Type")
|
} else if (prop.value == "lightmap_light_m4") {
|
||||||
{
|
matFlags = AI_IRRMESH_MAT_lightmap_light_m4;
|
||||||
if (prop.value == "solid")
|
} else if (prop.value == "lightmap_add") {
|
||||||
{
|
matFlags = AI_IRRMESH_MAT_lightmap_add;
|
||||||
// default material ...
|
} else if (prop.value == "normalmap_solid" ||
|
||||||
}
|
prop.value == "parallaxmap_solid") { // Normal and parallax maps are treated equally
|
||||||
else if (prop.value == "trans_vertex_alpha")
|
matFlags = AI_IRRMESH_MAT_normalmap_solid;
|
||||||
{
|
} else if (prop.value == "normalmap_trans_vertex_alpha" ||
|
||||||
matFlags = AI_IRRMESH_MAT_trans_vertex_alpha;
|
prop.value == "parallaxmap_trans_vertex_alpha") {
|
||||||
}
|
matFlags = AI_IRRMESH_MAT_normalmap_tva;
|
||||||
else if (prop.value == "lightmap")
|
} else if (prop.value == "normalmap_trans_add" ||
|
||||||
{
|
prop.value == "parallaxmap_trans_add") {
|
||||||
matFlags = AI_IRRMESH_MAT_lightmap;
|
matFlags = AI_IRRMESH_MAT_normalmap_ta;
|
||||||
}
|
} else {
|
||||||
else if (prop.value == "solid_2layer")
|
ASSIMP_LOG_WARN("IRRMat: Unrecognized material type: " + prop.value);
|
||||||
{
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ASSIMP_LOG_WARN("IRRMat: Unrecognized material type: " + prop.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Up to 4 texture channels are supported
|
// Up to 4 texture channels are supported
|
||||||
if (prop.name == "Texture1")
|
if (prop.name == "Texture1") {
|
||||||
{
|
// Always accept the primary texture channel
|
||||||
// Always accept the primary texture channel
|
++cnt;
|
||||||
++cnt;
|
s.Set(prop.value);
|
||||||
s.Set(prop.value);
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
} else if (prop.name == "Texture2" && cnt == 1) {
|
||||||
}
|
// 2-layer material lightmapped?
|
||||||
else if (prop.name == "Texture2" && cnt == 1)
|
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
||||||
{
|
++cnt;
|
||||||
// 2-layer material lightmapped?
|
s.Set(prop.value);
|
||||||
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_LIGHTMAP(0));
|
||||||
++cnt;
|
|
||||||
s.Set(prop.value);
|
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_LIGHTMAP(0));
|
|
||||||
|
|
||||||
// set the corresponding material flag
|
// set the corresponding material flag
|
||||||
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
||||||
}
|
} else if (matFlags & AI_IRRMESH_MAT_normalmap_solid) { // alternatively: normal or parallax mapping
|
||||||
// alternatively: normal or parallax mapping
|
++cnt;
|
||||||
else if (matFlags & AI_IRRMESH_MAT_normalmap_solid) {
|
s.Set(prop.value);
|
||||||
++cnt;
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_NORMALS(0));
|
||||||
s.Set(prop.value);
|
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_NORMALS(0));
|
|
||||||
|
|
||||||
// set the corresponding material flag
|
// set the corresponding material flag
|
||||||
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
||||||
} else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {// or just as second diffuse texture
|
} else if (matFlags & AI_IRRMESH_MAT_solid_2layer) { // or just as second diffuse texture
|
||||||
++cnt;
|
++cnt;
|
||||||
s.Set(prop.value);
|
s.Set(prop.value);
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(1));
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(1));
|
||||||
++nd;
|
++nd;
|
||||||
|
|
||||||
// set the corresponding material flag
|
// set the corresponding material flag
|
||||||
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN("IRRmat: Skipping second texture");
|
ASSIMP_LOG_WARN("IRRmat: Skipping second texture");
|
||||||
}
|
}
|
||||||
} else if (prop.name == "Texture3" && cnt == 2) {
|
} else if (prop.name == "Texture3" && cnt == 2) {
|
||||||
// Irrlicht does not seem to use these channels.
|
// Irrlicht does not seem to use these channels.
|
||||||
++cnt;
|
++cnt;
|
||||||
s.Set(prop.value);
|
s.Set(prop.value);
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(nd+1));
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(nd + 1));
|
||||||
} else if (prop.name == "Texture4" && cnt == 3) {
|
} else if (prop.name == "Texture4" && cnt == 3) {
|
||||||
// Irrlicht does not seem to use these channels.
|
// Irrlicht does not seem to use these channels.
|
||||||
++cnt;
|
++cnt;
|
||||||
s.Set(prop.value);
|
s.Set(prop.value);
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(nd+2));
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(nd + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture mapping options
|
// Texture mapping options
|
||||||
if (prop.name == "TextureWrap1" && cnt >= 1)
|
if (prop.name == "TextureWrap1" && cnt >= 1) {
|
||||||
{
|
int map = ConvertMappingMode(prop.value);
|
||||||
int map = ConvertMappingMode(prop.value);
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0));
|
} else if (prop.name == "TextureWrap2" && cnt >= 2) {
|
||||||
}
|
int map = ConvertMappingMode(prop.value);
|
||||||
else if (prop.name == "TextureWrap2" && cnt >= 2)
|
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
||||||
{
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(0));
|
||||||
int map = ConvertMappingMode(prop.value);
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(0));
|
||||||
if (matFlags & AI_IRRMESH_MAT_lightmap) {
|
} else if (matFlags & (AI_IRRMESH_MAT_normalmap_solid)) {
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(0));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_NORMALS(0));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(0));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_NORMALS(0));
|
||||||
}
|
} else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {
|
||||||
else if (matFlags & (AI_IRRMESH_MAT_normalmap_solid)) {
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_DIFFUSE(1));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_NORMALS(0));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_DIFFUSE(1));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_NORMALS(0));
|
}
|
||||||
}
|
} else if (prop.name == "TextureWrap3" && cnt >= 3) {
|
||||||
else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {
|
int map = ConvertMappingMode(prop.value);
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(1));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd + 1));
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(1));
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd + 1));
|
||||||
}
|
} else if (prop.name == "TextureWrap4" && cnt >= 4) {
|
||||||
}
|
int map = ConvertMappingMode(prop.value);
|
||||||
else if (prop.name == "TextureWrap3" && cnt >= 3)
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd + 2));
|
||||||
{
|
mat->AddProperty(&map, 1, AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd + 2));
|
||||||
int map = ConvertMappingMode(prop.value);
|
}
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd+1));
|
}
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd+1));
|
}
|
||||||
}
|
//break;
|
||||||
else if (prop.name == "TextureWrap4" && cnt >= 4)
|
/*case EXN_ELEMENT_END:
|
||||||
{
|
|
||||||
int map = ConvertMappingMode(prop.value);
|
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(nd+2));
|
|
||||||
mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(nd+2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case EXN_ELEMENT_END:
|
|
||||||
|
|
||||||
/* Assume there are no further nested nodes in <material> elements
|
// Assume there are no further nested nodes in <material> elements
|
||||||
*/
|
if ( !ASSIMP_stricmp(reader->getNodeName(),"material") ||
|
||||||
if (/* IRRMESH */ !ASSIMP_stricmp(reader->getNodeName(),"material") ||
|
!ASSIMP_stricmp(reader->getNodeName(),"attributes"))
|
||||||
/* IRR */ !ASSIMP_stricmp(reader->getNodeName(),"attributes"))
|
|
||||||
{
|
{
|
||||||
// Now process lightmapping flags
|
// Now process lightmapping flags
|
||||||
// We should have at least one textur to do that ..
|
// We should have at least one textur to do that ..
|
||||||
|
@ -492,7 +379,8 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
|
||||||
// GCC complains here ...
|
// GCC complains here ...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
}
|
||||||
ASSIMP_LOG_ERROR("IRRMESH: Unexpected end of file. Material is not complete");
|
ASSIMP_LOG_ERROR("IRRMESH: Unexpected end of file. Material is not complete");
|
||||||
|
|
||||||
return mat;
|
return mat;
|
||||||
|
|
|
@ -15,7 +15,6 @@ struct aiMaterial;
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
|
||||||
/** @brief Matrix to convert from Assimp to IRR and backwards
|
/** @brief Matrix to convert from Assimp to IRR and backwards
|
||||||
*/
|
*/
|
||||||
extern const aiMatrix4x4 AI_TO_IRR_MATRIX;
|
extern const aiMatrix4x4 AI_TO_IRR_MATRIX;
|
||||||
|
@ -80,6 +79,7 @@ protected:
|
||||||
|
|
||||||
/// XML reader instance
|
/// XML reader instance
|
||||||
XmlParser mParser;
|
XmlParser mParser;
|
||||||
|
pugi::xml_node &mNode;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Parse a material description from the XML
|
/** Parse a material description from the XML
|
||||||
|
@ -103,15 +103,14 @@ protected:
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Unpack a hex color, e.g. 0xdcdedfff
|
// Unpack a hex color, e.g. 0xdcdedfff
|
||||||
inline void ColorFromARGBPacked(uint32_t in, aiColor4D& clr)
|
inline
|
||||||
{
|
void ColorFromARGBPacked(uint32_t in, aiColor4D& clr) {
|
||||||
clr.a = ((in >> 24) & 0xff) / 255.f;
|
clr.a = ((in >> 24) & 0xff) / 255.f;
|
||||||
clr.r = ((in >> 16) & 0xff) / 255.f;
|
clr.r = ((in >> 16) & 0xff) / 255.f;
|
||||||
clr.g = ((in >> 8) & 0xff) / 255.f;
|
clr.g = ((in >> 8) & 0xff) / 255.f;
|
||||||
clr.b = ((in ) & 0xff) / 255.f;
|
clr.b = ((in ) & 0xff) / 255.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end namespace Assimp
|
} // end namespace Assimp
|
||||||
|
|
||||||
#endif // !! INCLUDED_AI_IRRSHARED_H
|
#endif // !! INCLUDED_AI_IRRSHARED_H
|
||||||
|
|
Loading…
Reference in New Issue