diff --git a/DESCRIPTION b/DESCRIPTION index 45c308f..f14df9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: brickr Title: Tools to emulate the LEGO® System in R -Version: 0.1.1.9002 +Version: 0.2.0 Authors@R: person(given = "Ryan", family = "Timpe", @@ -8,7 +8,7 @@ Authors@R: email = "ryan.timpe@gmail.com") Description: Generate digital LEGO-esque models using tidyverse functions. Convert image files into 2D and 3D mosaics, along with piece counts and instructions. - Build 3D models using data frames with rayshader. Create brick bar charts with ggplot2. + Build 3D models using data frames with rgl. Create brick bar charts with ggplot2. License: GPL-3 Encoding: UTF-8 LazyData: true diff --git a/NAMESPACE b/NAMESPACE index cbd03be..aec7472 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,7 @@ export(bricks_from_mosaic) export(bricks_from_rayshader) export(bricks_from_table) export(build_bricks) -export(build_bricks_rgl) +export(build_bricks_rayshader) export(build_colors) export(build_instructions) export(build_mosaic) diff --git a/NEWS.md b/NEWS.md index 19d35c3..7e46d16 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ -# brickr 0.2.1 +# brickr 0.2.0 + +* Lots of bug fixes. More to come. ## Documentation diff --git a/R/bricks-from-rayshader.R b/R/bricks-from-rayshader.R index a9a4fad..a078d94 100644 --- a/R/bricks-from-rayshader.R +++ b/R/bricks-from-rayshader.R @@ -49,7 +49,7 @@ bricks_from_rayshader <- function(hillshade, heightmap, max_height = 12, img_siz purrr::map_df(function(lvl){ dat <- img_sorted_by_lum %>% #Only get colors at or above the current level - dplyr::filter(Level >= lvl) %>% + dplyr::filter(Level >= lvl & Level <= (lvl + 2)) %>% #Replace any higher levels with colors in this level dplyr::mutate(Lego_name = ifelse(Level > lvl, NA_character_, Lego_name), Lego_color = ifelse(is.na(Lego_name), NA_character_, Lego_color), diff --git a/README.Rmd b/README.Rmd index f3a7bb1..f7995e2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -10,6 +10,8 @@ output: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) +rgl::setupKnitr() + library(brickr) library(jpeg) library(tidyverse) @@ -27,7 +29,7 @@ library(tidyverse) The package is divided into 3 separate systems: - [**Mosaics**](#mosaics): Convert image files into mosaics that could be built using LEGO® bricks. - - [**3D Models**](#3d-models): Build 3D LEGO® models from simple data formats & [rayshader](https://www.rayshader.com/). + - [**3D Models**](#3d-models): Build 3D LEGO® models from data tables using [rgl](https://cran.r-project.org/web/packages/rgl/index.html). - [**Charts**](#charts): A [ggplot2](https://ggplot2.tidyverse.org/) extension to generate plots that resemble LEGO® bricks. brickr also includes tools help users create the Mosaics and 3D model output using real LEGO® elements. @@ -42,7 +44,7 @@ The goal of **brickr** is to provide a series of tools to integrate the LEGO® - Generating interest in R and coding for new audiences with easy-to-create 3D models. - or just embracing pure novelty. -*brickr is developed using publicly available information about LEGO® products and is not officially affiliated with The LEGO Group* +*brickr is developed under the [Fair Play](https://www.lego.com/en-us/legal/notices-and-policies/fair-play/) policy using publicly available information about LEGO® products. brickr is not affiliated with The LEGO Group.* ## Installation ``` r @@ -83,7 +85,7 @@ In general, any **brickr** function that begins with `build_` generates a graphi ## 3D Models -The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://www.rayshader.com/) package. +The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a variety of input formats. - `bricks_from_table()` & `bricks_from_excel()` convert a matrix-shaped table of integers into LEGO bricks. 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. The left-most column in the table is associated with the Level or z-axis of the model. `bricks_from_excel()` is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: [brickr toybox](https://github.com/ryantimpe/brickr_toybox). @@ -91,9 +93,10 @@ The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a - `bricks_from_mosaic()` converts a 2D [mosaic](#mosaics) object from an image into 3D LEGO models, respectively. `bricks_from_rayshader()` creates a LEGO model from the same input as `rayshader::plot_3d()`. -Pass the output from any `bricks_from_*()` function to `build_bricks()` to see the 3D model. The `brick_res` option allows for higher resolution bricks in 'hd' or 'uhd', which will take longer to render. +Pass the output from any `bricks_from_*()` function to `build_bricks()` to see the 3D model. +Models are currently rendered in **rgl**. Previous versions of brickr use [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://www.rayshader.com/) package. This option is still available by passing the output from any `bricks_from_*()` function to `build_bricks_rayshader()`. Rayshader can still be used for saving snapshots and creating animations. -```{r bricks_1, echo=TRUE, warning=FALSE, message=FALSE, fig.width=3, fig.height=3} +```{r bricks_1, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=3, fig.height=3} library(brickr) #This is a brick @@ -105,9 +108,11 @@ brick <- data.frame( brick %>% bricks_from_table() %>% - build_bricks(brick_res = "uhd") + build_bricks() + +#Rotate the default view for a better snapshot +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 0.75*pi, 0, 0 ,1)) -rayshader::render_snapshot( clear = TRUE) ``` ### Stacking bricks @@ -116,7 +121,7 @@ The Level column in the input table determines the elevation of the bricks. `bri For larger models, use `tibble::tribble()` to more easily visualize the model. For very large models, use a csv or Excel. -```{r bricks_5, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4} +```{r bricks_5, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4} my_first_model <- tibble::tribble( ~Level, ~X1, ~X2, ~X3, ~x4, ~x5, ~X6, ~x7, ~x8, "A", 1, 1, 1, 0, 1, 1, 1, 1, @@ -149,16 +154,17 @@ brick_colors <- tibble::tribble( my_first_model %>% bricks_from_table(brick_colors) %>% - build_bricks(theta = 210, brick_res = "uhd") + build_bricks() -rayshader::render_snapshot(clear = TRUE) +#Rotate the default view for a better snapshot +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 1.1*pi, 0, 0 ,1)) ``` ### Programmatically build models Use `bricks_from_coords()` to programmatically build 3D LEGO models instead of manually drawing them in a spreadsheet or table. Here you must provide whole number coordinates for x, y, and z, along with an official LEGO color name for each point. -```{r bricks_6, echo=TRUE, warning=FALSE, message=FALSE, fig.width=5, fig.height=5} +```{r bricks_6, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=5, fig.height=5} radius <- 4 sphere_coords <- expand.grid( x = 1:round((radius*2.5)), @@ -177,11 +183,14 @@ sphere_coords <- expand.grid( sphere_coords %>% bricks_from_coords() %>% - build_bricks(brick_res = "uhd", phi = 30, theta = 30) + build_bricks(outline_bricks = TRUE, rgl_lit = FALSE) -rayshader::render_snapshot(clear = TRUE) + +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 1.1*pi/4, 0, 0 ,1)) ``` +The option `outline_bricks = TRUE` adds a black outline around the edges of the bricks. Setting `rgl_lit = FALSE` turns off automated lighting effects from rgl. Changing these two inputs together renders bricks in a more cartoon fashion. + ### Examples More examples using `bricks_from_table()` and `bricks_from_coords()` can be found at the links below. diff --git a/README.md b/README.md index c60efa1..390695f 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ The package is divided into 3 separate systems: - [**Mosaics**](#mosaics): Convert image files into mosaics that could be built using LEGO® bricks. - - [**3D Models**](#3d-models): Build 3D LEGO® models from simple data - formats & [rayshader](https://www.rayshader.com/). + - [**3D Models**](#3d-models): Build 3D LEGO® models from data tables + using [rgl](https://cran.r-project.org/web/packages/rgl/index.html). - [**Charts**](#charts): A [ggplot2](https://ggplot2.tidyverse.org/) extension to generate plots that resemble LEGO® bricks. @@ -41,8 +41,10 @@ LEGO® system with R by: easy-to-create 3D models. - or just embracing pure novelty. -*brickr is developed using publicly available information about LEGO® -products and is not officially affiliated with The LEGO Group* +*brickr is developed under the [Fair +Play](https://www.lego.com/en-us/legal/notices-and-policies/fair-play/) +policy using publicly available information about LEGO® products. brickr +is not affiliated with The LEGO Group.* ## Installation @@ -101,9 +103,7 @@ functions. ## 3D Models The `bricks_from_*` series of functions creates 3D models of LEGO bricks -from a variety of input formats. These models are rendered using [Tyler -Morgan-Wall](https://twitter.com/tylermorganwall)’s -[rayshader](https://www.rayshader.com/) package. +from a variety of input formats. - `bricks_from_table()` & `bricks_from_excel()` convert a matrix-shaped table of integers into LEGO bricks. For simple models, @@ -128,8 +128,13 @@ Morgan-Wall](https://twitter.com/tylermorganwall)’s as `rayshader::plot_3d()`. Pass the output from any `bricks_from_*()` function to `build_bricks()` -to see the 3D model. The `brick_res` option allows for higher resolution -bricks in ‘hd’ or ‘uhd’, which will take longer to render. +to see the 3D model. Models are currently rendered in **rgl**. Previous +versions of brickr use [Tyler +Morgan-Wall](https://twitter.com/tylermorganwall)’s +[rayshader](https://www.rayshader.com/) package. This option is still +available by passing the output from any `bricks_from_*()` function to +`build_bricks_rayshader()`. Rayshader can still be used for saving +snapshots and creating animations. ``` r library(brickr) @@ -143,9 +148,10 @@ brick <- data.frame( brick %>% bricks_from_table() %>% - build_bricks(brick_res = "uhd") + build_bricks() -rayshader::render_snapshot( clear = TRUE) +#Rotate the default view for a better snapshot +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 0.75*pi, 0, 0 ,1)) ```  @@ -192,9 +198,10 @@ brick_colors <- tibble::tribble( my_first_model %>% bricks_from_table(brick_colors) %>% - build_bricks(theta = 210, brick_res = "uhd") + build_bricks() -rayshader::render_snapshot(clear = TRUE) +#Rotate the default view for a better snapshot +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 1.1*pi, 0, 0 ,1)) ```  @@ -225,13 +232,19 @@ sphere_coords <- expand.grid( sphere_coords %>% bricks_from_coords() %>% - build_bricks(brick_res = "uhd", phi = 30, theta = 30) + build_bricks(outline_bricks = TRUE, rgl_lit = FALSE) -rayshader::render_snapshot(clear = TRUE) + +rgl::par3d(userMatrix = rgl::rotate3d(rgl::par3d("userMatrix"), 1.1*pi/4, 0, 0 ,1)) ```  +The option `outline_bricks = TRUE` adds a black outline around the edges +of the bricks. Setting `rgl_lit = FALSE` turns off automated lighting +effects from rgl. Changing these two inputs together renders bricks in a +more cartoon fashion. + ### Examples More examples using `bricks_from_table()` and `bricks_from_coords()` can diff --git a/README_files/figure-gfm/bricks_1-1.png b/README_files/figure-gfm/bricks_1-1.png index 1b8ed6d..b0e68d5 100644 Binary files a/README_files/figure-gfm/bricks_1-1.png and b/README_files/figure-gfm/bricks_1-1.png differ diff --git a/README_files/figure-gfm/bricks_5-1.png b/README_files/figure-gfm/bricks_5-1.png index 809945b..5d9bb81 100644 Binary files a/README_files/figure-gfm/bricks_5-1.png and b/README_files/figure-gfm/bricks_5-1.png differ diff --git a/README_files/figure-gfm/bricks_6-1.png b/README_files/figure-gfm/bricks_6-1.png index c71117f..c3dc964 100644 Binary files a/README_files/figure-gfm/bricks_6-1.png and b/README_files/figure-gfm/bricks_6-1.png differ diff --git a/README_files/figure-gfm/geom_brick2-1.png b/README_files/figure-gfm/geom_brick2-1.png index 984602a..3b51842 100644 Binary files a/README_files/figure-gfm/geom_brick2-1.png and b/README_files/figure-gfm/geom_brick2-1.png differ diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..d675a1f --- /dev/null +++ b/docs/404.html @@ -0,0 +1,173 @@ + + + +
+ + + + +