nanogl-gltf
Version:
190 lines (189 loc) • 6.41 kB
TypeScript
import ExtensionsRegistry from './extensions/Registry';
import type Accessor from './elements/Accessor';
import type BufferView from './elements/BufferView';
import type Buffer from './elements/Buffer';
import type Animation from './elements/Animation';
import type Node from './elements/Node';
import type { IMaterial } from './elements/Material';
import type Mesh from './elements/Mesh';
import type Skin from './elements/Skin';
import type Camera from './elements/Camera';
import NanoCamera from 'nanogl-camera';
import { GLContext } from 'nanogl/types';
import NanoglNode from 'nanogl-node';
import { ISemantics } from './Semantics';
import { IExtensionFactory } from './extensions/IExtension';
import GltfTypes from './types/GltfTypes';
import { AnyElement, ElementOfType } from './types/Elements';
import IRenderConfig from './IRenderConfig';
import Primitive from './elements/Primitive';
import Texture from './elements/Texture';
import DepthPass from 'nanogl-pbr/DepthPass';
import MeshRenderer from './renderer/MeshRenderer';
import { LightCollection } from './extensions/KHR_lights_punctual';
import { AbortSignal } from '@azure/abort-controller';
import type Scene from './elements/Scene';
/**
* Collection of elements of a given type
*/
export declare class ElementCollection<T extends AnyElement = AnyElement> {
/**
* Array of elements order by specified index
*/
indexed: T[];
/**
* Array of elements ordered by push order
*/
list: T[];
/**
* Add an element to the collection
* @param element Element to add
* @param index Index of the element, if -1 or not specified, will not be pushed to indexed array
*/
addElement(element: T, index?: number): void;
}
/**
* Extras property of a Gltf (custom additional data that can be added to every gltf property).
* Lights can be stored in the extras property of the Gltf with the KHR_lights_punctual extension.
*/
export declare type GltfExtras = {
[]: any;
} & {
lights?: LightCollection;
};
/**
* Gltf file representation
*/
export default class Gltf {
/**
* Static registry of activated extensions for all Gltf instances
*/
private static _extensionsRegistry;
/**
* Static GLSL semantics' resolver for all Gltf instances
*/
private static _semantics;
/**
* Static render config for all Gltf instances
*/
private static _renderConfig;
/**
* Add an extension to the static Gltf's extensions registry
* @param ext Extension to add
*/
static addExtension(ext: IExtensionFactory): void;
/**
* Get the static Gltf's semantics resolver
*/
static getSemantics(): ISemantics;
/**
* Set a custom static Gltf's semantics resolver
* @param semantics Custom semantics resolver
*/
static setSemantics(semantics: ISemantics): void;
/**
* Set the static Gltf's render config
*/
static getRenderConfig(): IRenderConfig;
/**
* Get the static Gltf's extensions registry
*/
static getExtensionsRegistry(): ExtensionsRegistry;
/**
* Array of all elements of this Gltf, unordered
*/
private _elements;
/**
* Map of all elements of this Gltf, ordered in typed collections
*/
private _collections;
/**
* Root node of this Gltf
*/
readonly root: NanoglNode;
/**
* GL context of this Gltf
*/
gl: GLContext;
/**
* Array of all renderables of this Gltf, created as MeshRenderer
*/
renderables: MeshRenderer[];
/**
* Array of all cameras of this Gltf, created as Camera from nanogl-camera
*/
cameraInstances: NanoCamera[];
/**
* Depth pass of this Gltf
*/
depthPass: DepthPass;
/**
* Extras property of this Gltf (custom additional data that can be added to every gltf property)
*/
extras: GltfExtras;
constructor();
/**
* Get the Gltf ready to be used in a WebGL context.
* Generally the first method called after loading the Gltf.
* This will allocate all the needed textures to the GPU, create the renderables, cameras, initialize buffers for primitives,
* and create Cameras from nanogl-camera.
* @param gl GL context
* @param abortSignal Abort signal if you want to be able to cancel the request at any time
*/
allocate(gl: GLContext, abortSignal?: AbortSignal): Promise<void>;
/**
* Filter all gltf Nodes to get only the ones that are cameras, and create a Camera from nanogl-camera for each of them,
* added as child of the Node, storing them in cameraInstances
*/
createCameras(): void;
get buffers(): Buffer[];
get bufferViews(): BufferView[];
get accessors(): Accessor[];
get animations(): Animation[];
get meshes(): Mesh[];
get nodes(): Node[];
get materials(): IMaterial[];
get cameras(): Camera[];
get skins(): Skin[];
get primitives(): Primitive[];
get textures(): Texture[];
get scenes(): Scene[];
/**
* Get all elements of this Gltf, unordered and unfiltered
*/
getAllElements(): AnyElement[];
/**
* Get element by his type and index
* @param type Element's type
* @param index Element's index
*/
getElement<T extends GltfTypes>(type: T, index: number): ElementOfType<T>;
/**
* Get element by his type and name
* @param type Element's type
* @param name Element's name
*/
getElementByName<T extends GltfTypes>(type: T, name: string): ElementOfType<T>;
/**
* Get all elements of a specific type with a specific name
* @param type Elements' type
* @param name Elements' name
*/
getElementsByName<T extends GltfTypes>(type: T, name: string): ElementOfType<T>[];
getNode(name: string): Node;
getMesh(name: string): Mesh;
getMaterial(name: string): IMaterial;
getAnimation(name: string): Animation;
getScene(name: string): Scene;
/**
* Get full collection of a specific type
* @param type Type of targeted collection
*/
private _getCollection;
/**
* Add an element to the Gltf
* @param element Element to add
* @param index Index of the element, if -1 or not specified, will not be pushed to indexed array (only the unordered one)
*/
addElement(element: AnyElement, index?: number): void;
}