Learn R Programming

rgl2gltf (version 1.0.7)

gltfWidget: Create a widget for a glTF display.

Description

This creates a widget holding a glTF scene, with controls to animate it if it supports animation, and with shaders that implement normal textures.

Usage

gltfWidget(gltf,
           animation = 0,
           start = times[1], stop = times[2],
           times = gltf$timerange(animation),
           method = c("shader", "rigid"),
           add = FALSE, close = !add,
           verbose = FALSE,
           open3dParams = getr3dDefaults(),
           usePBR = hasPBRparams(gltf),
           PBRargs = list(), ...)

Value

A widget suitable for display or inclusion in an R Markdown document.

Arguments

gltf

A "gltf" object, e.g. produced by readglTF.

animation

Which animation to use? If no animation is present, this is ignored.

start, stop

The starting and stopping times for the animation. Ignored if no animation.

times

An alternate way to specify the times. Ignored if no animation.

method

The "shader" method installs a custom shader to implement the animation in GLSL, as intended for glTF. This is necessary for the normal texture support. The "rigid" method duplicates vertices as necessary so that all triangles remain rigid as the vertices move, and should match the corresponding method in playgltf.

add

Should the gltf object be added to an existing rgl scene, or should it open a new scene?

close

Should gltfWidget close the rgl scene after producing the widget?

verbose

Give some progress information.

open3dParams

A list to pass as the params argument to open3d.

usePBR

Whether to use physically based rendering methods. The default uses an internal function to determine if gltf actually contains PBR parameters.

PBRargs

A list containing optional arguments to the setPBRshaders function.

...

Additional parameters which will be passed to rgl::playwidget.

Details

See playgltf for a description of the method used for animation. The "fixed" method is fast, but doesn't do a good job on some animations.

If the gltf object doesn't contain any animations, or animation = NA, this will simply display it as a widget with no controls.

Examples

Run this code
if ((interactive() || rgl::in_pkgdown_example()) && requireNamespace("manipulateWidget")) {
  gltf <- readGLB(system.file("glb/RiggedSimple.glb", package = "rgl2gltf"))
  gltfWidget(gltf)
}

Run the code above in your browser using DataLab