babylonjs-loaders
Version:
Babylon.js Loaders module =====================
1,245 lines (1,233 loc) • 354 kB
TypeScript
declare module "babylonjs-loaders/index" {
export * from "babylonjs-loaders/glTF/index";
export * from "babylonjs-loaders/OBJ/index";
export * from "babylonjs-loaders/STL/index";
export * from "babylonjs-loaders/SPLAT/index";
}
declare module "babylonjs-loaders/dynamic" {
/**
* Registers the async plugin factories for all built-in loaders.
* Loaders will be dynamically imported on demand, only when a SceneLoader load operation needs each respective loader.
*/
export function registerBuiltInLoaders(): void;
}
declare module "babylonjs-loaders/glTF/index" {
export * from "babylonjs-loaders/glTF/glTFFileLoader";
export * from "babylonjs-loaders/glTF/glTFValidation";
import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
export { GLTF1, GLTF2 };
}
declare module "babylonjs-loaders/glTF/glTFValidation" {
import * as GLTF2 from "babylonjs-gltf2interface";
/**
* Configuration for glTF validation
*/
export interface IGLTFValidationConfiguration {
/**
* The url of the glTF validator.
*/
url: string;
}
/**
* glTF validation
*/
export class GLTFValidation {
/**
* The configuration. Defaults to `{ url: "https://cdn.babylonjs.com/gltf_validator.js" }`.
*/
static Configuration: IGLTFValidationConfiguration;
private static _LoadScriptPromise;
/**
* Validate a glTF asset using the glTF-Validator.
* @param data The JSON of a glTF or the array buffer of a binary glTF
* @param rootUrl The root url for the glTF
* @param fileName The file name for the glTF
* @param getExternalResource The callback to get external resources for the glTF validator
* @returns A promise that resolves with the glTF validation results once complete
*/
static ValidateAsync(data: string | Uint8Array, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<Uint8Array>): Promise<GLTF2.IGLTFValidationResults>;
}
}
declare module "babylonjs-loaders/glTF/glTFFileLoader.metadata" {
export const GLTFMagicBase64Encoded = "Z2xURg";
export const GLTFFileLoaderMetadata: {
readonly name: "gltf";
readonly extensions: {
readonly ".gltf": {
readonly isBinary: false;
};
readonly ".glb": {
readonly isBinary: true;
};
};
readonly canDirectLoad: (data: string) => boolean;
};
}
declare module "babylonjs-loaders/glTF/glTFFileLoader" {
import * as GLTF2 from "babylonjs-gltf2interface";
import { Nullable } from "babylonjs/types";
import { Observable } from "babylonjs/Misc/observable";
import { Camera } from "babylonjs/Cameras/camera";
import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
import { Material } from "babylonjs/Materials/material";
import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
import { ISceneLoaderPluginFactory, ISceneLoaderPluginAsync, ISceneLoaderProgressEvent, ISceneLoaderAsyncResult, SceneLoaderPluginOptions } from "babylonjs/Loading/sceneLoader";
import { AssetContainer } from "babylonjs/assetContainer";
import { Scene, IDisposable } from "babylonjs/scene";
import { WebRequest } from "babylonjs/Misc/webRequest";
import { IFileRequest } from "babylonjs/Misc/fileRequest";
import { IDataBuffer } from "babylonjs/Misc/dataReader";
import { GLTFFileLoaderMetadata } from "babylonjs-loaders/glTF/glTFFileLoader.metadata";
import { LoadFileError } from "babylonjs/Misc/fileTools";
import { TransformNode } from "babylonjs/Meshes/transformNode";
/**
* Defines options for glTF loader extensions. This interface is extended by specific extensions.
*/
export interface GLTFLoaderExtensionOptions extends Record<string, Record<string, unknown> | undefined> {
}
module "babylonjs/Loading/sceneLoader" {
interface SceneLoaderPluginOptions {
/**
* Defines options for the glTF loader.
*/
[GLTFFileLoaderMetadata.name]: Partial<GLTFLoaderOptions>;
}
}
/**
* Mode that determines the coordinate system to use.
*/
export enum GLTFLoaderCoordinateSystemMode {
/**
* Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
*/
AUTO = 0,
/**
* Sets the useRightHandedSystem flag on the scene.
*/
FORCE_RIGHT_HANDED = 1
}
/**
* Mode that determines what animations will start.
*/
export enum GLTFLoaderAnimationStartMode {
/**
* No animation will start.
*/
NONE = 0,
/**
* The first animation will start.
*/
FIRST = 1,
/**
* All animations will start.
*/
ALL = 2
}
/**
* Interface that contains the data for the glTF asset.
*/
export interface IGLTFLoaderData {
/**
* The object that represents the glTF JSON.
*/
json: Object;
/**
* The BIN chunk of a binary glTF.
*/
bin: Nullable<IDataBuffer>;
}
/**
* Interface for extending the loader.
*/
export interface IGLTFLoaderExtension {
/**
* The name of this extension.
*/
readonly name: string;
/**
* Defines whether this extension is enabled.
*/
enabled: boolean;
/**
* Defines the order of this extension.
* The loader sorts the extensions using these values when loading.
*/
order?: number;
}
/**
* Loader state.
*/
export enum GLTFLoaderState {
/**
* The asset is loading.
*/
LOADING = 0,
/**
* The asset is ready for rendering.
*/
READY = 1,
/**
* The asset is completely loaded.
*/
COMPLETE = 2
}
/** @internal */
export interface IGLTFLoader extends IDisposable {
importMeshAsync: (meshesNames: string | readonly string[] | null | undefined, scene: Scene, container: Nullable<AssetContainer>, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<ISceneLoaderAsyncResult>;
loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
}
/**
* Adds default/implicit options to extension specific options.
*/
type DefaultExtensionOptions<BaseExtensionOptions> = {
/**
* Defines if the extension is enabled
*/
enabled?: boolean;
} & BaseExtensionOptions;
abstract class GLTFLoaderOptions {
protected copyFrom(options?: Partial<Readonly<GLTFLoaderOptions>>): void;
/**
* Raised when the asset has been parsed
*/
abstract onParsed?: ((loaderData: IGLTFLoaderData) => void) | undefined;
/**
* The coordinate system mode. Defaults to AUTO.
*/
coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
/**
* The animation start mode. Defaults to FIRST.
*/
animationStartMode: GLTFLoaderAnimationStartMode;
/**
* Defines if the loader should load node animations. Defaults to true.
* NOTE: The animation of this node will still load if the node is also a joint of a skin and `loadSkins` is true.
*/
loadNodeAnimations: boolean;
/**
* Defines if the loader should load skins. Defaults to true.
*/
loadSkins: boolean;
/**
* Defines if the loader should load morph targets. Defaults to true.
*/
loadMorphTargets: boolean;
/**
* Defines if the loader should compile materials before raising the success callback. Defaults to false.
*/
compileMaterials: boolean;
/**
* Defines if the loader should also compile materials with clip planes. Defaults to false.
*/
useClipPlane: boolean;
/**
* Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
*/
compileShadowGenerators: boolean;
/**
* Defines if the Alpha blended materials are only applied as coverage.
* If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
* If true, no extra effects are applied to transparent pixels.
*/
transparencyAsCoverage: boolean;
/**
* Defines if the loader should use range requests when load binary glTF files from HTTP.
* Enabling will disable offline support and glTF validator.
* Defaults to false.
*/
useRangeRequests: boolean;
/**
* Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
*/
createInstances: boolean;
/**
* Defines if the loader should always compute the bounding boxes of meshes and not use the min/max values from the position accessor. Defaults to false.
*/
alwaysComputeBoundingBox: boolean;
/**
* If true, load all materials defined in the file, even if not used by any mesh. Defaults to false.
*/
loadAllMaterials: boolean;
/**
* If true, load only the materials defined in the file. Defaults to false.
*/
loadOnlyMaterials: boolean;
/**
* If true, do not load any materials defined in the file. Defaults to false.
*/
skipMaterials: boolean;
/**
* If true, load the color (gamma encoded) textures into sRGB buffers (if supported by the GPU), which will yield more accurate results when sampling the texture. Defaults to true.
*/
useSRGBBuffers: boolean;
/**
* When loading glTF animations, which are defined in seconds, target them to this FPS. Defaults to 60.
*/
targetFps: number;
/**
* Defines if the loader should always compute the nearest common ancestor of the skeleton joints instead of using `skin.skeleton`. Defaults to false.
* Set this to true if loading assets with invalid `skin.skeleton` values.
*/
alwaysComputeSkeletonRootNode: boolean;
/**
* Function called before loading a url referenced by the asset.
* @param url url referenced by the asset
* @returns Async url to load
*/
preprocessUrlAsync: (url: string) => Promise<string>;
/**
* Defines the node to use as the root of the hierarchy when loading the scene (default: undefined). If not defined, a root node will be automatically created.
* You can also pass null if you don't want a root node to be created.
*/
customRootNode?: Nullable<TransformNode>;
/**
* Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
* Note that the callback is called as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
*/
abstract onMeshLoaded?: ((mesh: AbstractMesh) => void) | undefined;
/**
* Callback raised when the loader creates a skin after parsing the glTF properties of the skin node.
* @see https://doc.babylonjs.com/features/featuresDeepDive/importers/glTF/glTFSkinning#ignoring-the-transform-of-the-skinned-mesh
*/
abstract onSkinLoaded?: ((node: TransformNode, skinnedNode: TransformNode) => void) | undefined;
/**
* Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
*/
abstract onTextureLoaded?: ((texture: BaseTexture) => void) | undefined;
/**
* Callback raised when the loader creates a material after parsing the glTF properties of the material.
*/
abstract onMaterialLoaded?: ((material: Material) => void) | undefined;
/**
* Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
*/
abstract onCameraLoaded?: ((camera: Camera) => void) | undefined;
/**
* Defines options for glTF extensions.
*/
extensionOptions: {
[Extension in keyof GLTFLoaderExtensionOptions]?: {
[Option in keyof DefaultExtensionOptions<GLTFLoaderExtensionOptions[Extension]>]: DefaultExtensionOptions<GLTFLoaderExtensionOptions[Extension]>[Option];
};
};
}
/**
* File loader for loading glTF files into a scene.
*/
export class GLTFFileLoader extends GLTFLoaderOptions implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
/** @internal */
static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
/** @internal */
static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
/**
* Creates a new glTF file loader.
* @param options The options for the loader
*/
constructor(options?: Partial<Readonly<GLTFLoaderOptions>>);
/**
* Raised when the asset has been parsed
*/
onParsedObservable: Observable<IGLTFLoaderData>;
private _onParsedObserver;
/**
* Raised when the asset has been parsed
*/
set onParsed(callback: ((loaderData: IGLTFLoaderData) => void) | undefined);
/**
* Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
* Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
* Defaults to true.
* @internal
*/
static IncrementalLoading: boolean;
/**
* Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
* Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
* @internal
*/
static HomogeneousCoordinates: boolean;
/**
* Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
* Note that the observable is raised as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
*/
readonly onMeshLoadedObservable: Observable<AbstractMesh>;
private _onMeshLoadedObserver;
/**
* Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
* Note that the callback is called as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
*/
set onMeshLoaded(callback: ((mesh: AbstractMesh) => void) | undefined);
/**
* Observable raised when the loader creates a skin after parsing the glTF properties of the skin node.
* @see https://doc.babylonjs.com/features/featuresDeepDive/importers/glTF/glTFSkinning#ignoring-the-transform-of-the-skinned-mesh
* @param node - the transform node that corresponds to the original glTF skin node used for animations
* @param skinnedNode - the transform node that is the skinned mesh itself or the parent of the skinned meshes
*/
readonly onSkinLoadedObservable: Observable<{
node: TransformNode;
skinnedNode: TransformNode;
}>;
private _onSkinLoadedObserver;
/**
* Callback raised when the loader creates a skin after parsing the glTF properties of the skin node.
* @see https://doc.babylonjs.com/features/featuresDeepDive/importers/glTF/glTFSkinning#ignoring-the-transform-of-the-skinned-mesh
*/
set onSkinLoaded(callback: ((node: TransformNode, skinnedNode: TransformNode) => void) | undefined);
/**
* Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
*/
readonly onTextureLoadedObservable: Observable<BaseTexture>;
private _onTextureLoadedObserver;
/**
* Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
*/
set onTextureLoaded(callback: ((texture: BaseTexture) => void) | undefined);
/**
* Observable raised when the loader creates a material after parsing the glTF properties of the material.
*/
readonly onMaterialLoadedObservable: Observable<Material>;
private _onMaterialLoadedObserver;
/**
* Callback raised when the loader creates a material after parsing the glTF properties of the material.
*/
set onMaterialLoaded(callback: ((material: Material) => void) | undefined);
/**
* Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
*/
readonly onCameraLoadedObservable: Observable<Camera>;
private _onCameraLoadedObserver;
/**
* Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
*/
set onCameraLoaded(callback: ((camera: Camera) => void) | undefined);
/**
* Observable raised when the asset is completely loaded, immediately before the loader is disposed.
* For assets with LODs, raised when all of the LODs are complete.
* For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
*/
readonly onCompleteObservable: Observable<void>;
private _onCompleteObserver;
/**
* Callback raised when the asset is completely loaded, immediately before the loader is disposed.
* For assets with LODs, raised when all of the LODs are complete.
* For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
*/
set onComplete(callback: () => void);
/**
* Observable raised when an error occurs.
*/
readonly onErrorObservable: Observable<any>;
private _onErrorObserver;
/**
* Callback raised when an error occurs.
*/
set onError(callback: (reason: any) => void);
/**
* Observable raised after the loader is disposed.
*/
readonly onDisposeObservable: Observable<void>;
private _onDisposeObserver;
/**
* Callback raised after the loader is disposed.
*/
set onDispose(callback: () => void);
/**
* Observable raised after a loader extension is created.
* Set additional options for a loader extension in this event.
*/
readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
private _onExtensionLoadedObserver;
/**
* Callback raised after a loader extension is created.
*/
set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
/**
* Defines if the loader logging is enabled.
*/
get loggingEnabled(): boolean;
set loggingEnabled(value: boolean);
/**
* Defines if the loader should capture performance counters.
*/
get capturePerformanceCounters(): boolean;
set capturePerformanceCounters(value: boolean);
/**
* Defines if the loader should validate the asset.
*/
validate: boolean;
/**
* Observable raised after validation when validate is set to true. The event data is the result of the validation.
*/
readonly onValidatedObservable: Observable<GLTF2.IGLTFValidationResults>;
private _onValidatedObserver;
/**
* Callback raised after a loader extension is created.
*/
set onValidated(callback: (results: GLTF2.IGLTFValidationResults) => void);
private _loader;
private _state;
private _progressCallback?;
private _requests;
/**
* Name of the loader ("gltf")
*/
readonly name: "gltf";
/** @internal */
readonly extensions: {
readonly ".gltf": {
readonly isBinary: false;
};
readonly ".glb": {
readonly isBinary: true;
};
};
/**
* Disposes the loader, releases resources during load, and cancels any outstanding requests.
*/
dispose(): void;
/**
* @internal
*/
loadFile(scene: Scene, fileOrUrl: File | string | ArrayBufferView, rootUrl: string, onSuccess: (data: unknown, responseURL?: string) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: LoadFileError) => void, name?: string): Nullable<IFileRequest>;
private _loadBinary;
/**
* @internal
*/
importMeshAsync(meshesNames: string | readonly string[] | null | undefined, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
/**
* @internal
*/
loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
/**
* @internal
*/
loadAssetContainerAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
/**
* @internal
*/
canDirectLoad(data: string): boolean;
/**
* @internal
*/
directLoad(scene: Scene, data: string): Promise<Object>;
/**
* The callback that allows custom handling of the root url based on the response url.
* @param rootUrl the original root url
* @param responseURL the response url if available
* @returns the new root url
*/
rewriteRootURL?(rootUrl: string, responseURL?: string): string;
/** @internal */
createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync;
/**
* The loader state or null if the loader is not active.
*/
get loaderState(): Nullable<GLTFLoaderState>;
/**
* Observable raised when the loader state changes.
*/
onLoaderStateChangedObservable: Observable<Nullable<GLTFLoaderState>>;
/**
* Returns a promise that resolves when the asset is completely loaded.
* @returns a promise that resolves when the asset is completely loaded.
*/
whenCompleteAsync(): Promise<void>;
/**
* @internal
*/
_setState(state: GLTFLoaderState): void;
/**
* @internal
*/
_loadFile(scene: Scene, fileOrUrl: File | string, onSuccess: (data: string | ArrayBuffer) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest) => void, onOpened?: (request: WebRequest) => void): IFileRequest;
private _onProgress;
private _validate;
private _getLoader;
private _parseJson;
private _unpackBinaryAsync;
private _unpackBinaryV1Async;
private _unpackBinaryV2Async;
private static _parseVersion;
private static _compareVersion;
private static readonly _logSpaces;
private _logIndentLevel;
private _loggingEnabled;
/** @internal */
_log: (message: string) => void;
/**
* @internal
*/
_logOpen(message: string): void;
/** @internal */
_logClose(): void;
private _logEnabled;
private _logDisabled;
private _capturePerformanceCounters;
/** @internal */
_startPerformanceCounter: (counterName: string) => void;
/** @internal */
_endPerformanceCounter: (counterName: string) => void;
private _startPerformanceCounterEnabled;
private _startPerformanceCounterDisabled;
private _endPerformanceCounterEnabled;
private _endPerformanceCounterDisabled;
}
export {};
}
declare module "babylonjs-loaders/glTF/2.0/index" {
export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtensionRegistry";
export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
}
declare module "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces" {
import { AnimationGroup } from "babylonjs/Animations/animationGroup";
import { Skeleton } from "babylonjs/Bones/skeleton";
import { Material } from "babylonjs/Materials/material";
import { TransformNode } from "babylonjs/Meshes/transformNode";
import { Buffer, VertexBuffer } from "babylonjs/Buffers/buffer";
import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
import { Mesh } from "babylonjs/Meshes/mesh";
import { Camera } from "babylonjs/Cameras/camera";
import { Light } from "babylonjs/Lights/light";
import * as GLTF2 from "babylonjs-gltf2interface";
/**
* Loader interface with an index field.
*/
export interface IArrayItem {
/**
* The index of this item in the array.
*/
index: number;
}
/**
* Loader interface with additional members.
*/
export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
/** @internal */
_data?: Promise<ArrayBufferView>;
/** @internal */
_babylonVertexBuffer?: {
[kind: string]: Promise<VertexBuffer>;
};
}
/**
* Loader interface with additional members.
*/
export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
}
/** @internal */
export interface _IAnimationSamplerData {
/** @internal */
input: Float32Array;
/** @internal */
interpolation: GLTF2.AnimationSamplerInterpolation;
/** @internal */
output: Float32Array;
}
/**
* Loader interface with additional members.
*/
export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
/** @internal */
_data?: Promise<_IAnimationSamplerData>;
}
/**
* Loader interface with additional members.
*/
export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
/** @internal */
channels: IAnimationChannel[];
/** @internal */
samplers: IAnimationSampler[];
/** @internal */
_babylonAnimationGroup?: AnimationGroup;
}
/**
* Loader interface with additional members.
*/
export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
/** @internal */
_data?: Promise<ArrayBufferView>;
}
/**
* Loader interface with additional members.
*/
export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
/** @internal */
_data?: Promise<ArrayBufferView>;
/** @internal */
_babylonBuffer?: Promise<Buffer>;
}
/**
* Loader interface with additional members.
*/
export interface ICamera extends GLTF2.ICamera, IArrayItem {
/** @internal */
_babylonCamera?: Camera;
}
/**
* Loader interface with additional members.
*/
export interface IImage extends GLTF2.IImage, IArrayItem {
/** @internal */
_data?: Promise<ArrayBufferView>;
}
/**
* Loader interface with additional members.
*/
export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
}
/**
* Loader interface with additional members.
*/
export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
}
/**
* Loader interface with additional members.
*/
export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
/** @internal */
baseColorTexture?: ITextureInfo;
/** @internal */
metallicRoughnessTexture?: ITextureInfo;
}
/**
* Loader interface with additional members.
*/
export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
/** @internal */
pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
/** @internal */
normalTexture?: IMaterialNormalTextureInfo;
/** @internal */
occlusionTexture?: IMaterialOcclusionTextureInfo;
/** @internal */
emissiveTexture?: ITextureInfo;
/** @internal */
_data?: {
[babylonDrawMode: number]: {
babylonMaterial: Material;
babylonMeshes: AbstractMesh[];
promise: Promise<void>;
};
};
}
/**
* Loader interface with additional members.
*/
export interface IMesh extends GLTF2.IMesh, IArrayItem {
/** @internal */
primitives: IMeshPrimitive[];
}
/**
* Loader interface with additional members.
*/
export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
/** @internal */
_instanceData?: {
babylonSourceMesh: Mesh;
promise: Promise<any>;
};
}
/**
* Loader interface with additional members.
*/
export interface INode extends GLTF2.INode, IArrayItem {
/** @internal */
parent?: INode;
/** @internal */
_babylonTransformNode?: TransformNode;
/** @internal */
_babylonTransformNodeForSkin?: TransformNode;
/** @internal */
_primitiveBabylonMeshes?: AbstractMesh[];
/** @internal */
_numMorphTargets?: number;
/** @internal */
_isJoint?: boolean;
}
/** @internal */
export interface _ISamplerData {
/** @internal */
noMipMaps: boolean;
/** @internal */
samplingMode: number;
/** @internal */
wrapU: number;
/** @internal */
wrapV: number;
}
/**
* Loader interface with additional members.
*/
export interface ISampler extends GLTF2.ISampler, IArrayItem {
/** @internal */
_data?: _ISamplerData;
}
/**
* Loader interface with additional members.
*/
export interface IScene extends GLTF2.IScene, IArrayItem {
}
/**
* Loader interface with additional members.
*/
export interface ISkin extends GLTF2.ISkin, IArrayItem {
/** @internal */
_data?: {
babylonSkeleton: Skeleton;
promise: Promise<void>;
};
}
/**
* Loader interface with additional members.
*/
export interface ITexture extends GLTF2.ITexture, IArrayItem {
/** @internal */
_textureInfo: ITextureInfo;
}
/**
* Loader interface with additional members.
*/
export interface ITextureInfo extends GLTF2.ITextureInfo {
/** false or undefined if the texture holds color data (true if data are roughness, normal, ...) */
nonColorData?: boolean;
}
/**
* Loader interface with additional members.
*/
export interface IGLTF extends GLTF2.IGLTF {
/** @internal */
accessors?: IAccessor[];
/** @internal */
animations?: IAnimation[];
/** @internal */
buffers?: IBuffer[];
/** @internal */
bufferViews?: IBufferView[];
/** @internal */
cameras?: ICamera[];
/** @internal */
images?: IImage[];
/** @internal */
materials?: IMaterial[];
/** @internal */
meshes?: IMesh[];
/** @internal */
nodes?: INode[];
/** @internal */
samplers?: ISampler[];
/** @internal */
scenes?: IScene[];
/** @internal */
skins?: ISkin[];
/** @internal */
textures?: ITexture[];
}
/**
* Loader interface with additional members.
*/
export interface IKHRLightsPunctual_Light extends GLTF2.IKHRLightsPunctual_Light, IArrayItem {
/** @hidden */
_babylonLight?: Light;
}
}
declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtensionRegistry" {
import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
interface IRegisteredGLTFExtension {
isGLTFExtension: boolean;
factory: GLTFExtensionFactory;
}
export type GLTFExtensionFactory = (loader: GLTFLoader) => IGLTFLoaderExtension | Promise<IGLTFLoaderExtension>;
/**
* All currently registered glTF 2.0 loader extensions.
*/
export const registeredGLTFExtensions: ReadonlyMap<string, Readonly<IRegisteredGLTFExtension>>;
/**
* Registers a loader extension.
* @param name The name of the loader extension.
* @param isGLTFExtension If the loader extension is a glTF extension, then it will only be used for glTF files that use the corresponding glTF extension. Otherwise, it will be used for all loaded glTF files.
* @param factory The factory function that creates the loader extension.
*/
export function registerGLTFExtension(name: string, isGLTFExtension: boolean, factory: GLTFExtensionFactory): void;
/**
* Unregisters a loader extension.
* @param name The name of the loader extension.
* @returns A boolean indicating whether the extension has been unregistered
*/
export function unregisterGLTFExtension(name: string): boolean;
export {};
}
declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtension" {
import { Nullable } from "babylonjs/types";
import { Animation } from "babylonjs/Animations/animation";
import { AnimationGroup } from "babylonjs/Animations/animationGroup";
import { Material } from "babylonjs/Materials/material";
import { Camera } from "babylonjs/Cameras/camera";
import { Geometry } from "babylonjs/Meshes/geometry";
import { TransformNode } from "babylonjs/Meshes/transformNode";
import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
import { Mesh } from "babylonjs/Meshes/mesh";
import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
import { IDisposable } from "babylonjs/scene";
import { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation, ITexture, IBufferView, IBuffer, IAnimationChannel } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
import { IProperty } from "babylonjs-gltf2interface";
import { IAnimatable } from "babylonjs/Animations/animatable.interface";
/**
* Interface for a glTF loader extension.
*/
export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
/**
* Called after the loader state changes to LOADING.
*/
onLoading?(): void;
/**
* Called after the loader state changes to READY.
*/
onReady?(): void;
/**
* Define this method to modify the default behavior when loading scenes.
* @param context The context when loading the asset
* @param scene The glTF scene property
* @returns A promise that resolves when the load is complete or null if not handled
*/
loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
/**
* Define this method to modify the default behavior when loading nodes.
* @param context The context when loading the asset
* @param node The glTF node property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
*/
loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
/**
* Define this method to modify the default behavior when loading cameras.
* @param context The context when loading the asset
* @param camera The glTF camera property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
*/
loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
/**
* @internal
* Define this method to modify the default behavior when loading vertex data for mesh primitives.
* @param context The context when loading the asset
* @param primitive The glTF mesh primitive property
* @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
*/
_loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
/**
* @internal
* Define this method to modify the default behavior when loading data for mesh primitives.
* @param context The context when loading the asset
* @param name The mesh name when loading the asset
* @param node The glTF node when loading the asset
* @param mesh The glTF mesh when loading the asset
* @param primitive The glTF mesh primitive property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
*/
_loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
/**
* @internal
* Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
* @param context The context when loading the asset
* @param material The glTF material property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
*/
_loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Nullable<Mesh>, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
/**
* Define this method to modify the default behavior when creating materials.
* @param context The context when loading the asset
* @param material The glTF material property
* @param babylonDrawMode The draw mode for the Babylon material
* @returns The Babylon material or null if not handled
*/
createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
/**
* Define this method to modify the default behavior when loading material properties.
* @param context The context when loading the asset
* @param material The glTF material property
* @param babylonMaterial The Babylon material
* @returns A promise that resolves when the load is complete or null if not handled
*/
loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
/**
* Define this method to modify the default behavior when loading texture infos.
* @param context The context when loading the asset
* @param textureInfo The glTF texture info property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
*/
loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
/**
* @internal
* Define this method to modify the default behavior when loading textures.
* @param context The context when loading the asset
* @param texture The glTF texture property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
*/
_loadTextureAsync?(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
/**
* Define this method to modify the default behavior when loading animations.
* @param context The context when loading the asset
* @param animation The glTF animation property
* @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
*/
loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
/**
* @internal
* Define this method to modify the default behvaior when loading animation channels.
* @param context The context when loading the asset
* @param animationContext The context of the animation when loading the asset
* @param animation The glTF animation property
* @param channel The glTF animation channel property
* @param onLoad Called for each animation loaded
* @returns A void promise that resolves when the load is complete or null if not handled
*/
_loadAnimationChannelAsync?(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Nullable<Promise<void>>;
/**
* @internal
* Define this method to modify the default behavior when loading skins.
* @param context The context when loading the asset
* @param node The glTF node property
* @param skin The glTF skin property
* @returns A promise that resolves when the load is complete or null if not handled
*/
_loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
/**
* @internal
* Define this method to modify the default behavior when loading uris.
* @param context The context when loading the asset
* @param property The glTF property associated with the uri
* @param uri The uri to load
* @returns A promise that resolves with the loaded data when the load is complete or null if not handled
*/
_loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
/**
* Define this method to modify the default behavior when loading buffer views.
* @param context The context when loading the asset
* @param bufferView The glTF buffer view property
* @returns A promise that resolves with the loaded data when the load is complete or null if not handled
*/
loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
/**
* Define this method to modify the default behavior when loading buffers.
* @param context The context when loading the asset
* @param buffer The glTF buffer property
* @param byteOffset The byte offset to load
* @param byteLength The byte length to load
* @returns A promise that resolves with the loaded data when the load is complete or null if not handled
*/
loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
}
}
declare module "babylonjs-loaders/glTF/2.0/glTFLoaderAnimation" {
import { Animation } from "babylonjs/Animations/animation";
import { Quaternion, Vector3 } from "babylonjs/Maths/math.vector";
import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
import { IAnimatable } from "babylonjs/Animations/animatable.interface";
/** @internal */
export type GetValueFn = (target: any, source: Float32Array, offset: number, scale: number) => any;
/** @internal */
export function getVector3(_target: any, source: Float32Array, offset: number, scale: number): Vector3;
/** @internal */
export function getQuaternion(_target: any, source: Float32Array, offset: number, scale: number): Quaternion;
/** @internal */
export function getWeights(target: INode, source: Float32Array, offset: number, scale: number): Array<number>;
/** @internal */
export abstract class AnimationPropertyInfo {
readonly type: number;
readonly name: string;
readonly getValue: GetValueFn;
readonly getStride: (target: any) => number;
/** @internal */
constructor(type: number, name: string, getValue: GetValueFn, getStride: (target: any) => number);
protected _buildAnimation(name: string, fps: number, keys: any[]): Animation;
/** @internal */
abstract buildAnimations(target: any, name: string, fps: number, keys: any[], callback: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): void;
}
/** @internal */
export class TransformNodeAnimationPropertyInfo extends AnimationPropertyInfo {
/** @internal */
buildAnimations(target: INode, name: string, fps: number, keys: any[], callback: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): void;
}
/** @internal */
export class WeightAnimationPropertyInfo extends AnimationPropertyInfo {
buildAnimations(target: INode, name: string, fps: number, keys: any[], callback: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): void;
}
/** @internal */
export const nodeAnimationData: {
translation: TransformNodeAnimationPropertyInfo[];
rotation: TransformNodeAnimationPropertyInfo[];
scale: TransformNodeAnimationPropertyInfo[];
weights: WeightAnimationPropertyInfo[];
};
}
declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
import { IndicesArray, Nullable } from "babylonjs/types";
import { Camera } from "babylonjs/Cameras/camera";
import { Animation } from "babylonjs/Animations/animation";
import { IAnimatable } from "babylonjs/Animations/animatable.interface";
import { AnimationGroup } from "babylonjs/Animations/animationGroup";
import { Material } from "babylonjs/Materials/material";
import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
import { TransformNode } from "babylonjs/Meshes/transformNode";
import { Buffer, VertexBuffer } from "babylonjs/Buffers/buffer";
import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
import { Mesh } from "babylonjs/Meshes/mesh";
import { ISceneLoaderAsyncResult, ISceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
import { Scene } from "babylonjs/scene";
import { IProperty } from "babylonjs-gltf2interface";
import { IGLTF, ISampler, INode, IScene, IMesh, IAccessor, ICamera, IAnimation, IBuffer, IBufferView, IMaterial, ITextureInfo, ITexture, IImage, IMeshPrimitive, IArrayItem, IAnimationChannel } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
import { IGLTFLoader, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
import { GLTFFileLoader } from "babylonjs-loaders/glTF/glTFFileLoader";
import { IDataBuffer } from "babylonjs/Misc/dataReader";
import { Light } from "babylonjs/Lights/light";
import { AssetContainer } from "babylonjs/assetContainer";
import { AnimationPropertyInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderAnimation";
import { IObjectInfo } from "babylonjs/ObjectModel/objectModelInterfaces";
import { GLTFExtensionFactory } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtensionRegistry";
export { GLTFFileLoader };
interface IWithMetadata {
metadata: any;
_internalMetadata: any;
}
/**
* Helper class for working with arrays when loading the glTF asset
*/
export class ArrayItem {
/**
* Gets an item from the given array.
* @param context The context when loading the asset
* @param array The array to get the item from
* @param index The index to the array
* @returns The array item
*/
static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
/**
* Gets an item from the given array or returns null if not available.
* @param array The array to get the item from
* @param index The index to the array
* @returns The array item or null
*/
static TryGet<T>(array: ArrayLike<T> | undefined, index: number | undefined): Nullable<T>;
/**
* Assign an `index` field to each item of the given array.
* @param array The array of items
*/
static Assign(array?: IArrayItem[]): void;
}
/** @internal */
export interface IAnimationTargetInfo {
/** @internal */
target: unknown;
/** @internal */
properties: Array<AnimationPropertyInfo>;
}
/**
* The glTF 2.0 loader
*/
export class GLTFLoader implements IGLTFLoader {
/** @internal */
readonly _completePromises: Promise<unknown>[];
/** @internal */
_assetContainer: Nullable<AssetContainer>;
/** Storage */
_babylonLights: Light[];
/** @internal */
_disableInstancedMesh: number;
/** @internal */
_allMaterialsDirtyRequired: boolean;
private readonly _parent;
private readonly _extensions;
private _disposed;
private _rootUrl;
private _fileName;
private _uniqueRootUrl;
private _gltf;
private _bin;
private _babylonScene;
private _rootBabylonMesh;
private _defaultBabylonMaterialData;
private readonly _postSceneLoadActions;
/**
* The default glTF sampler.
*/
static readonly DefaultSampler: ISampler;
/**
* Registers a loader extension.
* @param name The name of the loader extension.
* @param factory The factory function that creates the loader extension.
* @deprecated Please use registerGLTFExtension instead.
*/
static RegisterExtension(name: string, factory: GLTFExtensionFactory): void;
/**
* Unregisters a loader extension.
* @param name The name of the loader extension.
* @returns A boolean indicating whether the extension has been unregistered
* @deprecated Please use unregisterGLTFExtension instead.
*/
static UnregisterExtension(name: string): boolean;
/**
* The object that represents the glTF JSON.
*/
get gltf(): IGLTF;
/**
* The BIN chunk of a binary glTF.
*/
get bin(): Nullable<IDataBuffer>;
/**
* The parent file loader.
*/
get parent(): GLTFFileLoader;
/**
* The Babylon scene when loading the asset.
*/
get babylonScene(): Scene;
/**
* The root Babylon node when loading the asset.
*/
get rootBabylonMesh(): Nullable<TransformNode>;
/**
* The root url when loading the asset.
*/
get rootUrl(): Nullable<string>;
/**
* @internal
*/
constructor(parent: GLTFFileLoader);
/** @internal */
dispose(): void;
/**
* @internal
*/
importMeshAsync(meshesNames: string | readonly string[] | null | undefined, scene: Scene, container: Nullable<AssetContainer>, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
/**
* @internal
*/
loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
private _loadAsync;
private _loadData;
private _setupData;
private _loadExtensionsAsync;
private _createRootNode;
/**
* Loads a glTF scene.
* @param context The context when loading the asset
* @param scene The glTF scene property
* @returns A promise that resolves when the load is complete
*/
loadSceneAsync(context: string, scene: IScene): Promise<void>;
private _forEachPrimitive;
private _getGeometries;
private _getMeshes;
private _getTransformNodes;
private _getSkel