python - OpenMesh 随机访问一个面属性
问题描述
我可以在下面的代码中输出点的坐标,但无法访问人脸属性。我使用了错误的方法吗?
import openmesh as om
import numpy as np
mesh = om.TriMesh()
# add a a couple of vertices to the mesh
vh0 = mesh.add_vertex([0, 1, 0])
vh1 = mesh.add_vertex([1, 0, 0])
vh2 = mesh.add_vertex([2, 1, 0])
vh3 = mesh.add_vertex([0,-1, 0])
vh4 = mesh.add_vertex([2,-1, 0])
# add a couple of faces to the mesh
fh0 = mesh.add_face(vh0, vh1, vh2)
fh1 = mesh.add_face(vh1, vh3, vh4)
fh2 = mesh.add_face(vh0, vh3, vh1)
# add another face to the mesh, this time using a list
vh_list = [vh2, vh1, vh4]
fh3 = mesh.add_face(vh_list)
# 0 ==== 2
# |\ 0 /|
# | \ / |
# |2 1 3|
# | / \ |
# |/ 1 \|
# 3 ==== 4
# get the point with vertex handle vh0
point = mesh.point(vh0)
# get all points of the mesh
point_array = mesh.points()
for x in mesh.vertices():
print(x)
print(x.idx())
print(mesh.point(x))
for x in mesh.faces():
print(x)
print(x.idx())
#print(mesh.face(x)) <== THIS LINE THROWS ERROR
解决方案
face_array = mesh.face_vertex_indices()
这是行之有效的方法。
推荐阅读
- c++ - 除了锁和线程的创建和销毁成本之外,什么会降低多线程的性能?
- asp.net-core - 创建新项目时缺少asp.net core 3.1 accountcontroller
- c# - 如何在 C# 中使用表情符号构建 unicode 字符串?
- codeblocks - 如何为 WinBGIm 安装此修复程序?
- c# - 如何将 uint[] c# 传递给 c++ dll?
- angular - Angular 以编程方式将服务注入函数
- docker - docker-compose 报错无效类型,应该是字符串
- linux - 为什么终端和 bash 脚本的结果不同?
- javascript - 如何在 Firebase 身份验证中检查是否从 Google 重定向?
- mongodb - mongo 将单个对象转换为一个元素数组