Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tylermorganwall/rayrollercoaster
Create 3D Rollercoasters in R
https://github.com/tylermorganwall/rayrollercoaster
Last synced: 2 months ago
JSON representation
Create 3D Rollercoasters in R
- Host: GitHub
- URL: https://github.com/tylermorganwall/rayrollercoaster
- Owner: tylermorganwall
- Created: 2022-07-05T04:39:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-19T00:46:43.000Z (over 2 years ago)
- Last Synced: 2023-08-02T05:50:40.288Z (over 1 year ago)
- Language: R
- Size: 21.5 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# rayrollercoaster
Make 3D rollercoasters out of rayshader and rayrender scenes, without leaving R! Use rayrender's interactive
renderer to fly through your scene or dataviz and add a fun ride to your scene.## Installation
You can install rayrollercoaster via github (Note: installation requires X11/XQuartz on Linux/macOS):
``` r
remotes::install_github("tylermorganwall/rayrollercoaster")
```## Example
You can make roller coasters via a pre-made rayrender scene, or by calling `generate_rayshader_coaster()`. Here, we load a scene up using rayshader.
```{r example, eval=FALSE}
library(rayrollercoaster)
library(rayshader)volcano |>
sphere_shade() |>
plot_3d(volcano,fov=90)#Now, let's fly through a series of points to build the rollercoaster.
#You can pass arguments to `render_scene()` via `...`.
#This function doesn't return anything, but saves the scene with the rollercoaster and the
#motion information internally. This extracts the scene from `rayshader` directly from `rgl`.
#Here, we turn off the lighting and use ambient lighting only
generate_rayshader_coaster(light=FALSE, ambient_light=T)#We can also add extra lights by passing arguments via `...` to `rayshader::render_highquality()`
generate_rayshader_coaster(lightdirection=c(315,45),lightcolor=c("orange","white"))#We can pass an HDR file for high quality realistic lighting (which we will use in the animation
#as well by passing `environment_light = tempfilehdr` to `animate_rollercoaster()`:
tempfilehdr = tempfile(fileext = ".hdr")
download.file("https://www.tylermw.com/data/venice_sunset_2k.hdr",tempfilehdr)
generate_rayshader_coaster(light=FALSE, environment_light=tempfilehdr)#We now can create our animation using `animate_rollercoaster()`. This extracts the information
#(scene and motion) in the previous step. If no filename is given,
#it will simply preview the animation in the interactive screen, without saving anything.
#Set samples to `1` to render a quick preview.
animate_rollercoaster(samples=1, width=200,height=200, environment_light=tempfilehdr)#Increase the number of samples and resolution for a high quality animation (but longer render):
animate_rollercoaster(samples=128, width=800, height=800, environment_light=tempfilehdr)#Alternatively, get the scene and motion data yourself and call `rayrender::render_animation()`
#directly.
scene = get_rayrender_scene()
motion = get_rayrender_motion()render_animation(scene, motion, samples=1, sample_method="sobol_blue",environment_light=tempfilehdr)
```You can also build rollercoasters directly from rayrender scenes:
```{r example2, eval=FALSE}
library(rayrender)
scene = generate_ground(material=diffuse(checkercolor="grey20")) |>
add_object(obj_model(r_obj(),y=-1,x=1, material=diffuse(color = "purple"))) |>
add_object(sphere(y=-0,x=-1,radius=1, material=dielectric())) |>
add_object(sphere(y=5,x=5,z=5,material=light(intensity = 50))) |>
add_object(sphere(y=5,x=-5,z=5,material=light(color="orange",intensity = 50)))
render_scene(scene, fov=40,sample_method="sobol_blue")#Now, let's fly through a series of points to build the rollercoaster.
#You can pass arguments to `render_scene()` via `...`.
#This function doesn't return anything, but saves the scene with the rollercoaster and the
#motion information internally.
generate_rayrender_coaster(scene, fov = 120)#We now can create our animation using `animate_rollercoaster()`. This extracts the information
#(scene and motion) in the previous step. If no filename is given,
#it will simply preview the animation in the interactive screen, without saving anything.
#Set samples to `1` to render a quick preview.
animate_rollercoaster(samples=1)#Increase the number of samples and resolution for a high quality animation (but longer render):
animate_rollercoaster(samples=128, width=800, height=800)#Set the FOV to 360 to render a movie for VR headsets
#Use the Spatial Media Metadata Injector app from google to add the metadata to render in VR on
#youtube (available here: https://github.com/google/spatial-media/releases)
animate_rollercoaster(samples=128, width=800, height=800, fov=360, filename="video360.mp4")
```