Reconstructing Faces

Hi
When we create a plane the the face number (id) is in order and continuous. But when extruded or tessellated the continuity of the face number is getting changed. Is there a way to recreate or reconstruct the faces with continuous number?

Or please tell if there is a command to find the face next or near a selected face …

Thanks in advance

I don’t know which program you’re working in, but in 3dsmax I did it by finding edges/vertices of the selected face (through maxscript functions) and then find faces of those edge/vertices again.
So basically you determin neighbor faces, by finding faces that share a different element with the current face. You can even find loops this way, by recursing through neighbors of neighbors.

Does that make sense?

@saschaherfort : Thanks … This might be useful. I am using maya.
Is there any way for re ordering the face number ??

No, and depending on that sort of thing can be very dangerous if you don’t have predictable constraints (like procedurally created objects).

nicardo, what is the intended result?

The purpose of my tool is to make a huge object (Terrain in my case) into the given number of pieces with specified poly count. I am just using a plane without adding or deleting the poly to create the terrain, by the sculpt tool. So its easy for me to split into squares. But if i subdivide a region or add or delete, the order of the face is different and the face selection pattern is getting changed as i am calculating the terrain as row and columns with numbers in order.
Now I am trying to do area selection in the screen space ,so i don’t want to worry about the face number … if u got any easy way, please suggest.

Any suggestions for me ?

Hi nIcardo,

I’m not sure if I understand what you are trying to do yet, maybe a quick diagram would help explain it?

Keir

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.

If you want it to always be a regular grid pattern would it not be better to subdivide the initial plane and then move the faces to create the terrain? Or am I misunderstanding.

I had that plan before… but didn’t work.

I see,

If I were tackling this script I would ignore the face indices. They are not reliable and you are better off making your own data structure you can control.

The Plan:
Get the extents of the mesh that you need to cut up. Should be able to use the bounding box values in world space.

Create a class that represents a grid tile. It should have its AABB(axis aligned bounding box) values. It should also have a method to test is a given point is inside or outside its AABB. It should be able to store a list of faces.

Create a list of empty grid title, enough that you can cover the whole mesh. At this stage you should be setting their AABB.

Now go through each face in your mesh, find the center point, test that point against each grid tile. If it’s inside the tile’s range add it to that tiles list of faces.

Now all your faces are sorted into tiles, export each tile.

More Reading:
You should also do some research into Octrees.
I have used this script in the past to achieve a similar result to the above idea. Its just a bit more efficient (and complex). It took a lot of tweaking to get it behaving as I wanted.

Good Luck!

Keir

Thanks a lot… :slight_smile:
will try it right now