Last active
April 19, 2023 11:54
-
-
Save tylermorganwall/da2a41bbc4b755fd695e941143cfbab5 to your computer and use it in GitHub Desktop.
"RStudio Table Contest" 3D Table Render
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rayrender) | |
make_legs = function(x=0,y=0,z=0) { | |
csg_translate(y=-5, | |
csg_combine( | |
csg_rotate( | |
csg_pyramid(z=z,x=x,y=y, height = 10), pivot_point = c(x,5,y),up = c(0,-1,0)), | |
csg_box(x=x,z=z,y=2.5, width = c(1,5,1)), operation = "subtract")) | |
} | |
ang_vec = unlist(tweenr::tween(c(0,180), n=181, ease = "cubic-in-out"))[-181] | |
fov_vec = c(unlist(tweenr::tween(c(10.5,40), n=180, ease = "cubic-in-out")),rep(40,180)) | |
xval = c(rep(-20,180),-20*cospi(ang_vec*2/180)) | |
zval = c(rep(0,180),20*sinpi(ang_vec*2/180)) | |
yval = c(unlist(tweenr::tween(c(6.4,4.4), n=180, ease = "cubic-in-out")), rep(4.4,180)) | |
#Lamp 3D model: https://www.turbosquid.com/3d-models/3d-model-eclipse-desk-lamp-1388520 (edited in blender to remove cord) | |
#Succulent 3D model: https://sketchfab.com/3d-models/flower-pot-with-succulent-plants-acce0c2e1e5b4986b4ff18198eb90e3e | |
#Coffee cup 3D model: https://www.turbosquid.com/3d-models/3d-ceramic-coffee-cup-1427808 | |
#Laptop 3D model: https://free3d.com/3d-model/notebook-low-poly-version-57341.html | |
#HDRI environment image: hdrihaven.com | |
for(i in seq(1,360,by=1)) { | |
generate_ground(depth=0, spheresize=1000, material=diffuse(color="grey50",checkercolor = "grey20")) %>% | |
add_object(csg_object(make_legs(x=3,z=5), material=glossy(color="#2b0f02"))) %>% | |
add_object(csg_object(make_legs(x=-3,z=5), material=glossy(color="#2b0f02"))) %>% | |
add_object(csg_object(make_legs(x=3,z=-5), material=glossy(color="#2b0f02"))) %>% | |
add_object(csg_object(make_legs(x=-3,z=-5), material=glossy(color="#2b0f02"))) %>% | |
add_object(cube(y=5,ywidth=0.5, xwidth=7.5, zwidth=11.5,material=glossy(color="#2b0f02", gloss = 0.2))) %>% | |
add_object(xz_rect(y=5.26,xwidth=7.5, zwidth=11.5, | |
material=glossy(image_texture = "wood_planks.png", | |
bump_intensity = 0.0, | |
bump_texture = "Wood_Planks_009_DISP.png"))) %>% | |
add_object(obj_model("Lowpoly_Notebook_2.obj", texture = TRUE, y=5.3)) %>% | |
add_object(obj_model("Coffe_Cup.obj", texture = FALSE, y=5.6,z=3.1,x=-1.5, | |
material=glossy(color="grey90",gloss=0.3), | |
angle=c(0,225,0),scale_obj = 1/80)) %>% | |
add_object(obj_model("Pot.obj", angle=c(0,45,0), | |
texture = TRUE, y=5.25,z=-3.5,x=0.5,scale_obj = 0.7)) %>% | |
add_object(obj_model("lamp.obj", texture = FALSE, y=5.25,z=4,x=2, | |
material=microfacet(roughness=c(0.05,0.2), | |
eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)), | |
angle=c(0,225,0),scale_obj = 1/12)) %>% | |
add_object(yz_rect(y=6.4, x=0.22,zwidth=3.05,ywidth=1.95,flipped=TRUE, | |
material=light(intensity=1, importance_sample=FALSE, | |
image_texture = "desktop_screenshot.png"))) %>% | |
add_object(group_objects(sphere(y=0.3,material=glossy(color="#2b6eff",reflectance=0.05)) %>% | |
add_object(cube(y=-0.8,xwidth=2,ywidth=0.5,zwidth=2, | |
material=glossy(noisecolor="black", noise = 5, noiseintensity = 20))) %>% | |
add_object(obj_model(r_obj(),z=1,y=0.05,scale_obj=0.45,material=diffuse())), | |
group_translate = c(-2,5.8,-5), group_angle = c(0,-70,0), group_scale = c(0.5,0.5,0.5))) %>% | |
render_scene(lookat=c(0.22,yval[i],0),clamp_value=10, aperture=0.3, | |
lookfrom=c(xval[i],10,zval[i]), width=800,height=800, | |
fov=fov_vec[i],samples=400, sample_method="stratified", | |
filename=glue::glue("raytablereal{i}"), | |
environment_light = "the_sky_is_on_fire_2k.hdr") | |
} | |
for(i in 1:180) { | |
png::writePNG(png::readPNG(glue::glue("raytablereal{181-i}.png")), glue::glue("raytablereal{i+360}.png")) | |
} |
Thanks! The CSG functionality will be released in the next version version of rayrender
Great work Tyler! Learned a new thing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome job Tyler! Thanks for sharing! In trying to run your code, it appears the referenced "csg_object" is missing.