|
准备一个obj文件,内容如下:
####
# OBJ dataFile simple version. File name: triangles.obj
# Vertices: 4
# Faces: 2
####
# List of Vertices, with (x,y,z) coordinates, w is optional.
v 0.0 0.0 0.0
v 10.0 0.0 0.0
v 10.0 10.0 0.0
v 0.0 10.0 0.0
# 4 vertices
# Face Definitions
f 1 2 3
f 1 3 4
# End of File
加载obj文件代码
#include <pcl/io/vtk_lib_io.h>
pcl::PolygonMesh triangles;
pcl::io::loadPolygonFileOBJ("triangles_test.obj", *triangles);
使用pcl::visualization::PCLVisualizer* viewer显示PolygonMesh代码
viewer->addPolygonMesh(*triangles);
生成TextureMesh模型
pcl::TextureMeshPtr nvmMesh_(new pcl::TextureMesh());//带纹理的三维模型
nvmMesh_->cloud = triangles_->cloud;
nvmMesh_->header = triangles_->header;
nvmMesh_->tex_polygons.push_back(triangles_->polygons);
std::vector< Eigen::Vector2f > texcoord;
texcoord.push_back(Eigen::Vector2f(0.0,0.0));
texcoord.push_back(Eigen::Vector2f(1.0,0.0));
texcoord.push_back(Eigen::Vector2f(1.0,1.0));
texcoord.push_back(Eigen::Vector2f(0.0,1.0));
nvmMesh_->tex_coordinates.push_back(texcoord);
pcl::TexMaterial tex_material;
tex_material.tex_file = std::string("F:\\Develop\\examples\\111.jpg");
tex_material.tex_name = std::string("111.jpg");
nvmMesh_->tex_materials.push_back(tex_material);
使用pcl::visualization::PCLVisualizer* viewer显示TextureMesh代码
viewer->addTextureMesh(*nvmMesh_);
|
|