color node handling opengex
Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/547/head
parent
ce939b5126
commit
995bc41d57
|
@ -45,12 +45,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "DefaultIOSystem.h"
|
||||
#include "ObjFileImporter.h"
|
||||
#include "ObjFileParser.h"
|
||||
#include "ObjFileData.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include "../include/assimp/Importer.hpp"
|
||||
#include "../include/assimp/scene.h"
|
||||
#include "../include/assimp/ai_assert.h"
|
||||
#include "../include/assimp/DefaultLogger.hpp"
|
||||
#include "ObjFileData.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include "../include/assimp/Importer.hpp"
|
||||
#include "../include/assimp/scene.h"
|
||||
#include "../include/assimp/ai_assert.h"
|
||||
#include "../include/assimp/DefaultLogger.hpp"
|
||||
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
|
|
|
@ -42,14 +42,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include "ObjFileMtlImporter.h"
|
||||
#include "ObjTools.h"
|
||||
#include "ObjFileData.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 {
|
||||
|
@ -86,147 +86,147 @@ static const std::string TypeOption = "-type";
|
|||
// -------------------------------------------------------------------
|
||||
// Constructor
|
||||
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
|
||||
ObjFileMtlImporter::~ObjFileMtlImporter()
|
||||
{
|
||||
// empty
|
||||
// empty
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private copy constructor
|
||||
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & /* rOther */ )
|
||||
{
|
||||
// empty
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private copy constructor
|
||||
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & /*rOther */ )
|
||||
{
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the material description
|
||||
void ObjFileMtlImporter::load()
|
||||
{
|
||||
if ( m_DataIt == m_DataItEnd )
|
||||
return;
|
||||
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;
|
||||
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 '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 '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 '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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a color definition
|
||||
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
|
||||
if( !IsLineEnd( *m_DataIt ) ) {
|
||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, g );
|
||||
|
@ -240,107 +240,107 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|||
// Loads the kind of illumination 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.
|
||||
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.
|
||||
void ObjFileMtlImporter::createMaterial()
|
||||
{
|
||||
std::string line( "" );
|
||||
std::string line( "" );
|
||||
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 ];
|
||||
}
|
||||
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;
|
||||
}
|
||||
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.
|
||||
void ObjFileMtlImporter::getTexture() {
|
||||
aiString *out( NULL );
|
||||
int clampIndex = -1;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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 );
|
||||
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)
|
||||
{
|
||||
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 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < skipToken; ++i)
|
||||
{
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
@ -48,11 +48,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "ObjFileData.h"
|
||||
#include "ParsingUtils.h"
|
||||
#include "../include/assimp/types.h"
|
||||
#include "DefaultIOSystem.h"
|
||||
#include "BaseImporter.h"
|
||||
#include "../include/assimp/DefaultLogger.hpp"
|
||||
#include "../include/assimp/material.h"
|
||||
#include "../include/assimp/Importer.hpp"
|
||||
#include "DefaultIOSystem.h"
|
||||
#include "BaseImporter.h"
|
||||
#include "../include/assimp/DefaultLogger.hpp"
|
||||
#include "../include/assimp/material.h"
|
||||
#include "../include/assimp/Importer.hpp"
|
||||
|
||||
|
||||
namespace Assimp {
|
||||
|
|
|
@ -79,6 +79,10 @@ namespace Grammar {
|
|||
static const char *IndexArrayType = "IndexArray";
|
||||
static const char *MaterialType = "Material";
|
||||
static const char *ColorType = "Color";
|
||||
static const std::string DiffuseColorToken = "diffuse";
|
||||
static const std::string SpecularColorToken = "specular";
|
||||
static const std::string EmissionColorToken = "emission";
|
||||
|
||||
static const char *TextureType = "Texture";
|
||||
|
||||
enum TokenType {
|
||||
|
@ -362,9 +366,9 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
|
|||
|
||||
Property *prop( node->getProperties() );
|
||||
while( NULL != prop ) {
|
||||
if( NULL != prop->m_id ) {
|
||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
||||
std::string valName( (char*) prop->m_primData->m_data );
|
||||
if( NULL != prop->m_key ) {
|
||||
if( Value::ddl_string == prop->m_value->m_type ) {
|
||||
std::string valName( ( char* ) prop->m_value->m_data );
|
||||
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
||||
if( Grammar::NoneType != type ) {
|
||||
Value *val( node->getValue() );
|
||||
|
@ -414,7 +418,7 @@ static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
|
|||
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
||||
Name *currentName( ref->m_referencedName[ i ] );
|
||||
if( NULL != currentName && NULL != currentName->m_id ) {
|
||||
const std::string name( currentName->m_id->m_buffer );
|
||||
const std::string name( currentName->m_id->m_text.m_buffer );
|
||||
if( !name.empty() ) {
|
||||
names.push_back( name );
|
||||
}
|
||||
|
@ -529,10 +533,10 @@ static void propId2StdString( Property *prop, std::string &name, std::string &ke
|
|||
return;
|
||||
}
|
||||
|
||||
if( NULL != prop->m_id ) {
|
||||
name = prop->m_id->m_buffer;
|
||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
||||
key = prop->m_primData->getString();
|
||||
if( NULL != prop->m_key ) {
|
||||
name = prop->m_key->m_text.m_buffer;
|
||||
if( Value::ddl_string == prop->m_value->m_type ) {
|
||||
key = prop->m_value->getString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +708,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
|
|||
Value *next( vaList->m_dataList );
|
||||
for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
|
||||
const int idx = next->getInt32();
|
||||
ai_assert( idx <= m_currentVertices.m_numVerts );
|
||||
ai_assert( static_cast<size_t>( idx ) <= m_currentVertices.m_numVerts );
|
||||
|
||||
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
|
||||
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
|
||||
|
@ -724,7 +728,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static void getColorRGBA( aiColor3D *pColor, Value *data ) {
|
||||
static void getColorRGB( aiColor3D *pColor, Value *data ) {
|
||||
if( NULL == pColor || NULL == data ) {
|
||||
return;
|
||||
}
|
||||
|
@ -740,14 +744,19 @@ static void getColorRGBA( aiColor3D *pColor, Value *data ) {
|
|||
//------------------------------------------------------------------------------------------------
|
||||
enum ColorType {
|
||||
NoneColor = 0,
|
||||
DiffuseColor
|
||||
DiffuseColor,
|
||||
SpecularColor,
|
||||
EmissionColor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static ColorType getColorType( Identifier *id ) {
|
||||
const int res(strncmp("diffuse", id->m_buffer, id->m_len ) );
|
||||
if( 0 == res ) {
|
||||
if( id->m_text == Grammar::DiffuseColorToken ) {
|
||||
return DiffuseColor;
|
||||
} else if( id->m_text == Grammar::SpecularColorToken ) {
|
||||
return SpecularColor;
|
||||
} else if( id->m_text == Grammar::EmissionColorToken ) {
|
||||
return EmissionColor;
|
||||
}
|
||||
|
||||
return NoneColor;
|
||||
|
@ -768,9 +777,19 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
|
|||
return;
|
||||
}
|
||||
|
||||
Property *colorProp = node->getProperties();
|
||||
if( NULL != colorProp ) {
|
||||
if( NULL != colorProp->m_id ) {
|
||||
Property *prop = node->findPropertyByName( "attrib" );
|
||||
if( NULL != prop ) {
|
||||
if( NULL != prop->m_value ) {
|
||||
aiColor3D col;
|
||||
getColorRGB( &col, prop->m_value );
|
||||
const ColorType colType( getColorType( prop->m_key ) );
|
||||
if( DiffuseColor == colType ) {
|
||||
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );
|
||||
} else if( SpecularColor == colType ) {
|
||||
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_SPECULAR );
|
||||
} else if( EmissionColor == colType ) {
|
||||
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_EMISSIVE );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -785,6 +804,7 @@ void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
|||
if( m_meshCache.empty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
pScene->mNumMeshes = m_meshCache.size();
|
||||
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
|
||||
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
||||
|
@ -828,13 +848,10 @@ void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
|
|||
if( m_root->m_children.empty() ) {
|
||||
return;
|
||||
}
|
||||
size_t i( 0 );
|
||||
|
||||
pScene->mRootNode->mNumChildren = m_root->m_children.size();
|
||||
pScene->mRootNode->mChildren = new C_STRUCT aiNode*[ pScene->mRootNode->mNumChildren ];
|
||||
for( ChildInfo::NodeList::iterator it = m_root->m_children.begin(); it != m_root->m_children.end(); it++ ) {
|
||||
pScene->mRootNode->mChildren[ i ] = *it;
|
||||
i++;
|
||||
}
|
||||
pScene->mRootNode->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren ];
|
||||
std::copy( m_root->m_children.begin(), m_root->m_children.end(), pScene->mRootNode->mChildren );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue