I am putting my initial script here…
Some of the values are hard coded and to check this , create a polyplane
(mc.polyPlane (w = 20, h = 20 , sw = 30, sh = 30 , cuv = 2 )
and run the script, it will export the plane into squares in the given path
###########################################################
import maya.cmds as mc
import math
#directory to export the pieces
dir= mc.fileDialog2(fileMode=3, caption="Choose Directory")
#Select the source Terrian
realmesh = mc.ls(sl=True,tr=True)
mc.select(realmesh[0])
noPoly = mc.polyEvaluate(face=True)
sqr_noPoly = math.sqrt(noPoly)
endPoly = (int(sqr_noPoly))-1
chunkSize = 15
noRow = int(sqr_noPoly/chunkSize)
currentRow = 0
currentColumn = 0
fillSelection = 0
for currentRow in range(0,noRow):
#print "Row " + str(currentRow)
for currentColumn in range (0,noRow):
chunkStart = (currentColumn*chunkSize)+(endPoly*chunkSize*currentRow)+(chunkSize*currentRow)
print "chunkStart " + str(chunkStart)
mc.select (realmesh)
mc.duplicate(realmesh[0],name="TerrainChunk")
mesh = mc.ls (sl=True,tr=True)
faceInverseSelect=(str(mesh[0]) + ".f[0:"+str(int(noPoly-1))+"]")
mc.select(clear=True)
for fillSelection in range (0,chunkSize):
col = int(chunkStart)
colend = int((col+chunkSize)-1)
row = col+(int(sqr_noPoly * fillSelection))
rowEnd = int((row+chunkSize)-1)
faceSelection = (str(mesh[0]) + ".f["+str(col)+":"+str(colend)+"]")
faceSelectionLoop = (str(mesh[0]) + ".f["+str(row)+":"+str(rowEnd)+"]")
#print faceSelection
#print faceSelectionLoop
mc.selectType (polymeshFace=True)
mc.selectMode(component=True)
mc.select(faceSelection,faceSelectionLoop,add=True)
#print "Chunk"+ str(fillSelection)
mc.select(faceInverseSelect,tgl=True)
print "InvertSelection " + str(currentColumn)
print "Deleted" + str(currentColumn)+ "pre"
mc.selectType(polymeshFace=True)
mc.delete()
mc.select (mesh[0])
print "Deleted" + str(currentColumn)
mc.polyMultiLayoutUV(layoutMethod =1,scale=1,rotateForBestFit=1,flipReversed=True,percentageSpace=0.2,layout=2,prescale=0,sizeU=1,sizeV=1,offsetU=0,offsetV=0)
file=( str(dir[0]) + "/" + mesh[0] + ".obj" )
mc.file(file,force=True,type='OBJexport',pr=True,es = True )
tmpchunks=mc.ls(tr=True)
nooftempchunks = len(tmpchunks)
i=0
for i in range (0,int(nooftempchunks)):
mc.select(tmpchunks[i])
if ("Chunk" in str(tmpchunks[i])):
mc.delete()
del mesh[:]
del realmesh[:]
###########################################################
After checking extrude the plane or delete a face or smooth a region and run the script.
If you check the exported file, the shape will not be in square , as the order face number is changed.
All i want is the output pieces should be in square and not in a irregular shape. Suggest me to make it on a complex mesh.