-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path22_bvh_self_intersection.py
42 lines (37 loc) · 1.54 KB
/
22_bvh_self_intersection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pathlib
import moderngl
from PyQt5 import QtWidgets
import numpy
from util_moderngl_qt import DrawerMesh, DrawerCylinders, QGLWidgetViewer3
from del_msh import BVH, TriMesh
def main():
path_file = pathlib.Path('.') / 'asset' / 'bunny_1k.obj'
tri2vtx, vtx2xyz = TriMesh.load_wavefront_obj(str(path_file), is_centerize=True, normalized_size=1.)
vtx2xyz1 = vtx2xyz + numpy.array([0.2, 0.2, 0.2], dtype=numpy.float32)
tri2vtx, vtx2xyz = TriMesh.merge(tri2vtx, vtx2xyz, tri2vtx, vtx2xyz1)
bvhnodes = TriMesh.bvhnodes_tri(tri2vtx, vtx2xyz)
aabbs = TriMesh.aabbs_tri(tri2vtx, vtx2xyz, bvhnodes)
edge2node2xyz, edge2tri = TriMesh.self_intersection(tri2vtx, vtx2xyz, bvhnodes, aabbs)
# print(edge2node2xyz, edge2tri)
#
edge2vtx = TriMesh.edge2vtx(tri2vtx, vtx2xyz.shape[0])
drawer_mesh = DrawerMesh.Drawer(
vtx2xyz=vtx2xyz,
list_elem2vtx=[
DrawerMesh.ElementInfo(index=edge2vtx, color=(0, 0, 0), mode=moderngl.LINES),
# DrawerMesh.ElementInfo(index=tri2vtx, color=(1, 1, 0), mode=moderngl.TRIANGLES)
]
)
#
drawer_intersection = DrawerCylinders.Drawer()
drawer_intersection.rad = 0.005
for edge in edge2node2xyz[:]:
drawer_intersection.list_cylinder.append(
DrawerCylinders.CylinderInfo(pos0=edge[0], pos1=edge[1]))
#
with QtWidgets.QApplication([]) as app:
glwidget = QGLWidgetViewer3.QtGLWidget_Viewer3([drawer_mesh, drawer_intersection])
glwidget.show()
app.exec()
if __name__ == "__main__":
main()