babylonjs.loaders.d.ts 101 KB

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