Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

deleting faces in a polygon

ayaallah.saleh
Participant
Participant

deleting faces in a polygon

ayaallah.saleh
Participant
Participant

I have a poly cube with certain subdivisions and my code deletes certain faces at certain if conditions using polyDelFacet() 

The problem is if some faces are deleted at a certain condition, all the remaining faces get renumbered

so if another condition is also true it ends up deleting the wrong faces because if the renumbering that happened in the prev condition. 

 

Is there a way that the faces remain with the same numbers even if any faces are deleted?

or any other way I could deal with this?

 

example:

(pseudo code)

if a have a cube with subdivisions =1 so we have 6 faces

 

say code is 

if x+y>2:

  polyDelFacet(f[1] of cube)

else:

  if x+y<4:

    polyDelFacet(f[3]) of cube)

 

and x+y=3 then both conditions are true

 

what happens is face 1 is deleted correctly but the deleted face 3 is not the correct one I wanted to delete since 3 was the number of the face when the all the faces of the cube existed before deleting face number 1

 

I don't want this behavior. I want the face numbers to remain constant cause my code has a lot of loops and conditions and it needs to apply to different scenarios

 

     

 

0 Likes
Reply
1,210 Views
7 Replies
Replies (7)

Kahylan
Advisor
Advisor

Hi!

 

Reindexing of faces when other faces are deleted is inavoidable since it is fundamental to the way maya calculates geometry. So the Index of your faces is constantly going to change and there is no way around that.

 

Now, since you only gave pseudo code and therefore I can't know what exactly your program needs to achieve, I'm afraid I can't really help you.

 

I can tell you two possible ways I could think of to deal with your problem:

1) You account for deleted faces by adding in math that changes the index of the faces you are targeting or your conditions accoriding to the amount of faces you deleted and their indexes.

 

2) You first store all the indexes of faces you need to delete into an array and then delete them all at once when you checked all your conditions. If all the faces are deleted with the same command, reindexing will occur after the command is run.

 

I can't really say what the right approach is form the information you gave.

0 Likes

ayaallah.saleh
Participant
Participant
if I go with option 2, how can I delete all faces in the array with one command?
the number of faces may differ according to my conditions, so I have to loop through the array and delete each one which will result in the same reindexing problem
0 Likes

Kahylan
Advisor
Advisor

the polyDelFacet() command as well as the normal delete() command will delete all elements of an array if an array is passed, e.g:

string $faces[] = {"pCube1.f[0]", "pCube1.f[3]"};

polyDelFacet($faces)

 

0 Likes

ayaallah.saleh
Participant
Participant

I am getting a syntax error
Do you happen to know what is the problem?

0 Likes

ayaallah.saleh
Participant
Participant

 

           $faces =[]    
           for i in range(len(doorsL)):
              selectedD=doorsL[i]
              print('START AND END COORD OF LINE')
              print(selectedD)
              object1=cmds.pointOnCurve( selectedD, pr=0 )
              startX=object1[0]
              print('start x= '+str(startX))
              startZ=object1[2]
              object2=cmds.pointOnCurve( selectedD, pr=1 )
              endX=object2[0]
              print('end x= '+str(endX))
              endZ=object2[2]

              print('xMin= ' +str(xMin))
              print('xMax= '+str(xMax)) 
              
           
              
              if (xMax>startX>xMin):
                 print('CASE 1')
                 if (startX>endX):
                    print('door in face 4')
                    faces.append("selectedR.f[9]")
                    faces.append("selectedR.f[10]")
                    cmds.polySubdivideFacet( '%s.f[4]' % selectedR , dv=2 )

                          
                 if (startX<endX):
                    print('door in face 3')  
                    faces.append("selectedR.f[3]")  
                    
              if (xMax>endX>xMin):
                 print('CASE 2')    
                 if (endX>startX):
                    print('door in face 4')
                    cmds.polySubdivideFacet( '%s.f[4]' % selectedR , dv=2 )
                    faces.append("selectedR.f[9]")
                    faces.append("selectedR.f[10]")
                    
                 if (endX<startX):
                     print('door in face 3')
                     faces.append("selectedR.f[3]")  
                     
           print(faces)  
           cmds.polyDelFacet($faces)  

 

sorry here is the code indented correctly

0 Likes

Kahylan
Advisor
Advisor

Ah sorry, I overlooked the the python tag in your first post, the synthax I wrote was MEL

 

just remove the "$" before "faces" and the synthax should be fine

 

also, if you are working in python 2.7 (Maya 2022 or below) you probably need to write the last line as:

cmds.polyDelFacet(*faces)

The * modifier was needed to unpack lists in certain functions in python 2.7 it should not be needed in python3, atleast I didn't need it when I tested the code.

0 Likes

ayaallah.saleh
Participant
Participant

sorry, I am just a beginner and started directly with python, not MEL so wasn't aware.
It is good now. Thank you so much.

0 Likes