diff options
Diffstat (limited to 'src/3rdparty/assimp/code/SMDLoader.cpp')
-rw-r--r-- | src/3rdparty/assimp/code/SMDLoader.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/3rdparty/assimp/code/SMDLoader.cpp b/src/3rdparty/assimp/code/SMDLoader.cpp index 7aef7bc56..60e3f63c8 100644 --- a/src/3rdparty/assimp/code/SMDLoader.cpp +++ b/src/3rdparty/assimp/code/SMDLoader.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. @@ -54,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <assimp/IOSystem.hpp> #include <assimp/scene.h> #include <assimp/DefaultLogger.hpp> +#include <assimp/importerdesc.h> #include <memory> using namespace Assimp; @@ -74,20 +76,22 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer SMDImporter::SMDImporter() - : configFrameID(), - mBuffer(), - pScene(), - iFileSize(), - iSmallestFrame(), - dLengthOfAnim(), - bHasUVs(), - iLineNumber() -{} +: configFrameID(), +mBuffer(), +pScene( nullptr ), +iFileSize( 0 ), +iSmallestFrame( -1 ), +dLengthOfAnim( 0.0 ), +bHasUVs(false ), +iLineNumber(-1) { + // empty +} // ------------------------------------------------------------------------------------------------ // Destructor, private as well -SMDImporter::~SMDImporter() -{} +SMDImporter::~SMDImporter() { + // empty +} // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. @@ -133,9 +137,8 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS // Allocate storage and copy the contents of the file to a memory buffer this->pScene = pScene; - std::vector<char> buff(iFileSize+1); - TextFileToBuffer(file.get(),buff); - mBuffer = &buff[0]; + mBuffer.resize( iFileSize + 1 ); + TextFileToBuffer(file.get(), mBuffer ); iSmallestFrame = (1 << 31); bHasUVs = true; @@ -447,7 +450,9 @@ void SMDImporter::CreateOutputMeshes() // add bone child nodes void SMDImporter::AddBoneChildren(aiNode* pcNode, uint32_t iParent) { - ai_assert(NULL != pcNode && 0 == pcNode->mNumChildren && NULL == pcNode->mChildren); + ai_assert( NULL != pcNode ); + ai_assert( 0 == pcNode->mNumChildren ); + ai_assert( NULL == pcNode->mChildren); // first count ... for (unsigned int i = 0; i < asBones.size();++i) @@ -640,17 +645,19 @@ void SMDImporter::ComputeAbsoluteBoneTransformations() bone.mOffsetMatrix.Inverse(); } } - +\ // ------------------------------------------------------------------------------------------------ // create output materials void SMDImporter::CreateOutputMaterials() { + ai_assert( nullptr != pScene ); + pScene->mNumMaterials = (unsigned int)aszTextures.size(); pScene->mMaterials = new aiMaterial*[std::max(1u, pScene->mNumMaterials)]; - for (unsigned int iMat = 0; iMat < pScene->mNumMaterials;++iMat) - { + for (unsigned int iMat = 0; iMat < pScene->mNumMaterials; ++iMat) { aiMaterial* pcMat = new aiMaterial(); + ai_assert( nullptr != pcMat ); pScene->mMaterials[iMat] = pcMat; aiString szName; @@ -659,7 +666,7 @@ void SMDImporter::CreateOutputMaterials() if (aszTextures[iMat].length()) { - ::strcpy(szName.data, aszTextures[iMat].c_str() ); + ::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1); szName.length = aszTextures[iMat].length(); pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0)); } @@ -694,14 +701,14 @@ void SMDImporter::CreateOutputMaterials() // Parse the file void SMDImporter::ParseFile() { - const char* szCurrent = mBuffer; + const char* szCurrent = &mBuffer[0]; // read line per line ... for ( ;; ) { if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break; - // "version <n> \n", <n> should be 1 for hl and hl� SMD files + // "version <n> \n", <n> should be 1 for hl and hl2 SMD files if (TokenMatch(szCurrent,"version",7)) { if(!SkipSpaces(szCurrent,&szCurrent)) break; @@ -1019,7 +1026,7 @@ void SMDImporter::ParseTriangle(const char* szCurrent, // read the texture file name const char* szLast = szCurrent; - while (!IsSpaceOrNewLine(*szCurrent++)); + while (!IsSpaceOrNewLine(*++szCurrent)); // ... and get the index that belongs to this file name face.iTexture = GetTextureIndex(std::string(szLast,(uintptr_t)szCurrent-(uintptr_t)szLast)); |