Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving rgl 3D scene to u3d (for .pdf integration)

Tags:

r

rgl

raster

u3d

I have a 3D scene generated with the R rgl package.

  • I can save it in RTL and OBJ format via the rgl functions, but these functions don't support colors.
  • I can save it in WebGL, but then I can't find a WebGL to .u3d converter, nor any way to insert WebGL content in a .pdf file (generated with LaTeX).
  • I can save it in PLY format and then export to .u3d (e.g. using Meshlab), but it gives me the following error:

    Error in if (sum(normals[1:3, it[j, i]] * normal) < 0) normals[, it[j,  : 
    missing value where TRUE/FALSE needed 
    

Which I really don't know how to solve.

Here is an example file to reproduce the problem. To reproduce simply download the file in the working directory, execute R and run:

library(rgl)
load("alps3d.Rdata") #This loads the alps3d variable
plot3d(alps3d)
writePLY("alps3d.ply")

How can I save the 3d scene in a format which can be itegrated in a .pdf using LaTeX?

like image 582
AF7 Avatar asked Feb 27 '15 09:02

AF7


Video Answer


2 Answers

You should try writeASY(). It writes for Asymptote, which can produce PRC rather than U3D, but may be good enough. I tried your sample scene, and it takes about 5 minutes to load the result in Acrobat Reader, but it eventually loads and works.

writeASY() is a recent addition to rgl; you'll need to get it from the R-Forge or Github copies.

like image 159
user2554330 Avatar answered Oct 24 '22 18:10

user2554330


You can use rgl.postscript, which allows to export to various formats, including pdf. Well, the result is not terrific, but that should depend on the type of plot.

> x <- y <- seq(-10, 10, length = 20)
> z <- outer(x, y, function(x, y) x^2 + y^2)
> persp3d(x, y, z, col = 'lightblue')
> rgl.postscript("persp3d.pdf", "pdf")

enter image description here

You can also export to tex, allowing to do some manual modifications.

like image 32
Stéphane Laurent Avatar answered Oct 24 '22 17:10

Stéphane Laurent