Blender: map texture influence to aiTextureType

Previously assimp mapped all blender image textures as
aiTextureType_DIFFUSE.  This change interprets the "mapto" property
which corresponds to the Blender "Influence" in the properties editor.

* Blender's Normal influence with "Normal Map" unchecked maps to
  aiTextureType_HEIGHT.
* Blender's Normal influence with "Normal Map" checked maps to
  aiTextureType_NORMAL.
* Influence scale is placed into AI_MATKEY_BUMPSCALING.
pull/146/head
Calvin Hsu 2013-10-08 18:55:42 -07:00
parent 57c0671681
commit a9a881cde6
3 changed files with 75 additions and 7 deletions

View File

@ -446,9 +446,43 @@ void BlenderImporter::ResolveImage(aiMaterial* out, const Material* mat, const M
else { else {
name = aiString( img->name ); name = aiString( img->name );
} }
out->AddProperty(&name,AI_MATKEY_TEXTURE_DIFFUSE(
conv_data.next_texture[aiTextureType_DIFFUSE]++) aiTextureType texture_type = aiTextureType_UNKNOWN;
); MTex::MapType map_type = tex->mapto;
if (map_type & MTex::MapType_COL)
texture_type = aiTextureType_DIFFUSE;
else if (map_type & MTex::MapType_NORM) {
if (tex->tex->imaflag & Tex::ImageFlags_NORMALMAP) {
texture_type = aiTextureType_NORMALS;
}
else {
texture_type = aiTextureType_HEIGHT;
}
out->AddProperty(&tex->norfac,1,AI_MATKEY_BUMPSCALING);
}
else if (map_type & MTex::MapType_COLSPEC)
texture_type = aiTextureType_SPECULAR;
else if (map_type & MTex::MapType_COLMIR)
texture_type = aiTextureType_REFLECTION;
//else if (map_type & MTex::MapType_REF)
else if (map_type & MTex::MapType_SPEC)
texture_type = aiTextureType_SHININESS;
else if (map_type & MTex::MapType_EMIT)
texture_type = aiTextureType_EMISSIVE;
//else if (map_type & MTex::MapType_ALPHA)
//else if (map_type & MTex::MapType_HAR)
//else if (map_type & MTex::MapType_RAYMIRR)
//else if (map_type & MTex::MapType_TRANSLU)
else if (map_type & MTex::MapType_AMB)
texture_type = aiTextureType_AMBIENT;
else if (map_type & MTex::MapType_DISPLACE)
texture_type = aiTextureType_DISPLACEMENT;
//else if (map_type & MTex::MapType_WARP)
out->AddProperty(&name,AI_MATKEY_TEXTURE(texture_type,
conv_data.next_texture[texture_type]++));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -100,6 +100,7 @@ template <> void Structure :: Convert<MTex> (
) const ) const
{ {
ReadField<ErrorPolicy_Igno>((short&)dest.mapto,"mapto",db);
ReadField<ErrorPolicy_Igno>((int&)dest.blendtype,"blendtype",db); ReadField<ErrorPolicy_Igno>((int&)dest.blendtype,"blendtype",db);
ReadFieldPtr<ErrorPolicy_Igno>(dest.object,"*object",db); ReadFieldPtr<ErrorPolicy_Igno>(dest.object,"*object",db);
ReadFieldPtr<ErrorPolicy_Igno>(dest.tex,"*tex",db); ReadFieldPtr<ErrorPolicy_Igno>(dest.tex,"*tex",db);
@ -126,6 +127,7 @@ template <> void Structure :: Convert<MTex> (
ReadField<ErrorPolicy_Igno>(dest.specfac,"specfac",db); ReadField<ErrorPolicy_Igno>(dest.specfac,"specfac",db);
ReadField<ErrorPolicy_Igno>(dest.emitfac,"emitfac",db); ReadField<ErrorPolicy_Igno>(dest.emitfac,"emitfac",db);
ReadField<ErrorPolicy_Igno>(dest.hardfac,"hardfac",db); ReadField<ErrorPolicy_Igno>(dest.hardfac,"hardfac",db);
ReadField<ErrorPolicy_Igno>(dest.norfac,"norfac",db);
db.reader->IncPtr(size); db.reader->IncPtr(size);
} }
@ -608,7 +610,7 @@ template <> void Structure :: Convert<Tex> (
const FileDatabase& db const FileDatabase& db
) const ) const
{ {
ReadField<ErrorPolicy_Igno>((short&)dest.imaflag,"imaflag",db);
ReadField<ErrorPolicy_Fail>((int&)dest.type,"type",db); ReadField<ErrorPolicy_Fail>((int&)dest.type,"type",db);
ReadFieldPtr<ErrorPolicy_Warn>(dest.ima,"*ima",db); ReadFieldPtr<ErrorPolicy_Warn>(dest.ima,"*ima",db);

View File

@ -598,6 +598,18 @@ struct Tex : ElemBase {
,Type_VOXELDATA = 15 ,Type_VOXELDATA = 15
}; };
enum ImageFlags {
ImageFlags_INTERPOL = 1
,ImageFlags_USEALPHA = 2
,ImageFlags_MIPMAP = 4
,ImageFlags_IMAROT = 16
,ImageFlags_CALCALPHA = 32
,ImageFlags_NORMALMAP = 2048
,ImageFlags_GAUSS_MIP = 4096
,ImageFlags_FILTER_MIN = 8192
,ImageFlags_DERIVATIVEMAP = 16384
};
ID id FAIL; ID id FAIL;
// AnimData *adt; // AnimData *adt;
@ -618,7 +630,8 @@ struct Tex : ElemBase {
//short noisedepth, noisetype; //short noisedepth, noisetype;
//short noisebasis, noisebasis2; //short noisebasis, noisebasis2;
//short imaflag, flag; //short flag;
ImageFlags imaflag;
Type type FAIL; Type type FAIL;
//short stype; //short stype;
@ -685,7 +698,25 @@ struct MTex : ElemBase {
,BlendType_BLEND_COLOR = 13 ,BlendType_BLEND_COLOR = 13
}; };
// short texco, mapto, maptoneg; enum MapType {
MapType_COL = 1
,MapType_NORM = 2
,MapType_COLSPEC = 4
,MapType_COLMIR = 8
,MapType_REF = 16
,MapType_SPEC = 32
,MapType_EMIT = 64
,MapType_ALPHA = 128
,MapType_HAR = 256
,MapType_RAYMIRR = 512
,MapType_TRANSLU = 1024
,MapType_AMB = 2048
,MapType_DISPLACE = 4096
,MapType_WARP = 8192
};
// short texco, maptoneg;
MapType mapto;
BlendType blendtype; BlendType blendtype;
boost::shared_ptr<Object> object; boost::shared_ptr<Object> object;
@ -705,7 +736,8 @@ struct MTex : ElemBase {
//float colfac, varfac; //float colfac, varfac;
//float norfac, dispfac, warpfac; float norfac;
//float dispfac, warpfac;
float colspecfac, mirrfac, alphafac; float colspecfac, mirrfac, alphafac;
float difffac, specfac, emitfac, hardfac; float difffac, specfac, emitfac, hardfac;
//float raymirrfac, translfac, ambfac; //float raymirrfac, translfac, ambfac;