Browse Source

B3DImporter: Store node animations in unique_ptr

Turo Lamminen 7 years ago
parent
commit
824dfc314b
2 changed files with 9 additions and 6 deletions
  1. 8 5
      code/B3DImporter.cpp
  2. 1 1
      code/B3DImporter.h

+ 8 - 5
code/B3DImporter.cpp

@@ -546,7 +546,7 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
     node->mParent=parent;
     node->mTransformation=tform;
 
-    aiNodeAnim *nodeAnim=0;
+    std::unique_ptr<aiNodeAnim> nodeAnim;
     vector<unsigned> meshes;
     vector<aiNode*> children;
 
@@ -564,11 +564,10 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
             ReadANIM();
         }else if( t=="KEYS" ){
             if( !nodeAnim ){
-                nodeAnim=new aiNodeAnim;
-                _nodeAnims.push_back( nodeAnim );
+                nodeAnim.reset(new aiNodeAnim);
                 nodeAnim->mNodeName=node->mName;
             }
-            ReadKEYS( nodeAnim );
+            ReadKEYS( nodeAnim.get() );
         }else if( t=="NODE" ){
             aiNode *child=ReadNODE( node );
             children.push_back( child );
@@ -576,6 +575,10 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){
         ExitChunk();
     }
 
+    if (nodeAnim) {
+        _nodeAnims.emplace_back( std::move(nodeAnim) );
+    }
+
     node->mNumMeshes= static_cast<unsigned int>(meshes.size());
     node->mMeshes=to_array( meshes );
 
@@ -716,7 +719,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
 
         aiAnimation *anim = _animations.back().get();
         anim->mNumChannels=static_cast<unsigned int>(_nodeAnims.size());
-        anim->mChannels=to_array( _nodeAnims );
+        anim->mChannels = unique_to_array( _nodeAnims );
 
         scene->mNumAnimations=static_cast<unsigned int>(_animations.size());
         scene->mAnimations=unique_to_array( _animations );

+ 1 - 1
code/B3DImporter.h

@@ -124,7 +124,7 @@ private:
 
     std::vector<aiNode*> _nodes;
     std::vector<std::unique_ptr<aiMesh> > _meshes;
-    std::vector<aiNodeAnim*> _nodeAnims;
+    std::vector<std::unique_ptr<aiNodeAnim> > _nodeAnims;
     std::vector<std::unique_ptr<aiAnimation> > _animations;
 };