diff options
Diffstat (limited to 'src/3rdparty/assimp/code/XGLLoader.cpp')
-rw-r--r-- | src/3rdparty/assimp/code/XGLLoader.cpp | 120 |
1 files changed, 64 insertions, 56 deletions
diff --git a/src/3rdparty/assimp/code/XGLLoader.cpp b/src/3rdparty/assimp/code/XGLLoader.cpp index fafad2f66..8ef91afac 100644 --- a/src/3rdparty/assimp/code/XGLLoader.cpp +++ b/src/3rdparty/assimp/code/XGLLoader.cpp @@ -3,7 +3,8 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2016, assimp team +Copyright (c) 2006-2017, assimp team + All rights reserved. @@ -52,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "MemoryIOWrapper.h" #include <assimp/mesh.h> #include <assimp/scene.h> +#include <assimp/importerdesc.h> #include <cctype> #include <memory> @@ -81,8 +83,11 @@ struct free_it }; namespace Assimp { // this has to be in here because LogFunctions is in ::Assimp -template<> const std::string LogFunctions<XGLImporter>::log_prefix = "XGL: "; - + template<> const char* LogFunctions<XGLImporter>::Prefix() + { + static auto prefix = "XGL: "; + return prefix; + } } static const aiImporterDesc desc = { @@ -102,12 +107,16 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer XGLImporter::XGLImporter() -{} +: m_reader( nullptr ) +, m_scene( nullptr ) { + // empty +} // ------------------------------------------------------------------------------------------------ // Destructor, private as well -XGLImporter::~XGLImporter() -{} +XGLImporter::~XGLImporter() { + // empty +} // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. @@ -149,7 +158,7 @@ void XGLImporter::InternReadFile( const std::string& pFile, free_it free_it_really(dest); #endif - scene = pScene; + m_scene = pScene; std::shared_ptr<IOStream> stream( pIOHandler->Open( pFile, "rb")); // check whether we can read from the file @@ -211,14 +220,13 @@ void XGLImporter::InternReadFile( const std::string& pFile, // construct the irrXML parser CIrrXML_IOStreamReader st(stream.get()); - std::unique_ptr<IrrXMLReader> read( createIrrXMLReader((IFileReadCallBack*) &st) ); - reader = read.get(); + m_reader.reset( createIrrXMLReader( ( IFileReadCallBack* ) &st ) ); // parse the XML file TempScope scope; while (ReadElement()) { - if (!ASSIMP_stricmp(reader->getNodeName(),"world")) { + if (!ASSIMP_stricmp(m_reader->getNodeName(),"world")) { ReadWorld(scope); } } @@ -231,21 +239,21 @@ void XGLImporter::InternReadFile( const std::string& pFile, } // copy meshes - scene->mNumMeshes = static_cast<unsigned int>(meshes.size()); - scene->mMeshes = new aiMesh*[scene->mNumMeshes](); - std::copy(meshes.begin(),meshes.end(),scene->mMeshes); + m_scene->mNumMeshes = static_cast<unsigned int>(meshes.size()); + m_scene->mMeshes = new aiMesh*[m_scene->mNumMeshes](); + std::copy(meshes.begin(),meshes.end(),m_scene->mMeshes); // copy materials - scene->mNumMaterials = static_cast<unsigned int>(materials.size()); - scene->mMaterials = new aiMaterial*[scene->mNumMaterials](); - std::copy(materials.begin(),materials.end(),scene->mMaterials); + m_scene->mNumMaterials = static_cast<unsigned int>(materials.size()); + m_scene->mMaterials = new aiMaterial*[m_scene->mNumMaterials](); + std::copy(materials.begin(),materials.end(),m_scene->mMaterials); if (scope.light) { - scene->mNumLights = 1; - scene->mLights = new aiLight*[1]; - scene->mLights[0] = scope.light; + m_scene->mNumLights = 1; + m_scene->mLights = new aiLight*[1]; + m_scene->mLights[0] = scope.light; - scope.light->mName = scene->mRootNode->mName; + scope.light->mName = m_scene->mRootNode->mName; } scope.dismiss(); @@ -254,8 +262,8 @@ void XGLImporter::InternReadFile( const std::string& pFile, // ------------------------------------------------------------------------------------------------ bool XGLImporter::ReadElement() { - while(reader->read()) { - if (reader->getNodeType() == EXN_ELEMENT) { + while(m_reader->read()) { + if (m_reader->getNodeType() == EXN_ELEMENT) { return true; } } @@ -265,11 +273,11 @@ bool XGLImporter::ReadElement() // ------------------------------------------------------------------------------------------------ bool XGLImporter::ReadElementUpToClosing(const char* closetag) { - while(reader->read()) { - if (reader->getNodeType() == EXN_ELEMENT) { + while(m_reader->read()) { + if (m_reader->getNodeType() == EXN_ELEMENT) { return true; } - else if (reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(reader->getNodeName(),closetag)) { + else if (m_reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(m_reader->getNodeName(),closetag)) { return false; } } @@ -280,11 +288,11 @@ bool XGLImporter::ReadElementUpToClosing(const char* closetag) // ------------------------------------------------------------------------------------------------ bool XGLImporter::SkipToText() { - while(reader->read()) { - if (reader->getNodeType() == EXN_TEXT) { + while(m_reader->read()) { + if (m_reader->getNodeType() == EXN_TEXT) { return true; } - else if (reader->getNodeType() == EXN_ELEMENT || reader->getNodeType() == EXN_ELEMENT_END) { + else if (m_reader->getNodeType() == EXN_ELEMENT || m_reader->getNodeType() == EXN_ELEMENT_END) { ThrowException("expected text contents but found another element (or element end)"); } } @@ -294,7 +302,7 @@ bool XGLImporter::SkipToText() // ------------------------------------------------------------------------------------------------ std::string XGLImporter::GetElementName() { - const char* s = reader->getNodeName(); + const char* s = m_reader->getNodeName(); size_t len = strlen(s); std::string ret; @@ -328,7 +336,7 @@ void XGLImporter::ReadWorld(TempScope& scope) nd->mName.Set("WORLD"); } - scene->mRootNode = nd; + m_scene->mRootNode = nd; } // ------------------------------------------------------------------------------------------------ @@ -351,7 +359,7 @@ void XGLImporter::ReadLighting(TempScope& scope) // ------------------------------------------------------------------------------------------------ aiLight* XGLImporter::ReadDirectionalLight() { - ScopeGuard<aiLight> l(new aiLight()); + std::unique_ptr<aiLight> l(new aiLight()); l->mType = aiLightSource_DIRECTIONAL; while (ReadElementUpToClosing("directionallight")) { @@ -366,13 +374,13 @@ aiLight* XGLImporter::ReadDirectionalLight() l->mColorSpecular = ReadCol3(); } } - return l.dismiss(); + return l.release(); } // ------------------------------------------------------------------------------------------------ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* closetag) { - ScopeGuard<aiNode> nd(new aiNode()); + std::unique_ptr<aiNode> nd(new aiNode()); std::vector<aiNode*> children; std::vector<unsigned int> meshes; @@ -455,11 +463,11 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl nd->mChildren = new aiNode*[nd->mNumChildren](); for(unsigned int i = 0; i < nd->mNumChildren; ++i) { nd->mChildren[i] = children[i]; - children[i]->mParent = nd; + children[i]->mParent = nd.get(); } } - return nd.dismiss(); + return nd.release(); } // ------------------------------------------------------------------------------------------------ @@ -498,9 +506,9 @@ aiMatrix4x4 XGLImporter::ReadTrafo() up.Normalize(); right = forward ^ up; - if (fabs(up * forward) > 1e-4) { + if (std::fabs(up * forward) > 1e-4) { // this is definitely wrong - a degenerate coordinate space ruins everything - // so substitute identity transform. + // so subtitute identity transform. LogError("<forward> and <up> vectors in <transform> are skewing, ignoring trafo"); return m; } @@ -531,7 +539,7 @@ aiMatrix4x4 XGLImporter::ReadTrafo() // ------------------------------------------------------------------------------------------------ aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m) { - ScopeGuard<aiMesh> mesh(new aiMesh()); + std::unique_ptr<aiMesh> mesh(new aiMesh()); mesh->mNumVertices = static_cast<unsigned int>(m.positions.size()); mesh->mVertices = new aiVector3D[mesh->mNumVertices]; @@ -568,7 +576,7 @@ aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m) mesh->mPrimitiveTypes = m.pflags; mesh->mMaterialIndex = m.matid; - return mesh.dismiss(); + return mesh.release(); } // ------------------------------------------------------------------------------------------------ @@ -586,29 +594,29 @@ bool XGLImporter::ReadMesh(TempScope& scope) ReadMaterial(scope); } else if (s == "p") { - if (!reader->getAttributeValue("ID")) { + if (!m_reader->getAttributeValue("ID")) { LogWarn("no ID attribute on <p>, ignoring"); } else { - int id = reader->getAttributeValueAsInt("ID"); + int id = m_reader->getAttributeValueAsInt("ID"); t.points[id] = ReadVec3(); } } else if (s == "n") { - if (!reader->getAttributeValue("ID")) { + if (!m_reader->getAttributeValue("ID")) { LogWarn("no ID attribute on <n>, ignoring"); } else { - int id = reader->getAttributeValueAsInt("ID"); + int id = m_reader->getAttributeValueAsInt("ID"); t.normals[id] = ReadVec3(); } } else if (s == "tc") { - if (!reader->getAttributeValue("ID")) { + if (!m_reader->getAttributeValue("ID")) { LogWarn("no ID attribute on <tc>, ignoring"); } else { - int id = reader->getAttributeValueAsInt("ID"); + int id = m_reader->getAttributeValueAsInt("ID"); t.uvs[id] = ReadVec2(); } } @@ -708,7 +716,7 @@ unsigned int XGLImporter::ResolveMaterialRef(TempScope& scope) const std::string& s = GetElementName(); if (s == "mat") { ReadMaterial(scope); - return scope.materials_linear.size()-1; + return static_cast<unsigned int>(scope.materials_linear.size()-1); } const int id = ReadIndexFromText(); @@ -737,7 +745,7 @@ void XGLImporter::ReadMaterial(TempScope& scope) { const unsigned int mat_id = ReadIDAttr(); - ScopeGuard<aiMaterial> mat(new aiMaterial()); + std::unique_ptr<aiMaterial> mat(new aiMaterial()); while (ReadElementUpToClosing("mat")) { const std::string& s = GetElementName(); if (s == "amb") { @@ -766,8 +774,8 @@ void XGLImporter::ReadMaterial(TempScope& scope) } } - scope.materials[mat_id] = mat; - scope.materials_linear.push_back(mat.dismiss()); + scope.materials[mat_id] = mat.get(); + scope.materials_linear.push_back(mat.release()); } @@ -828,10 +836,10 @@ void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out) // ------------------------------------------------------------------------------------------------ unsigned int XGLImporter::ReadIDAttr() { - for(int i = 0, e = reader->getAttributeCount(); i < e; ++i) { + for(int i = 0, e = m_reader->getAttributeCount(); i < e; ++i) { - if(!ASSIMP_stricmp(reader->getAttributeName(i),"id")) { - return reader->getAttributeValueAsInt(i); + if(!ASSIMP_stricmp(m_reader->getAttributeName(i),"id")) { + return m_reader->getAttributeValueAsInt(i); } } return ~0u; @@ -844,7 +852,7 @@ float XGLImporter::ReadFloat() LogError("unexpected EOF reading float element contents"); return 0.f; } - const char* s = reader->getNodeData(), *se; + const char* s = m_reader->getNodeData(), *se; if(!SkipSpaces(&s)) { LogError("unexpected EOL, failed to parse float"); @@ -869,7 +877,7 @@ unsigned int XGLImporter::ReadIndexFromText() LogError("unexpected EOF reading index element contents"); return ~0u; } - const char* s = reader->getNodeData(), *se; + const char* s = m_reader->getNodeData(), *se; if(!SkipSpaces(&s)) { LogError("unexpected EOL, failed to parse index element"); return ~0u; @@ -894,7 +902,7 @@ aiVector2D XGLImporter::ReadVec2() LogError("unexpected EOF reading vec2 contents"); return vec; } - const char* s = reader->getNodeData(); + const char* s = m_reader->getNodeData(); for(int i = 0; i < 2; ++i) { if(!SkipSpaces(&s)) { @@ -923,7 +931,7 @@ aiVector3D XGLImporter::ReadVec3() LogError("unexpected EOF reading vec3 contents"); return vec; } - const char* s = reader->getNodeData(); + const char* s = m_reader->getNodeData(); for(int i = 0; i < 3; ++i) { if(!SkipSpaces(&s)) { |