Browse Source

B3DImporter: Store meshes in unique_ptr

Turo Lamminen 7 năm trước cách đây
mục cha
commit
f1707e920d
2 tập tin đã thay đổi với 6 bổ sung5 xóa
  1. 5 4
      code/B3DImporter.cpp
  2. 1 1
      code/B3DImporter.h

+ 5 - 4
code/B3DImporter.cpp

@@ -400,8 +400,7 @@ void B3DImporter::ReadTRIS( int v0 ){
         Fail( "Bad material id" );
         Fail( "Bad material id" );
     }
     }
 
 
-    aiMesh *mesh=new aiMesh;
-    _meshes.push_back( mesh );
+    std::unique_ptr<aiMesh> mesh(new aiMesh);
 
 
     mesh->mMaterialIndex=matid;
     mesh->mMaterialIndex=matid;
     mesh->mNumFaces=0;
     mesh->mNumFaces=0;
@@ -429,6 +428,8 @@ void B3DImporter::ReadTRIS( int v0 ){
         ++mesh->mNumFaces;
         ++mesh->mNumFaces;
         ++face;
         ++face;
     }
     }
+
+    _meshes.emplace_back( std::move(mesh) );
 }
 }
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
@@ -635,7 +636,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
         aiNode *node=_nodes[i];
         aiNode *node=_nodes[i];
 
 
         for( size_t j=0;j<node->mNumMeshes;++j ){
         for( size_t j=0;j<node->mNumMeshes;++j ){
-            aiMesh *mesh=_meshes[node->mMeshes[j]];
+            aiMesh *mesh = _meshes[node->mMeshes[j]].get();
 
 
             int n_tris=mesh->mNumFaces;
             int n_tris=mesh->mNumFaces;
             int n_verts=mesh->mNumVertices=n_tris * 3;
             int n_verts=mesh->mNumVertices=n_tris * 3;
@@ -708,7 +709,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){
 
 
     //meshes
     //meshes
     scene->mNumMeshes= static_cast<unsigned int>(_meshes.size());
     scene->mNumMeshes= static_cast<unsigned int>(_meshes.size());
-    scene->mMeshes=to_array( _meshes );
+    scene->mMeshes = unique_to_array( _meshes );
 
 
     //animations
     //animations
     if( _animations.size()==1 && _nodeAnims.size() ){
     if( _animations.size()==1 && _nodeAnims.size() ){

+ 1 - 1
code/B3DImporter.h

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