本文整理汇总了C++中MeshObject::getFaces方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshObject::getFaces方法的具体用法?C++ MeshObject::getFaces怎么用?C++ MeshObject::getFaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshObject
的用法示例。
在下文中一共展示了MeshObject::getFaces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMeshObject
void loadMeshObject(const std::string& filename, MeshObject& mo)
{
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string err = tinyobj::LoadObj(shapes, materials, filename.c_str());
if (!err.empty()) {
std::cerr << err << std::endl;
exit(1);
}
assert(shapes.size() == 1 ? true : ("obj should be only one shape" && false));
tinyobj::mesh_t& mesh = shapes[0].mesh;
assert((mesh.positions.size() % 3) == 0);
assert((mesh.normals.size() % 3) == 0);
assert((mesh.indices.size() % 3) == 0);
VerticesArray& vts = mo.getVertices();
NormalsArray& nls = mo.getNormals();
FacesArray& fs = mo.getFaces();
for (size_t v = 0; v < mesh.positions.size() / 3; v++)
vts.push_back(VertexType(mesh.positions[3*v+0], mesh.positions[3*v+1], mesh.positions[3*v+2]));
for (size_t n = 0; n < mesh.normals.size() / 3; n++)
nls.push_back(NormalType(mesh.normals[3*n+0], mesh.normals[3*n+1], mesh.normals[3*n+2]));
for (size_t f = 0; f < mesh.indices.size() / 3; f++)
fs.push_back(Face(mesh.indices[3*f+0], mesh.indices[3*f+1], mesh.indices[3*f+2]));
}
示例2: saveMeshObject
void saveMeshObject(const std::string& filename, MeshObject& mo)
{
std::vector<tinyobj::shape_t> out_shape(1);
tinyobj::mesh_t& mesh = out_shape[0].mesh;
VerticesArray& vts = mo.getVertices();
NormalsArray& nls = mo.getNormals();
FacesArray& fs = mo.getFaces();
for (size_t v = 0; v < vts.size(); ++ v)
{
mesh.positions.push_back(vts[v].x());
mesh.positions.push_back(vts[v].y());
mesh.positions.push_back(vts[v].z());
}
for (size_t n = 0; n < nls.size(); ++ n)
{
mesh.normals.push_back(nls[n].x());
mesh.normals.push_back(nls[n].y());
mesh.normals.push_back(nls[n].z());
}
for (size_t f = 0; f < fs.size(); ++ f)
{
mesh.indices.push_back(fs[f][0]);
mesh.indices.push_back(fs[f][1]);
mesh.indices.push_back(fs[f][2]);
}
bool ret = WriteObj(filename, out_shape, false);
assert(ret);
}