Notifications
Clear all

[Closed] What is the use of 'flag'??

hi.

Recently a problem has been borthering me. —-“flag”

such as :
polyop.getVertFlags <Poly poly> <int vert>
polyop.setVertFlags <Poly poly> <vertlist> <int flag> mask:<int=0> undoable:<boolean=false>

What is the use of this? And Mainly used in what place?? :shrug:

3 Replies

Did you read the explanation on the same page the methods were listed?
Granted, the description of what mask does is a bit convoluted (it was taken directly from the developer’s notes, I think), but the general idea is illustrated in the example that follows.

So Editable Poly has a bunch of flags associated with each vertex, stored in a long integer, which gives you exactly 32 bits (flags). A flag can be either raised (set, true) or not set (false) and can be used to mark certain vertices for special use. Some of these bits are reserved for internal use by the Editable Poly system, some are free for general use.

According to the help,

bit 1: vertex is selected
bit 2
: vertex is dead
bit 3
: reserved
bit 4
: indicates the vertex faces “backwards” in the current viewport
bit 5-24
: reserved
bit 25-32
: available for general use

So you can get and set vertices by flag, or get and set the flags themselves. For example, if you create a Sphere, collapse it to EPoly, select some vertices and call

polyop.getVertsByFlag $Sphere01 1

the returned result will be a bitarray with all selected vertices, equivalent to

polyop.getVertSelection $Sphere01

Similarly, asking for flag with bit 2 set will return all dead vertices and bit 4 will return all backfacing vertices.

polyOp.setVertSelection $Sphere01 (polyop.getVertsByFlag $Sphere01 8)

will select all vertices that are facing away in the current viewport.

The mask bits can be used to determine the opposite – what flags to ignore, for example to prevent dead vertices from being returned in the result. Since the mask and the flag integers are compared with a bitwise-AND, you have to set in the mask both the bit for the requested feature to produce true and return a result, and the one to filter by to produce false and filter by it. For example, in the backfacing vertices example above, (polyop.getVertsByFlag $Sphere01 8 mask:9) will return backfacing vertices that are NOT selected. This is because bit 1 (2^0) + bit 4 (2^3) = 9 and this tells the method that you do want backfacing but do not want selected.

You can use bits 25 to 32 to flag the vertices for your own needs, kind of like custom vertex selections. For example if you run some code that finds specific vertices, instead of storing this in a bitarray in your script, you could flag the vertices in one of the free bits for later retrieval. Using the mask, you can also filter out easily selected or dead vertices, or combine multiple “sets” of flags, subtract sets using the mask: keyword and so on.

Keep in mind this is a relatively low-level access to the internal workings of the Editable Poly object and there are higher-level methods for doing most of these operations, so if you don’t feel comfortable with using the flags or don’t understand what they are for, just ignore them.

hi bobo you are my idol!!!~
And Thank you very much to explain this problem for me . it is my pleasure

Would using flags vs polyop be faster? I am on my phone now so I can’t test.

Thanks!