Gltf {rgl2gltf}R Documentation

R6 Class for glTF file objects

Description

The glTF file spec is described here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html. This object encapsulates most of the data from those files.

Super class

rgl::Buffer -> gltf

Public fields

scene

The default scene number

Methods

Public methods

Inherited methods

Method new()

Usage
Gltf$new(json = NULL, defaultbin = NULL)
Arguments
json

List read from glTF file.

defaultbin

Optional external binary file.


Method addAccessor()

Write values to accessor, including min and max.

The glTF standard requires min and max values in accessors, whereas other uses of buffers may not. This function stores in the usual way using the Buffer$addAccessor() method, and then adds min and max values.

The standard also doesn't support signed 4 byte integers or double precision values, so we test for those here.

Usage
Gltf$addAccessor(values, target = NULL, types = "anyGLTF", normalized = FALSE)
Arguments
values

Values to write.

target

Optional target use for values.

types

Allowed types (from names of rgl::gltfTypes), or c("any", "anyGLTF")).

normalized

Are these normalized integer values?

Returns

New accessor number.


Method getScene()

Get scene object.

Usage
Gltf$getScene(sc)
Arguments
sc

Scene number.

Returns

Scene object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-scene.


Method setScene()

Update scene record.

Usage
Gltf$setScene(sc, scene)
Arguments
sc

Which scene to update.

scene

New scene record.


Method addScene()

Add a scene object.

Usage
Gltf$addScene()
Returns

Scene number.


Method addToScene()

Add node to scene.

Usage
Gltf$addToScene(scene, node)
Arguments
scene

Scene number to modify.

node

Node number(s) to add.


Method defaultScene()

Get default scene, creating it if necessary.

Usage
Gltf$defaultScene()
Returns

Scene number.


Method getNode()

Get node object.

Usage
Gltf$getNode(n)
Arguments
n

Node number.

Returns

Node object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-node.


Method setNode()

Set node object.

Usage
Gltf$setNode(n, node)
Arguments
n

Node number.

node

New node object.


Method addNode()

Add a node object.

Usage
Gltf$addNode(mesh = NULL, matrix = NULL, extras = NULL)
Arguments
mesh

A mesh number.

matrix

A matrix transformation for the node.

extras

A list of extras, typically rgl objects.

Returns

Node number.


Method addChild()

Add node as child of another.

Usage
Gltf$addChild(parent, node)
Arguments
parent

Node number to modify.

node

Node number(s) to add as children.


Method setParents()

Set parent member for all nodes

Usage
Gltf$setParents()

Method getSkin()

Get skin object.

Usage
Gltf$getSkin(skin)
Arguments
skin

Skin number.

Returns

Skin object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-skin.


Method setSkin()

Set skin object.

Usage
Gltf$setSkin(n, skin)
Arguments
n

Skin number.

skin

New skin object.


Method getJoint()

Get joint node.

Usage
Gltf$getJoint(skin, num)
Arguments
skin

Skin number.

num

Joint number.

Returns

Node object


Method getInverseBindMatrices()

Get "inverse bind matrices".

These matrices undo the existing transformation before applying the skin transformations.

Usage
Gltf$getInverseBindMatrices(skin)
Arguments
skin

Skin number.

Returns

A 4x4xn array of matrices, one per joint.


Method getForwardBindMatrices()

Get "forward bind matrices".

These matrices applying the skin transformations.

Usage
Gltf$getForwardBindMatrices(skin)
Arguments
skin

Skin number.

Returns

A 4x4xn array of matrices, one per joint.


Method getCamera()

Get camera object.

Usage
Gltf$getCamera(cam)
Arguments
cam

Camera number.

Returns

Camera object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-camera.


Method getExtras()

Get top-level extras list.

Usage
Gltf$getExtras()
Returns

Extras list, including rgl objects.


Method setExtras()

Set extras list.

Usage
Gltf$setExtras(extras)
Arguments
extras

New extras list.


Method getMesh()

Get mesh object.

Usage
Gltf$getMesh(m)
Arguments
m

Mesh number.

Returns

Mesh object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-mesh.


Method setMesh()

Set mesh object.

Usage
Gltf$setMesh(m, mesh)
Arguments
m

Mesh number.

mesh

New mesh object


Method addMesh()

Add a mesh object.

Usage
Gltf$addMesh(primitives)
Arguments
primitives

A list of primitive objects.

Returns

Mesh number.


Method getMaterial()

Get material object.

Usage
Gltf$getMaterial(m)
Arguments
m

Material number.

Returns

Material object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-material.


Method getTexture()

Get texture object.

Usage
Gltf$getTexture(tex)
Arguments
tex

Texture number.

Returns

Texture object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-texture.


Method getImage()

Get image object.

Usage
Gltf$getImage(im)
Arguments
im

Image number.

Returns

Image object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-image.


Method addMaterial()

Construct and possibly add material.

This will return an existing material if possible.

Usage
Gltf$addMaterial(mat, defaultMaterial = list())
Arguments
mat

An rgl material record.

defaultMaterial

Default material properties.

Returns

Material number.


Method addTexture()

Add a texture.

Usage
Gltf$addTexture(mat)
Arguments
mat

An rgl material record.

Returns

Texture number.


Method addImage()

Add an image for a texture.

Usage
Gltf$addImage(mat)
Arguments
mat

An rgl material record.

Returns

Image number.


Method addSampler()

Add a sampler.

Usage
Gltf$addSampler(mat)
Arguments
mat

An rgl material record.

Returns

Sampler number.


Method getMaterialNumber()

Add or return a material.

Usage
Gltf$getMaterialNumber(material)
Arguments
material

A glTF material record.

Returns

Material number.


Method writeVectors()

Write data.

Usage
Gltf$writeVectors(
  coords,
  target = targetArray,
  types = "anyGLTF",
  normalized = FALSE
)
Arguments
coords

Data to write, or NULL.

target

Optional target use for data.

types

A character vector of allowed types, or "any" or "anyGLTF"

normalized

Are these integer values representing floats?

Returns

Accessor number, or NULL.


Method makePrimitive()

Create a primitive record.

Usage
Gltf$makePrimitive(inds, mode = NULL, attributes = NULL, matnum = NULL)
Arguments
inds

Indices of vertices.

mode

Mode of primitive.

attributes

Primitive attributes.

matnum

Material number.

Returns

Primitive record, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-primitive.


Method getAsset()

Get asset list.

Usage
Gltf$getAsset()
Returns

Asset object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-asset.


Method setAsset()

Set asset list.

Usage
Gltf$setAsset(version, generator)
Arguments
version

Version number of glTF format.

generator

Identifier of code generating it.


Method getTransform()

Get local transform.

Usage
Gltf$getTransform(n)
Arguments
n

Node number.

Returns

4x4 matrix of local transform.


Method getRglMaterial()

Reconstruct rgl material.

Usage
Gltf$getRglMaterial(n)
Arguments
n

Material number.

Returns

rgl material record.


Method getAnimation()

Get animation.

Usage
Gltf$getAnimation(ani)
Arguments
ani

Animation number

Returns

Animation object, documented here: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-animation.


Method setAnimation()

Set animation.

Usage
Gltf$setAnimation(ani, animation)
Arguments
ani

Animation number

animation

New animation object


Method timerange()

Find time range of an animation

Usage
Gltf$timerange(ani)
Arguments
ani

Animation number

Returns

Min and max times from the samplers in the animation.


Method initAnimation()

Initialize animation.

This builds all of the interpolation functions in the samplers.

Usage
Gltf$initAnimation(ani)
Arguments
ani

Animation number

Returns

Modified animation object


Method settime()

Set time for an animation.

This evaluates all the interpolators and modifies self to reflect the specified time point.

Usage
Gltf$settime(time, ani = 0)
Arguments
time

Time to set.

ani

Animation number.

Returns

Vector of node numbers that were changed.


Method print()

Print gltf objects with various levels of detail.

Usage
Gltf$print(verbose = FALSE, names = FALSE, showExtras = TRUE, ...)
Arguments
verbose

Logical indicator of verbose printing, or character vector of components to print verbosely.

names

Print names for components.

showExtras

Logical: show extra fields?

...

Passed ... .

Examples
\donttest{
samples <- "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0"
gltf <- readGLB(paste0(samples, "/2CylinderEngine/glTF-Binary/2CylinderEngine.glb?raw=true"))
gltf$print(names = "meshes")
}

Method listCount()

Get number of items in private list.

Usage
Gltf$listCount(list)
Arguments
list

Name of list to get.


Method clone()

The objects of this class are cloneable with this method.

Usage
Gltf$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `Gltf$print`
## ------------------------------------------------


samples <- "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0"
gltf <- readGLB(paste0(samples, "/2CylinderEngine/glTF-Binary/2CylinderEngine.glb?raw=true"))
gltf$print(names = "meshes")


[Package rgl2gltf version 1.0.3 Index]