babylon.glTFFileLoader.d.ts 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  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. /** @hidden */
  76. interface IGLTFLoader extends IDisposable {
  77. readonly state: Nullable<GLTFLoaderState>;
  78. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  79. meshes: AbstractMesh[];
  80. particleSystems: IParticleSystem[];
  81. skeletons: Skeleton[];
  82. animationGroups: AnimationGroup[];
  83. }>;
  84. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  85. }
  86. /**
  87. * File loader for loading glTF files into a scene.
  88. */
  89. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  90. /** @hidden */
  91. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  92. /** @hidden */
  93. static _CreateGLTFLoaderV2: (parent: GLTFFileLoader) => IGLTFLoader;
  94. /**
  95. * Raised when the asset has been parsed
  96. */
  97. onParsedObservable: Observable<IGLTFLoaderData>;
  98. private _onParsedObserver;
  99. /**
  100. * Raised when the asset has been parsed
  101. */
  102. onParsed: (loaderData: IGLTFLoaderData) => void;
  103. /**
  104. * 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.
  105. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  106. * Defaults to true.
  107. * @hidden
  108. */
  109. static IncrementalLoading: boolean;
  110. /**
  111. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  112. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  113. * @hidden
  114. */
  115. static HomogeneousCoordinates: boolean;
  116. /**
  117. * The coordinate system mode. Defaults to AUTO.
  118. */
  119. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  120. /**
  121. * The animation start mode. Defaults to FIRST.
  122. */
  123. animationStartMode: GLTFLoaderAnimationStartMode;
  124. /**
  125. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  126. */
  127. compileMaterials: boolean;
  128. /**
  129. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  130. */
  131. useClipPlane: boolean;
  132. /**
  133. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  134. */
  135. compileShadowGenerators: boolean;
  136. /**
  137. * Defines if the Alpha blended materials are only applied as coverage.
  138. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  139. * If true, no extra effects are applied to transparent pixels.
  140. */
  141. transparencyAsCoverage: boolean;
  142. /** @hidden */
  143. _normalizeAnimationGroupsToBeginAtZero: boolean;
  144. /**
  145. * Function called before loading a url referenced by the asset.
  146. */
  147. preprocessUrlAsync: (url: string) => Promise<string>;
  148. /**
  149. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  150. */
  151. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  152. private _onMeshLoadedObserver;
  153. /**
  154. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  155. */
  156. onMeshLoaded: (mesh: AbstractMesh) => void;
  157. /**
  158. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  159. */
  160. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  161. private _onTextureLoadedObserver;
  162. /**
  163. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  164. */
  165. onTextureLoaded: (texture: BaseTexture) => void;
  166. /**
  167. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  168. */
  169. readonly onMaterialLoadedObservable: Observable<Material>;
  170. private _onMaterialLoadedObserver;
  171. /**
  172. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  173. */
  174. onMaterialLoaded: (material: Material) => void;
  175. /**
  176. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  177. */
  178. readonly onCameraLoadedObservable: Observable<Camera>;
  179. private _onCameraLoadedObserver;
  180. /**
  181. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  182. */
  183. onCameraLoaded: (camera: Camera) => void;
  184. /**
  185. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  186. * For assets with LODs, raised when all of the LODs are complete.
  187. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  188. */
  189. readonly onCompleteObservable: Observable<void>;
  190. private _onCompleteObserver;
  191. /**
  192. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  193. * For assets with LODs, raised when all of the LODs are complete.
  194. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  195. */
  196. onComplete: () => void;
  197. /**
  198. * Observable raised when an error occurs.
  199. */
  200. readonly onErrorObservable: Observable<any>;
  201. private _onErrorObserver;
  202. /**
  203. * Callback raised when an error occurs.
  204. */
  205. onError: (reason: any) => void;
  206. /**
  207. * Observable raised after the loader is disposed.
  208. */
  209. readonly onDisposeObservable: Observable<void>;
  210. private _onDisposeObserver;
  211. /**
  212. * Callback raised after the loader is disposed.
  213. */
  214. onDispose: () => void;
  215. /**
  216. * Observable raised after a loader extension is created.
  217. * Set additional options for a loader extension in this event.
  218. */
  219. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  220. private _onExtensionLoadedObserver;
  221. /**
  222. * Callback raised after a loader extension is created.
  223. */
  224. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  225. /**
  226. * Returns a promise that resolves when the asset is completely loaded.
  227. * @returns a promise that resolves when the asset is completely loaded.
  228. */
  229. whenCompleteAsync(): Promise<void>;
  230. /**
  231. * The loader state or null if the loader is not active.
  232. */
  233. readonly loaderState: Nullable<GLTFLoaderState>;
  234. /**
  235. * Defines if the loader logging is enabled.
  236. */
  237. loggingEnabled: boolean;
  238. /**
  239. * Defines if the loader should capture performance counters.
  240. */
  241. capturePerformanceCounters: boolean;
  242. private _loader;
  243. /**
  244. * Name of the loader ("gltf")
  245. */
  246. name: string;
  247. /**
  248. * Supported file extensions of the loader (.gltf, .glb)
  249. */
  250. extensions: ISceneLoaderPluginExtensions;
  251. /**
  252. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  253. */
  254. dispose(): void;
  255. /** @hidden */
  256. _clear(): void;
  257. /**
  258. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  259. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  260. * @param scene the scene the meshes should be added to
  261. * @param data the glTF data to load
  262. * @param rootUrl root url to load from
  263. * @param onProgress event that fires when loading progress has occured
  264. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  265. */
  266. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  267. meshes: AbstractMesh[];
  268. particleSystems: IParticleSystem[];
  269. skeletons: Skeleton[];
  270. animationGroups: AnimationGroup[];
  271. }>;
  272. /**
  273. * Imports all objects from the loaded glTF data and adds them to the scene
  274. * @param scene the scene the objects should be added to
  275. * @param data the glTF data to load
  276. * @param rootUrl root url to load from
  277. * @param onProgress event that fires when loading progress has occured
  278. * @returns a promise which completes when objects have been loaded to the scene
  279. */
  280. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  281. /**
  282. * Load into an asset container.
  283. * @param scene The scene to load into
  284. * @param data The data to import
  285. * @param rootUrl The root url for scene and resources
  286. * @param onProgress The callback when the load progresses
  287. * @returns The loaded asset container
  288. */
  289. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  290. /**
  291. * If the data string can be loaded directly.
  292. * @param data string contianing the file data
  293. * @returns if the data can be loaded directly
  294. */
  295. canDirectLoad(data: string): boolean;
  296. /**
  297. * Rewrites a url by combining a root url and response url.
  298. */
  299. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  300. /**
  301. * Instantiates a glTF file loader plugin.
  302. * @returns the created plugin
  303. */
  304. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  305. private _parse;
  306. private _getLoader;
  307. private _parseBinary;
  308. private _parseV1;
  309. private _parseV2;
  310. private static _parseVersion;
  311. private static _compareVersion;
  312. private static _decodeBufferToText;
  313. private static readonly _logSpaces;
  314. private _logIndentLevel;
  315. private _loggingEnabled;
  316. /** @hidden */
  317. _log: (message: string) => void;
  318. /** @hidden */
  319. _logOpen(message: string): void;
  320. /** @hidden */
  321. _logClose(): void;
  322. private _logEnabled;
  323. private _logDisabled;
  324. private _capturePerformanceCounters;
  325. /** @hidden */
  326. _startPerformanceCounter: (counterName: string) => void;
  327. /** @hidden */
  328. _endPerformanceCounter: (counterName: string) => void;
  329. private _startPerformanceCounterEnabled;
  330. private _startPerformanceCounterDisabled;
  331. private _endPerformanceCounterEnabled;
  332. private _endPerformanceCounterDisabled;
  333. }
  334. }
  335. declare module BABYLON.GLTF1 {
  336. /**
  337. * Enums
  338. */
  339. enum EComponentType {
  340. BYTE = 5120,
  341. UNSIGNED_BYTE = 5121,
  342. SHORT = 5122,
  343. UNSIGNED_SHORT = 5123,
  344. FLOAT = 5126
  345. }
  346. enum EShaderType {
  347. FRAGMENT = 35632,
  348. VERTEX = 35633
  349. }
  350. enum EParameterType {
  351. BYTE = 5120,
  352. UNSIGNED_BYTE = 5121,
  353. SHORT = 5122,
  354. UNSIGNED_SHORT = 5123,
  355. INT = 5124,
  356. UNSIGNED_INT = 5125,
  357. FLOAT = 5126,
  358. FLOAT_VEC2 = 35664,
  359. FLOAT_VEC3 = 35665,
  360. FLOAT_VEC4 = 35666,
  361. INT_VEC2 = 35667,
  362. INT_VEC3 = 35668,
  363. INT_VEC4 = 35669,
  364. BOOL = 35670,
  365. BOOL_VEC2 = 35671,
  366. BOOL_VEC3 = 35672,
  367. BOOL_VEC4 = 35673,
  368. FLOAT_MAT2 = 35674,
  369. FLOAT_MAT3 = 35675,
  370. FLOAT_MAT4 = 35676,
  371. SAMPLER_2D = 35678
  372. }
  373. enum ETextureWrapMode {
  374. CLAMP_TO_EDGE = 33071,
  375. MIRRORED_REPEAT = 33648,
  376. REPEAT = 10497
  377. }
  378. enum ETextureFilterType {
  379. NEAREST = 9728,
  380. LINEAR = 9728,
  381. NEAREST_MIPMAP_NEAREST = 9984,
  382. LINEAR_MIPMAP_NEAREST = 9985,
  383. NEAREST_MIPMAP_LINEAR = 9986,
  384. LINEAR_MIPMAP_LINEAR = 9987
  385. }
  386. enum ETextureFormat {
  387. ALPHA = 6406,
  388. RGB = 6407,
  389. RGBA = 6408,
  390. LUMINANCE = 6409,
  391. LUMINANCE_ALPHA = 6410
  392. }
  393. enum ECullingType {
  394. FRONT = 1028,
  395. BACK = 1029,
  396. FRONT_AND_BACK = 1032
  397. }
  398. enum EBlendingFunction {
  399. ZERO = 0,
  400. ONE = 1,
  401. SRC_COLOR = 768,
  402. ONE_MINUS_SRC_COLOR = 769,
  403. DST_COLOR = 774,
  404. ONE_MINUS_DST_COLOR = 775,
  405. SRC_ALPHA = 770,
  406. ONE_MINUS_SRC_ALPHA = 771,
  407. DST_ALPHA = 772,
  408. ONE_MINUS_DST_ALPHA = 773,
  409. CONSTANT_COLOR = 32769,
  410. ONE_MINUS_CONSTANT_COLOR = 32770,
  411. CONSTANT_ALPHA = 32771,
  412. ONE_MINUS_CONSTANT_ALPHA = 32772,
  413. SRC_ALPHA_SATURATE = 776
  414. }
  415. /**
  416. * Interfaces
  417. */
  418. interface IGLTFProperty {
  419. extensions?: {
  420. [key: string]: any;
  421. };
  422. extras?: Object;
  423. }
  424. interface IGLTFChildRootProperty extends IGLTFProperty {
  425. name?: string;
  426. }
  427. interface IGLTFAccessor extends IGLTFChildRootProperty {
  428. bufferView: string;
  429. byteOffset: number;
  430. byteStride: number;
  431. count: number;
  432. type: string;
  433. componentType: EComponentType;
  434. max?: number[];
  435. min?: number[];
  436. name?: string;
  437. }
  438. interface IGLTFBufferView extends IGLTFChildRootProperty {
  439. buffer: string;
  440. byteOffset: number;
  441. byteLength: number;
  442. byteStride: number;
  443. target?: number;
  444. }
  445. interface IGLTFBuffer extends IGLTFChildRootProperty {
  446. uri: string;
  447. byteLength?: number;
  448. type?: string;
  449. }
  450. interface IGLTFShader extends IGLTFChildRootProperty {
  451. uri: string;
  452. type: EShaderType;
  453. }
  454. interface IGLTFProgram extends IGLTFChildRootProperty {
  455. attributes: string[];
  456. fragmentShader: string;
  457. vertexShader: string;
  458. }
  459. interface IGLTFTechniqueParameter {
  460. type: number;
  461. count?: number;
  462. semantic?: string;
  463. node?: string;
  464. value?: number | boolean | string | Array<any>;
  465. source?: string;
  466. babylonValue?: any;
  467. }
  468. interface IGLTFTechniqueCommonProfile {
  469. lightingModel: string;
  470. texcoordBindings: Object;
  471. parameters?: Array<any>;
  472. }
  473. interface IGLTFTechniqueStatesFunctions {
  474. blendColor?: number[];
  475. blendEquationSeparate?: number[];
  476. blendFuncSeparate?: number[];
  477. colorMask: boolean[];
  478. cullFace: number[];
  479. }
  480. interface IGLTFTechniqueStates {
  481. enable: number[];
  482. functions: IGLTFTechniqueStatesFunctions;
  483. }
  484. interface IGLTFTechnique extends IGLTFChildRootProperty {
  485. parameters: {
  486. [key: string]: IGLTFTechniqueParameter;
  487. };
  488. program: string;
  489. attributes: {
  490. [key: string]: string;
  491. };
  492. uniforms: {
  493. [key: string]: string;
  494. };
  495. states: IGLTFTechniqueStates;
  496. }
  497. interface IGLTFMaterial extends IGLTFChildRootProperty {
  498. technique?: string;
  499. values: string[];
  500. }
  501. interface IGLTFMeshPrimitive extends IGLTFProperty {
  502. attributes: {
  503. [key: string]: string;
  504. };
  505. indices: string;
  506. material: string;
  507. mode?: number;
  508. }
  509. interface IGLTFMesh extends IGLTFChildRootProperty {
  510. primitives: IGLTFMeshPrimitive[];
  511. }
  512. interface IGLTFImage extends IGLTFChildRootProperty {
  513. uri: string;
  514. }
  515. interface IGLTFSampler extends IGLTFChildRootProperty {
  516. magFilter?: number;
  517. minFilter?: number;
  518. wrapS?: number;
  519. wrapT?: number;
  520. }
  521. interface IGLTFTexture extends IGLTFChildRootProperty {
  522. sampler: string;
  523. source: string;
  524. format?: ETextureFormat;
  525. internalFormat?: ETextureFormat;
  526. target?: number;
  527. type?: number;
  528. babylonTexture?: Texture;
  529. }
  530. interface IGLTFAmbienLight {
  531. color?: number[];
  532. }
  533. interface IGLTFDirectionalLight {
  534. color?: number[];
  535. }
  536. interface IGLTFPointLight {
  537. color?: number[];
  538. constantAttenuation?: number;
  539. linearAttenuation?: number;
  540. quadraticAttenuation?: number;
  541. }
  542. interface IGLTFSpotLight {
  543. color?: number[];
  544. constantAttenuation?: number;
  545. fallOfAngle?: number;
  546. fallOffExponent?: number;
  547. linearAttenuation?: number;
  548. quadraticAttenuation?: number;
  549. }
  550. interface IGLTFLight extends IGLTFChildRootProperty {
  551. type: string;
  552. }
  553. interface IGLTFCameraOrthographic {
  554. xmag: number;
  555. ymag: number;
  556. zfar: number;
  557. znear: number;
  558. }
  559. interface IGLTFCameraPerspective {
  560. aspectRatio: number;
  561. yfov: number;
  562. zfar: number;
  563. znear: number;
  564. }
  565. interface IGLTFCamera extends IGLTFChildRootProperty {
  566. type: string;
  567. }
  568. interface IGLTFAnimationChannelTarget {
  569. id: string;
  570. path: string;
  571. }
  572. interface IGLTFAnimationChannel {
  573. sampler: string;
  574. target: IGLTFAnimationChannelTarget;
  575. }
  576. interface IGLTFAnimationSampler {
  577. input: string;
  578. output: string;
  579. interpolation?: string;
  580. }
  581. interface IGLTFAnimation extends IGLTFChildRootProperty {
  582. channels?: IGLTFAnimationChannel[];
  583. parameters?: {
  584. [key: string]: string;
  585. };
  586. samplers?: {
  587. [key: string]: IGLTFAnimationSampler;
  588. };
  589. }
  590. interface IGLTFNodeInstanceSkin {
  591. skeletons: string[];
  592. skin: string;
  593. meshes: string[];
  594. }
  595. interface IGLTFSkins extends IGLTFChildRootProperty {
  596. bindShapeMatrix: number[];
  597. inverseBindMatrices: string;
  598. jointNames: string[];
  599. babylonSkeleton?: Skeleton;
  600. }
  601. interface IGLTFNode extends IGLTFChildRootProperty {
  602. camera?: string;
  603. children: string[];
  604. skin?: string;
  605. jointName?: string;
  606. light?: string;
  607. matrix: number[];
  608. mesh?: string;
  609. meshes?: string[];
  610. rotation?: number[];
  611. scale?: number[];
  612. translation?: number[];
  613. babylonNode?: Node;
  614. }
  615. interface IGLTFScene extends IGLTFChildRootProperty {
  616. nodes: string[];
  617. }
  618. /**
  619. * Runtime
  620. */
  621. interface IGLTFRuntime {
  622. extensions: {
  623. [key: string]: any;
  624. };
  625. accessors: {
  626. [key: string]: IGLTFAccessor;
  627. };
  628. buffers: {
  629. [key: string]: IGLTFBuffer;
  630. };
  631. bufferViews: {
  632. [key: string]: IGLTFBufferView;
  633. };
  634. meshes: {
  635. [key: string]: IGLTFMesh;
  636. };
  637. lights: {
  638. [key: string]: IGLTFLight;
  639. };
  640. cameras: {
  641. [key: string]: IGLTFCamera;
  642. };
  643. nodes: {
  644. [key: string]: IGLTFNode;
  645. };
  646. images: {
  647. [key: string]: IGLTFImage;
  648. };
  649. textures: {
  650. [key: string]: IGLTFTexture;
  651. };
  652. shaders: {
  653. [key: string]: IGLTFShader;
  654. };
  655. programs: {
  656. [key: string]: IGLTFProgram;
  657. };
  658. samplers: {
  659. [key: string]: IGLTFSampler;
  660. };
  661. techniques: {
  662. [key: string]: IGLTFTechnique;
  663. };
  664. materials: {
  665. [key: string]: IGLTFMaterial;
  666. };
  667. animations: {
  668. [key: string]: IGLTFAnimation;
  669. };
  670. skins: {
  671. [key: string]: IGLTFSkins;
  672. };
  673. currentScene?: Object;
  674. scenes: {
  675. [key: string]: IGLTFScene;
  676. };
  677. extensionsUsed: string[];
  678. extensionsRequired?: string[];
  679. buffersCount: number;
  680. shaderscount: number;
  681. scene: Scene;
  682. rootUrl: string;
  683. loadedBufferCount: number;
  684. loadedBufferViews: {
  685. [name: string]: ArrayBufferView;
  686. };
  687. loadedShaderCount: number;
  688. importOnlyMeshes: boolean;
  689. importMeshesNames?: string[];
  690. dummyNodes: Node[];
  691. }
  692. /**
  693. * Bones
  694. */
  695. interface INodeToRoot {
  696. bone: Bone;
  697. node: IGLTFNode;
  698. id: string;
  699. }
  700. interface IJointNode {
  701. node: IGLTFNode;
  702. id: string;
  703. }
  704. }
  705. declare module BABYLON.GLTF1 {
  706. /**
  707. * Implementation of the base glTF spec
  708. */
  709. class GLTFLoaderBase {
  710. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  711. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  712. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  713. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  714. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  715. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  716. }
  717. /**
  718. * glTF V1 Loader
  719. */
  720. class GLTFLoader implements IGLTFLoader {
  721. static Extensions: {
  722. [name: string]: GLTFLoaderExtension;
  723. };
  724. static RegisterExtension(extension: GLTFLoaderExtension): void;
  725. state: Nullable<GLTFLoaderState>;
  726. dispose(): void;
  727. private _importMeshAsync;
  728. /**
  729. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  730. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  731. * @param scene the scene the meshes should be added to
  732. * @param data gltf data containing information of the meshes in a loaded file
  733. * @param rootUrl root url to load from
  734. * @param onProgress event that fires when loading progress has occured
  735. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  736. */
  737. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  738. meshes: AbstractMesh[];
  739. particleSystems: IParticleSystem[];
  740. skeletons: Skeleton[];
  741. animationGroups: AnimationGroup[];
  742. }>;
  743. private _loadAsync;
  744. /**
  745. * Imports all objects from a loaded gltf file and adds them to the scene
  746. * @param scene the scene the objects should be added to
  747. * @param data gltf data containing information of the meshes in a loaded file
  748. * @param rootUrl root url to load from
  749. * @param onProgress event that fires when loading progress has occured
  750. * @returns a promise which completes when objects have been loaded to the scene
  751. */
  752. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  753. private _loadShadersAsync;
  754. private _loadBuffersAsync;
  755. private _createNodes;
  756. }
  757. }
  758. declare module BABYLON.GLTF1 {
  759. /**
  760. * Utils functions for GLTF
  761. */
  762. class GLTFUtils {
  763. /**
  764. * Sets the given "parameter" matrix
  765. * @param scene: the {BABYLON.Scene} object
  766. * @param source: the source node where to pick the matrix
  767. * @param parameter: the GLTF technique parameter
  768. * @param uniformName: the name of the shader's uniform
  769. * @param shaderMaterial: the shader material
  770. */
  771. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  772. /**
  773. * Sets the given "parameter" matrix
  774. * @param shaderMaterial: the shader material
  775. * @param uniform: the name of the shader's uniform
  776. * @param value: the value of the uniform
  777. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  778. */
  779. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  780. /**
  781. * Returns the wrap mode of the texture
  782. * @param mode: the mode value
  783. */
  784. static GetWrapMode(mode: number): number;
  785. /**
  786. * Returns the byte stride giving an accessor
  787. * @param accessor: the GLTF accessor objet
  788. */
  789. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  790. /**
  791. * Returns the texture filter mode giving a mode value
  792. * @param mode: the filter mode value
  793. */
  794. static GetTextureFilterMode(mode: number): ETextureFilterType;
  795. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  796. /**
  797. * Returns a buffer from its accessor
  798. * @param gltfRuntime: the GLTF runtime
  799. * @param accessor: the GLTF accessor
  800. */
  801. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  802. /**
  803. * Decodes a buffer view into a string
  804. * @param view: the buffer view
  805. */
  806. static DecodeBufferToText(view: ArrayBufferView): string;
  807. /**
  808. * Returns the default material of gltf. Related to
  809. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  810. * @param scene: the Babylon.js scene
  811. */
  812. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  813. private static _DefaultMaterial;
  814. }
  815. }
  816. declare module BABYLON.GLTF1 {
  817. abstract class GLTFLoaderExtension {
  818. private _name;
  819. constructor(name: string);
  820. readonly name: string;
  821. /**
  822. * Defines an override for loading the runtime
  823. * Return true to stop further extensions from loading the runtime
  824. */
  825. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  826. /**
  827. * Defines an onverride for creating gltf runtime
  828. * Return true to stop further extensions from creating the runtime
  829. */
  830. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  831. /**
  832. * Defines an override for loading buffers
  833. * Return true to stop further extensions from loading this buffer
  834. */
  835. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  836. /**
  837. * Defines an override for loading texture buffers
  838. * Return true to stop further extensions from loading this texture data
  839. */
  840. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  841. /**
  842. * Defines an override for creating textures
  843. * Return true to stop further extensions from loading this texture
  844. */
  845. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  846. /**
  847. * Defines an override for loading shader strings
  848. * Return true to stop further extensions from loading this shader data
  849. */
  850. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  851. /**
  852. * Defines an override for loading materials
  853. * Return true to stop further extensions from loading this material
  854. */
  855. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  856. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  857. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  858. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  859. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  860. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  861. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  862. private static LoadTextureBufferAsync;
  863. private static CreateTextureAsync;
  864. private static ApplyExtensions;
  865. }
  866. }
  867. declare module BABYLON.GLTF1 {
  868. class GLTFBinaryExtension extends GLTFLoaderExtension {
  869. private _bin;
  870. constructor();
  871. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  872. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  873. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  874. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  875. }
  876. }
  877. declare module BABYLON.GLTF1 {
  878. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  879. constructor();
  880. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  881. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  882. private _loadTexture;
  883. }
  884. }
  885. declare module BABYLON.GLTF2 {
  886. /**
  887. * Loader interface with an index field.
  888. */
  889. interface IArrayItem {
  890. /**
  891. * The index of this item in the array.
  892. */
  893. index: number;
  894. }
  895. /**
  896. * Loader interface with additional members.
  897. */
  898. interface ILoaderAccessor extends IAccessor, IArrayItem {
  899. /** @hidden */
  900. _data?: Promise<ArrayBufferView>;
  901. /** @hidden */
  902. _babylonVertexBuffer?: Promise<VertexBuffer>;
  903. }
  904. /**
  905. * Loader interface with additional members.
  906. */
  907. interface ILoaderAnimationChannel extends IAnimationChannel, IArrayItem {
  908. }
  909. /** @hidden */
  910. interface _ILoaderAnimationSamplerData {
  911. input: Float32Array;
  912. interpolation: AnimationSamplerInterpolation;
  913. output: Float32Array;
  914. }
  915. /**
  916. * Loader interface with additional members.
  917. */
  918. interface ILoaderAnimationSampler extends IAnimationSampler, IArrayItem {
  919. /** @hidden */
  920. _data?: Promise<_ILoaderAnimationSamplerData>;
  921. }
  922. /**
  923. * Loader interface with additional members.
  924. */
  925. interface ILoaderAnimation extends IAnimation, IArrayItem {
  926. channels: ILoaderAnimationChannel[];
  927. samplers: ILoaderAnimationSampler[];
  928. /** @hidden */
  929. _babylonAnimationGroup?: AnimationGroup;
  930. }
  931. /**
  932. * Loader interface with additional members.
  933. */
  934. interface ILoaderBuffer extends IBuffer, IArrayItem {
  935. /** @hidden */
  936. _data?: Promise<ArrayBufferView>;
  937. }
  938. /**
  939. * Loader interface with additional members.
  940. */
  941. interface ILoaderBufferView extends IBufferView, IArrayItem {
  942. /** @hidden */
  943. _data?: Promise<ArrayBufferView>;
  944. /** @hidden */
  945. _babylonBuffer?: Promise<Buffer>;
  946. }
  947. /**
  948. * Loader interface with additional members.
  949. */
  950. interface ILoaderCamera extends ICamera, IArrayItem {
  951. }
  952. /**
  953. * Loader interface with additional members.
  954. */
  955. interface ILoaderImage extends IImage, IArrayItem {
  956. /** @hidden */
  957. _data?: Promise<ArrayBufferView>;
  958. }
  959. /**
  960. * Loader interface with additional members.
  961. */
  962. interface ILoaderMaterialNormalTextureInfo extends IMaterialNormalTextureInfo, ILoaderTextureInfo {
  963. }
  964. /**
  965. * Loader interface with additional members.
  966. */
  967. interface ILoaderMaterialOcclusionTextureInfo extends IMaterialOcclusionTextureInfo, ILoaderTextureInfo {
  968. }
  969. /**
  970. * Loader interface with additional members.
  971. */
  972. interface ILoaderMaterialPbrMetallicRoughness extends IMaterialPbrMetallicRoughness {
  973. baseColorTexture?: ILoaderTextureInfo;
  974. metallicRoughnessTexture?: ILoaderTextureInfo;
  975. }
  976. /**
  977. * Loader interface with additional members.
  978. */
  979. interface ILoaderMaterial extends IMaterial, IArrayItem {
  980. pbrMetallicRoughness?: ILoaderMaterialPbrMetallicRoughness;
  981. normalTexture?: ILoaderMaterialNormalTextureInfo;
  982. occlusionTexture?: ILoaderMaterialOcclusionTextureInfo;
  983. emissiveTexture?: ILoaderTextureInfo;
  984. /** @hidden */
  985. _babylonData?: {
  986. [drawMode: number]: {
  987. material: Material;
  988. meshes: AbstractMesh[];
  989. promise: Promise<void>;
  990. };
  991. };
  992. }
  993. /**
  994. * Loader interface with additional members.
  995. */
  996. interface ILoaderMesh extends IMesh, IArrayItem {
  997. primitives: ILoaderMeshPrimitive[];
  998. }
  999. /**
  1000. * Loader interface with additional members.
  1001. */
  1002. interface ILoaderMeshPrimitive extends IMeshPrimitive, IArrayItem {
  1003. }
  1004. /**
  1005. * Loader interface with additional members.
  1006. */
  1007. interface ILoaderNode extends INode, IArrayItem {
  1008. /**
  1009. * The parent glTF node.
  1010. */
  1011. parent?: ILoaderNode;
  1012. /** @hidden */
  1013. _babylonMesh?: Mesh;
  1014. /** @hidden */
  1015. _primitiveBabylonMeshes?: Mesh[];
  1016. /** @hidden */
  1017. _babylonBones?: Bone[];
  1018. /** @hidden */
  1019. _numMorphTargets?: number;
  1020. }
  1021. /** @hidden */
  1022. interface _ILoaderSamplerData {
  1023. noMipMaps: boolean;
  1024. samplingMode: number;
  1025. wrapU: number;
  1026. wrapV: number;
  1027. }
  1028. /**
  1029. * Loader interface with additional members.
  1030. */
  1031. interface ILoaderSampler extends ISampler, IArrayItem {
  1032. /** @hidden */
  1033. _data?: _ILoaderSamplerData;
  1034. }
  1035. /**
  1036. * Loader interface with additional members.
  1037. */
  1038. interface ILoaderScene extends IScene, IArrayItem {
  1039. }
  1040. /**
  1041. * Loader interface with additional members.
  1042. */
  1043. interface ILoaderSkin extends ISkin, IArrayItem {
  1044. /** @hidden */
  1045. _babylonSkeleton?: Skeleton;
  1046. /** @hidden */
  1047. _promise?: Promise<void>;
  1048. }
  1049. /**
  1050. * Loader interface with additional members.
  1051. */
  1052. interface ILoaderTexture extends ITexture, IArrayItem {
  1053. }
  1054. /**
  1055. * Loader interface with additional members.
  1056. */
  1057. interface ILoaderTextureInfo extends ITextureInfo {
  1058. }
  1059. /**
  1060. * Loader interface with additional members.
  1061. */
  1062. interface ILoaderGLTF extends IGLTF {
  1063. accessors?: ILoaderAccessor[];
  1064. animations?: ILoaderAnimation[];
  1065. buffers?: ILoaderBuffer[];
  1066. bufferViews?: ILoaderBufferView[];
  1067. cameras?: ILoaderCamera[];
  1068. images?: ILoaderImage[];
  1069. materials?: ILoaderMaterial[];
  1070. meshes?: ILoaderMesh[];
  1071. nodes?: ILoaderNode[];
  1072. samplers?: ILoaderSampler[];
  1073. scenes?: ILoaderScene[];
  1074. skins?: ILoaderSkin[];
  1075. textures?: ILoaderTexture[];
  1076. }
  1077. }
  1078. /**
  1079. * Defines the module for importing and exporting glTF 2.0 assets
  1080. */
  1081. declare module BABYLON.GLTF2 {
  1082. /**
  1083. * Helper class for working with arrays when loading the glTF asset
  1084. */
  1085. class ArrayItem {
  1086. /**
  1087. * Gets an item from the given array.
  1088. * @param context The context when loading the asset
  1089. * @param array The array to get the item from
  1090. * @param index The index to the array
  1091. * @returns The array item
  1092. */
  1093. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1094. /**
  1095. * Assign an `index` field to each item of the given array.
  1096. * @param array The array of items
  1097. */
  1098. static Assign(array?: IArrayItem[]): void;
  1099. }
  1100. /**
  1101. * The glTF 2.0 loader
  1102. */
  1103. class GLTFLoader implements IGLTFLoader {
  1104. /** The glTF object parsed from the JSON. */
  1105. gltf: ILoaderGLTF;
  1106. /** The Babylon scene when loading the asset. */
  1107. babylonScene: Scene;
  1108. /** @hidden */
  1109. _completePromises: Promise<any>[];
  1110. private _disposed;
  1111. private _parent;
  1112. private _state;
  1113. private _extensions;
  1114. private _rootUrl;
  1115. private _rootBabylonMesh;
  1116. private _defaultBabylonMaterialData;
  1117. private _progressCallback?;
  1118. private _requests;
  1119. private static readonly _DefaultSampler;
  1120. private static _ExtensionNames;
  1121. private static _ExtensionFactories;
  1122. /**
  1123. * Registers a loader extension.
  1124. * @param name The name of the loader extension.
  1125. * @param factory The factory function that creates the loader extension.
  1126. */
  1127. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1128. /**
  1129. * Unregisters a loader extension.
  1130. * @param name The name of the loader extenion.
  1131. * @returns A boolean indicating whether the extension has been unregistered
  1132. */
  1133. static UnregisterExtension(name: string): boolean;
  1134. /**
  1135. * Gets the loader state.
  1136. */
  1137. readonly state: Nullable<GLTFLoaderState>;
  1138. /** @hidden */
  1139. constructor(parent: GLTFFileLoader);
  1140. /** @hidden */
  1141. dispose(): void;
  1142. /** @hidden */
  1143. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1144. meshes: AbstractMesh[];
  1145. particleSystems: IParticleSystem[];
  1146. skeletons: Skeleton[];
  1147. animationGroups: AnimationGroup[];
  1148. }>;
  1149. /** @hidden */
  1150. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1151. private _loadAsync;
  1152. private _loadData;
  1153. private _setupData;
  1154. private _loadExtensions;
  1155. private _checkExtensions;
  1156. private _setState;
  1157. private _createRootNode;
  1158. /**
  1159. * Loads a glTF scene.
  1160. * @param context The context when loading the asset
  1161. * @param scene The glTF scene property
  1162. * @returns A promise that resolves when the load is complete
  1163. */
  1164. loadSceneAsync(context: string, scene: ILoaderScene): Promise<void>;
  1165. private _forEachPrimitive;
  1166. private _getMeshes;
  1167. private _getSkeletons;
  1168. private _getAnimationGroups;
  1169. private _startAnimations;
  1170. /**
  1171. * Loads a glTF node.
  1172. * @param context The context when loading the asset
  1173. * @param node The glTF node property
  1174. * @param assign A function called synchronously after parsing the glTF properties
  1175. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1176. */
  1177. loadNodeAsync(context: string, node: ILoaderNode, assign?: (babylonMesh: Mesh) => void): Promise<Mesh>;
  1178. private _loadMeshAsync;
  1179. private _loadMeshPrimitiveAsync;
  1180. private _loadVertexDataAsync;
  1181. private _createMorphTargets;
  1182. private _loadMorphTargetsAsync;
  1183. private _loadMorphTargetVertexDataAsync;
  1184. private static _LoadTransform;
  1185. private _loadSkinAsync;
  1186. private _loadBones;
  1187. private _loadBone;
  1188. private _loadSkinInverseBindMatricesDataAsync;
  1189. private _updateBoneMatrices;
  1190. private _getNodeMatrix;
  1191. /**
  1192. * Loads a glTF camera.
  1193. * @param context The context when loading the asset
  1194. * @param camera The glTF camera property
  1195. * @param assign A function called synchronously after parsing the glTF properties
  1196. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1197. */
  1198. loadCameraAsync(context: string, camera: ILoaderCamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1199. private _loadAnimationsAsync;
  1200. /**
  1201. * Loads a glTF animation.
  1202. * @param context The context when loading the asset
  1203. * @param animation The glTF animation property
  1204. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1205. */
  1206. loadAnimationAsync(context: string, animation: ILoaderAnimation): Promise<AnimationGroup>;
  1207. private _loadAnimationChannelAsync;
  1208. private _loadAnimationSamplerAsync;
  1209. private _loadBufferAsync;
  1210. /**
  1211. * Loads a glTF buffer view.
  1212. * @param context The context when loading the asset
  1213. * @param bufferView The glTF buffer view property
  1214. * @returns A promise that resolves with the loaded data when the load is complete
  1215. */
  1216. loadBufferViewAsync(context: string, bufferView: ILoaderBufferView): Promise<ArrayBufferView>;
  1217. private _loadIndicesAccessorAsync;
  1218. private _loadFloatAccessorAsync;
  1219. private _loadVertexBufferViewAsync;
  1220. private _loadVertexAccessorAsync;
  1221. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1222. /** @hidden */
  1223. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1224. private _createDefaultMaterial;
  1225. /**
  1226. * Creates a Babylon material from a glTF material.
  1227. * @param context The context when loading the asset
  1228. * @param material The glTF material property
  1229. * @param babylonDrawMode The draw mode for the Babylon material
  1230. * @returns The Babylon material
  1231. */
  1232. createMaterial(context: string, material: ILoaderMaterial, babylonDrawMode: number): Material;
  1233. /**
  1234. * Loads properties from a glTF material into a Babylon material.
  1235. * @param context The context when loading the asset
  1236. * @param material The glTF material property
  1237. * @param babylonMaterial The Babylon material
  1238. * @returns A promise that resolves when the load is complete
  1239. */
  1240. loadMaterialPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  1241. /**
  1242. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1243. * @param context The context when loading the asset
  1244. * @param material The glTF material property
  1245. * @param babylonMaterial The Babylon material
  1246. * @returns A promise that resolves when the load is complete
  1247. */
  1248. loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  1249. /**
  1250. * Loads the alpha properties from a glTF material into a Babylon material.
  1251. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1252. * @param context The context when loading the asset
  1253. * @param material The glTF material property
  1254. * @param babylonMaterial The Babylon material
  1255. */
  1256. loadMaterialAlphaProperties(context: string, material: ILoaderMaterial, babylonMaterial: Material): void;
  1257. /**
  1258. * Loads a glTF texture info.
  1259. * @param context The context when loading the asset
  1260. * @param textureInfo The glTF texture info property
  1261. * @param assign A function called synchronously after parsing the glTF properties
  1262. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1263. */
  1264. loadTextureInfoAsync(context: string, textureInfo: ILoaderTextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1265. private _loadTextureAsync;
  1266. private _loadSampler;
  1267. /**
  1268. * Loads a glTF image.
  1269. * @param context The context when loading the asset
  1270. * @param image The glTF image property
  1271. * @returns A promise that resolves with the loaded data when the load is complete
  1272. */
  1273. loadImageAsync(context: string, image: ILoaderImage): Promise<ArrayBufferView>;
  1274. /**
  1275. * Loads a glTF uri.
  1276. * @param context The context when loading the asset
  1277. * @param uri The base64 or relative uri
  1278. * @returns A promise that resolves with the loaded data when the load is complete
  1279. */
  1280. loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1281. private _onProgress;
  1282. private static _GetTextureWrapMode;
  1283. private static _GetTextureSamplingMode;
  1284. private static _GetTypedArray;
  1285. private static _GetNumComponents;
  1286. private static _ValidateUri;
  1287. private static _GetDrawMode;
  1288. private _compileMaterialsAsync;
  1289. private _compileShadowGeneratorsAsync;
  1290. private _forEachExtensions;
  1291. private _applyExtensions;
  1292. private _extensionsOnLoading;
  1293. private _extensionsOnReady;
  1294. private _extensionsLoadSceneAsync;
  1295. private _extensionsLoadNodeAsync;
  1296. private _extensionsLoadCameraAsync;
  1297. private _extensionsLoadVertexDataAsync;
  1298. private _extensionsLoadMaterialAsync;
  1299. private _extensionsCreateMaterial;
  1300. private _extensionsLoadMaterialPropertiesAsync;
  1301. private _extensionsLoadTextureInfoAsync;
  1302. private _extensionsLoadAnimationAsync;
  1303. private _extensionsLoadUriAsync;
  1304. /**
  1305. * Helper method called by a loader extension to load an glTF extension.
  1306. * @param context The context when loading the asset
  1307. * @param property The glTF property to load the extension from
  1308. * @param extensionName The name of the extension to load
  1309. * @param actionAsync The action to run
  1310. * @returns The promise returned by actionAsync or null if the extension does not exist
  1311. */
  1312. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1313. /**
  1314. * Helper method called by a loader extension to load a glTF extra.
  1315. * @param context The context when loading the asset
  1316. * @param property The glTF property to load the extra from
  1317. * @param extensionName The name of the extension to load
  1318. * @param actionAsync The action to run
  1319. * @returns The promise returned by actionAsync or null if the extra does not exist
  1320. */
  1321. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1322. /**
  1323. * Increments the indentation level and logs a message.
  1324. * @param message The message to log
  1325. */
  1326. logOpen(message: string): void;
  1327. /**
  1328. * Decrements the indentation level.
  1329. */
  1330. logClose(): void;
  1331. /**
  1332. * Logs a message
  1333. * @param message The message to log
  1334. */
  1335. log(message: string): void;
  1336. /**
  1337. * Starts a performance counter.
  1338. * @param counterName The name of the performance counter
  1339. */
  1340. startPerformanceCounter(counterName: string): void;
  1341. /**
  1342. * Ends a performance counter.
  1343. * @param counterName The name of the performance counter
  1344. */
  1345. endPerformanceCounter(counterName: string): void;
  1346. }
  1347. }
  1348. declare module BABYLON.GLTF2 {
  1349. /**
  1350. * Interface for a glTF loader extension.
  1351. */
  1352. interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1353. /**
  1354. * Called after the loader state changes to LOADING.
  1355. */
  1356. onLoading?(): void;
  1357. /**
  1358. * Called after the loader state changes to READY.
  1359. */
  1360. onReady?(): void;
  1361. /**
  1362. * Define this method to modify the default behavior when loading scenes.
  1363. * @param context The context when loading the asset
  1364. * @param scene The glTF scene property
  1365. * @returns A promise that resolves when the load is complete or null if not handled
  1366. */
  1367. loadSceneAsync?(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1368. /**
  1369. * Define this method to modify the default behavior when loading nodes.
  1370. * @param context The context when loading the asset
  1371. * @param node The glTF node property
  1372. * @param assign A function called synchronously after parsing the glTF properties
  1373. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete or null if not handled
  1374. */
  1375. loadNodeAsync?(context: string, node: ILoaderNode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1376. /**
  1377. * Define this method to modify the default behavior when loading cameras.
  1378. * @param context The context when loading the asset
  1379. * @param camera The glTF camera property
  1380. * @param assign A function called synchronously after parsing the glTF properties
  1381. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1382. */
  1383. loadCameraAsync?(context: string, camera: ILoaderCamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1384. /**
  1385. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1386. * @param context The context when loading the asset
  1387. * @param primitive The glTF mesh primitive property
  1388. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1389. */
  1390. _loadVertexDataAsync?(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1391. /**
  1392. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1393. * @param context The context when loading the asset
  1394. * @param material The glTF material property
  1395. * @param assign A function called synchronously after parsing the glTF properties
  1396. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1397. */
  1398. _loadMaterialAsync?(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1399. /**
  1400. * Define this method to modify the default behavior when creating materials.
  1401. * @param context The context when loading the asset
  1402. * @param material The glTF material property
  1403. * @param babylonDrawMode The draw mode for the Babylon material
  1404. * @returns The Babylon material or null if not handled
  1405. */
  1406. createMaterial?(context: string, material: ILoaderMaterial, babylonDrawMode: number): Nullable<Material>;
  1407. /**
  1408. * Define this method to modify the default behavior when loading material properties.
  1409. * @param context The context when loading the asset
  1410. * @param material The glTF material property
  1411. * @param babylonMaterial The Babylon material
  1412. * @returns A promise that resolves when the load is complete or null if not handled
  1413. */
  1414. loadMaterialPropertiesAsync?(context: string, material: ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1415. /**
  1416. * Define this method to modify the default behavior when loading texture infos.
  1417. * @param context The context when loading the asset
  1418. * @param textureInfo The glTF texture info property
  1419. * @param assign A function called synchronously after parsing the glTF properties
  1420. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1421. */
  1422. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1423. /**
  1424. * Define this method to modify the default behavior when loading animations.
  1425. * @param context The context when loading the asset
  1426. * @param animation The glTF animation property
  1427. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1428. */
  1429. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1430. /**
  1431. * Define this method to modify the default behavior when loading uris.
  1432. * @param context The context when loading the asset
  1433. * @param uri The uri to load
  1434. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1435. */
  1436. _loadUriAsync?(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1437. }
  1438. }
  1439. /**
  1440. * Defines the module for the built-in glTF 2.0 loader extensions.
  1441. */
  1442. declare module BABYLON.GLTF2.Extensions {
  1443. }
  1444. declare module BABYLON.GLTF2.Extensions {
  1445. /**
  1446. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1447. */
  1448. class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1449. /** The name of this extension. */
  1450. readonly name: string;
  1451. /** Defines whether this extension is enabled. */
  1452. enabled: boolean;
  1453. private _loader;
  1454. private _clips;
  1455. private _emitters;
  1456. /** @hidden */
  1457. constructor(loader: GLTFLoader);
  1458. /** @hidden */
  1459. dispose(): void;
  1460. /** @hidden */
  1461. onLoading(): void;
  1462. /** @hidden */
  1463. loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1464. /** @hidden */
  1465. loadNodeAsync(context: string, node: ILoaderNode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1466. /** @hidden */
  1467. loadAnimationAsync(context: string, animation: ILoaderAnimation): Nullable<Promise<AnimationGroup>>;
  1468. private _loadClipAsync;
  1469. private _loadEmitterAsync;
  1470. private _getEventAction;
  1471. private _loadAnimationEventAsync;
  1472. }
  1473. }
  1474. declare module BABYLON.GLTF2.Extensions {
  1475. /**
  1476. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1477. */
  1478. class MSFT_lod implements IGLTFLoaderExtension {
  1479. /** The name of this extension. */
  1480. readonly name: string;
  1481. /** Defines whether this extension is enabled. */
  1482. enabled: boolean;
  1483. /**
  1484. * Maximum number of LODs to load, starting from the lowest LOD.
  1485. */
  1486. maxLODsToLoad: number;
  1487. /**
  1488. * Observable raised when all node LODs of one level are loaded.
  1489. * The event data is the index of the loaded LOD starting from zero.
  1490. * Dispose the loader to cancel the loading of the next level of LODs.
  1491. */
  1492. onNodeLODsLoadedObservable: Observable<number>;
  1493. /**
  1494. * Observable raised when all material LODs of one level are loaded.
  1495. * The event data is the index of the loaded LOD starting from zero.
  1496. * Dispose the loader to cancel the loading of the next level of LODs.
  1497. */
  1498. onMaterialLODsLoadedObservable: Observable<number>;
  1499. private _loader;
  1500. private _nodeIndexLOD;
  1501. private _nodeSignalLODs;
  1502. private _nodePromiseLODs;
  1503. private _materialIndexLOD;
  1504. private _materialSignalLODs;
  1505. private _materialPromiseLODs;
  1506. /** @hidden */
  1507. constructor(loader: GLTFLoader);
  1508. /** @hidden */
  1509. dispose(): void;
  1510. /** @hidden */
  1511. onReady(): void;
  1512. /** @hidden */
  1513. loadNodeAsync(context: string, node: ILoaderNode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1514. /** @hidden */
  1515. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1516. /** @hidden */
  1517. _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1518. /**
  1519. * Gets an array of LOD properties from lowest to highest.
  1520. */
  1521. private _getLODs;
  1522. private _disposeUnusedMaterials;
  1523. }
  1524. }
  1525. declare module BABYLON.GLTF2.Extensions {
  1526. /** @hidden */
  1527. class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1528. readonly name: string;
  1529. enabled: boolean;
  1530. private _loader;
  1531. constructor(loader: GLTFLoader);
  1532. dispose(): void;
  1533. loadMaterialPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1534. }
  1535. }
  1536. declare module BABYLON.GLTF2.Extensions {
  1537. /** @hidden */
  1538. class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1539. readonly name: string;
  1540. enabled: boolean;
  1541. private _loader;
  1542. constructor(loader: GLTFLoader);
  1543. dispose(): void;
  1544. loadMaterialPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1545. }
  1546. }
  1547. declare module BABYLON.GLTF2.Extensions {
  1548. /**
  1549. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1550. */
  1551. class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1552. /** The name of this extension. */
  1553. readonly name: string;
  1554. /** Defines whether this extension is enabled. */
  1555. enabled: boolean;
  1556. private _loader;
  1557. private _dracoCompression?;
  1558. /** @hidden */
  1559. constructor(loader: GLTFLoader);
  1560. /** @hidden */
  1561. dispose(): void;
  1562. /** @hidden */
  1563. _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1564. }
  1565. }
  1566. declare module BABYLON.GLTF2.Extensions {
  1567. /**
  1568. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1569. */
  1570. class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1571. /** The name of this extension. */
  1572. readonly name: string;
  1573. /** Defines whether this extension is enabled. */
  1574. enabled: boolean;
  1575. private _loader;
  1576. /** @hidden */
  1577. constructor(loader: GLTFLoader);
  1578. /** @hidden */
  1579. dispose(): void;
  1580. /** @hidden */
  1581. loadMaterialPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1582. private _loadSpecularGlossinessPropertiesAsync;
  1583. }
  1584. }
  1585. declare module BABYLON.GLTF2.Extensions {
  1586. /**
  1587. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1588. */
  1589. class KHR_materials_unlit implements IGLTFLoaderExtension {
  1590. /** The name of this extension. */
  1591. readonly name: string;
  1592. /** Defines whether this extension is enabled. */
  1593. enabled: boolean;
  1594. private _loader;
  1595. /** @hidden */
  1596. constructor(loader: GLTFLoader);
  1597. /** @hidden */
  1598. dispose(): void;
  1599. /** @hidden */
  1600. loadMaterialPropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1601. private _loadUnlitPropertiesAsync;
  1602. }
  1603. }
  1604. declare module BABYLON.GLTF2.Extensions {
  1605. /**
  1606. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1607. */
  1608. class KHR_lights implements IGLTFLoaderExtension {
  1609. /** The name of this extension. */
  1610. readonly name: string;
  1611. /** Defines whether this extension is enabled. */
  1612. enabled: boolean;
  1613. private _loader;
  1614. private _lights?;
  1615. /** @hidden */
  1616. constructor(loader: GLTFLoader);
  1617. /** @hidden */
  1618. dispose(): void;
  1619. /** @hidden */
  1620. onLoading(): void;
  1621. /** @hidden */
  1622. loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1623. /** @hidden */
  1624. loadNodeAsync(context: string, node: ILoaderNode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1625. }
  1626. }
  1627. declare module BABYLON.GLTF2.Extensions {
  1628. /**
  1629. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1630. */
  1631. class KHR_texture_transform implements IGLTFLoaderExtension {
  1632. /** The name of this extension. */
  1633. readonly name: string;
  1634. /** Defines whether this extension is enabled. */
  1635. enabled: boolean;
  1636. private _loader;
  1637. /** @hidden */
  1638. constructor(loader: GLTFLoader);
  1639. /** @hidden */
  1640. dispose(): void;
  1641. /** @hidden */
  1642. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1643. }
  1644. }
  1645. declare module BABYLON.GLTF2.Extensions {
  1646. /**
  1647. * [Specification](TODO) (Experimental)
  1648. */
  1649. class EXT_lights_imageBased implements IGLTFLoaderExtension {
  1650. /** The name of this extension. */
  1651. readonly name: string;
  1652. /** Defines whether this extension is enabled. */
  1653. enabled: boolean;
  1654. private _loader;
  1655. private _lights?;
  1656. /** @hidden */
  1657. constructor(loader: GLTFLoader);
  1658. /** @hidden */
  1659. dispose(): void;
  1660. /** @hidden */
  1661. onLoading(): void;
  1662. /** @hidden */
  1663. loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1664. private _loadLightAsync;
  1665. }
  1666. }