Cleaning LDraw Files for Export
LDraw models are great to look at, but are generally inappropriate for real-time rendering tasks such as video games. Here's why.
Level of detail
The main issue is detail. LDraw models are highly accurate representations of real Lego parts. Each part can have lots of minute details, and the number of parts in a single large model can be quite huge! This amount of detail translates into lots and lots of polygons, which is the main limiter of how well a real-time rendering application will run.
The second issue is hidden objects: LDraw models are made up of multiple smaller parts. These parts are assembled as they are, with no modification. Thus, all the inner bits and pieces (such as studs) that are visible when viewing the part by itself but invisible when viewing the entire model are still there. That means there's lots of detail (and thus polygons) in the model that will never see the light of day!
The third issue is redundancy: Let's take for example a model composed of two identical bricks stacked on top of each other. The bricks are flush with each other such that the bottom surface of the top object is pressed against the top surface of the bottom object. You could say that many of the surface details where the two objects meet occupy the same place, or are coincident. In reality, there's a tiny gap (the seam width) between these surfaces where a small amount of air can pass through. In computer modeling, however, it is often desirable to disregard the seam width and simply make all points and surfaces mathematically perfect. While this is trivial to do and can lead to pleasing results, it introduces a problem: each part has a set of matching surfaces and vertices shared by the other part. Some of these surfaces and vertices are in fact duplicates. The duplicate elements no longer serve a useful purpose, and end up merely taking up much needed space in the model file. There's a strong need to get rid of these redundant, wasteful elements.
I know of two tentative, partially automated ways of addressing these issues that, when used in conjunction with each other, might eliminate the above problems: removing internal faces using MeshLab and using LDBoxer to convert parts to simpler, lighter versions. I will not discuss these in detail. They are, however, addressed in the links at the end of this article. Simple poly-reduction techniques such as Blender's "Decimate" operation will not work, as they choose polygons more or less randomly, and don't differentiate between the "inside" and "outside" of a model.
Note that there is an additional issue related to MeshLab's internal face reduction approach: back-face culling (BFC). When cleaning parts from a model, Meshlab requires that the vertices of the triangles be "wound" properly. Winding is what allows the program (and other programs that use 3D models) to determine the surface normal when not specifically defined, and thus (roughly) the "outside" and "inside" of the model. If the vertices are not wound properly, the program will get confused and behave improperly. Unfortunately, in the case of LDraw models not all parts have been validated as "BFC certified", and thus wound properly. This fact peculiar to LDraw models will likely make the approach untenable in the majority cases.