@babylonjs/loaders
Version:
The Babylon.js file loaders library is an extension you can use to load different 3D file types into a Babylon scene.
303 lines (302 loc) • 13.6 kB
TypeScript
import { Nullable } from "@babylonjs/core/types";
import { Camera } from "@babylonjs/core/Cameras/camera";
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup";
import { Skeleton } from "@babylonjs/core/Bones/skeleton";
import { IParticleSystem } from "@babylonjs/core/Particles/IParticleSystem";
import { Material } from "@babylonjs/core/Materials/material";
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
import { Mesh } from "@babylonjs/core/Meshes/mesh";
import { SceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader";
import { Scene } from "@babylonjs/core/scene";
import { IProperty } from "babylonjs-gltf2interface";
import { IGLTF, INode, IScene, ICamera, IAnimation, IBufferView, IMaterial, ITextureInfo, IImage, IArrayItem as IArrItem } from "./glTFLoaderInterfaces";
import { IGLTFLoaderExtension } from "./glTFLoaderExtension";
import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "../glTFFileLoader";
/**
* Helper class for working with arrays when loading the glTF asset
*/
export declare 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;
/**
* Assign an `index` field to each item of the given array.
* @param array The array of items
*/
static Assign(array?: IArrItem[]): void;
}
/**
* The glTF 2.0 loader
*/
export declare class GLTFLoader implements IGLTFLoader {
/** @hidden */
_completePromises: Promise<any>[];
private _disposed;
private _parent;
private _state;
private _extensions;
private _rootUrl;
private _fileName;
private _uniqueRootUrl;
private _gltf;
private _babylonScene;
private _rootBabylonMesh;
private _defaultBabylonMaterialData;
private _progressCallback?;
private _requests;
private static readonly _DefaultSampler;
private static _ExtensionNames;
private static _ExtensionFactories;
/**
* Registers a loader extension.
* @param name The name of the loader extension.
* @param factory The factory function that creates the loader extension.
*/
static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
/**
* Unregisters a loader extension.
* @param name The name of the loader extenion.
* @returns A boolean indicating whether the extension has been unregistered
*/
static UnregisterExtension(name: string): boolean;
/**
* Gets the loader state.
*/
readonly state: Nullable<GLTFLoaderState>;
/**
* The glTF object parsed from the JSON.
*/
readonly gltf: IGLTF;
/**
* The Babylon scene when loading the asset.
*/
readonly babylonScene: Scene;
/**
* The root Babylon mesh when loading the asset.
*/
readonly rootBabylonMesh: Mesh;
/** @hidden */
constructor(parent: GLTFFileLoader);
/** @hidden */
dispose(): void;
/** @hidden */
importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
meshes: AbstractMesh[];
particleSystems: IParticleSystem[];
skeletons: Skeleton[];
animationGroups: AnimationGroup[];
}>;
/** @hidden */
loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
private _loadAsync;
private _loadData;
private _setupData;
private _loadExtensions;
private _checkExtensions;
private _setState;
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 _getMeshes;
private _getSkeletons;
private _getAnimationGroups;
private _startAnimations;
/**
* Loads a glTF node.
* @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 mesh when the load is complete
*/
loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
private _loadMeshAsync;
private _loadMeshPrimitiveAsync;
private _loadVertexDataAsync;
private _createMorphTargets;
private _loadMorphTargetsAsync;
private _loadMorphTargetVertexDataAsync;
private static _LoadTransform;
private _loadSkinAsync;
private _loadBones;
private _loadBone;
private _loadSkinInverseBindMatricesDataAsync;
private _updateBoneMatrices;
private _getNodeMatrix;
/**
* Loads a glTF camera.
* @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
*/
loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
private _loadAnimationsAsync;
/**
* Loads a glTF animation.
* @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
*/
loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
private _loadAnimationChannelAsync;
private _loadAnimationSamplerAsync;
private _loadBufferAsync;
/**
* Loads a glTF buffer view.
* @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
*/
loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
private _loadIndicesAccessorAsync;
private _loadFloatAccessorAsync;
private _loadVertexBufferViewAsync;
private _loadVertexAccessorAsync;
private _loadMaterialMetallicRoughnessPropertiesAsync;
/** @hidden */
_loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
private _createDefaultMaterial;
/**
* Creates a Babylon material from a glTF material.
* @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
*/
createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
/**
* Loads properties from a glTF material into a Babylon material.
* @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
*/
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
/**
* Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
* @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
*/
loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
/**
* Loads the alpha properties from a glTF material into a Babylon material.
* Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
* @param context The context when loading the asset
* @param material The glTF material property
* @param babylonMaterial The Babylon material
*/
loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
/**
* Loads a glTF texture info.
* @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
*/
loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
private _loadTextureAsync;
private _loadSampler;
/**
* Loads a glTF image.
* @param context The context when loading the asset
* @param image The glTF image property
* @returns A promise that resolves with the loaded data when the load is complete
*/
loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
/**
* Loads a glTF uri.
* @param context The context when loading the asset
* @param property The glTF property associated with the uri
* @param uri The base64 or relative uri
* @returns A promise that resolves with the loaded data when the load is complete
*/
loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
private _onProgress;
/**
* Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
* @param babylonObject the Babylon object with metadata
* @param pointer the JSON pointer
*/
static AddPointerMetadata(babylonObject: {
metadata: any;
}, pointer: string): void;
private static _GetTextureWrapMode;
private static _GetTextureSamplingMode;
private static _GetTypedArray;
private static _GetNumComponents;
private static _ValidateUri;
private static _GetDrawMode;
private _compileMaterialsAsync;
private _compileShadowGeneratorsAsync;
private _forEachExtensions;
private _applyExtensions;
private _extensionsOnLoading;
private _extensionsOnReady;
private _extensionsLoadSceneAsync;
private _extensionsLoadNodeAsync;
private _extensionsLoadCameraAsync;
private _extensionsLoadVertexDataAsync;
private _extensionsLoadMaterialAsync;
private _extensionsCreateMaterial;
private _extensionsLoadMaterialPropertiesAsync;
private _extensionsLoadTextureInfoAsync;
private _extensionsLoadAnimationAsync;
private _extensionsLoadUriAsync;
/**
* Helper method called by a loader extension to load an glTF extension.
* @param context The context when loading the asset
* @param property The glTF property to load the extension from
* @param extensionName The name of the extension to load
* @param actionAsync The action to run
* @returns The promise returned by actionAsync or null if the extension does not exist
*/
static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
/**
* Helper method called by a loader extension to load a glTF extra.
* @param context The context when loading the asset
* @param property The glTF property to load the extra from
* @param extensionName The name of the extension to load
* @param actionAsync The action to run
* @returns The promise returned by actionAsync or null if the extra does not exist
*/
static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
/**
* Increments the indentation level and logs a message.
* @param message The message to log
*/
logOpen(message: string): void;
/**
* Decrements the indentation level.
*/
logClose(): void;
/**
* Logs a message
* @param message The message to log
*/
log(message: string): void;
/**
* Starts a performance counter.
* @param counterName The name of the performance counter
*/
startPerformanceCounter(counterName: string): void;
/**
* Ends a performance counter.
* @param counterName The name of the performance counter
*/
endPerformanceCounter(counterName: string): void;
}