tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.07k stars 214 forks source link

Export function to GLTF [FEATURE] #290

Open SbastianGarzon opened 1 year ago

SbastianGarzon commented 1 year ago

Export function to GLTF

Hello, I'm working on a solution to integrate rayshader models into virtual reality environments (e.g., A-frame). I'm wondering if it is possible to have a save_gltf() function. You mentioned in an old issue that you have developed a function for this task.

writeWebGL currently is fairly limited in its utility--It only supports 65536 vertices per object, so it's not ideal given map dimensions will be limited to a maximum of 256x256. I've got a glTF 2.0 output function written that will eventually be included that has no such limitations, so that's going to form the basis of a rglwidget() replacement that could be used on RStudio server.

Originally posted by @tylermorganwall in https://github.com/tylermorganwall/rayshader/issues/27#issuecomment-459987313

dmurdoch commented 12 months ago

Have you tried rgl2gltf::writeGLB?

SbastianGarzon commented 2 months ago

Hi @dmurdoch,

I'm trying this approach, following your example here

volcano %>%
  sphere_shade(texture = "desert") %>%
  plot_3d(volcano, zscale = 10, fov = 0, theta = 135, phi = 45, zoom = 0.75, windowsize = c(1000, 800))

# Capture the rgl scene
scene <- rgl::rglwidget()

# Convert rgl scene to GLTF 
gltf <- rgl2gltf::as.gltf(scene)

I'm getting this error:

Error in xyz.coords(x, y, z, recycle = TRUE) :
'x' is a list, but does not have components 'x', 'y' and 'z'