我只是想设置某张脸的颜色,而我的代码一直在抛出一个错误。
行mesh.set_color(*f_it, clr);抛出一个错误(与属性错误有关)。我尝试将其更改为mesh.set_color(f_it.handle(), clr);,但这会引发取消引用错误。
我要正确地设置颜色吗?
typedef OpenMesh::TriMesh_ArrayKernelT<> myMesh;
myMesh * Mesh;
myMesh mesh;
void computeFaceNormals(myMesh mesh) {
OpenMesh::Vec3f pointA, pointB, pointC;
myMesh::VertexIter vlt, vBegin, vEnd;
myMesh::ConstFaceVertexIter cfvlt;
myMesh::Color clr;
for (myMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end(); f_it++) {
cfvlt = mesh.cfv_iter(*f_it);
pointA = mesh.point(*cfvlt);
pointB = mesh.point((*cfvlt++));
pointC = mesh.point((*cfvlt++));
clr[0] = 0;
clr[1] = 1;
clr[2] = 0;
mesh.set_color(*f_it, clr);
}
}发布于 2019-09-20 11:03:14
openmesh网格(OpenMesh::TriMesh_ArrayKernelT) 具有不同的属性:顶点颜色、人脸颜色、顶点法线等。但是,您需要显式地指定,即您希望网格具有的属性。
在您的例子中,您缺少的是一个mesh.request_face_colors();。
如果将网格作为参数接收,则可以检查它是否已经具有带有:mesh.has_face_colors()的颜色特性。
还可以使用:mesh.release_face_colors();删除属性
有关详细信息,请阅读本教程。是您应该考虑的一个重要注意事项(在本教程中),它澄清了request/has/release的用法:
但是,如果顶点状态属性被请求了两次,会发生什么呢?然后第一个版本什么也不做,但第二个版本将删除它。标准属性有一个引用计数器,每个请求增加一个,每个版本减少一个。如果计数器达到0,则将从内存中删除该属性。
https://stackoverflow.com/questions/57976347
复制相似问题