如何解决CGAL输出参数化网格
我目前正在使用CGAL从封闭的网格计算参数化。 这是我关注的示例: https://doc.cgal.org/latest/Surface_mesh_parameterization/Surface_mesh_parameterization_2seam_Polyhedron_3_8cpp-example.html
是否可以通过CGAL输出带有uv坐标/纹理贴图的3D网格? 例如,在obj文件或层上。
看起来很简单,但是我找不到它的功能。
谢谢!
解决方法
CGAL当前不具有处理纹理的功能。但是,处理UV属性是可行的。将属性输出到文件的最简单方法是:
- 使用
CGAL::Surface_mesh
存储网格物体 - 使用简单属性(double,int等)存储U V信息
- 使用
CGAL::write_ply()
编写文件
例如,如果我运行这段代码:
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh/IO.h>
using Kernel = CGAL::Simple_cartesian<double>;
using Point_3 = Kernel::Point_3;
using Mesh = CGAL::Surface_mesh<Point_3>;
using Vertex_index = Mesh::Vertex_index;
using Halfedge_index = Mesh::Halfedge_index;
using Edge_index = Mesh::Edge_index;
int main()
{
Mesh mesh;
Mesh::Property_map<Edge_index,double> u_map
= mesh.add_property_map<Edge_index,double>("U").first;
Mesh::Property_map<Edge_index,double> v_map
= mesh.add_property_map<Edge_index,double>("V").first;
Vertex_index v0 = mesh.add_vertex(Point_3(0,0));
Vertex_index v1 = mesh.add_vertex(Point_3(0,1));
Halfedge_index hi = mesh.add_edge (v0,v1);
Edge_index ei = mesh.edge(hi);
u_map[ei] = 0.2;
v_map[ei] = 0.8;
std::ofstream ofile ("out.ply");
CGAL::write_ply (ofile,mesh);
return EXIT_SUCCESS;
}
我得到以下输出PLY文件,该文件确实将UV属性存储在边缘:
ply
format ascii 1.0
comment Generated by the CGAL library
element vertex 2
property double x
property double y
property double z
element face 0
property list uchar int vertex_indices
element edge 1
property int v0
property int v1
property double U
property double V
end_header
0 0 0
0 0 1
1 0 0.2 0.8
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。