Merge pull request #670 from romeoxbm/master
Added support for reflection maps for OBJ filesreviewable/pr672/r1
commit
282a913b7f
|
@ -156,6 +156,7 @@ struct Material
|
||||||
aiString textureEmissive;
|
aiString textureEmissive;
|
||||||
aiString textureBump;
|
aiString textureBump;
|
||||||
aiString textureNormal;
|
aiString textureNormal;
|
||||||
|
aiString textureReflection[6];
|
||||||
aiString textureSpecularity;
|
aiString textureSpecularity;
|
||||||
aiString textureOpacity;
|
aiString textureOpacity;
|
||||||
aiString textureDisp;
|
aiString textureDisp;
|
||||||
|
@ -167,6 +168,13 @@ struct Material
|
||||||
TextureEmissiveType,
|
TextureEmissiveType,
|
||||||
TextureBumpType,
|
TextureBumpType,
|
||||||
TextureNormalType,
|
TextureNormalType,
|
||||||
|
TextureReflectionSphereType,
|
||||||
|
TextureReflectionCubeTopType,
|
||||||
|
TextureReflectionCubeBottomType,
|
||||||
|
TextureReflectionCubeFrontType,
|
||||||
|
TextureReflectionCubeBackType,
|
||||||
|
TextureReflectionCubeLeftType,
|
||||||
|
TextureReflectionCubeRightType,
|
||||||
TextureSpecularityType,
|
TextureSpecularityType,
|
||||||
TextureOpacityType,
|
TextureOpacityType,
|
||||||
TextureDispType,
|
TextureDispType,
|
||||||
|
|
|
@ -636,6 +636,22 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( 0 != pCurrentMaterial->textureReflection[0].length )
|
||||||
|
{
|
||||||
|
ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ?
|
||||||
|
ObjFile::Material::TextureReflectionCubeTopType :
|
||||||
|
ObjFile::Material::TextureReflectionSphereType;
|
||||||
|
|
||||||
|
unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6;
|
||||||
|
for( unsigned i = 0; i < count; i++ )
|
||||||
|
mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i));
|
||||||
|
|
||||||
|
if(pCurrentMaterial->clamp[type])
|
||||||
|
//TODO addTextureMappingModeProperty should accept an index to handle clamp option for each
|
||||||
|
//texture of a cubemap
|
||||||
|
addTextureMappingModeProperty(mat, aiTextureType_REFLECTION);
|
||||||
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureDisp.length )
|
if ( 0 != pCurrentMaterial->textureDisp.length )
|
||||||
{
|
{
|
||||||
mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) );
|
mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) );
|
||||||
|
|
|
@ -64,6 +64,7 @@ static const std::string BumpTexture1 = "map_bump";
|
||||||
static const std::string BumpTexture2 = "map_Bump";
|
static const std::string BumpTexture2 = "map_Bump";
|
||||||
static const std::string BumpTexture3 = "bump";
|
static const std::string BumpTexture3 = "bump";
|
||||||
static const std::string NormalTexture = "map_Kn";
|
static const std::string NormalTexture = "map_Kn";
|
||||||
|
static const std::string ReflectionTexture = "refl";
|
||||||
static const std::string DisplacementTexture = "disp";
|
static const std::string DisplacementTexture = "disp";
|
||||||
static const std::string SpecularityTexture = "map_ns";
|
static const std::string SpecularityTexture = "map_ns";
|
||||||
|
|
||||||
|
@ -200,6 +201,7 @@ void ObjFileMtlImporter::load()
|
||||||
|
|
||||||
case 'm': // Texture
|
case 'm': // Texture
|
||||||
case 'b': // quick'n'dirty - for 'bump' sections
|
case 'b': // quick'n'dirty - for 'bump' sections
|
||||||
|
case 'r': // quick'n'dirty - for 'refl' sections
|
||||||
{
|
{
|
||||||
getTexture();
|
getTexture();
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||||
|
@ -332,6 +334,9 @@ void ObjFileMtlImporter::getTexture() {
|
||||||
// Normal map
|
// Normal map
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
||||||
clampIndex = ObjFile::Material::TextureNormalType;
|
clampIndex = ObjFile::Material::TextureNormalType;
|
||||||
|
} else if(!ASSIMP_strincmp( pPtr, ReflectionTexture.c_str(), ReflectionTexture.size() ) ) {
|
||||||
|
// Reflection texture(s)
|
||||||
|
//Do nothing here
|
||||||
} else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) {
|
} else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) {
|
||||||
// Displacement texture
|
// Displacement texture
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
||||||
|
@ -346,7 +351,7 @@ void ObjFileMtlImporter::getTexture() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clamp = false;
|
bool clamp = false;
|
||||||
getTextureOption(clamp);
|
getTextureOption(clamp, clampIndex, out);
|
||||||
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
||||||
|
|
||||||
std::string texture;
|
std::string texture;
|
||||||
|
@ -369,7 +374,7 @@ void ObjFileMtlImporter::getTexture() {
|
||||||
* Because aiMaterial supports clamp option, so we also want to return it
|
* Because aiMaterial supports clamp option, so we also want to return it
|
||||||
* /////////////////////////////////////////////////////////////////////////////
|
* /////////////////////////////////////////////////////////////////////////////
|
||||||
*/
|
*/
|
||||||
void ObjFileMtlImporter::getTextureOption(bool &clamp)
|
void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString *&out)
|
||||||
{
|
{
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
|
|
||||||
|
@ -392,13 +397,55 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp)
|
||||||
|
|
||||||
skipToken = 2;
|
skipToken = 2;
|
||||||
}
|
}
|
||||||
|
else if( !ASSIMP_strincmp( pPtr, TypeOption.c_str(), TypeOption.size() ) )
|
||||||
|
{
|
||||||
|
DataArrayIt it = getNextToken<DataArrayIt>( m_DataIt, m_DataItEnd );
|
||||||
|
char value[ 12 ];
|
||||||
|
CopyNextWord( it, m_DataItEnd, value, sizeof( value ) / sizeof( *value ) );
|
||||||
|
if( !ASSIMP_strincmp( value, "cube_top", 8 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "cube_front", 10 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "cube_back", 9 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "cube_left", 9 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "cube_right", 10 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
|
||||||
|
}
|
||||||
|
else if( !ASSIMP_strincmp( value, "sphere", 6 ) )
|
||||||
|
{
|
||||||
|
clampIndex = ObjFile::Material::TextureReflectionSphereType;
|
||||||
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
skipToken = 2;
|
||||||
|
}
|
||||||
else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
|
else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
|
||||||
|| !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size())
|
|| !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size())
|
||||||
|| !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size())
|
|| !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size())
|
||||||
|| !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size())
|
|| !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size())
|
||||||
|| !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size())
|
|| !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size())
|
||||||
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size())
|
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size()))
|
||||||
|| !ASSIMP_strincmp(pPtr, TypeOption.c_str(), TypeOption.size()) )
|
|
||||||
{
|
{
|
||||||
skipToken = 2;
|
skipToken = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct aiColor3D;
|
struct aiColor3D;
|
||||||
|
struct aiString;
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ private:
|
||||||
void createMaterial();
|
void createMaterial();
|
||||||
/// Get texture name from loaded data.
|
/// Get texture name from loaded data.
|
||||||
void getTexture();
|
void getTexture();
|
||||||
void getTextureOption(bool &clamp);
|
void getTextureOption(bool &clamp, int &clampIndex, aiString *&out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Absolute pathname
|
//! Absolute pathname
|
||||||
|
|
Loading…
Reference in New Issue