Reconstruct Subdiv for Maya [Python]

Just trying my hands on making little tools that could be useful in day to day work…
Here’s a small script which reverses the result of the smooth operation in maya even after deleting the history…and also preserves your UV
I know Zbrush and Mudbox already have this tool but i wanted to make it available withing maya
I have tried it on various models and seems to be giving correct results..except for one or two models..
I shall be working on the bugfixes soon…but as of now u r free to try this script on your models and let me know if you face any issues..
WARNING : It takes a while to calculate the mesh….may cause maya to freeze for a while…


Here is the script…

 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
#---------Reconstruct Subdiv Script for Maya----------
#Script by - Kanishk Chouhan
#Email - kanishk2391@gmail.com
#Blog - www.pixel-architect.blogspot.com

#Description - 
#This script allows u to reverse the result of smooth operation in maya after deleting the history
#It also preserves the original UV of the mesh
#Select the mesh u want to unsmooth and execute the script
#Script might take some time to execute depending on the polycount...

import maya.cmds as cmds
import maya.mel as mel

#Get the selected mesh
selectedMesh=cmds.ls( selection=True )[0]
#Get the vertex count i.e. vertex id of last vertex...
vertexCount=cmds.polyEvaluate( v=True )
vertexId = selectedMesh+'.vtx['+str(vertexCount)+']'
cmds.select(vertexId)
#Convert selection to edges...
x=cmds.polyListComponentConversion( fv=True,te=True )
cmds.select(x)

#get the edges number...
k=x[0].rfind(']')
l=x[0].rfind('[')
start = x[0][l+1:]
edges = str(start[:-1])
colon = edges.split(':')

#Select edge loops and rings...
mel.eval('SelectEdgeLoopSp;')
mel.eval('polySelectEdgesEveryN "edgeRing" 2;')
mel.eval('SelectEdgeLoopSp;')
mel.eval('SelectEdgeLoopSp;')
mel.eval('SelectEdgeLoopSp;')
mel.eval('polySelectEdgesEveryN "edgeRing" 2;')

#Delete the selected edgeloops
cmds.polyDelEdge( cv=True )

cmds.select(selectedMesh)

 

U can download it from the link below….

 

Leave a Reply

Your email address will not be published. Required fields are marked *