top of page

LEGO EDITOR

TYPE

SUMMARY

TOOLS & TECH

University

Development of an editor for building complex structures with LEGO bricks

C++ // DirectX // Shader Programming

Editor_1.png

I created the first version of a LEGO editor for an assignment during the first semester of my Games Software Development course at Sheffield Hallam University. The original task did not require the implementation of an editor, only an application capable of rendering structures made from individual bricks. However, I decided early on to create an editor, as it made building LEGO structures much more convenient than placing each brick manually through code.

​

I used C++ and DirectX 9 to develop this first version of the application, which consisted of several components, including a camera system, input handler, editor logic, and a renderer. The user could cycle through available brick types and colors, and view the current selection through a simple user interface. The editor also displayed a grid to support accurate placement. When a brick was placed, a data set was created containing its position (derived from the selected grid cell), rotation, and identifiers for the brick type and color. These were stored in a container and passed to the renderer for display.

​

To allow continued work on previously created structures, I implemented a simple save and load system that wrote and read the brick data sets to and from a text file. However, I soon noticed that manually placing every single brick became increasingly time-consuming for larger builds. To address this, I added support for custom LEGO structures that could be defined by the user and reused multiple times. To define a structure, the user could activate "Recording Mode." All bricks placed while this mode was active were not only added to the usual brick container, but also temporarily stored in a second one. When recording ended, the user could name the structure, and the application would create a new reusable object from the recorded bricks. This structure could then be selected and placed like any regular brick type.

​

To improve the application's performance, I implemented frustum culling in combination with an octree for spatial partitioning. An octree is a hierarchy of bounding volumes where each node contains eight equally sized sub-volumes, all within the volume of its parent. When a brick was placed, it was assigned to the smallest node that fully enclosed it. Rather than checking each brick individually against the view frustum, the application only tested the bounding volumes of relevant nodes.
I also attempted to implement hardware instancing to further improve performance. However, I did not manage to get it working in time for the assignment submission. As a result, performance suffered when several thousand bricks were on screen.

​

In my spare time, I continued working on the editor in order to address these limitations, especially in terms of performance. I also used the opportunity to transition from DirectX 9 to DirectX 11 and become more familiar with the newer API. The updated editor retains all features of the original version, but many have been improved during the DirectX 11 migration. For example, the octree has additional uses, and I improved modularity by separating interfaces from implementations. Additionally, I was able to successfully implement hardware instancing, which significantly improved performance. The editor could then render tens of thousands of LEGO bricks without dropping below 30 frames per second, at least on my laptop at the time.

​

I actually used this updated version of the editor as a sort of testbed to compare different cel shading techniques for another module during my second semester. The latest version therefore includes six toon shaders that simplify lighting and draw black outlines around object silhouettes, each using a different method. I encapsulated each shader in its own class and added functionality to switch between them at runtime. This made it possible to directly compare the performance and visual quality of each shader from the same camera angle.

​

Even when I stopped working on the editor, there was still a long list of ideas and improvements that I never got around to implementing, including:

  • Add a more advanced graphical interface with buttons, icons, and menus

  • Replace text file storage with binary files to speed up saving and loading

  • Expand the list of available shaders and visual effects

  • Add a level of detail system to improve performance by combining distant meshes

  • Explore occlusion culling to further reduce the rendering load

  • Introduce a first-person camera with collision detection to allow users to walk through their LEGO worlds

The video below shows the latest version of the editor, including demonstrations of the different shaders. It's a bit old, so the quality is not the best but I think it's sufficient to give a good idea of the capabilities of the editor. 

bottom of page