babylonjs.loaders.d.ts 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595
  1. declare module BABYLON {
  2. /**
  3. * Configuration for glTF validation
  4. */
  5. export interface IGLTFValidationConfiguration {
  6. /**
  7. * The url of the glTF validator.
  8. */
  9. url: string;
  10. }
  11. /**
  12. * glTF validation
  13. */
  14. export class GLTFValidation {
  15. /**
  16. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  17. */
  18. static Configuration: IGLTFValidationConfiguration;
  19. private static _LoadScriptPromise;
  20. /**
  21. * Validate a glTF asset using the glTF-Validator.
  22. * @param data The JSON of a glTF or the array buffer of a binary glTF
  23. * @param rootUrl The root url for the glTF
  24. * @param fileName The file name for the glTF
  25. * @param getExternalResource The callback to get external resources for the glTF validator
  26. * @returns A promise that resolves with the glTF validation results once complete
  27. */
  28. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<BABYLON.GLTF2.IGLTFValidationResults>;
  29. }
  30. }
  31. declare module BABYLON {
  32. /**
  33. * Mode that determines the coordinate system to use.
  34. */
  35. export enum GLTFLoaderCoordinateSystemMode {
  36. /**
  37. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  38. */
  39. AUTO = 0,
  40. /**
  41. * Sets the useRightHandedSystem flag on the scene.
  42. */
  43. FORCE_RIGHT_HANDED = 1
  44. }
  45. /**
  46. * Mode that determines what animations will start.
  47. */
  48. export enum GLTFLoaderAnimationStartMode {
  49. /**
  50. * No animation will start.
  51. */
  52. NONE = 0,
  53. /**
  54. * The first animation will start.
  55. */
  56. FIRST = 1,
  57. /**
  58. * All animations will start.
  59. */
  60. ALL = 2
  61. }
  62. /**
  63. * Interface that contains the data for the glTF asset.
  64. */
  65. export interface IGLTFLoaderData {
  66. /**
  67. * The object that represents the glTF JSON.
  68. */
  69. json: Object;
  70. /**
  71. * The BIN chunk of a binary glTF.
  72. */
  73. bin: Nullable<IDataBuffer>;
  74. }
  75. /**
  76. * Interface for extending the loader.
  77. */
  78. export interface IGLTFLoaderExtension {
  79. /**
  80. * The name of this extension.
  81. */
  82. readonly name: string;
  83. /**
  84. * Defines whether this extension is enabled.
  85. */
  86. enabled: boolean;
  87. /**
  88. * Defines the order of this extension.
  89. * The loader sorts the extensions using these values when loading.
  90. */
  91. order?: number;
  92. }
  93. /**
  94. * Loader state.
  95. */
  96. export enum GLTFLoaderState {
  97. /**
  98. * The asset is loading.
  99. */
  100. LOADING = 0,
  101. /**
  102. * The asset is ready for rendering.
  103. */
  104. READY = 1,
  105. /**
  106. * The asset is completely loaded.
  107. */
  108. COMPLETE = 2
  109. }
  110. /** @hidden */
  111. export interface IGLTFLoader extends IDisposable {
  112. readonly state: Nullable<GLTFLoaderState>;
  113. importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<ISceneLoaderAsyncResult>;
  114. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  115. }
  116. /**
  117. * File loader for loading glTF files into a scene.
  118. */
  119. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  120. /** @hidden */
  121. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  122. /** @hidden */
  123. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  124. /**
  125. * Raised when the asset has been parsed
  126. */
  127. onParsedObservable: Observable<IGLTFLoaderData>;
  128. private _onParsedObserver;
  129. /**
  130. * Raised when the asset has been parsed
  131. */
  132. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  133. /**
  134. * 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.
  135. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  136. * Defaults to true.
  137. * @hidden
  138. */
  139. static IncrementalLoading: boolean;
  140. /**
  141. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  142. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  143. * @hidden
  144. */
  145. static HomogeneousCoordinates: boolean;
  146. /**
  147. * The coordinate system mode. Defaults to AUTO.
  148. */
  149. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  150. /**
  151. * The animation start mode. Defaults to FIRST.
  152. */
  153. animationStartMode: GLTFLoaderAnimationStartMode;
  154. /**
  155. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  156. */
  157. compileMaterials: boolean;
  158. /**
  159. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  160. */
  161. useClipPlane: boolean;
  162. /**
  163. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  164. */
  165. compileShadowGenerators: boolean;
  166. /**
  167. * Defines if the Alpha blended materials are only applied as coverage.
  168. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  169. * If true, no extra effects are applied to transparent pixels.
  170. */
  171. transparencyAsCoverage: boolean;
  172. /**
  173. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  174. * Enabling will disable offline support and glTF validator.
  175. * Defaults to false.
  176. */
  177. useRangeRequests: boolean;
  178. /**
  179. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  180. */
  181. createInstances: boolean;
  182. /**
  183. * Defines if the loader should always compute the bounding boxes of meshes and not use the min/max values from the position accessor. Defaults to false.
  184. */
  185. alwaysComputeBoundingBox: boolean;
  186. /**
  187. * If true, load all materials defined in the file, even if not used by any mesh. Defaults to false.
  188. */
  189. loadAllMaterials: boolean;
  190. /**
  191. * Function called before loading a url referenced by the asset.
  192. */
  193. preprocessUrlAsync: (url: string) => Promise<string>;
  194. /**
  195. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  196. * Note that the observable is raised as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
  197. */
  198. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  199. private _onMeshLoadedObserver;
  200. /**
  201. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  202. * Note that the callback is called as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
  203. */
  204. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  205. /**
  206. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  207. */
  208. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  209. private _onTextureLoadedObserver;
  210. /**
  211. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  212. */
  213. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  214. /**
  215. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  216. */
  217. readonly onMaterialLoadedObservable: Observable<Material>;
  218. private _onMaterialLoadedObserver;
  219. /**
  220. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  221. */
  222. set onMaterialLoaded(callback: (material: Material) => void);
  223. /**
  224. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  225. */
  226. readonly onCameraLoadedObservable: Observable<Camera>;
  227. private _onCameraLoadedObserver;
  228. /**
  229. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  230. */
  231. set onCameraLoaded(callback: (camera: Camera) => void);
  232. /**
  233. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  234. * For assets with LODs, raised when all of the LODs are complete.
  235. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  236. */
  237. readonly onCompleteObservable: Observable<void>;
  238. private _onCompleteObserver;
  239. /**
  240. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  241. * For assets with LODs, raised when all of the LODs are complete.
  242. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  243. */
  244. set onComplete(callback: () => void);
  245. /**
  246. * Observable raised when an error occurs.
  247. */
  248. readonly onErrorObservable: Observable<any>;
  249. private _onErrorObserver;
  250. /**
  251. * Callback raised when an error occurs.
  252. */
  253. set onError(callback: (reason: any) => void);
  254. /**
  255. * Observable raised after the loader is disposed.
  256. */
  257. readonly onDisposeObservable: Observable<void>;
  258. private _onDisposeObserver;
  259. /**
  260. * Callback raised after the loader is disposed.
  261. */
  262. set onDispose(callback: () => void);
  263. /**
  264. * Observable raised after a loader extension is created.
  265. * Set additional options for a loader extension in this event.
  266. */
  267. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  268. private _onExtensionLoadedObserver;
  269. /**
  270. * Callback raised after a loader extension is created.
  271. */
  272. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  273. /**
  274. * Defines if the loader logging is enabled.
  275. */
  276. get loggingEnabled(): boolean;
  277. set loggingEnabled(value: boolean);
  278. /**
  279. * Defines if the loader should capture performance counters.
  280. */
  281. get capturePerformanceCounters(): boolean;
  282. set capturePerformanceCounters(value: boolean);
  283. /**
  284. * Defines if the loader should validate the asset.
  285. */
  286. validate: boolean;
  287. /**
  288. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  289. */
  290. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  291. private _onValidatedObserver;
  292. /**
  293. * Callback raised after a loader extension is created.
  294. */
  295. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  296. private _loader;
  297. private _progressCallback?;
  298. private _requests;
  299. private static magicBase64Encoded;
  300. /**
  301. * Name of the loader ("gltf")
  302. */
  303. name: string;
  304. /** @hidden */
  305. extensions: ISceneLoaderPluginExtensions;
  306. /**
  307. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  308. */
  309. dispose(): void;
  310. /** @hidden */
  311. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  312. /** @hidden */
  313. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  314. /** @hidden */
  315. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
  316. /** @hidden */
  317. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  318. /** @hidden */
  319. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  320. /** @hidden */
  321. canDirectLoad(data: string): boolean;
  322. /** @hidden */
  323. directLoad(scene: Scene, data: string): Promise<any>;
  324. /**
  325. * The callback that allows custom handling of the root url based on the response url.
  326. * @param rootUrl the original root url
  327. * @param responseURL the response url if available
  328. * @returns the new root url
  329. */
  330. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  331. /** @hidden */
  332. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  333. /**
  334. * The loader state or null if the loader is not active.
  335. */
  336. get loaderState(): Nullable<GLTFLoaderState>;
  337. /**
  338. * Returns a promise that resolves when the asset is completely loaded.
  339. * @returns a promise that resolves when the asset is completely loaded.
  340. */
  341. whenCompleteAsync(): Promise<void>;
  342. /** @hidden */
  343. _loadFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest) => void): IFileRequest;
  344. /** @hidden */
  345. _requestFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer, request?: WebRequest) => void, useArrayBuffer?: boolean, onError?: (error: RequestFileError) => void, onOpened?: (request: WebRequest) => void): IFileRequest;
  346. private _onProgress;
  347. private _validate;
  348. private _getLoader;
  349. private _parseJson;
  350. private _unpackBinaryAsync;
  351. private _unpackBinaryV1Async;
  352. private _unpackBinaryV2Async;
  353. private static _parseVersion;
  354. private static _compareVersion;
  355. private static readonly _logSpaces;
  356. private _logIndentLevel;
  357. private _loggingEnabled;
  358. /** @hidden */
  359. _log: (message: string) => void;
  360. /** @hidden */
  361. _logOpen(message: string): void;
  362. /** @hidden */
  363. _logClose(): void;
  364. private _logEnabled;
  365. private _logDisabled;
  366. private _capturePerformanceCounters;
  367. /** @hidden */
  368. _startPerformanceCounter: (counterName: string) => void;
  369. /** @hidden */
  370. _endPerformanceCounter: (counterName: string) => void;
  371. private _startPerformanceCounterEnabled;
  372. private _startPerformanceCounterDisabled;
  373. private _endPerformanceCounterEnabled;
  374. private _endPerformanceCounterDisabled;
  375. }
  376. }
  377. declare module BABYLON.GLTF1 {
  378. /**
  379. * Enums
  380. * @hidden
  381. */
  382. export enum EComponentType {
  383. BYTE = 5120,
  384. UNSIGNED_BYTE = 5121,
  385. SHORT = 5122,
  386. UNSIGNED_SHORT = 5123,
  387. FLOAT = 5126
  388. }
  389. /** @hidden */
  390. export enum EShaderType {
  391. FRAGMENT = 35632,
  392. VERTEX = 35633
  393. }
  394. /** @hidden */
  395. export enum EParameterType {
  396. BYTE = 5120,
  397. UNSIGNED_BYTE = 5121,
  398. SHORT = 5122,
  399. UNSIGNED_SHORT = 5123,
  400. INT = 5124,
  401. UNSIGNED_INT = 5125,
  402. FLOAT = 5126,
  403. FLOAT_VEC2 = 35664,
  404. FLOAT_VEC3 = 35665,
  405. FLOAT_VEC4 = 35666,
  406. INT_VEC2 = 35667,
  407. INT_VEC3 = 35668,
  408. INT_VEC4 = 35669,
  409. BOOL = 35670,
  410. BOOL_VEC2 = 35671,
  411. BOOL_VEC3 = 35672,
  412. BOOL_VEC4 = 35673,
  413. FLOAT_MAT2 = 35674,
  414. FLOAT_MAT3 = 35675,
  415. FLOAT_MAT4 = 35676,
  416. SAMPLER_2D = 35678
  417. }
  418. /** @hidden */
  419. export enum ETextureWrapMode {
  420. CLAMP_TO_EDGE = 33071,
  421. MIRRORED_REPEAT = 33648,
  422. REPEAT = 10497
  423. }
  424. /** @hidden */
  425. export enum ETextureFilterType {
  426. NEAREST = 9728,
  427. LINEAR = 9728,
  428. NEAREST_MIPMAP_NEAREST = 9984,
  429. LINEAR_MIPMAP_NEAREST = 9985,
  430. NEAREST_MIPMAP_LINEAR = 9986,
  431. LINEAR_MIPMAP_LINEAR = 9987
  432. }
  433. /** @hidden */
  434. export enum ETextureFormat {
  435. ALPHA = 6406,
  436. RGB = 6407,
  437. RGBA = 6408,
  438. LUMINANCE = 6409,
  439. LUMINANCE_ALPHA = 6410
  440. }
  441. /** @hidden */
  442. export enum ECullingType {
  443. FRONT = 1028,
  444. BACK = 1029,
  445. FRONT_AND_BACK = 1032
  446. }
  447. /** @hidden */
  448. export enum EBlendingFunction {
  449. ZERO = 0,
  450. ONE = 1,
  451. SRC_COLOR = 768,
  452. ONE_MINUS_SRC_COLOR = 769,
  453. DST_COLOR = 774,
  454. ONE_MINUS_DST_COLOR = 775,
  455. SRC_ALPHA = 770,
  456. ONE_MINUS_SRC_ALPHA = 771,
  457. DST_ALPHA = 772,
  458. ONE_MINUS_DST_ALPHA = 773,
  459. CONSTANT_COLOR = 32769,
  460. ONE_MINUS_CONSTANT_COLOR = 32770,
  461. CONSTANT_ALPHA = 32771,
  462. ONE_MINUS_CONSTANT_ALPHA = 32772,
  463. SRC_ALPHA_SATURATE = 776
  464. }
  465. /** @hidden */
  466. export interface IGLTFProperty {
  467. extensions?: {
  468. [key: string]: any;
  469. };
  470. extras?: Object;
  471. }
  472. /** @hidden */
  473. export interface IGLTFChildRootProperty extends IGLTFProperty {
  474. name?: string;
  475. }
  476. /** @hidden */
  477. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  478. bufferView: string;
  479. byteOffset: number;
  480. byteStride: number;
  481. count: number;
  482. type: string;
  483. componentType: EComponentType;
  484. max?: number[];
  485. min?: number[];
  486. name?: string;
  487. }
  488. /** @hidden */
  489. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  490. buffer: string;
  491. byteOffset: number;
  492. byteLength: number;
  493. byteStride: number;
  494. target?: number;
  495. }
  496. /** @hidden */
  497. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  498. uri: string;
  499. byteLength?: number;
  500. type?: string;
  501. }
  502. /** @hidden */
  503. export interface IGLTFShader extends IGLTFChildRootProperty {
  504. uri: string;
  505. type: EShaderType;
  506. }
  507. /** @hidden */
  508. export interface IGLTFProgram extends IGLTFChildRootProperty {
  509. attributes: string[];
  510. fragmentShader: string;
  511. vertexShader: string;
  512. }
  513. /** @hidden */
  514. export interface IGLTFTechniqueParameter {
  515. type: number;
  516. count?: number;
  517. semantic?: string;
  518. node?: string;
  519. value?: number | boolean | string | Array<any>;
  520. source?: string;
  521. babylonValue?: any;
  522. }
  523. /** @hidden */
  524. export interface IGLTFTechniqueCommonProfile {
  525. lightingModel: string;
  526. texcoordBindings: Object;
  527. parameters?: Array<any>;
  528. }
  529. /** @hidden */
  530. export interface IGLTFTechniqueStatesFunctions {
  531. blendColor?: number[];
  532. blendEquationSeparate?: number[];
  533. blendFuncSeparate?: number[];
  534. colorMask: boolean[];
  535. cullFace: number[];
  536. }
  537. /** @hidden */
  538. export interface IGLTFTechniqueStates {
  539. enable: number[];
  540. functions: IGLTFTechniqueStatesFunctions;
  541. }
  542. /** @hidden */
  543. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  544. parameters: {
  545. [key: string]: IGLTFTechniqueParameter;
  546. };
  547. program: string;
  548. attributes: {
  549. [key: string]: string;
  550. };
  551. uniforms: {
  552. [key: string]: string;
  553. };
  554. states: IGLTFTechniqueStates;
  555. }
  556. /** @hidden */
  557. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  558. technique?: string;
  559. values: string[];
  560. }
  561. /** @hidden */
  562. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  563. attributes: {
  564. [key: string]: string;
  565. };
  566. indices: string;
  567. material: string;
  568. mode?: number;
  569. }
  570. /** @hidden */
  571. export interface IGLTFMesh extends IGLTFChildRootProperty {
  572. primitives: IGLTFMeshPrimitive[];
  573. }
  574. /** @hidden */
  575. export interface IGLTFImage extends IGLTFChildRootProperty {
  576. uri: string;
  577. }
  578. /** @hidden */
  579. export interface IGLTFSampler extends IGLTFChildRootProperty {
  580. magFilter?: number;
  581. minFilter?: number;
  582. wrapS?: number;
  583. wrapT?: number;
  584. }
  585. /** @hidden */
  586. export interface IGLTFTexture extends IGLTFChildRootProperty {
  587. sampler: string;
  588. source: string;
  589. format?: ETextureFormat;
  590. internalFormat?: ETextureFormat;
  591. target?: number;
  592. type?: number;
  593. babylonTexture?: Texture;
  594. }
  595. /** @hidden */
  596. export interface IGLTFAmbienLight {
  597. color?: number[];
  598. }
  599. /** @hidden */
  600. export interface IGLTFDirectionalLight {
  601. color?: number[];
  602. }
  603. /** @hidden */
  604. export interface IGLTFPointLight {
  605. color?: number[];
  606. constantAttenuation?: number;
  607. linearAttenuation?: number;
  608. quadraticAttenuation?: number;
  609. }
  610. /** @hidden */
  611. export interface IGLTFSpotLight {
  612. color?: number[];
  613. constantAttenuation?: number;
  614. fallOfAngle?: number;
  615. fallOffExponent?: number;
  616. linearAttenuation?: number;
  617. quadraticAttenuation?: number;
  618. }
  619. /** @hidden */
  620. export interface IGLTFLight extends IGLTFChildRootProperty {
  621. type: string;
  622. }
  623. /** @hidden */
  624. export interface IGLTFCameraOrthographic {
  625. xmag: number;
  626. ymag: number;
  627. zfar: number;
  628. znear: number;
  629. }
  630. /** @hidden */
  631. export interface IGLTFCameraPerspective {
  632. aspectRatio: number;
  633. yfov: number;
  634. zfar: number;
  635. znear: number;
  636. }
  637. /** @hidden */
  638. export interface IGLTFCamera extends IGLTFChildRootProperty {
  639. type: string;
  640. }
  641. /** @hidden */
  642. export interface IGLTFAnimationChannelTarget {
  643. id: string;
  644. path: string;
  645. }
  646. /** @hidden */
  647. export interface IGLTFAnimationChannel {
  648. sampler: string;
  649. target: IGLTFAnimationChannelTarget;
  650. }
  651. /** @hidden */
  652. export interface IGLTFAnimationSampler {
  653. input: string;
  654. output: string;
  655. interpolation?: string;
  656. }
  657. /** @hidden */
  658. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  659. channels?: IGLTFAnimationChannel[];
  660. parameters?: {
  661. [key: string]: string;
  662. };
  663. samplers?: {
  664. [key: string]: IGLTFAnimationSampler;
  665. };
  666. }
  667. /** @hidden */
  668. export interface IGLTFNodeInstanceSkin {
  669. skeletons: string[];
  670. skin: string;
  671. meshes: string[];
  672. }
  673. /** @hidden */
  674. export interface IGLTFSkins extends IGLTFChildRootProperty {
  675. bindShapeMatrix: number[];
  676. inverseBindMatrices: string;
  677. jointNames: string[];
  678. babylonSkeleton?: Skeleton;
  679. }
  680. /** @hidden */
  681. export interface IGLTFNode extends IGLTFChildRootProperty {
  682. camera?: string;
  683. children: string[];
  684. skin?: string;
  685. jointName?: string;
  686. light?: string;
  687. matrix: number[];
  688. mesh?: string;
  689. meshes?: string[];
  690. rotation?: number[];
  691. scale?: number[];
  692. translation?: number[];
  693. babylonNode?: Node;
  694. }
  695. /** @hidden */
  696. export interface IGLTFScene extends IGLTFChildRootProperty {
  697. nodes: string[];
  698. }
  699. /** @hidden */
  700. export interface IGLTFRuntime {
  701. extensions: {
  702. [key: string]: any;
  703. };
  704. accessors: {
  705. [key: string]: IGLTFAccessor;
  706. };
  707. buffers: {
  708. [key: string]: IGLTFBuffer;
  709. };
  710. bufferViews: {
  711. [key: string]: IGLTFBufferView;
  712. };
  713. meshes: {
  714. [key: string]: IGLTFMesh;
  715. };
  716. lights: {
  717. [key: string]: IGLTFLight;
  718. };
  719. cameras: {
  720. [key: string]: IGLTFCamera;
  721. };
  722. nodes: {
  723. [key: string]: IGLTFNode;
  724. };
  725. images: {
  726. [key: string]: IGLTFImage;
  727. };
  728. textures: {
  729. [key: string]: IGLTFTexture;
  730. };
  731. shaders: {
  732. [key: string]: IGLTFShader;
  733. };
  734. programs: {
  735. [key: string]: IGLTFProgram;
  736. };
  737. samplers: {
  738. [key: string]: IGLTFSampler;
  739. };
  740. techniques: {
  741. [key: string]: IGLTFTechnique;
  742. };
  743. materials: {
  744. [key: string]: IGLTFMaterial;
  745. };
  746. animations: {
  747. [key: string]: IGLTFAnimation;
  748. };
  749. skins: {
  750. [key: string]: IGLTFSkins;
  751. };
  752. currentScene?: Object;
  753. scenes: {
  754. [key: string]: IGLTFScene;
  755. };
  756. extensionsUsed: string[];
  757. extensionsRequired?: string[];
  758. buffersCount: number;
  759. shaderscount: number;
  760. scene: Scene;
  761. rootUrl: string;
  762. loadedBufferCount: number;
  763. loadedBufferViews: {
  764. [name: string]: ArrayBufferView;
  765. };
  766. loadedShaderCount: number;
  767. importOnlyMeshes: boolean;
  768. importMeshesNames?: string[];
  769. dummyNodes: Node[];
  770. forAssetContainer: boolean;
  771. }
  772. /** @hidden */
  773. export interface INodeToRoot {
  774. bone: Bone;
  775. node: IGLTFNode;
  776. id: string;
  777. }
  778. /** @hidden */
  779. export interface IJointNode {
  780. node: IGLTFNode;
  781. id: string;
  782. }
  783. }
  784. declare module BABYLON.GLTF1 {
  785. /**
  786. * Utils functions for GLTF
  787. * @hidden
  788. */
  789. export class GLTFUtils {
  790. /**
  791. * Sets the given "parameter" matrix
  792. * @param scene: the Scene object
  793. * @param source: the source node where to pick the matrix
  794. * @param parameter: the GLTF technique parameter
  795. * @param uniformName: the name of the shader's uniform
  796. * @param shaderMaterial: the shader material
  797. */
  798. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  799. /**
  800. * Sets the given "parameter" matrix
  801. * @param shaderMaterial: the shader material
  802. * @param uniform: the name of the shader's uniform
  803. * @param value: the value of the uniform
  804. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  805. */
  806. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  807. /**
  808. * Returns the wrap mode of the texture
  809. * @param mode: the mode value
  810. */
  811. static GetWrapMode(mode: number): number;
  812. /**
  813. * Returns the byte stride giving an accessor
  814. * @param accessor: the GLTF accessor objet
  815. */
  816. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  817. /**
  818. * Returns the texture filter mode giving a mode value
  819. * @param mode: the filter mode value
  820. */
  821. static GetTextureFilterMode(mode: number): ETextureFilterType;
  822. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  823. /**
  824. * Returns a buffer from its accessor
  825. * @param gltfRuntime: the GLTF runtime
  826. * @param accessor: the GLTF accessor
  827. */
  828. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  829. /**
  830. * Decodes a buffer view into a string
  831. * @param view: the buffer view
  832. */
  833. static DecodeBufferToText(view: ArrayBufferView): string;
  834. /**
  835. * Returns the default material of gltf. Related to
  836. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  837. * @param scene: the Babylon.js scene
  838. */
  839. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  840. private static _DefaultMaterial;
  841. }
  842. }
  843. declare module BABYLON.GLTF1 {
  844. /**
  845. * Implementation of the base glTF spec
  846. * @hidden
  847. */
  848. export class GLTFLoaderBase {
  849. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  850. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  851. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  852. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  853. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  854. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  855. }
  856. /**
  857. * glTF V1 Loader
  858. * @hidden
  859. */
  860. export class GLTFLoader implements IGLTFLoader {
  861. static Extensions: {
  862. [name: string]: GLTFLoaderExtension;
  863. };
  864. static RegisterExtension(extension: GLTFLoaderExtension): void;
  865. state: Nullable<GLTFLoaderState>;
  866. dispose(): void;
  867. private _importMeshAsync;
  868. /**
  869. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  870. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  871. * @param scene the scene the meshes should be added to
  872. * @param forAssetContainer defines if the entities must be stored in the scene
  873. * @param data gltf data containing information of the meshes in a loaded file
  874. * @param rootUrl root url to load from
  875. * @param onProgress event that fires when loading progress has occured
  876. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  877. */
  878. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<ISceneLoaderAsyncResult>;
  879. private _loadAsync;
  880. /**
  881. * Imports all objects from a loaded gltf file and adds them to the scene
  882. * @param scene the scene the objects should be added to
  883. * @param data gltf data containing information of the meshes in a loaded file
  884. * @param rootUrl root url to load from
  885. * @param onProgress event that fires when loading progress has occured
  886. * @returns a promise which completes when objects have been loaded to the scene
  887. */
  888. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<void>;
  889. private _loadShadersAsync;
  890. private _loadBuffersAsync;
  891. private _createNodes;
  892. }
  893. /** @hidden */
  894. export abstract class GLTFLoaderExtension {
  895. private _name;
  896. constructor(name: string);
  897. get name(): string;
  898. /**
  899. * Defines an override for loading the runtime
  900. * Return true to stop further extensions from loading the runtime
  901. */
  902. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  903. /**
  904. * Defines an onverride for creating gltf runtime
  905. * Return true to stop further extensions from creating the runtime
  906. */
  907. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  908. /**
  909. * Defines an override for loading buffers
  910. * Return true to stop further extensions from loading this buffer
  911. */
  912. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  913. /**
  914. * Defines an override for loading texture buffers
  915. * Return true to stop further extensions from loading this texture data
  916. */
  917. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  918. /**
  919. * Defines an override for creating textures
  920. * Return true to stop further extensions from loading this texture
  921. */
  922. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  923. /**
  924. * Defines an override for loading shader strings
  925. * Return true to stop further extensions from loading this shader data
  926. */
  927. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  928. /**
  929. * Defines an override for loading materials
  930. * Return true to stop further extensions from loading this material
  931. */
  932. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  933. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  934. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  935. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  936. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  937. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  938. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  939. private static LoadTextureBufferAsync;
  940. private static CreateTextureAsync;
  941. private static ApplyExtensions;
  942. }
  943. }
  944. declare module BABYLON.GLTF1 {
  945. /** @hidden */
  946. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  947. private _bin;
  948. constructor();
  949. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  950. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  951. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  952. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  953. }
  954. }
  955. declare module BABYLON.GLTF1 {
  956. /** @hidden */
  957. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  958. constructor();
  959. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  960. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  961. private _loadTexture;
  962. }
  963. }
  964. declare module BABYLON.GLTF2.Loader {
  965. /**
  966. * Loader interface with an index field.
  967. */
  968. export interface IArrayItem {
  969. /**
  970. * The index of this item in the array.
  971. */
  972. index: number;
  973. }
  974. /**
  975. * Loader interface with additional members.
  976. */
  977. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  978. /** @hidden */
  979. _data?: Promise<ArrayBufferView>;
  980. /** @hidden */
  981. _babylonVertexBuffer?: Promise<VertexBuffer>;
  982. }
  983. /**
  984. * Loader interface with additional members.
  985. */
  986. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  987. }
  988. /** @hidden */
  989. export interface _IAnimationSamplerData {
  990. input: Float32Array;
  991. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  992. output: Float32Array;
  993. }
  994. /**
  995. * Loader interface with additional members.
  996. */
  997. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  998. /** @hidden */
  999. _data?: Promise<_IAnimationSamplerData>;
  1000. }
  1001. /**
  1002. * Loader interface with additional members.
  1003. */
  1004. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  1005. channels: IAnimationChannel[];
  1006. samplers: IAnimationSampler[];
  1007. /** @hidden */
  1008. _babylonAnimationGroup?: AnimationGroup;
  1009. }
  1010. /**
  1011. * Loader interface with additional members.
  1012. */
  1013. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  1014. /** @hidden */
  1015. _data?: Promise<ArrayBufferView>;
  1016. }
  1017. /**
  1018. * Loader interface with additional members.
  1019. */
  1020. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  1021. /** @hidden */
  1022. _data?: Promise<ArrayBufferView>;
  1023. /** @hidden */
  1024. _babylonBuffer?: Promise<Buffer>;
  1025. }
  1026. /**
  1027. * Loader interface with additional members.
  1028. */
  1029. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  1030. }
  1031. /**
  1032. * Loader interface with additional members.
  1033. */
  1034. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  1035. /** @hidden */
  1036. _data?: Promise<ArrayBufferView>;
  1037. }
  1038. /**
  1039. * Loader interface with additional members.
  1040. */
  1041. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1042. }
  1043. /**
  1044. * Loader interface with additional members.
  1045. */
  1046. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1047. }
  1048. /**
  1049. * Loader interface with additional members.
  1050. */
  1051. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  1052. baseColorTexture?: ITextureInfo;
  1053. metallicRoughnessTexture?: ITextureInfo;
  1054. }
  1055. /**
  1056. * Loader interface with additional members.
  1057. */
  1058. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  1059. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1060. normalTexture?: IMaterialNormalTextureInfo;
  1061. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1062. emissiveTexture?: ITextureInfo;
  1063. /** @hidden */
  1064. _data?: {
  1065. [babylonDrawMode: number]: {
  1066. babylonMaterial: Material;
  1067. babylonMeshes: AbstractMesh[];
  1068. promise: Promise<void>;
  1069. };
  1070. };
  1071. }
  1072. /**
  1073. * Loader interface with additional members.
  1074. */
  1075. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  1076. primitives: IMeshPrimitive[];
  1077. }
  1078. /**
  1079. * Loader interface with additional members.
  1080. */
  1081. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  1082. /** @hidden */
  1083. _instanceData?: {
  1084. babylonSourceMesh: Mesh;
  1085. promise: Promise<any>;
  1086. };
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  1092. /**
  1093. * The parent glTF node.
  1094. */
  1095. parent?: INode;
  1096. /** @hidden */
  1097. _babylonTransformNode?: TransformNode;
  1098. /** @hidden */
  1099. _primitiveBabylonMeshes?: AbstractMesh[];
  1100. /** @hidden */
  1101. _babylonBones?: Bone[];
  1102. /** @hidden */
  1103. _numMorphTargets?: number;
  1104. }
  1105. /** @hidden */
  1106. export interface _ISamplerData {
  1107. noMipMaps: boolean;
  1108. samplingMode: number;
  1109. wrapU: number;
  1110. wrapV: number;
  1111. }
  1112. /**
  1113. * Loader interface with additional members.
  1114. */
  1115. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  1116. /** @hidden */
  1117. _data?: _ISamplerData;
  1118. }
  1119. /**
  1120. * Loader interface with additional members.
  1121. */
  1122. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  1123. }
  1124. /**
  1125. * Loader interface with additional members.
  1126. */
  1127. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  1128. /** @hidden */
  1129. _data?: {
  1130. babylonSkeleton: Skeleton;
  1131. promise: Promise<void>;
  1132. };
  1133. }
  1134. /**
  1135. * Loader interface with additional members.
  1136. */
  1137. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  1138. /** @hidden */
  1139. _textureInfo: ITextureInfo;
  1140. }
  1141. /**
  1142. * Loader interface with additional members.
  1143. */
  1144. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  1145. /** false or undefined if the texture holds color data (true if data are roughness, normal, ...) */
  1146. nonColorData?: boolean;
  1147. }
  1148. /**
  1149. * Loader interface with additional members.
  1150. */
  1151. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  1152. accessors?: IAccessor[];
  1153. animations?: IAnimation[];
  1154. buffers?: IBuffer[];
  1155. bufferViews?: IBufferView[];
  1156. cameras?: ICamera[];
  1157. images?: IImage[];
  1158. materials?: IMaterial[];
  1159. meshes?: IMesh[];
  1160. nodes?: INode[];
  1161. samplers?: ISampler[];
  1162. scenes?: IScene[];
  1163. skins?: ISkin[];
  1164. textures?: ITexture[];
  1165. }
  1166. }
  1167. declare module BABYLON.GLTF2 {
  1168. /**
  1169. * Interface for a glTF loader extension.
  1170. */
  1171. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1172. /**
  1173. * Called after the loader state changes to LOADING.
  1174. */
  1175. onLoading?(): void;
  1176. /**
  1177. * Called after the loader state changes to READY.
  1178. */
  1179. onReady?(): void;
  1180. /**
  1181. * Define this method to modify the default behavior when loading scenes.
  1182. * @param context The context when loading the asset
  1183. * @param scene The glTF scene property
  1184. * @returns A promise that resolves when the load is complete or null if not handled
  1185. */
  1186. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1187. /**
  1188. * Define this method to modify the default behavior when loading nodes.
  1189. * @param context The context when loading the asset
  1190. * @param node The glTF node property
  1191. * @param assign A function called synchronously after parsing the glTF properties
  1192. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1193. */
  1194. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1195. /**
  1196. * Define this method to modify the default behavior when loading cameras.
  1197. * @param context The context when loading the asset
  1198. * @param camera The glTF camera property
  1199. * @param assign A function called synchronously after parsing the glTF properties
  1200. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1201. */
  1202. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1203. /**
  1204. * @hidden
  1205. * Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1206. * @param context The context when loading the asset
  1207. * @param primitive The glTF mesh primitive property
  1208. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1209. */
  1210. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1211. /**
  1212. * @hidden
  1213. * Define this method to modify the default behavior when loading data for mesh primitives.
  1214. * @param context The context when loading the asset
  1215. * @param name The mesh name when loading the asset
  1216. * @param node The glTF node when loading the asset
  1217. * @param mesh The glTF mesh when loading the asset
  1218. * @param primitive The glTF mesh primitive property
  1219. * @param assign A function called synchronously after parsing the glTF properties
  1220. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1221. */
  1222. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1223. /**
  1224. * @hidden
  1225. * Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1226. * @param context The context when loading the asset
  1227. * @param material The glTF material property
  1228. * @param assign A function called synchronously after parsing the glTF properties
  1229. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1230. */
  1231. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Nullable<Mesh>, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1232. /**
  1233. * Define this method to modify the default behavior when creating materials.
  1234. * @param context The context when loading the asset
  1235. * @param material The glTF material property
  1236. * @param babylonDrawMode The draw mode for the Babylon material
  1237. * @returns The Babylon material or null if not handled
  1238. */
  1239. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1240. /**
  1241. * Define this method to modify the default behavior when loading material properties.
  1242. * @param context The context when loading the asset
  1243. * @param material The glTF material property
  1244. * @param babylonMaterial The Babylon material
  1245. * @returns A promise that resolves when the load is complete or null if not handled
  1246. */
  1247. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1248. /**
  1249. * Define this method to modify the default behavior when loading texture infos.
  1250. * @param context The context when loading the asset
  1251. * @param textureInfo The glTF texture info property
  1252. * @param assign A function called synchronously after parsing the glTF properties
  1253. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1254. */
  1255. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1256. /**
  1257. * @hidden
  1258. * Define this method to modify the default behavior when loading textures.
  1259. * @param context The context when loading the asset
  1260. * @param texture The glTF texture property
  1261. * @param assign A function called synchronously after parsing the glTF properties
  1262. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1263. */
  1264. _loadTextureAsync?(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1265. /**
  1266. * Define this method to modify the default behavior when loading animations.
  1267. * @param context The context when loading the asset
  1268. * @param animation The glTF animation property
  1269. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1270. */
  1271. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1272. /**
  1273. * @hidden
  1274. * Define this method to modify the default behavior when loading skins.
  1275. * @param context The context when loading the asset
  1276. * @param node The glTF node property
  1277. * @param skin The glTF skin property
  1278. * @returns A promise that resolves when the load is complete or null if not handled
  1279. */
  1280. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1281. /**
  1282. * @hidden
  1283. * Define this method to modify the default behavior when loading uris.
  1284. * @param context The context when loading the asset
  1285. * @param property The glTF property associated with the uri
  1286. * @param uri The uri to load
  1287. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1288. */
  1289. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1290. /**
  1291. * Define this method to modify the default behavior when loading buffer views.
  1292. * @param context The context when loading the asset
  1293. * @param bufferView The glTF buffer view property
  1294. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1295. */
  1296. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1297. /**
  1298. * Define this method to modify the default behavior when loading buffers.
  1299. * @param context The context when loading the asset
  1300. * @param buffer The glTF buffer property
  1301. * @param byteOffset The byte offset to load
  1302. * @param byteLength The byte length to load
  1303. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1304. */
  1305. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1306. }
  1307. }
  1308. declare module BABYLON.GLTF2 {
  1309. /**
  1310. * Helper class for working with arrays when loading the glTF asset
  1311. */
  1312. export class ArrayItem {
  1313. /**
  1314. * Gets an item from the given array.
  1315. * @param context The context when loading the asset
  1316. * @param array The array to get the item from
  1317. * @param index The index to the array
  1318. * @returns The array item
  1319. */
  1320. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1321. /**
  1322. * Assign an `index` field to each item of the given array.
  1323. * @param array The array of items
  1324. */
  1325. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1326. }
  1327. /**
  1328. * The glTF 2.0 loader
  1329. */
  1330. export class GLTFLoader implements IGLTFLoader {
  1331. /** @hidden */
  1332. _completePromises: Promise<any>[];
  1333. /** @hidden */
  1334. _forAssetContainer: boolean;
  1335. /** Storage */
  1336. _babylonLights: Light[];
  1337. /** @hidden */
  1338. _disableInstancedMesh: number;
  1339. private _disposed;
  1340. private _parent;
  1341. private _state;
  1342. private _extensions;
  1343. private _rootUrl;
  1344. private _fileName;
  1345. private _uniqueRootUrl;
  1346. private _gltf;
  1347. private _bin;
  1348. private _babylonScene;
  1349. private _rootBabylonMesh;
  1350. private _defaultBabylonMaterialData;
  1351. private static _RegisteredExtensions;
  1352. /**
  1353. * The default glTF sampler.
  1354. */
  1355. static readonly DefaultSampler: ISampler;
  1356. /**
  1357. * Registers a loader extension.
  1358. * @param name The name of the loader extension.
  1359. * @param factory The factory function that creates the loader extension.
  1360. */
  1361. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1362. /**
  1363. * Unregisters a loader extension.
  1364. * @param name The name of the loader extension.
  1365. * @returns A boolean indicating whether the extension has been unregistered
  1366. */
  1367. static UnregisterExtension(name: string): boolean;
  1368. /**
  1369. * The loader state.
  1370. */
  1371. get state(): Nullable<GLTFLoaderState>;
  1372. /**
  1373. * The object that represents the glTF JSON.
  1374. */
  1375. get gltf(): IGLTF;
  1376. /**
  1377. * The BIN chunk of a binary glTF.
  1378. */
  1379. get bin(): Nullable<IDataBuffer>;
  1380. /**
  1381. * The parent file loader.
  1382. */
  1383. get parent(): GLTFFileLoader;
  1384. /**
  1385. * The Babylon scene when loading the asset.
  1386. */
  1387. get babylonScene(): Scene;
  1388. /**
  1389. * The root Babylon mesh when loading the asset.
  1390. */
  1391. get rootBabylonMesh(): Mesh;
  1392. /** @hidden */
  1393. constructor(parent: GLTFFileLoader);
  1394. /** @hidden */
  1395. dispose(): void;
  1396. /** @hidden */
  1397. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
  1398. /** @hidden */
  1399. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1400. private _loadAsync;
  1401. private _loadData;
  1402. private _setupData;
  1403. private _loadExtensions;
  1404. private _checkExtensions;
  1405. private _setState;
  1406. private _createRootNode;
  1407. /**
  1408. * Loads a glTF scene.
  1409. * @param context The context when loading the asset
  1410. * @param scene The glTF scene property
  1411. * @returns A promise that resolves when the load is complete
  1412. */
  1413. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1414. private _forEachPrimitive;
  1415. private _getGeometries;
  1416. private _getMeshes;
  1417. private _getTransformNodes;
  1418. private _getSkeletons;
  1419. private _getAnimationGroups;
  1420. private _startAnimations;
  1421. /**
  1422. * Loads a glTF node.
  1423. * @param context The context when loading the asset
  1424. * @param node The glTF node property
  1425. * @param assign A function called synchronously after parsing the glTF properties
  1426. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1427. */
  1428. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1429. private _loadMeshAsync;
  1430. /**
  1431. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1432. * @param context The context when loading the asset
  1433. * @param name The mesh name when loading the asset
  1434. * @param node The glTF node when loading the asset
  1435. * @param mesh The glTF mesh when loading the asset
  1436. * @param primitive The glTF mesh primitive property
  1437. * @param assign A function called synchronously after parsing the glTF properties
  1438. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1439. */
  1440. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1441. private _loadVertexDataAsync;
  1442. private _createMorphTargets;
  1443. private _loadMorphTargetsAsync;
  1444. private _loadMorphTargetVertexDataAsync;
  1445. private static _LoadTransform;
  1446. private _loadSkinAsync;
  1447. private _loadBones;
  1448. private _loadBone;
  1449. private _loadSkinInverseBindMatricesDataAsync;
  1450. private _updateBoneMatrices;
  1451. private _getNodeMatrix;
  1452. /**
  1453. * Loads a glTF camera.
  1454. * @param context The context when loading the asset
  1455. * @param camera The glTF camera property
  1456. * @param assign A function called synchronously after parsing the glTF properties
  1457. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1458. */
  1459. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1460. private _loadAnimationsAsync;
  1461. /**
  1462. * Loads a glTF animation.
  1463. * @param context The context when loading the asset
  1464. * @param animation The glTF animation property
  1465. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1466. */
  1467. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1468. /**
  1469. * @hidden Loads a glTF animation channel.
  1470. * @param context The context when loading the asset
  1471. * @param animationContext The context of the animation when loading the asset
  1472. * @param animation The glTF animation property
  1473. * @param channel The glTF animation channel property
  1474. * @param babylonAnimationGroup The babylon animation group property
  1475. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1476. * @returns A void promise when the channel load is complete
  1477. */
  1478. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1479. private _loadAnimationSamplerAsync;
  1480. private _loadBufferAsync;
  1481. /**
  1482. * Loads a glTF buffer view.
  1483. * @param context The context when loading the asset
  1484. * @param bufferView The glTF buffer view property
  1485. * @returns A promise that resolves with the loaded data when the load is complete
  1486. */
  1487. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1488. private _loadAccessorAsync;
  1489. /** @hidden */
  1490. _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array>;
  1491. private _loadIndicesAccessorAsync;
  1492. private _loadVertexBufferViewAsync;
  1493. private _loadVertexAccessorAsync;
  1494. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1495. /** @hidden */
  1496. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Nullable<Mesh>, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1497. private _createDefaultMaterial;
  1498. /**
  1499. * Creates a Babylon material from a glTF material.
  1500. * @param context The context when loading the asset
  1501. * @param material The glTF material property
  1502. * @param babylonDrawMode The draw mode for the Babylon material
  1503. * @returns The Babylon material
  1504. */
  1505. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1506. /**
  1507. * Loads properties from a glTF material into a Babylon material.
  1508. * @param context The context when loading the asset
  1509. * @param material The glTF material property
  1510. * @param babylonMaterial The Babylon material
  1511. * @returns A promise that resolves when the load is complete
  1512. */
  1513. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1514. /**
  1515. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1516. * @param context The context when loading the asset
  1517. * @param material The glTF material property
  1518. * @param babylonMaterial The Babylon material
  1519. * @returns A promise that resolves when the load is complete
  1520. */
  1521. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1522. /**
  1523. * Loads the alpha properties from a glTF material into a Babylon material.
  1524. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1525. * @param context The context when loading the asset
  1526. * @param material The glTF material property
  1527. * @param babylonMaterial The Babylon material
  1528. */
  1529. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1530. /**
  1531. * Loads a glTF texture info.
  1532. * @param context The context when loading the asset
  1533. * @param textureInfo The glTF texture info property
  1534. * @param assign A function called synchronously after parsing the glTF properties
  1535. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1536. */
  1537. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1538. /** @hidden */
  1539. _loadTextureAsync(context: string, texture: ITexture, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1540. /** @hidden */
  1541. _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void, textureLoaderOptions?: any): Promise<BaseTexture>;
  1542. private _loadSampler;
  1543. /**
  1544. * Loads a glTF image.
  1545. * @param context The context when loading the asset
  1546. * @param image The glTF image property
  1547. * @returns A promise that resolves with the loaded data when the load is complete
  1548. */
  1549. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1550. /**
  1551. * Loads a glTF uri.
  1552. * @param context The context when loading the asset
  1553. * @param property The glTF property associated with the uri
  1554. * @param uri The base64 or relative uri
  1555. * @returns A promise that resolves with the loaded data when the load is complete
  1556. */
  1557. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1558. /**
  1559. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1560. * @param babylonObject the Babylon object with metadata
  1561. * @param pointer the JSON pointer
  1562. */
  1563. static AddPointerMetadata(babylonObject: {
  1564. metadata: any;
  1565. }, pointer: string): void;
  1566. private static _GetTextureWrapMode;
  1567. private static _GetTextureSamplingMode;
  1568. private static _GetTypedArrayConstructor;
  1569. private static _GetTypedArray;
  1570. private static _GetNumComponents;
  1571. private static _ValidateUri;
  1572. /** @hidden */
  1573. static _GetDrawMode(context: string, mode: number | undefined): number;
  1574. private _compileMaterialsAsync;
  1575. private _compileShadowGeneratorsAsync;
  1576. private _forEachExtensions;
  1577. private _applyExtensions;
  1578. private _extensionsOnLoading;
  1579. private _extensionsOnReady;
  1580. private _extensionsLoadSceneAsync;
  1581. private _extensionsLoadNodeAsync;
  1582. private _extensionsLoadCameraAsync;
  1583. private _extensionsLoadVertexDataAsync;
  1584. private _extensionsLoadMeshPrimitiveAsync;
  1585. private _extensionsLoadMaterialAsync;
  1586. private _extensionsCreateMaterial;
  1587. private _extensionsLoadMaterialPropertiesAsync;
  1588. private _extensionsLoadTextureInfoAsync;
  1589. private _extensionsLoadTextureAsync;
  1590. private _extensionsLoadAnimationAsync;
  1591. private _extensionsLoadSkinAsync;
  1592. private _extensionsLoadUriAsync;
  1593. private _extensionsLoadBufferViewAsync;
  1594. private _extensionsLoadBufferAsync;
  1595. /**
  1596. * Helper method called by a loader extension to load an glTF extension.
  1597. * @param context The context when loading the asset
  1598. * @param property The glTF property to load the extension from
  1599. * @param extensionName The name of the extension to load
  1600. * @param actionAsync The action to run
  1601. * @returns The promise returned by actionAsync or null if the extension does not exist
  1602. */
  1603. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1604. /**
  1605. * Helper method called by a loader extension to load a glTF extra.
  1606. * @param context The context when loading the asset
  1607. * @param property The glTF property to load the extra from
  1608. * @param extensionName The name of the extension to load
  1609. * @param actionAsync The action to run
  1610. * @returns The promise returned by actionAsync or null if the extra does not exist
  1611. */
  1612. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1613. /**
  1614. * Checks for presence of an extension.
  1615. * @param name The name of the extension to check
  1616. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1617. */
  1618. isExtensionUsed(name: string): boolean;
  1619. /**
  1620. * Increments the indentation level and logs a message.
  1621. * @param message The message to log
  1622. */
  1623. logOpen(message: string): void;
  1624. /**
  1625. * Decrements the indentation level.
  1626. */
  1627. logClose(): void;
  1628. /**
  1629. * Logs a message
  1630. * @param message The message to log
  1631. */
  1632. log(message: string): void;
  1633. /**
  1634. * Starts a performance counter.
  1635. * @param counterName The name of the performance counter
  1636. */
  1637. startPerformanceCounter(counterName: string): void;
  1638. /**
  1639. * Ends a performance counter.
  1640. * @param counterName The name of the performance counter
  1641. */
  1642. endPerformanceCounter(counterName: string): void;
  1643. }
  1644. }
  1645. declare module BABYLON.GLTF2.Loader.Extensions {
  1646. /** @hidden */
  1647. interface IEXTLightsImageBased_LightImageBased {
  1648. _babylonTexture?: BaseTexture;
  1649. _loaded?: Promise<void>;
  1650. }
  1651. /**
  1652. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1653. */
  1654. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1655. /**
  1656. * The name of this extension.
  1657. */
  1658. readonly name: string;
  1659. /**
  1660. * Defines whether this extension is enabled.
  1661. */
  1662. enabled: boolean;
  1663. private _loader;
  1664. private _lights?;
  1665. /** @hidden */
  1666. constructor(loader: GLTFLoader);
  1667. /** @hidden */
  1668. dispose(): void;
  1669. /** @hidden */
  1670. onLoading(): void;
  1671. /** @hidden */
  1672. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1673. private _loadLightAsync;
  1674. }
  1675. }
  1676. declare module BABYLON.GLTF2.Loader.Extensions {
  1677. /**
  1678. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  1679. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  1680. * !!! Experimental Extension Subject to Changes !!!
  1681. */
  1682. export class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
  1683. /**
  1684. * The name of this extension.
  1685. */
  1686. readonly name: string;
  1687. /**
  1688. * Defines whether this extension is enabled.
  1689. */
  1690. enabled: boolean;
  1691. private _loader;
  1692. /** @hidden */
  1693. constructor(loader: GLTFLoader);
  1694. /** @hidden */
  1695. dispose(): void;
  1696. /** @hidden */
  1697. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1698. }
  1699. }
  1700. declare module BABYLON.GLTF2.Loader.Extensions {
  1701. /**
  1702. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression)
  1703. *
  1704. * This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js
  1705. */
  1706. export class EXT_meshopt_compression implements IGLTFLoaderExtension {
  1707. /**
  1708. * The name of this extension.
  1709. */
  1710. readonly name: string;
  1711. /**
  1712. * Defines whether this extension is enabled.
  1713. */
  1714. enabled: boolean;
  1715. /**
  1716. * Path to decoder module; defaults to https://preview.babylonjs.com/meshopt_decoder.module.js
  1717. */
  1718. static DecoderPath: string;
  1719. private _loader;
  1720. private _decoder;
  1721. /** @hidden */
  1722. constructor(loader: GLTFLoader);
  1723. /** @hidden */
  1724. dispose(): void;
  1725. /** @hidden */
  1726. loadBufferViewAsync(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1727. }
  1728. }
  1729. declare module BABYLON.GLTF2.Loader.Extensions {
  1730. /**
  1731. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_texture_webp/)
  1732. */
  1733. export class EXT_texture_webp implements IGLTFLoaderExtension {
  1734. /** The name of this extension. */
  1735. readonly name: string;
  1736. /** Defines whether this extension is enabled. */
  1737. enabled: boolean;
  1738. private _loader;
  1739. /** @hidden */
  1740. constructor(loader: GLTFLoader);
  1741. /** @hidden */
  1742. dispose(): void;
  1743. /** @hidden */
  1744. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1745. }
  1746. }
  1747. declare module BABYLON.GLTF2.Loader.Extensions {
  1748. /**
  1749. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1750. */
  1751. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1752. /**
  1753. * The name of this extension.
  1754. */
  1755. readonly name: string;
  1756. /**
  1757. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1758. */
  1759. dracoCompression?: DracoCompression;
  1760. /**
  1761. * Defines whether this extension is enabled.
  1762. */
  1763. enabled: boolean;
  1764. private _loader;
  1765. /** @hidden */
  1766. constructor(loader: GLTFLoader);
  1767. /** @hidden */
  1768. dispose(): void;
  1769. /** @hidden */
  1770. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1771. }
  1772. }
  1773. declare module BABYLON.GLTF2.Loader.Extensions {
  1774. /**
  1775. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  1776. */
  1777. export class KHR_lights implements IGLTFLoaderExtension {
  1778. /**
  1779. * The name of this extension.
  1780. */
  1781. readonly name: string;
  1782. /**
  1783. * Defines whether this extension is enabled.
  1784. */
  1785. enabled: boolean;
  1786. private _loader;
  1787. private _lights?;
  1788. /** @hidden */
  1789. constructor(loader: GLTFLoader);
  1790. /** @hidden */
  1791. dispose(): void;
  1792. /** @hidden */
  1793. onLoading(): void;
  1794. /** @hidden */
  1795. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1796. }
  1797. }
  1798. declare module BABYLON.GLTF2.Loader.Extensions {
  1799. /**
  1800. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1801. */
  1802. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1803. /**
  1804. * The name of this extension.
  1805. */
  1806. readonly name: string;
  1807. /**
  1808. * Defines whether this extension is enabled.
  1809. */
  1810. enabled: boolean;
  1811. /**
  1812. * Defines a number that determines the order the extensions are applied.
  1813. */
  1814. order: number;
  1815. private _loader;
  1816. /** @hidden */
  1817. constructor(loader: GLTFLoader);
  1818. /** @hidden */
  1819. dispose(): void;
  1820. /** @hidden */
  1821. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1822. private _loadSpecularGlossinessPropertiesAsync;
  1823. }
  1824. }
  1825. declare module BABYLON.GLTF2.Loader.Extensions {
  1826. /**
  1827. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1828. */
  1829. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1830. /**
  1831. * The name of this extension.
  1832. */
  1833. readonly name: string;
  1834. /**
  1835. * Defines whether this extension is enabled.
  1836. */
  1837. enabled: boolean;
  1838. /**
  1839. * Defines a number that determines the order the extensions are applied.
  1840. */
  1841. order: number;
  1842. private _loader;
  1843. /** @hidden */
  1844. constructor(loader: GLTFLoader);
  1845. /** @hidden */
  1846. dispose(): void;
  1847. /** @hidden */
  1848. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1849. private _loadUnlitPropertiesAsync;
  1850. }
  1851. }
  1852. declare module BABYLON.GLTF2.Loader.Extensions {
  1853. /**
  1854. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)
  1855. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1856. */
  1857. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1858. /**
  1859. * The name of this extension.
  1860. */
  1861. readonly name: string;
  1862. /**
  1863. * Defines whether this extension is enabled.
  1864. */
  1865. enabled: boolean;
  1866. /**
  1867. * Defines a number that determines the order the extensions are applied.
  1868. */
  1869. order: number;
  1870. private _loader;
  1871. /** @hidden */
  1872. constructor(loader: GLTFLoader);
  1873. /** @hidden */
  1874. dispose(): void;
  1875. /** @hidden */
  1876. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1877. private _loadClearCoatPropertiesAsync;
  1878. }
  1879. }
  1880. declare module BABYLON.GLTF2.Loader.Extensions {
  1881. /**
  1882. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_sheen/README.md)
  1883. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1884. * !!! Experimental Extension Subject to Changes !!!
  1885. */
  1886. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1887. /**
  1888. * The name of this extension.
  1889. */
  1890. readonly name: string;
  1891. /**
  1892. * Defines whether this extension is enabled.
  1893. */
  1894. enabled: boolean;
  1895. /**
  1896. * Defines a number that determines the order the extensions are applied.
  1897. */
  1898. order: number;
  1899. private _loader;
  1900. /** @hidden */
  1901. constructor(loader: GLTFLoader);
  1902. /** @hidden */
  1903. dispose(): void;
  1904. /** @hidden */
  1905. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1906. private _loadSheenPropertiesAsync;
  1907. }
  1908. }
  1909. declare module BABYLON.GLTF2.Loader.Extensions {
  1910. /**
  1911. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  1912. * !!! Experimental Extension Subject to Changes !!!
  1913. */
  1914. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1915. /**
  1916. * The name of this extension.
  1917. */
  1918. readonly name: string;
  1919. /**
  1920. * Defines whether this extension is enabled.
  1921. */
  1922. enabled: boolean;
  1923. /**
  1924. * Defines a number that determines the order the extensions are applied.
  1925. */
  1926. order: number;
  1927. private _loader;
  1928. /** @hidden */
  1929. constructor(loader: GLTFLoader);
  1930. /** @hidden */
  1931. dispose(): void;
  1932. /** @hidden */
  1933. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1934. private _loadSpecularPropertiesAsync;
  1935. }
  1936. }
  1937. declare module BABYLON.GLTF2.Loader.Extensions {
  1938. /**
  1939. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  1940. * !!! Experimental Extension Subject to Changes !!!
  1941. */
  1942. export class KHR_materials_ior implements IGLTFLoaderExtension {
  1943. /**
  1944. * Default ior Value from the spec.
  1945. */
  1946. private static readonly _DEFAULT_IOR;
  1947. /**
  1948. * The name of this extension.
  1949. */
  1950. readonly name: string;
  1951. /**
  1952. * Defines whether this extension is enabled.
  1953. */
  1954. enabled: boolean;
  1955. /**
  1956. * Defines a number that determines the order the extensions are applied.
  1957. */
  1958. order: number;
  1959. private _loader;
  1960. /** @hidden */
  1961. constructor(loader: GLTFLoader);
  1962. /** @hidden */
  1963. dispose(): void;
  1964. /** @hidden */
  1965. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1966. private _loadIorPropertiesAsync;
  1967. }
  1968. }
  1969. declare module BABYLON.GLTF2.Loader.Extensions {
  1970. /**
  1971. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)
  1972. */
  1973. export class KHR_materials_variants implements IGLTFLoaderExtension {
  1974. /**
  1975. * The name of this extension.
  1976. */
  1977. readonly name: string;
  1978. /**
  1979. * Defines whether this extension is enabled.
  1980. */
  1981. enabled: boolean;
  1982. private _loader;
  1983. private _variants?;
  1984. /** @hidden */
  1985. constructor(loader: GLTFLoader);
  1986. /** @hidden */
  1987. dispose(): void;
  1988. /**
  1989. * Gets the list of available variant names for this asset.
  1990. * @param rootMesh The glTF root mesh
  1991. * @returns the list of all the variant names for this model
  1992. */
  1993. static GetAvailableVariants(rootMesh: Mesh): string[];
  1994. /**
  1995. * Gets the list of available variant names for this asset.
  1996. * @param rootMesh The glTF root mesh
  1997. * @returns the list of all the variant names for this model
  1998. */
  1999. getAvailableVariants(rootMesh: Mesh): string[];
  2000. /**
  2001. * Select a variant given a variant name or a list of variant names.
  2002. * @param rootMesh The glTF root mesh
  2003. * @param variantName The variant name(s) to select.
  2004. */
  2005. static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void;
  2006. /**
  2007. * Select a variant given a variant name or a list of variant names.
  2008. * @param rootMesh The glTF root mesh
  2009. * @param variantName The variant name(s) to select.
  2010. */
  2011. selectVariant(rootMesh: Mesh, variantName: string | string[]): void;
  2012. /**
  2013. * Reset back to the original before selecting a variant.
  2014. * @param rootMesh The glTF root mesh
  2015. */
  2016. static Reset(rootMesh: Mesh): void;
  2017. /**
  2018. * Reset back to the original before selecting a variant.
  2019. * @param rootMesh The glTF root mesh
  2020. */
  2021. reset(rootMesh: Mesh): void;
  2022. /**
  2023. * Gets the last selected variant name(s) or null if original.
  2024. * @param rootMesh The glTF root mesh
  2025. * @returns The selected variant name(s).
  2026. */
  2027. static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]>;
  2028. /**
  2029. * Gets the last selected variant name(s) or null if original.
  2030. * @param rootMesh The glTF root mesh
  2031. * @returns The selected variant name(s).
  2032. */
  2033. getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]>;
  2034. private static _GetExtensionMetadata;
  2035. /** @hidden */
  2036. onLoading(): void;
  2037. /** @hidden */
  2038. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  2039. }
  2040. }
  2041. declare module BABYLON.GLTF2.Loader.Extensions {
  2042. /**
  2043. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
  2044. */
  2045. export class KHR_materials_transmission implements IGLTFLoaderExtension {
  2046. /**
  2047. * The name of this extension.
  2048. */
  2049. readonly name: string;
  2050. /**
  2051. * Defines whether this extension is enabled.
  2052. */
  2053. enabled: boolean;
  2054. /**
  2055. * Defines a number that determines the order the extensions are applied.
  2056. */
  2057. order: number;
  2058. private _loader;
  2059. /** @hidden */
  2060. constructor(loader: GLTFLoader);
  2061. /** @hidden */
  2062. dispose(): void;
  2063. /** @hidden */
  2064. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2065. private _loadTransparentPropertiesAsync;
  2066. }
  2067. }
  2068. declare module BABYLON.GLTF2.Loader.Extensions {
  2069. /**
  2070. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
  2071. * !!! Experimental Extension Subject to Changes !!!
  2072. */
  2073. export class KHR_materials_translucency implements IGLTFLoaderExtension {
  2074. /**
  2075. * The name of this extension.
  2076. */
  2077. readonly name: string;
  2078. /**
  2079. * Defines whether this extension is enabled.
  2080. */
  2081. enabled: boolean;
  2082. /**
  2083. * Defines a number that determines the order the extensions are applied.
  2084. */
  2085. order: number;
  2086. private _loader;
  2087. /** @hidden */
  2088. constructor(loader: GLTFLoader);
  2089. /** @hidden */
  2090. dispose(): void;
  2091. /** @hidden */
  2092. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2093. private _loadTranslucentPropertiesAsync;
  2094. }
  2095. }
  2096. declare module BABYLON.GLTF2.Loader.Extensions {
  2097. /**
  2098. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  2099. */
  2100. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  2101. /**
  2102. * The name of this extension.
  2103. */
  2104. readonly name: string;
  2105. /**
  2106. * Defines whether this extension is enabled.
  2107. */
  2108. enabled: boolean;
  2109. /** @hidden */
  2110. constructor(loader: GLTFLoader);
  2111. /** @hidden */
  2112. dispose(): void;
  2113. }
  2114. }
  2115. declare module BABYLON.GLTF2.Loader.Extensions {
  2116. /**
  2117. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  2118. * !!! Experimental Extension Subject to Changes !!!
  2119. */
  2120. export class KHR_texture_basisu implements IGLTFLoaderExtension {
  2121. /** The name of this extension. */
  2122. readonly name: string;
  2123. /** Defines whether this extension is enabled. */
  2124. enabled: boolean;
  2125. private _loader;
  2126. /** @hidden */
  2127. constructor(loader: GLTFLoader);
  2128. /** @hidden */
  2129. dispose(): void;
  2130. /** @hidden */
  2131. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2132. }
  2133. }
  2134. declare module BABYLON.GLTF2.Loader.Extensions {
  2135. /**
  2136. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  2137. */
  2138. export class KHR_texture_transform implements IGLTFLoaderExtension {
  2139. /**
  2140. * The name of this extension.
  2141. */
  2142. readonly name: string;
  2143. /**
  2144. * Defines whether this extension is enabled.
  2145. */
  2146. enabled: boolean;
  2147. private _loader;
  2148. /** @hidden */
  2149. constructor(loader: GLTFLoader);
  2150. /** @hidden */
  2151. dispose(): void;
  2152. /** @hidden */
  2153. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2154. }
  2155. }
  2156. declare module BABYLON.GLTF2.Loader.Extensions {
  2157. /**
  2158. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2159. */
  2160. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2161. /**
  2162. * The name of this extension.
  2163. */
  2164. readonly name: string;
  2165. /**
  2166. * Defines whether this extension is enabled.
  2167. */
  2168. enabled: boolean;
  2169. private _loader;
  2170. private _clips;
  2171. private _emitters;
  2172. /** @hidden */
  2173. constructor(loader: GLTFLoader);
  2174. /** @hidden */
  2175. dispose(): void;
  2176. /** @hidden */
  2177. onLoading(): void;
  2178. /** @hidden */
  2179. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2180. /** @hidden */
  2181. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2182. /** @hidden */
  2183. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2184. private _loadClipAsync;
  2185. private _loadEmitterAsync;
  2186. private _getEventAction;
  2187. private _loadAnimationEventAsync;
  2188. }
  2189. }
  2190. declare module BABYLON.GLTF2.Loader.Extensions {
  2191. /**
  2192. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2193. */
  2194. export class MSFT_lod implements IGLTFLoaderExtension {
  2195. /**
  2196. * The name of this extension.
  2197. */
  2198. readonly name: string;
  2199. /**
  2200. * Defines whether this extension is enabled.
  2201. */
  2202. enabled: boolean;
  2203. /**
  2204. * Defines a number that determines the order the extensions are applied.
  2205. */
  2206. order: number;
  2207. /**
  2208. * Maximum number of LODs to load, starting from the lowest LOD.
  2209. */
  2210. maxLODsToLoad: number;
  2211. /**
  2212. * Observable raised when all node LODs of one level are loaded.
  2213. * The event data is the index of the loaded LOD starting from zero.
  2214. * Dispose the loader to cancel the loading of the next level of LODs.
  2215. */
  2216. onNodeLODsLoadedObservable: Observable<number>;
  2217. /**
  2218. * Observable raised when all material LODs of one level are loaded.
  2219. * The event data is the index of the loaded LOD starting from zero.
  2220. * Dispose the loader to cancel the loading of the next level of LODs.
  2221. */
  2222. onMaterialLODsLoadedObservable: Observable<number>;
  2223. private _loader;
  2224. private _bufferLODs;
  2225. private _nodeIndexLOD;
  2226. private _nodeSignalLODs;
  2227. private _nodePromiseLODs;
  2228. private _nodeBufferLODs;
  2229. private _materialIndexLOD;
  2230. private _materialSignalLODs;
  2231. private _materialPromiseLODs;
  2232. private _materialBufferLODs;
  2233. /** @hidden */
  2234. constructor(loader: GLTFLoader);
  2235. /** @hidden */
  2236. dispose(): void;
  2237. /** @hidden */
  2238. onReady(): void;
  2239. /** @hidden */
  2240. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2241. /** @hidden */
  2242. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2243. /** @hidden */
  2244. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Nullable<Mesh>, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2245. /** @hidden */
  2246. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2247. /** @hidden */
  2248. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2249. private _loadBufferLOD;
  2250. /**
  2251. * Gets an array of LOD properties from lowest to highest.
  2252. */
  2253. private _getLODs;
  2254. private _disposeTransformNode;
  2255. private _disposeMaterials;
  2256. }
  2257. }
  2258. declare module BABYLON.GLTF2.Loader.Extensions {
  2259. /** @hidden */
  2260. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2261. readonly name: string;
  2262. enabled: boolean;
  2263. private _loader;
  2264. constructor(loader: GLTFLoader);
  2265. dispose(): void;
  2266. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2267. }
  2268. }
  2269. declare module BABYLON.GLTF2.Loader.Extensions {
  2270. /** @hidden */
  2271. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2272. readonly name: string;
  2273. enabled: boolean;
  2274. private _loader;
  2275. constructor(loader: GLTFLoader);
  2276. dispose(): void;
  2277. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2278. }
  2279. }
  2280. declare module BABYLON.GLTF2.Loader.Extensions {
  2281. /**
  2282. * Store glTF extras (if present) in BJS objects' metadata
  2283. */
  2284. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2285. /**
  2286. * The name of this extension.
  2287. */
  2288. readonly name: string;
  2289. /**
  2290. * Defines whether this extension is enabled.
  2291. */
  2292. enabled: boolean;
  2293. private _loader;
  2294. private _assignExtras;
  2295. /** @hidden */
  2296. constructor(loader: GLTFLoader);
  2297. /** @hidden */
  2298. dispose(): void;
  2299. /** @hidden */
  2300. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2301. /** @hidden */
  2302. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2303. /** @hidden */
  2304. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2305. }
  2306. }
  2307. declare module BABYLON {
  2308. /**
  2309. * Class reading and parsing the MTL file bundled with the obj file.
  2310. */
  2311. export class MTLFileLoader {
  2312. /**
  2313. * Invert Y-Axis of referenced textures on load
  2314. */
  2315. static INVERT_TEXTURE_Y: boolean;
  2316. /**
  2317. * All material loaded from the mtl will be set here
  2318. */
  2319. materials: StandardMaterial[];
  2320. /**
  2321. * This function will read the mtl file and create each material described inside
  2322. * This function could be improve by adding :
  2323. * -some component missing (Ni, Tf...)
  2324. * -including the specific options available
  2325. *
  2326. * @param scene defines the scene the material will be created in
  2327. * @param data defines the mtl data to parse
  2328. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2329. * @param forAssetContainer defines if the material should be registered in the scene
  2330. */
  2331. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2332. /**
  2333. * Gets the texture for the material.
  2334. *
  2335. * If the material is imported from input file,
  2336. * We sanitize the url to ensure it takes the textre from aside the material.
  2337. *
  2338. * @param rootUrl The root url to load from
  2339. * @param value The value stored in the mtl
  2340. * @return The Texture
  2341. */
  2342. private static _getTexture;
  2343. }
  2344. }
  2345. declare module BABYLON {
  2346. /**
  2347. * Options for loading OBJ/MTL files
  2348. */
  2349. type MeshLoadOptions = {
  2350. /**
  2351. * Defines if UVs are optimized by default during load.
  2352. */
  2353. OptimizeWithUV: boolean;
  2354. /**
  2355. * Defines custom scaling of UV coordinates of loaded meshes.
  2356. */
  2357. UVScaling: Vector2;
  2358. /**
  2359. * Invert model on y-axis (does a model scaling inversion)
  2360. */
  2361. InvertY: boolean;
  2362. /**
  2363. * Invert Y-Axis of referenced textures on load
  2364. */
  2365. InvertTextureY: boolean;
  2366. /**
  2367. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2368. */
  2369. ImportVertexColors: boolean;
  2370. /**
  2371. * Compute the normals for the model, even if normals are present in the file.
  2372. */
  2373. ComputeNormals: boolean;
  2374. /**
  2375. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2376. */
  2377. SkipMaterials: boolean;
  2378. /**
  2379. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2380. */
  2381. MaterialLoadingFailsSilently: boolean;
  2382. };
  2383. /**
  2384. * OBJ file type loader.
  2385. * This is a babylon scene loader plugin.
  2386. */
  2387. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2388. /**
  2389. * Defines if UVs are optimized by default during load.
  2390. */
  2391. static OPTIMIZE_WITH_UV: boolean;
  2392. /**
  2393. * Invert model on y-axis (does a model scaling inversion)
  2394. */
  2395. static INVERT_Y: boolean;
  2396. /**
  2397. * Invert Y-Axis of referenced textures on load
  2398. */
  2399. static get INVERT_TEXTURE_Y(): boolean;
  2400. static set INVERT_TEXTURE_Y(value: boolean);
  2401. /**
  2402. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2403. */
  2404. static IMPORT_VERTEX_COLORS: boolean;
  2405. /**
  2406. * Compute the normals for the model, even if normals are present in the file.
  2407. */
  2408. static COMPUTE_NORMALS: boolean;
  2409. /**
  2410. * Defines custom scaling of UV coordinates of loaded meshes.
  2411. */
  2412. static UV_SCALING: Vector2;
  2413. /**
  2414. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2415. */
  2416. static SKIP_MATERIALS: boolean;
  2417. /**
  2418. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2419. *
  2420. * Defaults to true for backwards compatibility.
  2421. */
  2422. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2423. /**
  2424. * Defines the name of the plugin.
  2425. */
  2426. name: string;
  2427. /**
  2428. * Defines the extension the plugin is able to load.
  2429. */
  2430. extensions: string;
  2431. /** @hidden */
  2432. obj: RegExp;
  2433. /** @hidden */
  2434. group: RegExp;
  2435. /** @hidden */
  2436. mtllib: RegExp;
  2437. /** @hidden */
  2438. usemtl: RegExp;
  2439. /** @hidden */
  2440. smooth: RegExp;
  2441. /** @hidden */
  2442. vertexPattern: RegExp;
  2443. /** @hidden */
  2444. normalPattern: RegExp;
  2445. /** @hidden */
  2446. uvPattern: RegExp;
  2447. /** @hidden */
  2448. facePattern1: RegExp;
  2449. /** @hidden */
  2450. facePattern2: RegExp;
  2451. /** @hidden */
  2452. facePattern3: RegExp;
  2453. /** @hidden */
  2454. facePattern4: RegExp;
  2455. /** @hidden */
  2456. facePattern5: RegExp;
  2457. private _forAssetContainer;
  2458. private _meshLoadOptions;
  2459. /**
  2460. * Creates loader for .OBJ files
  2461. *
  2462. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2463. */
  2464. constructor(meshLoadOptions?: MeshLoadOptions);
  2465. private static get currentMeshLoadOptions();
  2466. /**
  2467. * Calls synchronously the MTL file attached to this obj.
  2468. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2469. * Without this function materials are not displayed in the first frame (but displayed after).
  2470. * In consequence it is impossible to get material information in your HTML file
  2471. *
  2472. * @param url The URL of the MTL file
  2473. * @param rootUrl
  2474. * @param onSuccess Callback function to be called when the MTL file is loaded
  2475. * @private
  2476. */
  2477. private _loadMTL;
  2478. /**
  2479. * Instantiates a OBJ file loader plugin.
  2480. * @returns the created plugin
  2481. */
  2482. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2483. /**
  2484. * If the data string can be loaded directly.
  2485. *
  2486. * @param data string containing the file data
  2487. * @returns if the data can be loaded directly
  2488. */
  2489. canDirectLoad(data: string): boolean;
  2490. /**
  2491. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2492. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2493. * @param scene the scene the meshes should be added to
  2494. * @param data the OBJ data to load
  2495. * @param rootUrl root url to load from
  2496. * @param onProgress event that fires when loading progress has occured
  2497. * @param fileName Defines the name of the file to load
  2498. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2499. */
  2500. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
  2501. /**
  2502. * Imports all objects from the loaded OBJ data and adds them to the scene
  2503. * @param scene the scene the objects should be added to
  2504. * @param data the OBJ data to load
  2505. * @param rootUrl root url to load from
  2506. * @param onProgress event that fires when loading progress has occured
  2507. * @param fileName Defines the name of the file to load
  2508. * @returns a promise which completes when objects have been loaded to the scene
  2509. */
  2510. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2511. /**
  2512. * Load into an asset container.
  2513. * @param scene The scene to load into
  2514. * @param data The data to import
  2515. * @param rootUrl The root url for scene and resources
  2516. * @param onProgress The callback when the load progresses
  2517. * @param fileName Defines the name of the file to load
  2518. * @returns The loaded asset container
  2519. */
  2520. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2521. /**
  2522. * Read the OBJ file and create an Array of meshes.
  2523. * Each mesh contains all information given by the OBJ and the MTL file.
  2524. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2525. *
  2526. * @param meshesNames
  2527. * @param scene Scene The scene where are displayed the data
  2528. * @param data String The content of the obj file
  2529. * @param rootUrl String The path to the folder
  2530. * @returns Array<AbstractMesh>
  2531. * @private
  2532. */
  2533. private _parseSolid;
  2534. }
  2535. }
  2536. declare module BABYLON {
  2537. /**
  2538. * STL file type loader.
  2539. * This is a babylon scene loader plugin.
  2540. */
  2541. export class STLFileLoader implements ISceneLoaderPlugin {
  2542. /** @hidden */
  2543. solidPattern: RegExp;
  2544. /** @hidden */
  2545. facetsPattern: RegExp;
  2546. /** @hidden */
  2547. normalPattern: RegExp;
  2548. /** @hidden */
  2549. vertexPattern: RegExp;
  2550. /**
  2551. * Defines the name of the plugin.
  2552. */
  2553. name: string;
  2554. /**
  2555. * Defines the extensions the stl loader is able to load.
  2556. * force data to come in as an ArrayBuffer
  2557. * we'll convert to string if it looks like it's an ASCII .stl
  2558. */
  2559. extensions: ISceneLoaderPluginExtensions;
  2560. /**
  2561. * Import meshes into a scene.
  2562. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2563. * @param scene The scene to import into
  2564. * @param data The data to import
  2565. * @param rootUrl The root url for scene and resources
  2566. * @param meshes The meshes array to import into
  2567. * @param particleSystems The particle systems array to import into
  2568. * @param skeletons The skeletons array to import into
  2569. * @param onError The callback when import fails
  2570. * @returns True if successful or false otherwise
  2571. */
  2572. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2573. /**
  2574. * Load into a scene.
  2575. * @param scene The scene to load into
  2576. * @param data The data to import
  2577. * @param rootUrl The root url for scene and resources
  2578. * @param onError The callback when import fails
  2579. * @returns true if successful or false otherwise
  2580. */
  2581. load(scene: Scene, data: any, rootUrl: string): boolean;
  2582. /**
  2583. * Load into an asset container.
  2584. * @param scene The scene to load into
  2585. * @param data The data to import
  2586. * @param rootUrl The root url for scene and resources
  2587. * @param onError The callback when import fails
  2588. * @returns The loaded asset container
  2589. */
  2590. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2591. private _isBinary;
  2592. private _parseBinary;
  2593. private _parseASCII;
  2594. }
  2595. }