Leafs, What are they?
News Tutorials Coding Reviews Resources


Understanding Leafs

Leafs are something that all mappers should understand as they are an important factor in making a map without problems( who hasn't got the WARNING:leaf portals saw into leafs or the Max_Leaf_Faces error).Leafs come in to play in both the BSP and VIS compling.

BSP(Binary Space Portal) splits each level into leafs(a convex hull->player space) and portals.This is then written to your *.prt file. The joint area between 2 leafs is called a portal.

The way in which the level is split into leafs is very important,how can you effect this?..by using hint brushes (which will be discussed in another tutorial).All you need to know now is that during the compile process VIS finds the visibilty of different areas of your map by doing the following,

  • lets say you got a 2 leafs(XX and YY), now VIS checks if any point(brush) in leaf XX can see any point in leaf YY by connecting and by checking the intersection points with the players sightline(viewing frustrum/cone).
  • if the sightline goes through the portal, then everything in leaf XX is visible from leaf YY(this is what the engine thinks anyway)
  • otherwise nothing in leaf XX is displayed as you can't see anything in XX from leaf YY.

eg.(PLAN view)

     -The red boxes are the leafs.
     -The blue lines are the portals.

So whats WARNING:leaf portals saw into leaf?

Well this means that you have a leaf that isn't convex. David Hyde once gave the analogy 'It's equivalent to looking out the window of a room and seeing back into the room' and this pretty much explains it.

Convex Problems

What can i do?

This can be a very difficult problem to solve as you can't track it down normally as it more to due with portals than anything else.You basically have an over complex area thats generating this warning(check cyclindrical and vertex manipulated brushes first) and you can either simplify it, delete it or just turn it into a func_wall.

What about the MAX_LEAF_FACES error?

This results from an over detailed brush and the same solutions apply as above.

Want to go into more detail?

This is an extra/optional part of this tutorial which goes into more detail of how the leaf/portal system works.Take for example the following simple map,

BSP separates this map into 3 leafs (cells) and 2 portals which the next diagram(the PLAN view) demonstrates,

The red boxes are the leafs while the blue boxes are the portals.The generated *.prt file looks like,

PRT1
3
2
4 0 1 (352 -240 -448 ) (352 -384 -448 ) (352 -384 -384 ) (352 -240 -384 )
4 1 2 (288 -240 -448 ) (288 -384 -448 ) (288 -384 -384 ) (288 -240 -384 )

The following information can be extracted from the *.prt,

  • On the second line 3 indicates the number of portals in the level.
  • On the next line 2 indicates the number of leafs in the level.
Now comes the portal points(2 in this case),lets first look at the first portal point,
  • 4 is the number of vertices of this portal.
  • 0 and 1 are the reference numbers of the leafs connected by this portal.
  • The rest of the line contains the coordinates of portal.
The same explantion applies to the last portal point.

If you don't fully understand these leaf/portal concepts yet have a read of this article on 3D graphics.

Any questions/comments about this tutorial contact me