我基本上想在 3D 对象的网格上生成随机表面点,包括 python 中的表面法线。我在该领域没有很多经验。那么有人可以推荐我一些包、途径、方法来解决这个任务吗?
研究了open3d和trimesh,但仍然遇到一些问题。
谢谢!
最佳答案
使用 trimesh 非常简单:
In [1]: import trimesh
In [2]: m = trimesh.creation.icosphere()
In [3]: m
Out[3]: <trimesh.base.Trimesh at 0x7f99bec7d550>
In [4]: m.sample?
Signature: m.sample(count, return_index=False)
Docstring:
Return random samples distributed normally across the
surface of the mesh
Parameters
---------
count : int
Number of points to sample
return_index : bool
If True will also return the index of which face each
sample was taken from.
Returns
---------
samples : (count, 3) float
Points on surface of mesh
face_index : (count, ) int
Index of self.faces
File: /media/psf/Dropbox/robotics/trimesh/trimesh/base.py
Type: method
In [5]: points, index = m.sample(1000, return_index=True)
In [6]: points
Out[6]:
array([[ 0.79934465, 0.58103816, 0.1308479 ],
[-0.07373243, 0.08338232, 0.99055759],
[ 0.71660325, 0.21369974, 0.65889903],
...,
[-0.08330094, 0.98915598, 0.10205582],
[ 0.2558548 , -0.68523377, -0.6770221 ],
[-0.11483521, 0.97023335, 0.19696663]])
In [8]: normals = m.face_normals[index]
In [9]: normals
Out[9]:
array([[ 0.79167915, 0.58957859, 0.16012871],
[-0.04950537, 0.06905681, 0.99638365],
[ 0.73810358, 0.21732806, 0.63872656],
...,
[-0.06905681, 0.99638365, 0.04950537],
[ 0.23921922, -0.7022584 , -0.67052763],
[-0.08142553, 0.97123096, 0.22378629]])
您可以通过找到每个点的重心坐标然后插入顶点法线来获得更好的法线,但仅使用面法线非常简单。
关于python - 在python中使用网格上的法线创建曲面点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56046601/