Updated
This commit is contained in:
200
Scripts/Modeling/Edit/LDMT/ldmt_instantMeshes.py
Normal file
200
Scripts/Modeling/Edit/LDMT/ldmt_instantMeshes.py
Normal file
@ -0,0 +1,200 @@
|
||||
import os
|
||||
import math
|
||||
import tempfile
|
||||
from ldmt_function.ldmt_loadUIFile import get_maya_window
|
||||
import maya.OpenMayaUI as omui
|
||||
import subprocess
|
||||
from ldmt_core import ldmt_cmds as ld
|
||||
from functools import partial
|
||||
import maya.cmds as cmds
|
||||
import maya.mel as mel
|
||||
|
||||
from Qt.QtWidgets import *
|
||||
from Qt.QtGui import *
|
||||
from Qt.QtCore import *
|
||||
# from Qt.QtUiTools import QUiLoader
|
||||
from Qt.QtCompat import loadUi
|
||||
import maya.cmds as cmds
|
||||
|
||||
import maya.OpenMaya as om
|
||||
import maya.api.OpenMaya as om2
|
||||
import random
|
||||
import ast
|
||||
|
||||
LDMTPATH = ld.getPath('LDMT')
|
||||
ldmt_uifile = LDMTPATH + '/ldmt_ui/ldmt_instantMeshes.ui'
|
||||
# ldmt_list_form, ldmt_list_base = load_ui_type(ldmt_uifile)
|
||||
ldmt_window_name = 'ldmt_instantMeshes'
|
||||
ldmt_button_name = 'btn_'+ldmt_window_name.split('_')[1]
|
||||
|
||||
'''
|
||||
#Functions
|
||||
'''
|
||||
|
||||
'''
|
||||
#UI
|
||||
'''
|
||||
class ldmt_cls(QDialog):
|
||||
def __init__(self, parent = get_maya_window()):
|
||||
super(ldmt_cls, self).__init__(parent)
|
||||
self.window_name = ldmt_window_name
|
||||
self.setWindowTitle(ldmt_window_name)
|
||||
self.setWindowFlags(Qt.Window)
|
||||
# self.move(QCursor.pos() + QPoint(20,20))
|
||||
self.set_ui()
|
||||
self.setupBtn()
|
||||
|
||||
self.temp_dir = os.path.join(LDMTPATH, 'temp')
|
||||
if not os.path.exists(self.temp_dir):
|
||||
os.makedirs(self.temp_dir)
|
||||
# self.installStartBar()
|
||||
|
||||
def set_ui(self):
|
||||
main_layout = QVBoxLayout(self)
|
||||
|
||||
# ui_file = QFile(ldmt_uifile)
|
||||
# ui_file.open(QFile.ReadOnly)
|
||||
self.ui = loadUi(ldmt_uifile)
|
||||
# self.ui = QUiLoader().load(ui_file)
|
||||
# ui_file.close()
|
||||
|
||||
main_layout.addWidget(self.ui)
|
||||
|
||||
def setupBtn(self):
|
||||
self.ui.btn_sendToExe.clicked.connect(self.sendToExe)
|
||||
self.ui.btn_remesh.clicked.connect(self.remesh)
|
||||
self.ui.text_targetCount.setPlainText("50%")
|
||||
self.ui.statusbar.showMessage(ld.tag())
|
||||
|
||||
def sendToExe(self):
|
||||
sel=cmds.ls(sl=1,o=1)
|
||||
if sel == []:
|
||||
InstantMeshPath = LDMTPATH + "/ldmt_exe/instantMesh.exe"
|
||||
subprocess.Popen(InstantMeshPath,False)
|
||||
else:
|
||||
self.instantMeshes_sendToExe()
|
||||
|
||||
def remesh(self):
|
||||
targetCount = self.ui.text_targetCount.toPlainText()
|
||||
try:
|
||||
if targetCount.endswith('%'):
|
||||
sel = cmds.ls(sl=1,o=1)
|
||||
sel = sel[0]
|
||||
currentFaceCount = int(cmds.polyEvaluate(sel, f=True))
|
||||
targetCount = 2*int(currentFaceCount*float(targetCount[:-1])/100)
|
||||
else:
|
||||
targetCount = int(targetCount)
|
||||
except:
|
||||
ld.msg('Please input a number or ratio!')
|
||||
return
|
||||
self.instantMeshes_remesh(targetCount)
|
||||
|
||||
def instantMeshes_sendToExe(self,face_count=None):
|
||||
inst_mesh_path = LDMTPATH + "/ldmt_exe/instantMesh.exe"
|
||||
if not os.path.exists(inst_mesh_path):
|
||||
cmds.warning('Instant Mesh path not found!')
|
||||
return
|
||||
# Get current selection
|
||||
sel_obj = cmds.ls(sl=True)
|
||||
if sel_obj:
|
||||
print('Processing Instant Mesh...')
|
||||
# Create temp file for OBJ export
|
||||
# temp = tempfile.NamedTemporaryFile(prefix='instantMesh_', suffix='.obj', delete=False)
|
||||
# temp_path = temp.name
|
||||
|
||||
temp_file = os.path.join(self.temp_dir, 'instantMesh_temp.obj')
|
||||
# Make sure OBJexport is loaded
|
||||
if not cmds.pluginInfo('objExport', q=True, loaded=True):
|
||||
cmds.loadPlugin('objExport')
|
||||
# Save the currently selected object as an OBJ
|
||||
cmds.file(temp_file, force=True, exportSelected=True, type="OBJexport")
|
||||
# run instamesh command on the OBJ
|
||||
# print(temp_path)
|
||||
print("Instant Mesh start")
|
||||
some_command = inst_mesh_path + " " + temp_file
|
||||
p = subprocess.Popen(some_command, False)
|
||||
# temp.close()
|
||||
else:
|
||||
cmds.warning('No objects selected...')
|
||||
|
||||
def instantMeshes_remesh(self,face_count=None):
|
||||
inst_mesh_path = LDMTPATH + "/ldmt_exe/instantMesh.exe"
|
||||
if not os.path.exists(inst_mesh_path):
|
||||
cmds.warning('Instant Mesh path not found!')
|
||||
return
|
||||
# Get current selection
|
||||
sel_obj = cmds.ls(sl=True)
|
||||
if sel_obj:
|
||||
print('Processing Instant Mesh...')
|
||||
# if no polycount set just double the amount of the source object
|
||||
if not face_count:
|
||||
face_count = int(cmds.polyEvaluate(sel_obj, f=True))
|
||||
face_count *= 2
|
||||
face_count /= 2
|
||||
face_count = int(face_count)
|
||||
# Create temp file for OBJ export
|
||||
# temp = tempfile.NamedTemporaryFile(prefix='instantMesh_', suffix='.obj', delete=False)
|
||||
# temp_path = temp.name
|
||||
temp_path = os.path.join(self.temp_dir, 'instantMesh_temp.obj')
|
||||
# Make sure OBJexport is loaded
|
||||
if not cmds.pluginInfo('objExport', q=True, loaded=True):
|
||||
cmds.loadPlugin('objExport')
|
||||
# Save the currently selected object as an OBJ
|
||||
cmds.file(temp_path, force=True, exportSelected=True, type="OBJexport")
|
||||
# run instamesh command on the OBJ
|
||||
print(temp_path)
|
||||
print("Instant Mesh start")
|
||||
some_command = inst_mesh_path + " " + temp_path + " -o " + temp_path + " -f " + str(face_count) + " -D" + " -b"
|
||||
p = subprocess.Popen(some_command, stdout=subprocess.PIPE, shell=True)
|
||||
p.communicate()
|
||||
p.wait()
|
||||
print("Instant Mesh end")
|
||||
print(some_command)
|
||||
# import back the temp OBJ file
|
||||
returnedNodes = cmds.file(temp_path,
|
||||
i=True,
|
||||
type="OBJ",
|
||||
rnn=True,
|
||||
ignoreVersion=True,
|
||||
options="mo=1",
|
||||
loadReferenceDepth="all")
|
||||
# delete the temp file
|
||||
# temp.close()
|
||||
# Select the imported nodes
|
||||
if returnedNodes:
|
||||
cmds.select(returnedNodes, r=True)
|
||||
print("Instant Mesh done...")
|
||||
else:
|
||||
cmds.warning('No objects selected...')
|
||||
|
||||
def installStartBar(self):
|
||||
allQWidgets = self.ui.findChildren(QWidget)
|
||||
for i in allQWidgets:
|
||||
i.installEventFilter(self)
|
||||
|
||||
def eventFilter(self, obj, event ):
|
||||
'''Connect signals on mouse over'''
|
||||
if event.type() == QEvent.Enter:
|
||||
self.oldMessage = ld.tag()
|
||||
# self.statusbar.showMessage(' '+obj.statusTip(),0)
|
||||
elif event.type() == QEvent.Leave:
|
||||
# self.statusbar.showMessage(' '+self.oldMessage, 0)
|
||||
pass
|
||||
event.accept()
|
||||
return False
|
||||
|
||||
def closeEvent(self,event):
|
||||
# ld.turnToolBtnOff(self,ldmt_button_name)
|
||||
cmds.deleteUI(ldmt_window_name)
|
||||
|
||||
def ldmt_show():
|
||||
if cmds.window(ldmt_window_name, exists=True):
|
||||
cmds.deleteUI(ldmt_window_name)
|
||||
app = QApplication.instance()
|
||||
dialog = ldmt_cls(parent=app.activeWindow())
|
||||
|
||||
dialog.show()
|
||||
app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
ldmt_show()
|
Reference in New Issue
Block a user