babylonjs.loaders.d.ts 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  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 materials. Load material creates the material and then loads material properties.
  1184. * @param context The context when loading the asset
  1185. * @param material The glTF material property
  1186. * @param assign A function called synchronously after parsing the glTF properties
  1187. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1188. */
  1189. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1190. /**
  1191. * Define this method to modify the default behavior when creating materials.
  1192. * @param context The context when loading the asset
  1193. * @param material The glTF material property
  1194. * @param babylonDrawMode The draw mode for the Babylon material
  1195. * @returns The Babylon material or null if not handled
  1196. */
  1197. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1198. /**
  1199. * Define this method to modify the default behavior when loading material properties.
  1200. * @param context The context when loading the asset
  1201. * @param material The glTF material property
  1202. * @param babylonMaterial The Babylon material
  1203. * @returns A promise that resolves when the load is complete or null if not handled
  1204. */
  1205. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1206. /**
  1207. * Define this method to modify the default behavior when loading texture infos.
  1208. * @param context The context when loading the asset
  1209. * @param textureInfo The glTF texture info property
  1210. * @param assign A function called synchronously after parsing the glTF properties
  1211. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1212. */
  1213. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1214. /**
  1215. * Define this method to modify the default behavior when loading animations.
  1216. * @param context The context when loading the asset
  1217. * @param animation The glTF animation property
  1218. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1219. */
  1220. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1221. /**
  1222. * Define this method to modify the default behavior when loading uris.
  1223. * @param context The context when loading the asset
  1224. * @param property The glTF property associated with the uri
  1225. * @param uri The uri to load
  1226. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1227. */
  1228. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1229. }
  1230. }
  1231. declare module BABYLON.GLTF2 {
  1232. /**
  1233. * Helper class for working with arrays when loading the glTF asset
  1234. */
  1235. export class ArrayItem {
  1236. /**
  1237. * Gets an item from the given array.
  1238. * @param context The context when loading the asset
  1239. * @param array The array to get the item from
  1240. * @param index The index to the array
  1241. * @returns The array item
  1242. */
  1243. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1244. /**
  1245. * Assign an `index` field to each item of the given array.
  1246. * @param array The array of items
  1247. */
  1248. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1249. }
  1250. /**
  1251. * The glTF 2.0 loader
  1252. */
  1253. export class GLTFLoader implements IGLTFLoader {
  1254. /** @hidden */
  1255. _completePromises: Promise<any>[];
  1256. private _disposed;
  1257. private _parent;
  1258. private _state;
  1259. private _extensions;
  1260. private _rootUrl;
  1261. private _fileName;
  1262. private _uniqueRootUrl;
  1263. private _gltf;
  1264. private _babylonScene;
  1265. private _rootBabylonMesh;
  1266. private _defaultBabylonMaterialData;
  1267. private _progressCallback?;
  1268. private _requests;
  1269. private static readonly _DefaultSampler;
  1270. private static _ExtensionNames;
  1271. private static _ExtensionFactories;
  1272. /**
  1273. * Registers a loader extension.
  1274. * @param name The name of the loader extension.
  1275. * @param factory The factory function that creates the loader extension.
  1276. */
  1277. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1278. /**
  1279. * Unregisters a loader extension.
  1280. * @param name The name of the loader extenion.
  1281. * @returns A boolean indicating whether the extension has been unregistered
  1282. */
  1283. static UnregisterExtension(name: string): boolean;
  1284. /**
  1285. * Gets the loader state.
  1286. */
  1287. readonly state: Nullable<GLTFLoaderState>;
  1288. /**
  1289. * The glTF object parsed from the JSON.
  1290. */
  1291. readonly gltf: IGLTF;
  1292. /**
  1293. * The Babylon scene when loading the asset.
  1294. */
  1295. readonly babylonScene: Scene;
  1296. /**
  1297. * The root Babylon mesh when loading the asset.
  1298. */
  1299. readonly rootBabylonMesh: Mesh;
  1300. /** @hidden */
  1301. constructor(parent: GLTFFileLoader);
  1302. /** @hidden */
  1303. dispose(): void;
  1304. /** @hidden */
  1305. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1306. meshes: AbstractMesh[];
  1307. particleSystems: IParticleSystem[];
  1308. skeletons: Skeleton[];
  1309. animationGroups: AnimationGroup[];
  1310. }>;
  1311. /** @hidden */
  1312. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1313. private _loadAsync;
  1314. private _loadData;
  1315. private _setupData;
  1316. private _loadExtensions;
  1317. private _checkExtensions;
  1318. private _setState;
  1319. private _createRootNode;
  1320. /**
  1321. * Loads a glTF scene.
  1322. * @param context The context when loading the asset
  1323. * @param scene The glTF scene property
  1324. * @returns A promise that resolves when the load is complete
  1325. */
  1326. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1327. private _forEachPrimitive;
  1328. private _getMeshes;
  1329. private _getSkeletons;
  1330. private _getAnimationGroups;
  1331. private _startAnimations;
  1332. /**
  1333. * Loads a glTF node.
  1334. * @param context The context when loading the asset
  1335. * @param node The glTF node property
  1336. * @param assign A function called synchronously after parsing the glTF properties
  1337. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1338. */
  1339. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1340. private _loadMeshAsync;
  1341. private _loadMeshPrimitiveAsync;
  1342. private _loadVertexDataAsync;
  1343. private _createMorphTargets;
  1344. private _loadMorphTargetsAsync;
  1345. private _loadMorphTargetVertexDataAsync;
  1346. private static _LoadTransform;
  1347. private _loadSkinAsync;
  1348. private _loadBones;
  1349. private _loadBone;
  1350. private _loadSkinInverseBindMatricesDataAsync;
  1351. private _updateBoneMatrices;
  1352. private _getNodeMatrix;
  1353. /**
  1354. * Loads a glTF camera.
  1355. * @param context The context when loading the asset
  1356. * @param camera The glTF camera property
  1357. * @param assign A function called synchronously after parsing the glTF properties
  1358. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1359. */
  1360. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1361. private _loadAnimationsAsync;
  1362. /**
  1363. * Loads a glTF animation.
  1364. * @param context The context when loading the asset
  1365. * @param animation The glTF animation property
  1366. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1367. */
  1368. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1369. private _loadAnimationChannelAsync;
  1370. private _loadAnimationSamplerAsync;
  1371. private _loadBufferAsync;
  1372. /**
  1373. * Loads a glTF buffer view.
  1374. * @param context The context when loading the asset
  1375. * @param bufferView The glTF buffer view property
  1376. * @returns A promise that resolves with the loaded data when the load is complete
  1377. */
  1378. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1379. private _loadIndicesAccessorAsync;
  1380. private _loadFloatAccessorAsync;
  1381. private _loadVertexBufferViewAsync;
  1382. private _loadVertexAccessorAsync;
  1383. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1384. /** @hidden */
  1385. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1386. private _createDefaultMaterial;
  1387. /**
  1388. * Creates a Babylon material from a glTF material.
  1389. * @param context The context when loading the asset
  1390. * @param material The glTF material property
  1391. * @param babylonDrawMode The draw mode for the Babylon material
  1392. * @returns The Babylon material
  1393. */
  1394. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1395. /**
  1396. * Loads properties from a glTF material into a Babylon material.
  1397. * @param context The context when loading the asset
  1398. * @param material The glTF material property
  1399. * @param babylonMaterial The Babylon material
  1400. * @returns A promise that resolves when the load is complete
  1401. */
  1402. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1403. /**
  1404. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1405. * @param context The context when loading the asset
  1406. * @param material The glTF material property
  1407. * @param babylonMaterial The Babylon material
  1408. * @returns A promise that resolves when the load is complete
  1409. */
  1410. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1411. /**
  1412. * Loads the alpha properties from a glTF material into a Babylon material.
  1413. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1414. * @param context The context when loading the asset
  1415. * @param material The glTF material property
  1416. * @param babylonMaterial The Babylon material
  1417. */
  1418. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1419. /**
  1420. * Loads a glTF texture info.
  1421. * @param context The context when loading the asset
  1422. * @param textureInfo The glTF texture info property
  1423. * @param assign A function called synchronously after parsing the glTF properties
  1424. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1425. */
  1426. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1427. private _loadTextureAsync;
  1428. private _loadSampler;
  1429. /**
  1430. * Loads a glTF image.
  1431. * @param context The context when loading the asset
  1432. * @param image The glTF image property
  1433. * @returns A promise that resolves with the loaded data when the load is complete
  1434. */
  1435. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1436. /**
  1437. * Loads a glTF uri.
  1438. * @param context The context when loading the asset
  1439. * @param property The glTF property associated with the uri
  1440. * @param uri The base64 or relative uri
  1441. * @returns A promise that resolves with the loaded data when the load is complete
  1442. */
  1443. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1444. private _onProgress;
  1445. /**
  1446. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1447. * @param babylonObject the Babylon object with metadata
  1448. * @param pointer the JSON pointer
  1449. */
  1450. static AddPointerMetadata(babylonObject: {
  1451. metadata: any;
  1452. }, pointer: string): void;
  1453. private static _GetTextureWrapMode;
  1454. private static _GetTextureSamplingMode;
  1455. private static _GetTypedArray;
  1456. private static _GetNumComponents;
  1457. private static _ValidateUri;
  1458. private static _GetDrawMode;
  1459. private _compileMaterialsAsync;
  1460. private _compileShadowGeneratorsAsync;
  1461. private _forEachExtensions;
  1462. private _applyExtensions;
  1463. private _extensionsOnLoading;
  1464. private _extensionsOnReady;
  1465. private _extensionsLoadSceneAsync;
  1466. private _extensionsLoadNodeAsync;
  1467. private _extensionsLoadCameraAsync;
  1468. private _extensionsLoadVertexDataAsync;
  1469. private _extensionsLoadMaterialAsync;
  1470. private _extensionsCreateMaterial;
  1471. private _extensionsLoadMaterialPropertiesAsync;
  1472. private _extensionsLoadTextureInfoAsync;
  1473. private _extensionsLoadAnimationAsync;
  1474. private _extensionsLoadUriAsync;
  1475. /**
  1476. * Helper method called by a loader extension to load an glTF extension.
  1477. * @param context The context when loading the asset
  1478. * @param property The glTF property to load the extension from
  1479. * @param extensionName The name of the extension to load
  1480. * @param actionAsync The action to run
  1481. * @returns The promise returned by actionAsync or null if the extension does not exist
  1482. */
  1483. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1484. /**
  1485. * Helper method called by a loader extension to load a glTF extra.
  1486. * @param context The context when loading the asset
  1487. * @param property The glTF property to load the extra from
  1488. * @param extensionName The name of the extension to load
  1489. * @param actionAsync The action to run
  1490. * @returns The promise returned by actionAsync or null if the extra does not exist
  1491. */
  1492. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1493. /**
  1494. * Increments the indentation level and logs a message.
  1495. * @param message The message to log
  1496. */
  1497. logOpen(message: string): void;
  1498. /**
  1499. * Decrements the indentation level.
  1500. */
  1501. logClose(): void;
  1502. /**
  1503. * Logs a message
  1504. * @param message The message to log
  1505. */
  1506. log(message: string): void;
  1507. /**
  1508. * Starts a performance counter.
  1509. * @param counterName The name of the performance counter
  1510. */
  1511. startPerformanceCounter(counterName: string): void;
  1512. /**
  1513. * Ends a performance counter.
  1514. * @param counterName The name of the performance counter
  1515. */
  1516. endPerformanceCounter(counterName: string): void;
  1517. }
  1518. }
  1519. declare module BABYLON.GLTF2.Loader.Extensions {
  1520. /**
  1521. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1522. */
  1523. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1524. /** The name of this extension. */
  1525. readonly name: string;
  1526. /** Defines whether this extension is enabled. */
  1527. enabled: boolean;
  1528. private _loader;
  1529. private _lights?;
  1530. /** @hidden */
  1531. constructor(loader: GLTFLoader);
  1532. /** @hidden */
  1533. dispose(): void;
  1534. /** @hidden */
  1535. onLoading(): void;
  1536. /** @hidden */
  1537. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1538. private _loadLightAsync;
  1539. }
  1540. }
  1541. declare module BABYLON.GLTF2.Loader.Extensions {
  1542. /**
  1543. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1544. */
  1545. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1546. /** The name of this extension. */
  1547. readonly name: string;
  1548. /** The draco compression used to decode vertex data. */
  1549. dracoCompression?: DracoCompression;
  1550. /** Defines whether this extension is enabled. */
  1551. enabled: boolean;
  1552. private _loader;
  1553. private _dracoCompressionOwned;
  1554. /** @hidden */
  1555. constructor(loader: GLTFLoader);
  1556. /** @hidden */
  1557. dispose(): void;
  1558. /** @hidden */
  1559. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1560. }
  1561. }
  1562. declare module BABYLON.GLTF2.Loader.Extensions {
  1563. /**
  1564. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1565. */
  1566. export class KHR_lights implements IGLTFLoaderExtension {
  1567. /** The name of this extension. */
  1568. readonly name: string;
  1569. /** Defines whether this extension is enabled. */
  1570. enabled: boolean;
  1571. private _loader;
  1572. private _lights?;
  1573. /** @hidden */
  1574. constructor(loader: GLTFLoader);
  1575. /** @hidden */
  1576. dispose(): void;
  1577. /** @hidden */
  1578. onLoading(): void;
  1579. /** @hidden */
  1580. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1581. }
  1582. }
  1583. declare module BABYLON.GLTF2.Loader.Extensions {
  1584. /**
  1585. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1586. */
  1587. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1588. /** The name of this extension. */
  1589. readonly name: string;
  1590. /** Defines whether this extension is enabled. */
  1591. enabled: boolean;
  1592. private _loader;
  1593. /** @hidden */
  1594. constructor(loader: GLTFLoader);
  1595. /** @hidden */
  1596. dispose(): void;
  1597. /** @hidden */
  1598. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1599. private _loadSpecularGlossinessPropertiesAsync;
  1600. }
  1601. }
  1602. declare module BABYLON.GLTF2.Loader.Extensions {
  1603. /**
  1604. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1605. */
  1606. export class KHR_materials_unlit 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. /** @hidden */
  1613. constructor(loader: GLTFLoader);
  1614. /** @hidden */
  1615. dispose(): void;
  1616. /** @hidden */
  1617. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1618. private _loadUnlitPropertiesAsync;
  1619. }
  1620. }
  1621. declare module BABYLON.GLTF2.Loader.Extensions {
  1622. /**
  1623. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1624. */
  1625. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1626. /** The name of this extension. */
  1627. readonly name: string;
  1628. /** Defines whether this extension is enabled. */
  1629. enabled: boolean;
  1630. private _loader;
  1631. /** @hidden */
  1632. constructor(loader: GLTFLoader);
  1633. /** @hidden */
  1634. dispose(): void;
  1635. /** @hidden */
  1636. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1637. }
  1638. }
  1639. declare module BABYLON.GLTF2.Loader.Extensions {
  1640. /**
  1641. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1642. */
  1643. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1644. /** The name of this extension. */
  1645. readonly name: string;
  1646. /** Defines whether this extension is enabled. */
  1647. enabled: boolean;
  1648. private _loader;
  1649. private _clips;
  1650. private _emitters;
  1651. /** @hidden */
  1652. constructor(loader: GLTFLoader);
  1653. /** @hidden */
  1654. dispose(): void;
  1655. /** @hidden */
  1656. onLoading(): void;
  1657. /** @hidden */
  1658. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1659. /** @hidden */
  1660. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1661. /** @hidden */
  1662. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1663. private _loadClipAsync;
  1664. private _loadEmitterAsync;
  1665. private _getEventAction;
  1666. private _loadAnimationEventAsync;
  1667. }
  1668. }
  1669. declare module BABYLON.GLTF2.Loader.Extensions {
  1670. /**
  1671. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1672. */
  1673. export class MSFT_lod implements IGLTFLoaderExtension {
  1674. /** The name of this extension. */
  1675. readonly name: string;
  1676. /** Defines whether this extension is enabled. */
  1677. enabled: boolean;
  1678. /**
  1679. * Maximum number of LODs to load, starting from the lowest LOD.
  1680. */
  1681. maxLODsToLoad: number;
  1682. /**
  1683. * Observable raised when all node LODs of one level are loaded.
  1684. * The event data is the index of the loaded LOD starting from zero.
  1685. * Dispose the loader to cancel the loading of the next level of LODs.
  1686. */
  1687. onNodeLODsLoadedObservable: Observable<number>;
  1688. /**
  1689. * Observable raised when all material LODs of one level are loaded.
  1690. * The event data is the index of the loaded LOD starting from zero.
  1691. * Dispose the loader to cancel the loading of the next level of LODs.
  1692. */
  1693. onMaterialLODsLoadedObservable: Observable<number>;
  1694. private _loader;
  1695. private _nodeIndexLOD;
  1696. private _nodeSignalLODs;
  1697. private _nodePromiseLODs;
  1698. private _materialIndexLOD;
  1699. private _materialSignalLODs;
  1700. private _materialPromiseLODs;
  1701. /** @hidden */
  1702. constructor(loader: GLTFLoader);
  1703. /** @hidden */
  1704. dispose(): void;
  1705. /** @hidden */
  1706. onReady(): void;
  1707. /** @hidden */
  1708. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1709. /** @hidden */
  1710. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1711. /** @hidden */
  1712. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1713. /**
  1714. * Gets an array of LOD properties from lowest to highest.
  1715. */
  1716. private _getLODs;
  1717. private _disposeUnusedMaterials;
  1718. }
  1719. }
  1720. declare module BABYLON.GLTF2.Loader.Extensions {
  1721. /** @hidden */
  1722. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1723. readonly name: string;
  1724. enabled: boolean;
  1725. private _loader;
  1726. constructor(loader: GLTFLoader);
  1727. dispose(): void;
  1728. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1729. }
  1730. }
  1731. declare module BABYLON.GLTF2.Loader.Extensions {
  1732. /** @hidden */
  1733. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1734. readonly name: string;
  1735. enabled: boolean;
  1736. private _loader;
  1737. constructor(loader: GLTFLoader);
  1738. dispose(): void;
  1739. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1740. }
  1741. }
  1742. declare module BABYLON {
  1743. /**
  1744. * Class reading and parsing the MTL file bundled with the obj file.
  1745. */
  1746. export class MTLFileLoader {
  1747. /**
  1748. * All material loaded from the mtl will be set here
  1749. */
  1750. materials: StandardMaterial[];
  1751. /**
  1752. * This function will read the mtl file and create each material described inside
  1753. * This function could be improve by adding :
  1754. * -some component missing (Ni, Tf...)
  1755. * -including the specific options available
  1756. *
  1757. * @param scene defines the scene the material will be created in
  1758. * @param data defines the mtl data to parse
  1759. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1760. */
  1761. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1762. /**
  1763. * Gets the texture for the material.
  1764. *
  1765. * If the material is imported from input file,
  1766. * We sanitize the url to ensure it takes the textre from aside the material.
  1767. *
  1768. * @param rootUrl The root url to load from
  1769. * @param value The value stored in the mtl
  1770. * @return The Texture
  1771. */
  1772. private static _getTexture;
  1773. }
  1774. /**
  1775. * Options for loading OBJ/MTL files
  1776. */
  1777. type MeshLoadOptions = {
  1778. /**
  1779. * Defines if UVs are optimized by default during load.
  1780. */
  1781. OptimizeWithUV: boolean;
  1782. /**
  1783. * Invert model on y-axis (does a model scaling inversion)
  1784. */
  1785. InvertY: boolean;
  1786. /**
  1787. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1788. */
  1789. ImportVertexColors: boolean;
  1790. /**
  1791. * Compute the normals for the model, even if normals are present in the file.
  1792. */
  1793. ComputeNormals: boolean;
  1794. /**
  1795. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1796. */
  1797. SkipMaterials: boolean;
  1798. /**
  1799. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1800. */
  1801. MaterialLoadingFailsSilently: boolean;
  1802. };
  1803. /**
  1804. * OBJ file type loader.
  1805. * This is a babylon scene loader plugin.
  1806. */
  1807. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  1808. /**
  1809. * Defines if UVs are optimized by default during load.
  1810. */
  1811. static OPTIMIZE_WITH_UV: boolean;
  1812. /**
  1813. * Invert model on y-axis (does a model scaling inversion)
  1814. */
  1815. static INVERT_Y: boolean;
  1816. /**
  1817. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1818. */
  1819. static IMPORT_VERTEX_COLORS: boolean;
  1820. /**
  1821. * Compute the normals for the model, even if normals are present in the file.
  1822. */
  1823. static COMPUTE_NORMALS: boolean;
  1824. /**
  1825. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1826. */
  1827. static SKIP_MATERIALS: boolean;
  1828. /**
  1829. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1830. *
  1831. * Defaults to true for backwards compatibility.
  1832. */
  1833. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  1834. /**
  1835. * Defines the name of the plugin.
  1836. */
  1837. name: string;
  1838. /**
  1839. * Defines the extension the plugin is able to load.
  1840. */
  1841. extensions: string;
  1842. /** @hidden */
  1843. obj: RegExp;
  1844. /** @hidden */
  1845. group: RegExp;
  1846. /** @hidden */
  1847. mtllib: RegExp;
  1848. /** @hidden */
  1849. usemtl: RegExp;
  1850. /** @hidden */
  1851. smooth: RegExp;
  1852. /** @hidden */
  1853. vertexPattern: RegExp;
  1854. /** @hidden */
  1855. normalPattern: RegExp;
  1856. /** @hidden */
  1857. uvPattern: RegExp;
  1858. /** @hidden */
  1859. facePattern1: RegExp;
  1860. /** @hidden */
  1861. facePattern2: RegExp;
  1862. /** @hidden */
  1863. facePattern3: RegExp;
  1864. /** @hidden */
  1865. facePattern4: RegExp;
  1866. /** @hidden */
  1867. facePattern5: RegExp;
  1868. private _meshLoadOptions;
  1869. /**
  1870. * Creates loader for .OBJ files
  1871. *
  1872. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  1873. */
  1874. constructor(meshLoadOptions?: MeshLoadOptions);
  1875. private static readonly currentMeshLoadOptions;
  1876. /**
  1877. * Calls synchronously the MTL file attached to this obj.
  1878. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  1879. * Without this function materials are not displayed in the first frame (but displayed after).
  1880. * In consequence it is impossible to get material information in your HTML file
  1881. *
  1882. * @param url The URL of the MTL file
  1883. * @param rootUrl
  1884. * @param onSuccess Callback function to be called when the MTL file is loaded
  1885. * @private
  1886. */
  1887. private _loadMTL;
  1888. /**
  1889. * Instantiates a OBJ file loader plugin.
  1890. * @returns the created plugin
  1891. */
  1892. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  1893. /**
  1894. * If the data string can be loaded directly.
  1895. *
  1896. * @param data string containing the file data
  1897. * @returns if the data can be loaded directly
  1898. */
  1899. canDirectLoad(data: string): boolean;
  1900. /**
  1901. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  1902. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1903. * @param scene the scene the meshes should be added to
  1904. * @param data the OBJ data to load
  1905. * @param rootUrl root url to load from
  1906. * @param onProgress event that fires when loading progress has occured
  1907. * @param fileName Defines the name of the file to load
  1908. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1909. */
  1910. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1911. meshes: AbstractMesh[];
  1912. particleSystems: IParticleSystem[];
  1913. skeletons: Skeleton[];
  1914. animationGroups: AnimationGroup[];
  1915. }>;
  1916. /**
  1917. * Imports all objects from the loaded OBJ data and adds them to the scene
  1918. * @param scene the scene the objects should be added to
  1919. * @param data the OBJ data to load
  1920. * @param rootUrl root url to load from
  1921. * @param onProgress event that fires when loading progress has occured
  1922. * @param fileName Defines the name of the file to load
  1923. * @returns a promise which completes when objects have been loaded to the scene
  1924. */
  1925. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1926. /**
  1927. * Load into an asset container.
  1928. * @param scene The scene to load into
  1929. * @param data The data to import
  1930. * @param rootUrl The root url for scene and resources
  1931. * @param onProgress The callback when the load progresses
  1932. * @param fileName Defines the name of the file to load
  1933. * @returns The loaded asset container
  1934. */
  1935. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  1936. /**
  1937. * Read the OBJ file and create an Array of meshes.
  1938. * Each mesh contains all information given by the OBJ and the MTL file.
  1939. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  1940. *
  1941. * @param meshesNames
  1942. * @param scene Scene The scene where are displayed the data
  1943. * @param data String The content of the obj file
  1944. * @param rootUrl String The path to the folder
  1945. * @returns Array<AbstractMesh>
  1946. * @private
  1947. */
  1948. private _parseSolid;
  1949. }
  1950. }
  1951. declare module BABYLON {
  1952. /**
  1953. * STL file type loader.
  1954. * This is a babylon scene loader plugin.
  1955. */
  1956. export class STLFileLoader implements ISceneLoaderPlugin {
  1957. /** @hidden */
  1958. solidPattern: RegExp;
  1959. /** @hidden */
  1960. facetsPattern: RegExp;
  1961. /** @hidden */
  1962. normalPattern: RegExp;
  1963. /** @hidden */
  1964. vertexPattern: RegExp;
  1965. /**
  1966. * Defines the name of the plugin.
  1967. */
  1968. name: string;
  1969. /**
  1970. * Defines the extensions the stl loader is able to load.
  1971. * force data to come in as an ArrayBuffer
  1972. * we'll convert to string if it looks like it's an ASCII .stl
  1973. */
  1974. extensions: ISceneLoaderPluginExtensions;
  1975. /**
  1976. * Import meshes into a scene.
  1977. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1978. * @param scene The scene to import into
  1979. * @param data The data to import
  1980. * @param rootUrl The root url for scene and resources
  1981. * @param meshes The meshes array to import into
  1982. * @param particleSystems The particle systems array to import into
  1983. * @param skeletons The skeletons array to import into
  1984. * @param onError The callback when import fails
  1985. * @returns True if successful or false otherwise
  1986. */
  1987. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  1988. /**
  1989. * Load into a scene.
  1990. * @param scene The scene to load into
  1991. * @param data The data to import
  1992. * @param rootUrl The root url for scene and resources
  1993. * @param onError The callback when import fails
  1994. * @returns true if successful or false otherwise
  1995. */
  1996. load(scene: Scene, data: any, rootUrl: string): boolean;
  1997. /**
  1998. * Load into an asset container.
  1999. * @param scene The scene to load into
  2000. * @param data The data to import
  2001. * @param rootUrl The root url for scene and resources
  2002. * @param onError The callback when import fails
  2003. * @returns The loaded asset container
  2004. */
  2005. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2006. private _isBinary;
  2007. private _parseBinary;
  2008. private _parseASCII;
  2009. }
  2010. }