-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.py
149 lines (119 loc) · 4.72 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys
import os
from threading import Thread
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from viewer import ViewerWidget
from util import *
from extractor import unpack
from converter import saveobj, saveiqe, savepmx
class CentralWidget(QSplitter):
def __init__(self, parent):
super().__init__(parent)
self.statusBar = parent.statusBar
self.listWidget = QListWidget(self)
self.viewer = ViewerWidget(self)
self.paths = []
self.names = []
self.name = ''
self.mesh = None
self.grabKeyboard()
self.listWidget.itemSelectionChanged.connect(self.cb_itemSelectionChanged)
self.initLayout()
def cb_itemSelectionChanged(self):
current_row = self.listWidget.currentRow()
if len(self.paths) > current_row:
path = self.paths[current_row]
self.name = self.names[current_row]
self.mesh = mesh_from_path(path)
self.viewer.load_mesh(self.mesh)
self.statusBar.showMessage('Face {}, Bone: {}'.format(
len(self.mesh['face']),
len(self.mesh['bone_name']) if self.mesh['bone_exist'] else 0
))
def init_load_mesh(self):
if (len(self.paths) > 0):
path = self.paths[0]
self.name = self.names[0]
self.mesh = mesh_from_path(path)
self.viewer.load_mesh(self.mesh)
def keyPressEvent(self, event):
if event.key() in [16777235, 16777237]:
self.listWidget.keyPressEvent(event)
else:
self.viewer.keyPressEvent(event)
def keyReleaseEvent(self, event):
self.viewer.keyReleaseEvent(event)
def load_folder(self, folder_path):
self.viewer.release_mesh()
self.paths = file_paths_from_dir(folder_path)
self.names = list(map(lambda s: s.split('/')[-1], self.paths))
self.listWidget.clear()
self.listWidget.addItems(self.names)
def initLayout(self):
self.addWidget(self.listWidget)
self.addWidget(self.viewer)
self.setStretchFactor(0, 1)
self.setStretchFactor(1, 4)
self.setMinimumHeight(450)
class MyApp(QMainWindow):
def __init__(self):
super().__init__()
self.version = '0.0.1'
self.title = 'NeoX Mesh Viewer'
self.setWindowTitle(self.title)
self.setGeometry(100, 100, 300, 200)
self.setMinimumWidth(620)
self.menubar = self.menuBar()
self.file = self.menubar.addMenu('File')
self.file.addAction('Load Unpack Folder', self.cb_load_folder)
self.file.addAction('Unpack', self.cb_unpack)
self.file.addAction('Save Obj', self.cb_save_obj)
self.file.addAction('Save Iqe', self.cb_save_iqe)
self.file.addAction('Save Pmx', self.cb_save_pmx)
self.about = self.menubar.addMenu('About')
self.about.addAction('Home Page', self.cb_openHomePage)
self.about.addAction('Help', self.cb_help)
self.statusBar = QStatusBar()
self.statusBar.showMessage('Author: zhouhang95')
self.setStatusBar(self.statusBar)
self.centralWidget = CentralWidget(self)
self.setCentralWidget(self.centralWidget)
self.show()
def cb_unpack(self):
path = QFileDialog.getOpenFileName()
path = path[0]
if path == '':
return
self.thread = Thread(target=unpack, args=(path, self.statusBar))
self.thread.start()
def cb_openHomePage(self):
QDesktopServices.openUrl(QUrl('https://github.com/zhouhang95/neox_tools'))
def cb_load_folder(self):
path = QFileDialog.getExistingDirectory()
if path == '':
return
self.centralWidget.load_folder(path)
self.centralWidget.init_load_mesh()
def cb_save_obj(self):
if self.centralWidget.name == '':
return
saveobj(self.centralWidget.mesh, self.centralWidget.name)
self.statusBar.showMessage('OBJ saved!')
def cb_save_iqe(self):
if self.centralWidget.name == '':
return
saveiqe(self.centralWidget.mesh, self.centralWidget.name)
self.statusBar.showMessage('IQE saved!')
def cb_save_pmx(self):
if self.centralWidget.name == '':
return
savepmx(self.centralWidget.mesh, self.centralWidget.name)
self.statusBar.showMessage('PMX saved!')
def cb_help(self):
QMessageBox.about(self, 'Help', help_text)
if __name__ == '__main__':
app = QApplication(sys.argv)
my_app = MyApp()
sys.exit(app.exec_())