|
@@ -1,8 +1,8 @@
|
|
|
/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
|
|
|
|
|
|
/**
|
|
|
-* Defines the GLTF2 module used to import/export GLTF 2.0 files
|
|
|
-*/
|
|
|
+ * Defines the module used to import/export glTF 2.0 assets
|
|
|
+ */
|
|
|
module BABYLON.GLTF2 {
|
|
|
interface IFileRequestInfo extends IFileRequest {
|
|
|
_lengthComputable?: boolean;
|
|
@@ -10,37 +10,23 @@ module BABYLON.GLTF2 {
|
|
|
_total?: number;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Interface for a meterial with a constructor
|
|
|
- */
|
|
|
- export interface MaterialConstructor<T extends Material> {
|
|
|
- /**
|
|
|
- * The material class
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
+ export interface _MaterialConstructor<T extends Material> {
|
|
|
readonly prototype: T;
|
|
|
- /**
|
|
|
- * Instatiates a material
|
|
|
- * @param name name of the material
|
|
|
- * @param scene the scene the material will be added to
|
|
|
- */
|
|
|
new(name: string, scene: Scene): T;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Used to load from a GLTF2 file
|
|
|
- */
|
|
|
+ * Loader for loading a glTF 2.0 asset
|
|
|
+ */
|
|
|
export class GLTFLoader implements IGLTFLoader {
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _gltf: ILoaderGLTF;
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
+ public _gltf: _ILoaderGLTF;
|
|
|
+
|
|
|
+ /** @ignore */
|
|
|
public _babylonScene: Scene;
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+
|
|
|
+ /** @ignore */
|
|
|
public _completePromises = new Array<Promise<void>>();
|
|
|
|
|
|
private _disposed = false;
|
|
@@ -48,18 +34,15 @@ module BABYLON.GLTF2 {
|
|
|
private _extensions: { [name: string]: GLTFLoaderExtension } = {};
|
|
|
private _rootUrl: string;
|
|
|
private _rootBabylonMesh: Mesh;
|
|
|
- private _defaultSampler = {} as ILoaderSampler;
|
|
|
+ private _defaultSampler = {} as _ILoaderSampler;
|
|
|
private _defaultBabylonMaterials: { [drawMode: number]: PBRMaterial } = {};
|
|
|
private _progressCallback?: (event: SceneLoaderProgressEvent) => void;
|
|
|
private _requests = new Array<IFileRequestInfo>();
|
|
|
|
|
|
private static _Names = new Array<string>();
|
|
|
private static _Factories: { [name: string]: (loader: GLTFLoader) => GLTFLoaderExtension } = {};
|
|
|
- /**
|
|
|
- * @ignore, registers the loader
|
|
|
- * @param name name of the loader
|
|
|
- * @param factory function that converts a loader to a loader extension
|
|
|
- */
|
|
|
+
|
|
|
+ /** @ignore */
|
|
|
public static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void {
|
|
|
if (GLTFLoader._Factories[name]) {
|
|
|
Tools.Error(`Extension with the name '${name}' already exists`);
|
|
@@ -73,61 +56,74 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Coordinate system that will be used when loading from the gltf file
|
|
|
- */
|
|
|
+ * Mode that determines the coordinate system to use.
|
|
|
+ */
|
|
|
public coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
|
|
|
+
|
|
|
/**
|
|
|
- * Animation mode that determines which animations should be started when a file is loaded
|
|
|
- */
|
|
|
+ * Mode that determines what animations will start.
|
|
|
+ */
|
|
|
public animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
|
|
|
+
|
|
|
/**
|
|
|
- * If the materials in the file should automatically be compiled
|
|
|
- */
|
|
|
+ * Defines if the loader should compile materials.
|
|
|
+ */
|
|
|
public compileMaterials = false;
|
|
|
+
|
|
|
/**
|
|
|
- * If a clip plane should be usede when loading meshes in the file
|
|
|
- */
|
|
|
+ * Defines if the loader should also compile materials with clip planes.
|
|
|
+ */
|
|
|
public useClipPlane = false;
|
|
|
+
|
|
|
/**
|
|
|
- * If shadow generators should automatically be compiled
|
|
|
- */
|
|
|
+ * Defines if the loader should compile shadow generators.
|
|
|
+ */
|
|
|
public compileShadowGenerators = false;
|
|
|
|
|
|
/**
|
|
|
- * Observable that fires when the loader is disposed
|
|
|
- */
|
|
|
- public readonly onDisposeObservable = new Observable<IGLTFLoader>();
|
|
|
- /**
|
|
|
- * Observable that fires each time a mesh is loaded
|
|
|
- */
|
|
|
+ * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
|
|
+ */
|
|
|
public readonly onMeshLoadedObservable = new Observable<AbstractMesh>();
|
|
|
+
|
|
|
/**
|
|
|
- * Observable that fires each time a texture is loaded
|
|
|
- */
|
|
|
+ * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
|
|
|
+ */
|
|
|
public readonly onTextureLoadedObservable = new Observable<BaseTexture>();
|
|
|
+
|
|
|
/**
|
|
|
- * Observable that fires each time a material is loaded
|
|
|
- */
|
|
|
+ * Observable raised when the loader creates a material after parsing the glTF properties of the material.
|
|
|
+ */
|
|
|
public readonly onMaterialLoadedObservable = new Observable<Material>();
|
|
|
+
|
|
|
/**
|
|
|
- * Observable that fires each time an extension is loaded
|
|
|
- */
|
|
|
- public readonly onExtensionLoadedObservable = new Observable<IGLTFLoaderExtension>();
|
|
|
- /**
|
|
|
- * Observable that fires when the load has completed
|
|
|
- */
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
public readonly onCompleteObservable = new Observable<IGLTFLoader>();
|
|
|
|
|
|
/**
|
|
|
- * The current state of the loader
|
|
|
- */
|
|
|
+ * Observable raised after the loader is disposed.
|
|
|
+ */
|
|
|
+ public readonly onDisposeObservable = new Observable<IGLTFLoader>();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Observable raised after a loader extension is created.
|
|
|
+ * Set additional options for a loader extension in this event.
|
|
|
+ */
|
|
|
+ public readonly onExtensionLoadedObservable = new Observable<IGLTFLoaderExtension>();
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Loader state or null if the loader is not active.
|
|
|
+ */
|
|
|
public get state(): Nullable<GLTFLoaderState> {
|
|
|
return this._state;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Disposes of the loader
|
|
|
- */
|
|
|
+ * Disposes the loader, releases resources during load, and cancels any outstanding requests.
|
|
|
+ */
|
|
|
public dispose(): void {
|
|
|
if (this._disposed) {
|
|
|
return;
|
|
@@ -142,20 +138,20 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Imports one or more meshes from a loaded gltf file and adds them to the scene
|
|
|
- * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
|
|
- * @param scene the scene the meshes should be added to
|
|
|
- * @param data gltf data containing information of the meshes in a loaded file
|
|
|
- * @param rootUrl root url to load from
|
|
|
- * @param onProgress event that fires when loading progress has occured
|
|
|
- * @returns a promise containg the loaded meshes, particles, skeletons and animations
|
|
|
- */
|
|
|
+ * Imports one or more meshes from the loaded glTF data and adds them to the scene
|
|
|
+ * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
|
|
+ * @param scene the scene the meshes should be added to
|
|
|
+ * @param data the glTF data to load
|
|
|
+ * @param rootUrl root url to load from
|
|
|
+ * @param onProgress event that fires when loading progress has occured
|
|
|
+ * @returns a promise containg the loaded meshes, particles, skeletons and animations
|
|
|
+ */
|
|
|
public importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{ meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[] }> {
|
|
|
return Promise.resolve().then(() => {
|
|
|
- let nodes: Nullable<Array<ILoaderNode>> = null;
|
|
|
+ let nodes: Nullable<Array<_ILoaderNode>> = null;
|
|
|
|
|
|
if (meshesNames) {
|
|
|
- const nodeMap: { [name: string]: ILoaderNode } = {};
|
|
|
+ const nodeMap: { [name: string]: _ILoaderNode } = {};
|
|
|
if (this._gltf.nodes) {
|
|
|
for (const node of this._gltf.nodes) {
|
|
|
if (node.name) {
|
|
@@ -187,18 +183,18 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Imports all objects from a loaded gltf file and adds them to the scene
|
|
|
- * @param scene the scene the objects should be added to
|
|
|
- * @param data gltf data containing information of the meshes in a loaded file
|
|
|
- * @param rootUrl root url to load from
|
|
|
- * @param onProgress event that fires when loading progress has occured
|
|
|
- * @returns a promise which completes when objects have been loaded to the scene
|
|
|
- */
|
|
|
+ * Imports all objects from the loaded glTF data and adds them to the scene
|
|
|
+ * @param scene the scene the objects should be added to
|
|
|
+ * @param data the glTF data to load
|
|
|
+ * @param rootUrl root url to load from
|
|
|
+ * @param onProgress event that fires when loading progress has occured
|
|
|
+ * @returns a promise which completes when objects have been loaded to the scene
|
|
|
+ */
|
|
|
public loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void> {
|
|
|
return this._loadAsync(null, scene, data, rootUrl, onProgress);
|
|
|
}
|
|
|
|
|
|
- private _loadAsync(nodes: Nullable<Array<ILoaderNode>>, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void> {
|
|
|
+ private _loadAsync(nodes: Nullable<Array<_ILoaderNode>>, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void> {
|
|
|
return Promise.resolve().then(() => {
|
|
|
this._loadExtensions();
|
|
|
|
|
@@ -271,7 +267,7 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
|
|
|
private _loadData(data: IGLTFLoaderData): void {
|
|
|
- this._gltf = data.json as ILoaderGLTF;
|
|
|
+ this._gltf = data.json as _ILoaderGLTF;
|
|
|
this._setupData();
|
|
|
|
|
|
if (data.bin) {
|
|
@@ -291,19 +287,19 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
|
|
|
private _setupData(): void {
|
|
|
- ArrayItem.Assign(this._gltf.accessors);
|
|
|
- ArrayItem.Assign(this._gltf.animations);
|
|
|
- ArrayItem.Assign(this._gltf.buffers);
|
|
|
- ArrayItem.Assign(this._gltf.bufferViews);
|
|
|
- ArrayItem.Assign(this._gltf.cameras);
|
|
|
- ArrayItem.Assign(this._gltf.images);
|
|
|
- ArrayItem.Assign(this._gltf.materials);
|
|
|
- ArrayItem.Assign(this._gltf.meshes);
|
|
|
- ArrayItem.Assign(this._gltf.nodes);
|
|
|
- ArrayItem.Assign(this._gltf.samplers);
|
|
|
- ArrayItem.Assign(this._gltf.scenes);
|
|
|
- ArrayItem.Assign(this._gltf.skins);
|
|
|
- ArrayItem.Assign(this._gltf.textures);
|
|
|
+ _ArrayItem.Assign(this._gltf.accessors);
|
|
|
+ _ArrayItem.Assign(this._gltf.animations);
|
|
|
+ _ArrayItem.Assign(this._gltf.buffers);
|
|
|
+ _ArrayItem.Assign(this._gltf.bufferViews);
|
|
|
+ _ArrayItem.Assign(this._gltf.cameras);
|
|
|
+ _ArrayItem.Assign(this._gltf.images);
|
|
|
+ _ArrayItem.Assign(this._gltf.materials);
|
|
|
+ _ArrayItem.Assign(this._gltf.meshes);
|
|
|
+ _ArrayItem.Assign(this._gltf.nodes);
|
|
|
+ _ArrayItem.Assign(this._gltf.samplers);
|
|
|
+ _ArrayItem.Assign(this._gltf.scenes);
|
|
|
+ _ArrayItem.Assign(this._gltf.skins);
|
|
|
+ _ArrayItem.Assign(this._gltf.textures);
|
|
|
|
|
|
if (this._gltf.nodes) {
|
|
|
const nodeParents: { [index: number]: number } = {};
|
|
@@ -334,11 +330,11 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private _createRootNode(): ILoaderNode {
|
|
|
+ private _createRootNode(): _ILoaderNode {
|
|
|
this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
|
|
|
this._rootBabylonMesh.setEnabled(false);
|
|
|
|
|
|
- const rootNode = { _babylonMesh: this._rootBabylonMesh } as ILoaderNode;
|
|
|
+ const rootNode = { _babylonMesh: this._rootBabylonMesh } as _ILoaderNode;
|
|
|
switch (this.coordinateSystemMode) {
|
|
|
case GLTFLoaderCoordinateSystemMode.AUTO: {
|
|
|
if (!this._babylonScene.useRightHandedSystem) {
|
|
@@ -361,7 +357,7 @@ module BABYLON.GLTF2 {
|
|
|
return rootNode;
|
|
|
}
|
|
|
|
|
|
- private _loadNodesAsync(nodes: ILoaderNode[], ): Promise<void> {
|
|
|
+ private _loadNodesAsync(nodes: _ILoaderNode[], ): Promise<void> {
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
for (let node of nodes) {
|
|
@@ -373,10 +369,8 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadSceneAsync(context: string, scene: ILoaderScene): Promise<void> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void> {
|
|
|
const promise = GLTFLoaderExtension._LoadSceneAsync(this, context, scene);
|
|
|
if (promise) {
|
|
|
return promise;
|
|
@@ -394,7 +388,7 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private _forEachPrimitive(node: ILoaderNode, callback: (babylonMesh: Mesh) => void): void {
|
|
|
+ private _forEachPrimitive(node: _ILoaderNode, callback: (babylonMesh: Mesh) => void): void {
|
|
|
if (node._primitiveBabylonMeshes) {
|
|
|
for (const babylonMesh of node._primitiveBabylonMeshes) {
|
|
|
callback(babylonMesh);
|
|
@@ -486,10 +480,8 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadNodeAsync(context: string, node: ILoaderNode): Promise<void> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void> {
|
|
|
const promise = GLTFLoaderExtension._LoadNodeAsync(this, context, node);
|
|
|
if (promise) {
|
|
|
return promise;
|
|
@@ -526,7 +518,7 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private _loadMeshAsync(context: string, node: ILoaderNode, mesh: ILoaderMesh, babylonMesh: Mesh): Promise<void> {
|
|
|
+ private _loadMeshAsync(context: string, node: _ILoaderNode, mesh: _ILoaderMesh, babylonMesh: Mesh): Promise<void> {
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
const primitives = mesh.primitives;
|
|
@@ -534,7 +526,7 @@ module BABYLON.GLTF2 {
|
|
|
throw new Error(`${context}: Primitives are missing`);
|
|
|
}
|
|
|
|
|
|
- ArrayItem.Assign(primitives);
|
|
|
+ _ArrayItem.Assign(primitives);
|
|
|
if (primitives.length === 1) {
|
|
|
const primitive = primitives[0];
|
|
|
promises.push(this._loadPrimitiveAsync(`${context}/primitives/${primitive._index}`, node, mesh, primitive, babylonMesh));
|
|
@@ -561,7 +553,7 @@ module BABYLON.GLTF2 {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private _loadPrimitiveAsync(context: string, node: ILoaderNode, mesh: ILoaderMesh, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Promise<void> {
|
|
|
+ private _loadPrimitiveAsync(context: string, node: _ILoaderNode, mesh: _ILoaderMesh, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Promise<void> {
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
|
|
@@ -585,7 +577,7 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Promise<Geometry> {
|
|
|
+ private _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Promise<Geometry> {
|
|
|
const promise = GLTFLoaderExtension._LoadVertexDataAsync(this, context, primitive, babylonMesh);
|
|
|
if (promise) {
|
|
|
return promise;
|
|
@@ -610,7 +602,7 @@ module BABYLON.GLTF2 {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
- const loadAttribute = (attribute: string, kind: string, callback?: (accessor: ILoaderAccessor) => void) => {
|
|
|
+ const loadAttribute = (attribute: string, kind: string, callback?: (accessor: _ILoaderAccessor) => void) => {
|
|
|
if (attributes[attribute] == undefined) {
|
|
|
return;
|
|
|
}
|
|
@@ -648,7 +640,7 @@ module BABYLON.GLTF2 {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private _createMorphTargets(context: string, node: ILoaderNode, mesh: ILoaderMesh, primitive: IMeshPrimitive, babylonMesh: Mesh): void {
|
|
|
+ private _createMorphTargets(context: string, node: _ILoaderNode, mesh: _ILoaderMesh, primitive: IMeshPrimitive, babylonMesh: Mesh): void {
|
|
|
if (!primitive.targets) {
|
|
|
return;
|
|
|
}
|
|
@@ -739,7 +731,7 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private static _LoadTransform(node: ILoaderNode, babylonNode: TransformNode): void {
|
|
|
+ private static _LoadTransform(node: _ILoaderNode, babylonNode: TransformNode): void {
|
|
|
let position = Vector3.Zero();
|
|
|
let rotation = Quaternion.Identity();
|
|
|
let scaling = Vector3.One();
|
|
@@ -759,7 +751,7 @@ module BABYLON.GLTF2 {
|
|
|
babylonNode.scaling = scaling;
|
|
|
}
|
|
|
|
|
|
- private _loadSkinAsync(context: string, node: ILoaderNode, mesh: ILoaderMesh, skin: ILoaderSkin): Promise<void> {
|
|
|
+ private _loadSkinAsync(context: string, node: _ILoaderNode, mesh: _ILoaderMesh, skin: _ILoaderSkin): Promise<void> {
|
|
|
const assignSkeleton = (skeleton: Skeleton) => {
|
|
|
this._forEachPrimitive(node, babylonMesh => {
|
|
|
babylonMesh.skeleton = skeleton;
|
|
@@ -790,7 +782,7 @@ module BABYLON.GLTF2 {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
- private _loadBones(context: string, skin: ILoaderSkin): void {
|
|
|
+ private _loadBones(context: string, skin: _ILoaderSkin): void {
|
|
|
const babylonBones: { [index: number]: Bone } = {};
|
|
|
for (const index of skin.joints) {
|
|
|
const node = GLTFLoader._GetProperty(`${context}/joints/${index}`, this._gltf.nodes, index);
|
|
@@ -798,7 +790,7 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private _loadBone(node: ILoaderNode, skin: ILoaderSkin, babylonBones: { [index: number]: Bone }): Bone {
|
|
|
+ private _loadBone(node: _ILoaderNode, skin: _ILoaderSkin, babylonBones: { [index: number]: Bone }): Bone {
|
|
|
let babylonBone = babylonBones[node._index];
|
|
|
if (babylonBone) {
|
|
|
return babylonBone;
|
|
@@ -820,7 +812,7 @@ module BABYLON.GLTF2 {
|
|
|
return babylonBone;
|
|
|
}
|
|
|
|
|
|
- private _loadSkinInverseBindMatricesDataAsync(context: string, skin: ILoaderSkin): Promise<Nullable<Float32Array>> {
|
|
|
+ private _loadSkinInverseBindMatricesDataAsync(context: string, skin: _ILoaderSkin): Promise<Nullable<Float32Array>> {
|
|
|
if (skin.inverseBindMatrices == undefined) {
|
|
|
return Promise.resolve(null);
|
|
|
}
|
|
@@ -850,7 +842,7 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private _getNodeMatrix(node: ILoaderNode): Matrix {
|
|
|
+ private _getNodeMatrix(node: _ILoaderNode): Matrix {
|
|
|
return node.matrix ?
|
|
|
Matrix.FromArray(node.matrix) :
|
|
|
Matrix.Compose(
|
|
@@ -875,14 +867,14 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private _loadAnimationAsync(context: string, animation: ILoaderAnimation): Promise<void> {
|
|
|
+ private _loadAnimationAsync(context: string, animation: _ILoaderAnimation): Promise<void> {
|
|
|
const babylonAnimationGroup = new AnimationGroup(animation.name || `animation${animation._index}`, this._babylonScene);
|
|
|
animation._babylonAnimationGroup = babylonAnimationGroup;
|
|
|
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
- ArrayItem.Assign(animation.channels);
|
|
|
- ArrayItem.Assign(animation.samplers);
|
|
|
+ _ArrayItem.Assign(animation.channels);
|
|
|
+ _ArrayItem.Assign(animation.samplers);
|
|
|
|
|
|
for (const channel of animation.channels) {
|
|
|
promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel._index}`, context, animation, channel, babylonAnimationGroup));
|
|
@@ -893,7 +885,7 @@ module BABYLON.GLTF2 {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private _loadAnimationChannelAsync(context: string, animationContext: string, animation: ILoaderAnimation, channel: ILoaderAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
|
|
|
+ private _loadAnimationChannelAsync(context: string, animationContext: string, animation: _ILoaderAnimation, channel: _ILoaderAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
|
|
|
const targetNode = GLTFLoader._GetProperty(`${context}/target/node`, this._gltf.nodes, channel.target.node);
|
|
|
if (!targetNode._babylonMesh) {
|
|
|
return Promise.resolve();
|
|
@@ -1044,7 +1036,7 @@ module BABYLON.GLTF2 {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private _loadAnimationSamplerAsync(context: string, sampler: ILoaderAnimationSampler): Promise<ILoaderAnimationSamplerData> {
|
|
|
+ private _loadAnimationSamplerAsync(context: string, sampler: _ILoaderAnimationSampler): Promise<_ILoaderAnimationSamplerData> {
|
|
|
if (sampler._data) {
|
|
|
return sampler._data;
|
|
|
}
|
|
@@ -1085,7 +1077,7 @@ module BABYLON.GLTF2 {
|
|
|
return sampler._data;
|
|
|
}
|
|
|
|
|
|
- private _loadBufferAsync(context: string, buffer: ILoaderBuffer): Promise<ArrayBufferView> {
|
|
|
+ private _loadBufferAsync(context: string, buffer: _ILoaderBuffer): Promise<ArrayBufferView> {
|
|
|
if (buffer._data) {
|
|
|
return buffer._data;
|
|
|
}
|
|
@@ -1099,10 +1091,8 @@ module BABYLON.GLTF2 {
|
|
|
return buffer._data;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadBufferViewAsync(context: string, bufferView: ILoaderBufferView): Promise<ArrayBufferView> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView> {
|
|
|
if (bufferView._data) {
|
|
|
return bufferView._data;
|
|
|
}
|
|
@@ -1120,7 +1110,7 @@ module BABYLON.GLTF2 {
|
|
|
return bufferView._data;
|
|
|
}
|
|
|
|
|
|
- private _loadAccessorAsync(context: string, accessor: ILoaderAccessor): Promise<ArrayBufferView> {
|
|
|
+ private _loadAccessorAsync(context: string, accessor: _ILoaderAccessor): Promise<ArrayBufferView> {
|
|
|
if (accessor.sparse) {
|
|
|
throw new Error(`${context}: Sparse accessors are not currently supported`);
|
|
|
}
|
|
@@ -1168,10 +1158,8 @@ module BABYLON.GLTF2 {
|
|
|
return accessor._data;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadVertexBufferViewAsync(context: string, bufferView: ILoaderBufferView, kind: string): Promise<Buffer> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer> {
|
|
|
if (bufferView._babylonBuffer) {
|
|
|
return bufferView._babylonBuffer;
|
|
|
}
|
|
@@ -1183,7 +1171,7 @@ module BABYLON.GLTF2 {
|
|
|
return bufferView._babylonBuffer;
|
|
|
}
|
|
|
|
|
|
- private _loadVertexAccessorAsync(context: string, accessor: ILoaderAccessor, kind: string): Promise<VertexBuffer> {
|
|
|
+ private _loadVertexAccessorAsync(context: string, accessor: _ILoaderAccessor, kind: string): Promise<VertexBuffer> {
|
|
|
if (accessor.sparse) {
|
|
|
throw new Error(`${context}: Sparse accessors are not currently supported`);
|
|
|
}
|
|
@@ -1215,7 +1203,7 @@ module BABYLON.GLTF2 {
|
|
|
return babylonMaterial;
|
|
|
}
|
|
|
|
|
|
- private _loadMaterialMetallicRoughnessPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void> {
|
|
|
+ private _loadMaterialMetallicRoughnessPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void> {
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
// Ensure metallic workflow
|
|
@@ -1257,10 +1245,8 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void> {
|
|
|
const promise = GLTFLoaderExtension._LoadMaterialAsync(this, context, material, babylonMesh, babylonDrawMode, assign);
|
|
|
if (promise) {
|
|
|
return promise;
|
|
@@ -1294,20 +1280,16 @@ module BABYLON.GLTF2 {
|
|
|
return babylonData.loaded;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _createMaterial<T extends Material>(type: MaterialConstructor<T>, name: string, drawMode: number): T {
|
|
|
+ /** @ignore */
|
|
|
+ public _createMaterial<T extends Material>(type: _MaterialConstructor<T>, name: string, drawMode: number): T {
|
|
|
const babylonMaterial = new type(name, this._babylonScene);
|
|
|
babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
|
|
babylonMaterial.fillMode = drawMode;
|
|
|
return babylonMaterial;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void> {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void> {
|
|
|
const promises = new Array<Promise<void>>();
|
|
|
|
|
|
babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
|
@@ -1348,10 +1330,8 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
- public _loadMaterialAlphaProperties(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): void {
|
|
|
+ /** @ignore */
|
|
|
+ public _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void {
|
|
|
const alphaMode = material.alphaMode || MaterialAlphaMode.OPAQUE;
|
|
|
switch (alphaMode) {
|
|
|
case MaterialAlphaMode.OPAQUE: {
|
|
@@ -1380,9 +1360,7 @@ module BABYLON.GLTF2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
public _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void> {
|
|
|
const texture = GLTFLoader._GetProperty(`${context}/index`, this._gltf.textures, textureInfo.index);
|
|
|
context = `#/textures/${textureInfo.index}`;
|
|
@@ -1420,7 +1398,7 @@ module BABYLON.GLTF2 {
|
|
|
return Promise.all(promises).then(() => {});
|
|
|
}
|
|
|
|
|
|
- private _loadSampler(context: string, sampler: ILoaderSampler): ILoaderSamplerData {
|
|
|
+ private _loadSampler(context: string, sampler: _ILoaderSampler): _ILoaderSamplerData {
|
|
|
if (!sampler._data) {
|
|
|
sampler._data = {
|
|
|
noMipMaps: (sampler.minFilter === TextureMinFilter.NEAREST || sampler.minFilter === TextureMinFilter.LINEAR),
|
|
@@ -1433,7 +1411,7 @@ module BABYLON.GLTF2 {
|
|
|
return sampler._data;
|
|
|
}
|
|
|
|
|
|
- private _loadImageAsync(context: string, image: ILoaderImage): Promise<string> {
|
|
|
+ private _loadImageAsync(context: string, image: _ILoaderImage): Promise<string> {
|
|
|
if (image._objectURL) {
|
|
|
return image._objectURL;
|
|
|
}
|
|
@@ -1454,9 +1432,7 @@ module BABYLON.GLTF2 {
|
|
|
return image._objectURL;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
public _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView> {
|
|
|
const promise = GLTFLoaderExtension._LoadUriAsync(this, context, uri);
|
|
|
if (promise) {
|
|
@@ -1521,9 +1497,7 @@ module BABYLON.GLTF2 {
|
|
|
this._progressCallback(new SceneLoaderProgressEvent(lengthComputable, loaded, lengthComputable ? total : 0));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
public static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T {
|
|
|
if (!array || index == undefined || !array[index]) {
|
|
|
throw new Error(`${context}: Failed to find index (${index})`);
|
|
@@ -1696,9 +1670,7 @@ module BABYLON.GLTF2 {
|
|
|
this.onMaterialLoadedObservable.clear();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ignore
|
|
|
- */
|
|
|
+ /** @ignore */
|
|
|
public _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>) {
|
|
|
for (const name of GLTFLoader._Names) {
|
|
|
const extension = this._extensions[name];
|