Notifications
Clear all

[Closed] want to understand that paragraph

[color=white]Get By Flag[/color]

[left]
[/left]
[left]polyop.getVertsByFlag <Poly poly> mask:<int maskflag>
[/left]
[left]Each vertex in a poly contains a 32 bit flag variable. This method returns a bitarray of the vertices that have specific bits in this flag variable set, where the bits being tested are based on a combination of <flag> and <maskflag>.
[/left]
[left]The default value for <maskflag> is 0.
[/left]
[left]Internally, if <maskflag> is 0 then <maskflag> is set to the <flag> value, otherwise <flag> is set to the bitwise-AND of <flag> and <maskflag>. Bit 2 of <maskflag> is then set, which prevents dead vertices from being included in the resulting bitarray unless this bit was set in <mask>. Each bit in the resulting bitarray is set if the bitwise-AND of the flag variable and <maskflag> is equal to the bitwise-AND of <flag> and <maskflag>.
[/left]
[left]The vertex level flags are:
[/left]
[left]bit 1: vertex is selected
[/left]
[left]bit 2: vertex is dead
[/left]
[left]bit 3: reserved
[/left]
[left]bit 4: indicates the vertex faces “backwards” in the current viewport
[/left]
[left]bit 5-24: reserved
[/left]
[left]bit 25-32: available for general use
[/left]

read it many many times tried to understand and searched out the threads and didnt get it

5 Replies

is my question is so hard? or is it really simple ?

It’s rather simple. You should read somewhere what flags (bit fields) are.

 For example we have 4 bits variale (number that can be 0-15)
 Now each bit can means something true or false (1 or 0):
 [left][b][b]bit 1[/b][/b]: vertex is selected
  [/left]
   [left][b][b]bit 2[/b][/b]: vertex is dead
  [/left]
   [left][b][b]bit 3[/b][/b]: reserved
  [/left]
   [b][b]bit 4[/b][/b]: indicates the vertex faces "backwards" in the current  viewport
 
 So we have example value:
 [b]1010[/b] - our value in binnary notation
 
 now we want to check is the [b][b]"[/b]bit 3[/b][b]: reserved[/b]" parameter is true
 We will use [b]MASK[/b] and [b]AND[/b] operation to do it. 
 [b]AND[/b] operation is same as multipling (but for single bits)
 
    [b]    1010[/b] - our value in binnary notation
 [b]0100[/b] - mask contains the parameter to check
 -------
        [b]0000[/b] - result is false, so the parameter is not true (not set)
 
 [b][b]
 checking bit 2[/b]: vertex is dead[/b]:
    [b]    1010[/b] - our value in binnary notation
  [b]0010[/b] - mask contains the parameter to check
  -------
         [b]0010[/b] - result is true, so the parameter is true (set)
 
 Mask can contains more than one parameters to check, in this case result will be true if ANY parameter is set (true)

oh thats much better , but another qs emergs: are bits read from right to left ?, i noticed that in your examples
another more important note what is the importance of these flags practically?

Yes, bits flags are counted from left to rgiht.
Offen you can read about flags 2 4 8 16 32…, becouse of:
0001 is 1 in decimal
0010 is 2
0100 is 4
1000 is 8
so value 7 contains flags 1, 2 and 4 (1+2+4=7)

I often use flags to quickly get the indexes of new faces/edges/vertices created from flagged faces/edges/vertices. As far as I know “children” of flagged f/e/v inherits the flag.


area51 = convertTo (plane()) polyMeshObject  --create a plane, convert it to editable_poly
flag = bit.set 0 30 true  --create a flag with an available bit (25-32), true must be on in this case
polyop.setFaceFlags area51 6 flag --assign the flag to a face
polyop.tessellateByFace area51 6 --create new faces on the flagged face
newFaces = polyop.getFacesByFlag area51 flag --get the new face indexes
polyop.setFaceSelection area51 newFaces