OpenMesh 讀寫網格控制(讀取寫入紋理坐標,法向等)


OpenMesh讀取網格默認是不自動讀取obj網格中的法向,紋理坐標等信息的,寫入網格同樣也是。所以要讀取(或寫入)這些信息需要修改默認的選項。

先看一下其讀寫網格的函數

1   template<class Mesh>
2   bool OpenMesh::IO::read_mesh(
3       Mesh &_mesh,
4       const std::string &_filename,
5       Options &_opt,
6       bool _clear = true
7   )

 

1   template<class Mesh >
2   bool OpenMesh::IO::write_mesh(
3       const Mesh &_mesh,
4       const std::string &_filename,
5       Options _opt = Options::Default,
6       std::streamsize _precision = 6
7   )

函數中的參數 Options 就可以控制讀寫其他信息。

 

  • OpenMesh的IO::Options::Flag

在OpenMesh的官方文檔中,有很多關於IO的options,更詳細的內容請看這里  http://www.openmesh.org/media/Documentations/OpenMesh-Doc-Latest/a00231.html#details

    enum Flag
    { 
        Default = 0x0000, Binary = 0x0001, MSB = 0x0002, LSB = 0x0004, Swap = 0x0006, VertexNormal = 0x0010, VertexColor = 0x0020, VertexTexCoord = 0x0040, EdgeColor = 0x0080, FaceNormal = 0x0100, FaceColor = 0x0200, FaceTexCoord = 0x0400, ColorAlpha = 0x0800, ColorFloat = 0x1000, Custom = 0x2000 }

 這些options可以讓你自定義讀取/寫入網格。

 

  • OpenMesh 讀網格

如果想要在讀取obj網格的時候自動讀取紋理坐標,只需要添加讀取紋理坐標的option,注意在讀取網格之前要先給紋理坐標分配內存,即 request_vertex_texcoords2D()。讀取法向或其他信息也是一樣。

1     OpenMesh::IO::Options opt_read = 0x0040;   //選項控制讀取紋理坐標
2    ptr_mesh_->request_vertex_texcoords2D();
3     if ( !OpenMesh::IO::read_mesh(*ptr_mesh_, byfilename.data(), opt_read) )
4     {
5         std::cerr<< "Cannot Open mesh to file '1.obj'" << std::endl;
6         return;
7     }

 

  • OpenMesh 寫網格

如果要想在寫入網格時寫入頂點的法向信息,也是同樣的。

1      OpenMesh::IO::Options opt_write = OpenMesh::IO::Options::VertexNormal;
2      if (!OpenMesh::IO::write_mesh(*ptr_mesh_, "mesh.obj", opt_write))
3      {
4          std::cerr << "Cannot Write mesh to file" << std::endl;
5          return;
6      }

如果要控制寫入網格的數據精度,也很簡單:

1 OpenMesh::IO::write_mesh(*ptr_mesh_, "mesh.obj", opt_write, 12)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM