Learn R Programming

rgl2gltf: Read and write .gltf and .glb files

This R package contains functions to read, write and display .gltf and .glb files containing 3D models, following the official spec at khronos.org . It also contains functions to convert rgl scenes and mesh3d objects to and from glTF objects.

It is still in active development. Please add issues or pull requests if something important to you is missing.

A pkgdown website is here: https://dmurdoch.github.io/rgl2gltf/dev/

To install from CRAN, run

install.packages("rgl2gltf")

To install the development version, run

remotes::install_github("dmurdoch/rgl2gltf")

Sample code:

library(rgl)
library(rgl2gltf)

gltf <- readGLB("https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/2CylinderEngine/glTF-Binary/2CylinderEngine.glb?raw=true")
mesh <- as.mesh3d(gltf)
plot3d(gltf)
snapshot3d(webshot = FALSE, filename = "man/figures/engine.png")

Copyright

Most of this package is written by Duncan Murdoch and licensed under GPL 2.0.

Sample files in inst/glb and inst/localtests are unmodified copies of files from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0, and have details of copyright and licenses listed there. All have permissive licenses, some requiring acknowledgment.

Files in inst/localtests are in the Github repository, but are not included in the package tarball.

Briefly,

  • 2CylinderEngine.glb was produced by Okino Computer Graphics.
  • AlphaBlendModeTest.glb, NormalTangentTest.glb and NormalTangentMirrorTest.glb were created by Ed Mackey and are owned by Analytical Graphics, Inc., licensed under CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/.
  • AntiqueCamera.glb was produced by Maximilian Kamps and UX3D.
  • Avocado.glb was produced by Microsoft.
  • BarramundiFish.glb was produced by Microsoft.
  • BoxAnimated.glb and RiggedSimple.glb were produced by Cesium.
  • BrainStem.glb was created by Keith Hunter and is owned by Smith Micro Software, Inc. 
  • DamagedHelmet.glb was created by theblueturtle_.

Files src/mikktspace.c and src/mikktspace.h are written by Morten S. Mikkelsen and used under the permissive license included within them, with slight modifications for C99 compatibility.

Copy Link

Version

Install

install.packages('rgl2gltf')

Monthly Downloads

201

Version

1.0.7

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Duncan Murdoch

Last Published

November 21st, 2024

Functions in rgl2gltf (1.0.7)

setPBRshaders

Set shaders for physically based rendering.
readglTF

Read a glTF file
showTags

Debugging tool: show tags for objects in rgl scene
showtree

Show the tree structure of nodes in a glTF object or rglscene object.
writeglTF

Write a glTF or GLB file.
readGLB

Read a GLB file.
playgltf

Play an animated glTF object.
as.rglscene.gltf

Convert a glTF object to an rglscene or mesh3d object.
getTangents

Use the MikkTSpace code to generate tangent vectors.
extractTexture

Extract a texture file from a glTF object
findEntry

Find a component of a recursive object
matrixSequence

Print the sequence of matrices affecting an object.
modifyShaders

Edit shader code
gltfWidget

Create a widget for a glTF display.
as.gltf

Produce glTF objects
imports

Imports from rgl
Gltf

R6 Class for glTF file objects