Getting started

The bricks_from_* series of functions creates 3D models of LEGO bricks from a variety of input formats.

bricks_from_table() converts a matrix-shaped table of integers into LEGO bricks, where most columns are x-coordinates, rows are y-coordinates, and a special Level column denotes the elevation of the row. For simple models, this table can be made manually using data.frame() or tibble::tribble().

For more advanced models, it’s recommended you use MS Excel or a .csv file. bricks_from_excel() is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: brickr toybox.

Pass the output of any bricks_from_*() function to build_bricks() to render it as a 3D model.

Individual bricks

Create a single 2x4 brick with a 2x4 data frame, with an additional column to specify the ‘Level’. These can be letters or numbers.

Stack many bricks by changing the ‘Level’ value in the data frame. The script below uses purrr::map_df() to avoid copying and pasting. Changing the numeric values inside the data frame for each level creates different colors.

1:10 %>% 
  purrr::map_df(~dplyr::mutate(brick,
                        Level = LETTERS[.x], 
                        X1 = .x,
                        X2 = .x)) %>% 
  bricks_from_table() %>% 
  build_bricks(rgl_lit=FALSE, outline_bricks = TRUE)

rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 1.1*pi/4, 0, 0 ,1))

Full models

The most direct way to create a 3D model is to manually create a data frame. Below, we create a data frame using tibble::tribble() so we can more easily see the structure as it’s written.

The data frame has 3 numbers as input (values of 0 are void spaces in the model). Rather than use the default brickr colors for the values of 1, 2, and 3, we define another data frame ‘brick_colors’

Plates instead of bricks

Currently unavailable in build_bricks(). Use build_bricks_rayshader()

That’s clearly a tree, right? Why is the data frame called ‘tree_or_mushroom’?

Use the input ‘brick_type=“plate”’ to render the 3D model using LEGO plates rather than bricks, which are 1/3 as tall.

Bricks from Excel

When designing larger models, it is much easier to use a spreadsheet program to lay out the bricks for each level.

See the brickr toybox GitHub repo for some examples and templates.