|
@@ -42,14 +42,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
|
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
|
|
|
|
|
-#include <stdlib.h>
|
|
|
|
|
|
+#include <stdlib.h>
|
|
#include "ObjFileMtlImporter.h"
|
|
#include "ObjFileMtlImporter.h"
|
|
#include "ObjTools.h"
|
|
#include "ObjTools.h"
|
|
#include "ObjFileData.h"
|
|
#include "ObjFileData.h"
|
|
#include "fast_atof.h"
|
|
#include "fast_atof.h"
|
|
-#include "ParsingUtils.h"
|
|
|
|
-#include "../include/assimp/material.h"
|
|
|
|
-#include "../include/assimp/DefaultLogger.hpp"
|
|
|
|
|
|
+#include "ParsingUtils.h"
|
|
|
|
+#include "../include/assimp/material.h"
|
|
|
|
+#include "../include/assimp/DefaultLogger.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
namespace Assimp {
|
|
@@ -86,147 +86,147 @@ static const std::string TypeOption = "-type";
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Constructor
|
|
// Constructor
|
|
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|
- const std::string & /*strAbsPath*/,
|
|
|
|
- ObjFile::Model *pModel ) :
|
|
|
|
- m_DataIt( buffer.begin() ),
|
|
|
|
- m_DataItEnd( buffer.end() ),
|
|
|
|
- m_pModel( pModel ),
|
|
|
|
- m_uiLine( 0 )
|
|
|
|
|
|
+ const std::string & /*strAbsPath*/,
|
|
|
|
+ ObjFile::Model *pModel ) :
|
|
|
|
+ m_DataIt( buffer.begin() ),
|
|
|
|
+ m_DataItEnd( buffer.end() ),
|
|
|
|
+ m_pModel( pModel ),
|
|
|
|
+ m_uiLine( 0 )
|
|
{
|
|
{
|
|
- ai_assert( NULL != m_pModel );
|
|
|
|
- if ( NULL == m_pModel->m_pDefaultMaterial )
|
|
|
|
- {
|
|
|
|
- m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
|
|
|
- m_pModel->m_pDefaultMaterial->MaterialName.Set( "default" );
|
|
|
|
- }
|
|
|
|
- load();
|
|
|
|
|
|
+ ai_assert( NULL != m_pModel );
|
|
|
|
+ if ( NULL == m_pModel->m_pDefaultMaterial )
|
|
|
|
+ {
|
|
|
|
+ m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
|
|
|
+ m_pModel->m_pDefaultMaterial->MaterialName.Set( "default" );
|
|
|
|
+ }
|
|
|
|
+ load();
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Destructor
|
|
// Destructor
|
|
ObjFileMtlImporter::~ObjFileMtlImporter()
|
|
ObjFileMtlImporter::~ObjFileMtlImporter()
|
|
{
|
|
{
|
|
- // empty
|
|
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Private copy constructor
|
|
// Private copy constructor
|
|
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & /* rOther */ )
|
|
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & /* rOther */ )
|
|
{
|
|
{
|
|
- // empty
|
|
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Private copy constructor
|
|
// Private copy constructor
|
|
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & /*rOther */ )
|
|
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & /*rOther */ )
|
|
{
|
|
{
|
|
- return *this;
|
|
|
|
|
|
+ return *this;
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Loads the material description
|
|
// Loads the material description
|
|
void ObjFileMtlImporter::load()
|
|
void ObjFileMtlImporter::load()
|
|
{
|
|
{
|
|
- if ( m_DataIt == m_DataItEnd )
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- while ( m_DataIt != m_DataItEnd )
|
|
|
|
- {
|
|
|
|
- switch (*m_DataIt)
|
|
|
|
- {
|
|
|
|
- case 'k':
|
|
|
|
- case 'K':
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- if (*m_DataIt == 'a') // Ambient color
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getColorRGBA( &m_pModel->m_pCurrentMaterial->ambient );
|
|
|
|
- }
|
|
|
|
- else if (*m_DataIt == 'd') // Diffuse color
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getColorRGBA( &m_pModel->m_pCurrentMaterial->diffuse );
|
|
|
|
- }
|
|
|
|
- else if (*m_DataIt == 's')
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getColorRGBA( &m_pModel->m_pCurrentMaterial->specular );
|
|
|
|
- }
|
|
|
|
- else if (*m_DataIt == 'e')
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getColorRGBA( &m_pModel->m_pCurrentMaterial->emissive );
|
|
|
|
- }
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 'd': // Alpha value
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getFloatValue( m_pModel->m_pCurrentMaterial->alpha );
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 'N':
|
|
|
|
- case 'n':
|
|
|
|
- {
|
|
|
|
- ++m_DataIt;
|
|
|
|
- switch(*m_DataIt)
|
|
|
|
- {
|
|
|
|
- case 's': // Specular exponent
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
|
|
|
- break;
|
|
|
|
- case 'i': // Index Of refraction
|
|
|
|
- ++m_DataIt;
|
|
|
|
- getFloatValue(m_pModel->m_pCurrentMaterial->ior);
|
|
|
|
- break;
|
|
|
|
- case 'e': // New material
|
|
|
|
- createMaterial();
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 'm': // Texture
|
|
|
|
- case 'b': // quick'n'dirty - for 'bump' sections
|
|
|
|
- {
|
|
|
|
- getTexture();
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 'i': // Illumination model
|
|
|
|
- {
|
|
|
|
- m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
- getIlluminationModel( m_pModel->m_pCurrentMaterial->illumination_model );
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- {
|
|
|
|
- m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if ( m_DataIt == m_DataItEnd )
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ while ( m_DataIt != m_DataItEnd )
|
|
|
|
+ {
|
|
|
|
+ switch (*m_DataIt)
|
|
|
|
+ {
|
|
|
|
+ case 'k':
|
|
|
|
+ case 'K':
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ if (*m_DataIt == 'a') // Ambient color
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getColorRGBA( &m_pModel->m_pCurrentMaterial->ambient );
|
|
|
|
+ }
|
|
|
|
+ else if (*m_DataIt == 'd') // Diffuse color
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getColorRGBA( &m_pModel->m_pCurrentMaterial->diffuse );
|
|
|
|
+ }
|
|
|
|
+ else if (*m_DataIt == 's')
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getColorRGBA( &m_pModel->m_pCurrentMaterial->specular );
|
|
|
|
+ }
|
|
|
|
+ else if (*m_DataIt == 'e')
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getColorRGBA( &m_pModel->m_pCurrentMaterial->emissive );
|
|
|
|
+ }
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'd': // Alpha value
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getFloatValue( m_pModel->m_pCurrentMaterial->alpha );
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'N':
|
|
|
|
+ case 'n':
|
|
|
|
+ {
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ switch(*m_DataIt)
|
|
|
|
+ {
|
|
|
|
+ case 's': // Specular exponent
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
|
|
|
+ break;
|
|
|
|
+ case 'i': // Index Of refraction
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ getFloatValue(m_pModel->m_pCurrentMaterial->ior);
|
|
|
|
+ break;
|
|
|
|
+ case 'e': // New material
|
|
|
|
+ createMaterial();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'm': // Texture
|
|
|
|
+ case 'b': // quick'n'dirty - for 'bump' sections
|
|
|
|
+ {
|
|
|
|
+ getTexture();
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'i': // Illumination model
|
|
|
|
+ {
|
|
|
|
+ m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
+ getIlluminationModel( m_pModel->m_pCurrentMaterial->illumination_model );
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ {
|
|
|
|
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Loads a color definition
|
|
// Loads a color definition
|
|
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|
{
|
|
{
|
|
- ai_assert( NULL != pColor );
|
|
|
|
-
|
|
|
|
- float r( 0.0f ), g( 0.0f ), b( 0.0f );
|
|
|
|
- m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, r );
|
|
|
|
- pColor->r = r;
|
|
|
|
-
|
|
|
|
|
|
+ ai_assert( NULL != pColor );
|
|
|
|
+
|
|
|
|
+ float r( 0.0f ), g( 0.0f ), b( 0.0f );
|
|
|
|
+ m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, r );
|
|
|
|
+ pColor->r = r;
|
|
|
|
+
|
|
// we have to check if color is default 0 with only one token
|
|
// we have to check if color is default 0 with only one token
|
|
if( !IsLineEnd( *m_DataIt ) ) {
|
|
if( !IsLineEnd( *m_DataIt ) ) {
|
|
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, g );
|
|
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, g );
|
|
@@ -240,107 +240,107 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|
// Loads the kind of illumination model.
|
|
// Loads the kind of illumination model.
|
|
void ObjFileMtlImporter::getIlluminationModel( int &illum_model )
|
|
void ObjFileMtlImporter::getIlluminationModel( int &illum_model )
|
|
{
|
|
{
|
|
- m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
|
|
|
- illum_model = atoi(m_buffer);
|
|
|
|
|
|
+ m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
|
|
|
+ illum_model = atoi(m_buffer);
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Loads a single float value.
|
|
// Loads a single float value.
|
|
void ObjFileMtlImporter::getFloatValue( float &value )
|
|
void ObjFileMtlImporter::getFloatValue( float &value )
|
|
{
|
|
{
|
|
- m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
|
|
|
- value = (float) fast_atof(m_buffer);
|
|
|
|
|
|
+ m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
|
|
|
+ value = (float) fast_atof(m_buffer);
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Creates a material from loaded data.
|
|
// Creates a material from loaded data.
|
|
void ObjFileMtlImporter::createMaterial()
|
|
void ObjFileMtlImporter::createMaterial()
|
|
{
|
|
{
|
|
- std::string line( "" );
|
|
|
|
|
|
+ std::string line( "" );
|
|
while( !IsLineEnd( *m_DataIt ) ) {
|
|
while( !IsLineEnd( *m_DataIt ) ) {
|
|
- line += *m_DataIt;
|
|
|
|
- ++m_DataIt;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::vector<std::string> token;
|
|
|
|
- const unsigned int numToken = tokenize<std::string>( line, token, " " );
|
|
|
|
- std::string name( "" );
|
|
|
|
- if ( numToken == 1 ) {
|
|
|
|
- name = AI_DEFAULT_MATERIAL_NAME;
|
|
|
|
- } else {
|
|
|
|
- name = token[ 1 ];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
|
|
|
|
- if ( m_pModel->m_MaterialMap.end() == it) {
|
|
|
|
- // New Material created
|
|
|
|
- m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
|
|
|
- m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
|
|
|
|
- m_pModel->m_MaterialLib.push_back( name );
|
|
|
|
- m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
|
|
|
|
- } else {
|
|
|
|
- // Use older material
|
|
|
|
- m_pModel->m_pCurrentMaterial = (*it).second;
|
|
|
|
- }
|
|
|
|
|
|
+ line += *m_DataIt;
|
|
|
|
+ ++m_DataIt;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std::vector<std::string> token;
|
|
|
|
+ const unsigned int numToken = tokenize<std::string>( line, token, " " );
|
|
|
|
+ std::string name( "" );
|
|
|
|
+ if ( numToken == 1 ) {
|
|
|
|
+ name = AI_DEFAULT_MATERIAL_NAME;
|
|
|
|
+ } else {
|
|
|
|
+ name = token[ 1 ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
|
|
|
|
+ if ( m_pModel->m_MaterialMap.end() == it) {
|
|
|
|
+ // New Material created
|
|
|
|
+ m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
|
|
|
+ m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
|
|
|
|
+ m_pModel->m_MaterialLib.push_back( name );
|
|
|
|
+ m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
|
|
|
|
+ } else {
|
|
|
|
+ // Use older material
|
|
|
|
+ m_pModel->m_pCurrentMaterial = (*it).second;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Gets a texture name from data.
|
|
// Gets a texture name from data.
|
|
void ObjFileMtlImporter::getTexture() {
|
|
void ObjFileMtlImporter::getTexture() {
|
|
- aiString *out( NULL );
|
|
|
|
- int clampIndex = -1;
|
|
|
|
-
|
|
|
|
- const char *pPtr( &(*m_DataIt) );
|
|
|
|
- if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), DiffuseTexture.size() ) ) {
|
|
|
|
- // Diffuse texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->texture;
|
|
|
|
- clampIndex = ObjFile::Material::TextureDiffuseType;
|
|
|
|
- } else if ( !ASSIMP_strincmp( pPtr,AmbientTexture.c_str(),AmbientTexture.size() ) ) {
|
|
|
|
- // Ambient texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
|
|
- clampIndex = ObjFile::Material::TextureAmbientType;
|
|
|
|
- } else if (!ASSIMP_strincmp( pPtr, SpecularTexture.c_str(), SpecularTexture.size())) {
|
|
|
|
- // Specular texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
|
|
|
- clampIndex = ObjFile::Material::TextureSpecularType;
|
|
|
|
- } else if ( !ASSIMP_strincmp( pPtr, OpacityTexture.c_str(), OpacityTexture.size() ) ) {
|
|
|
|
- // Opacity texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
|
|
|
- clampIndex = ObjFile::Material::TextureOpacityType;
|
|
|
|
- } else if (!ASSIMP_strincmp( pPtr, EmmissiveTexture.c_str(), EmmissiveTexture.size())) {
|
|
|
|
- // Emissive texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureEmissive;
|
|
|
|
- clampIndex = ObjFile::Material::TextureEmissiveType;
|
|
|
|
- } else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), BumpTexture1.size() ) ||
|
|
|
|
- !ASSIMP_strincmp( pPtr, BumpTexture2.c_str(), BumpTexture2.size() ) ||
|
|
|
|
- !ASSIMP_strincmp( pPtr, BumpTexture3.c_str(), BumpTexture3.size() ) ) {
|
|
|
|
- // Bump texture
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureBump;
|
|
|
|
- clampIndex = ObjFile::Material::TextureBumpType;
|
|
|
|
- } else if (!ASSIMP_strincmp( pPtr,NormalTexture.c_str(), NormalTexture.size())) {
|
|
|
|
- // Normal map
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
|
|
|
- clampIndex = ObjFile::Material::TextureNormalType;
|
|
|
|
- } else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) {
|
|
|
|
- // Displacement texture
|
|
|
|
- out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
|
|
|
- clampIndex = ObjFile::Material::TextureDispType;
|
|
|
|
- } else if (!ASSIMP_strincmp( pPtr, SpecularityTexture.c_str(),SpecularityTexture.size() ) ) {
|
|
|
|
- // Specularity scaling (glossiness)
|
|
|
|
- out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
|
|
|
- clampIndex = ObjFile::Material::TextureSpecularityType;
|
|
|
|
- } else {
|
|
|
|
- DefaultLogger::get()->error("OBJ/MTL: Encountered unknown texture type");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bool clamp = false;
|
|
|
|
- getTextureOption(clamp);
|
|
|
|
- m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
|
|
|
-
|
|
|
|
- std::string strTexture;
|
|
|
|
- m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, strTexture );
|
|
|
|
- out->Set( strTexture );
|
|
|
|
|
|
+ aiString *out( NULL );
|
|
|
|
+ int clampIndex = -1;
|
|
|
|
+
|
|
|
|
+ const char *pPtr( &(*m_DataIt) );
|
|
|
|
+ if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), DiffuseTexture.size() ) ) {
|
|
|
|
+ // Diffuse texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->texture;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureDiffuseType;
|
|
|
|
+ } else if ( !ASSIMP_strincmp( pPtr,AmbientTexture.c_str(),AmbientTexture.size() ) ) {
|
|
|
|
+ // Ambient texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureAmbientType;
|
|
|
|
+ } else if (!ASSIMP_strincmp( pPtr, SpecularTexture.c_str(), SpecularTexture.size())) {
|
|
|
|
+ // Specular texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureSpecularType;
|
|
|
|
+ } else if ( !ASSIMP_strincmp( pPtr, OpacityTexture.c_str(), OpacityTexture.size() ) ) {
|
|
|
|
+ // Opacity texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureOpacityType;
|
|
|
|
+ } else if (!ASSIMP_strincmp( pPtr, EmmissiveTexture.c_str(), EmmissiveTexture.size())) {
|
|
|
|
+ // Emissive texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureEmissive;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureEmissiveType;
|
|
|
|
+ } else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), BumpTexture1.size() ) ||
|
|
|
|
+ !ASSIMP_strincmp( pPtr, BumpTexture2.c_str(), BumpTexture2.size() ) ||
|
|
|
|
+ !ASSIMP_strincmp( pPtr, BumpTexture3.c_str(), BumpTexture3.size() ) ) {
|
|
|
|
+ // Bump texture
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureBump;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureBumpType;
|
|
|
|
+ } else if (!ASSIMP_strincmp( pPtr,NormalTexture.c_str(), NormalTexture.size())) {
|
|
|
|
+ // Normal map
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureNormalType;
|
|
|
|
+ } else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) {
|
|
|
|
+ // Displacement texture
|
|
|
|
+ out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureDispType;
|
|
|
|
+ } else if (!ASSIMP_strincmp( pPtr, SpecularityTexture.c_str(),SpecularityTexture.size() ) ) {
|
|
|
|
+ // Specularity scaling (glossiness)
|
|
|
|
+ out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureSpecularityType;
|
|
|
|
+ } else {
|
|
|
|
+ DefaultLogger::get()->error("OBJ/MTL: Encountered unknown texture type");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool clamp = false;
|
|
|
|
+ getTextureOption(clamp);
|
|
|
|
+ m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
|
|
|
+
|
|
|
|
+ std::string strTexture;
|
|
|
|
+ m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, strTexture );
|
|
|
|
+ out->Set( strTexture );
|
|
}
|
|
}
|
|
|
|
|
|
/* /////////////////////////////////////////////////////////////////////////////
|
|
/* /////////////////////////////////////////////////////////////////////////////
|
|
@@ -360,54 +360,54 @@ void ObjFileMtlImporter::getTexture() {
|
|
*/
|
|
*/
|
|
void ObjFileMtlImporter::getTextureOption(bool &clamp)
|
|
void ObjFileMtlImporter::getTextureOption(bool &clamp)
|
|
{
|
|
{
|
|
- m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
-
|
|
|
|
- //If there is any more texture option
|
|
|
|
- while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-')
|
|
|
|
- {
|
|
|
|
- const char *pPtr( &(*m_DataIt) );
|
|
|
|
- //skip option key and value
|
|
|
|
- int skipToken = 1;
|
|
|
|
-
|
|
|
|
- if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), ClampOption.size()))
|
|
|
|
- {
|
|
|
|
- DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
- char value[3];
|
|
|
|
- CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
|
|
|
- if (!ASSIMP_strincmp(value, "on", 2))
|
|
|
|
- {
|
|
|
|
- clamp = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- skipToken = 2;
|
|
|
|
- }
|
|
|
|
- else if ( !ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, TypeOption.c_str(), TypeOption.size()) )
|
|
|
|
- {
|
|
|
|
- skipToken = 2;
|
|
|
|
- }
|
|
|
|
- else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), ModifyMapOption.size()))
|
|
|
|
- {
|
|
|
|
- skipToken = 3;
|
|
|
|
- }
|
|
|
|
- else if ( !ASSIMP_strincmp(pPtr, OffsetOption.c_str(), OffsetOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), ScaleOption.size())
|
|
|
|
- || !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), TurbulenceOption.size())
|
|
|
|
- )
|
|
|
|
- {
|
|
|
|
- skipToken = 4;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < skipToken; ++i)
|
|
|
|
- {
|
|
|
|
- m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
+
|
|
|
|
+ //If there is any more texture option
|
|
|
|
+ while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-')
|
|
|
|
+ {
|
|
|
|
+ const char *pPtr( &(*m_DataIt) );
|
|
|
|
+ //skip option key and value
|
|
|
|
+ int skipToken = 1;
|
|
|
|
+
|
|
|
|
+ if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), ClampOption.size()))
|
|
|
|
+ {
|
|
|
|
+ DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
+ char value[3];
|
|
|
|
+ CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
|
|
|
+ if (!ASSIMP_strincmp(value, "on", 2))
|
|
|
|
+ {
|
|
|
|
+ clamp = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ skipToken = 2;
|
|
|
|
+ }
|
|
|
|
+ else if ( !ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, TypeOption.c_str(), TypeOption.size()) )
|
|
|
|
+ {
|
|
|
|
+ skipToken = 2;
|
|
|
|
+ }
|
|
|
|
+ else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), ModifyMapOption.size()))
|
|
|
|
+ {
|
|
|
|
+ skipToken = 3;
|
|
|
|
+ }
|
|
|
|
+ else if ( !ASSIMP_strincmp(pPtr, OffsetOption.c_str(), OffsetOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), ScaleOption.size())
|
|
|
|
+ || !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), TurbulenceOption.size())
|
|
|
|
+ )
|
|
|
|
+ {
|
|
|
|
+ skipToken = 4;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < skipToken; ++i)
|
|
|
|
+ {
|
|
|
|
+ m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|