babylonjs.loaders.module.d.ts 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. /// <reference types="babylonjs"/>
  2. /// <reference types="babylonjs-gltf2interface"/>
  3. declare module 'babylonjs-loaders' {
  4. export = BABYLON;
  5. }
  6. declare module BABYLON {
  7. class STLFileLoader implements ISceneLoaderPlugin {
  8. solidPattern: RegExp;
  9. facetsPattern: RegExp;
  10. normalPattern: RegExp;
  11. vertexPattern: RegExp;
  12. name: string;
  13. extensions: ISceneLoaderPluginExtensions;
  14. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  15. load(scene: Scene, data: any, rootUrl: string): boolean;
  16. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  17. private isBinary(data);
  18. private parseBinary(mesh, data);
  19. private parseASCII(mesh, solidData);
  20. }
  21. }
  22. declare module BABYLON {
  23. /**
  24. * Class reading and parsing the MTL file bundled with the obj file.
  25. */
  26. class MTLFileLoader {
  27. materials: BABYLON.StandardMaterial[];
  28. /**
  29. * This function will read the mtl file and create each material described inside
  30. * This function could be improve by adding :
  31. * -some component missing (Ni, Tf...)
  32. * -including the specific options available
  33. *
  34. * @param scene
  35. * @param data
  36. * @param rootUrl
  37. */
  38. parseMTL(scene: BABYLON.Scene, data: string | ArrayBuffer, rootUrl: string): void;
  39. /**
  40. * Gets the texture for the material.
  41. *
  42. * If the material is imported from input file,
  43. * We sanitize the url to ensure it takes the textre from aside the material.
  44. *
  45. * @param rootUrl The root url to load from
  46. * @param value The value stored in the mtl
  47. * @return The Texture
  48. */
  49. private static _getTexture(rootUrl, value, scene);
  50. }
  51. class OBJFileLoader implements ISceneLoaderPlugin {
  52. static OPTIMIZE_WITH_UV: boolean;
  53. static INVERT_Y: boolean;
  54. name: string;
  55. extensions: string;
  56. obj: RegExp;
  57. group: RegExp;
  58. mtllib: RegExp;
  59. usemtl: RegExp;
  60. smooth: RegExp;
  61. vertexPattern: RegExp;
  62. normalPattern: RegExp;
  63. uvPattern: RegExp;
  64. facePattern1: RegExp;
  65. facePattern2: RegExp;
  66. facePattern3: RegExp;
  67. facePattern4: RegExp;
  68. /**
  69. * Calls synchronously the MTL file attached to this obj.
  70. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  71. * Without this function materials are not displayed in the first frame (but displayed after).
  72. * In consequence it is impossible to get material information in your HTML file
  73. *
  74. * @param url The URL of the MTL file
  75. * @param rootUrl
  76. * @param onSuccess Callback function to be called when the MTL file is loaded
  77. * @private
  78. */
  79. private _loadMTL(url, rootUrl, onSuccess);
  80. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  81. load(scene: Scene, data: string, rootUrl: string): boolean;
  82. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  83. /**
  84. * Read the OBJ file and create an Array of meshes.
  85. * Each mesh contains all information given by the OBJ and the MTL file.
  86. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  87. *
  88. * @param meshesNames
  89. * @param scene BABYLON.Scene The scene where are displayed the data
  90. * @param data String The content of the obj file
  91. * @param rootUrl String The path to the folder
  92. * @returns Array<AbstractMesh>
  93. * @private
  94. */
  95. private _parseSolid(meshesNames, scene, data, rootUrl);
  96. }
  97. }
  98. declare module BABYLON {
  99. /**
  100. * Mode that determines the coordinate system to use.
  101. */
  102. enum GLTFLoaderCoordinateSystemMode {
  103. /**
  104. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  105. */
  106. AUTO = 0,
  107. /**
  108. * Sets the useRightHandedSystem flag on the scene.
  109. */
  110. FORCE_RIGHT_HANDED = 1,
  111. }
  112. /**
  113. * Mode that determines what animations will start.
  114. */
  115. enum GLTFLoaderAnimationStartMode {
  116. /**
  117. * No animation will start.
  118. */
  119. NONE = 0,
  120. /**
  121. * The first animation will start.
  122. */
  123. FIRST = 1,
  124. /**
  125. * All animations will start.
  126. */
  127. ALL = 2,
  128. }
  129. /**
  130. * Interface that contains the data for the glTF asset.
  131. */
  132. interface IGLTFLoaderData {
  133. /**
  134. * JSON that represents the glTF.
  135. */
  136. json: Object;
  137. /**
  138. * The BIN chunk of a binary glTF
  139. */
  140. bin: Nullable<ArrayBufferView>;
  141. }
  142. /**
  143. * Interface for extending the loader.
  144. */
  145. interface IGLTFLoaderExtension {
  146. /**
  147. * The name of this extension.
  148. */
  149. readonly name: string;
  150. /**
  151. * Defines whether this extension is enabled.
  152. */
  153. enabled: boolean;
  154. }
  155. /**
  156. * Loader state.
  157. */
  158. enum GLTFLoaderState {
  159. /**
  160. * The asset is loading.
  161. */
  162. LOADING = 0,
  163. /**
  164. * The asset is ready for rendering.
  165. */
  166. READY = 1,
  167. /**
  168. * The asset is completely loaded.
  169. */
  170. COMPLETE = 2,
  171. }
  172. /** @hidden */
  173. interface IGLTFLoader extends IDisposable {
  174. readonly state: Nullable<GLTFLoaderState>;
  175. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  176. meshes: AbstractMesh[];
  177. particleSystems: ParticleSystem[];
  178. skeletons: Skeleton[];
  179. animationGroups: AnimationGroup[];
  180. }>;
  181. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  182. }
  183. /**
  184. * File loader for loading glTF files into a scene.
  185. */
  186. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  187. /** @hidden */
  188. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  189. /** @hidden */
  190. static _CreateGLTFLoaderV2: (parent: GLTFFileLoader) => IGLTFLoader;
  191. /**
  192. * Raised when the asset has been parsed
  193. */
  194. onParsedObservable: Observable<IGLTFLoaderData>;
  195. private _onParsedObserver;
  196. /**
  197. * Raised when the asset has been parsed
  198. */
  199. onParsed: (loaderData: IGLTFLoaderData) => void;
  200. /**
  201. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  202. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  203. * Defaults to true.
  204. * @hidden
  205. */
  206. static IncrementalLoading: boolean;
  207. /**
  208. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  209. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  210. * @hidden
  211. */
  212. static HomogeneousCoordinates: boolean;
  213. /**
  214. * The coordinate system mode. Defaults to AUTO.
  215. */
  216. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  217. /**
  218. * The animation start mode. Defaults to FIRST.
  219. */
  220. animationStartMode: GLTFLoaderAnimationStartMode;
  221. /**
  222. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  223. */
  224. compileMaterials: boolean;
  225. /**
  226. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  227. */
  228. useClipPlane: boolean;
  229. /**
  230. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  231. */
  232. compileShadowGenerators: boolean;
  233. /**
  234. * Defines if the Alpha blended materials are only applied as coverage.
  235. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  236. * If true, no extra effects are applied to transparent pixels.
  237. */
  238. transparencyAsCoverage: boolean;
  239. /** @hidden */
  240. _normalizeAnimationGroupsToBeginAtZero: boolean;
  241. /**
  242. * Defines if the loader logging is enabled.
  243. */
  244. loggingEnabled: boolean;
  245. /**
  246. * Observable raised when the loader logs a message.
  247. */
  248. readonly onLogObservable: Observable<string>;
  249. private _logIndentLevel;
  250. private static readonly _logSpaces;
  251. /** @hidden */
  252. _log(message: string): void;
  253. /** @hidden */
  254. _logOpen(message: string): void;
  255. /** @hidden */
  256. _logClose(): void;
  257. /**
  258. * Function called before loading a url referenced by the asset.
  259. */
  260. preprocessUrlAsync: (url: string) => Promise<string>;
  261. /**
  262. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  263. */
  264. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  265. private _onMeshLoadedObserver;
  266. /**
  267. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  268. */
  269. onMeshLoaded: (mesh: AbstractMesh) => void;
  270. /**
  271. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  272. */
  273. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  274. private _onTextureLoadedObserver;
  275. /**
  276. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  277. */
  278. onTextureLoaded: (texture: BaseTexture) => void;
  279. /**
  280. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  281. */
  282. readonly onMaterialLoadedObservable: Observable<Material>;
  283. private _onMaterialLoadedObserver;
  284. /**
  285. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  286. */
  287. onMaterialLoaded: (material: Material) => void;
  288. /**
  289. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  290. */
  291. readonly onCameraLoadedObservable: Observable<Camera>;
  292. private _onCameraLoadedObserver;
  293. /**
  294. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  295. */
  296. onCameraLoaded: (camera: Camera) => void;
  297. /**
  298. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  299. * For assets with LODs, raised when all of the LODs are complete.
  300. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  301. */
  302. readonly onCompleteObservable: Observable<void>;
  303. private _onCompleteObserver;
  304. /**
  305. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  306. */
  307. onComplete: () => void;
  308. /**
  309. * Observable raised after the loader is disposed.
  310. */
  311. readonly onDisposeObservable: Observable<void>;
  312. private _onDisposeObserver;
  313. /**
  314. * Callback raised after the loader is disposed.
  315. */
  316. onDispose: () => void;
  317. /**
  318. * Observable raised after a loader extension is created.
  319. * Set additional options for a loader extension in this event.
  320. */
  321. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  322. private _onExtensionLoadedObserver;
  323. /**
  324. * Callback raised after a loader extension is created.
  325. */
  326. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  327. /**
  328. * Returns a promise that resolves when the asset is completely loaded.
  329. * @returns a promise that resolves when the asset is completely loaded.
  330. */
  331. whenCompleteAsync(): Promise<void>;
  332. /**
  333. * The loader state or null if the loader is not active.
  334. */
  335. readonly loaderState: Nullable<GLTFLoaderState>;
  336. private _loader;
  337. /**
  338. * Name of the loader ("gltf")
  339. */
  340. name: string;
  341. /**
  342. * Supported file extensions of the loader (.gltf, .glb)
  343. */
  344. extensions: ISceneLoaderPluginExtensions;
  345. /**
  346. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  347. */
  348. dispose(): void;
  349. /** @hidden */
  350. _clear(): void;
  351. /**
  352. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  353. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  354. * @param scene the scene the meshes should be added to
  355. * @param data the glTF data to load
  356. * @param rootUrl root url to load from
  357. * @param onProgress event that fires when loading progress has occured
  358. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  359. */
  360. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  361. meshes: AbstractMesh[];
  362. particleSystems: ParticleSystem[];
  363. skeletons: Skeleton[];
  364. animationGroups: AnimationGroup[];
  365. }>;
  366. /**
  367. * Imports all objects from the loaded glTF data and adds them to the scene
  368. * @param scene the scene the objects should be added to
  369. * @param data the glTF data to load
  370. * @param rootUrl root url to load from
  371. * @param onProgress event that fires when loading progress has occured
  372. * @returns a promise which completes when objects have been loaded to the scene
  373. */
  374. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  375. /**
  376. * Load into an asset container.
  377. * @param scene The scene to load into
  378. * @param data The data to import
  379. * @param rootUrl The root url for scene and resources
  380. * @param onProgress The callback when the load progresses
  381. * @returns The loaded asset container
  382. */
  383. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  384. /**
  385. * If the data string can be loaded directly.
  386. * @param data string contianing the file data
  387. * @returns if the data can be loaded directly
  388. */
  389. canDirectLoad(data: string): boolean;
  390. /**
  391. * Rewrites a url by combining a root url and response url.
  392. */
  393. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  394. /**
  395. * Instantiates a glTF file loader plugin.
  396. * @returns the created plugin
  397. */
  398. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  399. private _parse(data);
  400. private _getLoader(loaderData);
  401. private _parseBinary(data);
  402. private _parseV1(binaryReader);
  403. private _parseV2(binaryReader);
  404. private static _parseVersion(version);
  405. private static _compareVersion(a, b);
  406. private static _decodeBufferToText(buffer);
  407. }
  408. }
  409. declare module BABYLON.GLTF1 {
  410. /**
  411. * Enums
  412. */
  413. enum EComponentType {
  414. BYTE = 5120,
  415. UNSIGNED_BYTE = 5121,
  416. SHORT = 5122,
  417. UNSIGNED_SHORT = 5123,
  418. FLOAT = 5126,
  419. }
  420. enum EShaderType {
  421. FRAGMENT = 35632,
  422. VERTEX = 35633,
  423. }
  424. enum EParameterType {
  425. BYTE = 5120,
  426. UNSIGNED_BYTE = 5121,
  427. SHORT = 5122,
  428. UNSIGNED_SHORT = 5123,
  429. INT = 5124,
  430. UNSIGNED_INT = 5125,
  431. FLOAT = 5126,
  432. FLOAT_VEC2 = 35664,
  433. FLOAT_VEC3 = 35665,
  434. FLOAT_VEC4 = 35666,
  435. INT_VEC2 = 35667,
  436. INT_VEC3 = 35668,
  437. INT_VEC4 = 35669,
  438. BOOL = 35670,
  439. BOOL_VEC2 = 35671,
  440. BOOL_VEC3 = 35672,
  441. BOOL_VEC4 = 35673,
  442. FLOAT_MAT2 = 35674,
  443. FLOAT_MAT3 = 35675,
  444. FLOAT_MAT4 = 35676,
  445. SAMPLER_2D = 35678,
  446. }
  447. enum ETextureWrapMode {
  448. CLAMP_TO_EDGE = 33071,
  449. MIRRORED_REPEAT = 33648,
  450. REPEAT = 10497,
  451. }
  452. enum ETextureFilterType {
  453. NEAREST = 9728,
  454. LINEAR = 9728,
  455. NEAREST_MIPMAP_NEAREST = 9984,
  456. LINEAR_MIPMAP_NEAREST = 9985,
  457. NEAREST_MIPMAP_LINEAR = 9986,
  458. LINEAR_MIPMAP_LINEAR = 9987,
  459. }
  460. enum ETextureFormat {
  461. ALPHA = 6406,
  462. RGB = 6407,
  463. RGBA = 6408,
  464. LUMINANCE = 6409,
  465. LUMINANCE_ALPHA = 6410,
  466. }
  467. enum ECullingType {
  468. FRONT = 1028,
  469. BACK = 1029,
  470. FRONT_AND_BACK = 1032,
  471. }
  472. enum EBlendingFunction {
  473. ZERO = 0,
  474. ONE = 1,
  475. SRC_COLOR = 768,
  476. ONE_MINUS_SRC_COLOR = 769,
  477. DST_COLOR = 774,
  478. ONE_MINUS_DST_COLOR = 775,
  479. SRC_ALPHA = 770,
  480. ONE_MINUS_SRC_ALPHA = 771,
  481. DST_ALPHA = 772,
  482. ONE_MINUS_DST_ALPHA = 773,
  483. CONSTANT_COLOR = 32769,
  484. ONE_MINUS_CONSTANT_COLOR = 32770,
  485. CONSTANT_ALPHA = 32771,
  486. ONE_MINUS_CONSTANT_ALPHA = 32772,
  487. SRC_ALPHA_SATURATE = 776,
  488. }
  489. /**
  490. * Interfaces
  491. */
  492. interface IGLTFProperty {
  493. extensions?: {
  494. [key: string]: any;
  495. };
  496. extras?: Object;
  497. }
  498. interface IGLTFChildRootProperty extends IGLTFProperty {
  499. name?: string;
  500. }
  501. interface IGLTFAccessor extends IGLTFChildRootProperty {
  502. bufferView: string;
  503. byteOffset: number;
  504. byteStride: number;
  505. count: number;
  506. type: string;
  507. componentType: EComponentType;
  508. max?: number[];
  509. min?: number[];
  510. name?: string;
  511. }
  512. interface IGLTFBufferView extends IGLTFChildRootProperty {
  513. buffer: string;
  514. byteOffset: number;
  515. byteLength: number;
  516. byteStride: number;
  517. target?: number;
  518. }
  519. interface IGLTFBuffer extends IGLTFChildRootProperty {
  520. uri: string;
  521. byteLength?: number;
  522. type?: string;
  523. }
  524. interface IGLTFShader extends IGLTFChildRootProperty {
  525. uri: string;
  526. type: EShaderType;
  527. }
  528. interface IGLTFProgram extends IGLTFChildRootProperty {
  529. attributes: string[];
  530. fragmentShader: string;
  531. vertexShader: string;
  532. }
  533. interface IGLTFTechniqueParameter {
  534. type: number;
  535. count?: number;
  536. semantic?: string;
  537. node?: string;
  538. value?: number | boolean | string | Array<any>;
  539. source?: string;
  540. babylonValue?: any;
  541. }
  542. interface IGLTFTechniqueCommonProfile {
  543. lightingModel: string;
  544. texcoordBindings: Object;
  545. parameters?: Array<any>;
  546. }
  547. interface IGLTFTechniqueStatesFunctions {
  548. blendColor?: number[];
  549. blendEquationSeparate?: number[];
  550. blendFuncSeparate?: number[];
  551. colorMask: boolean[];
  552. cullFace: number[];
  553. }
  554. interface IGLTFTechniqueStates {
  555. enable: number[];
  556. functions: IGLTFTechniqueStatesFunctions;
  557. }
  558. interface IGLTFTechnique extends IGLTFChildRootProperty {
  559. parameters: {
  560. [key: string]: IGLTFTechniqueParameter;
  561. };
  562. program: string;
  563. attributes: {
  564. [key: string]: string;
  565. };
  566. uniforms: {
  567. [key: string]: string;
  568. };
  569. states: IGLTFTechniqueStates;
  570. }
  571. interface IGLTFMaterial extends IGLTFChildRootProperty {
  572. technique?: string;
  573. values: string[];
  574. }
  575. interface IGLTFMeshPrimitive extends IGLTFProperty {
  576. attributes: {
  577. [key: string]: string;
  578. };
  579. indices: string;
  580. material: string;
  581. mode?: number;
  582. }
  583. interface IGLTFMesh extends IGLTFChildRootProperty {
  584. primitives: IGLTFMeshPrimitive[];
  585. }
  586. interface IGLTFImage extends IGLTFChildRootProperty {
  587. uri: string;
  588. }
  589. interface IGLTFSampler extends IGLTFChildRootProperty {
  590. magFilter?: number;
  591. minFilter?: number;
  592. wrapS?: number;
  593. wrapT?: number;
  594. }
  595. interface IGLTFTexture extends IGLTFChildRootProperty {
  596. sampler: string;
  597. source: string;
  598. format?: ETextureFormat;
  599. internalFormat?: ETextureFormat;
  600. target?: number;
  601. type?: number;
  602. babylonTexture?: Texture;
  603. }
  604. interface IGLTFAmbienLight {
  605. color?: number[];
  606. }
  607. interface IGLTFDirectionalLight {
  608. color?: number[];
  609. }
  610. interface IGLTFPointLight {
  611. color?: number[];
  612. constantAttenuation?: number;
  613. linearAttenuation?: number;
  614. quadraticAttenuation?: number;
  615. }
  616. interface IGLTFSpotLight {
  617. color?: number[];
  618. constantAttenuation?: number;
  619. fallOfAngle?: number;
  620. fallOffExponent?: number;
  621. linearAttenuation?: number;
  622. quadraticAttenuation?: number;
  623. }
  624. interface IGLTFLight extends IGLTFChildRootProperty {
  625. type: string;
  626. }
  627. interface IGLTFCameraOrthographic {
  628. xmag: number;
  629. ymag: number;
  630. zfar: number;
  631. znear: number;
  632. }
  633. interface IGLTFCameraPerspective {
  634. aspectRatio: number;
  635. yfov: number;
  636. zfar: number;
  637. znear: number;
  638. }
  639. interface IGLTFCamera extends IGLTFChildRootProperty {
  640. type: string;
  641. }
  642. interface IGLTFAnimationChannelTarget {
  643. id: string;
  644. path: string;
  645. }
  646. interface IGLTFAnimationChannel {
  647. sampler: string;
  648. target: IGLTFAnimationChannelTarget;
  649. }
  650. interface IGLTFAnimationSampler {
  651. input: string;
  652. output: string;
  653. interpolation?: string;
  654. }
  655. interface IGLTFAnimation extends IGLTFChildRootProperty {
  656. channels?: IGLTFAnimationChannel[];
  657. parameters?: {
  658. [key: string]: string;
  659. };
  660. samplers?: {
  661. [key: string]: IGLTFAnimationSampler;
  662. };
  663. }
  664. interface IGLTFNodeInstanceSkin {
  665. skeletons: string[];
  666. skin: string;
  667. meshes: string[];
  668. }
  669. interface IGLTFSkins extends IGLTFChildRootProperty {
  670. bindShapeMatrix: number[];
  671. inverseBindMatrices: string;
  672. jointNames: string[];
  673. babylonSkeleton?: Skeleton;
  674. }
  675. interface IGLTFNode extends IGLTFChildRootProperty {
  676. camera?: string;
  677. children: string[];
  678. skin?: string;
  679. jointName?: string;
  680. light?: string;
  681. matrix: number[];
  682. mesh?: string;
  683. meshes?: string[];
  684. rotation?: number[];
  685. scale?: number[];
  686. translation?: number[];
  687. babylonNode?: Node;
  688. }
  689. interface IGLTFScene extends IGLTFChildRootProperty {
  690. nodes: string[];
  691. }
  692. /**
  693. * Runtime
  694. */
  695. interface IGLTFRuntime {
  696. extensions: {
  697. [key: string]: any;
  698. };
  699. accessors: {
  700. [key: string]: IGLTFAccessor;
  701. };
  702. buffers: {
  703. [key: string]: IGLTFBuffer;
  704. };
  705. bufferViews: {
  706. [key: string]: IGLTFBufferView;
  707. };
  708. meshes: {
  709. [key: string]: IGLTFMesh;
  710. };
  711. lights: {
  712. [key: string]: IGLTFLight;
  713. };
  714. cameras: {
  715. [key: string]: IGLTFCamera;
  716. };
  717. nodes: {
  718. [key: string]: IGLTFNode;
  719. };
  720. images: {
  721. [key: string]: IGLTFImage;
  722. };
  723. textures: {
  724. [key: string]: IGLTFTexture;
  725. };
  726. shaders: {
  727. [key: string]: IGLTFShader;
  728. };
  729. programs: {
  730. [key: string]: IGLTFProgram;
  731. };
  732. samplers: {
  733. [key: string]: IGLTFSampler;
  734. };
  735. techniques: {
  736. [key: string]: IGLTFTechnique;
  737. };
  738. materials: {
  739. [key: string]: IGLTFMaterial;
  740. };
  741. animations: {
  742. [key: string]: IGLTFAnimation;
  743. };
  744. skins: {
  745. [key: string]: IGLTFSkins;
  746. };
  747. currentScene?: Object;
  748. scenes: {
  749. [key: string]: IGLTFScene;
  750. };
  751. extensionsUsed: string[];
  752. extensionsRequired?: string[];
  753. buffersCount: number;
  754. shaderscount: number;
  755. scene: Scene;
  756. rootUrl: string;
  757. loadedBufferCount: number;
  758. loadedBufferViews: {
  759. [name: string]: ArrayBufferView;
  760. };
  761. loadedShaderCount: number;
  762. importOnlyMeshes: boolean;
  763. importMeshesNames?: string[];
  764. dummyNodes: Node[];
  765. }
  766. /**
  767. * Bones
  768. */
  769. interface INodeToRoot {
  770. bone: Bone;
  771. node: IGLTFNode;
  772. id: string;
  773. }
  774. interface IJointNode {
  775. node: IGLTFNode;
  776. id: string;
  777. }
  778. }
  779. declare module BABYLON.GLTF1 {
  780. /**
  781. * Implementation of the base glTF spec
  782. */
  783. class GLTFLoaderBase {
  784. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  785. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  786. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  787. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  788. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  789. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  790. }
  791. /**
  792. * glTF V1 Loader
  793. */
  794. class GLTFLoader implements IGLTFLoader {
  795. static Extensions: {
  796. [name: string]: GLTFLoaderExtension;
  797. };
  798. static RegisterExtension(extension: GLTFLoaderExtension): void;
  799. state: Nullable<GLTFLoaderState>;
  800. dispose(): void;
  801. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  802. /**
  803. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  804. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  805. * @param scene the scene the meshes should be added to
  806. * @param data gltf data containing information of the meshes in a loaded file
  807. * @param rootUrl root url to load from
  808. * @param onProgress event that fires when loading progress has occured
  809. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  810. */
  811. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  812. meshes: AbstractMesh[];
  813. particleSystems: ParticleSystem[];
  814. skeletons: Skeleton[];
  815. animationGroups: AnimationGroup[];
  816. }>;
  817. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  818. /**
  819. * Imports all objects from a loaded gltf file and adds them to the scene
  820. * @param scene the scene the objects should be added to
  821. * @param data gltf data containing information of the meshes in a loaded file
  822. * @param rootUrl root url to load from
  823. * @param onProgress event that fires when loading progress has occured
  824. * @returns a promise which completes when objects have been loaded to the scene
  825. */
  826. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  827. private _loadShadersAsync(gltfRuntime, onload);
  828. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  829. private _createNodes(gltfRuntime);
  830. }
  831. }
  832. declare module BABYLON.GLTF1 {
  833. /**
  834. * Utils functions for GLTF
  835. */
  836. class GLTFUtils {
  837. /**
  838. * Sets the given "parameter" matrix
  839. * @param scene: the {BABYLON.Scene} object
  840. * @param source: the source node where to pick the matrix
  841. * @param parameter: the GLTF technique parameter
  842. * @param uniformName: the name of the shader's uniform
  843. * @param shaderMaterial: the shader material
  844. */
  845. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  846. /**
  847. * Sets the given "parameter" matrix
  848. * @param shaderMaterial: the shader material
  849. * @param uniform: the name of the shader's uniform
  850. * @param value: the value of the uniform
  851. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  852. */
  853. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  854. /**
  855. * Returns the wrap mode of the texture
  856. * @param mode: the mode value
  857. */
  858. static GetWrapMode(mode: number): number;
  859. /**
  860. * Returns the byte stride giving an accessor
  861. * @param accessor: the GLTF accessor objet
  862. */
  863. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  864. /**
  865. * Returns the texture filter mode giving a mode value
  866. * @param mode: the filter mode value
  867. */
  868. static GetTextureFilterMode(mode: number): ETextureFilterType;
  869. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  870. /**
  871. * Returns a buffer from its accessor
  872. * @param gltfRuntime: the GLTF runtime
  873. * @param accessor: the GLTF accessor
  874. */
  875. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  876. /**
  877. * Decodes a buffer view into a string
  878. * @param view: the buffer view
  879. */
  880. static DecodeBufferToText(view: ArrayBufferView): string;
  881. /**
  882. * Returns the default material of gltf. Related to
  883. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  884. * @param scene: the Babylon.js scene
  885. */
  886. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  887. private static _DefaultMaterial;
  888. }
  889. }
  890. declare module BABYLON.GLTF1 {
  891. abstract class GLTFLoaderExtension {
  892. private _name;
  893. constructor(name: string);
  894. readonly name: string;
  895. /**
  896. * Defines an override for loading the runtime
  897. * Return true to stop further extensions from loading the runtime
  898. */
  899. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  900. /**
  901. * Defines an onverride for creating gltf runtime
  902. * Return true to stop further extensions from creating the runtime
  903. */
  904. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  905. /**
  906. * Defines an override for loading buffers
  907. * Return true to stop further extensions from loading this buffer
  908. */
  909. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  910. /**
  911. * Defines an override for loading texture buffers
  912. * Return true to stop further extensions from loading this texture data
  913. */
  914. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  915. /**
  916. * Defines an override for creating textures
  917. * Return true to stop further extensions from loading this texture
  918. */
  919. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  920. /**
  921. * Defines an override for loading shader strings
  922. * Return true to stop further extensions from loading this shader data
  923. */
  924. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  925. /**
  926. * Defines an override for loading materials
  927. * Return true to stop further extensions from loading this material
  928. */
  929. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  930. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  931. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  932. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  933. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  934. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  935. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  936. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  937. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  938. private static ApplyExtensions(func, defaultFunc);
  939. }
  940. }
  941. declare module BABYLON.GLTF1 {
  942. class GLTFBinaryExtension extends GLTFLoaderExtension {
  943. private _bin;
  944. constructor();
  945. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  946. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  947. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  948. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  949. }
  950. }
  951. declare module BABYLON.GLTF1 {
  952. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  953. constructor();
  954. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  955. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  956. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  957. }
  958. }
  959. declare module BABYLON.GLTF2 {
  960. /** @hidden */
  961. interface _IArrayItem {
  962. _index: number;
  963. }
  964. /** @hidden */
  965. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  966. _data?: Promise<ArrayBufferView>;
  967. _babylonVertexBuffer?: Promise<VertexBuffer>;
  968. }
  969. /** @hidden */
  970. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  971. }
  972. /** @hidden */
  973. interface _ILoaderAnimationSamplerData {
  974. input: Float32Array;
  975. interpolation: AnimationSamplerInterpolation;
  976. output: Float32Array;
  977. }
  978. /** @hidden */
  979. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  980. _data?: Promise<_ILoaderAnimationSamplerData>;
  981. }
  982. /** @hidden */
  983. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  984. channels: _ILoaderAnimationChannel[];
  985. samplers: _ILoaderAnimationSampler[];
  986. _babylonAnimationGroup?: AnimationGroup;
  987. }
  988. /** @hidden */
  989. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  990. _data?: Promise<ArrayBufferView>;
  991. }
  992. /** @hidden */
  993. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  994. _data?: Promise<ArrayBufferView>;
  995. _babylonBuffer?: Promise<Buffer>;
  996. }
  997. /** @hidden */
  998. interface _ILoaderCamera extends ICamera, _IArrayItem {
  999. }
  1000. /** @hidden */
  1001. interface _ILoaderImage extends IImage, _IArrayItem {
  1002. _blob?: Promise<Blob>;
  1003. }
  1004. /** @hidden */
  1005. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1006. _babylonData?: {
  1007. [drawMode: number]: {
  1008. material: Material;
  1009. meshes: AbstractMesh[];
  1010. loaded: Promise<void>;
  1011. };
  1012. };
  1013. }
  1014. /** @hidden */
  1015. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1016. primitives: _ILoaderMeshPrimitive[];
  1017. }
  1018. /** @hidden */
  1019. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1020. }
  1021. /** @hidden */
  1022. interface _ILoaderNode extends INode, _IArrayItem {
  1023. _parent?: _ILoaderNode;
  1024. _babylonMesh?: Mesh;
  1025. _primitiveBabylonMeshes?: Mesh[];
  1026. _babylonBones?: Bone[];
  1027. _numMorphTargets?: number;
  1028. }
  1029. /** @hidden */
  1030. interface _ILoaderSamplerData {
  1031. noMipMaps: boolean;
  1032. samplingMode: number;
  1033. wrapU: number;
  1034. wrapV: number;
  1035. }
  1036. /** @hidden */
  1037. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1038. _data?: _ILoaderSamplerData;
  1039. }
  1040. /** @hidden */
  1041. interface _ILoaderScene extends IScene, _IArrayItem {
  1042. }
  1043. /** @hidden */
  1044. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1045. _babylonSkeleton?: Skeleton;
  1046. _loaded?: Promise<void>;
  1047. }
  1048. /** @hidden */
  1049. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1050. }
  1051. /** @hidden */
  1052. interface _ILoaderGLTF extends IGLTF {
  1053. accessors?: _ILoaderAccessor[];
  1054. animations?: _ILoaderAnimation[];
  1055. buffers?: _ILoaderBuffer[];
  1056. bufferViews?: _ILoaderBufferView[];
  1057. cameras?: _ILoaderCamera[];
  1058. images?: _ILoaderImage[];
  1059. materials?: _ILoaderMaterial[];
  1060. meshes?: _ILoaderMesh[];
  1061. nodes?: _ILoaderNode[];
  1062. samplers?: _ILoaderSampler[];
  1063. scenes?: _ILoaderScene[];
  1064. skins?: _ILoaderSkin[];
  1065. textures?: _ILoaderTexture[];
  1066. }
  1067. }
  1068. /**
  1069. * Defines the module used to import/export glTF 2.0 assets
  1070. */
  1071. declare module BABYLON.GLTF2 {
  1072. /** @hidden */
  1073. class GLTFLoader implements IGLTFLoader {
  1074. _parent: GLTFFileLoader;
  1075. _gltf: _ILoaderGLTF;
  1076. _babylonScene: Scene;
  1077. _completePromises: Promise<void>[];
  1078. _onReadyObservable: Observable<IGLTFLoader>;
  1079. private _disposed;
  1080. private _state;
  1081. private _extensions;
  1082. private _rootUrl;
  1083. private _rootBabylonMesh;
  1084. private _defaultSampler;
  1085. private _defaultBabylonMaterials;
  1086. private _progressCallback?;
  1087. private _requests;
  1088. private static _ExtensionNames;
  1089. private static _ExtensionFactories;
  1090. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1091. /**
  1092. * Loader state or null if the loader is not active.
  1093. */
  1094. readonly state: Nullable<GLTFLoaderState>;
  1095. constructor(parent: GLTFFileLoader);
  1096. dispose(): void;
  1097. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1098. meshes: AbstractMesh[];
  1099. particleSystems: ParticleSystem[];
  1100. skeletons: Skeleton[];
  1101. animationGroups: AnimationGroup[];
  1102. }>;
  1103. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1104. private _loadAsync(nodes);
  1105. private _loadData(data);
  1106. private _setupData();
  1107. private _loadExtensions();
  1108. private _checkExtensions();
  1109. private _createRootNode();
  1110. private _loadNodesAsync(nodes);
  1111. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1112. private _forEachPrimitive(node, callback);
  1113. private _getMeshes();
  1114. private _getSkeletons();
  1115. private _getAnimationGroups();
  1116. private _startAnimations();
  1117. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1118. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1119. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1120. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1121. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1122. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1123. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1124. private static _LoadTransform(node, babylonNode);
  1125. private _loadSkinAsync(context, node, mesh, skin);
  1126. private _loadBones(context, skin);
  1127. private _loadBone(node, skin, babylonBones);
  1128. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1129. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1130. private _getNodeMatrix(node);
  1131. private _loadCamera(context, camera, babylonMesh);
  1132. private _loadAnimationsAsync();
  1133. private _loadAnimationAsync(context, animation);
  1134. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1135. private _loadAnimationSamplerAsync(context, sampler);
  1136. private _loadBufferAsync(context, buffer);
  1137. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1138. private _loadIndicesAccessorAsync(context, accessor);
  1139. private _loadFloatAccessorAsync(context, accessor);
  1140. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1141. private _loadVertexAccessorAsync(context, accessor, kind);
  1142. private _getDefaultMaterial(drawMode);
  1143. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1144. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1145. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1146. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1147. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1148. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1149. private _loadSampler(context, sampler);
  1150. private _loadImageAsync(context, image);
  1151. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1152. private _onProgress();
  1153. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1154. private static _GetTextureWrapMode(context, mode);
  1155. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1156. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1157. private static _GetNumComponents(context, type);
  1158. private static _ValidateUri(uri);
  1159. private static _GetDrawMode(context, mode);
  1160. private _compileMaterialsAsync();
  1161. private _compileShadowGeneratorsAsync();
  1162. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1163. }
  1164. }
  1165. declare module BABYLON.GLTF2 {
  1166. /**
  1167. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1168. */
  1169. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1170. /**
  1171. * Gets or sets a boolean indicating if the extension is enabled
  1172. */
  1173. enabled: boolean;
  1174. /**
  1175. * Gets or sets extension name
  1176. */
  1177. readonly abstract name: string;
  1178. protected _loader: GLTFLoader;
  1179. /**
  1180. * Creates new GLTFLoaderExtension
  1181. * @param loader defines the GLTFLoader to use
  1182. */
  1183. constructor(loader: GLTFLoader);
  1184. /**
  1185. * Release all resources
  1186. */
  1187. dispose(): void;
  1188. /**
  1189. * Override this method to modify the default behavior for loading scenes.
  1190. * @hidden
  1191. */
  1192. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1193. /**
  1194. * Override this method to modify the default behavior for loading nodes.
  1195. * @hidden
  1196. */
  1197. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1198. /**
  1199. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1200. * @hidden
  1201. */
  1202. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1203. /**
  1204. * Override this method to modify the default behavior for loading materials.
  1205. * @hidden
  1206. */
  1207. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1208. /**
  1209. * Override this method to modify the default behavior for loading textures.
  1210. * @hidden
  1211. */
  1212. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1213. /**
  1214. * Override this method to modify the default behavior for loading uris.
  1215. * @hidden
  1216. */
  1217. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1218. /**
  1219. * Helper method called by a loader extension to load an glTF extension.
  1220. * @hidden
  1221. */
  1222. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1223. /**
  1224. * Helper method called by the loader to allow extensions to override loading scenes.
  1225. * @hidden
  1226. */
  1227. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1228. /**
  1229. * Helper method called by the loader to allow extensions to override loading scenes.
  1230. * @hidden
  1231. */
  1232. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1233. /**
  1234. * Helper method called by the loader to allow extensions to override loading nodes.
  1235. * @hidden
  1236. */
  1237. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1238. /**
  1239. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1240. * @hidden
  1241. */
  1242. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1243. /**
  1244. * Helper method called by the loader to allow extensions to override loading materials.
  1245. * @hidden
  1246. */
  1247. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1248. /**
  1249. * Helper method called by the loader to allow extensions to override loading textures.
  1250. * @hidden
  1251. */
  1252. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1253. /**
  1254. * Helper method called by the loader to allow extensions to override loading uris.
  1255. * @hidden
  1256. */
  1257. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1258. }
  1259. }
  1260. /**
  1261. * Defines the module of the glTF 2.0 loader extensions.
  1262. */
  1263. declare module BABYLON.GLTF2.Extensions {
  1264. }
  1265. declare module BABYLON.GLTF2.Extensions {
  1266. /**
  1267. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1268. */
  1269. class MSFT_lod extends GLTFLoaderExtension {
  1270. readonly name: string;
  1271. /**
  1272. * Maximum number of LODs to load, starting from the lowest LOD.
  1273. */
  1274. maxLODsToLoad: number;
  1275. /**
  1276. * Observable raised when all node LODs of one level are loaded.
  1277. * The event data is the index of the loaded LOD starting from zero.
  1278. * Dispose the loader to cancel the loading of the next level of LODs.
  1279. */
  1280. onNodeLODsLoadedObservable: Observable<number>;
  1281. /**
  1282. * Observable raised when all material LODs of one level are loaded.
  1283. * The event data is the index of the loaded LOD starting from zero.
  1284. * Dispose the loader to cancel the loading of the next level of LODs.
  1285. */
  1286. onMaterialLODsLoadedObservable: Observable<number>;
  1287. private _loadingNodeLOD;
  1288. private _loadNodeSignals;
  1289. private _loadNodePromises;
  1290. private _loadingMaterialLOD;
  1291. private _loadMaterialSignals;
  1292. private _loadMaterialPromises;
  1293. constructor(loader: GLTFLoader);
  1294. dispose(): void;
  1295. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1296. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1297. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1298. /**
  1299. * Gets an array of LOD properties from lowest to highest.
  1300. */
  1301. private _getLODs<T>(context, property, array, ids);
  1302. }
  1303. }
  1304. declare module BABYLON.GLTF2.Extensions {
  1305. /** @hidden */
  1306. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1307. readonly name: string;
  1308. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1309. }
  1310. }
  1311. declare module BABYLON.GLTF2.Extensions {
  1312. /** @hidden */
  1313. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1314. readonly name: string;
  1315. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1316. }
  1317. }
  1318. declare module BABYLON.GLTF2.Extensions {
  1319. /**
  1320. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1321. */
  1322. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1323. readonly name: string;
  1324. private _dracoCompression;
  1325. constructor(loader: GLTFLoader);
  1326. dispose(): void;
  1327. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1328. }
  1329. }
  1330. declare module BABYLON.GLTF2.Extensions {
  1331. /**
  1332. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1333. */
  1334. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1335. readonly name: string;
  1336. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1337. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1338. }
  1339. }
  1340. declare module BABYLON.GLTF2.Extensions {
  1341. /**
  1342. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1343. */
  1344. class KHR_materials_unlit extends GLTFLoaderExtension {
  1345. readonly name: string;
  1346. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1347. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1348. }
  1349. }
  1350. declare module BABYLON.GLTF2.Extensions {
  1351. /**
  1352. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1353. */
  1354. class KHR_lights extends GLTFLoaderExtension {
  1355. readonly name: string;
  1356. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1357. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1358. private readonly _lights;
  1359. }
  1360. }
  1361. declare module BABYLON.GLTF2.Extensions {
  1362. /**
  1363. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1364. */
  1365. class KHR_texture_transform extends GLTFLoaderExtension {
  1366. readonly name: string;
  1367. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1368. }
  1369. }