Merge pull request #23 from ryantimpe/rglModels
Documentation and website updates for the 0.2 release
1
NEWS.md
@@ -9,6 +9,7 @@
|
||||
## 3D Models
|
||||
|
||||
* `build_bricks()` now renders models in {rgl}, rather than {rayshader}. Most options for the rendering have changed. Use `build_brick_rayshader()` for previous output.
|
||||
* Support for transparent bricks. See `build_colors()` for list of color names.
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -8,6 +8,18 @@
|
||||
#' Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.
|
||||
#' @param trans_alpha Default 0.5. Alpha level for transparent bricks.
|
||||
#' @param view_levels Numeric array of Levels/z values to display. Leave as 'NULL' to include all.
|
||||
#' @examples \dontrun{
|
||||
#' #This is a brick
|
||||
#'brick <- data.frame(
|
||||
#' Level="A",
|
||||
#' X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
|
||||
#' X2 = rep(3,4)
|
||||
#')
|
||||
#'
|
||||
#'brick %>%
|
||||
#' bricks_from_table() %>%
|
||||
#' build_bricks()
|
||||
#' }
|
||||
#' @return 3D brick model rendered in the 'rgl' package.
|
||||
#' @family 3D Models
|
||||
#' @export
|
||||
|
||||
@@ -43,7 +43,7 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
|
||||
hd = 30,
|
||||
uhd = 60)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#Use below is edge calculation
|
||||
# Optimized color only in HD bricks >20 pixels
|
||||
@@ -94,8 +94,8 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
|
||||
dplyr::mutate(x_mid = median(x), y_mid = median(y),
|
||||
stud = ((x-x_mid)^2 + (y-y_mid)^2)^(1/2) <= (ex_size * (5/8 * (1/2))),
|
||||
stud_color = dplyr::between(((x-x_mid)^2 + (y-y_mid)^2)^(1/2),
|
||||
(ex_size * (5/8 * (1/2))) - 1,
|
||||
(ex_size * (5/8 * (1/2))) + 1
|
||||
(ex_size * (5/8 * (1/2))) - 1,
|
||||
(ex_size * (5/8 * (1/2))) + 1
|
||||
)) %>%
|
||||
dplyr::ungroup() %>%
|
||||
dplyr::mutate(elevation = ifelse(stud, elevation+0.5, elevation)) %>%
|
||||
@@ -176,13 +176,25 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
|
||||
#' @param water Default 'FALSE'. If 'TRUE', a water layer is rendered.
|
||||
#' @param waterdepth Default '0'. Water level.
|
||||
#' @param ... All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, \code{zscale}, and \code{shadow}.
|
||||
#' @return 3D brick model rendered in the 'rgl' package.
|
||||
#' @examples \dontrun{
|
||||
#' #This is a brick
|
||||
#'brick <- data.frame(
|
||||
#' Level="A",
|
||||
#' X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
|
||||
#' X2 = rep(3,4)
|
||||
#')
|
||||
#'
|
||||
#'brick %>%
|
||||
#' bricks_from_table() %>%
|
||||
#' build_bricks()
|
||||
#' }
|
||||
#' @return 3D brick model rendered in the 'rayshader' package.
|
||||
#' @family 3D Models
|
||||
#' @export
|
||||
#'
|
||||
build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res = "sd",
|
||||
view_levels = NULL, solidcolor = "#a3a2a4",
|
||||
water = FALSE, waterdepth = 0, ...){
|
||||
view_levels = NULL, solidcolor = "#a3a2a4",
|
||||
water = FALSE, waterdepth = 0, ...){
|
||||
#Requires Rayshader
|
||||
if (!requireNamespace("rayshader", quietly = TRUE)) {
|
||||
stop("Package \"rayshader\" needed for this function to work. Please install it.",
|
||||
@@ -198,7 +210,7 @@ build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res =
|
||||
if(is.null(view_levels)){
|
||||
view_levels <- unique(img_lego$Level)
|
||||
}
|
||||
|
||||
|
||||
for(ii in view_levels){
|
||||
brick_layer <- brick_list %>%
|
||||
layer_from_bricks(ii, brick_type = brick_type, brick_res = brick_res)
|
||||
@@ -216,7 +228,7 @@ build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res =
|
||||
solidcolor=solidcolor, shadow = FALSE,
|
||||
water = FALSE, waterdepth = 0, ...)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -121,12 +121,20 @@ scaled_to_colors <- function(image_list, method = "cie94",
|
||||
#No transparent colors in mosaics
|
||||
dplyr::filter(!Trans_lego)
|
||||
} else{
|
||||
brick_table <- color_table
|
||||
# if(any(stringr::str_detect(color_table$Color, stringr::fixed("Tr. ")))){
|
||||
# warning("Transparent bricks cannot be used in mosaics. Removing from color_table.")
|
||||
# }
|
||||
|
||||
brick_table <- color_table %>%
|
||||
#No transparent colors in mosaics
|
||||
dplyr::filter(!stringr::str_detect(Color, stringr::fixed("Tr. ")))
|
||||
}
|
||||
|
||||
#Set up color palette... used standard way or with Dithering
|
||||
if(any(c("universal", "generic", "special") %in% color_palette)){
|
||||
brick_table <- brick_table %>%
|
||||
#No transparent colors in mosaics
|
||||
dplyr::filter(!Trans_lego) %>%
|
||||
dplyr::filter(tolower(Palette) %in% color_palette)
|
||||
} else {
|
||||
#Black and white is simpler... cut the colors into 4 groups, then assign lightest = white, darkest = black
|
||||
|
||||
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 4.8 KiB |
@@ -11,6 +11,7 @@ reference:
|
||||
contents:
|
||||
- starts_with("bricks_")
|
||||
- build_bricks
|
||||
- build_bricks_rayshader
|
||||
- title: ggplot Extension
|
||||
desc: Brick bar charts in ggplot
|
||||
contents:
|
||||
|
||||
BIN
docs/README_files/figure-gfm/bricks_1-1.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
docs/README_files/figure-gfm/bricks_2-1.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
docs/README_files/figure-gfm/bricks_3-1.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/README_files/figure-gfm/bricks_4-1.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
docs/README_files/figure-gfm/bricks_5-1.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
docs/README_files/figure-gfm/bricks_6-1.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
docs/README_files/figure-gfm/display_colors-1.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
docs/README_files/figure-gfm/geom_brick-1.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
docs/README_files/figure-gfm/geom_brick2-1.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
docs/README_files/figure-gfm/m1_3d-1.png
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
docs/README_files/figure-gfm/m1_instructions-1.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
docs/README_files/figure-gfm/m1_pieces-1.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
docs/README_files/figure-gfm/m1_set-1.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
docs/README_files/figure-markdown_github/m1_3d-1.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
docs/README_files/figure-markdown_github/m1_bw-1.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
docs/README_files/figure-markdown_github/m1_instructions-1.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
docs/README_files/figure-markdown_github/m1_orig-1.png
Normal file
|
After Width: | Height: | Size: 144 KiB |
BIN
docs/README_files/figure-markdown_github/m1_pieces-1.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
docs/README_files/figure-markdown_github/m1_set-1.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
docs/README_files/figure-markdown_github/m2_pieces-1.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
docs/README_files/figure-markdown_github/m2_set-1.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 79 KiB |
@@ -193,7 +193,8 @@
|
||||
<a class="sourceLine" id="cb4-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader</a></span>(<span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">phi =</span> <span class="dv">45</span>)</a>
|
||||
<a class="sourceLine" id="cb4-6" title="6"></a>
|
||||
<a class="sourceLine" id="cb4-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/rayshader/man/render_snapshot.html">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
|
||||
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"><img src="models-from-other_files/figure-html/bricks_rayshader-1.png" width="384"> This example is rendered using <code><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader()</a></code>, which a bit faster for very large sets.</p>
|
||||
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"></p>
|
||||
<p>This example is rendered using <code><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader()</a></code>, which a bit faster for very large sets.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 337 KiB |
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
@@ -7,6 +7,15 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-toggle .icon-bar {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav>li>a:hover {
|
||||
color: #FAC80A;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-link {
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
|
||||
@@ -164,6 +164,7 @@
|
||||
<ul>
|
||||
<li>
|
||||
<code><a href="../reference/build_bricks.html">build_bricks()</a></code> now renders models in {rgl}, rather than {rayshader}. Most options for the rendering have changed. Use <code>build_brick_rayshader()</code> for previous output.</li>
|
||||
<li>Support for transparent bricks. See <code><a href="../reference/build_colors.html">build_colors()</a></code> for list of color names.</li>
|
||||
</ul>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
@@ -200,6 +200,19 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.</p></td>
|
||||
<code><a href='bricks_from_table.html'>bricks_from_table</a></code>,
|
||||
<code><a href='build_bricks_rayshader.html'>build_bricks_rayshader</a></code></p></div>
|
||||
|
||||
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
|
||||
<pre class="examples"><div class='input'><span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
|
||||
<span class='co'>#This is a brick</span>
|
||||
<span class='no'>brick</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(
|
||||
<span class='kw'>Level</span><span class='kw'>=</span><span class='st'>"A"</span>,
|
||||
<span class='kw'>X1</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>), <span class='co'>#The number 3 is the brickrID for 'bright red'</span>
|
||||
<span class='kw'>X2</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>)
|
||||
)
|
||||
|
||||
<span class='no'>brick</span> <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='bricks_from_table.html'>bricks_from_table</a></span>() <span class='kw'>%>%</span>
|
||||
<span class='fu'>build_bricks</span>()
|
||||
}</div></pre>
|
||||
</div>
|
||||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||||
<h2>Contents</h2>
|
||||
@@ -207,6 +220,7 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.</p></td>
|
||||
<li><a href="#arguments">Arguments</a></li>
|
||||
<li><a href="#value">Value</a></li>
|
||||
<li><a href="#see-also">See also</a></li>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -195,7 +195,7 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
|
||||
|
||||
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
|
||||
|
||||
<p>3D brick model rendered in the 'rgl' package.</p>
|
||||
<p>3D brick model rendered in the 'rayshader' package.</p>
|
||||
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
|
||||
|
||||
<div class='dont-index'><p>Other 3D Models: <code><a href='bricks_from_coords.html'>bricks_from_coords</a></code>,
|
||||
@@ -205,6 +205,19 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
|
||||
<code><a href='bricks_from_table.html'>bricks_from_table</a></code>,
|
||||
<code><a href='build_bricks.html'>build_bricks</a></code></p></div>
|
||||
|
||||
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
|
||||
<pre class="examples"><div class='input'><span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
|
||||
<span class='co'>#This is a brick</span>
|
||||
<span class='no'>brick</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(
|
||||
<span class='kw'>Level</span><span class='kw'>=</span><span class='st'>"A"</span>,
|
||||
<span class='kw'>X1</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>), <span class='co'>#The number 3 is the brickrID for 'bright red'</span>
|
||||
<span class='kw'>X2</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>)
|
||||
)
|
||||
|
||||
<span class='no'>brick</span> <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='bricks_from_table.html'>bricks_from_table</a></span>() <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='build_bricks.html'>build_bricks</a></span>()
|
||||
}</div></pre>
|
||||
</div>
|
||||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||||
<h2>Contents</h2>
|
||||
@@ -212,6 +225,7 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
|
||||
<li><a href="#arguments">Arguments</a></li>
|
||||
<li><a href="#value">Value</a></li>
|
||||
<li><a href="#see-also">See also</a></li>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -215,6 +215,12 @@
|
||||
<p><code><a href="build_bricks.html">build_bricks()</a></code> </p>
|
||||
</td>
|
||||
<td><p>Build 3D brick model with rgl</p></td>
|
||||
</tr><tr>
|
||||
|
||||
<td>
|
||||
<p><code><a href="build_bricks_rayshader.html">build_bricks_rayshader()</a></code> </p>
|
||||
</td>
|
||||
<td><p>Build 3D brick model with rayshader.</p></td>
|
||||
</tr>
|
||||
</tbody><tbody>
|
||||
<tr>
|
||||
|
||||
@@ -29,6 +29,20 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.}
|
||||
\description{
|
||||
Build 3D brick model with rgl
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
#This is a brick
|
||||
brick <- data.frame(
|
||||
Level="A",
|
||||
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
|
||||
X2 = rep(3,4)
|
||||
)
|
||||
|
||||
brick \%>\%
|
||||
bricks_from_table() \%>\%
|
||||
build_bricks()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other 3D Models: \code{\link{bricks_from_coords}},
|
||||
\code{\link{bricks_from_excel}},
|
||||
|
||||
@@ -27,11 +27,25 @@ Enter a value for a custom resolution. High resolutions take longer to render.}
|
||||
\item{...}{All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, \code{zscale}, and \code{shadow}.}
|
||||
}
|
||||
\value{
|
||||
3D brick model rendered in the 'rgl' package.
|
||||
3D brick model rendered in the 'rayshader' package.
|
||||
}
|
||||
\description{
|
||||
Build 3D brick model with rayshader.
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
#This is a brick
|
||||
brick <- data.frame(
|
||||
Level="A",
|
||||
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
|
||||
X2 = rep(3,4)
|
||||
)
|
||||
|
||||
brick \%>\%
|
||||
bricks_from_table() \%>\%
|
||||
build_bricks()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other 3D Models: \code{\link{bricks_from_coords}},
|
||||
\code{\link{bricks_from_excel}},
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-toggle .icon-bar {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav>li>a:hover {
|
||||
color: #FAC80A;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-link {
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
|
||||
@@ -39,6 +39,7 @@ mosaic <- png::readPNG(demo_img) %>%
|
||||
|
||||
mosaic %>% build_mosaic()
|
||||
```
|
||||
|
||||
```{r bricks_6a, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
|
||||
mosaic %>%
|
||||
bricks_from_mosaic(highest_el = "dark") %>%
|
||||
@@ -62,7 +63,7 @@ rgl::par3d(userMatrix = rgl::rotate3d(custom_rotation, 0, 0, pi/4 ,1))
|
||||
* `max_height` is the number of bricks stacked at the mosaic's highest point. The default is 12.
|
||||
* `img_size` is the number of bricks on each side of the model. The default is 48.
|
||||
|
||||
```{r bricks_rayshader, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
|
||||
```{r bricks_rayshader, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
|
||||
library(rayshader)
|
||||
|
||||
#Example from rayshader.com
|
||||
@@ -95,4 +96,5 @@ rayshader_object %>%
|
||||
|
||||
rayshader::render_snapshot(clear = TRUE)
|
||||
```
|
||||
|
||||
This example is rendered using `build_bricks_rayshader()`, which a bit faster for very large sets.
|
||||