瀏覽代碼

Loaders Rebuild Import

sebastien 6 年之前
父節點
當前提交
2a14b5049c

+ 4 - 2
dist/preview release/babylon.d.ts

@@ -33975,7 +33975,7 @@ declare module BABYLON {
     /**
      * The SPS is a single updatable mesh. The solid particles are simply separate parts or faces fo this big mesh.
      *As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.
-
+
      * The SPS is also a particle system. It provides some methods to manage the particles.
      * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
      *
@@ -46665,6 +46665,8 @@ declare module BABYLON {
          * @param callback Define the callback triggered once the entire list will be ready
          */
         static WhenAllReady(textures: BaseTexture[], callback: () => void): void;
+
+        metadata: any;
     }
 }
 
@@ -51028,4 +51030,4 @@ declare module BABYLON {
          */
         static LuminanceSteps: number;
     }
-}
+}

+ 58 - 59
loaders/src/glTF/2.0/glTFLoader.ts

@@ -1,9 +1,9 @@
-/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+import { IFileRequest, Buffer, Animation, Scene, Nullable, Mesh, Material, SceneLoaderProgressEvent, Tools, AbstractMesh, IParticleSystem, Skeleton, AnimationGroup, Geometry, VertexBuffer, MorphTargetManager, MorphTarget, TransformNode, Vector3, Quaternion, Matrix, Bone, Camera, FreeCamera, IAnimationKey, AnimationKeyInterpolation, IndicesArray, PBRMaterial, Color3, BaseTexture, Deferred, Texture, LoadFileError } from "babylonjs";
+import { IProperty, AccessorType, CameraType, AnimationChannelTargetPath, AnimationSamplerInterpolation, AccessorComponentType, MaterialAlphaMode, TextureMinFilter, TextureWrapMode, TextureMagFilter, MeshPrimitiveMode } from "babylonjs-gltf2interface";
+import { _IAnimationSamplerData, IGLTF, ISampler, INode, IScene, IMesh,  IAccessor, ISkin, ICamera, IAnimation, IAnimationChannel, IAnimationSampler, IBuffer, IBufferView, IMaterialPbrMetallicRoughness, IMaterial, ITextureInfo, ITexture, IImage, IMeshPrimitive, IArrayItem as IArrItem, _ISamplerData } from "./glTFLoaderInterfaces";
+import { IGLTFLoaderExtension } from "./glTFLoaderExtension";
+import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader";
 
-/**
- * Defines the module for importing and exporting glTF 2.0 assets
- */
-module BABYLON.GLTF2 {
     interface IFileRequestInfo extends IFileRequest {
         _lengthComputable?: boolean;
         _loaded?: number;
@@ -37,7 +37,7 @@ module BABYLON.GLTF2 {
          * Assign an `index` field to each item of the given array.
          * @param array The array of items
          */
-        public static Assign(array?: Loader.IArrayItem[]): void {
+        public static Assign(array?: IArrItem[]): void {
             if (array) {
                 for (let index = 0; index < array.length; index++) {
                     array[index].index = index;
@@ -51,7 +51,7 @@ module BABYLON.GLTF2 {
      */
     export class GLTFLoader implements IGLTFLoader {
         /** The glTF object parsed from the JSON. */
-        public gltf: Loader.IGLTF;
+        public gltf: IGLTF;
 
         /** The Babylon scene when loading the asset. */
         public babylonScene: Scene;
@@ -71,7 +71,7 @@ module BABYLON.GLTF2 {
         private _progressCallback?: (event: SceneLoaderProgressEvent) => void;
         private _requests = new Array<IFileRequestInfo>();
 
-        private static readonly _DefaultSampler: Loader.ISampler = { index: -1 };
+        private static readonly _DefaultSampler: ISampler = { index: -1 };
 
         private static _ExtensionNames = new Array<string>();
         private static _ExtensionFactories: { [name: string]: (loader: GLTFLoader) => IGLTFLoaderExtension } = {};
@@ -297,7 +297,7 @@ module BABYLON.GLTF2 {
         }
 
         private _loadData(data: IGLTFLoaderData): void {
-            this.gltf = data.json as Loader.IGLTF;
+            this.gltf = data.json as IGLTF;
             this._setupData();
 
             if (data.bin) {
@@ -376,11 +376,11 @@ module BABYLON.GLTF2 {
             this.log(GLTFLoaderState[this._state]);
         }
 
-        private _createRootNode(): Loader.INode {
+        private _createRootNode(): INode {
             this._rootBabylonMesh = new Mesh("__root__", this.babylonScene);
             this._rootBabylonMesh.setEnabled(false);
 
-            const rootNode: Loader.INode = {
+            const rootNode: INode = {
                 _babylonTransformNode: this._rootBabylonMesh,
                 index: -1
             };
@@ -413,7 +413,7 @@ module BABYLON.GLTF2 {
          * @param scene The glTF scene property
          * @returns A promise that resolves when the load is complete
          */
-        public loadSceneAsync(context: string, scene: Loader.IScene): Promise<void> {
+        public loadSceneAsync(context: string, scene: IScene): Promise<void> {
             const extensionPromise = this._extensionsLoadSceneAsync(context, scene);
             if (extensionPromise) {
                 return extensionPromise;
@@ -439,7 +439,7 @@ module BABYLON.GLTF2 {
             return Promise.all(promises).then(() => { });
         }
 
-        private _forEachPrimitive(node: Loader.INode, callback: (babylonMesh: AbstractMesh) => void): void {
+        private _forEachPrimitive(node: INode, callback: (babylonMesh: AbstractMesh) => void): void {
             if (node._primitiveBabylonMeshes) {
                 for (const babylonMesh of node._primitiveBabylonMeshes) {
                     callback(babylonMesh);
@@ -532,7 +532,7 @@ module BABYLON.GLTF2 {
          * @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
          */
-        public loadNodeAsync(context: string, node: Loader.INode, assign: (babylonTransformNode: TransformNode) => void = () => { }): Promise<TransformNode> {
+        public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void = () => { }): Promise<TransformNode> {
             const extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
             if (extensionPromise) {
                 return extensionPromise;
@@ -596,7 +596,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadMeshAsync(context: string, node: Loader.INode, mesh: Loader.IMesh, assign: (babylonTransformNode: TransformNode) => void): Promise<TransformNode> {
+        private _loadMeshAsync(context: string, node: INode, mesh: IMesh, assign: (babylonTransformNode: TransformNode) => void): Promise<TransformNode> {
             const primitives = mesh.primitives;
             if (!primitives || !primitives.length) {
                 throw new Error(`${context}: Primitives are missing`);
@@ -644,7 +644,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadMeshPrimitiveAsync(context: string, name: string, node: Loader.INode, mesh: Loader.IMesh, primitive: Loader.IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh> {
+        private _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh> {
             this.logOpen(`${context}`);
 
             const canInstance = (node.skin == undefined && !mesh.primitives[0].targets);
@@ -673,7 +673,7 @@ module BABYLON.GLTF2 {
                 if (primitive.material == undefined) {
                     let babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
                     if (!babylonMaterial) {
-                        babylonMaterial = this._createDefaultMaterial("__gltf_default", babylonDrawMode);
+                        babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
                         this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
                         this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
                     }
@@ -709,7 +709,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadVertexDataAsync(context: string, primitive: Loader.IMeshPrimitive, babylonMesh: Mesh): Promise<Geometry> {
+        private _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Promise<Geometry> {
             const extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
             if (extensionPromise) {
                 return extensionPromise;
@@ -734,7 +734,7 @@ module BABYLON.GLTF2 {
                 }));
             }
 
-            const loadAttribute = (attribute: string, kind: string, callback?: (accessor: Loader.IAccessor) => void) => {
+            const loadAttribute = (attribute: string, kind: string, callback?: (accessor: IAccessor) => void) => {
                 if (attributes[attribute] == undefined) {
                     return;
                 }
@@ -772,7 +772,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _createMorphTargets(context: string, node: Loader.INode, mesh: Loader.IMesh, primitive: Loader.IMeshPrimitive, babylonMesh: Mesh): void {
+        private _createMorphTargets(context: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, babylonMesh: Mesh): void {
             if (!primitive.targets) {
                 return;
             }
@@ -792,7 +792,7 @@ module BABYLON.GLTF2 {
             }
         }
 
-        private _loadMorphTargetsAsync(context: string, primitive: Loader.IMeshPrimitive, babylonMesh: Mesh, babylonGeometry: Geometry): Promise<void> {
+        private _loadMorphTargetsAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh, babylonGeometry: Geometry): Promise<void> {
             if (!primitive.targets) {
                 return Promise.resolve();
             }
@@ -859,7 +859,7 @@ module BABYLON.GLTF2 {
             return Promise.all(promises).then(() => { });
         }
 
-        private static _LoadTransform(node: Loader.INode, babylonNode: TransformNode): void {
+        private static _LoadTransform(node: INode, babylonNode: TransformNode): void {
             // Ignore the TRS of skinned nodes.
             // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
             if (node.skin != undefined) {
@@ -885,7 +885,7 @@ module BABYLON.GLTF2 {
             babylonNode.scaling = scaling;
         }
 
-        private _loadSkinAsync(context: string, node: Loader.INode, skin: Loader.ISkin): Promise<void> {
+        private _loadSkinAsync(context: string, node: INode, skin: ISkin): Promise<void> {
             const assignSkeleton = (skeleton: Skeleton) => {
                 this._forEachPrimitive(node, (babylonMesh) => {
                     babylonMesh.skeleton = skeleton;
@@ -916,7 +916,7 @@ module BABYLON.GLTF2 {
             return promise;
         }
 
-        private _loadBones(context: string, skin: Loader.ISkin, babylonSkeleton: Skeleton): void {
+        private _loadBones(context: string, skin: ISkin, babylonSkeleton: Skeleton): void {
             const babylonBones: { [index: number]: Bone } = {};
             for (const index of skin.joints) {
                 const node = ArrayItem.Get(`${context}/joints/${index}`, this.gltf.nodes, index);
@@ -924,7 +924,7 @@ module BABYLON.GLTF2 {
             }
         }
 
-        private _loadBone(node: Loader.INode, skin: Loader.ISkin, babylonSkeleton: Skeleton, babylonBones: { [index: number]: Bone }): Bone {
+        private _loadBone(node: INode, skin: ISkin, babylonSkeleton: Skeleton, babylonBones: { [index: number]: Bone }): Bone {
             let babylonBone = babylonBones[node.index];
             if (babylonBone) {
                 return babylonBone;
@@ -946,7 +946,7 @@ module BABYLON.GLTF2 {
             return babylonBone;
         }
 
-        private _loadSkinInverseBindMatricesDataAsync(context: string, skin: Loader.ISkin): Promise<Nullable<Float32Array>> {
+        private _loadSkinInverseBindMatricesDataAsync(context: string, skin: ISkin): Promise<Nullable<Float32Array>> {
             if (skin.inverseBindMatrices == undefined) {
                 return Promise.resolve(null);
             }
@@ -974,7 +974,7 @@ module BABYLON.GLTF2 {
             }
         }
 
-        private _getNodeMatrix(node: Loader.INode): Matrix {
+        private _getNodeMatrix(node: INode): Matrix {
             return node.matrix ?
                 Matrix.FromArray(node.matrix) :
                 Matrix.Compose(
@@ -990,7 +990,7 @@ module BABYLON.GLTF2 {
          * @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
          */
-        public loadCameraAsync(context: string, camera: Loader.ICamera, assign: (babylonCamera: Camera) => void = () => { }): Promise<Camera> {
+        public loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void = () => { }): Promise<Camera> {
             const extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
             if (extensionPromise) {
                 return extensionPromise;
@@ -1065,7 +1065,7 @@ module BABYLON.GLTF2 {
          * @param animation The glTF animation property
          * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
          */
-        public loadAnimationAsync(context: string, animation: Loader.IAnimation): Promise<AnimationGroup> {
+        public loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup> {
             const promise = this._extensionsLoadAnimationAsync(context, animation);
             if (promise) {
                 return promise;
@@ -1089,7 +1089,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadAnimationChannelAsync(context: string, animationContext: string, animation: Loader.IAnimation, channel: Loader.IAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
+        private _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
             if (channel.target.node == undefined) {
                 return Promise.resolve();
             }
@@ -1251,7 +1251,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadAnimationSamplerAsync(context: string, sampler: Loader.IAnimationSampler): Promise<Loader._IAnimationSamplerData> {
+        private _loadAnimationSamplerAsync(context: string, sampler: IAnimationSampler): Promise<_IAnimationSamplerData> {
             if (sampler._data) {
                 return sampler._data;
             }
@@ -1284,7 +1284,7 @@ module BABYLON.GLTF2 {
             return sampler._data;
         }
 
-        private _loadBufferAsync(context: string, buffer: Loader.IBuffer): Promise<ArrayBufferView> {
+        private _loadBufferAsync(context: string, buffer: IBuffer): Promise<ArrayBufferView> {
             if (buffer._data) {
                 return buffer._data;
             }
@@ -1304,7 +1304,7 @@ module BABYLON.GLTF2 {
          * @param bufferView The glTF buffer view property
          * @returns A promise that resolves with the loaded data when the load is complete
          */
-        public loadBufferViewAsync(context: string, bufferView: Loader.IBufferView): Promise<ArrayBufferView> {
+        public loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView> {
             if (bufferView._data) {
                 return bufferView._data;
             }
@@ -1322,7 +1322,7 @@ module BABYLON.GLTF2 {
             return bufferView._data;
         }
 
-        private _loadIndicesAccessorAsync(context: string, accessor: Loader.IAccessor): Promise<IndicesArray> {
+        private _loadIndicesAccessorAsync(context: string, accessor: IAccessor): Promise<IndicesArray> {
             if (accessor.type !== AccessorType.SCALAR) {
                 throw new Error(`${context}/type: Invalid value ${accessor.type}`);
             }
@@ -1345,7 +1345,7 @@ module BABYLON.GLTF2 {
             return accessor._data as Promise<IndicesArray>;
         }
 
-        private _loadFloatAccessorAsync(context: string, accessor: Loader.IAccessor): Promise<Float32Array> {
+        private _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array> {
             // TODO: support normalized and stride
 
             if (accessor.componentType !== AccessorComponentType.FLOAT) {
@@ -1397,7 +1397,7 @@ module BABYLON.GLTF2 {
             return accessor._data as Promise<Float32Array>;
         }
 
-        private _loadVertexBufferViewAsync(bufferView: Loader.IBufferView, kind: string): Promise<Buffer> {
+        private _loadVertexBufferViewAsync(bufferView: IBufferView, kind: string): Promise<Buffer> {
             if (bufferView._babylonBuffer) {
                 return bufferView._babylonBuffer;
             }
@@ -1409,7 +1409,7 @@ module BABYLON.GLTF2 {
             return bufferView._babylonBuffer;
         }
 
-        private _loadVertexAccessorAsync(context: string, accessor: Loader.IAccessor, kind: string): Promise<VertexBuffer> {
+        private _loadVertexAccessorAsync(context: string, accessor: IAccessor, kind: string): Promise<VertexBuffer> {
             if (accessor._babylonVertexBuffer) {
                 return accessor._babylonVertexBuffer;
             }
@@ -1438,7 +1438,7 @@ module BABYLON.GLTF2 {
             return accessor._babylonVertexBuffer;
         }
 
-        private _loadMaterialMetallicRoughnessPropertiesAsync(context: string, properties: Loader.IMaterialPbrMetallicRoughness, babylonMaterial: Material): Promise<void> {
+        private _loadMaterialMetallicRoughnessPropertiesAsync(context: string, properties: IMaterialPbrMetallicRoughness, babylonMaterial: Material): Promise<void> {
             if (!(babylonMaterial instanceof PBRMaterial)) {
                 throw new Error(`${context}: Material type not supported`);
             }
@@ -1480,7 +1480,7 @@ module BABYLON.GLTF2 {
         }
 
         /** @hidden */
-        public _loadMaterialAsync(context: string, material: Loader.IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void = () => { }): Promise<Material> {
+        public _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void = () => { }): Promise<Material> {
             const extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
             if (extensionPromise) {
                 return extensionPromise;
@@ -1543,7 +1543,7 @@ module BABYLON.GLTF2 {
          * @param babylonDrawMode The draw mode for the Babylon material
          * @returns The Babylon material
          */
-        public createMaterial(context: string, material: Loader.IMaterial, babylonDrawMode: number): Material {
+        public createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material {
             const extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
             if (extensionPromise) {
                 return extensionPromise;
@@ -1562,7 +1562,7 @@ module BABYLON.GLTF2 {
          * @param babylonMaterial The Babylon material
          * @returns A promise that resolves when the load is complete
          */
-        public loadMaterialPropertiesAsync(context: string, material: Loader.IMaterial, babylonMaterial: Material): Promise<void> {
+        public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void> {
             const extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
             if (extensionPromise) {
                 return extensionPromise;
@@ -1588,7 +1588,7 @@ module BABYLON.GLTF2 {
          * @param babylonMaterial The Babylon material
          * @returns A promise that resolves when the load is complete
          */
-        public loadMaterialBasePropertiesAsync(context: string, material: Loader.IMaterial, babylonMaterial: Material): Promise<void> {
+        public loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void> {
             if (!(babylonMaterial instanceof PBRMaterial)) {
                 throw new Error(`${context}: Material type not supported`);
             }
@@ -1643,7 +1643,7 @@ module BABYLON.GLTF2 {
          * @param material The glTF material property
          * @param babylonMaterial The Babylon material
          */
-        public loadMaterialAlphaProperties(context: string, material: Loader.IMaterial, babylonMaterial: Material): void {
+        public loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void {
             if (!(babylonMaterial instanceof PBRMaterial)) {
                 throw new Error(`${context}: Material type not supported`);
             }
@@ -1683,7 +1683,7 @@ module BABYLON.GLTF2 {
          * @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
          */
-        public loadTextureInfoAsync(context: string, textureInfo: Loader.ITextureInfo, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
+        public loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
             const extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
             if (extensionPromise) {
                 return extensionPromise;
@@ -1705,7 +1705,7 @@ module BABYLON.GLTF2 {
             return promise;
         }
 
-        private _loadTextureAsync(context: string, texture: Loader.ITexture, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
+        private _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void = () => { }): Promise<BaseTexture> {
             const promises = new Array<Promise<any>>();
 
             this.logOpen(`${context} ${texture.name || ""}`);
@@ -1744,7 +1744,7 @@ module BABYLON.GLTF2 {
             });
         }
 
-        private _loadSampler(context: string, sampler: Loader.ISampler): Loader._ISamplerData {
+        private _loadSampler(context: string, sampler: ISampler): _ISamplerData {
             if (!sampler._data) {
                 sampler._data = {
                     noMipMaps: (sampler.minFilter === TextureMinFilter.NEAREST || sampler.minFilter === TextureMinFilter.LINEAR),
@@ -1763,7 +1763,7 @@ module BABYLON.GLTF2 {
          * @param image The glTF image property
          * @returns A promise that resolves with the loaded data when the load is complete
          */
-        public loadImageAsync(context: string, image: Loader.IImage): Promise<ArrayBufferView> {
+        public loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView> {
             if (!image._data) {
                 this.logOpen(`${context} ${image.name || ""}`);
 
@@ -1890,7 +1890,7 @@ module BABYLON.GLTF2 {
             }
         }
 
-        private static _GetTextureSamplingMode(context: string, sampler: Loader.ISampler): number {
+        private static _GetTextureSamplingMode(context: string, sampler: ISampler): number {
             // Set defaults if undefined
             const magFilter = sampler.magFilter == undefined ? TextureMagFilter.LINEAR : sampler.magFilter;
             const minFilter = sampler.minFilter == undefined ? TextureMinFilter.LINEAR_MIPMAP_LINEAR : sampler.minFilter;
@@ -2074,39 +2074,39 @@ module BABYLON.GLTF2 {
             this._forEachExtensions((extension) => extension.onReady && extension.onReady());
         }
 
-        private _extensionsLoadSceneAsync(context: string, scene: Loader.IScene): Nullable<Promise<void>> {
+        private _extensionsLoadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {
             return this._applyExtensions(scene, (extension) => extension.loadSceneAsync && extension.loadSceneAsync(context, scene));
         }
 
-        private _extensionsLoadNodeAsync(context: string, node: Loader.INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {
+        private _extensionsLoadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {
             return this._applyExtensions(node, (extension) => extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign));
         }
 
-        private _extensionsLoadCameraAsync(context: string, camera: Loader.ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>> {
+        private _extensionsLoadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>> {
             return this._applyExtensions(camera, (extension) => extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign));
         }
 
-        private _extensionsLoadVertexDataAsync(context: string, primitive: Loader.IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>> {
+        private _extensionsLoadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>> {
             return this._applyExtensions(primitive, (extension) => extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh));
         }
 
-        private _extensionsLoadMaterialAsync(context: string, material: Loader.IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>> {
+        private _extensionsLoadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>> {
             return this._applyExtensions(material, (extension) => extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign));
         }
 
-        private _extensionsCreateMaterial(context: string, material: Loader.IMaterial, babylonDrawMode: number): Nullable<Material> {
+        private _extensionsCreateMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material> {
             return this._applyExtensions({}, (extension) => extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode));
         }
 
-        private _extensionsLoadMaterialPropertiesAsync(context: string, material: Loader.IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {
+        private _extensionsLoadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {
             return this._applyExtensions(material, (extension) => extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial));
         }
 
-        private _extensionsLoadTextureInfoAsync(context: string, textureInfo: Loader.ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {
+        private _extensionsLoadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {
             return this._applyExtensions(textureInfo, (extension) => extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign));
         }
 
-        private _extensionsLoadAnimationAsync(context: string, animation: Loader.IAnimation): Nullable<Promise<AnimationGroup>> {
+        private _extensionsLoadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {
             return this._applyExtensions(animation, (extension) => extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation));
         }
 
@@ -2200,5 +2200,4 @@ module BABYLON.GLTF2 {
         }
     }
 
-    GLTFFileLoader._CreateGLTFLoaderV2 = (parent) => new GLTFLoader(parent);
-}
+    GLTFFileLoader._CreateGLTF2Loader = (parent) => new GLTFLoader(parent);

+ 14 - 20
loaders/src/glTF/2.0/glTFLoaderExtension.ts

@@ -1,10 +1,11 @@
-/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+import { IDisposable, Nullable, TransformNode, Mesh, Camera, Geometry, Material, BaseTexture, AnimationGroup } from "babylonjs";
+import { IScene, INode, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation } from "./glTFLoaderInterfaces";
+import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "../glTFFileLoader";
 
-module BABYLON.GLTF2 {
     /**
      * Interface for a glTF loader extension.
      */
-    export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
+    export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
         /**
          * Called after the loader state changes to LOADING.
          */
@@ -21,7 +22,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.IScene): Nullable<Promise<void>>;
+        loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
 
         /**
          * Define this method to modify the default behavior when loading nodes.
@@ -30,7 +31,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
+        loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
 
         /**
          * Define this method to modify the default behavior when loading cameras.
@@ -39,7 +40,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
+        loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
 
         /**
          * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
@@ -47,7 +48,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
+        _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
 
         /**
          * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
@@ -56,7 +57,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
+        _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
 
         /**
          * Define this method to modify the default behavior when creating materials.
@@ -65,7 +66,7 @@ module BABYLON.GLTF2 {
          * @param babylonDrawMode The draw mode for the Babylon material
          * @returns The Babylon material or null if not handled
          */
-        createMaterial?(context: string, material: Loader.IMaterial, babylonDrawMode: number): Nullable<Material>;
+        createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
 
         /**
          * Define this method to modify the default behavior when loading material properties.
@@ -74,7 +75,7 @@ module BABYLON.GLTF2 {
          * @param babylonMaterial The Babylon material
          * @returns A promise that resolves when the load is complete or null if not handled
          */
-        loadMaterialPropertiesAsync?(context: string, material: Loader.IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
+        loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
 
         /**
          * Define this method to modify the default behavior when loading texture infos.
@@ -83,7 +84,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
+        loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
 
         /**
          * Define this method to modify the default behavior when loading animations.
@@ -91,7 +92,7 @@ module BABYLON.GLTF2 {
          * @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: Loader.IAnimation): Nullable<Promise<AnimationGroup>>;
+        loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
 
         /**
          * Define this method to modify the default behavior when loading uris.
@@ -100,11 +101,4 @@ module BABYLON.GLTF2 {
          * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
          */
         _loadUriAsync?(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
-    }
-}
-
-/**
- * Defines the module for the built-in glTF 2.0 loader extensions.
- */
-module BABYLON.GLTF2.Loader.Extensions {
-}
+    }

+ 24 - 25
loaders/src/glTF/2.0/glTFLoaderInterfaces.ts

@@ -1,6 +1,6 @@
-/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+import { VertexBuffer, Buffer, AnimationGroup, Material, TransformNode, AbstractMesh, Mesh, Bone, Skeleton } from "babylonjs";
+import * as IGLTF2 from "babylonjs-gltf2interface";
 
-module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with an index field.
      */
@@ -14,7 +14,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
+    export interface IAccessor extends IGLTF2.IAccessor, IArrayItem {
         /** @hidden */
         _data?: Promise<ArrayBufferView>;
 
@@ -25,20 +25,20 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
+    export interface IAnimationChannel extends IGLTF2.IAnimationChannel, IArrayItem {
     }
 
     /** @hidden */
     export interface _IAnimationSamplerData {
         input: Float32Array;
-        interpolation: AnimationSamplerInterpolation;
+        interpolation: IGLTF2.AnimationSamplerInterpolation;
         output: Float32Array;
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
+    export interface IAnimationSampler extends IGLTF2.IAnimationSampler, IArrayItem {
         /** @hidden */
         _data?: Promise<_IAnimationSamplerData>;
     }
@@ -46,7 +46,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
+    export interface IAnimation extends IGLTF2.IAnimation, IArrayItem {
         channels: IAnimationChannel[];
         samplers: IAnimationSampler[];
 
@@ -57,7 +57,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
+    export interface IBuffer extends IGLTF2.IBuffer, IArrayItem {
         /** @hidden */
         _data?: Promise<ArrayBufferView>;
     }
@@ -65,7 +65,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
+    export interface IBufferView extends IGLTF2.IBufferView, IArrayItem {
         /** @hidden */
         _data?: Promise<ArrayBufferView>;
 
@@ -76,13 +76,13 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface ICamera extends GLTF2.ICamera, IArrayItem {
+    export interface ICamera extends IGLTF2.ICamera, IArrayItem {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IImage extends GLTF2.IImage, IArrayItem {
+    export interface IImage extends IGLTF2.IImage, IArrayItem {
         /** @hidden */
         _data?: Promise<ArrayBufferView>;
     }
@@ -90,19 +90,19 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
+    export interface IMaterialNormalTextureInfo extends IGLTF2.IMaterialNormalTextureInfo, ITextureInfo {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
+    export interface IMaterialOcclusionTextureInfo extends IGLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
+    export interface IMaterialPbrMetallicRoughness extends IGLTF2.IMaterialPbrMetallicRoughness {
         baseColorTexture?: ITextureInfo;
         metallicRoughnessTexture?: ITextureInfo;
     }
@@ -110,7 +110,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
+    export interface IMaterial extends IGLTF2.IMaterial, IArrayItem {
         pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
         normalTexture?: IMaterialNormalTextureInfo;
         occlusionTexture?: IMaterialOcclusionTextureInfo;
@@ -129,14 +129,14 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IMesh extends GLTF2.IMesh, IArrayItem {
+    export interface IMesh extends IGLTF2.IMesh, IArrayItem {
         primitives: IMeshPrimitive[];
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
+    export interface IMeshPrimitive extends IGLTF2.IMeshPrimitive, IArrayItem {
         /** @hidden */
         _instanceData?: {
             babylonSourceMesh: Mesh;
@@ -147,7 +147,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface INode extends GLTF2.INode, IArrayItem {
+    export interface INode extends IGLTF2.INode, IArrayItem {
         /**
          * The parent glTF node.
          */
@@ -177,7 +177,7 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface ISampler extends GLTF2.ISampler, IArrayItem {
+    export interface ISampler extends IGLTF2.ISampler, IArrayItem {
         /** @hidden */
         _data?: _ISamplerData;
     }
@@ -185,13 +185,13 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface IScene extends GLTF2.IScene, IArrayItem {
+    export interface IScene extends IGLTF2.IScene, IArrayItem {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface ISkin extends GLTF2.ISkin, IArrayItem {
+    export interface ISkin extends IGLTF2.ISkin, IArrayItem {
         /** @hidden */
         _data?: {
             babylonSkeleton: Skeleton;
@@ -202,19 +202,19 @@ module BABYLON.GLTF2.Loader {
     /**
      * Loader interface with additional members.
      */
-    export interface ITexture extends GLTF2.ITexture, IArrayItem {
+    export interface ITexture extends IGLTF2.ITexture, IArrayItem {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface ITextureInfo extends GLTF2.ITextureInfo {
+    export interface ITextureInfo extends IGLTF2.ITextureInfo {
     }
 
     /**
      * Loader interface with additional members.
      */
-    export interface IGLTF extends GLTF2.IGLTF {
+    export interface IGLTF extends IGLTF2.IGLTF {
         accessors?: IAccessor[];
         animations?: IAnimation[];
         buffers?: IBuffer[];
@@ -229,4 +229,3 @@ module BABYLON.GLTF2.Loader {
         skins?: ISkin[];
         textures?: ITexture[];
     }
-}