babylonjs.loaders.d.ts 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  1. declare module BABYLON {
  2. /**
  3. * Mode that determines the coordinate system to use.
  4. */
  5. export 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. export 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. export interface IGLTFLoaderData {
  36. /**
  37. * Object that represents the glTF JSON.
  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. export 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. export 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. export interface IGLTFLoader extends IDisposable {
  77. readonly state: Nullable<GLTFLoaderState>;
  78. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => 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, fileName?: string) => Promise<void>;
  85. }
  86. /**
  87. * File loader for loading glTF files into a scene.
  88. */
  89. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  90. /** @hidden */
  91. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  92. /** @hidden */
  93. static _CreateGLTF2Loader: (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. /**
  143. * Function called before loading a url referenced by the asset.
  144. */
  145. preprocessUrlAsync: (url: string) => Promise<string>;
  146. /**
  147. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  148. */
  149. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  150. private _onMeshLoadedObserver;
  151. /**
  152. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  153. */
  154. onMeshLoaded: (mesh: AbstractMesh) => void;
  155. /**
  156. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  157. */
  158. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  159. private _onTextureLoadedObserver;
  160. /**
  161. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  162. */
  163. onTextureLoaded: (texture: BaseTexture) => void;
  164. /**
  165. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  166. */
  167. readonly onMaterialLoadedObservable: Observable<Material>;
  168. private _onMaterialLoadedObserver;
  169. /**
  170. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  171. */
  172. onMaterialLoaded: (material: Material) => void;
  173. /**
  174. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  175. */
  176. readonly onCameraLoadedObservable: Observable<Camera>;
  177. private _onCameraLoadedObserver;
  178. /**
  179. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  180. */
  181. onCameraLoaded: (camera: Camera) => void;
  182. /**
  183. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  184. * For assets with LODs, raised when all of the LODs are complete.
  185. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  186. */
  187. readonly onCompleteObservable: Observable<void>;
  188. private _onCompleteObserver;
  189. /**
  190. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  191. * For assets with LODs, raised when all of the LODs are complete.
  192. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  193. */
  194. onComplete: () => void;
  195. /**
  196. * Observable raised when an error occurs.
  197. */
  198. readonly onErrorObservable: Observable<any>;
  199. private _onErrorObserver;
  200. /**
  201. * Callback raised when an error occurs.
  202. */
  203. onError: (reason: any) => void;
  204. /**
  205. * Observable raised after the loader is disposed.
  206. */
  207. readonly onDisposeObservable: Observable<void>;
  208. private _onDisposeObserver;
  209. /**
  210. * Callback raised after the loader is disposed.
  211. */
  212. onDispose: () => void;
  213. /**
  214. * Observable raised after a loader extension is created.
  215. * Set additional options for a loader extension in this event.
  216. */
  217. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  218. private _onExtensionLoadedObserver;
  219. /**
  220. * Callback raised after a loader extension is created.
  221. */
  222. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  223. /**
  224. * Defines if the loader logging is enabled.
  225. */
  226. loggingEnabled: boolean;
  227. /**
  228. * Defines if the loader should capture performance counters.
  229. */
  230. capturePerformanceCounters: boolean;
  231. /**
  232. * Defines if the loader should validate the asset.
  233. */
  234. validate: boolean;
  235. /**
  236. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  237. */
  238. readonly onValidatedObservable: Observable<IGLTFValidationResults>;
  239. private _onValidatedObserver;
  240. /**
  241. * Callback raised after a loader extension is created.
  242. */
  243. onValidated: (results: IGLTFValidationResults) => void;
  244. private _loader;
  245. /**
  246. * Name of the loader ("gltf")
  247. */
  248. name: string;
  249. /**
  250. * Supported file extensions of the loader (.gltf, .glb)
  251. */
  252. extensions: ISceneLoaderPluginExtensions;
  253. /**
  254. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  255. */
  256. dispose(): void;
  257. /** @hidden */
  258. _clear(): void;
  259. /**
  260. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  261. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  262. * @param scene the scene the meshes should be added to
  263. * @param data the glTF data to load
  264. * @param rootUrl root url to load from
  265. * @param onProgress event that fires when loading progress has occured
  266. * @param fileName Defines the name of the file to load
  267. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  268. */
  269. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  270. meshes: AbstractMesh[];
  271. particleSystems: IParticleSystem[];
  272. skeletons: Skeleton[];
  273. animationGroups: AnimationGroup[];
  274. }>;
  275. /**
  276. * Imports all objects from the loaded glTF data and adds them to the scene
  277. * @param scene the scene the objects should be added to
  278. * @param data the glTF data to load
  279. * @param rootUrl root url to load from
  280. * @param onProgress event that fires when loading progress has occured
  281. * @param fileName Defines the name of the file to load
  282. * @returns a promise which completes when objects have been loaded to the scene
  283. */
  284. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  285. /**
  286. * Load into an asset container.
  287. * @param scene The scene to load into
  288. * @param data The data to import
  289. * @param rootUrl The root url for scene and resources
  290. * @param onProgress The callback when the load progresses
  291. * @param fileName Defines the name of the file to load
  292. * @returns The loaded asset container
  293. */
  294. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  295. /**
  296. * If the data string can be loaded directly.
  297. * @param data string contianing the file data
  298. * @returns if the data can be loaded directly
  299. */
  300. canDirectLoad(data: string): boolean;
  301. /**
  302. * Rewrites a url by combining a root url and response url.
  303. */
  304. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  305. /**
  306. * Instantiates a glTF file loader plugin.
  307. * @returns the created plugin
  308. */
  309. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  310. /**
  311. * The loader state or null if the loader is not active.
  312. */
  313. readonly loaderState: Nullable<GLTFLoaderState>;
  314. /**
  315. * Returns a promise that resolves when the asset is completely loaded.
  316. * @returns a promise that resolves when the asset is completely loaded.
  317. */
  318. whenCompleteAsync(): Promise<void>;
  319. private _parseAsync;
  320. private _validateAsync;
  321. private _getLoader;
  322. private _unpackBinary;
  323. private _unpackBinaryV1;
  324. private _unpackBinaryV2;
  325. private static _parseVersion;
  326. private static _compareVersion;
  327. private static _decodeBufferToText;
  328. private static readonly _logSpaces;
  329. private _logIndentLevel;
  330. private _loggingEnabled;
  331. /** @hidden */
  332. _log: (message: string) => void;
  333. /** @hidden */
  334. _logOpen(message: string): void;
  335. /** @hidden */
  336. _logClose(): void;
  337. private _logEnabled;
  338. private _logDisabled;
  339. private _capturePerformanceCounters;
  340. /** @hidden */
  341. _startPerformanceCounter: (counterName: string) => void;
  342. /** @hidden */
  343. _endPerformanceCounter: (counterName: string) => void;
  344. private _startPerformanceCounterEnabled;
  345. private _startPerformanceCounterDisabled;
  346. private _endPerformanceCounterEnabled;
  347. private _endPerformanceCounterDisabled;
  348. }
  349. }
  350. declare module BABYLON.GLTF1 {
  351. /**
  352. * Enums
  353. * @hidden
  354. */
  355. export enum EComponentType {
  356. BYTE = 5120,
  357. UNSIGNED_BYTE = 5121,
  358. SHORT = 5122,
  359. UNSIGNED_SHORT = 5123,
  360. FLOAT = 5126
  361. }
  362. /** @hidden */
  363. export enum EShaderType {
  364. FRAGMENT = 35632,
  365. VERTEX = 35633
  366. }
  367. /** @hidden */
  368. export enum EParameterType {
  369. BYTE = 5120,
  370. UNSIGNED_BYTE = 5121,
  371. SHORT = 5122,
  372. UNSIGNED_SHORT = 5123,
  373. INT = 5124,
  374. UNSIGNED_INT = 5125,
  375. FLOAT = 5126,
  376. FLOAT_VEC2 = 35664,
  377. FLOAT_VEC3 = 35665,
  378. FLOAT_VEC4 = 35666,
  379. INT_VEC2 = 35667,
  380. INT_VEC3 = 35668,
  381. INT_VEC4 = 35669,
  382. BOOL = 35670,
  383. BOOL_VEC2 = 35671,
  384. BOOL_VEC3 = 35672,
  385. BOOL_VEC4 = 35673,
  386. FLOAT_MAT2 = 35674,
  387. FLOAT_MAT3 = 35675,
  388. FLOAT_MAT4 = 35676,
  389. SAMPLER_2D = 35678
  390. }
  391. /** @hidden */
  392. export enum ETextureWrapMode {
  393. CLAMP_TO_EDGE = 33071,
  394. MIRRORED_REPEAT = 33648,
  395. REPEAT = 10497
  396. }
  397. /** @hidden */
  398. export enum ETextureFilterType {
  399. NEAREST = 9728,
  400. LINEAR = 9728,
  401. NEAREST_MIPMAP_NEAREST = 9984,
  402. LINEAR_MIPMAP_NEAREST = 9985,
  403. NEAREST_MIPMAP_LINEAR = 9986,
  404. LINEAR_MIPMAP_LINEAR = 9987
  405. }
  406. /** @hidden */
  407. export enum ETextureFormat {
  408. ALPHA = 6406,
  409. RGB = 6407,
  410. RGBA = 6408,
  411. LUMINANCE = 6409,
  412. LUMINANCE_ALPHA = 6410
  413. }
  414. /** @hidden */
  415. export enum ECullingType {
  416. FRONT = 1028,
  417. BACK = 1029,
  418. FRONT_AND_BACK = 1032
  419. }
  420. /** @hidden */
  421. export enum EBlendingFunction {
  422. ZERO = 0,
  423. ONE = 1,
  424. SRC_COLOR = 768,
  425. ONE_MINUS_SRC_COLOR = 769,
  426. DST_COLOR = 774,
  427. ONE_MINUS_DST_COLOR = 775,
  428. SRC_ALPHA = 770,
  429. ONE_MINUS_SRC_ALPHA = 771,
  430. DST_ALPHA = 772,
  431. ONE_MINUS_DST_ALPHA = 773,
  432. CONSTANT_COLOR = 32769,
  433. ONE_MINUS_CONSTANT_COLOR = 32770,
  434. CONSTANT_ALPHA = 32771,
  435. ONE_MINUS_CONSTANT_ALPHA = 32772,
  436. SRC_ALPHA_SATURATE = 776
  437. }
  438. /** @hidden */
  439. export interface IGLTFProperty {
  440. extensions?: {
  441. [key: string]: any;
  442. };
  443. extras?: Object;
  444. }
  445. /** @hidden */
  446. export interface IGLTFChildRootProperty extends IGLTFProperty {
  447. name?: string;
  448. }
  449. /** @hidden */
  450. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  451. bufferView: string;
  452. byteOffset: number;
  453. byteStride: number;
  454. count: number;
  455. type: string;
  456. componentType: EComponentType;
  457. max?: number[];
  458. min?: number[];
  459. name?: string;
  460. }
  461. /** @hidden */
  462. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  463. buffer: string;
  464. byteOffset: number;
  465. byteLength: number;
  466. byteStride: number;
  467. target?: number;
  468. }
  469. /** @hidden */
  470. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  471. uri: string;
  472. byteLength?: number;
  473. type?: string;
  474. }
  475. /** @hidden */
  476. export interface IGLTFShader extends IGLTFChildRootProperty {
  477. uri: string;
  478. type: EShaderType;
  479. }
  480. /** @hidden */
  481. export interface IGLTFProgram extends IGLTFChildRootProperty {
  482. attributes: string[];
  483. fragmentShader: string;
  484. vertexShader: string;
  485. }
  486. /** @hidden */
  487. export interface IGLTFTechniqueParameter {
  488. type: number;
  489. count?: number;
  490. semantic?: string;
  491. node?: string;
  492. value?: number | boolean | string | Array<any>;
  493. source?: string;
  494. babylonValue?: any;
  495. }
  496. /** @hidden */
  497. export interface IGLTFTechniqueCommonProfile {
  498. lightingModel: string;
  499. texcoordBindings: Object;
  500. parameters?: Array<any>;
  501. }
  502. /** @hidden */
  503. export interface IGLTFTechniqueStatesFunctions {
  504. blendColor?: number[];
  505. blendEquationSeparate?: number[];
  506. blendFuncSeparate?: number[];
  507. colorMask: boolean[];
  508. cullFace: number[];
  509. }
  510. /** @hidden */
  511. export interface IGLTFTechniqueStates {
  512. enable: number[];
  513. functions: IGLTFTechniqueStatesFunctions;
  514. }
  515. /** @hidden */
  516. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  517. parameters: {
  518. [key: string]: IGLTFTechniqueParameter;
  519. };
  520. program: string;
  521. attributes: {
  522. [key: string]: string;
  523. };
  524. uniforms: {
  525. [key: string]: string;
  526. };
  527. states: IGLTFTechniqueStates;
  528. }
  529. /** @hidden */
  530. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  531. technique?: string;
  532. values: string[];
  533. }
  534. /** @hidden */
  535. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  536. attributes: {
  537. [key: string]: string;
  538. };
  539. indices: string;
  540. material: string;
  541. mode?: number;
  542. }
  543. /** @hidden */
  544. export interface IGLTFMesh extends IGLTFChildRootProperty {
  545. primitives: IGLTFMeshPrimitive[];
  546. }
  547. /** @hidden */
  548. export interface IGLTFImage extends IGLTFChildRootProperty {
  549. uri: string;
  550. }
  551. /** @hidden */
  552. export interface IGLTFSampler extends IGLTFChildRootProperty {
  553. magFilter?: number;
  554. minFilter?: number;
  555. wrapS?: number;
  556. wrapT?: number;
  557. }
  558. /** @hidden */
  559. export interface IGLTFTexture extends IGLTFChildRootProperty {
  560. sampler: string;
  561. source: string;
  562. format?: ETextureFormat;
  563. internalFormat?: ETextureFormat;
  564. target?: number;
  565. type?: number;
  566. babylonTexture?: Texture;
  567. }
  568. /** @hidden */
  569. export interface IGLTFAmbienLight {
  570. color?: number[];
  571. }
  572. /** @hidden */
  573. export interface IGLTFDirectionalLight {
  574. color?: number[];
  575. }
  576. /** @hidden */
  577. export interface IGLTFPointLight {
  578. color?: number[];
  579. constantAttenuation?: number;
  580. linearAttenuation?: number;
  581. quadraticAttenuation?: number;
  582. }
  583. /** @hidden */
  584. export interface IGLTFSpotLight {
  585. color?: number[];
  586. constantAttenuation?: number;
  587. fallOfAngle?: number;
  588. fallOffExponent?: number;
  589. linearAttenuation?: number;
  590. quadraticAttenuation?: number;
  591. }
  592. /** @hidden */
  593. export interface IGLTFLight extends IGLTFChildRootProperty {
  594. type: string;
  595. }
  596. /** @hidden */
  597. export interface IGLTFCameraOrthographic {
  598. xmag: number;
  599. ymag: number;
  600. zfar: number;
  601. znear: number;
  602. }
  603. /** @hidden */
  604. export interface IGLTFCameraPerspective {
  605. aspectRatio: number;
  606. yfov: number;
  607. zfar: number;
  608. znear: number;
  609. }
  610. /** @hidden */
  611. export interface IGLTFCamera extends IGLTFChildRootProperty {
  612. type: string;
  613. }
  614. /** @hidden */
  615. export interface IGLTFAnimationChannelTarget {
  616. id: string;
  617. path: string;
  618. }
  619. /** @hidden */
  620. export interface IGLTFAnimationChannel {
  621. sampler: string;
  622. target: IGLTFAnimationChannelTarget;
  623. }
  624. /** @hidden */
  625. export interface IGLTFAnimationSampler {
  626. input: string;
  627. output: string;
  628. interpolation?: string;
  629. }
  630. /** @hidden */
  631. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  632. channels?: IGLTFAnimationChannel[];
  633. parameters?: {
  634. [key: string]: string;
  635. };
  636. samplers?: {
  637. [key: string]: IGLTFAnimationSampler;
  638. };
  639. }
  640. /** @hidden */
  641. export interface IGLTFNodeInstanceSkin {
  642. skeletons: string[];
  643. skin: string;
  644. meshes: string[];
  645. }
  646. /** @hidden */
  647. export interface IGLTFSkins extends IGLTFChildRootProperty {
  648. bindShapeMatrix: number[];
  649. inverseBindMatrices: string;
  650. jointNames: string[];
  651. babylonSkeleton?: Skeleton;
  652. }
  653. /** @hidden */
  654. export interface IGLTFNode extends IGLTFChildRootProperty {
  655. camera?: string;
  656. children: string[];
  657. skin?: string;
  658. jointName?: string;
  659. light?: string;
  660. matrix: number[];
  661. mesh?: string;
  662. meshes?: string[];
  663. rotation?: number[];
  664. scale?: number[];
  665. translation?: number[];
  666. babylonNode?: Node;
  667. }
  668. /** @hidden */
  669. export interface IGLTFScene extends IGLTFChildRootProperty {
  670. nodes: string[];
  671. }
  672. /** @hidden */
  673. export interface IGLTFRuntime {
  674. extensions: {
  675. [key: string]: any;
  676. };
  677. accessors: {
  678. [key: string]: IGLTFAccessor;
  679. };
  680. buffers: {
  681. [key: string]: IGLTFBuffer;
  682. };
  683. bufferViews: {
  684. [key: string]: IGLTFBufferView;
  685. };
  686. meshes: {
  687. [key: string]: IGLTFMesh;
  688. };
  689. lights: {
  690. [key: string]: IGLTFLight;
  691. };
  692. cameras: {
  693. [key: string]: IGLTFCamera;
  694. };
  695. nodes: {
  696. [key: string]: IGLTFNode;
  697. };
  698. images: {
  699. [key: string]: IGLTFImage;
  700. };
  701. textures: {
  702. [key: string]: IGLTFTexture;
  703. };
  704. shaders: {
  705. [key: string]: IGLTFShader;
  706. };
  707. programs: {
  708. [key: string]: IGLTFProgram;
  709. };
  710. samplers: {
  711. [key: string]: IGLTFSampler;
  712. };
  713. techniques: {
  714. [key: string]: IGLTFTechnique;
  715. };
  716. materials: {
  717. [key: string]: IGLTFMaterial;
  718. };
  719. animations: {
  720. [key: string]: IGLTFAnimation;
  721. };
  722. skins: {
  723. [key: string]: IGLTFSkins;
  724. };
  725. currentScene?: Object;
  726. scenes: {
  727. [key: string]: IGLTFScene;
  728. };
  729. extensionsUsed: string[];
  730. extensionsRequired?: string[];
  731. buffersCount: number;
  732. shaderscount: number;
  733. scene: Scene;
  734. rootUrl: string;
  735. loadedBufferCount: number;
  736. loadedBufferViews: {
  737. [name: string]: ArrayBufferView;
  738. };
  739. loadedShaderCount: number;
  740. importOnlyMeshes: boolean;
  741. importMeshesNames?: string[];
  742. dummyNodes: Node[];
  743. }
  744. /** @hidden */
  745. export interface INodeToRoot {
  746. bone: Bone;
  747. node: IGLTFNode;
  748. id: string;
  749. }
  750. /** @hidden */
  751. export interface IJointNode {
  752. node: IGLTFNode;
  753. id: string;
  754. }
  755. }
  756. declare module BABYLON.GLTF1 {
  757. /**
  758. * Utils functions for GLTF
  759. * @hidden
  760. */
  761. export class GLTFUtils {
  762. /**
  763. * Sets the given "parameter" matrix
  764. * @param scene: the Scene object
  765. * @param source: the source node where to pick the matrix
  766. * @param parameter: the GLTF technique parameter
  767. * @param uniformName: the name of the shader's uniform
  768. * @param shaderMaterial: the shader material
  769. */
  770. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  771. /**
  772. * Sets the given "parameter" matrix
  773. * @param shaderMaterial: the shader material
  774. * @param uniform: the name of the shader's uniform
  775. * @param value: the value of the uniform
  776. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  777. */
  778. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  779. /**
  780. * Returns the wrap mode of the texture
  781. * @param mode: the mode value
  782. */
  783. static GetWrapMode(mode: number): number;
  784. /**
  785. * Returns the byte stride giving an accessor
  786. * @param accessor: the GLTF accessor objet
  787. */
  788. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  789. /**
  790. * Returns the texture filter mode giving a mode value
  791. * @param mode: the filter mode value
  792. */
  793. static GetTextureFilterMode(mode: number): ETextureFilterType;
  794. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  795. /**
  796. * Returns a buffer from its accessor
  797. * @param gltfRuntime: the GLTF runtime
  798. * @param accessor: the GLTF accessor
  799. */
  800. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  801. /**
  802. * Decodes a buffer view into a string
  803. * @param view: the buffer view
  804. */
  805. static DecodeBufferToText(view: ArrayBufferView): string;
  806. /**
  807. * Returns the default material of gltf. Related to
  808. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  809. * @param scene: the Babylon.js scene
  810. */
  811. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  812. private static _DefaultMaterial;
  813. }
  814. }
  815. declare module BABYLON.GLTF1 {
  816. /**
  817. * Implementation of the base glTF spec
  818. * @hidden
  819. */
  820. export class GLTFLoaderBase {
  821. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  822. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  823. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  824. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  825. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  826. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  827. }
  828. /**
  829. * glTF V1 Loader
  830. * @hidden
  831. */
  832. export class GLTFLoader implements IGLTFLoader {
  833. static Extensions: {
  834. [name: string]: GLTFLoaderExtension;
  835. };
  836. static RegisterExtension(extension: GLTFLoaderExtension): void;
  837. state: Nullable<GLTFLoaderState>;
  838. dispose(): void;
  839. private _importMeshAsync;
  840. /**
  841. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  842. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  843. * @param scene the scene the meshes should be added to
  844. * @param data gltf data containing information of the meshes in a loaded file
  845. * @param rootUrl root url to load from
  846. * @param onProgress event that fires when loading progress has occured
  847. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  848. */
  849. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  850. meshes: AbstractMesh[];
  851. particleSystems: IParticleSystem[];
  852. skeletons: Skeleton[];
  853. animationGroups: AnimationGroup[];
  854. }>;
  855. private _loadAsync;
  856. /**
  857. * Imports all objects from a loaded gltf file and adds them to the scene
  858. * @param scene the scene the objects should be added to
  859. * @param data gltf data containing information of the meshes in a loaded file
  860. * @param rootUrl root url to load from
  861. * @param onProgress event that fires when loading progress has occured
  862. * @returns a promise which completes when objects have been loaded to the scene
  863. */
  864. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  865. private _loadShadersAsync;
  866. private _loadBuffersAsync;
  867. private _createNodes;
  868. }
  869. /** @hidden */
  870. export abstract class GLTFLoaderExtension {
  871. private _name;
  872. constructor(name: string);
  873. readonly name: string;
  874. /**
  875. * Defines an override for loading the runtime
  876. * Return true to stop further extensions from loading the runtime
  877. */
  878. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  879. /**
  880. * Defines an onverride for creating gltf runtime
  881. * Return true to stop further extensions from creating the runtime
  882. */
  883. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  884. /**
  885. * Defines an override for loading buffers
  886. * Return true to stop further extensions from loading this buffer
  887. */
  888. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  889. /**
  890. * Defines an override for loading texture buffers
  891. * Return true to stop further extensions from loading this texture data
  892. */
  893. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  894. /**
  895. * Defines an override for creating textures
  896. * Return true to stop further extensions from loading this texture
  897. */
  898. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  899. /**
  900. * Defines an override for loading shader strings
  901. * Return true to stop further extensions from loading this shader data
  902. */
  903. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  904. /**
  905. * Defines an override for loading materials
  906. * Return true to stop further extensions from loading this material
  907. */
  908. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  909. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  910. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  911. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  912. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  913. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  914. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  915. private static LoadTextureBufferAsync;
  916. private static CreateTextureAsync;
  917. private static ApplyExtensions;
  918. }
  919. }
  920. declare module BABYLON.GLTF1 {
  921. /** @hidden */
  922. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  923. private _bin;
  924. constructor();
  925. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  926. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  927. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  928. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  929. }
  930. }
  931. declare module BABYLON.GLTF1 {
  932. /** @hidden */
  933. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  934. constructor();
  935. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  936. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  937. private _loadTexture;
  938. }
  939. }
  940. declare module BABYLON.GLTF2.Loader {
  941. /**
  942. * Loader interface with an index field.
  943. */
  944. export interface IArrayItem {
  945. /**
  946. * The index of this item in the array.
  947. */
  948. index: number;
  949. }
  950. /**
  951. * Loader interface with additional members.
  952. */
  953. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  954. /** @hidden */
  955. _data?: Promise<ArrayBufferView>;
  956. /** @hidden */
  957. _babylonVertexBuffer?: Promise<VertexBuffer>;
  958. }
  959. /**
  960. * Loader interface with additional members.
  961. */
  962. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  963. }
  964. /** @hidden */
  965. export interface _IAnimationSamplerData {
  966. input: Float32Array;
  967. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  968. output: Float32Array;
  969. }
  970. /**
  971. * Loader interface with additional members.
  972. */
  973. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  974. /** @hidden */
  975. _data?: Promise<_IAnimationSamplerData>;
  976. }
  977. /**
  978. * Loader interface with additional members.
  979. */
  980. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  981. channels: IAnimationChannel[];
  982. samplers: IAnimationSampler[];
  983. /** @hidden */
  984. _babylonAnimationGroup?: AnimationGroup;
  985. }
  986. /**
  987. * Loader interface with additional members.
  988. */
  989. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  990. /** @hidden */
  991. _data?: Promise<ArrayBufferView>;
  992. }
  993. /**
  994. * Loader interface with additional members.
  995. */
  996. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  997. /** @hidden */
  998. _data?: Promise<ArrayBufferView>;
  999. /** @hidden */
  1000. _babylonBuffer?: Promise<Buffer>;
  1001. }
  1002. /**
  1003. * Loader interface with additional members.
  1004. */
  1005. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  1006. }
  1007. /**
  1008. * Loader interface with additional members.
  1009. */
  1010. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  1011. /** @hidden */
  1012. _data?: Promise<ArrayBufferView>;
  1013. }
  1014. /**
  1015. * Loader interface with additional members.
  1016. */
  1017. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1018. }
  1019. /**
  1020. * Loader interface with additional members.
  1021. */
  1022. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1023. }
  1024. /**
  1025. * Loader interface with additional members.
  1026. */
  1027. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  1028. baseColorTexture?: ITextureInfo;
  1029. metallicRoughnessTexture?: ITextureInfo;
  1030. }
  1031. /**
  1032. * Loader interface with additional members.
  1033. */
  1034. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  1035. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1036. normalTexture?: IMaterialNormalTextureInfo;
  1037. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1038. emissiveTexture?: ITextureInfo;
  1039. /** @hidden */
  1040. _data?: {
  1041. [babylonDrawMode: number]: {
  1042. babylonMaterial: Material;
  1043. babylonMeshes: AbstractMesh[];
  1044. promise: Promise<void>;
  1045. };
  1046. };
  1047. }
  1048. /**
  1049. * Loader interface with additional members.
  1050. */
  1051. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  1052. primitives: IMeshPrimitive[];
  1053. }
  1054. /**
  1055. * Loader interface with additional members.
  1056. */
  1057. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  1058. /** @hidden */
  1059. _instanceData?: {
  1060. babylonSourceMesh: Mesh;
  1061. promise: Promise<any>;
  1062. };
  1063. }
  1064. /**
  1065. * Loader interface with additional members.
  1066. */
  1067. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  1068. /**
  1069. * The parent glTF node.
  1070. */
  1071. parent?: INode;
  1072. /** @hidden */
  1073. _babylonTransformNode?: TransformNode;
  1074. /** @hidden */
  1075. _primitiveBabylonMeshes?: AbstractMesh[];
  1076. /** @hidden */
  1077. _babylonBones?: Bone[];
  1078. /** @hidden */
  1079. _numMorphTargets?: number;
  1080. }
  1081. /** @hidden */
  1082. export interface _ISamplerData {
  1083. noMipMaps: boolean;
  1084. samplingMode: number;
  1085. wrapU: number;
  1086. wrapV: number;
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  1092. /** @hidden */
  1093. _data?: _ISamplerData;
  1094. }
  1095. /**
  1096. * Loader interface with additional members.
  1097. */
  1098. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  1099. }
  1100. /**
  1101. * Loader interface with additional members.
  1102. */
  1103. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  1104. /** @hidden */
  1105. _data?: {
  1106. babylonSkeleton: Skeleton;
  1107. promise: Promise<void>;
  1108. };
  1109. }
  1110. /**
  1111. * Loader interface with additional members.
  1112. */
  1113. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  1114. }
  1115. /**
  1116. * Loader interface with additional members.
  1117. */
  1118. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  1119. }
  1120. /**
  1121. * Loader interface with additional members.
  1122. */
  1123. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  1124. accessors?: IAccessor[];
  1125. animations?: IAnimation[];
  1126. buffers?: IBuffer[];
  1127. bufferViews?: IBufferView[];
  1128. cameras?: ICamera[];
  1129. images?: IImage[];
  1130. materials?: IMaterial[];
  1131. meshes?: IMesh[];
  1132. nodes?: INode[];
  1133. samplers?: ISampler[];
  1134. scenes?: IScene[];
  1135. skins?: ISkin[];
  1136. textures?: ITexture[];
  1137. }
  1138. }
  1139. declare module BABYLON.GLTF2 {
  1140. /**
  1141. * Interface for a glTF loader extension.
  1142. */
  1143. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1144. /**
  1145. * Called after the loader state changes to LOADING.
  1146. */
  1147. onLoading?(): void;
  1148. /**
  1149. * Called after the loader state changes to READY.
  1150. */
  1151. onReady?(): void;
  1152. /**
  1153. * Define this method to modify the default behavior when loading scenes.
  1154. * @param context The context when loading the asset
  1155. * @param scene The glTF scene property
  1156. * @returns A promise that resolves when the load is complete or null if not handled
  1157. */
  1158. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1159. /**
  1160. * Define this method to modify the default behavior when loading nodes.
  1161. * @param context The context when loading the asset
  1162. * @param node The glTF node property
  1163. * @param assign A function called synchronously after parsing the glTF properties
  1164. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1165. */
  1166. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1167. /**
  1168. * Define this method to modify the default behavior when loading cameras.
  1169. * @param context The context when loading the asset
  1170. * @param camera The glTF camera property
  1171. * @param assign A function called synchronously after parsing the glTF properties
  1172. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1173. */
  1174. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1175. /**
  1176. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1177. * @param context The context when loading the asset
  1178. * @param primitive The glTF mesh primitive property
  1179. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1180. */
  1181. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1182. /**
  1183. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1184. * @param context The context when loading the asset
  1185. * @param name The mesh name when loading the asset
  1186. * @param node The glTF node when loading the asset
  1187. * @param mesh The glTF mesh when loading the asset
  1188. * @param primitive The glTF mesh primitive property
  1189. * @param assign A function called synchronously after parsing the glTF properties
  1190. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1191. */
  1192. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1193. /**
  1194. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1195. * @param context The context when loading the asset
  1196. * @param material The glTF material property
  1197. * @param assign A function called synchronously after parsing the glTF properties
  1198. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1199. */
  1200. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1201. /**
  1202. * Define this method to modify the default behavior when creating materials.
  1203. * @param context The context when loading the asset
  1204. * @param material The glTF material property
  1205. * @param babylonDrawMode The draw mode for the Babylon material
  1206. * @returns The Babylon material or null if not handled
  1207. */
  1208. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1209. /**
  1210. * Define this method to modify the default behavior when loading material properties.
  1211. * @param context The context when loading the asset
  1212. * @param material The glTF material property
  1213. * @param babylonMaterial The Babylon material
  1214. * @returns A promise that resolves when the load is complete or null if not handled
  1215. */
  1216. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1217. /**
  1218. * Define this method to modify the default behavior when loading texture infos.
  1219. * @param context The context when loading the asset
  1220. * @param textureInfo The glTF texture info property
  1221. * @param assign A function called synchronously after parsing the glTF properties
  1222. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1223. */
  1224. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1225. /**
  1226. * Define this method to modify the default behavior when loading animations.
  1227. * @param context The context when loading the asset
  1228. * @param animation The glTF animation property
  1229. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1230. */
  1231. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1232. /**
  1233. * @hidden Define this method to modify the default behavior when loading skins.
  1234. * @param context The context when loading the asset
  1235. * @param node The glTF node property
  1236. * @param skin The glTF skin property
  1237. * @returns A promise that resolves when the load is complete or null if not handled
  1238. */
  1239. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1240. /**
  1241. * @hidden Define this method to modify the default behavior when loading uris.
  1242. * @param context The context when loading the asset
  1243. * @param property The glTF property associated with the uri
  1244. * @param uri The uri to load
  1245. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1246. */
  1247. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1248. }
  1249. }
  1250. declare module BABYLON.GLTF2 {
  1251. /**
  1252. * Helper class for working with arrays when loading the glTF asset
  1253. */
  1254. export class ArrayItem {
  1255. /**
  1256. * Gets an item from the given array.
  1257. * @param context The context when loading the asset
  1258. * @param array The array to get the item from
  1259. * @param index The index to the array
  1260. * @returns The array item
  1261. */
  1262. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1263. /**
  1264. * Assign an `index` field to each item of the given array.
  1265. * @param array The array of items
  1266. */
  1267. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1268. }
  1269. /**
  1270. * The glTF 2.0 loader
  1271. */
  1272. export class GLTFLoader implements IGLTFLoader {
  1273. /** @hidden */
  1274. _completePromises: Promise<any>[];
  1275. private _disposed;
  1276. private _parent;
  1277. private _state;
  1278. private _extensions;
  1279. private _rootUrl;
  1280. private _fileName;
  1281. private _uniqueRootUrl;
  1282. private _gltf;
  1283. private _babylonScene;
  1284. private _rootBabylonMesh;
  1285. private _defaultBabylonMaterialData;
  1286. private _progressCallback?;
  1287. private _requests;
  1288. private static readonly _DefaultSampler;
  1289. private static _ExtensionNames;
  1290. private static _ExtensionFactories;
  1291. /**
  1292. * Registers a loader extension.
  1293. * @param name The name of the loader extension.
  1294. * @param factory The factory function that creates the loader extension.
  1295. */
  1296. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1297. /**
  1298. * Unregisters a loader extension.
  1299. * @param name The name of the loader extenion.
  1300. * @returns A boolean indicating whether the extension has been unregistered
  1301. */
  1302. static UnregisterExtension(name: string): boolean;
  1303. /**
  1304. * Gets the loader state.
  1305. */
  1306. readonly state: Nullable<GLTFLoaderState>;
  1307. /**
  1308. * The glTF object parsed from the JSON.
  1309. */
  1310. readonly gltf: IGLTF;
  1311. /**
  1312. * The Babylon scene when loading the asset.
  1313. */
  1314. readonly babylonScene: Scene;
  1315. /**
  1316. * The root Babylon mesh when loading the asset.
  1317. */
  1318. readonly rootBabylonMesh: Mesh;
  1319. /** @hidden */
  1320. constructor(parent: GLTFFileLoader);
  1321. /** @hidden */
  1322. dispose(): void;
  1323. /** @hidden */
  1324. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1325. meshes: AbstractMesh[];
  1326. particleSystems: IParticleSystem[];
  1327. skeletons: Skeleton[];
  1328. animationGroups: AnimationGroup[];
  1329. }>;
  1330. /** @hidden */
  1331. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1332. private _loadAsync;
  1333. private _loadData;
  1334. private _setupData;
  1335. private _loadExtensions;
  1336. private _checkExtensions;
  1337. private _setState;
  1338. private _createRootNode;
  1339. /**
  1340. * Loads a glTF scene.
  1341. * @param context The context when loading the asset
  1342. * @param scene The glTF scene property
  1343. * @returns A promise that resolves when the load is complete
  1344. */
  1345. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1346. private _forEachPrimitive;
  1347. private _getMeshes;
  1348. private _getSkeletons;
  1349. private _getAnimationGroups;
  1350. private _startAnimations;
  1351. /**
  1352. * Loads a glTF node.
  1353. * @param context The context when loading the asset
  1354. * @param node The glTF node property
  1355. * @param assign A function called synchronously after parsing the glTF properties
  1356. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1357. */
  1358. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1359. private _loadMeshAsync;
  1360. /**
  1361. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1362. * @param context The context when loading the asset
  1363. * @param name The mesh name when loading the asset
  1364. * @param node The glTF node when loading the asset
  1365. * @param mesh The glTF mesh when loading the asset
  1366. * @param primitive The glTF mesh primitive property
  1367. * @param assign A function called synchronously after parsing the glTF properties
  1368. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1369. */
  1370. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1371. private _loadVertexDataAsync;
  1372. private _createMorphTargets;
  1373. private _loadMorphTargetsAsync;
  1374. private _loadMorphTargetVertexDataAsync;
  1375. private static _LoadTransform;
  1376. private _loadSkinAsync;
  1377. private _loadBones;
  1378. private _loadBone;
  1379. private _loadSkinInverseBindMatricesDataAsync;
  1380. private _updateBoneMatrices;
  1381. private _getNodeMatrix;
  1382. /**
  1383. * Loads a glTF camera.
  1384. * @param context The context when loading the asset
  1385. * @param camera The glTF camera property
  1386. * @param assign A function called synchronously after parsing the glTF properties
  1387. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1388. */
  1389. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1390. private _loadAnimationsAsync;
  1391. /**
  1392. * Loads a glTF animation.
  1393. * @param context The context when loading the asset
  1394. * @param animation The glTF animation property
  1395. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1396. */
  1397. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1398. /**
  1399. * @hidden Loads a glTF animation channel.
  1400. * @param context The context when loading the asset
  1401. * @param animationContext The context of the animation when loading the asset
  1402. * @param animation The glTF animation property
  1403. * @param channel The glTF animation channel property
  1404. * @param babylonAnimationGroup The babylon animation group property
  1405. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1406. * @returns A void promise when the channel load is complete
  1407. */
  1408. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1409. private _loadAnimationSamplerAsync;
  1410. private _loadBufferAsync;
  1411. /**
  1412. * Loads a glTF buffer view.
  1413. * @param context The context when loading the asset
  1414. * @param bufferView The glTF buffer view property
  1415. * @returns A promise that resolves with the loaded data when the load is complete
  1416. */
  1417. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1418. private _loadIndicesAccessorAsync;
  1419. private _loadFloatAccessorAsync;
  1420. private _loadVertexBufferViewAsync;
  1421. private _loadVertexAccessorAsync;
  1422. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1423. /** @hidden */
  1424. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1425. private _createDefaultMaterial;
  1426. /**
  1427. * Creates a Babylon material from a glTF material.
  1428. * @param context The context when loading the asset
  1429. * @param material The glTF material property
  1430. * @param babylonDrawMode The draw mode for the Babylon material
  1431. * @returns The Babylon material
  1432. */
  1433. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1434. /**
  1435. * Loads properties from a glTF material into a Babylon material.
  1436. * @param context The context when loading the asset
  1437. * @param material The glTF material property
  1438. * @param babylonMaterial The Babylon material
  1439. * @returns A promise that resolves when the load is complete
  1440. */
  1441. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1442. /**
  1443. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1444. * @param context The context when loading the asset
  1445. * @param material The glTF material property
  1446. * @param babylonMaterial The Babylon material
  1447. * @returns A promise that resolves when the load is complete
  1448. */
  1449. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1450. /**
  1451. * Loads the alpha properties from a glTF material into a Babylon material.
  1452. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1453. * @param context The context when loading the asset
  1454. * @param material The glTF material property
  1455. * @param babylonMaterial The Babylon material
  1456. */
  1457. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1458. /**
  1459. * Loads a glTF texture info.
  1460. * @param context The context when loading the asset
  1461. * @param textureInfo The glTF texture info property
  1462. * @param assign A function called synchronously after parsing the glTF properties
  1463. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1464. */
  1465. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1466. private _loadTextureAsync;
  1467. private _loadSampler;
  1468. /**
  1469. * Loads a glTF image.
  1470. * @param context The context when loading the asset
  1471. * @param image The glTF image property
  1472. * @returns A promise that resolves with the loaded data when the load is complete
  1473. */
  1474. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1475. /**
  1476. * Loads a glTF uri.
  1477. * @param context The context when loading the asset
  1478. * @param property The glTF property associated with the uri
  1479. * @param uri The base64 or relative uri
  1480. * @returns A promise that resolves with the loaded data when the load is complete
  1481. */
  1482. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1483. private _onProgress;
  1484. /**
  1485. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1486. * @param babylonObject the Babylon object with metadata
  1487. * @param pointer the JSON pointer
  1488. */
  1489. static AddPointerMetadata(babylonObject: {
  1490. metadata: any;
  1491. }, pointer: string): void;
  1492. private static _GetTextureWrapMode;
  1493. private static _GetTextureSamplingMode;
  1494. private static _GetTypedArray;
  1495. private static _GetNumComponents;
  1496. private static _ValidateUri;
  1497. private static _GetDrawMode;
  1498. private _compileMaterialsAsync;
  1499. private _compileShadowGeneratorsAsync;
  1500. private _forEachExtensions;
  1501. private _applyExtensions;
  1502. private _extensionsOnLoading;
  1503. private _extensionsOnReady;
  1504. private _extensionsLoadSceneAsync;
  1505. private _extensionsLoadNodeAsync;
  1506. private _extensionsLoadCameraAsync;
  1507. private _extensionsLoadVertexDataAsync;
  1508. private _extensionsLoadMeshPrimitiveAsync;
  1509. private _extensionsLoadMaterialAsync;
  1510. private _extensionsCreateMaterial;
  1511. private _extensionsLoadMaterialPropertiesAsync;
  1512. private _extensionsLoadTextureInfoAsync;
  1513. private _extensionsLoadAnimationAsync;
  1514. private _extensionsLoadSkinAsync;
  1515. private _extensionsLoadUriAsync;
  1516. /**
  1517. * Helper method called by a loader extension to load an glTF extension.
  1518. * @param context The context when loading the asset
  1519. * @param property The glTF property to load the extension from
  1520. * @param extensionName The name of the extension to load
  1521. * @param actionAsync The action to run
  1522. * @returns The promise returned by actionAsync or null if the extension does not exist
  1523. */
  1524. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1525. /**
  1526. * Helper method called by a loader extension to load a glTF extra.
  1527. * @param context The context when loading the asset
  1528. * @param property The glTF property to load the extra from
  1529. * @param extensionName The name of the extension to load
  1530. * @param actionAsync The action to run
  1531. * @returns The promise returned by actionAsync or null if the extra does not exist
  1532. */
  1533. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1534. /**
  1535. * Increments the indentation level and logs a message.
  1536. * @param message The message to log
  1537. */
  1538. logOpen(message: string): void;
  1539. /**
  1540. * Decrements the indentation level.
  1541. */
  1542. logClose(): void;
  1543. /**
  1544. * Logs a message
  1545. * @param message The message to log
  1546. */
  1547. log(message: string): void;
  1548. /**
  1549. * Starts a performance counter.
  1550. * @param counterName The name of the performance counter
  1551. */
  1552. startPerformanceCounter(counterName: string): void;
  1553. /**
  1554. * Ends a performance counter.
  1555. * @param counterName The name of the performance counter
  1556. */
  1557. endPerformanceCounter(counterName: string): void;
  1558. }
  1559. }
  1560. declare module BABYLON.GLTF2.Loader.Extensions {
  1561. /**
  1562. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1563. */
  1564. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1565. /** The name of this extension. */
  1566. readonly name: string;
  1567. /** Defines whether this extension is enabled. */
  1568. enabled: boolean;
  1569. private _loader;
  1570. private _lights?;
  1571. /** @hidden */
  1572. constructor(loader: GLTFLoader);
  1573. /** @hidden */
  1574. dispose(): void;
  1575. /** @hidden */
  1576. onLoading(): void;
  1577. /** @hidden */
  1578. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1579. private _loadLightAsync;
  1580. }
  1581. }
  1582. declare module BABYLON.GLTF2.Loader.Extensions {
  1583. /**
  1584. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1585. */
  1586. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1587. /** The name of this extension. */
  1588. readonly name: string;
  1589. /** The draco compression used to decode vertex data or DracoCompression.Default if not defined */
  1590. dracoCompression?: DracoCompression;
  1591. /** Defines whether this extension is enabled. */
  1592. enabled: boolean;
  1593. private _loader;
  1594. /** @hidden */
  1595. constructor(loader: GLTFLoader);
  1596. /** @hidden */
  1597. dispose(): void;
  1598. /** @hidden */
  1599. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1600. }
  1601. }
  1602. declare module BABYLON.GLTF2.Loader.Extensions {
  1603. /**
  1604. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1605. */
  1606. export class KHR_lights implements IGLTFLoaderExtension {
  1607. /** The name of this extension. */
  1608. readonly name: string;
  1609. /** Defines whether this extension is enabled. */
  1610. enabled: boolean;
  1611. private _loader;
  1612. private _lights?;
  1613. /** @hidden */
  1614. constructor(loader: GLTFLoader);
  1615. /** @hidden */
  1616. dispose(): void;
  1617. /** @hidden */
  1618. onLoading(): void;
  1619. /** @hidden */
  1620. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1621. }
  1622. }
  1623. declare module BABYLON.GLTF2.Loader.Extensions {
  1624. /**
  1625. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1626. */
  1627. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1628. /** The name of this extension. */
  1629. readonly name: string;
  1630. /** Defines whether this extension is enabled. */
  1631. enabled: boolean;
  1632. private _loader;
  1633. /** @hidden */
  1634. constructor(loader: GLTFLoader);
  1635. /** @hidden */
  1636. dispose(): void;
  1637. /** @hidden */
  1638. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1639. private _loadSpecularGlossinessPropertiesAsync;
  1640. }
  1641. }
  1642. declare module BABYLON.GLTF2.Loader.Extensions {
  1643. /**
  1644. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1645. */
  1646. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1647. /** The name of this extension. */
  1648. readonly name: string;
  1649. /** Defines whether this extension is enabled. */
  1650. enabled: boolean;
  1651. private _loader;
  1652. /** @hidden */
  1653. constructor(loader: GLTFLoader);
  1654. /** @hidden */
  1655. dispose(): void;
  1656. /** @hidden */
  1657. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1658. private _loadUnlitPropertiesAsync;
  1659. }
  1660. }
  1661. declare module BABYLON.GLTF2.Loader.Extensions {
  1662. /**
  1663. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1664. */
  1665. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1666. /** The name of this extension. */
  1667. readonly name: string;
  1668. /** Defines whether this extension is enabled. */
  1669. enabled: boolean;
  1670. private _loader;
  1671. /** @hidden */
  1672. constructor(loader: GLTFLoader);
  1673. /** @hidden */
  1674. dispose(): void;
  1675. /** @hidden */
  1676. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1677. }
  1678. }
  1679. declare module BABYLON.GLTF2.Loader.Extensions {
  1680. /**
  1681. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1682. */
  1683. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1684. /** The name of this extension. */
  1685. readonly name: string;
  1686. /** Defines whether this extension is enabled. */
  1687. enabled: boolean;
  1688. private _loader;
  1689. private _clips;
  1690. private _emitters;
  1691. /** @hidden */
  1692. constructor(loader: GLTFLoader);
  1693. /** @hidden */
  1694. dispose(): void;
  1695. /** @hidden */
  1696. onLoading(): void;
  1697. /** @hidden */
  1698. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1699. /** @hidden */
  1700. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1701. /** @hidden */
  1702. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1703. private _loadClipAsync;
  1704. private _loadEmitterAsync;
  1705. private _getEventAction;
  1706. private _loadAnimationEventAsync;
  1707. }
  1708. }
  1709. declare module BABYLON.GLTF2.Loader.Extensions {
  1710. /**
  1711. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1712. */
  1713. export class MSFT_lod implements IGLTFLoaderExtension {
  1714. /** The name of this extension. */
  1715. readonly name: string;
  1716. /** Defines whether this extension is enabled. */
  1717. enabled: boolean;
  1718. /**
  1719. * Maximum number of LODs to load, starting from the lowest LOD.
  1720. */
  1721. maxLODsToLoad: number;
  1722. /**
  1723. * Observable raised when all node LODs of one level are loaded.
  1724. * The event data is the index of the loaded LOD starting from zero.
  1725. * Dispose the loader to cancel the loading of the next level of LODs.
  1726. */
  1727. onNodeLODsLoadedObservable: Observable<number>;
  1728. /**
  1729. * Observable raised when all material LODs of one level are loaded.
  1730. * The event data is the index of the loaded LOD starting from zero.
  1731. * Dispose the loader to cancel the loading of the next level of LODs.
  1732. */
  1733. onMaterialLODsLoadedObservable: Observable<number>;
  1734. private _loader;
  1735. private _nodeIndexLOD;
  1736. private _nodeSignalLODs;
  1737. private _nodePromiseLODs;
  1738. private _materialIndexLOD;
  1739. private _materialSignalLODs;
  1740. private _materialPromiseLODs;
  1741. /** @hidden */
  1742. constructor(loader: GLTFLoader);
  1743. /** @hidden */
  1744. dispose(): void;
  1745. /** @hidden */
  1746. onReady(): void;
  1747. /** @hidden */
  1748. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1749. /** @hidden */
  1750. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1751. /** @hidden */
  1752. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1753. /**
  1754. * Gets an array of LOD properties from lowest to highest.
  1755. */
  1756. private _getLODs;
  1757. private _disposeUnusedMaterials;
  1758. }
  1759. }
  1760. declare module BABYLON.GLTF2.Loader.Extensions {
  1761. /** @hidden */
  1762. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1763. readonly name: string;
  1764. enabled: boolean;
  1765. private _loader;
  1766. constructor(loader: GLTFLoader);
  1767. dispose(): void;
  1768. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1769. }
  1770. }
  1771. declare module BABYLON.GLTF2.Loader.Extensions {
  1772. /** @hidden */
  1773. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1774. readonly name: string;
  1775. enabled: boolean;
  1776. private _loader;
  1777. constructor(loader: GLTFLoader);
  1778. dispose(): void;
  1779. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1780. }
  1781. }
  1782. declare module BABYLON {
  1783. /**
  1784. * Class reading and parsing the MTL file bundled with the obj file.
  1785. */
  1786. export class MTLFileLoader {
  1787. /**
  1788. * All material loaded from the mtl will be set here
  1789. */
  1790. materials: StandardMaterial[];
  1791. /**
  1792. * This function will read the mtl file and create each material described inside
  1793. * This function could be improve by adding :
  1794. * -some component missing (Ni, Tf...)
  1795. * -including the specific options available
  1796. *
  1797. * @param scene defines the scene the material will be created in
  1798. * @param data defines the mtl data to parse
  1799. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1800. */
  1801. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1802. /**
  1803. * Gets the texture for the material.
  1804. *
  1805. * If the material is imported from input file,
  1806. * We sanitize the url to ensure it takes the textre from aside the material.
  1807. *
  1808. * @param rootUrl The root url to load from
  1809. * @param value The value stored in the mtl
  1810. * @return The Texture
  1811. */
  1812. private static _getTexture;
  1813. }
  1814. /**
  1815. * Options for loading OBJ/MTL files
  1816. */
  1817. type MeshLoadOptions = {
  1818. /**
  1819. * Defines if UVs are optimized by default during load.
  1820. */
  1821. OptimizeWithUV: boolean;
  1822. /**
  1823. * Defines custom scaling of UV coordinates of loaded meshes.
  1824. */
  1825. UVScaling: Vector2;
  1826. /**
  1827. * Invert model on y-axis (does a model scaling inversion)
  1828. */
  1829. InvertY: boolean;
  1830. /**
  1831. * Invert Y-Axis of referenced textures on load
  1832. */
  1833. InvertTextureY: boolean;
  1834. /**
  1835. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1836. */
  1837. ImportVertexColors: boolean;
  1838. /**
  1839. * Compute the normals for the model, even if normals are present in the file.
  1840. */
  1841. ComputeNormals: boolean;
  1842. /**
  1843. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1844. */
  1845. SkipMaterials: boolean;
  1846. /**
  1847. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1848. */
  1849. MaterialLoadingFailsSilently: boolean;
  1850. };
  1851. /**
  1852. * OBJ file type loader.
  1853. * This is a babylon scene loader plugin.
  1854. */
  1855. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  1856. /**
  1857. * Defines if UVs are optimized by default during load.
  1858. */
  1859. static OPTIMIZE_WITH_UV: boolean;
  1860. /**
  1861. * Invert model on y-axis (does a model scaling inversion)
  1862. */
  1863. static INVERT_Y: boolean;
  1864. /**
  1865. * Invert Y-Axis of referenced textures on load
  1866. */
  1867. static INVERT_TEXTURE_Y: boolean;
  1868. /**
  1869. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1870. */
  1871. static IMPORT_VERTEX_COLORS: boolean;
  1872. /**
  1873. * Compute the normals for the model, even if normals are present in the file.
  1874. */
  1875. static COMPUTE_NORMALS: boolean;
  1876. /**
  1877. * Defines custom scaling of UV coordinates of loaded meshes.
  1878. */
  1879. static UV_SCALING: Vector2;
  1880. /**
  1881. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1882. */
  1883. static SKIP_MATERIALS: boolean;
  1884. /**
  1885. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1886. *
  1887. * Defaults to true for backwards compatibility.
  1888. */
  1889. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  1890. /**
  1891. * Defines the name of the plugin.
  1892. */
  1893. name: string;
  1894. /**
  1895. * Defines the extension the plugin is able to load.
  1896. */
  1897. extensions: string;
  1898. /** @hidden */
  1899. obj: RegExp;
  1900. /** @hidden */
  1901. group: RegExp;
  1902. /** @hidden */
  1903. mtllib: RegExp;
  1904. /** @hidden */
  1905. usemtl: RegExp;
  1906. /** @hidden */
  1907. smooth: RegExp;
  1908. /** @hidden */
  1909. vertexPattern: RegExp;
  1910. /** @hidden */
  1911. normalPattern: RegExp;
  1912. /** @hidden */
  1913. uvPattern: RegExp;
  1914. /** @hidden */
  1915. facePattern1: RegExp;
  1916. /** @hidden */
  1917. facePattern2: RegExp;
  1918. /** @hidden */
  1919. facePattern3: RegExp;
  1920. /** @hidden */
  1921. facePattern4: RegExp;
  1922. /** @hidden */
  1923. facePattern5: RegExp;
  1924. private _meshLoadOptions;
  1925. /**
  1926. * Creates loader for .OBJ files
  1927. *
  1928. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  1929. */
  1930. constructor(meshLoadOptions?: MeshLoadOptions);
  1931. private static readonly currentMeshLoadOptions;
  1932. /**
  1933. * Calls synchronously the MTL file attached to this obj.
  1934. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  1935. * Without this function materials are not displayed in the first frame (but displayed after).
  1936. * In consequence it is impossible to get material information in your HTML file
  1937. *
  1938. * @param url The URL of the MTL file
  1939. * @param rootUrl
  1940. * @param onSuccess Callback function to be called when the MTL file is loaded
  1941. * @private
  1942. */
  1943. private _loadMTL;
  1944. /**
  1945. * Instantiates a OBJ file loader plugin.
  1946. * @returns the created plugin
  1947. */
  1948. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  1949. /**
  1950. * If the data string can be loaded directly.
  1951. *
  1952. * @param data string containing the file data
  1953. * @returns if the data can be loaded directly
  1954. */
  1955. canDirectLoad(data: string): boolean;
  1956. /**
  1957. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  1958. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1959. * @param scene the scene the meshes should be added to
  1960. * @param data the OBJ data to load
  1961. * @param rootUrl root url to load from
  1962. * @param onProgress event that fires when loading progress has occured
  1963. * @param fileName Defines the name of the file to load
  1964. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1965. */
  1966. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1967. meshes: AbstractMesh[];
  1968. particleSystems: IParticleSystem[];
  1969. skeletons: Skeleton[];
  1970. animationGroups: AnimationGroup[];
  1971. }>;
  1972. /**
  1973. * Imports all objects from the loaded OBJ data and adds them to the scene
  1974. * @param scene the scene the objects should be added to
  1975. * @param data the OBJ data to load
  1976. * @param rootUrl root url to load from
  1977. * @param onProgress event that fires when loading progress has occured
  1978. * @param fileName Defines the name of the file to load
  1979. * @returns a promise which completes when objects have been loaded to the scene
  1980. */
  1981. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1982. /**
  1983. * Load into an asset container.
  1984. * @param scene The scene to load into
  1985. * @param data The data to import
  1986. * @param rootUrl The root url for scene and resources
  1987. * @param onProgress The callback when the load progresses
  1988. * @param fileName Defines the name of the file to load
  1989. * @returns The loaded asset container
  1990. */
  1991. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  1992. /**
  1993. * Read the OBJ file and create an Array of meshes.
  1994. * Each mesh contains all information given by the OBJ and the MTL file.
  1995. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  1996. *
  1997. * @param meshesNames
  1998. * @param scene Scene The scene where are displayed the data
  1999. * @param data String The content of the obj file
  2000. * @param rootUrl String The path to the folder
  2001. * @returns Array<AbstractMesh>
  2002. * @private
  2003. */
  2004. private _parseSolid;
  2005. }
  2006. }
  2007. declare module BABYLON {
  2008. /**
  2009. * STL file type loader.
  2010. * This is a babylon scene loader plugin.
  2011. */
  2012. export class STLFileLoader implements ISceneLoaderPlugin {
  2013. /** @hidden */
  2014. solidPattern: RegExp;
  2015. /** @hidden */
  2016. facetsPattern: RegExp;
  2017. /** @hidden */
  2018. normalPattern: RegExp;
  2019. /** @hidden */
  2020. vertexPattern: RegExp;
  2021. /**
  2022. * Defines the name of the plugin.
  2023. */
  2024. name: string;
  2025. /**
  2026. * Defines the extensions the stl loader is able to load.
  2027. * force data to come in as an ArrayBuffer
  2028. * we'll convert to string if it looks like it's an ASCII .stl
  2029. */
  2030. extensions: ISceneLoaderPluginExtensions;
  2031. /**
  2032. * Import meshes into a scene.
  2033. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2034. * @param scene The scene to import into
  2035. * @param data The data to import
  2036. * @param rootUrl The root url for scene and resources
  2037. * @param meshes The meshes array to import into
  2038. * @param particleSystems The particle systems array to import into
  2039. * @param skeletons The skeletons array to import into
  2040. * @param onError The callback when import fails
  2041. * @returns True if successful or false otherwise
  2042. */
  2043. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2044. /**
  2045. * Load into a scene.
  2046. * @param scene The scene to load into
  2047. * @param data The data to import
  2048. * @param rootUrl The root url for scene and resources
  2049. * @param onError The callback when import fails
  2050. * @returns true if successful or false otherwise
  2051. */
  2052. load(scene: Scene, data: any, rootUrl: string): boolean;
  2053. /**
  2054. * Load into an asset container.
  2055. * @param scene The scene to load into
  2056. * @param data The data to import
  2057. * @param rootUrl The root url for scene and resources
  2058. * @param onError The callback when import fails
  2059. * @returns The loaded asset container
  2060. */
  2061. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2062. private _isBinary;
  2063. private _parseBinary;
  2064. private _parseASCII;
  2065. }
  2066. }