The glTF file spec is described here: https://www.khronos.org/registry/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

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.


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.


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.


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.


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.


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.


Method getTexture()

Get texture object.

Usage

Gltf$getTexture(tex)

Arguments

tex

Texture number.


Method getImage()

Get image object.

Usage

Gltf$getImage(im)

Arguments

im

Image number.


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.


Method getAsset()

Get asset list.

Usage

Gltf$getAsset()


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


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

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")
#> asset fields:
#>   GLtf version 2.0 file.
#>   Generated by COLLADA2GLTF.
#> Scenes ( 1 )
#> Nodes ( 82 )
#> Buffers ( 1 )
#> Bufferviews ( 2 )
#> Meshes ( 29 )
#>   0: Piston_123-844_0_Parts_1
#>   1: body_24
#>   2: body_23
#>   3: body_22
#>   4: body_21
#>   5: body_20
#>   6: Spring_Link__0_Parts_1
#>   7: body_19
#>   8: body_18
#>   9: body_17
#>   10: body_16
#>   11: body_15
#>   12: body_14
#>   13: body_13
#>   14: body_12
#>   15: body_11
#>   16: body_10
#>   17: body_9
#>   18: body_8
#>   19: body_7
#>   20: body_6
#>   21: body_5
#>   22: body_4
#>   23: body
#>   24: body_3
#>   25: body_2
#>   26: body_1
#>   27: rod_123-699_0_Parts_1
#>   28: Lifter_123-923_0_Parts_1
#> Cameras ( 1 )
#> Accessors ( 102 )
#> Materials ( 34 )