as.gltf {rgl2gltf} | R Documentation |
Produce glTF objects
Description
The glTF file is the JSON part of a glTF representation of a 3D scene. This function creates the R structure corresponding to one, and writes the binary buffer file for it.
Usage
as.gltf(x, ...)
## Default S3 method:
as.gltf(x, y = NULL, z = NULL, vertices,
material = NULL,
normals = NULL,
texcoords = NULL,
points = NULL, segments = NULL,
triangles = NULL,
quads = NULL,
transform = diag(4),
extras = NULL,
...,
rglscene = list(),
previous = Gltf$new(),
newScene = FALSE,
parentNode = NULL,
dir = tempdir(),
scale = c(1,1,1))
## S3 method for class 'rglscene'
as.gltf(x, ..., previous = Gltf$new(),
newScene = FALSE)
## S3 method for class 'mesh3d'
as.gltf(x, ...)
Arguments
x |
An object to convert to a |
y , z |
In the default method, combined with |
vertices |
A 3 or 4 row matrix of Euclidean or homogeneous coordinates; takes
precedence over |
material |
material properties for rendering |
normals |
normals at each vertex as a 3 or 4 column matrix |
texcoords |
texture coordinates at each vertex as a 2 column matrix |
points |
vector of indices of vertices to draw as points |
segments |
2 x n matrix of indices of vertices to draw as segments |
triangles |
3 x n matrix of indices of vertices to draw as triangles |
quads |
4 x n matrix of indices of vertices to draw as quads |
transform |
4 x 4 matrix associated with this object (e.g. a subscene) |
extras |
A list to attach as |
... |
Other parameters passed to the default method. |
rglscene |
The RGL scene this came from, e.g. to look up defaults |
previous |
Optionally a previously produced |
newScene |
logical; if |
parentNode |
If not |
dir |
Where to write the binary buffer file. |
scale |
Rescaling in the enclosing subscene. |
Details
as.gltf
is a generic function.
The method for "rglscene"
objects can handle most
objects produced by scene3d
, but not all
objects will be handled. In particular:
Lights, text, bounding box decorations and backgrounds are saved in “extra” fields, so they can be read by rgl2gltf, but most other software will ignore them or only display some parts.
Most material properties are also stored in “extra” fields.
There are methods for many individual types of "rglobject"
, but these are intended for internal
use.
Value
A "gltf"
object.
Author(s)
Duncan Murdoch
References
The specification of the glTF format: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html
Examples
cube <- rgl::rotate3d(rgl::cube3d(col = "red"), -pi/10, 1,0,0)
gltf <- as.gltf(cube)
rgl::plot3d(gltf)
gltf$closeBuffers()