babylonjs.loaders.d.ts 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  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. */
  1590. dracoCompression?: DracoCompression;
  1591. /** Defines whether this extension is enabled. */
  1592. enabled: boolean;
  1593. private _loader;
  1594. private _dracoCompressionOwned;
  1595. /** @hidden */
  1596. constructor(loader: GLTFLoader);
  1597. /** @hidden */
  1598. dispose(): void;
  1599. /** @hidden */
  1600. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1601. }
  1602. }
  1603. declare module BABYLON.GLTF2.Loader.Extensions {
  1604. /**
  1605. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1606. */
  1607. export class KHR_lights implements IGLTFLoaderExtension {
  1608. /** The name of this extension. */
  1609. readonly name: string;
  1610. /** Defines whether this extension is enabled. */
  1611. enabled: boolean;
  1612. private _loader;
  1613. private _lights?;
  1614. /** @hidden */
  1615. constructor(loader: GLTFLoader);
  1616. /** @hidden */
  1617. dispose(): void;
  1618. /** @hidden */
  1619. onLoading(): void;
  1620. /** @hidden */
  1621. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1622. }
  1623. }
  1624. declare module BABYLON.GLTF2.Loader.Extensions {
  1625. /**
  1626. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1627. */
  1628. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1629. /** The name of this extension. */
  1630. readonly name: string;
  1631. /** Defines whether this extension is enabled. */
  1632. enabled: boolean;
  1633. private _loader;
  1634. /** @hidden */
  1635. constructor(loader: GLTFLoader);
  1636. /** @hidden */
  1637. dispose(): void;
  1638. /** @hidden */
  1639. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1640. private _loadSpecularGlossinessPropertiesAsync;
  1641. }
  1642. }
  1643. declare module BABYLON.GLTF2.Loader.Extensions {
  1644. /**
  1645. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1646. */
  1647. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1648. /** The name of this extension. */
  1649. readonly name: string;
  1650. /** Defines whether this extension is enabled. */
  1651. enabled: boolean;
  1652. private _loader;
  1653. /** @hidden */
  1654. constructor(loader: GLTFLoader);
  1655. /** @hidden */
  1656. dispose(): void;
  1657. /** @hidden */
  1658. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1659. private _loadUnlitPropertiesAsync;
  1660. }
  1661. }
  1662. declare module BABYLON.GLTF2.Loader.Extensions {
  1663. /**
  1664. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1665. */
  1666. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1667. /** The name of this extension. */
  1668. readonly name: string;
  1669. /** Defines whether this extension is enabled. */
  1670. enabled: boolean;
  1671. private _loader;
  1672. /** @hidden */
  1673. constructor(loader: GLTFLoader);
  1674. /** @hidden */
  1675. dispose(): void;
  1676. /** @hidden */
  1677. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1678. }
  1679. }
  1680. declare module BABYLON.GLTF2.Loader.Extensions {
  1681. /**
  1682. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1683. */
  1684. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1685. /** The name of this extension. */
  1686. readonly name: string;
  1687. /** Defines whether this extension is enabled. */
  1688. enabled: boolean;
  1689. private _loader;
  1690. private _clips;
  1691. private _emitters;
  1692. /** @hidden */
  1693. constructor(loader: GLTFLoader);
  1694. /** @hidden */
  1695. dispose(): void;
  1696. /** @hidden */
  1697. onLoading(): void;
  1698. /** @hidden */
  1699. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1700. /** @hidden */
  1701. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1702. /** @hidden */
  1703. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1704. private _loadClipAsync;
  1705. private _loadEmitterAsync;
  1706. private _getEventAction;
  1707. private _loadAnimationEventAsync;
  1708. }
  1709. }
  1710. declare module BABYLON.GLTF2.Loader.Extensions {
  1711. /**
  1712. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1713. */
  1714. export class MSFT_lod implements IGLTFLoaderExtension {
  1715. /** The name of this extension. */
  1716. readonly name: string;
  1717. /** Defines whether this extension is enabled. */
  1718. enabled: boolean;
  1719. /**
  1720. * Maximum number of LODs to load, starting from the lowest LOD.
  1721. */
  1722. maxLODsToLoad: number;
  1723. /**
  1724. * Observable raised when all node LODs of one level are loaded.
  1725. * The event data is the index of the loaded LOD starting from zero.
  1726. * Dispose the loader to cancel the loading of the next level of LODs.
  1727. */
  1728. onNodeLODsLoadedObservable: Observable<number>;
  1729. /**
  1730. * Observable raised when all material LODs of one level are loaded.
  1731. * The event data is the index of the loaded LOD starting from zero.
  1732. * Dispose the loader to cancel the loading of the next level of LODs.
  1733. */
  1734. onMaterialLODsLoadedObservable: Observable<number>;
  1735. private _loader;
  1736. private _nodeIndexLOD;
  1737. private _nodeSignalLODs;
  1738. private _nodePromiseLODs;
  1739. private _materialIndexLOD;
  1740. private _materialSignalLODs;
  1741. private _materialPromiseLODs;
  1742. /** @hidden */
  1743. constructor(loader: GLTFLoader);
  1744. /** @hidden */
  1745. dispose(): void;
  1746. /** @hidden */
  1747. onReady(): void;
  1748. /** @hidden */
  1749. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1750. /** @hidden */
  1751. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1752. /** @hidden */
  1753. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1754. /**
  1755. * Gets an array of LOD properties from lowest to highest.
  1756. */
  1757. private _getLODs;
  1758. private _disposeUnusedMaterials;
  1759. }
  1760. }
  1761. declare module BABYLON.GLTF2.Loader.Extensions {
  1762. /** @hidden */
  1763. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1764. readonly name: string;
  1765. enabled: boolean;
  1766. private _loader;
  1767. constructor(loader: GLTFLoader);
  1768. dispose(): void;
  1769. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1770. }
  1771. }
  1772. declare module BABYLON.GLTF2.Loader.Extensions {
  1773. /** @hidden */
  1774. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1775. readonly name: string;
  1776. enabled: boolean;
  1777. private _loader;
  1778. constructor(loader: GLTFLoader);
  1779. dispose(): void;
  1780. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1781. }
  1782. }
  1783. declare module BABYLON {
  1784. /**
  1785. * Class reading and parsing the MTL file bundled with the obj file.
  1786. */
  1787. export class MTLFileLoader {
  1788. /**
  1789. * All material loaded from the mtl will be set here
  1790. */
  1791. materials: StandardMaterial[];
  1792. /**
  1793. * This function will read the mtl file and create each material described inside
  1794. * This function could be improve by adding :
  1795. * -some component missing (Ni, Tf...)
  1796. * -including the specific options available
  1797. *
  1798. * @param scene defines the scene the material will be created in
  1799. * @param data defines the mtl data to parse
  1800. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1801. */
  1802. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1803. /**
  1804. * Gets the texture for the material.
  1805. *
  1806. * If the material is imported from input file,
  1807. * We sanitize the url to ensure it takes the textre from aside the material.
  1808. *
  1809. * @param rootUrl The root url to load from
  1810. * @param value The value stored in the mtl
  1811. * @return The Texture
  1812. */
  1813. private static _getTexture;
  1814. }
  1815. /**
  1816. * Options for loading OBJ/MTL files
  1817. */
  1818. type MeshLoadOptions = {
  1819. /**
  1820. * Defines if UVs are optimized by default during load.
  1821. */
  1822. OptimizeWithUV: boolean;
  1823. /**
  1824. * Defines custom scaling of UV coordinates of loaded meshes.
  1825. */
  1826. UVScaling: Vector2;
  1827. /**
  1828. * Invert model on y-axis (does a model scaling inversion)
  1829. */
  1830. InvertY: boolean;
  1831. /**
  1832. * Invert Y-Axis of referenced textures on load
  1833. */
  1834. InvertTextureY: boolean;
  1835. /**
  1836. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1837. */
  1838. ImportVertexColors: boolean;
  1839. /**
  1840. * Compute the normals for the model, even if normals are present in the file.
  1841. */
  1842. ComputeNormals: boolean;
  1843. /**
  1844. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1845. */
  1846. SkipMaterials: boolean;
  1847. /**
  1848. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1849. */
  1850. MaterialLoadingFailsSilently: boolean;
  1851. };
  1852. /**
  1853. * OBJ file type loader.
  1854. * This is a babylon scene loader plugin.
  1855. */
  1856. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  1857. /**
  1858. * Defines if UVs are optimized by default during load.
  1859. */
  1860. static OPTIMIZE_WITH_UV: boolean;
  1861. /**
  1862. * Invert model on y-axis (does a model scaling inversion)
  1863. */
  1864. static INVERT_Y: boolean;
  1865. /**
  1866. * Invert Y-Axis of referenced textures on load
  1867. */
  1868. static INVERT_TEXTURE_Y: boolean;
  1869. /**
  1870. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1871. */
  1872. static IMPORT_VERTEX_COLORS: boolean;
  1873. /**
  1874. * Compute the normals for the model, even if normals are present in the file.
  1875. */
  1876. static COMPUTE_NORMALS: boolean;
  1877. /**
  1878. * Defines custom scaling of UV coordinates of loaded meshes.
  1879. */
  1880. static UV_SCALING: Vector2;
  1881. /**
  1882. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1883. */
  1884. static SKIP_MATERIALS: boolean;
  1885. /**
  1886. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1887. *
  1888. * Defaults to true for backwards compatibility.
  1889. */
  1890. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  1891. /**
  1892. * Defines the name of the plugin.
  1893. */
  1894. name: string;
  1895. /**
  1896. * Defines the extension the plugin is able to load.
  1897. */
  1898. extensions: string;
  1899. /** @hidden */
  1900. obj: RegExp;
  1901. /** @hidden */
  1902. group: RegExp;
  1903. /** @hidden */
  1904. mtllib: RegExp;
  1905. /** @hidden */
  1906. usemtl: RegExp;
  1907. /** @hidden */
  1908. smooth: RegExp;
  1909. /** @hidden */
  1910. vertexPattern: RegExp;
  1911. /** @hidden */
  1912. normalPattern: RegExp;
  1913. /** @hidden */
  1914. uvPattern: RegExp;
  1915. /** @hidden */
  1916. facePattern1: RegExp;
  1917. /** @hidden */
  1918. facePattern2: RegExp;
  1919. /** @hidden */
  1920. facePattern3: RegExp;
  1921. /** @hidden */
  1922. facePattern4: RegExp;
  1923. /** @hidden */
  1924. facePattern5: RegExp;
  1925. private _meshLoadOptions;
  1926. /**
  1927. * Creates loader for .OBJ files
  1928. *
  1929. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  1930. */
  1931. constructor(meshLoadOptions?: MeshLoadOptions);
  1932. private static readonly currentMeshLoadOptions;
  1933. /**
  1934. * Calls synchronously the MTL file attached to this obj.
  1935. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  1936. * Without this function materials are not displayed in the first frame (but displayed after).
  1937. * In consequence it is impossible to get material information in your HTML file
  1938. *
  1939. * @param url The URL of the MTL file
  1940. * @param rootUrl
  1941. * @param onSuccess Callback function to be called when the MTL file is loaded
  1942. * @private
  1943. */
  1944. private _loadMTL;
  1945. /**
  1946. * Instantiates a OBJ file loader plugin.
  1947. * @returns the created plugin
  1948. */
  1949. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  1950. /**
  1951. * If the data string can be loaded directly.
  1952. *
  1953. * @param data string containing the file data
  1954. * @returns if the data can be loaded directly
  1955. */
  1956. canDirectLoad(data: string): boolean;
  1957. /**
  1958. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  1959. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1960. * @param scene the scene the meshes should be added to
  1961. * @param data the OBJ data to load
  1962. * @param rootUrl root url to load from
  1963. * @param onProgress event that fires when loading progress has occured
  1964. * @param fileName Defines the name of the file to load
  1965. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1966. */
  1967. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1968. meshes: AbstractMesh[];
  1969. particleSystems: IParticleSystem[];
  1970. skeletons: Skeleton[];
  1971. animationGroups: AnimationGroup[];
  1972. }>;
  1973. /**
  1974. * Imports all objects from the loaded OBJ data and adds them to the scene
  1975. * @param scene the scene the objects should be added to
  1976. * @param data the OBJ data to load
  1977. * @param rootUrl root url to load from
  1978. * @param onProgress event that fires when loading progress has occured
  1979. * @param fileName Defines the name of the file to load
  1980. * @returns a promise which completes when objects have been loaded to the scene
  1981. */
  1982. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1983. /**
  1984. * Load into an asset container.
  1985. * @param scene The scene to load into
  1986. * @param data The data to import
  1987. * @param rootUrl The root url for scene and resources
  1988. * @param onProgress The callback when the load progresses
  1989. * @param fileName Defines the name of the file to load
  1990. * @returns The loaded asset container
  1991. */
  1992. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  1993. /**
  1994. * Read the OBJ file and create an Array of meshes.
  1995. * Each mesh contains all information given by the OBJ and the MTL file.
  1996. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  1997. *
  1998. * @param meshesNames
  1999. * @param scene Scene The scene where are displayed the data
  2000. * @param data String The content of the obj file
  2001. * @param rootUrl String The path to the folder
  2002. * @returns Array<AbstractMesh>
  2003. * @private
  2004. */
  2005. private _parseSolid;
  2006. }
  2007. }
  2008. declare module BABYLON {
  2009. /**
  2010. * STL file type loader.
  2011. * This is a babylon scene loader plugin.
  2012. */
  2013. export class STLFileLoader implements ISceneLoaderPlugin {
  2014. /** @hidden */
  2015. solidPattern: RegExp;
  2016. /** @hidden */
  2017. facetsPattern: RegExp;
  2018. /** @hidden */
  2019. normalPattern: RegExp;
  2020. /** @hidden */
  2021. vertexPattern: RegExp;
  2022. /**
  2023. * Defines the name of the plugin.
  2024. */
  2025. name: string;
  2026. /**
  2027. * Defines the extensions the stl loader is able to load.
  2028. * force data to come in as an ArrayBuffer
  2029. * we'll convert to string if it looks like it's an ASCII .stl
  2030. */
  2031. extensions: ISceneLoaderPluginExtensions;
  2032. /**
  2033. * Import meshes into a scene.
  2034. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2035. * @param scene The scene to import into
  2036. * @param data The data to import
  2037. * @param rootUrl The root url for scene and resources
  2038. * @param meshes The meshes array to import into
  2039. * @param particleSystems The particle systems array to import into
  2040. * @param skeletons The skeletons array to import into
  2041. * @param onError The callback when import fails
  2042. * @returns True if successful or false otherwise
  2043. */
  2044. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2045. /**
  2046. * Load into a scene.
  2047. * @param scene The scene to load into
  2048. * @param data The data to import
  2049. * @param rootUrl The root url for scene and resources
  2050. * @param onError The callback when import fails
  2051. * @returns true if successful or false otherwise
  2052. */
  2053. load(scene: Scene, data: any, rootUrl: string): boolean;
  2054. /**
  2055. * Load into an asset container.
  2056. * @param scene The scene to load into
  2057. * @param data The data to import
  2058. * @param rootUrl The root url for scene and resources
  2059. * @param onError The callback when import fails
  2060. * @returns The loaded asset container
  2061. */
  2062. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2063. private _isBinary;
  2064. private _parseBinary;
  2065. private _parseASCII;
  2066. }
  2067. }