babylonjs.loaders.d.ts 104 KB

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