The glTF2 Importer class for loading and processing glTF 2.0 files. Supports both .gltf (JSON) and .glb (binary) formats with comprehensive extension support and resource loading capabilities.

Methods

  • Internal

    Merges default options with glTF asset extras and user-provided options. Handles loader extension initialization based on the extension name.

    Parameters

    • defaultOptions: GltfLoadOption

      The base default options to merge into

    • json: RnM2

      The glTF JSON data that may contain loader options in asset.extras

    • options: GltfLoadOption

      User-provided options to override defaults

    Returns GltfLoadOption

    The merged and processed options object

  • Internal

    Imports and processes a binary glTF (.glb) file from ArrayBuffer. Validates the GLB format, extracts JSON and binary chunks, and processes the content.

    Parameters

    • arrayBuffer: ArrayBuffer

      The GLB file data as ArrayBuffer

    • files: GltfFileBuffers

      Additional resource files for resolving dependencies

    • options: GltfLoadOption

      Configuration options for the loading process

    Returns Promise<RnM2>

    A Promise that resolves to the processed glTF2 data in RnM2 format

    Will throw if the GLB format is invalid or unsupported

  • Internal

    Imports and processes a JSON glTF (.gltf) file with external resources. Handles resource loading from external files and applies processing options.

    Parameters

    • gltfJson: RnM2

      The parsed glTF JSON data

    • fileArrayBuffers: GltfFileBuffers

      Collection of external resource files

    • options: GltfLoadOption

      Configuration options for the loading process

    • Optionaluri: string

      Optional base URI for resolving relative resource paths

    • Optionalcallback: RnPromiseCallback

      Optional callback for progress tracking

    Returns Promise<RnM2>

    A Promise that resolves to the processed glTF2 data in RnM2 format

  • Internal

    Internal method to import glTF2 data from ArrayBuffer, handling both .gltf and .glb formats. Determines the file format by checking the magic number and processes accordingly.

    Parameters

    • arrayBuffer: ArrayBuffer

      The main glTF/GLB file as ArrayBuffer

    • otherFiles: GltfFileBuffers

      Additional resource files (textures, bins) as ArrayBuffers

    • Optionaloptions: GltfLoadOption

      Optional configuration for the loading process

    • Optionaluri: string

      Optional URI of the glTF file for resolving relative paths

    Returns Promise<Result<RnM2, undefined>>

    A Result containing the processed RnM2 data or an error

  • Internal

    Resolves dependencies for glTF accessors including buffer views and sparse data. Links accessors to their underlying buffer data for vertex attributes and indices.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing accessors

    Returns void

  • Internal

    Resolves dependencies for glTF animations including channels, samplers, and targets. Handles different interpolation modes and sets up animation data structures.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing animations

    Returns void

  • Internal

    Resolves dependencies for glTF buffer views by linking them to their buffers. Establishes the connection between buffer views and the actual buffer data.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing buffer views

    Returns void

  • Internal

    Resolves dependencies for glTF skins including skeleton, joints, and inverse bind matrices. Sets up the skeletal animation structure with proper object references.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing skins

    Returns void

  • Internal

    Resolves dependencies for glTF materials including all texture references. Handles PBR textures, normal maps, occlusion, emissive, and various extensions like clearcoat, transmission, sheen, specular, iridescence, anisotropy, and MToon.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing materials

    Returns void

  • Internal

    Resolves dependencies for glTF meshes including materials, attributes, indices, and morph targets. Handles material variants and creates direct object references for efficient access.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing meshes

    Returns void

  • Internal

    Resolves dependencies for glTF nodes including hierarchy, meshes, skins, cameras, and lights. Establishes parent-child relationships and links to associated objects.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing nodes

    Returns void

  • Internal

    Resolves dependencies for glTF scenes by linking node references. Creates nodesObjects array with direct references to node objects.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing scenes

    Returns void

  • Internal

    Resolves dependencies for glTF textures including samplers and image sources. Handles KHR_texture_basisu extension for Basis Universal texture compression.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data containing textures

    Returns void

  • Internal

    Orchestrates the loading of resources and JSON content processing. Creates promises for both resource loading and JSON dependency resolution.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data to process

    • files: GltfFileBuffers

      Collection of resource files

    • options: GltfLoadOption

      Loading configuration options

    • Optionaluint8arrayOfGlb: Uint8Array

      Optional binary data from GLB file

    • OptionalbasePath: string

      Optional base path for resolving relative URIs

    • Optionalcallback: RnPromiseCallback

      Optional progress callback

    Returns RnPromise<any[]>

    A Promise that resolves when all loading operations complete

  • Internal

    Processes the glTF JSON content by resolving all internal dependencies. Sets up object references between scenes, nodes, meshes, materials, textures, etc.

    Parameters

    • gltfJson: RnM2

      The glTF JSON data to process

    Returns void

  • Internal

    Loads all external resources referenced by the glTF file including buffers and images. Handles various URI formats including data URIs, file references, and embedded data. Supports multiple image formats including Basis Universal and KTX2 compression.

    Parameters

    • uint8ArrayOfGlb: Uint8Array

      Binary data from GLB file (if applicable)

    • gltfJson: RnM2

      The glTF JSON data containing resource references

    • files: GltfFileBuffers

      Collection of external files to load from

    • options: GltfLoadOption

      Loading configuration options

    • OptionalbasePath: string

      Base path for resolving relative URIs

    • Optionalcallback: RnPromiseCallback

      Optional progress callback

    Returns RnPromise<any[]>

    A Promise that resolves when all resources are loaded

  • Internal

    Merges extended JSON data into the main glTF JSON structure. Supports ArrayBuffer, string, or object formats for extended data.

    Parameters

    • gltfJson: RnM2

      The main glTF JSON to merge into

    • extendedData: string | object | ArrayBuffer

      Additional data to merge (ArrayBuffer, string, or object)

    Returns void

  • Imports glTF2 data from a collection of ArrayBuffer files. Automatically identifies the main glTF or GLB file from the provided files.

    Parameters

    • files: GltfFileBuffers

      A collection of file buffers where keys are filenames and values are ArrayBuffers

    • Optionaloptions: GltfLoadOption

      Optional configuration for the loading process

    Returns Promise<RnM2>

    A Promise that resolves to the processed glTF2 data in RnM2 format

    Will reject if no glTF or GLB file is found in the provided files

    const files = {
    'model.gltf': gltfBuffer,
    'texture.jpg': textureBuffer
    };
    const gltfData = await Gltf2Importer.importFromArrayBuffers(files);
  • Imports a glTF2 file from a URL and processes it into RnM2 format. Automatically detects whether the file is in .gltf or .glb format.

    Parameters

    • url: string

      The URL of the glTF file to import

    • Optionaloptions: GltfLoadOption

      Optional configuration for the loading process

    Returns Promise<RnM2>

    A Promise that resolves to the processed glTF2 data in RnM2 format

    Will reject if the file cannot be fetched or processed

    const gltfData = await Gltf2Importer.importFromUrl('path/to/model.gltf', {
    cameraComponent: CameraComponent,
    lightComponent: LightComponent
    });