layerMask value limit

Hi am creating multiple viewports with independent layers which my meshes are allocated too. I seem to be running into trouble with the layerMask bitmask values. I will need aleast 8 values to play with, 4 different cameras and triads. The first four work:

modelOne.layerMask = 0x10000000;
modelTwo.layerMask = 0x20000000;
modelThree.layerMask = 0x40000000;
modelFour.layerMask = 0x80000000;

however I cannot use any other value after allocating my first four - meshes are places in the wrong viewport etc. I would guess then next one would be 0x160000000.

I’ve also tried normal Integersm but that doesnt work either:

2
4
8
16

Am I doing something wrong, or if there a limitation I need to know about ? Thanks in advance

as it is defined in hex I would think:

0x000000001
0x000000002
0x000000004
0x000000008
0x000000010
0x000000020
0x000000040
0x000000080
0x000000100

should work ?

2 Likes

So just like @sebavan is saying for values like 2, 4, 8, and 16, they would be expressed in hex with the zeroes on the left (eg. 2 = 0x00000002). You should also be able to mix hex and decimal values for the layermasks as long as they match up bit-wise.
Example:

a.layerMask = 1;
b.layerMask = 2;
c.layerMask = 4;
d.layerMask = 8;
e.layerMask = 16;

// Show all five meshes
camera.layerMask = 0x0000001F;

// Show a and e
camera.layerMask = 0x00000011;
2 Likes

ok great its working now. I had to loop over all the meshes and override the default value. setting scene.meshes.forEach(mesh => mesh.layerMask =0) first then I get control

Yes, not easy to understand about layerMask. FYI: This is why (following my desperate request for answers about 18months ago :wink:, with the invaluable help and expertise of @Evgeni_Popov, we have introduced this new section of in-depth layer mask in the doc.

Edit: Pls feel free to improve it and make it even more comprehensive.

2 Likes

I didn’t know we had a guide that goes in depth on the layerMask. That’d be a good resource to link on the layerMask page in the Cameras section of the docs. Awesome work @mawa!

1 Like

Also, I changed the default years ago, so that there are top 4 levels which are beyond the the default. This should be enough for most people to assign without going through all the meshes to make room. They are:

0x10000000
0x20000000
0x40000000
0x80000000

Yes, I bet this section could be improved and updated. At least, it’s a base.