Skip to content

Latest commit

 

History

History
2103 lines (1533 loc) · 90.5 KB

API.md

File metadata and controls

2103 lines (1533 loc) · 90.5 KB

Classes

GltfView

GltfView represents a view on a gltf, e.g. in a canvas

GltfState

GltfState containing a state for visualization in GltfView

AnimationTimer

AnimationTimer class to control animation playback.

ResourceLoader

ResourceLoader can be used to load resources for the GltfState that are then used to display the loaded data with GltfView

UserCamera
GraphController

A controller for managing KHR_interactivity graphs in a glTF scene.

PhysicsController

Controller for managing the physics simulation of a glTF scene.

ResourceLoaderUtils

Utility class providing static helper methods for resource loading operations, such as extracting file extensions, resolving folder paths, normalizing relative paths, and detecting absolute URLs.

GltfView

GltfView represents a view on a gltf, e.g. in a canvas

Kind: global class

new GltfView(context)

GltfView representing one WebGl 2.0 context or in other words one 3D rendering of the Gltf. You can create multiple views for example when multiple canvases should be shown on the same webpage.

Param Type Description
context * WebGl 2.0 context. Get it from a canvas with canvas.getContext("webgl2")

gltfView.createState() ⇒ GltfState

createState constructs a new GltfState for the GltfView. The resources referenced in a gltf state can directly be stored as resources on the WebGL context of GltfView, therefore GltfStates cannot not be shared between GltfViews.

Kind: instance method of GltfView
Returns: GltfState - GltfState

gltfView.createResourceLoader([externalDracoLib], [externalKtxLib], [libPath]) ⇒ ResourceLoader

createResourceLoader creates a resource loader with which glTFs and environments can be loaded for the view

Kind: instance method of GltfView
Returns: ResourceLoader - ResourceLoader

Param Type Description
[externalDracoLib] Object optional object of an external Draco library, e.g. from a CDN
[externalKtxLib] Object optional object of an external KTX library, e.g. from a CDN
[libPath] string optional path to the libraries. Used to define the path to the WASM files on repackaging

gltfView.renderFrame(state, width, height)

renderFrame to the context's default frame buffer Call this function in the javascript animation update loop for continuous rendering to a canvas

Kind: instance method of GltfView

Param Type Description
state * GltfState that is be used for rendering
width * of the viewport
height * of the viewport

gltfView.gatherStatistics(state) ⇒ Object

gatherStatistics collects information about the GltfState such as the number of rendered meshes or triangles

Kind: instance method of GltfView
Returns: Object - an object containing statistics information

Param Type Description
state * GltfState about which the statistics should be collected

GltfState

GltfState containing a state for visualization in GltfView

Kind: global class

new GltfState(view)

GltfState represents all state that can be visualized in a view. You could have multiple GltfStates configured and switch between them on demand.

Param Type Description
view * GltfView to which this state belongs

gltfState.gltf

loaded gltf data @see ResourceLoader.loadGltf

Kind: instance property of GltfState

gltfState.environment

loaded environment data @see ResourceLoader.loadEnvironment

Kind: instance property of GltfState

gltfState.userCamera

user camera @see UserCamera, convenient camera controls

Kind: instance property of GltfState

gltfState.sceneIndex

gltf scene that is visible in the view

Kind: instance property of GltfState

gltfState.cameraNodeIndex

index of the camera node that is used to render the view. a value of 'undefined' enables the user camera

Kind: instance property of GltfState

gltfState.animationIndices

indices of active animations

Kind: instance property of GltfState

gltfState.animationTimer

animation timer allows to control the animation time

Kind: instance property of GltfState

gltfState.variant

KHR_materials_variants

Kind: instance property of GltfState

gltfState.graphController

the graph controller allows selecting and playing graphs from KHR_interactivity

Kind: instance property of GltfState

gltfState.selectionCallback

callback for selection: (selectionInfo : { node, position, rayOrigin, controller }) => {}

Kind: instance property of GltfState

gltfState.hoverCallback

callback for hovering: (hoverInfo : { node, controller }) => {}

Kind: instance property of GltfState

gltfState.triggerSelection

If the renderer should compute selection information in the next frame. Is automatically reset after the frame is rendered

Kind: instance property of GltfState

gltfState.enableHover

If the renderer should compute hover information in the next frame.

Kind: instance property of GltfState

gltfState.needsRedraw

Indicates whether the view needs to be redrawn, currently used to indicate new sorting orders for gaussian splatting

Kind: instance property of GltfState

gltfState.renderingParameters

parameters used to configure the rendering

Kind: instance property of GltfState

renderingParameters.morphing

morphing between vertices

Kind: static property of renderingParameters

renderingParameters.skinning

skin / skeleton

Kind: static property of renderingParameters

renderingParameters.wireframe

overlay the triangle edges of all meshes as black lines (wireframe), requires WEBGL_polygon_mode

Kind: static property of renderingParameters

renderingParameters.lightGizmos

draw debug gizmos for the scene's lights

Kind: static property of renderingParameters

renderingParameters.cameraGizmos

draw debug gizmos for the scene's cameras

Kind: static property of renderingParameters

renderingParameters.jointGizmos

draw debug gizmos for skeletal joints

Kind: static property of renderingParameters

renderingParameters.aabbGizmos

draw debug gizmos for mesh bounds

Kind: static property of renderingParameters

renderingParameters.enabledExtensions

enabled extensions

Kind: static property of renderingParameters

enabledExtensions.KHR_materials_clearcoat

KHR_materials_clearcoat adds a clear coat layer on top of the glTF base material

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_sheen

KHR_materials_sheen adds a sheen layer on top of the glTF base material

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_transmission

KHR_materials_transmission adds physical-based transparency

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_volume

KHR_materials_volume adds support for volumetric materials. Used together with KHR_materials_transmission and KHR_materials_diffuse_transmission

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_scatter

KHR_materials_scatter defines scattering properties for both thin-walled and volumetric materials. Used together with KHR_materials_transmission and optionally KHR_materials_volume

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_ior

KHR_materials_ior makes the index of refraction configurable

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_specular

KHR_materials_specular allows configuring specular color (f0 color) and amount of specular reflection

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_iridescence

KHR_materials_iridescence adds a thin-film iridescence effect

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_diffuse_transmission

KHR_materials_diffuse_transmission allows light to pass diffusely through the material

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_anisotropy

KHR_materials_anisotropy defines microfacet grooves in the surface, stretching the specular reflection on the surface

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_dispersion

KHR_materials_dispersion defines configuring the strength of the angular separation of colors (chromatic abberation)

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_emissive_strength

KHR_materials_emissive_strength enables emissive factors larger than 1.0

Kind: static property of enabledExtensions

enabledExtensions.KHR_materials_retroreflection

KHR_materials_retroreflection adds a retroreflective response to the metallic and dielectric BRDFs

Kind: static property of enabledExtensions

enabledExtensions.KHR_interactivity

KHR_interactivity enables execution of a behavior graph

Kind: static property of enabledExtensions

enabledExtensions.KHR_node_hoverability

KHR_node_hoverability enables hovering over nodes

Kind: static property of enabledExtensions

enabledExtensions.KHR_node_selectability

KHR_node_selectability enables selecting nodes

Kind: static property of enabledExtensions

enabledExtensions.KHR_node_visibility

KHR_node_visibility enables controlling the visibility of nodes

Kind: static property of enabledExtensions

enabledExtensions.KHR_gaussian_splatting

KHR_gaussian_splatting

Kind: static property of enabledExtensions

renderingParameters.clearColor

clear color expressed as list of floats in the range [0, 1]

Kind: static property of renderingParameters

renderingParameters.exposure

exposure factor

Kind: static property of renderingParameters

renderingParameters.usePunctual

KHR_lights_punctual

Kind: static property of renderingParameters

renderingParameters.useIBL

image based lighting

Kind: static property of renderingParameters

renderingParameters.iblIntensity

image based lighting intensity

Kind: static property of renderingParameters

renderingParameters.renderEnvironmentMap

render the environment map in the background

Kind: static property of renderingParameters

renderingParameters.blurEnvironmentMap

apply blur to the background environment map

Kind: static property of renderingParameters

renderingParameters.useUniformEnvironment

illuminate with a uniform color instead of the environment map

Kind: static property of renderingParameters

renderingParameters.uniformEnvironmentColor

the uniform color used when useUniformEnvironment is set

Kind: static property of renderingParameters

renderingParameters.toneMap

which tonemap to use, use KHR_PBR_NEUTRAL for best color reproduction

Kind: static property of renderingParameters

renderingParameters.debugOutput

render some debug output channes, such as for example the normals

Kind: static property of renderingParameters

renderingParameters.environmentRotation

By default the front face of the environment is +Z (90) Front faces: +X = 0 +Z = 90 -X = 180 -Z = 270

Kind: static property of renderingParameters

renderingParameters.useDirectionalLightsWithDisabledIBL

If this is set to true, directional lights will be generated if IBL is disabled

Kind: static property of renderingParameters

renderingParameters.internalMSAA

MSAA used for cases which are not handled by the browser (e.g. Transmission)

Kind: static property of renderingParameters

renderingParameters.floatingPointFramebuffer

Use RGBA16F floating-point main framebuffer instead of RGBA8

Kind: static property of renderingParameters

renderingParameters.cullByBoundingVolume

skip nodes whose glTF 2.1 bounding volume is outside the view

Kind: static property of renderingParameters

renderingParameters.debugShapes

debug visualization of glTF 2.1 shapes and bounding volumes

Kind: static property of renderingParameters

debugShapes.boundingVolumes

draw node bounding volumes, see BoundingVolumeMode

Kind: static property of debugShapes

debugShapes.allShapes

draw every entry of the shapes array at the nodes referencing it

Kind: static property of debugShapes

debugShapes.style

how shapes are drawn, see DebugShapeStyle

Kind: static property of debugShapes

debugShapes.colorMode

how shapes are coloured, see DebugShapeColor

Kind: static property of debugShapes

debugShapes.depthTest

when false, shapes are drawn through geometry (x-ray)

Kind: static property of debugShapes

debugShapes.highlightNonEnclosing

flag bounding volumes that fail to enclose their node's geometry

Kind: static property of debugShapes

renderingParameters.clipping

cuboid of six clipping planes that cuts the model open for inspection. Requires WEBGL_clip_cull_distance, which is not available on all browsers/platforms; setting enabled to true has no effect where it is unsupported.

Kind: static property of renderingParameters

clipping.enabled

discard everything outside the cuboid. Requires WEBGL_clip_cull_distance

Kind: static property of clipping

clipping.orientation

space the cuboid is aligned to @see GltfState.ClippingOrientations

Kind: static property of clipping

clipping.min

per axis lower bound of the kept region, as a fraction of the scene extents in [0, 1]

Kind: static property of clipping

clipping.max

per axis upper bound of the kept region, as a fraction of the scene extents in [0, 1]

Kind: static property of clipping

GltfState.ToneMaps

ToneMaps enum for the different tonemappings that are supported by gltf sample viewer

Kind: static property of GltfState

ToneMaps.KHR_PBR_NEUTRAL

Khronos PBR neutral tone mapping, see https://github.com/KhronosGroup/ToneMapping, https://modelviewer.dev/examples/tone-mapping

Kind: static property of ToneMaps

ToneMaps.ACES_HILL_EXPOSURE_BOOST

ACES sRGB RRT+ODT implementation for 3D Commerce based on Stephen Hill's implementation with a exposure factor of 1.0 / 0.6

Kind: static property of ToneMaps

ToneMaps.ACES_NARKOWICZ

fast implementation of the ACES sRGB RRT+ODT based on Krzysztof Narkowicz' implementation

Kind: static property of ToneMaps

ToneMaps.ACES_HILL

more accurate implementation of the ACES sRGB RRT+ODT based on Stephen Hill's implementation

Kind: static property of ToneMaps

ToneMaps.NONE

Linear mapping, clamped at 1.0 per channel

Kind: static property of ToneMaps

GltfState.BoundingVolumeMode

Which node bounding volumes the shape debug pass draws

Kind: static property of GltfState

BoundingVolumeMode.NONE

bounding volumes are not drawn

Kind: static property of BoundingVolumeMode

BoundingVolumeMode.ALL

draw the bounding volume of every node in the scene

Kind: static property of BoundingVolumeMode

GltfState.DebugShapeStyle

How the shape debug pass draws a shape

Kind: static property of GltfState

DebugShapeStyle.WIREFRAME

edges only

Kind: static property of DebugShapeStyle

DebugShapeStyle.SOLID

translucent solid surfaces

Kind: static property of DebugShapeStyle

DebugShapeStyle.BOTH

translucent solid surfaces with their edges on top

Kind: static property of DebugShapeStyle

GltfState.DebugShapeColor

How the shape debug pass colours a shape

Kind: static property of GltfState

DebugShapeColor.UNIFORM

one colour for everything

Kind: static property of DebugShapeColor

DebugShapeColor.DEPTH

by depth in the node hierarchy, which makes a bounding volume hierarchy legible

Kind: static property of DebugShapeColor

DebugShapeColor.TYPE

by shape type

Kind: static property of DebugShapeColor

GltfState.ClippingOrientations

ClippingOrientations enum for the space the clipping cuboid is aligned to

Kind: static property of GltfState

ClippingOrientations.AXIS_ALIGNED

the cuboid is aligned to the world axes

Kind: static property of ClippingOrientations

ClippingOrientations.VIEW_ALIGNED

the cuboid is aligned to the camera, so it cuts towards the viewer

Kind: static property of ClippingOrientations

GltfState.DebugOutput

DebugOutput enum for selecting debug output channels such as "NORMAL"

Kind: static property of GltfState

DebugOutput.NONE

standard rendering - debug output is disabled

Kind: static property of DebugOutput

DebugOutput.generic

generic debug outputs

Kind: static property of DebugOutput

generic.NORMAL

output the normal texture value

Kind: static property of generic

generic.ALPHA

output the alpha value

Kind: static property of generic

generic.OCCLUSION

output the occlusion value

Kind: static property of generic

generic.EMISSIVE

output the emissive value

Kind: static property of generic

DebugOutput.shading

the geometric and shading normal/tangent frame

Kind: static property of DebugOutput

shading.GEOMETRYNORMAL

output the normal from the TBN

Kind: static property of shading

shading.TANGENT

output the tangent from the TBN

Kind: static property of shading

shading.BITANGENT

output the bitangent from the TBN

Kind: static property of shading

shading.TANGENTW

output the tangent w from the TBN (black corresponds to -1; white to 1

Kind: static property of shading

shading.WORLDSPACENORMAL

output the world space normals (i.e. with TBN applied)

Kind: static property of shading

DebugOutput.mr

metallic roughness

Kind: static property of DebugOutput

mr.BASECOLOR

output the base color value

Kind: static property of mr

mr.METALLIC

output the metallic value from pbr metallic roughness

Kind: static property of mr

mr.ROUGHNESS

output the roughness value from pbr metallic roughness

Kind: static property of mr

DebugOutput.clearcoat

KHR_materials_clearcoat

Kind: static property of DebugOutput

clearcoat.CLEARCOAT_FACTOR

output the clearcoat strength

Kind: static property of clearcoat

clearcoat.CLEARCOAT_ROUGHNESS

output the clearcoat roughness

Kind: static property of clearcoat

clearcoat.CLEARCOAT_NORMAL

output the clearcoat normal

Kind: static property of clearcoat

DebugOutput.sheen

KHR_materials_sheen

Kind: static property of DebugOutput

sheen.SHEEN_COLOR

output the sheen color

Kind: static property of sheen

sheen.SHEEN_ROUGHNESS

output the sheen roughness

Kind: static property of sheen

DebugOutput.specular

KHR_materials_specular

Kind: static property of DebugOutput

specular.SPECULAR_FACTOR

output the specular strength

Kind: static property of specular

specular.SPECULAR_COLOR

output the specular color

Kind: static property of specular

DebugOutput.transmission

KHR_materials_transmission

Kind: static property of DebugOutput

transmission.TRANSMISSION_FACTOR

output the transmission strength

Kind: static property of transmission

DebugOutput.volume

KHR_materials_volume

Kind: static property of DebugOutput

volume.VOLUME_THICKNESS

output the volume thickness

Kind: static property of volume

volume.VOLUME_ATTENUATION_DISTANCE

output the attenuation distance

Kind: static property of volume

volume.VOLUME_ATTENUATION_COLOR

output the attenuation color

Kind: static property of volume

DebugOutput.ior

KHR_materials_ior

Kind: static property of DebugOutput

ior.IOR

output the index of refraction

Kind: static property of ior

DebugOutput.dispersion

KHR_materials_dispersion

Kind: static property of DebugOutput

dispersion.DISPERSION

output the dispersion strength

Kind: static property of dispersion

DebugOutput.diffuseTransmission

KHR_materials_diffuse_tranmission

Kind: static property of DebugOutput

diffuseTransmission.DIFFUSE_TRANSMISSION_FACTOR

output the diffuse tranmission strength

Kind: static property of diffuseTransmission

diffuseTransmission.DIFFUSE_TRANSMISSION_COLOR_FACTOR

output the diffuse tranmission color factor

Kind: static property of diffuseTransmission

DebugOutput.iridescence

KHR_materials_iridescence

Kind: static property of DebugOutput

iridescence.IRIDESCENCE_FACTOR

output the iridescence strength

Kind: static property of iridescence

iridescence.IRIDESCENCE_THICKNESS

output the iridescence thickness

Kind: static property of iridescence

iridescence.IRIDESCENCE_IOR

output the iridescence index of refraction

Kind: static property of iridescence

DebugOutput.retroreflection

KHR_materials_retroreflection

Kind: static property of DebugOutput

retroreflection.RETROREFLECTION_FACTOR

output the retroreflection strength

Kind: static property of retroreflection

DebugOutput.anisotropy

KHR_materials_anisotropy

Kind: static property of DebugOutput

anisotropy.ANISOTROPIC_STRENGTH

output the anisotropy strength

Kind: static property of anisotropy

anisotropy.ANISOTROPIC_DIRECTION

output the final direction as defined by the anisotropyTexture and rotation

Kind: static property of anisotropy

DebugOutput.emissiveStrength

KHR_materials_emissive_strength

Kind: static property of DebugOutput

emissiveStrength.EMISSIVE_STRENGTH

output the emissive strength

Kind: static property of emissiveStrength

DebugOutput.misc

miscellaneous debug outputs

Kind: static property of DebugOutput

misc.PICKING_COLOR

color each node with its picking color (used by the picking pass)

Kind: static property of misc

AnimationTimer

AnimationTimer class to control animation playback.

Kind: global class

animationTimer.start()

Start the animation timer and all animations

Kind: instance method of AnimationTimer

animationTimer.pause()

Pause all animations

Kind: instance method of AnimationTimer

animationTimer.unpause()

Unpause all animations

Kind: instance method of AnimationTimer

animationTimer.toggle()

Toggle the animation playback state

Kind: instance method of AnimationTimer

animationTimer.reset()

Reset the animation timer. If animations were playing, they will be restarted.

Kind: instance method of AnimationTimer

animationTimer.setFixedTime(timeInSec)

Plays all animations starting from the specified time

Kind: instance method of AnimationTimer

Param Type Description
timeInSec number The time in seconds to set the animation timer to

animationTimer.setTimeOverride(timeInSec)

Sets the animation time override. While set, elapsedSec() returns this value instead of the running clock, which keeps advancing underneath.

Kind: instance method of AnimationTimer

Param Type Description
timeInSec number The time in seconds to override the animation to

animationTimer.clearTimeOverride()

Clears the time override so the running clock is used again.

Kind: instance method of AnimationTimer

animationTimer.elapsedSec()

Get the elapsed time in seconds

Kind: instance method of AnimationTimer

ResourceLoader

ResourceLoader can be used to load resources for the GltfState that are then used to display the loaded data with GltfView

Kind: global class

new ResourceLoader(view, libPath)

ResourceLoader class that provides an interface to load resources into the view. Typically this is created with GltfView.createResourceLoader() You cannot share resource loaders between GltfViews as some of the resources are allocated directly on the WebGl2 Context

Param Type Default Description
view Object the GltfView for which the resources are loaded
libPath String ./libs/ path to the lib folder. This can be used to find the WASM files if sample viewer is repackaged

resourceLoader.loadGltf(gltfFile, [externalFiles], allowResourceAbsolutePath) ⇒ Promise

loadGltf asynchroneously and create resources for rendering

Kind: instance method of ResourceLoader
Returns: Promise - a promise that fulfills when the gltf file was loaded

Param Type Default Description
gltfFile String | ArrayBuffer | File the .gltf or .glb file either as path or as preloaded resource. In node.js environments, only ArrayBuffer types are accepted.
[externalFiles] Array.<File> additional files containing resources that are referenced in the gltf
allowResourceAbsolutePath Boolean true whether to allow absolute paths for images/buffers.

resourceLoader.buildDocument()

Parses one glTF document, loads its resources, then recurses into the assets it references. Buffers have to land before the recursion, because a referenced asset may live in a bufferView of this one.

Kind: instance method of ResourceLoader

resourceLoader.loadThumbnail(gltfFile, [externalFiles]) ⇒ Promise.<(Object|undefined)>

loadThumbnail reads only the asset.thumbnail image of a glTF 2.1 asset, without building a glTF document or touching WebGL. Use it to preview an asset cheaply.

Kind: instance method of ResourceLoader
Returns: Promise.<(Object|undefined)> - { url, mimeType }, or undefined when the asset declares no thumbnail. The caller owns url and must revoke it.

Param Type Description
gltfFile String | ArrayBuffer | File | Array the .gltf or .glb file
[externalFiles] Array.<File> files accompanying a dropped asset

resourceLoader.loadEnvironment(environmentFile, [lutFiles]) ⇒ Promise

loadEnvironment asynchroneously, run IBL sampling and create resources for rendering

Kind: instance method of ResourceLoader
Returns: Promise - a promise that fulfills when the environment file was loaded

Param Type Description
environmentFile String | ArrayBuffer | File the .hdr file either as path or resource
[lutFiles] Object object containing paths or resources for the environment look up textures. Keys are lut_sheen_E_file

resourceLoader.initKtxLib([externalKtxLib])

initKtxLib must be called before loading gltf files with ktx2 assets

Kind: instance method of ResourceLoader

Param Type Description
[externalKtxLib] Object external ktx library (for example from a CDN)

resourceLoader.initDracoLib([externalDracoLib]) ⇒ Promise

initDracoLib must be called before loading gltf files with draco meshes

Kind: instance method of ResourceLoader
Returns: Promise - a promise that fulfills once the draco decoder is usable

Param Type Description
[externalDracoLib] * external draco library (for example from a CDN)

UserCamera

Kind: global class

new UserCamera()

Create a new user camera.

userCamera.setVerticalFoV(yfov)

Sets the vertical FoV of the user camera.

Kind: instance method of UserCamera

Param Type
yfov number

userCamera.getPosition()

Returns the current position of the user camera as a vec3.

Kind: instance method of UserCamera

userCamera.getRotation()

Returns the current rotation of the user camera as quat.

Kind: instance method of UserCamera

userCamera.getLookDirection()

Returns the normalized direction the user camera looks at as vec3.

Kind: instance method of UserCamera

userCamera.getTarget()

Returns the current target the camera looks at as vec3. This multiplies the viewing direction with the distance. For distance 0 the normalized viewing direction is used.

Kind: instance method of UserCamera

userCamera.lookAt(from, to)

Look from user camera to target. This changes the transformation of the user camera.

Kind: instance method of UserCamera

Param Type
from vec3
to vec3

userCamera.setPosition(position)

Sets the position of the user camera.

Kind: instance method of UserCamera

Param Type
position vec3

userCamera.setTarget(target)

This rotates the user camera towards the target and sets the position of the user camera according to the current distance.

Kind: instance method of UserCamera

Param Type
target vec3

userCamera.setRotation(yaw, pitch)

Sets the rotation of the camera. Yaw and pitch in euler angles (degrees).

Kind: instance method of UserCamera

Param Type
yaw number
pitch number

userCamera.setDistanceFromTarget(distance, target)

Transforms the user camera to look at a target from a specfic distance using the current rotation. This will only change the position of the user camera, not the rotation. Use this function to set the distance.

Kind: instance method of UserCamera

Param Type
distance number
target vec3

userCamera.zoomBy(value)

Zoom exponentially according to this.zoomFactor and this.zoomExponent. The default zoomFactor provides good zoom speed for values from [-1,1].

Kind: instance method of UserCamera

Param Type
value number

userCamera.orbit(x, y)

Orbit around the target. x and y should be in radient and are added to the current rotation. The rotation around the x-axis is limited to 180 degree. The axes are inverted: e.g. if y is positive the camera will look further down.

Kind: instance method of UserCamera

Param Type
x number
y number

userCamera.pan(x, y)

Pan the user camera. The axes are inverted: e.g. if y is positive the camera will move down.

Kind: instance method of UserCamera

Param Type
x number
y number

userCamera.resetView(gltf, sceneIndex)

Calculates a camera position which looks at the center of the scene from an appropriate distance. This calculates near and far plane as well.

Kind: instance method of UserCamera

Param Type
gltf Gltf
sceneIndex number

userCamera.fitViewToScene(gltf, sceneIndex)

Fit view to updated canvas size without changing rotation if distance is incorrect

Kind: instance method of UserCamera

Param Type
gltf Gltf
sceneIndex number

GraphController

A controller for managing KHR_interactivity graphs in a glTF scene.

Kind: global class

graphController.initializeGraphs(state)

Initialize the graph controller with the given state. This needs to be called every time a glTF assets is loaded.

Kind: instance method of GraphController

Param Type Description
state GltfState The state of the application.

graphController.loadGraph(graphIndex) ⇒ Array

Loads the specified graph. Resets the engine. Starts playing if this.playing is true.

Kind: instance method of GraphController
Returns: Array - An array of custom events defined in the graph.

Param Type
graphIndex number

graphController.stopGraphEngine()

Stops the graph engine.

Kind: instance method of GraphController

graphController.pauseGraph()

Pauses the currently playing graph.

Kind: instance method of GraphController

graphController.resumeGraph()

Resumes the currently paused graph.

Kind: instance method of GraphController

graphController.resetGraph()

Resets the current graph.

Kind: instance method of GraphController

graphController.dispatchEvent(eventName, data)

Dispatches an event to the behavior engine.

Kind: instance method of GraphController

Param Type
eventName string
data *

graphController.addCustomEventListener(eventName, callback)

Adds a custom event listener to the decorator. Khronos test assets use test/onStart, test/onFail and test/onSuccess.

Kind: instance method of GraphController

Param Type
eventName string
callback function

graphController.clearCustomEventListeners()

Clears all custom event listeners from the decorator.

Kind: instance method of GraphController

PhysicsController

Controller for managing the physics simulation of a glTF scene.

Kind: global class

physicsController.initializeEngine(engine)

Initializes the physics engine. This must be called before loading any scenes. Currently, only "NvidiaPhysX" is supported.

Kind: instance method of PhysicsController

Param Type
engine string

physicsController.getEngineVersion() ⇒ string | undefined

Returns the version string of the initialized physics engine, or undefined if the engine has not been initialized yet.

Kind: instance method of PhysicsController

physicsController.loadScene(state, sceneIndex)

Resets the current physics state and loads the physics data for a given scene and initializes the physics simulation. The first two frames of the simulation are skipped to allow the physics engine to initialize before applying any physics updates. Resets all dirty flags.

Kind: instance method of PhysicsController

Param Type
state GltfState
sceneIndex number

physicsController.resetScene(gltf)

Resets the current physics state.

Kind: instance method of PhysicsController

Param Type
gltf glTF

physicsController.setPhysicsEnabled(state, enabled)

Enables or disables physics as a whole.

Disabling pauses the simulation, tears it down and snaps any simulated nodes back to their authored transforms. Enabling rebuilds the simulation for the current scene.

Kind: instance method of PhysicsController

Param Type
state GltfState
enabled boolean

physicsController.resumeSimulation()

Resumes the physics simulation if it was paused. If the simulation is not paused, this function does nothing.

Kind: instance method of PhysicsController

physicsController.pauseSimulation()

Pauses the physics simulation. If the simulation is already paused, this function does nothing.

Kind: instance method of PhysicsController

physicsController.simulateStep(state, deltaTime)

Simulates a single step of the physics simulation, if the initial loading is done. A step will only be simulated if enough time has passed since the last simulated step, based on the configured simulation step time. Can also be used to manually advance the simulation when it is paused.

Kind: instance method of PhysicsController

Param Type
state GltfState
deltaTime number

physicsController.enableDebugColliders(enable)

Enable debug visualization of physics colliders. The exact visualization depends on the physics engine implementation.

Kind: instance method of PhysicsController

Param Type
enable boolean

physicsController.enableDebugJoints(enable)

Enable debug visualization of physics joints. The exact visualization depends on the physics engine implementation.

Kind: instance method of PhysicsController

Param Type
enable boolean

physicsController.applyImpulse(nodeIndex, linearImpulse, angularImpulse)

Applies a linear and/or angular impulse to the actor associated with the given node. An impulse causes an instantaneous change in the actor's velocity proportional to its mass.

Kind: instance method of PhysicsController

Param Type Description
nodeIndex number glTF node index of the target dynamic actor.
linearImpulse vec3 Impulse vector applied to the center of mass, in world space (kg⋅m/s).
angularImpulse vec3 Angular impulse vector applied around the center of mass, in world space (kg⋅m²/s).

physicsController.applyPointImpulse(nodeIndex, impulse, position)

Applies a linear impulse to the actor associated with the given node at a specific world-space position. Applying the impulse off-center will also induce a torque on the actor.

Kind: instance method of PhysicsController

Param Type Description
nodeIndex number glTF node index of the target dynamic actor.
impulse vec3 Impulse vector to apply, in world space (kg⋅m/s).
position vec3 World-space position at which the impulse is applied.

physicsController.rayCast(rayStart, rayEnd) ⇒ Object

Performs a ray-cast between two world-space points and returns information about the first shape hit.

Kind: instance method of PhysicsController
Returns: Object - An object containing the index of the hit node (-1 on miss), the normalised hit fraction along the ray, and the surface normal at the hit point.

Param Type Description
rayStart Array.<number> World-space ray origin as [x, y, z].
rayEnd Array.<number> World-space ray terminus as [x, y, z].

ResourceLoaderUtils

Utility class providing static helper methods for resource loading operations, such as extracting file extensions, resolving folder paths, normalizing relative paths, and detecting absolute URLs.

Kind: global class

ResourceLoaderUtils.getExtension(filename) ⇒ string | undefined

Extracts the file extension from a filename.

Kind: static method of ResourceLoaderUtils
Returns: string | undefined - The lowercase file extension (without the leading dot), or undefined if the filename has no extension.

Param Type Description
filename string The filename or path to extract the extension from.

ResourceLoaderUtils.getContainingFolder(filePath) ⇒ string

Returns the directory portion of a file path, including the trailing slash.

Kind: static method of ResourceLoaderUtils
Returns: string - The path up to and including the last /, or an empty string if no / is present.

Param Type Description
filePath string The full file path.

ResourceLoaderUtils.cleanRelativePath(relativePath) ⇒ string

Normalizes a relative URL path by resolving . and .. segments.

  • Strips a leading ./ prefix.
  • Collapses /./ sequences to /.
  • Resolves /../ sequences by removing the preceding path segment.

Kind: static method of ResourceLoaderUtils
Returns: string - The normalized path with dot segments resolved.

Param Type Description
relativePath string The relative path to clean.

ResourceLoaderUtils.isAbsoluteUrl(url) ⇒ boolean

Determines whether a URL is absolute (i.e. contains a scheme such as http: or data:). A URL is considered absolute when it contains a : that appears before any /.

Kind: static method of ResourceLoaderUtils
Returns: boolean - true if the URL is absolute, false otherwise.

Param Type Description
url string The URL string to test.