@babylonjs/loaders 5.0.0-alpha.9 → 5.0.0-beta.4
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +2 -0
- package/OBJ/index.js +4 -2
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +4 -2
- package/OBJ/mtlFileLoader.js +7 -6
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +12 -84
- package/OBJ/objFileLoader.js +50 -667
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -0
- package/OBJ/objLoadingOptions.js +2 -0
- package/OBJ/objLoadingOptions.js.map +1 -0
- package/OBJ/solidParser.d.ts +153 -0
- package/OBJ/solidParser.js +700 -0
- package/OBJ/solidParser.js.map +1 -0
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +6 -0
- package/STL/stlFileLoader.js +38 -11
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +4 -4
- package/glTF/1.0/glTFLoader.d.ts +4 -4
- package/glTF/1.0/glTFLoader.js +60 -55
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +3 -1
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +6 -6
- package/glTF/1.0/glTFMaterialsCommonExtension.js +12 -12
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -3
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +1 -5
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +5 -21
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +8 -4
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +9 -8
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +30 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +46 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_specular.js +12 -6
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +6 -6
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +93 -84
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
- package/glTF/2.0/Extensions/KHR_materials_variants.js +70 -5
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +31 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js +79 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -4
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +2 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -3
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +6 -7
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +2 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +48 -8
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +2 -2
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +2 -2
- package/glTF/2.0/Extensions/index.d.ts +2 -0
- package/glTF/2.0/Extensions/index.js +26 -24
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +6 -11
- package/glTF/2.0/glTFLoader.js +129 -95
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +4 -2
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +1 -1
- package/glTF/2.0/index.js +4 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +15 -9
- package/glTF/glTFFileLoader.js +62 -76
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +1 -1
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +2 -2
- package/glTF/index.js +4 -4
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.js +4 -4
- package/legacy/legacy-glTF1.d.ts +1 -1
- package/legacy/legacy-glTF1.js +1 -1
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.js +2 -2
- package/legacy/legacy-glTF2.d.ts +1 -1
- package/legacy/legacy-glTF2.js +3 -3
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.js +2 -2
- package/legacy/legacy-glTFFileLoader.js +3 -3
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.js +6 -6
- package/package.json +16 -4
@@ -3,7 +3,7 @@ import { Bone } from "@babylonjs/core/Bones/bone";
|
|
3
3
|
import { Skeleton } from "@babylonjs/core/Bones/skeleton";
|
4
4
|
import { Material } from "@babylonjs/core/Materials/material";
|
5
5
|
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
|
6
|
-
import { Buffer, VertexBuffer } from "@babylonjs/core/
|
6
|
+
import { Buffer, VertexBuffer } from "@babylonjs/core/Buffers/buffer";
|
7
7
|
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
|
8
8
|
import { Mesh } from "@babylonjs/core/Meshes/mesh";
|
9
9
|
import * as GLTF2 from "babylonjs-gltf2interface";
|
@@ -23,7 +23,9 @@ export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
|
|
23
23
|
/** @hidden */
|
24
24
|
_data?: Promise<ArrayBufferView>;
|
25
25
|
/** @hidden */
|
26
|
-
_babylonVertexBuffer?:
|
26
|
+
_babylonVertexBuffer?: {
|
27
|
+
[kind: string]: Promise<VertexBuffer>;
|
28
|
+
};
|
27
29
|
}
|
28
30
|
/**
|
29
31
|
* Loader interface with additional members.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"glTFLoaderInterfaces.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/2.0/glTFLoaderInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import { AnimationGroup } from \"@babylonjs/core/Animations/animationGroup\";\r\nimport { Bone } from \"@babylonjs/core/Bones/bone\";\r\nimport { Skeleton } from \"@babylonjs/core/Bones/skeleton\";\r\nimport { Material } from \"@babylonjs/core/Materials/material\";\r\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\r\nimport { Buffer, VertexBuffer } from \"@babylonjs/core/
|
1
|
+
{"version":3,"file":"glTFLoaderInterfaces.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/2.0/glTFLoaderInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import { AnimationGroup } from \"@babylonjs/core/Animations/animationGroup\";\r\nimport { Bone } from \"@babylonjs/core/Bones/bone\";\r\nimport { Skeleton } from \"@babylonjs/core/Bones/skeleton\";\r\nimport { Material } from \"@babylonjs/core/Materials/material\";\r\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\r\nimport { Buffer, VertexBuffer } from \"@babylonjs/core/Buffers/buffer\";\r\nimport { AbstractMesh } from \"@babylonjs/core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"@babylonjs/core/Meshes/mesh\";\r\n\r\nimport * as GLTF2 from \"babylonjs-gltf2interface\";\r\n\r\n/**\r\n * Loader interface with an index field.\r\n */\r\nexport interface IArrayItem {\r\n /**\r\n * The index of this item in the array.\r\n */\r\n index: number;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IAccessor extends GLTF2.IAccessor, IArrayItem {\r\n /** @hidden */\r\n _data?: Promise<ArrayBufferView>;\r\n\r\n /** @hidden */\r\n _babylonVertexBuffer?: { [kind: string]: Promise<VertexBuffer>; };\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {\r\n}\r\n\r\n/** @hidden */\r\nexport interface _IAnimationSamplerData {\r\n input: Float32Array;\r\n interpolation: GLTF2.AnimationSamplerInterpolation;\r\n output: Float32Array;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {\r\n /** @hidden */\r\n _data?: Promise<_IAnimationSamplerData>;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IAnimation extends GLTF2.IAnimation, IArrayItem {\r\n channels: IAnimationChannel[];\r\n samplers: IAnimationSampler[];\r\n\r\n /** @hidden */\r\n _babylonAnimationGroup?: AnimationGroup;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IBuffer extends GLTF2.IBuffer, IArrayItem {\r\n /** @hidden */\r\n _data?: Promise<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IBufferView extends GLTF2.IBufferView, IArrayItem {\r\n /** @hidden */\r\n _data?: Promise<ArrayBufferView>;\r\n\r\n /** @hidden */\r\n _babylonBuffer?: Promise<Buffer>;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface ICamera extends GLTF2.ICamera, IArrayItem {\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IImage extends GLTF2.IImage, IArrayItem {\r\n /** @hidden */\r\n _data?: Promise<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {\r\n baseColorTexture?: ITextureInfo;\r\n metallicRoughnessTexture?: ITextureInfo;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMaterial extends GLTF2.IMaterial, IArrayItem {\r\n pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;\r\n normalTexture?: IMaterialNormalTextureInfo;\r\n occlusionTexture?: IMaterialOcclusionTextureInfo;\r\n emissiveTexture?: ITextureInfo;\r\n\r\n /** @hidden */\r\n _data?: {\r\n [babylonDrawMode: number]: {\r\n babylonMaterial: Material;\r\n babylonMeshes: AbstractMesh[];\r\n promise: Promise<void>;\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMesh extends GLTF2.IMesh, IArrayItem {\r\n primitives: IMeshPrimitive[];\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {\r\n /** @hidden */\r\n _instanceData?: {\r\n babylonSourceMesh: Mesh;\r\n promise: Promise<any>;\r\n };\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface INode extends GLTF2.INode, IArrayItem {\r\n /**\r\n * The parent glTF node.\r\n */\r\n parent?: INode;\r\n\r\n /** @hidden */\r\n _babylonTransformNode?: TransformNode;\r\n\r\n /** @hidden */\r\n _primitiveBabylonMeshes?: AbstractMesh[];\r\n\r\n /** @hidden */\r\n _babylonBones?: Bone[];\r\n\r\n /** @hidden */\r\n _numMorphTargets?: number;\r\n}\r\n\r\n/** @hidden */\r\nexport interface _ISamplerData {\r\n noMipMaps: boolean;\r\n samplingMode: number;\r\n wrapU: number;\r\n wrapV: number;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface ISampler extends GLTF2.ISampler, IArrayItem {\r\n /** @hidden */\r\n _data?: _ISamplerData;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IScene extends GLTF2.IScene, IArrayItem {\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface ISkin extends GLTF2.ISkin, IArrayItem {\r\n /** @hidden */\r\n _data?: {\r\n babylonSkeleton: Skeleton;\r\n promise: Promise<void>;\r\n };\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface ITexture extends GLTF2.ITexture, IArrayItem {\r\n /** @hidden */\r\n _textureInfo: ITextureInfo;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface ITextureInfo extends GLTF2.ITextureInfo {\r\n /** false or undefined if the texture holds color data (true if data are roughness, normal, ...) */\r\n nonColorData?: boolean;\r\n}\r\n\r\n/**\r\n * Loader interface with additional members.\r\n */\r\nexport interface IGLTF extends GLTF2.IGLTF {\r\n accessors?: IAccessor[];\r\n animations?: IAnimation[];\r\n buffers?: IBuffer[];\r\n bufferViews?: IBufferView[];\r\n cameras?: ICamera[];\r\n images?: IImage[];\r\n materials?: IMaterial[];\r\n meshes?: IMesh[];\r\n nodes?: INode[];\r\n samplers?: ISampler[];\r\n scenes?: IScene[];\r\n skins?: ISkin[];\r\n textures?: ITexture[];\r\n}\r\n"]}
|
package/glTF/2.0/index.d.ts
CHANGED
package/glTF/2.0/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
export * from "./glTFLoader";
|
2
|
-
export * from "./glTFLoaderExtension";
|
3
|
-
export * from "./glTFLoaderInterfaces";
|
4
|
-
export * from "./Extensions";
|
1
|
+
export * from "./glTFLoader.js";
|
2
|
+
export * from "./glTFLoaderExtension.js";
|
3
|
+
export * from "./glTFLoaderInterfaces.js";
|
4
|
+
export * from "./Extensions/index.js";
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/glTF/2.0/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/2.0/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/2.0/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./glTFLoader\";\r\nexport * from \"./glTFLoaderExtension\";\r\nexport * from \"./glTFLoaderInterfaces\";\r\nexport * from \"./Extensions/index\";"]}
|
package/glTF/glTFFileLoader.d.ts
CHANGED
@@ -11,7 +11,7 @@ import { Scene, IDisposable } from "@babylonjs/core/scene";
|
|
11
11
|
import { WebRequest } from "@babylonjs/core/Misc/webRequest";
|
12
12
|
import { IFileRequest } from "@babylonjs/core/Misc/fileRequest";
|
13
13
|
import { IDataBuffer } from '@babylonjs/core/Misc/dataReader';
|
14
|
-
import {
|
14
|
+
import { LoadFileError } from '@babylonjs/core/Misc/fileTools';
|
15
15
|
/**
|
16
16
|
* Mode that determines the coordinate system to use.
|
17
17
|
*/
|
@@ -92,8 +92,7 @@ export declare enum GLTFLoaderState {
|
|
92
92
|
}
|
93
93
|
/** @hidden */
|
94
94
|
export interface IGLTFLoader extends IDisposable {
|
95
|
-
|
96
|
-
importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<ISceneLoaderAsyncResult>;
|
95
|
+
importMeshAsync: (meshesNames: any, scene: Scene, container: Nullable<AssetContainer>, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<ISceneLoaderAsyncResult>;
|
97
96
|
loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
|
98
97
|
}
|
99
98
|
/**
|
@@ -171,8 +170,12 @@ export declare class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAs
|
|
171
170
|
*/
|
172
171
|
loadAllMaterials: boolean;
|
173
172
|
/**
|
174
|
-
*
|
173
|
+
* 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.
|
175
174
|
*/
|
175
|
+
useSRGBBuffers: boolean;
|
176
|
+
/**
|
177
|
+
* Function called before loading a url referenced by the asset.
|
178
|
+
*/
|
176
179
|
preprocessUrlAsync: (url: string) => Promise<string>;
|
177
180
|
/**
|
178
181
|
* Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
@@ -277,6 +280,7 @@ export declare class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAs
|
|
277
280
|
*/
|
278
281
|
set onValidated(callback: (results: GLTF2.IGLTFValidationResults) => void);
|
279
282
|
private _loader;
|
283
|
+
private _state;
|
280
284
|
private _progressCallback?;
|
281
285
|
private _requests;
|
282
286
|
private static magicBase64Encoded;
|
@@ -291,9 +295,7 @@ export declare class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAs
|
|
291
295
|
*/
|
292
296
|
dispose(): void;
|
293
297
|
/** @hidden */
|
294
|
-
|
295
|
-
/** @hidden */
|
296
|
-
readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
|
298
|
+
loadFile(scene: Scene, fileOrUrl: File | string, onSuccess: (data: any, responseURL?: string) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: LoadFileError) => void): IFileRequest;
|
297
299
|
/** @hidden */
|
298
300
|
importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
|
299
301
|
/** @hidden */
|
@@ -317,15 +319,19 @@ export declare class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAs
|
|
317
319
|
* The loader state or null if the loader is not active.
|
318
320
|
*/
|
319
321
|
get loaderState(): Nullable<GLTFLoaderState>;
|
322
|
+
/**
|
323
|
+
* Observable raised when the loader state changes.
|
324
|
+
*/
|
325
|
+
onLoaderStateChangedObservable: Observable<Nullable<GLTFLoaderState>>;
|
320
326
|
/**
|
321
327
|
* Returns a promise that resolves when the asset is completely loaded.
|
322
328
|
* @returns a promise that resolves when the asset is completely loaded.
|
323
329
|
*/
|
324
330
|
whenCompleteAsync(): Promise<void>;
|
325
331
|
/** @hidden */
|
326
|
-
|
332
|
+
_setState(state: GLTFLoaderState): void;
|
327
333
|
/** @hidden */
|
328
|
-
|
334
|
+
_loadFile(scene: Scene, fileOrUrl: File | string, onSuccess: (data: string | ArrayBuffer) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest) => void, onOpened?: (request: WebRequest) => void): IFileRequest;
|
329
335
|
private _onProgress;
|
330
336
|
private _validate;
|
331
337
|
private _getLoader;
|
package/glTF/glTFFileLoader.js
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
-
import { Observable } from "@babylonjs/core/Misc/observable";
|
2
|
-
import { Tools } from "@babylonjs/core/Misc/tools";
|
3
|
-
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader";
|
4
|
-
import { AssetContainer } from "@babylonjs/core/assetContainer";
|
5
|
-
import { Logger } from '@babylonjs/core/Misc/logger';
|
6
|
-
import { DataReader } from '@babylonjs/core/Misc/dataReader';
|
7
|
-
import { GLTFValidation } from './glTFValidation';
|
8
|
-
import {
|
1
|
+
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
2
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
+
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
|
+
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
+
import { Logger } from '@babylonjs/core/Misc/logger.js';
|
6
|
+
import { DataReader } from '@babylonjs/core/Misc/dataReader.js';
|
7
|
+
import { GLTFValidation } from './glTFValidation.js';
|
8
|
+
import { DecodeBase64UrlToBinary } from '@babylonjs/core/Misc/fileTools.js';
|
9
|
+
import { StringTools } from '@babylonjs/core/Misc/stringTools.js';
|
10
|
+
function readAsync(arrayBuffer, byteOffset, byteLength) {
|
11
|
+
try {
|
12
|
+
return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength));
|
13
|
+
}
|
14
|
+
catch (e) {
|
15
|
+
return Promise.reject(e);
|
16
|
+
}
|
17
|
+
}
|
9
18
|
/**
|
10
19
|
* Mode that determines the coordinate system to use.
|
11
20
|
*/
|
@@ -116,8 +125,12 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
116
125
|
*/
|
117
126
|
this.loadAllMaterials = false;
|
118
127
|
/**
|
119
|
-
*
|
128
|
+
* 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.
|
120
129
|
*/
|
130
|
+
this.useSRGBBuffers = true;
|
131
|
+
/**
|
132
|
+
* Function called before loading a url referenced by the asset.
|
133
|
+
*/
|
121
134
|
this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
|
122
135
|
/**
|
123
136
|
* Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
@@ -164,6 +177,7 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
164
177
|
*/
|
165
178
|
this.onValidatedObservable = new Observable();
|
166
179
|
this._loader = null;
|
180
|
+
this._state = null;
|
167
181
|
this._requests = new Array();
|
168
182
|
/**
|
169
183
|
* Name of the loader ("gltf")
|
@@ -174,6 +188,10 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
174
188
|
".gltf": { isBinary: false },
|
175
189
|
".glb": { isBinary: true }
|
176
190
|
};
|
191
|
+
/**
|
192
|
+
* Observable raised when the loader state changes.
|
193
|
+
*/
|
194
|
+
this.onLoaderStateChangedObservable = new Observable();
|
177
195
|
this._logIndentLevel = 0;
|
178
196
|
this._loggingEnabled = false;
|
179
197
|
/** @hidden */
|
@@ -388,7 +406,7 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
388
406
|
this.onDisposeObservable.clear();
|
389
407
|
};
|
390
408
|
/** @hidden */
|
391
|
-
GLTFFileLoader.prototype.
|
409
|
+
GLTFFileLoader.prototype.loadFile = function (scene, fileOrUrl, onSuccess, onProgress, useArrayBuffer, onError) {
|
392
410
|
var _this = this;
|
393
411
|
this._progressCallback = onProgress;
|
394
412
|
if (useArrayBuffer) {
|
@@ -403,7 +421,7 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
403
421
|
var dataBuffer = {
|
404
422
|
readAsync: function (byteOffset, byteLength) {
|
405
423
|
return new Promise(function (resolve, reject) {
|
406
|
-
_this.
|
424
|
+
_this._loadFile(scene, fileOrUrl, function (data) {
|
407
425
|
resolve(new Uint8Array(data));
|
408
426
|
}, true, function (error) {
|
409
427
|
reject(error);
|
@@ -417,40 +435,29 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
417
435
|
this._unpackBinaryAsync(new DataReader(dataBuffer)).then(function (loaderData) {
|
418
436
|
fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
|
419
437
|
onSuccess(loaderData);
|
420
|
-
}, onError);
|
438
|
+
}, onError ? function (error) { return onError(undefined, error); } : undefined);
|
421
439
|
return fileRequest_1;
|
422
440
|
}
|
423
|
-
return this.
|
441
|
+
return this._loadFile(scene, fileOrUrl, function (data) {
|
424
442
|
var arrayBuffer = data;
|
425
443
|
_this._unpackBinaryAsync(new DataReader({
|
426
|
-
readAsync: function (byteOffset, byteLength) { return
|
444
|
+
readAsync: function (byteOffset, byteLength) { return readAsync(arrayBuffer, byteOffset, byteLength); },
|
427
445
|
byteLength: arrayBuffer.byteLength
|
428
446
|
})).then(function (loaderData) {
|
429
|
-
onSuccess(loaderData
|
430
|
-
}, onError);
|
447
|
+
onSuccess(loaderData);
|
448
|
+
}, onError ? function (error) { return onError(undefined, error); } : undefined);
|
431
449
|
}, true, onError);
|
432
450
|
}
|
433
|
-
return this.
|
434
|
-
|
435
|
-
|
436
|
-
}, useArrayBuffer, onError);
|
437
|
-
};
|
438
|
-
/** @hidden */
|
439
|
-
GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
|
440
|
-
var _this = this;
|
441
|
-
return scene._readFile(file, function (data) {
|
442
|
-
_this._validate(scene, data, "file:", file.name);
|
443
|
-
if (useArrayBuffer) {
|
444
|
-
var arrayBuffer_1 = data;
|
445
|
-
_this._unpackBinaryAsync(new DataReader({
|
446
|
-
readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
|
447
|
-
byteLength: arrayBuffer_1.byteLength
|
448
|
-
})).then(onSuccess, onError);
|
451
|
+
return this._loadFile(scene, fileOrUrl, function (data) {
|
452
|
+
if (fileOrUrl.name) {
|
453
|
+
_this._validate(scene, data, "file:", fileOrUrl.name);
|
449
454
|
}
|
450
455
|
else {
|
451
|
-
|
456
|
+
var url = fileOrUrl;
|
457
|
+
_this._validate(scene, data, Tools.GetFolderPath(url), Tools.GetFilename(url));
|
452
458
|
}
|
453
|
-
|
459
|
+
onSuccess({ json: _this._parseJson(data) });
|
460
|
+
}, useArrayBuffer, onError);
|
454
461
|
};
|
455
462
|
/** @hidden */
|
456
463
|
GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
|
@@ -460,7 +467,7 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
460
467
|
_this.onParsedObservable.clear();
|
461
468
|
_this._log("Loading " + (fileName || ""));
|
462
469
|
_this._loader = _this._getLoader(data);
|
463
|
-
return _this._loader.importMeshAsync(meshesNames, scene,
|
470
|
+
return _this._loader.importMeshAsync(meshesNames, scene, null, data, rootUrl, onProgress, fileName);
|
464
471
|
});
|
465
472
|
};
|
466
473
|
/** @hidden */
|
@@ -488,36 +495,16 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
488
495
|
var materials = [];
|
489
496
|
_this.onMaterialLoadedObservable.add(function (material) {
|
490
497
|
materials.push(material);
|
491
|
-
material.onDisposeObservable.addOnce(function () {
|
492
|
-
var index = container.materials.indexOf(material);
|
493
|
-
if (index > -1) {
|
494
|
-
container.materials.splice(index, 1);
|
495
|
-
}
|
496
|
-
index = materials.indexOf(material);
|
497
|
-
if (index > -1) {
|
498
|
-
materials.splice(index, 1);
|
499
|
-
}
|
500
|
-
});
|
501
498
|
});
|
502
499
|
var textures = [];
|
503
500
|
_this.onTextureLoadedObservable.add(function (texture) {
|
504
501
|
textures.push(texture);
|
505
|
-
texture.onDisposeObservable.addOnce(function () {
|
506
|
-
var index = container.textures.indexOf(texture);
|
507
|
-
if (index > -1) {
|
508
|
-
container.textures.splice(index, 1);
|
509
|
-
}
|
510
|
-
index = textures.indexOf(texture);
|
511
|
-
if (index > -1) {
|
512
|
-
textures.splice(index, 1);
|
513
|
-
}
|
514
|
-
});
|
515
502
|
});
|
516
503
|
var cameras = [];
|
517
504
|
_this.onCameraLoadedObservable.add(function (camera) {
|
518
505
|
cameras.push(camera);
|
519
506
|
});
|
520
|
-
return _this._loader.importMeshAsync(null, scene,
|
507
|
+
return _this._loader.importMeshAsync(null, scene, container, data, rootUrl, onProgress, fileName).then(function (result) {
|
521
508
|
Array.prototype.push.apply(container.geometries, result.geometries);
|
522
509
|
Array.prototype.push.apply(container.meshes, result.meshes);
|
523
510
|
Array.prototype.push.apply(container.particleSystems, result.particleSystems);
|
@@ -535,20 +522,22 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
535
522
|
/** @hidden */
|
536
523
|
GLTFFileLoader.prototype.canDirectLoad = function (data) {
|
537
524
|
return (data.indexOf("asset") !== -1 && data.indexOf("version") !== -1)
|
538
|
-
|| StringTools.StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded)
|
525
|
+
|| StringTools.StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded) // this is technically incorrect, but will continue to support for backcompat.
|
526
|
+
|| StringTools.StartsWith(data, "data:;base64," + GLTFFileLoader.magicBase64Encoded)
|
539
527
|
|| StringTools.StartsWith(data, "data:application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded)
|
540
528
|
|| StringTools.StartsWith(data, "data:model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded);
|
541
529
|
};
|
542
530
|
/** @hidden */
|
543
531
|
GLTFFileLoader.prototype.directLoad = function (scene, data) {
|
544
|
-
if (StringTools.StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) ||
|
532
|
+
if (StringTools.StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) || // this is technically incorrect, but will continue to support for backcompat.
|
533
|
+
StringTools.StartsWith(data, ";base64," + GLTFFileLoader.magicBase64Encoded) ||
|
545
534
|
StringTools.StartsWith(data, "application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded) ||
|
546
535
|
StringTools.StartsWith(data, "model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded)) {
|
547
|
-
var
|
548
|
-
this._validate(scene,
|
536
|
+
var arrayBuffer_1 = DecodeBase64UrlToBinary(data);
|
537
|
+
this._validate(scene, arrayBuffer_1);
|
549
538
|
return this._unpackBinaryAsync(new DataReader({
|
550
|
-
readAsync: function (byteOffset, byteLength) { return
|
551
|
-
byteLength:
|
539
|
+
readAsync: function (byteOffset, byteLength) { return readAsync(arrayBuffer_1, byteOffset, byteLength); },
|
540
|
+
byteLength: arrayBuffer_1.byteLength
|
552
541
|
}));
|
553
542
|
}
|
554
543
|
this._validate(scene, data);
|
@@ -563,7 +552,7 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
563
552
|
* The loader state or null if the loader is not active.
|
564
553
|
*/
|
565
554
|
get: function () {
|
566
|
-
return this.
|
555
|
+
return this._state;
|
567
556
|
},
|
568
557
|
enumerable: false,
|
569
558
|
configurable: true
|
@@ -584,23 +573,20 @@ var GLTFFileLoader = /** @class */ (function () {
|
|
584
573
|
});
|
585
574
|
};
|
586
575
|
/** @hidden */
|
587
|
-
GLTFFileLoader.prototype.
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
});
|
595
|
-
this._requests.push(request);
|
596
|
-
return request;
|
576
|
+
GLTFFileLoader.prototype._setState = function (state) {
|
577
|
+
if (this._state === state) {
|
578
|
+
return;
|
579
|
+
}
|
580
|
+
this._state = state;
|
581
|
+
this.onLoaderStateChangedObservable.notifyObservers(this._state);
|
582
|
+
this._log(GLTFLoaderState[this._state]);
|
597
583
|
};
|
598
584
|
/** @hidden */
|
599
|
-
GLTFFileLoader.prototype.
|
585
|
+
GLTFFileLoader.prototype._loadFile = function (scene, fileOrUrl, onSuccess, useArrayBuffer, onError, onOpened) {
|
600
586
|
var _this = this;
|
601
|
-
var request = scene.
|
587
|
+
var request = scene._loadFile(fileOrUrl, onSuccess, function (event) {
|
602
588
|
_this._onProgress(event, request);
|
603
|
-
},
|
589
|
+
}, true, useArrayBuffer, onError, onOpened);
|
604
590
|
request.onCompleteObservable.add(function (request) {
|
605
591
|
_this._requests.splice(_this._requests.indexOf(request), 1);
|
606
592
|
});
|