Updated
This commit is contained in:
61
Scripts/Modeling/Edit/LDMT/ldmt_function/ldmt_loadUIFile.py
Normal file
61
Scripts/Modeling/Edit/LDMT/ldmt_function/ldmt_loadUIFile.py
Normal file
@ -0,0 +1,61 @@
|
||||
#from Qt.QtCompat import wrapInstance, getCppPointer
|
||||
import os
|
||||
import maya.cmds as cmds
|
||||
import maya.OpenMayaUI as omui
|
||||
try:
|
||||
from Qt.QtCore import *
|
||||
from Qt.QtGui import *
|
||||
from Qt.QtWidgets import *
|
||||
from Qt import __version__
|
||||
# from Qt.QtUiTools import QUiLoader
|
||||
from Qt.QtCompat import loadUi
|
||||
# from pyside2uic import *
|
||||
from Qt.QtCompat import wrapInstance
|
||||
|
||||
except ImportError:
|
||||
from Qt.QtCore import *
|
||||
from Qt.QtGui import *
|
||||
from Qt import __version__
|
||||
# from pysideuic import *
|
||||
from Qt.QtCompat import wrapInstance
|
||||
# from cStringIO import StringIO
|
||||
# import xml.etree.ElementTree as xml
|
||||
|
||||
def get_maya_window():
|
||||
|
||||
ptr = omui.MQtUtil.mainWindow()
|
||||
#if ptr is not None:
|
||||
return wrapInstance(int(ptr), QMainWindow)
|
||||
|
||||
def load_ui_file(ui_path):
|
||||
if not os.path.exists(ui_path):
|
||||
cmds.warning("UI file not found: {}".format(ui_path))
|
||||
return None
|
||||
# ui_file = QFile(ui_path)
|
||||
# ui_file.open(QFile.ReadOnly)
|
||||
# ui = loadUi(ui_file)
|
||||
ui = loadUi(ui_path)
|
||||
# ui = QUiLoader().load(ui_file)
|
||||
# ui_file.close()
|
||||
return ui
|
||||
|
||||
def load_ui_type(ui_path):
|
||||
pass
|
||||
# parsed = xml.parse(ui_file)
|
||||
# widget_class = parsed.find('widget').get('class')
|
||||
# form_class = parsed.find('class').text
|
||||
|
||||
# with open(ui_file,'r') as f:
|
||||
# o = StringIO()
|
||||
# frame = {}
|
||||
|
||||
# compileUi(f, o, indent = 0)
|
||||
# pyc = compile(o.getvalue(), '<string>', 'exec')
|
||||
# exec(pyc, frame)
|
||||
|
||||
|
||||
# # Fetch the base_class and form class based on their type in the xml from design
|
||||
# form_class = frame['Ui_{0}'.format(form_class)]
|
||||
# base_class = eval('{0}'.format(widget_class))
|
||||
|
||||
# return form_class, base_class
|
@ -0,0 +1,30 @@
|
||||
import maya.cmds as cmds
|
||||
import maya.mel as mel
|
||||
import maya.api.OpenMaya as om2
|
||||
|
||||
def morph2UV(baseObj):
|
||||
sel = baseObj
|
||||
selList = om2.MSelectionList()
|
||||
selList.add(sel)
|
||||
path = selList.getDagPath(0)
|
||||
myMesh = om2.MFnMesh(path)
|
||||
newPointArray = om2.MPointArray()
|
||||
space = om2.MSpace.kWorld
|
||||
myMesh_UVs = myMesh.getUVs()
|
||||
myMesh_points = myMesh.getPoints()
|
||||
# for i in range(myMesh.numVertices):
|
||||
myMesh_itVertex = om2.MItMeshVertex(path)
|
||||
points = om2.MPointArray()
|
||||
while not myMesh_itVertex.isDone():
|
||||
vertIndex = myMesh_itVertex.index()
|
||||
gotUV = myMesh_itVertex.getUV()
|
||||
point = om2.MPoint(gotUV[0],gotUV[1],0)
|
||||
points.append(point)
|
||||
myMesh_itVertex.next()
|
||||
myMesh.setPoints(points,space)
|
||||
|
||||
def runMorph2UV(sel):
|
||||
baseObjDup = cmds.duplicate(sel)
|
||||
baseObj = baseObjDup[0]
|
||||
morph2UV(baseObj)
|
||||
return baseObj
|
75
Scripts/Modeling/Edit/LDMT/ldmt_function/ldmt_morphToUV.py
Normal file
75
Scripts/Modeling/Edit/LDMT/ldmt_function/ldmt_morphToUV.py
Normal file
@ -0,0 +1,75 @@
|
||||
import maya.cmds as cmds
|
||||
import maya.mel as mel
|
||||
import maya.api.OpenMaya as om2
|
||||
def deleteNoUV():
|
||||
selObj = cmds.ls(sl=1,o=1)
|
||||
selObj = selObj[0]
|
||||
selObj_face = selObj + '.f[*]'
|
||||
selObj_face = cmds.ls(selObj_face, fl=1)
|
||||
selObj_uv = cmds.polyListComponentConversion(selObj,tuv=1)
|
||||
selObj_face_hasUV = cmds.polyListComponentConversion(selObj_uv,tf=1)
|
||||
selObj_face_hasUV = cmds.ls(selObj_face_hasUV, fl=1)
|
||||
selObj_face_noUV = list(set(selObj_face).difference(set(selObj_face_hasUV)))
|
||||
if selObj_face_noUV:
|
||||
cmds.delete(selObj_face_noUV)
|
||||
return selObj
|
||||
|
||||
def splitIfOnUVBorder():
|
||||
sel = cmds.ls(sl=1,o=1)
|
||||
sel = sel[0]
|
||||
selList = om2.MGlobal.getActiveSelectionList()
|
||||
selListPath = selList.getDagPath(0)
|
||||
vertIt = om2.MItMeshVertex(selListPath)
|
||||
selMesh = om2.MFnMesh(selListPath)
|
||||
vertIdToSplit = []
|
||||
vertToSplit = []
|
||||
while not vertIt.isDone():
|
||||
uvIndices = vertIt.getUVIndices()
|
||||
uvIndices = list(set(uvIndices))
|
||||
if len(uvIndices)>=2:
|
||||
vertIdToSplit.append(vertIt.index())
|
||||
elif vertIt.onBoundary():
|
||||
vertIdToSplit.append(vertIt.index())
|
||||
vertIt.next()
|
||||
for i in range(len(vertIdToSplit)):
|
||||
vertToSplit.append(sel+'.vtx['+str(vertIdToSplit[i])+']')
|
||||
cmds.polySplitVertex(vertToSplit,cch=0)
|
||||
|
||||
def morph2UV():
|
||||
sel = cmds.ls(sl=1,o=1)
|
||||
sel = sel[0]
|
||||
selList = om2.MSelectionList()
|
||||
selList.add(sel)
|
||||
path = selList.getDagPath(0)
|
||||
myMesh = om2.MFnMesh(path)
|
||||
newPointArray = om2.MPointArray()
|
||||
space = om2.MSpace.kWorld
|
||||
myMesh_UVs = myMesh.getUVs()
|
||||
myMesh_points = myMesh.getPoints()
|
||||
# for i in range(myMesh.numVertices):
|
||||
myMesh_itVertex = om2.MItMeshVertex(path)
|
||||
points = om2.MPointArray()
|
||||
while not myMesh_itVertex.isDone():
|
||||
vertIndex = myMesh_itVertex.index()
|
||||
gotUV = myMesh_itVertex.getUV()
|
||||
point = om2.MPoint(gotUV[0],gotUV[1],0)
|
||||
points.append(point)
|
||||
myMesh_itVertex.next()
|
||||
myMesh.setPoints(points,space)
|
||||
|
||||
def runMorph2UV():
|
||||
baseObj = cmds.ls(sl=1,o=1) #1. inputmesh
|
||||
baseObjDup = cmds.duplicate() #2. duplicate
|
||||
mel.eval("FreezeTransformations")
|
||||
mel.eval("ResetTransformations")
|
||||
baseObj = baseObjDup[0]
|
||||
deleteNoUV()
|
||||
splitIfOnUVBorder()
|
||||
morph2UV()
|
||||
currentSelection = cmds.ls(sl=1)
|
||||
currentUV = cmds.polyListComponentConversion(currentSelection,tuv=1)
|
||||
cmds.polyMergeVertex(currentSelection,d=0.0001,cch=0)
|
||||
cmds.polyMergeUV(currentUV,d=0.001,cch=0) # fix split
|
||||
cmds.select(baseObj,r=1)
|
||||
if __name__ == "__main__":
|
||||
runMorph2UV()
|
@ -0,0 +1,7 @@
|
||||
import maya.cmds as cmds
|
||||
import maya.mel as mel
|
||||
def normalFacet():
|
||||
sel = cmds.ls(sl=1,o=1)
|
||||
cmds.polyNormalPerVertex(sel,ufn=1)
|
||||
mel.eval('SetToFaceNormals;')
|
||||
mel.eval('DeleteHistory;')
|
Reference in New Issue
Block a user