forked from nobuyuki83/python_graphics_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_obj_with_texture.py
More file actions
27 lines (23 loc) · 915 Bytes
/
06_obj_with_texture.py
File metadata and controls
27 lines (23 loc) · 915 Bytes
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
from pathlib import Path
import moderngl
import numpy
from PIL import Image
from PyQt5 import QtWidgets
from del_msh import WavefrontObj
from util_moderngl_qt import DrawerMeshTexture, QGLWidgetViewer3Texture
if __name__ == '__main__':
path_obj = Path('.') / 'asset' / 'Babi' / 'Babi.obj'
obj = WavefrontObj.load(str(path_obj), is_centerize=True, normalized_size=1.8)
tri2uni, uni2xyz, uni2uv, _, _ = obj.triangle_mesh_with_uv()
img = Image.open("asset/Babi/Tex.png")
img = numpy.asarray(img)
with QtWidgets.QApplication([]) as app:
drawer = DrawerMeshTexture.Drawer(
list_elem2vtx=[
DrawerMeshTexture.ElementInfo(index=tri2uni, color=None, mode=moderngl.TRIANGLES)],
vtx2xyz=uni2xyz,
vtx2uv=uni2uv
)
win = QGLWidgetViewer3Texture.QtGLWidget_Viewer3_Texture([drawer], img)
win.show()
app.exec()