sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
934 stars 312 forks source link

Multi-Mesh loader design (Assimp plugin integration) #602

Open epernod opened 6 years ago

epernod commented 6 years ago

Hello,

I would like to discuss a design to represent mesh loaded from a file that contains several child meshes.

For example FBX or COLLADA can now be loaded in Sofa using the SofaAssimp plugin but for the moment all child meshes are merged in one big mesh. We loose the information of Bones etc..

The API from sofa::core::loader::MeshLoader doesn't support several mesh for the moment.

   // Point coordinates in 3D in double.
    Data< helper::vector<sofa::defaulttype::Vec<3,SReal> > > d_positions; ///< Vertices of the mesh loaded

    //Tab of 1D elements
    Data< helper::vector< Polyline > > d_polylines; ///< Polylines of the mesh loaded

    // Tab of 2D elements composition
    Data< helper::vector< Edge > > d_edges; ///< Edges of the mesh loaded
    Data< helper::vector< Triangle > > d_triangles; ///< Triangles of the mesh loaded
    Data< helper::vector< Quad > > d_quads; ///< Quads of the mesh loaded

Any suggestion?


Suggested labels:

epernod commented 6 years ago

First discussion with @damienmarchal . To generate the data on the flow.

Backup gitter discussion here:

Loader {
    std::vector<Data<std::vector<Vec3f>> positions;
load(){
        for(auto& mesh : assimp.meshes ) {
             BaseData* data = new Data<std::vector<Vec3f>>() ;  
             WriteOnlAccessor acc =  WriteOnlyAccessor(data);  
             acc.resize(mesh.vertices.size());
              for( int i ;  i< mesh.vertices.size();++i ){
                      acc[i] = v[i] ; 
               }
               positions.push_back(data);
               addData(data, mesh.name+"_positions") ;
      }
}
}

 Data<std::string>* t = new Data<std::string>() ;
   t = new(t) Data<std::string>(obj->initData(t, std::string(""), dataName, dataHelp)) ;