|
@@ -40,45 +40,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
----------------------------------------------------------------------
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
-
|
|
|
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
|
|
|
|
|
#include "OgreImporter.h"
|
|
|
+#include <assimp/StringUtils.h>
|
|
|
#include <assimp/TinyFormatter.h>
|
|
|
+#include <assimp/fast_atof.h>
|
|
|
#include <assimp/material.h>
|
|
|
#include <assimp/scene.h>
|
|
|
#include <assimp/DefaultLogger.hpp>
|
|
|
-#include <assimp/fast_atof.h>
|
|
|
|
|
|
-#include <vector>
|
|
|
-#include <sstream>
|
|
|
#include <memory>
|
|
|
+#include <sstream>
|
|
|
+#include <vector>
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
-namespace Assimp
|
|
|
-{
|
|
|
-namespace Ogre
|
|
|
-{
|
|
|
+namespace Assimp {
|
|
|
+namespace Ogre {
|
|
|
|
|
|
-static const string partComment = "//";
|
|
|
+static const string partComment = "//";
|
|
|
static const string partBlockStart = "{";
|
|
|
-static const string partBlockEnd = "}";
|
|
|
+static const string partBlockEnd = "}";
|
|
|
|
|
|
-void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, Mesh *mesh)
|
|
|
-{
|
|
|
- std::vector<aiMaterial*> materials;
|
|
|
+void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, Mesh *mesh) {
|
|
|
+ std::vector<aiMaterial *> materials;
|
|
|
|
|
|
// Create materials that can be found and parsed via the IOSystem.
|
|
|
- for (size_t i=0, len=mesh->NumSubMeshes(); i<len; ++i)
|
|
|
- {
|
|
|
+ for (size_t i = 0, len = mesh->NumSubMeshes(); i < len; ++i) {
|
|
|
SubMesh *submesh = mesh->GetSubMesh(i);
|
|
|
- if (submesh && !submesh->materialRef.empty())
|
|
|
- {
|
|
|
+ if (submesh && !submesh->materialRef.empty()) {
|
|
|
aiMaterial *material = ReadMaterial(pFile, pIOHandler, submesh->materialRef);
|
|
|
- if (material)
|
|
|
- {
|
|
|
+ if (material) {
|
|
|
submesh->materialIndex = static_cast<int>(materials.size());
|
|
|
materials.push_back(material);
|
|
|
}
|
|
@@ -88,19 +81,15 @@ void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIO
|
|
|
AssignMaterials(pScene, materials);
|
|
|
}
|
|
|
|
|
|
-void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, MeshXml *mesh)
|
|
|
-{
|
|
|
- std::vector<aiMaterial*> materials;
|
|
|
+void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, MeshXml *mesh) {
|
|
|
+ std::vector<aiMaterial *> materials;
|
|
|
|
|
|
// Create materials that can be found and parsed via the IOSystem.
|
|
|
- for (size_t i=0, len=mesh->NumSubMeshes(); i<len; ++i)
|
|
|
- {
|
|
|
- SubMeshXml *submesh = mesh->GetSubMesh( static_cast<uint16_t>(i));
|
|
|
- if (submesh && !submesh->materialRef.empty())
|
|
|
- {
|
|
|
+ for (size_t i = 0, len = mesh->NumSubMeshes(); i < len; ++i) {
|
|
|
+ SubMeshXml *submesh = mesh->GetSubMesh(static_cast<uint16_t>(i));
|
|
|
+ if (submesh && !submesh->materialRef.empty()) {
|
|
|
aiMaterial *material = ReadMaterial(pFile, pIOHandler, submesh->materialRef);
|
|
|
- if (material)
|
|
|
- {
|
|
|
+ if (material) {
|
|
|
submesh->materialIndex = static_cast<int>(materials.size());
|
|
|
materials.push_back(material);
|
|
|
}
|
|
@@ -110,20 +99,17 @@ void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIO
|
|
|
AssignMaterials(pScene, materials);
|
|
|
}
|
|
|
|
|
|
-void OgreImporter::AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &materials)
|
|
|
-{
|
|
|
+void OgreImporter::AssignMaterials(aiScene *pScene, std::vector<aiMaterial *> &materials) {
|
|
|
pScene->mNumMaterials = static_cast<unsigned int>(materials.size());
|
|
|
- if (pScene->mNumMaterials > 0)
|
|
|
- {
|
|
|
- pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
|
|
- for(size_t i=0;i<pScene->mNumMaterials; ++i) {
|
|
|
+ if (pScene->mNumMaterials > 0) {
|
|
|
+ pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
|
|
|
+ for (size_t i = 0; i < pScene->mNumMaterials; ++i) {
|
|
|
pScene->mMaterials[i] = materials[i];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string &materialName)
|
|
|
-{
|
|
|
+aiMaterial *OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string &materialName) {
|
|
|
if (materialName.empty()) {
|
|
|
return 0;
|
|
|
}
|
|
@@ -169,24 +155,21 @@ aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSyste
|
|
|
potentialFiles.push_back(m_userDefinedMaterialLibFile);
|
|
|
|
|
|
IOStream *materialFile = 0;
|
|
|
- for(size_t i=0; i<potentialFiles.size(); ++i)
|
|
|
- {
|
|
|
+ for (size_t i = 0; i < potentialFiles.size(); ++i) {
|
|
|
materialFile = pIOHandler->Open(potentialFiles[i]);
|
|
|
if (materialFile) {
|
|
|
break;
|
|
|
}
|
|
|
- ASSIMP_LOG_VERBOSE_DEBUG_F( "Source file for material '", materialName, "' ", potentialFiles[i], " does not exist");
|
|
|
+ ASSIMP_LOG_VERBOSE_DEBUG_F("Source file for material '", materialName, "' ", potentialFiles[i], " does not exist");
|
|
|
}
|
|
|
- if (!materialFile)
|
|
|
- {
|
|
|
- ASSIMP_LOG_ERROR_F( "Failed to find source file for material '", materialName, "'");
|
|
|
+ if (!materialFile) {
|
|
|
+ ASSIMP_LOG_ERROR_F("Failed to find source file for material '", materialName, "'");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
std::unique_ptr<IOStream> stream(materialFile);
|
|
|
- if (stream->FileSize() == 0)
|
|
|
- {
|
|
|
- ASSIMP_LOG_WARN_F( "Source file for material '", materialName, "' is empty (size is 0 bytes)");
|
|
|
+ if (stream->FileSize() == 0) {
|
|
|
+ ASSIMP_LOG_WARN_F("Source file for material '", materialName, "' is empty (size is 0 bytes)");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -214,48 +197,41 @@ aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSyste
|
|
|
string linePart;
|
|
|
ss >> linePart;
|
|
|
|
|
|
- const string partMaterial = "material";
|
|
|
- const string partTechnique = "technique";
|
|
|
+ const string partMaterial = "material";
|
|
|
+ const string partTechnique = "technique";
|
|
|
|
|
|
- while(!ss.eof())
|
|
|
- {
|
|
|
+ while (!ss.eof()) {
|
|
|
// Skip commented lines
|
|
|
- if (linePart == partComment)
|
|
|
- {
|
|
|
+ if (linePart == partComment) {
|
|
|
NextAfterNewLine(ss, linePart);
|
|
|
continue;
|
|
|
}
|
|
|
- if (linePart != partMaterial)
|
|
|
- {
|
|
|
+ if (linePart != partMaterial) {
|
|
|
ss >> linePart;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
ss >> linePart;
|
|
|
- if (linePart != materialName)
|
|
|
- {
|
|
|
+ if (linePart != materialName) {
|
|
|
ss >> linePart;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
NextAfterNewLine(ss, linePart);
|
|
|
- if (linePart != partBlockStart)
|
|
|
- {
|
|
|
- ASSIMP_LOG_ERROR_F( "Invalid material: block start missing near index ", ss.tellg());
|
|
|
+ if (linePart != partBlockStart) {
|
|
|
+ ASSIMP_LOG_ERROR_F("Invalid material: block start missing near index ", ss.tellg());
|
|
|
return material;
|
|
|
}
|
|
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG_F("material '", materialName, "'");
|
|
|
|
|
|
- while(linePart != partBlockEnd)
|
|
|
- {
|
|
|
+ while (linePart != partBlockEnd) {
|
|
|
// Proceed to the first technique
|
|
|
ss >> linePart;
|
|
|
|
|
|
- if (linePart == partTechnique)
|
|
|
- {
|
|
|
- string techniqueName = SkipLine(ss);
|
|
|
- ReadTechnique(Trim(techniqueName), ss, material);
|
|
|
+ if (linePart == partTechnique) {
|
|
|
+ std::string techniqueName = SkipLine(ss);
|
|
|
+ ReadTechnique(ai_trim(techniqueName), ss, material);
|
|
|
}
|
|
|
|
|
|
// Read information from a custom material
|
|
@@ -264,71 +240,51 @@ aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSyste
|
|
|
parent texture unit name in your cloned material.
|
|
|
This is not yet supported and below code is probably some hack from the original
|
|
|
author of this Ogre importer. Should be removed? */
|
|
|
- if (linePart=="set")
|
|
|
- {
|
|
|
+ if (linePart == "set") {
|
|
|
ss >> linePart;
|
|
|
- if (linePart=="$specular")//todo load this values:
|
|
|
- {
|
|
|
- }
|
|
|
- else if (linePart=="$diffuse")
|
|
|
- {
|
|
|
- }
|
|
|
- else if (linePart=="$ambient")
|
|
|
- {
|
|
|
- }
|
|
|
- else if (linePart=="$colormap")
|
|
|
+ if (linePart == "$specular") //todo load this values:
|
|
|
{
|
|
|
+ } else if (linePart == "$diffuse") {
|
|
|
+ } else if (linePart == "$ambient") {
|
|
|
+ } else if (linePart == "$colormap") {
|
|
|
ss >> linePart;
|
|
|
aiString cm(linePart);
|
|
|
material->AddProperty(&cm, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
|
|
|
- }
|
|
|
- else if (linePart=="$normalmap")
|
|
|
- {
|
|
|
+ } else if (linePart == "$normalmap") {
|
|
|
ss >> linePart;
|
|
|
aiString nm(linePart);
|
|
|
material->AddProperty(&nm, AI_MATKEY_TEXTURE(aiTextureType_NORMALS, 0));
|
|
|
- }
|
|
|
- else if (linePart=="$shininess_strength")
|
|
|
- {
|
|
|
+ } else if (linePart == "$shininess_strength") {
|
|
|
ss >> linePart;
|
|
|
float Shininess = fast_atof(linePart.c_str());
|
|
|
material->AddProperty(&Shininess, 1, AI_MATKEY_SHININESS_STRENGTH);
|
|
|
- }
|
|
|
- else if (linePart=="$shininess_exponent")
|
|
|
- {
|
|
|
+ } else if (linePart == "$shininess_exponent") {
|
|
|
ss >> linePart;
|
|
|
float Shininess = fast_atof(linePart.c_str());
|
|
|
material->AddProperty(&Shininess, 1, AI_MATKEY_SHININESS);
|
|
|
}
|
|
|
//Properties from Venetica:
|
|
|
- else if (linePart=="$diffuse_map")
|
|
|
- {
|
|
|
+ else if (linePart == "$diffuse_map") {
|
|
|
ss >> linePart;
|
|
|
- if (linePart[0] == '"')// "file" -> file
|
|
|
- linePart = linePart.substr(1, linePart.size()-2);
|
|
|
+ if (linePart[0] == '"') // "file" -> file
|
|
|
+ linePart = linePart.substr(1, linePart.size() - 2);
|
|
|
aiString ts(linePart);
|
|
|
material->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
|
|
|
- }
|
|
|
- else if (linePart=="$specular_map")
|
|
|
- {
|
|
|
+ } else if (linePart == "$specular_map") {
|
|
|
ss >> linePart;
|
|
|
- if (linePart[0] == '"')// "file" -> file
|
|
|
- linePart = linePart.substr(1, linePart.size()-2);
|
|
|
+ if (linePart[0] == '"') // "file" -> file
|
|
|
+ linePart = linePart.substr(1, linePart.size() - 2);
|
|
|
aiString ts(linePart);
|
|
|
material->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_SHININESS, 0));
|
|
|
- }
|
|
|
- else if (linePart=="$normal_map")
|
|
|
- {
|
|
|
+ } else if (linePart == "$normal_map") {
|
|
|
ss >> linePart;
|
|
|
- if (linePart[0]=='"')// "file" -> file
|
|
|
- linePart = linePart.substr(1, linePart.size()-2);
|
|
|
+ if (linePart[0] == '"') // "file" -> file
|
|
|
+ linePart = linePart.substr(1, linePart.size() - 2);
|
|
|
aiString ts(linePart);
|
|
|
material->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_NORMALS, 0));
|
|
|
- }
|
|
|
- else if (linePart=="$light_map")
|
|
|
- {
|
|
|
+ } else if (linePart == "$light_map") {
|
|
|
ss >> linePart;
|
|
|
- if (linePart[0]=='"') {
|
|
|
+ if (linePart[0] == '"') {
|
|
|
linePart = linePart.substr(1, linePart.size() - 2);
|
|
|
}
|
|
|
aiString ts(linePart);
|
|
@@ -342,216 +298,166 @@ aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSyste
|
|
|
return material;
|
|
|
}
|
|
|
|
|
|
-bool OgreImporter::ReadTechnique(const std::string &techniqueName, stringstream &ss, aiMaterial *material)
|
|
|
-{
|
|
|
+bool OgreImporter::ReadTechnique(const std::string &techniqueName, stringstream &ss, aiMaterial *material) {
|
|
|
string linePart;
|
|
|
ss >> linePart;
|
|
|
|
|
|
- if (linePart != partBlockStart)
|
|
|
- {
|
|
|
- ASSIMP_LOG_ERROR_F( "Invalid material: Technique block start missing near index ", ss.tellg());
|
|
|
+ if (linePart != partBlockStart) {
|
|
|
+ ASSIMP_LOG_ERROR_F("Invalid material: Technique block start missing near index ", ss.tellg());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG_F(" technique '", techniqueName, "'");
|
|
|
|
|
|
- const string partPass = "pass";
|
|
|
+ const string partPass = "pass";
|
|
|
|
|
|
- while(linePart != partBlockEnd)
|
|
|
- {
|
|
|
+ while (linePart != partBlockEnd) {
|
|
|
ss >> linePart;
|
|
|
|
|
|
// Skip commented lines
|
|
|
- if (linePart == partComment)
|
|
|
- {
|
|
|
+ if (linePart == partComment) {
|
|
|
SkipLine(ss);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
/// @todo Techniques have other attributes than just passes.
|
|
|
- if (linePart == partPass)
|
|
|
- {
|
|
|
+ if (linePart == partPass) {
|
|
|
string passName = SkipLine(ss);
|
|
|
- ReadPass(Trim(passName), ss, material);
|
|
|
+ ReadPass(ai_trim(passName), ss, material);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool OgreImporter::ReadPass(const std::string &passName, stringstream &ss, aiMaterial *material)
|
|
|
-{
|
|
|
+bool OgreImporter::ReadPass(const std::string &passName, stringstream &ss, aiMaterial *material) {
|
|
|
string linePart;
|
|
|
ss >> linePart;
|
|
|
|
|
|
- if (linePart != partBlockStart)
|
|
|
- {
|
|
|
- ASSIMP_LOG_ERROR_F( "Invalid material: Pass block start missing near index ", ss.tellg());
|
|
|
+ if (linePart != partBlockStart) {
|
|
|
+ ASSIMP_LOG_ERROR_F("Invalid material: Pass block start missing near index ", ss.tellg());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG_F(" pass '", passName, "'");
|
|
|
|
|
|
- const string partAmbient = "ambient";
|
|
|
- const string partDiffuse = "diffuse";
|
|
|
- const string partSpecular = "specular";
|
|
|
- const string partEmissive = "emissive";
|
|
|
+ const string partAmbient = "ambient";
|
|
|
+ const string partDiffuse = "diffuse";
|
|
|
+ const string partSpecular = "specular";
|
|
|
+ const string partEmissive = "emissive";
|
|
|
const string partTextureUnit = "texture_unit";
|
|
|
|
|
|
- while(linePart != partBlockEnd)
|
|
|
- {
|
|
|
+ while (linePart != partBlockEnd) {
|
|
|
ss >> linePart;
|
|
|
|
|
|
// Skip commented lines
|
|
|
- if (linePart == partComment)
|
|
|
- {
|
|
|
+ if (linePart == partComment) {
|
|
|
SkipLine(ss);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// Colors
|
|
|
/// @todo Support alpha via aiColor4D.
|
|
|
- if (linePart == partAmbient || linePart == partDiffuse || linePart == partSpecular || linePart == partEmissive)
|
|
|
- {
|
|
|
+ if (linePart == partAmbient || linePart == partDiffuse || linePart == partSpecular || linePart == partEmissive) {
|
|
|
float r, g, b;
|
|
|
ss >> r >> g >> b;
|
|
|
const aiColor3D color(r, g, b);
|
|
|
|
|
|
- ASSIMP_LOG_VERBOSE_DEBUG_F( " ", linePart, " ", r, " ", g, " ", b);
|
|
|
+ ASSIMP_LOG_VERBOSE_DEBUG_F(" ", linePart, " ", r, " ", g, " ", b);
|
|
|
|
|
|
- if (linePart == partAmbient)
|
|
|
- {
|
|
|
+ if (linePart == partAmbient) {
|
|
|
material->AddProperty(&color, 1, AI_MATKEY_COLOR_AMBIENT);
|
|
|
- }
|
|
|
- else if (linePart == partDiffuse)
|
|
|
- {
|
|
|
+ } else if (linePart == partDiffuse) {
|
|
|
material->AddProperty(&color, 1, AI_MATKEY_COLOR_DIFFUSE);
|
|
|
- }
|
|
|
- else if (linePart == partSpecular)
|
|
|
- {
|
|
|
+ } else if (linePart == partSpecular) {
|
|
|
material->AddProperty(&color, 1, AI_MATKEY_COLOR_SPECULAR);
|
|
|
- }
|
|
|
- else if (linePart == partEmissive)
|
|
|
- {
|
|
|
+ } else if (linePart == partEmissive) {
|
|
|
material->AddProperty(&color, 1, AI_MATKEY_COLOR_EMISSIVE);
|
|
|
}
|
|
|
- }
|
|
|
- else if (linePart == partTextureUnit)
|
|
|
- {
|
|
|
+ } else if (linePart == partTextureUnit) {
|
|
|
string textureUnitName = SkipLine(ss);
|
|
|
- ReadTextureUnit(Trim(textureUnitName), ss, material);
|
|
|
+ ReadTextureUnit(ai_trim(textureUnitName), ss, material);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstream &ss, aiMaterial *material)
|
|
|
-{
|
|
|
+bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstream &ss, aiMaterial *material) {
|
|
|
string linePart;
|
|
|
ss >> linePart;
|
|
|
|
|
|
- if (linePart != partBlockStart)
|
|
|
- {
|
|
|
- ASSIMP_LOG_ERROR_F( "Invalid material: Texture unit block start missing near index ", ss.tellg());
|
|
|
+ if (linePart != partBlockStart) {
|
|
|
+ ASSIMP_LOG_ERROR_F("Invalid material: Texture unit block start missing near index ", ss.tellg());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG_F(" texture_unit '", textureUnitName, "'");
|
|
|
|
|
|
- const string partTexture = "texture";
|
|
|
+ const string partTexture = "texture";
|
|
|
const string partTextCoordSet = "tex_coord_set";
|
|
|
- const string partColorOp = "colour_op";
|
|
|
+ const string partColorOp = "colour_op";
|
|
|
|
|
|
aiTextureType textureType = aiTextureType_NONE;
|
|
|
std::string textureRef;
|
|
|
int uvCoord = 0;
|
|
|
|
|
|
- while(linePart != partBlockEnd)
|
|
|
- {
|
|
|
+ while (linePart != partBlockEnd) {
|
|
|
ss >> linePart;
|
|
|
|
|
|
// Skip commented lines
|
|
|
- if (linePart == partComment)
|
|
|
- {
|
|
|
+ if (linePart == partComment) {
|
|
|
SkipLine(ss);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (linePart == partTexture)
|
|
|
- {
|
|
|
+ if (linePart == partTexture) {
|
|
|
ss >> linePart;
|
|
|
textureRef = linePart;
|
|
|
|
|
|
// User defined Assimp config property to detect texture type from filename.
|
|
|
- if (m_detectTextureTypeFromFilename)
|
|
|
- {
|
|
|
+ if (m_detectTextureTypeFromFilename) {
|
|
|
size_t posSuffix = textureRef.find_last_of(".");
|
|
|
size_t posUnderscore = textureRef.find_last_of("_");
|
|
|
|
|
|
- if (posSuffix != string::npos && posUnderscore != string::npos && posSuffix > posUnderscore)
|
|
|
- {
|
|
|
- string identifier = Ogre::ToLower(textureRef.substr(posUnderscore, posSuffix - posUnderscore));
|
|
|
- ASSIMP_LOG_VERBOSE_DEBUG_F( "Detecting texture type from filename postfix '", identifier, "'");
|
|
|
+ if (posSuffix != string::npos && posUnderscore != string::npos && posSuffix > posUnderscore) {
|
|
|
+ string identifier = ai_str_tolower(textureRef.substr(posUnderscore, posSuffix - posUnderscore));
|
|
|
+ ASSIMP_LOG_VERBOSE_DEBUG_F("Detecting texture type from filename postfix '", identifier, "'");
|
|
|
|
|
|
- if (identifier == "_n" || identifier == "_nrm" || identifier == "_nrml" || identifier == "_normal" || identifier == "_normals" || identifier == "_normalmap")
|
|
|
- {
|
|
|
+ if (identifier == "_n" || identifier == "_nrm" || identifier == "_nrml" || identifier == "_normal" || identifier == "_normals" || identifier == "_normalmap") {
|
|
|
textureType = aiTextureType_NORMALS;
|
|
|
- }
|
|
|
- else if (identifier == "_s" || identifier == "_spec" || identifier == "_specular" || identifier == "_specularmap")
|
|
|
- {
|
|
|
+ } else if (identifier == "_s" || identifier == "_spec" || identifier == "_specular" || identifier == "_specularmap") {
|
|
|
textureType = aiTextureType_SPECULAR;
|
|
|
- }
|
|
|
- else if (identifier == "_l" || identifier == "_light" || identifier == "_lightmap" || identifier == "_occ" || identifier == "_occlusion")
|
|
|
- {
|
|
|
+ } else if (identifier == "_l" || identifier == "_light" || identifier == "_lightmap" || identifier == "_occ" || identifier == "_occlusion") {
|
|
|
textureType = aiTextureType_LIGHTMAP;
|
|
|
- }
|
|
|
- else if (identifier == "_disp" || identifier == "_displacement")
|
|
|
- {
|
|
|
+ } else if (identifier == "_disp" || identifier == "_displacement") {
|
|
|
textureType = aiTextureType_DISPLACEMENT;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
textureType = aiTextureType_DIFFUSE;
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
textureType = aiTextureType_DIFFUSE;
|
|
|
}
|
|
|
}
|
|
|
// Detect from texture unit name. This cannot be too broad as
|
|
|
// authors might give names like "LightSaber" or "NormalNinja".
|
|
|
- else
|
|
|
- {
|
|
|
- string unitNameLower = Ogre::ToLower(textureUnitName);
|
|
|
- if (unitNameLower.find("normalmap") != string::npos)
|
|
|
- {
|
|
|
+ else {
|
|
|
+ string unitNameLower = ai_str_tolower(textureUnitName);
|
|
|
+ if (unitNameLower.find("normalmap") != string::npos) {
|
|
|
textureType = aiTextureType_NORMALS;
|
|
|
- }
|
|
|
- else if (unitNameLower.find("specularmap") != string::npos)
|
|
|
- {
|
|
|
+ } else if (unitNameLower.find("specularmap") != string::npos) {
|
|
|
textureType = aiTextureType_SPECULAR;
|
|
|
- }
|
|
|
- else if (unitNameLower.find("lightmap") != string::npos)
|
|
|
- {
|
|
|
+ } else if (unitNameLower.find("lightmap") != string::npos) {
|
|
|
textureType = aiTextureType_LIGHTMAP;
|
|
|
- }
|
|
|
- else if (unitNameLower.find("displacementmap") != string::npos)
|
|
|
- {
|
|
|
+ } else if (unitNameLower.find("displacementmap") != string::npos) {
|
|
|
textureType = aiTextureType_DISPLACEMENT;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
textureType = aiTextureType_DIFFUSE;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else if (linePart == partTextCoordSet)
|
|
|
- {
|
|
|
+ } else if (linePart == partTextCoordSet) {
|
|
|
ss >> uvCoord;
|
|
|
}
|
|
|
/// @todo Implement
|
|
|
- else if(linePart == partColorOp)
|
|
|
- {
|
|
|
+ else if (linePart == partColorOp) {
|
|
|
/*
|
|
|
ss >> linePart;
|
|
|
if("replace"==linePart)//I don't think, assimp has something for this...
|
|
@@ -566,22 +472,20 @@ bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (textureRef.empty())
|
|
|
- {
|
|
|
+ if (textureRef.empty()) {
|
|
|
ASSIMP_LOG_WARN("Texture reference is empty, ignoring texture_unit.");
|
|
|
return false;
|
|
|
}
|
|
|
- if (textureType == aiTextureType_NONE)
|
|
|
- {
|
|
|
- ASSIMP_LOG_WARN("Failed to detect texture type for '" + textureRef + "', ignoring texture_unit.");
|
|
|
+ if (textureType == aiTextureType_NONE) {
|
|
|
+ ASSIMP_LOG_WARN("Failed to detect texture type for '" + textureRef + "', ignoring texture_unit.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
unsigned int textureTypeIndex = m_textures[textureType];
|
|
|
m_textures[textureType]++;
|
|
|
|
|
|
- ASSIMP_LOG_VERBOSE_DEBUG_F( " texture '", textureRef, "' type ", textureType,
|
|
|
- " index ", textureTypeIndex, " UV ", uvCoord);
|
|
|
+ ASSIMP_LOG_VERBOSE_DEBUG_F(" texture '", textureRef, "' type ", textureType,
|
|
|
+ " index ", textureTypeIndex, " UV ", uvCoord);
|
|
|
|
|
|
aiString assimpTextureRef(textureRef);
|
|
|
material->AddProperty(&assimpTextureRef, AI_MATKEY_TEXTURE(textureType, textureTypeIndex));
|
|
@@ -590,7 +494,7 @@ bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstr
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-} // Ogre
|
|
|
-} // Assimp
|
|
|
+} // namespace Ogre
|
|
|
+} // namespace Assimp
|
|
|
|
|
|
#endif // ASSIMP_BUILD_NO_OGRE_IMPORTER
|