|
@@ -61,6 +61,22 @@ static const std::string NormalTexture = "map_Kn";
|
|
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";
|
|
|
|
|
|
|
|
+// texture option specific token
|
|
|
|
+static const std::string BlendUOption = "-blendu";
|
|
|
|
+static const std::string BlendVOption = "-blendv";
|
|
|
|
+static const std::string BoostOption = "-boost";
|
|
|
|
+static const std::string ModifyMapOption = "-mm";
|
|
|
|
+static const std::string OffsetOption = "-o";
|
|
|
|
+static const std::string ScaleOption = "-s";
|
|
|
|
+static const std::string TurbulenceOption = "-t";
|
|
|
|
+static const std::string ResolutionOption = "-texres";
|
|
|
|
+static const std::string ClampOption = "-clamp";
|
|
|
|
+static const std::string BumpOption = "-bm";
|
|
|
|
+static const std::string ChannelOption = "-imfchan";
|
|
|
|
+static const std::string TypeOption = "-type";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
// Constructor
|
|
// Constructor
|
|
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|
@@ -263,47 +279,128 @@ void ObjFileMtlImporter::createMaterial()
|
|
// Gets a texture name from data.
|
|
// Gets a texture name from data.
|
|
void ObjFileMtlImporter::getTexture() {
|
|
void ObjFileMtlImporter::getTexture() {
|
|
aiString *out( NULL );
|
|
aiString *out( NULL );
|
|
|
|
+ int clampIndex = -1;
|
|
|
|
|
|
const char *pPtr( &(*m_DataIt) );
|
|
const char *pPtr( &(*m_DataIt) );
|
|
if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), DiffuseTexture.size() ) ) {
|
|
if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), DiffuseTexture.size() ) ) {
|
|
// Diffuse texture
|
|
// Diffuse texture
|
|
out = & m_pModel->m_pCurrentMaterial->texture;
|
|
out = & m_pModel->m_pCurrentMaterial->texture;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureDiffuseType;
|
|
} else if ( !ASSIMP_strincmp( pPtr,AmbientTexture.c_str(),AmbientTexture.size() ) ) {
|
|
} else if ( !ASSIMP_strincmp( pPtr,AmbientTexture.c_str(),AmbientTexture.size() ) ) {
|
|
// Ambient texture
|
|
// Ambient texture
|
|
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureAmbientType;
|
|
} else if (!ASSIMP_strincmp( pPtr, SpecularTexture.c_str(), SpecularTexture.size())) {
|
|
} else if (!ASSIMP_strincmp( pPtr, SpecularTexture.c_str(), SpecularTexture.size())) {
|
|
// Specular texture
|
|
// Specular texture
|
|
out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
|
out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureSpecularType;
|
|
} else if ( !ASSIMP_strincmp( pPtr, OpacityTexture.c_str(), OpacityTexture.size() ) ) {
|
|
} else if ( !ASSIMP_strincmp( pPtr, OpacityTexture.c_str(), OpacityTexture.size() ) ) {
|
|
// Opacity texture
|
|
// Opacity texture
|
|
out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
|
out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureOpacityType;
|
|
} else if (!ASSIMP_strincmp( pPtr,"map_ka",6)) {
|
|
} else if (!ASSIMP_strincmp( pPtr,"map_ka",6)) {
|
|
// Ambient texture
|
|
// Ambient texture
|
|
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureAmbientType;
|
|
} else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), BumpTexture1.size() ) ||
|
|
} else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), BumpTexture1.size() ) ||
|
|
!ASSIMP_strincmp( pPtr, BumpTexture2.c_str(), BumpTexture2.size() ) ||
|
|
!ASSIMP_strincmp( pPtr, BumpTexture2.c_str(), BumpTexture2.size() ) ||
|
|
!ASSIMP_strincmp( pPtr, BumpTexture3.c_str(), BumpTexture3.size() ) ) {
|
|
!ASSIMP_strincmp( pPtr, BumpTexture3.c_str(), BumpTexture3.size() ) ) {
|
|
// Bump texture
|
|
// Bump texture
|
|
out = & m_pModel->m_pCurrentMaterial->textureBump;
|
|
out = & m_pModel->m_pCurrentMaterial->textureBump;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureBumpType;
|
|
} else if (!ASSIMP_strincmp( pPtr,NormalTexture.c_str(), NormalTexture.size())) {
|
|
} else if (!ASSIMP_strincmp( pPtr,NormalTexture.c_str(), NormalTexture.size())) {
|
|
// Normal map
|
|
// Normal map
|
|
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
|
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureNormalType;
|
|
} 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;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureDispType;
|
|
} else if (!ASSIMP_strincmp( pPtr, SpecularityTexture.c_str(),SpecularityTexture.size() ) ) {
|
|
} else if (!ASSIMP_strincmp( pPtr, SpecularityTexture.c_str(),SpecularityTexture.size() ) ) {
|
|
// Specularity scaling (glossiness)
|
|
// Specularity scaling (glossiness)
|
|
out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
|
out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
|
|
|
+ clampIndex = ObjFile::Material::TextureSpecularityType;
|
|
} else {
|
|
} else {
|
|
DefaultLogger::get()->error("OBJ/MTL: Encountered unknown texture type");
|
|
DefaultLogger::get()->error("OBJ/MTL: Encountered unknown texture type");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ bool clamp = false;
|
|
|
|
+ getTextureOption(clamp);
|
|
|
|
+ m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
|
|
|
+
|
|
std::string strTexture;
|
|
std::string strTexture;
|
|
m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, strTexture );
|
|
m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, strTexture );
|
|
out->Set( strTexture );
|
|
out->Set( strTexture );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* /////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ * Texture Option
|
|
|
|
+ * /////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ * According to http://en.wikipedia.org/wiki/Wavefront_.obj_file#Texture_options
|
|
|
|
+ * Texture map statement can contains various texture option, for example:
|
|
|
|
+ *
|
|
|
|
+ * map_Ka -o 1 1 1 some.png
|
|
|
|
+ * map_Kd -clamp on some.png
|
|
|
|
+ *
|
|
|
|
+ * So we need to parse and skip these options, and leave the last part which is
|
|
|
|
+ * the url of image, otherwise we will get a wrong url like "-clamp on some.png".
|
|
|
|
+ *
|
|
|
|
+ * Because aiMaterial supports clamp option, so we also want to return it
|
|
|
|
+ * /////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ */
|
|
|
|
+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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// -------------------------------------------------------------------
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
} // Namespace Assimp
|
|
} // Namespace Assimp
|