summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/code/B3DImporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/assimp/code/B3DImporter.cpp')
-rw-r--r--src/3rdparty/assimp/code/B3DImporter.cpp63
1 files changed, 43 insertions, 20 deletions
diff --git a/src/3rdparty/assimp/code/B3DImporter.cpp b/src/3rdparty/assimp/code/B3DImporter.cpp
index 1b9ba1433..bc888fb66 100644
--- a/src/3rdparty/assimp/code/B3DImporter.cpp
+++ b/src/3rdparty/assimp/code/B3DImporter.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.
@@ -56,7 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/anim.h>
#include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp>
-
+#include <assimp/importerdesc.h>
using namespace Assimp;
using namespace std;
@@ -81,6 +82,20 @@ static const aiImporterDesc desc = {
//#define DEBUG_B3D
+template<typename T>
+void DeleteAllBarePointers(std::vector<T>& x)
+{
+ for(auto p : x)
+ {
+ delete p;
+ }
+}
+
+B3DImporter::~B3DImporter()
+{
+ DeleteAllBarePointers(_animations);
+}
+
// ------------------------------------------------------------------------------------------------
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
@@ -156,7 +171,8 @@ int B3DImporter::ReadByte(){
// ------------------------------------------------------------------------------------------------
int B3DImporter::ReadInt(){
if( _pos+4<=_buf.size() ){
- int n=*(int*)&_buf[_pos];
+ int n;
+ memcpy(&n, &_buf[_pos], 4);
_pos+=4;
return n;
}
@@ -167,7 +183,8 @@ int B3DImporter::ReadInt(){
// ------------------------------------------------------------------------------------------------
float B3DImporter::ReadFloat(){
if( _pos+4<=_buf.size() ){
- float n=*(float*)&_buf[_pos];
+ float n;
+ memcpy(&n, &_buf[_pos], 4);
_pos+=4;
return n;
}
@@ -331,7 +348,7 @@ void B3DImporter::ReadVRTS(){
int sz=12+(_vflags&1?12:0)+(_vflags&2?16:0)+(_tcsets*_tcsize*4);
int n_verts=ChunkSize()/sz;
- int v0=_vertices.size();
+ int v0=static_cast<int>(_vertices.size());
_vertices.resize( v0+n_verts );
for( int i=0;i<n_verts;++i ){
@@ -404,7 +421,7 @@ void B3DImporter::ReadTRIS( int v0 ){
void B3DImporter::ReadMESH(){
/*int matid=*/ReadInt();
- int v0=_vertices.size();
+ int v0= static_cast<int>(_vertices.size());
while( ChunkSize() ){
string t=ReadChunk();
@@ -462,17 +479,17 @@ void B3DImporter::ReadKEYS( aiNodeAnim *nodeAnim ){
}
if( flags & 1 ){
- nodeAnim->mNumPositionKeys=trans.size();
+ nodeAnim->mNumPositionKeys=static_cast<unsigned int>(trans.size());
nodeAnim->mPositionKeys=to_array( trans );
}
if( flags & 2 ){
- nodeAnim->mNumScalingKeys=scale.size();
+ nodeAnim->mNumScalingKeys=static_cast<unsigned int>(scale.size());
nodeAnim->mScalingKeys=to_array( scale );
}
if( flags & 4 ){
- nodeAnim->mNumRotationKeys=rot.size();
+ nodeAnim->mNumRotationKeys=static_cast<unsigned int>(rot.size());
nodeAnim->mRotationKeys=to_array( rot );
}
}
@@ -506,7 +523,7 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
aiMatrix4x4 tform=trans * rot * scale;
- int nodeid=_nodes.size();
+ int nodeid=static_cast<int>(_nodes.size());
aiNode *node=new aiNode( name );
_nodes.push_back( node );
@@ -521,9 +538,9 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
while( ChunkSize() ){
string t=ReadChunk();
if( t=="MESH" ){
- int n=_meshes.size();
+ unsigned int n= static_cast<unsigned int>(_meshes.size());
ReadMESH();
- for( int i=n;i<(int)_meshes.size();++i ){
+ for( unsigned int i=n;i<static_cast<unsigned int>(_meshes.size());++i ){
meshes.push_back( i );
}
}else if( t=="BONE" ){
@@ -544,10 +561,10 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
ExitChunk();
}
- node->mNumMeshes=meshes.size();
+ node->mNumMeshes= static_cast<unsigned int>(meshes.size());
node->mMeshes=to_array( meshes );
- node->mNumChildren=children.size();
+ node->mNumChildren=static_cast<unsigned int>(children.size());
node->mChildren=to_array( children );
return node;
@@ -557,13 +574,19 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
void B3DImporter::ReadBB3D( aiScene *scene ){
_textures.clear();
+
_materials.clear();
_vertices.clear();
+
_meshes.clear();
+ DeleteAllBarePointers(_nodes);
_nodes.clear();
+
_nodeAnims.clear();
+
+ DeleteAllBarePointers(_animations);
_animations.clear();
string t=ReadChunk();
@@ -645,7 +668,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
aiNode *bnode=_nodes[i];
bone->mName=bnode->mName;
- bone->mNumWeights=weights.size();
+ bone->mNumWeights= static_cast<unsigned int>(weights.size());
bone->mWeights=to_array( weights );
aiMatrix4x4 mat=bnode->mTransformation;
@@ -655,7 +678,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
}
bone->mOffsetMatrix=mat.Inverse();
}
- mesh->mNumBones=bones.size();
+ mesh->mNumBones= static_cast<unsigned int>(bones.size());
mesh->mBones=to_array( bones );
}
}
@@ -667,21 +690,21 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
if( !_materials.size() ){
_materials.push_back( new aiMaterial );
}
- scene->mNumMaterials=_materials.size();
+ scene->mNumMaterials= static_cast<unsigned int>(_materials.size());
scene->mMaterials=to_array( _materials );
//meshes
- scene->mNumMeshes=_meshes.size();
+ scene->mNumMeshes= static_cast<unsigned int>(_meshes.size());
scene->mMeshes=to_array( _meshes );
//animations
if( _animations.size()==1 && _nodeAnims.size() ){
aiAnimation *anim=_animations.back();
- anim->mNumChannels=_nodeAnims.size();
+ anim->mNumChannels=static_cast<unsigned int>(_nodeAnims.size());
anim->mChannels=to_array( _nodeAnims );
- scene->mNumAnimations=_animations.size();
+ scene->mNumAnimations=static_cast<unsigned int>(_animations.size());
scene->mAnimations=to_array( _animations );
}