babylon.glTFFileLoader.d.ts 55 KB

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