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

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(), ...)

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.

Note

Physically based rendering (PBR, controlled by usePBR) is only used with method = "shader".

If PBR is not used, the V8 package is required so that the shaders can be modified.

Value

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

Examples

if ((interactive() || rgl::in_pkgdown_example()) && requireNamespace("manipulateWidget")) {
  gltf <- readGLB(system.file("glb/RiggedSimple.glb", package = "rgl2gltf"))
  gltfWidget(gltf)
}
#> Loading required namespace: manipulateWidget