BFC

From LDraw.org Wiki
Revision as of 23:58, 27 March 2018 by Steffen (talk | contribs) (Created page with "'''BFC''' is the abbreviation for <u>B</u>ack <u>F</u>ace <u>C</u>ulling. That is a term from computer graphics: It describes a mechanism which assigns an orientation to a su...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

BFC is the abbreviation for Back Face Culling.

That is a term from computer graphics: It describes a mechanism which assigns an orientation to a surface, i.e., which side is "front" and which side is "back".

A software for 3D rendering can use that information to speed up its computations and renderings.

Read on to understand the details.

Orientation of Triangles and Quads: Which Side is "Front", and Which is "Back"?

In our LDRAW world, we have triangles and quads. Imagine such a triangle or quad in 3D space. It is infinitely thin, but has 1 front side and 1 back side. The question is: which side is front, and which is back? The choice is arbitrary, we just have to make a clear definition. The one chosen in LDRAW is: follow the sequence of corner points in the order they are written in the LDRAW files and let the 4 fingers of your right hand follow these points in 3D space. Then your erect thumb points to a certain direction. That side of the surface shall be called "front", the other side "back". (We could have chosen just the opposite definition - as said, the choice is arbitrary.) By using this simple definition, a clear and unique "side naming" is applied to such a triangle (or quad). If you reverse the sequence of corner points, then your thumb will point to the opposite direction. Thus, by reversing that sequence, the orientation of such a surface can be "flipped", meaning that the former "front" becomes "back", and the former "back" becomes "front".

Counter-Clockwise and Clockwise

The above description of the definition of a "front" and "back" side is difficult to remember without a clear name. LDRAW historically has found 2 easy-to-remember names for the orientation definition of "front" and "back": If you take an example triangle, put it into the X/Y plane, look at it from -Z direction to Z direction, and follow its points in COUNTER CLOCKWISE order, then by the above definition you will be looking at the FRONT of that triangle. That's why LDRAW chose the name "COUNTER CLOCKWISE BFC ORIENTATION" for that mechanism of defining FRONT and BACK of triangles. Of course, if you want the definition to be opposite, i.e., run through the points in CLOCKWISE order to see the front, then your definition will be called "CLOCKWISE BFC ORIENTATION". Every LDRAW file can choose which definition of FRONT and BACK it wants to use. It does so by writing a statement into its header:

0 BFC CERTIFY CCW

tells the consumer of this file that its contained triangles and quads follow the "COUNTER CLOCKWISE" definition for "front" and "back". Opposite to that, writing

0 BFC CERTIFY CW

into the header tells the consumer of this file that its contained triangles and quads follow the "CLOCKWISE" definition for "front" and "back".

Why is "Front" and "Back" Information of Surfaces Useful for Renderers?

If a renderer knows which side of a face is "front" and which is "back", and if a 3D geometric object made of such faces is looked at in 3D space, then a renderer can profit from that: it can know that those faces, of which only the rear can be seen, can be left out from rendering, if desired by the user. You can see an example image showing that mechanism in action in the Wikipedia: back-face culling. Leaving away these faces from the render can speed it up significantly.

"BFCing" an LDRAW File

"BFCing" an LDRAW file means to do 2 things with it:

  • Adding a 0 BFC CERTIFY CCW or 0 BFC CERTIFY CW statement to its header, and thereby stating that all its faces are (intended to be) properly oriented.
  • Checking that all faces are oriented in the file in the way that all part "outside" is formed by "front" faces and all "inside" is formed by "back" faces only.

Achieving this requires that a part author corrects the sequence of points of the surfaces inside the file.

(this article is currently work-in-progress by Steffen, I'll continue here later)

[[Category:]]