babylonjs.loaders.module.d.ts 186 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425
  1. declare module "babylonjs-loaders/glTF/glTFFileLoader" {
  2. import { Nullable } from "babylonjs/types";
  3. import { Observable } from "babylonjs/Misc/observable";
  4. import { Camera } from "babylonjs/Cameras/camera";
  5. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  6. import { Skeleton } from "babylonjs/Bones/skeleton";
  7. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  8. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  9. import { Material } from "babylonjs/Materials/material";
  10. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  11. import { ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  12. import { AssetContainer } from "babylonjs/assetContainer";
  13. import { Scene, IDisposable } from "babylonjs/scene";
  14. import * as GLTF2 from "babylonjs-gltf2interface";
  15. /**
  16. * Mode that determines the coordinate system to use.
  17. */
  18. export enum GLTFLoaderCoordinateSystemMode {
  19. /**
  20. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  21. */
  22. AUTO = 0,
  23. /**
  24. * Sets the useRightHandedSystem flag on the scene.
  25. */
  26. FORCE_RIGHT_HANDED = 1
  27. }
  28. /**
  29. * Mode that determines what animations will start.
  30. */
  31. export enum GLTFLoaderAnimationStartMode {
  32. /**
  33. * No animation will start.
  34. */
  35. NONE = 0,
  36. /**
  37. * The first animation will start.
  38. */
  39. FIRST = 1,
  40. /**
  41. * All animations will start.
  42. */
  43. ALL = 2
  44. }
  45. /**
  46. * Interface that contains the data for the glTF asset.
  47. */
  48. export interface IGLTFLoaderData {
  49. /**
  50. * Object that represents the glTF JSON.
  51. */
  52. json: Object;
  53. /**
  54. * The BIN chunk of a binary glTF.
  55. */
  56. bin: Nullable<ArrayBufferView>;
  57. }
  58. /**
  59. * Interface for extending the loader.
  60. */
  61. export interface IGLTFLoaderExtension {
  62. /**
  63. * The name of this extension.
  64. */
  65. readonly name: string;
  66. /**
  67. * Defines whether this extension is enabled.
  68. */
  69. enabled: boolean;
  70. }
  71. /**
  72. * Loader state.
  73. */
  74. export enum GLTFLoaderState {
  75. /**
  76. * The asset is loading.
  77. */
  78. LOADING = 0,
  79. /**
  80. * The asset is ready for rendering.
  81. */
  82. READY = 1,
  83. /**
  84. * The asset is completely loaded.
  85. */
  86. COMPLETE = 2
  87. }
  88. /** @hidden */
  89. export interface IGLTFLoader extends IDisposable {
  90. readonly state: Nullable<GLTFLoaderState>;
  91. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  92. meshes: AbstractMesh[];
  93. particleSystems: IParticleSystem[];
  94. skeletons: Skeleton[];
  95. animationGroups: AnimationGroup[];
  96. }>;
  97. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  98. }
  99. /**
  100. * File loader for loading glTF files into a scene.
  101. */
  102. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  103. /** @hidden */
  104. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  105. /** @hidden */
  106. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  107. /**
  108. * Raised when the asset has been parsed
  109. */
  110. onParsedObservable: Observable<IGLTFLoaderData>;
  111. private _onParsedObserver;
  112. /**
  113. * Raised when the asset has been parsed
  114. */
  115. onParsed: (loaderData: IGLTFLoaderData) => void;
  116. /**
  117. * 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.
  118. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  119. * Defaults to true.
  120. * @hidden
  121. */
  122. static IncrementalLoading: boolean;
  123. /**
  124. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  125. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  126. * @hidden
  127. */
  128. static HomogeneousCoordinates: boolean;
  129. /**
  130. * The coordinate system mode. Defaults to AUTO.
  131. */
  132. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  133. /**
  134. * The animation start mode. Defaults to FIRST.
  135. */
  136. animationStartMode: GLTFLoaderAnimationStartMode;
  137. /**
  138. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  139. */
  140. compileMaterials: boolean;
  141. /**
  142. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  143. */
  144. useClipPlane: boolean;
  145. /**
  146. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  147. */
  148. compileShadowGenerators: boolean;
  149. /**
  150. * Defines if the Alpha blended materials are only applied as coverage.
  151. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  152. * If true, no extra effects are applied to transparent pixels.
  153. */
  154. transparencyAsCoverage: boolean;
  155. /**
  156. * Function called before loading a url referenced by the asset.
  157. */
  158. preprocessUrlAsync: (url: string) => Promise<string>;
  159. /**
  160. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  161. */
  162. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  163. private _onMeshLoadedObserver;
  164. /**
  165. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  166. */
  167. onMeshLoaded: (mesh: AbstractMesh) => void;
  168. /**
  169. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  170. */
  171. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  172. private _onTextureLoadedObserver;
  173. /**
  174. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  175. */
  176. onTextureLoaded: (texture: BaseTexture) => void;
  177. /**
  178. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  179. */
  180. readonly onMaterialLoadedObservable: Observable<Material>;
  181. private _onMaterialLoadedObserver;
  182. /**
  183. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  184. */
  185. onMaterialLoaded: (material: Material) => void;
  186. /**
  187. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  188. */
  189. readonly onCameraLoadedObservable: Observable<Camera>;
  190. private _onCameraLoadedObserver;
  191. /**
  192. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  193. */
  194. onCameraLoaded: (camera: Camera) => void;
  195. /**
  196. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  197. * For assets with LODs, raised when all of the LODs are complete.
  198. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  199. */
  200. readonly onCompleteObservable: Observable<void>;
  201. private _onCompleteObserver;
  202. /**
  203. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  204. * For assets with LODs, raised when all of the LODs are complete.
  205. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  206. */
  207. onComplete: () => void;
  208. /**
  209. * Observable raised when an error occurs.
  210. */
  211. readonly onErrorObservable: Observable<any>;
  212. private _onErrorObserver;
  213. /**
  214. * Callback raised when an error occurs.
  215. */
  216. onError: (reason: any) => void;
  217. /**
  218. * Observable raised after the loader is disposed.
  219. */
  220. readonly onDisposeObservable: Observable<void>;
  221. private _onDisposeObserver;
  222. /**
  223. * Callback raised after the loader is disposed.
  224. */
  225. onDispose: () => void;
  226. /**
  227. * Observable raised after a loader extension is created.
  228. * Set additional options for a loader extension in this event.
  229. */
  230. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  231. private _onExtensionLoadedObserver;
  232. /**
  233. * Callback raised after a loader extension is created.
  234. */
  235. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  236. /**
  237. * Defines if the loader logging is enabled.
  238. */
  239. loggingEnabled: boolean;
  240. /**
  241. * Defines if the loader should capture performance counters.
  242. */
  243. capturePerformanceCounters: boolean;
  244. /**
  245. * Defines if the loader should validate the asset.
  246. */
  247. validate: boolean;
  248. /**
  249. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  250. */
  251. readonly onValidatedObservable: Observable<GLTF2.IGLTFValidationResults>;
  252. private _onValidatedObserver;
  253. /**
  254. * Callback raised after a loader extension is created.
  255. */
  256. onValidated: (results: GLTF2.IGLTFValidationResults) => void;
  257. private _loader;
  258. /**
  259. * Name of the loader ("gltf")
  260. */
  261. name: string;
  262. /**
  263. * Supported file extensions of the loader (.gltf, .glb)
  264. */
  265. extensions: ISceneLoaderPluginExtensions;
  266. /**
  267. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  268. */
  269. dispose(): void;
  270. /** @hidden */
  271. _clear(): void;
  272. /**
  273. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  274. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  275. * @param scene the scene the meshes should be added to
  276. * @param data the glTF data to load
  277. * @param rootUrl root url to load from
  278. * @param onProgress event that fires when loading progress has occured
  279. * @param fileName Defines the name of the file to load
  280. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  281. */
  282. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  283. meshes: AbstractMesh[];
  284. particleSystems: IParticleSystem[];
  285. skeletons: Skeleton[];
  286. animationGroups: AnimationGroup[];
  287. }>;
  288. /**
  289. * Imports all objects from the loaded glTF data and adds them to the scene
  290. * @param scene the scene the objects should be added to
  291. * @param data the glTF data to load
  292. * @param rootUrl root url to load from
  293. * @param onProgress event that fires when loading progress has occured
  294. * @param fileName Defines the name of the file to load
  295. * @returns a promise which completes when objects have been loaded to the scene
  296. */
  297. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  298. /**
  299. * Load into an asset container.
  300. * @param scene The scene to load into
  301. * @param data The data to import
  302. * @param rootUrl The root url for scene and resources
  303. * @param onProgress The callback when the load progresses
  304. * @param fileName Defines the name of the file to load
  305. * @returns The loaded asset container
  306. */
  307. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  308. /**
  309. * If the data string can be loaded directly.
  310. * @param data string contianing the file data
  311. * @returns if the data can be loaded directly
  312. */
  313. canDirectLoad(data: string): boolean;
  314. /**
  315. * Rewrites a url by combining a root url and response url.
  316. */
  317. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  318. /**
  319. * Instantiates a glTF file loader plugin.
  320. * @returns the created plugin
  321. */
  322. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  323. /**
  324. * The loader state or null if the loader is not active.
  325. */
  326. readonly loaderState: Nullable<GLTFLoaderState>;
  327. /**
  328. * Returns a promise that resolves when the asset is completely loaded.
  329. * @returns a promise that resolves when the asset is completely loaded.
  330. */
  331. whenCompleteAsync(): Promise<void>;
  332. private _parseAsync;
  333. private _validateAsync;
  334. private _getLoader;
  335. private _unpackBinary;
  336. private _unpackBinaryV1;
  337. private _unpackBinaryV2;
  338. private static _parseVersion;
  339. private static _compareVersion;
  340. private static _decodeBufferToText;
  341. private static readonly _logSpaces;
  342. private _logIndentLevel;
  343. private _loggingEnabled;
  344. /** @hidden */
  345. _log: (message: string) => void;
  346. /** @hidden */
  347. _logOpen(message: string): void;
  348. /** @hidden */
  349. _logClose(): void;
  350. private _logEnabled;
  351. private _logDisabled;
  352. private _capturePerformanceCounters;
  353. /** @hidden */
  354. _startPerformanceCounter: (counterName: string) => void;
  355. /** @hidden */
  356. _endPerformanceCounter: (counterName: string) => void;
  357. private _startPerformanceCounterEnabled;
  358. private _startPerformanceCounterDisabled;
  359. private _endPerformanceCounterEnabled;
  360. private _endPerformanceCounterDisabled;
  361. }
  362. }
  363. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces" {
  364. import { Bone } from "babylonjs/Bones/bone";
  365. import { Skeleton } from "babylonjs/Bones/skeleton";
  366. import { Texture } from "babylonjs/Materials/Textures/texture";
  367. import { Node } from "babylonjs/node";
  368. import { Scene } from "babylonjs/scene";
  369. /**
  370. * Enums
  371. * @hidden
  372. */
  373. export enum EComponentType {
  374. BYTE = 5120,
  375. UNSIGNED_BYTE = 5121,
  376. SHORT = 5122,
  377. UNSIGNED_SHORT = 5123,
  378. FLOAT = 5126
  379. }
  380. /** @hidden */
  381. export enum EShaderType {
  382. FRAGMENT = 35632,
  383. VERTEX = 35633
  384. }
  385. /** @hidden */
  386. export enum EParameterType {
  387. BYTE = 5120,
  388. UNSIGNED_BYTE = 5121,
  389. SHORT = 5122,
  390. UNSIGNED_SHORT = 5123,
  391. INT = 5124,
  392. UNSIGNED_INT = 5125,
  393. FLOAT = 5126,
  394. FLOAT_VEC2 = 35664,
  395. FLOAT_VEC3 = 35665,
  396. FLOAT_VEC4 = 35666,
  397. INT_VEC2 = 35667,
  398. INT_VEC3 = 35668,
  399. INT_VEC4 = 35669,
  400. BOOL = 35670,
  401. BOOL_VEC2 = 35671,
  402. BOOL_VEC3 = 35672,
  403. BOOL_VEC4 = 35673,
  404. FLOAT_MAT2 = 35674,
  405. FLOAT_MAT3 = 35675,
  406. FLOAT_MAT4 = 35676,
  407. SAMPLER_2D = 35678
  408. }
  409. /** @hidden */
  410. export enum ETextureWrapMode {
  411. CLAMP_TO_EDGE = 33071,
  412. MIRRORED_REPEAT = 33648,
  413. REPEAT = 10497
  414. }
  415. /** @hidden */
  416. export enum ETextureFilterType {
  417. NEAREST = 9728,
  418. LINEAR = 9728,
  419. NEAREST_MIPMAP_NEAREST = 9984,
  420. LINEAR_MIPMAP_NEAREST = 9985,
  421. NEAREST_MIPMAP_LINEAR = 9986,
  422. LINEAR_MIPMAP_LINEAR = 9987
  423. }
  424. /** @hidden */
  425. export enum ETextureFormat {
  426. ALPHA = 6406,
  427. RGB = 6407,
  428. RGBA = 6408,
  429. LUMINANCE = 6409,
  430. LUMINANCE_ALPHA = 6410
  431. }
  432. /** @hidden */
  433. export enum ECullingType {
  434. FRONT = 1028,
  435. BACK = 1029,
  436. FRONT_AND_BACK = 1032
  437. }
  438. /** @hidden */
  439. export enum EBlendingFunction {
  440. ZERO = 0,
  441. ONE = 1,
  442. SRC_COLOR = 768,
  443. ONE_MINUS_SRC_COLOR = 769,
  444. DST_COLOR = 774,
  445. ONE_MINUS_DST_COLOR = 775,
  446. SRC_ALPHA = 770,
  447. ONE_MINUS_SRC_ALPHA = 771,
  448. DST_ALPHA = 772,
  449. ONE_MINUS_DST_ALPHA = 773,
  450. CONSTANT_COLOR = 32769,
  451. ONE_MINUS_CONSTANT_COLOR = 32770,
  452. CONSTANT_ALPHA = 32771,
  453. ONE_MINUS_CONSTANT_ALPHA = 32772,
  454. SRC_ALPHA_SATURATE = 776
  455. }
  456. /** @hidden */
  457. export interface IGLTFProperty {
  458. extensions?: {
  459. [key: string]: any;
  460. };
  461. extras?: Object;
  462. }
  463. /** @hidden */
  464. export interface IGLTFChildRootProperty extends IGLTFProperty {
  465. name?: string;
  466. }
  467. /** @hidden */
  468. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  469. bufferView: string;
  470. byteOffset: number;
  471. byteStride: number;
  472. count: number;
  473. type: string;
  474. componentType: EComponentType;
  475. max?: number[];
  476. min?: number[];
  477. name?: string;
  478. }
  479. /** @hidden */
  480. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  481. buffer: string;
  482. byteOffset: number;
  483. byteLength: number;
  484. byteStride: number;
  485. target?: number;
  486. }
  487. /** @hidden */
  488. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  489. uri: string;
  490. byteLength?: number;
  491. type?: string;
  492. }
  493. /** @hidden */
  494. export interface IGLTFShader extends IGLTFChildRootProperty {
  495. uri: string;
  496. type: EShaderType;
  497. }
  498. /** @hidden */
  499. export interface IGLTFProgram extends IGLTFChildRootProperty {
  500. attributes: string[];
  501. fragmentShader: string;
  502. vertexShader: string;
  503. }
  504. /** @hidden */
  505. export interface IGLTFTechniqueParameter {
  506. type: number;
  507. count?: number;
  508. semantic?: string;
  509. node?: string;
  510. value?: number | boolean | string | Array<any>;
  511. source?: string;
  512. babylonValue?: any;
  513. }
  514. /** @hidden */
  515. export interface IGLTFTechniqueCommonProfile {
  516. lightingModel: string;
  517. texcoordBindings: Object;
  518. parameters?: Array<any>;
  519. }
  520. /** @hidden */
  521. export interface IGLTFTechniqueStatesFunctions {
  522. blendColor?: number[];
  523. blendEquationSeparate?: number[];
  524. blendFuncSeparate?: number[];
  525. colorMask: boolean[];
  526. cullFace: number[];
  527. }
  528. /** @hidden */
  529. export interface IGLTFTechniqueStates {
  530. enable: number[];
  531. functions: IGLTFTechniqueStatesFunctions;
  532. }
  533. /** @hidden */
  534. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  535. parameters: {
  536. [key: string]: IGLTFTechniqueParameter;
  537. };
  538. program: string;
  539. attributes: {
  540. [key: string]: string;
  541. };
  542. uniforms: {
  543. [key: string]: string;
  544. };
  545. states: IGLTFTechniqueStates;
  546. }
  547. /** @hidden */
  548. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  549. technique?: string;
  550. values: string[];
  551. }
  552. /** @hidden */
  553. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  554. attributes: {
  555. [key: string]: string;
  556. };
  557. indices: string;
  558. material: string;
  559. mode?: number;
  560. }
  561. /** @hidden */
  562. export interface IGLTFMesh extends IGLTFChildRootProperty {
  563. primitives: IGLTFMeshPrimitive[];
  564. }
  565. /** @hidden */
  566. export interface IGLTFImage extends IGLTFChildRootProperty {
  567. uri: string;
  568. }
  569. /** @hidden */
  570. export interface IGLTFSampler extends IGLTFChildRootProperty {
  571. magFilter?: number;
  572. minFilter?: number;
  573. wrapS?: number;
  574. wrapT?: number;
  575. }
  576. /** @hidden */
  577. export interface IGLTFTexture extends IGLTFChildRootProperty {
  578. sampler: string;
  579. source: string;
  580. format?: ETextureFormat;
  581. internalFormat?: ETextureFormat;
  582. target?: number;
  583. type?: number;
  584. babylonTexture?: Texture;
  585. }
  586. /** @hidden */
  587. export interface IGLTFAmbienLight {
  588. color?: number[];
  589. }
  590. /** @hidden */
  591. export interface IGLTFDirectionalLight {
  592. color?: number[];
  593. }
  594. /** @hidden */
  595. export interface IGLTFPointLight {
  596. color?: number[];
  597. constantAttenuation?: number;
  598. linearAttenuation?: number;
  599. quadraticAttenuation?: number;
  600. }
  601. /** @hidden */
  602. export interface IGLTFSpotLight {
  603. color?: number[];
  604. constantAttenuation?: number;
  605. fallOfAngle?: number;
  606. fallOffExponent?: number;
  607. linearAttenuation?: number;
  608. quadraticAttenuation?: number;
  609. }
  610. /** @hidden */
  611. export interface IGLTFLight extends IGLTFChildRootProperty {
  612. type: string;
  613. }
  614. /** @hidden */
  615. export interface IGLTFCameraOrthographic {
  616. xmag: number;
  617. ymag: number;
  618. zfar: number;
  619. znear: number;
  620. }
  621. /** @hidden */
  622. export interface IGLTFCameraPerspective {
  623. aspectRatio: number;
  624. yfov: number;
  625. zfar: number;
  626. znear: number;
  627. }
  628. /** @hidden */
  629. export interface IGLTFCamera extends IGLTFChildRootProperty {
  630. type: string;
  631. }
  632. /** @hidden */
  633. export interface IGLTFAnimationChannelTarget {
  634. id: string;
  635. path: string;
  636. }
  637. /** @hidden */
  638. export interface IGLTFAnimationChannel {
  639. sampler: string;
  640. target: IGLTFAnimationChannelTarget;
  641. }
  642. /** @hidden */
  643. export interface IGLTFAnimationSampler {
  644. input: string;
  645. output: string;
  646. interpolation?: string;
  647. }
  648. /** @hidden */
  649. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  650. channels?: IGLTFAnimationChannel[];
  651. parameters?: {
  652. [key: string]: string;
  653. };
  654. samplers?: {
  655. [key: string]: IGLTFAnimationSampler;
  656. };
  657. }
  658. /** @hidden */
  659. export interface IGLTFNodeInstanceSkin {
  660. skeletons: string[];
  661. skin: string;
  662. meshes: string[];
  663. }
  664. /** @hidden */
  665. export interface IGLTFSkins extends IGLTFChildRootProperty {
  666. bindShapeMatrix: number[];
  667. inverseBindMatrices: string;
  668. jointNames: string[];
  669. babylonSkeleton?: Skeleton;
  670. }
  671. /** @hidden */
  672. export interface IGLTFNode extends IGLTFChildRootProperty {
  673. camera?: string;
  674. children: string[];
  675. skin?: string;
  676. jointName?: string;
  677. light?: string;
  678. matrix: number[];
  679. mesh?: string;
  680. meshes?: string[];
  681. rotation?: number[];
  682. scale?: number[];
  683. translation?: number[];
  684. babylonNode?: Node;
  685. }
  686. /** @hidden */
  687. export interface IGLTFScene extends IGLTFChildRootProperty {
  688. nodes: string[];
  689. }
  690. /** @hidden */
  691. export interface IGLTFRuntime {
  692. extensions: {
  693. [key: string]: any;
  694. };
  695. accessors: {
  696. [key: string]: IGLTFAccessor;
  697. };
  698. buffers: {
  699. [key: string]: IGLTFBuffer;
  700. };
  701. bufferViews: {
  702. [key: string]: IGLTFBufferView;
  703. };
  704. meshes: {
  705. [key: string]: IGLTFMesh;
  706. };
  707. lights: {
  708. [key: string]: IGLTFLight;
  709. };
  710. cameras: {
  711. [key: string]: IGLTFCamera;
  712. };
  713. nodes: {
  714. [key: string]: IGLTFNode;
  715. };
  716. images: {
  717. [key: string]: IGLTFImage;
  718. };
  719. textures: {
  720. [key: string]: IGLTFTexture;
  721. };
  722. shaders: {
  723. [key: string]: IGLTFShader;
  724. };
  725. programs: {
  726. [key: string]: IGLTFProgram;
  727. };
  728. samplers: {
  729. [key: string]: IGLTFSampler;
  730. };
  731. techniques: {
  732. [key: string]: IGLTFTechnique;
  733. };
  734. materials: {
  735. [key: string]: IGLTFMaterial;
  736. };
  737. animations: {
  738. [key: string]: IGLTFAnimation;
  739. };
  740. skins: {
  741. [key: string]: IGLTFSkins;
  742. };
  743. currentScene?: Object;
  744. scenes: {
  745. [key: string]: IGLTFScene;
  746. };
  747. extensionsUsed: string[];
  748. extensionsRequired?: string[];
  749. buffersCount: number;
  750. shaderscount: number;
  751. scene: Scene;
  752. rootUrl: string;
  753. loadedBufferCount: number;
  754. loadedBufferViews: {
  755. [name: string]: ArrayBufferView;
  756. };
  757. loadedShaderCount: number;
  758. importOnlyMeshes: boolean;
  759. importMeshesNames?: string[];
  760. dummyNodes: Node[];
  761. }
  762. /** @hidden */
  763. export interface INodeToRoot {
  764. bone: Bone;
  765. node: IGLTFNode;
  766. id: string;
  767. }
  768. /** @hidden */
  769. export interface IJointNode {
  770. node: IGLTFNode;
  771. id: string;
  772. }
  773. }
  774. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderUtils" {
  775. import { IGLTFTechniqueParameter, IGLTFAccessor, ETextureFilterType, IGLTFRuntime, IGLTFBufferView, EComponentType } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  776. import { Effect } from "babylonjs/Materials/effect";
  777. import { ShaderMaterial } from "babylonjs/Materials/shaderMaterial";
  778. import { Node } from "babylonjs/node";
  779. import { Scene } from "babylonjs/scene";
  780. /**
  781. * Utils functions for GLTF
  782. * @hidden
  783. */
  784. export class GLTFUtils {
  785. /**
  786. * Sets the given "parameter" matrix
  787. * @param scene: the Scene object
  788. * @param source: the source node where to pick the matrix
  789. * @param parameter: the GLTF technique parameter
  790. * @param uniformName: the name of the shader's uniform
  791. * @param shaderMaterial: the shader material
  792. */
  793. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  794. /**
  795. * Sets the given "parameter" matrix
  796. * @param shaderMaterial: the shader material
  797. * @param uniform: the name of the shader's uniform
  798. * @param value: the value of the uniform
  799. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  800. */
  801. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  802. /**
  803. * Returns the wrap mode of the texture
  804. * @param mode: the mode value
  805. */
  806. static GetWrapMode(mode: number): number;
  807. /**
  808. * Returns the byte stride giving an accessor
  809. * @param accessor: the GLTF accessor objet
  810. */
  811. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  812. /**
  813. * Returns the texture filter mode giving a mode value
  814. * @param mode: the filter mode value
  815. */
  816. static GetTextureFilterMode(mode: number): ETextureFilterType;
  817. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  818. /**
  819. * Returns a buffer from its accessor
  820. * @param gltfRuntime: the GLTF runtime
  821. * @param accessor: the GLTF accessor
  822. */
  823. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  824. /**
  825. * Decodes a buffer view into a string
  826. * @param view: the buffer view
  827. */
  828. static DecodeBufferToText(view: ArrayBufferView): string;
  829. /**
  830. * Returns the default material of gltf. Related to
  831. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  832. * @param scene: the Babylon.js scene
  833. */
  834. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  835. private static _DefaultMaterial;
  836. }
  837. }
  838. declare module "babylonjs-loaders/glTF/1.0/glTFLoader" {
  839. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  840. import { Nullable } from "babylonjs/types";
  841. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  842. import { Skeleton } from "babylonjs/Bones/skeleton";
  843. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  844. import { Material } from "babylonjs/Materials/material";
  845. import { Texture } from "babylonjs/Materials/Textures/texture";
  846. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  847. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  848. import { Scene } from "babylonjs/scene";
  849. import { IGLTFLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  850. /**
  851. * Implementation of the base glTF spec
  852. * @hidden
  853. */
  854. export class GLTFLoaderBase {
  855. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  856. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  857. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  858. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  859. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  860. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  861. }
  862. /**
  863. * glTF V1 Loader
  864. * @hidden
  865. */
  866. export class GLTFLoader implements IGLTFLoader {
  867. static Extensions: {
  868. [name: string]: GLTFLoaderExtension;
  869. };
  870. static RegisterExtension(extension: GLTFLoaderExtension): void;
  871. state: Nullable<GLTFLoaderState>;
  872. dispose(): void;
  873. private _importMeshAsync;
  874. /**
  875. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  876. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  877. * @param scene the scene the meshes should be added to
  878. * @param data gltf data containing information of the meshes in a loaded file
  879. * @param rootUrl root url to load from
  880. * @param onProgress event that fires when loading progress has occured
  881. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  882. */
  883. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  884. meshes: AbstractMesh[];
  885. particleSystems: IParticleSystem[];
  886. skeletons: Skeleton[];
  887. animationGroups: AnimationGroup[];
  888. }>;
  889. private _loadAsync;
  890. /**
  891. * Imports all objects from a loaded gltf file and adds them to the scene
  892. * @param scene the scene the objects should be added to
  893. * @param data gltf data containing information of the meshes in a loaded file
  894. * @param rootUrl root url to load from
  895. * @param onProgress event that fires when loading progress has occured
  896. * @returns a promise which completes when objects have been loaded to the scene
  897. */
  898. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  899. private _loadShadersAsync;
  900. private _loadBuffersAsync;
  901. private _createNodes;
  902. }
  903. /** @hidden */
  904. export abstract class GLTFLoaderExtension {
  905. private _name;
  906. constructor(name: string);
  907. readonly name: string;
  908. /**
  909. * Defines an override for loading the runtime
  910. * Return true to stop further extensions from loading the runtime
  911. */
  912. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  913. /**
  914. * Defines an onverride for creating gltf runtime
  915. * Return true to stop further extensions from creating the runtime
  916. */
  917. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  918. /**
  919. * Defines an override for loading buffers
  920. * Return true to stop further extensions from loading this buffer
  921. */
  922. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  923. /**
  924. * Defines an override for loading texture buffers
  925. * Return true to stop further extensions from loading this texture data
  926. */
  927. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  928. /**
  929. * Defines an override for creating textures
  930. * Return true to stop further extensions from loading this texture
  931. */
  932. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  933. /**
  934. * Defines an override for loading shader strings
  935. * Return true to stop further extensions from loading this shader data
  936. */
  937. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  938. /**
  939. * Defines an override for loading materials
  940. * Return true to stop further extensions from loading this material
  941. */
  942. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  943. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  944. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  945. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  946. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  947. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  948. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  949. private static LoadTextureBufferAsync;
  950. private static CreateTextureAsync;
  951. private static ApplyExtensions;
  952. }
  953. }
  954. declare module "babylonjs-loaders/glTF/1.0/glTFBinaryExtension" {
  955. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  956. import { Scene } from "babylonjs/scene";
  957. import { IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  958. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  959. /** @hidden */
  960. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  961. private _bin;
  962. constructor();
  963. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  964. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  965. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  966. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  967. }
  968. }
  969. declare module "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension" {
  970. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  971. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  972. import { Material } from "babylonjs/Materials/material";
  973. /** @hidden */
  974. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  975. constructor();
  976. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  977. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  978. private _loadTexture;
  979. }
  980. }
  981. declare module "babylonjs-loaders/glTF/1.0/index" {
  982. export * from "babylonjs-loaders/glTF/1.0/glTFBinaryExtension";
  983. export * from "babylonjs-loaders/glTF/1.0/glTFLoader";
  984. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  985. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderUtils";
  986. export * from "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension";
  987. }
  988. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces" {
  989. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  990. import { Bone } from "babylonjs/Bones/bone";
  991. import { Skeleton } from "babylonjs/Bones/skeleton";
  992. import { Material } from "babylonjs/Materials/material";
  993. import { TransformNode } from "babylonjs/Meshes/transformNode";
  994. import { Buffer, VertexBuffer } from "babylonjs/Meshes/buffer";
  995. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  996. import { Mesh } from "babylonjs/Meshes/mesh";
  997. import * as GLTF2 from "babylonjs-gltf2interface";
  998. /**
  999. * Loader interface with an index field.
  1000. */
  1001. export interface IArrayItem {
  1002. /**
  1003. * The index of this item in the array.
  1004. */
  1005. index: number;
  1006. }
  1007. /**
  1008. * Loader interface with additional members.
  1009. */
  1010. export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
  1011. /** @hidden */
  1012. _data?: Promise<ArrayBufferView>;
  1013. /** @hidden */
  1014. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1015. }
  1016. /**
  1017. * Loader interface with additional members.
  1018. */
  1019. export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
  1020. }
  1021. /** @hidden */
  1022. export interface _IAnimationSamplerData {
  1023. input: Float32Array;
  1024. interpolation: GLTF2.AnimationSamplerInterpolation;
  1025. output: Float32Array;
  1026. }
  1027. /**
  1028. * Loader interface with additional members.
  1029. */
  1030. export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
  1031. /** @hidden */
  1032. _data?: Promise<_IAnimationSamplerData>;
  1033. }
  1034. /**
  1035. * Loader interface with additional members.
  1036. */
  1037. export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
  1038. channels: IAnimationChannel[];
  1039. samplers: IAnimationSampler[];
  1040. /** @hidden */
  1041. _babylonAnimationGroup?: AnimationGroup;
  1042. }
  1043. /**
  1044. * Loader interface with additional members.
  1045. */
  1046. export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
  1047. /** @hidden */
  1048. _data?: Promise<ArrayBufferView>;
  1049. }
  1050. /**
  1051. * Loader interface with additional members.
  1052. */
  1053. export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
  1054. /** @hidden */
  1055. _data?: Promise<ArrayBufferView>;
  1056. /** @hidden */
  1057. _babylonBuffer?: Promise<Buffer>;
  1058. }
  1059. /**
  1060. * Loader interface with additional members.
  1061. */
  1062. export interface ICamera extends GLTF2.ICamera, IArrayItem {
  1063. }
  1064. /**
  1065. * Loader interface with additional members.
  1066. */
  1067. export interface IImage extends GLTF2.IImage, IArrayItem {
  1068. /** @hidden */
  1069. _data?: Promise<ArrayBufferView>;
  1070. }
  1071. /**
  1072. * Loader interface with additional members.
  1073. */
  1074. export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1075. }
  1076. /**
  1077. * Loader interface with additional members.
  1078. */
  1079. export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1080. }
  1081. /**
  1082. * Loader interface with additional members.
  1083. */
  1084. export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
  1085. baseColorTexture?: ITextureInfo;
  1086. metallicRoughnessTexture?: ITextureInfo;
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
  1092. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1093. normalTexture?: IMaterialNormalTextureInfo;
  1094. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1095. emissiveTexture?: ITextureInfo;
  1096. /** @hidden */
  1097. _data?: {
  1098. [babylonDrawMode: number]: {
  1099. babylonMaterial: Material;
  1100. babylonMeshes: AbstractMesh[];
  1101. promise: Promise<void>;
  1102. };
  1103. };
  1104. }
  1105. /**
  1106. * Loader interface with additional members.
  1107. */
  1108. export interface IMesh extends GLTF2.IMesh, IArrayItem {
  1109. primitives: IMeshPrimitive[];
  1110. }
  1111. /**
  1112. * Loader interface with additional members.
  1113. */
  1114. export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
  1115. /** @hidden */
  1116. _instanceData?: {
  1117. babylonSourceMesh: Mesh;
  1118. promise: Promise<any>;
  1119. };
  1120. }
  1121. /**
  1122. * Loader interface with additional members.
  1123. */
  1124. export interface INode extends GLTF2.INode, IArrayItem {
  1125. /**
  1126. * The parent glTF node.
  1127. */
  1128. parent?: INode;
  1129. /** @hidden */
  1130. _babylonTransformNode?: TransformNode;
  1131. /** @hidden */
  1132. _primitiveBabylonMeshes?: AbstractMesh[];
  1133. /** @hidden */
  1134. _babylonBones?: Bone[];
  1135. /** @hidden */
  1136. _numMorphTargets?: number;
  1137. }
  1138. /** @hidden */
  1139. export interface _ISamplerData {
  1140. noMipMaps: boolean;
  1141. samplingMode: number;
  1142. wrapU: number;
  1143. wrapV: number;
  1144. }
  1145. /**
  1146. * Loader interface with additional members.
  1147. */
  1148. export interface ISampler extends GLTF2.ISampler, IArrayItem {
  1149. /** @hidden */
  1150. _data?: _ISamplerData;
  1151. }
  1152. /**
  1153. * Loader interface with additional members.
  1154. */
  1155. export interface IScene extends GLTF2.IScene, IArrayItem {
  1156. }
  1157. /**
  1158. * Loader interface with additional members.
  1159. */
  1160. export interface ISkin extends GLTF2.ISkin, IArrayItem {
  1161. /** @hidden */
  1162. _data?: {
  1163. babylonSkeleton: Skeleton;
  1164. promise: Promise<void>;
  1165. };
  1166. }
  1167. /**
  1168. * Loader interface with additional members.
  1169. */
  1170. export interface ITexture extends GLTF2.ITexture, IArrayItem {
  1171. }
  1172. /**
  1173. * Loader interface with additional members.
  1174. */
  1175. export interface ITextureInfo extends GLTF2.ITextureInfo {
  1176. }
  1177. /**
  1178. * Loader interface with additional members.
  1179. */
  1180. export interface IGLTF extends GLTF2.IGLTF {
  1181. accessors?: IAccessor[];
  1182. animations?: IAnimation[];
  1183. buffers?: IBuffer[];
  1184. bufferViews?: IBufferView[];
  1185. cameras?: ICamera[];
  1186. images?: IImage[];
  1187. materials?: IMaterial[];
  1188. meshes?: IMesh[];
  1189. nodes?: INode[];
  1190. samplers?: ISampler[];
  1191. scenes?: IScene[];
  1192. skins?: ISkin[];
  1193. textures?: ITexture[];
  1194. }
  1195. }
  1196. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtension" {
  1197. import { Nullable } from "babylonjs/types";
  1198. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1199. import { Material } from "babylonjs/Materials/material";
  1200. import { Camera } from "babylonjs/Cameras/camera";
  1201. import { Geometry } from "babylonjs/Meshes/geometry";
  1202. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1203. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1204. import { Mesh } from "babylonjs/Meshes/mesh";
  1205. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1206. import { IDisposable } from "babylonjs/scene";
  1207. import { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1208. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
  1209. import { IProperty } from 'babylonjs-gltf2interface';
  1210. /**
  1211. * Interface for a glTF loader extension.
  1212. */
  1213. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  1214. /**
  1215. * Called after the loader state changes to LOADING.
  1216. */
  1217. onLoading?(): void;
  1218. /**
  1219. * Called after the loader state changes to READY.
  1220. */
  1221. onReady?(): void;
  1222. /**
  1223. * Define this method to modify the default behavior when loading scenes.
  1224. * @param context The context when loading the asset
  1225. * @param scene The glTF scene property
  1226. * @returns A promise that resolves when the load is complete or null if not handled
  1227. */
  1228. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1229. /**
  1230. * Define this method to modify the default behavior when loading nodes.
  1231. * @param context The context when loading the asset
  1232. * @param node The glTF node property
  1233. * @param assign A function called synchronously after parsing the glTF properties
  1234. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1235. */
  1236. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1237. /**
  1238. * Define this method to modify the default behavior when loading cameras.
  1239. * @param context The context when loading the asset
  1240. * @param camera The glTF camera property
  1241. * @param assign A function called synchronously after parsing the glTF properties
  1242. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1243. */
  1244. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1245. /**
  1246. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1247. * @param context The context when loading the asset
  1248. * @param primitive The glTF mesh primitive property
  1249. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1250. */
  1251. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1252. /**
  1253. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1254. * @param context The context when loading the asset
  1255. * @param name The mesh name when loading the asset
  1256. * @param node The glTF node when loading the asset
  1257. * @param mesh The glTF mesh when loading the asset
  1258. * @param primitive The glTF mesh primitive property
  1259. * @param assign A function called synchronously after parsing the glTF properties
  1260. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1261. */
  1262. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1263. /**
  1264. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1265. * @param context The context when loading the asset
  1266. * @param material The glTF material property
  1267. * @param assign A function called synchronously after parsing the glTF properties
  1268. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1269. */
  1270. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1271. /**
  1272. * Define this method to modify the default behavior when creating materials.
  1273. * @param context The context when loading the asset
  1274. * @param material The glTF material property
  1275. * @param babylonDrawMode The draw mode for the Babylon material
  1276. * @returns The Babylon material or null if not handled
  1277. */
  1278. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1279. /**
  1280. * Define this method to modify the default behavior when loading material properties.
  1281. * @param context The context when loading the asset
  1282. * @param material The glTF material property
  1283. * @param babylonMaterial The Babylon material
  1284. * @returns A promise that resolves when the load is complete or null if not handled
  1285. */
  1286. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1287. /**
  1288. * Define this method to modify the default behavior when loading texture infos.
  1289. * @param context The context when loading the asset
  1290. * @param textureInfo The glTF texture info property
  1291. * @param assign A function called synchronously after parsing the glTF properties
  1292. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1293. */
  1294. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1295. /**
  1296. * Define this method to modify the default behavior when loading animations.
  1297. * @param context The context when loading the asset
  1298. * @param animation The glTF animation property
  1299. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1300. */
  1301. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1302. /**
  1303. * @hidden Define this method to modify the default behavior when loading skins.
  1304. * @param context The context when loading the asset
  1305. * @param node The glTF node property
  1306. * @param skin The glTF skin property
  1307. * @returns A promise that resolves when the load is complete or null if not handled
  1308. */
  1309. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1310. /**
  1311. * @hidden Define this method to modify the default behavior when loading uris.
  1312. * @param context The context when loading the asset
  1313. * @param property The glTF property associated with the uri
  1314. * @param uri The uri to load
  1315. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1316. */
  1317. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1318. }
  1319. }
  1320. declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
  1321. import { Nullable } from "babylonjs/types";
  1322. import { Camera } from "babylonjs/Cameras/camera";
  1323. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1324. import { Skeleton } from "babylonjs/Bones/skeleton";
  1325. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1326. import { Material } from "babylonjs/Materials/material";
  1327. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1328. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1329. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1330. import { Mesh } from "babylonjs/Meshes/mesh";
  1331. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1332. import { Scene } from "babylonjs/scene";
  1333. import { IProperty } from "babylonjs-gltf2interface";
  1334. import { IGLTF, INode, IScene, IMesh, ICamera, IAnimation, IAnimationChannel, IBufferView, IMaterial, ITextureInfo, IImage, IMeshPrimitive, IArrayItem as IArrItem } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1335. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1336. import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  1337. import { IAnimatable } from 'babylonjs/Animations/animatable.interface';
  1338. /**
  1339. * Helper class for working with arrays when loading the glTF asset
  1340. */
  1341. export class ArrayItem {
  1342. /**
  1343. * Gets an item from the given array.
  1344. * @param context The context when loading the asset
  1345. * @param array The array to get the item from
  1346. * @param index The index to the array
  1347. * @returns The array item
  1348. */
  1349. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1350. /**
  1351. * Assign an `index` field to each item of the given array.
  1352. * @param array The array of items
  1353. */
  1354. static Assign(array?: IArrItem[]): void;
  1355. }
  1356. /**
  1357. * The glTF 2.0 loader
  1358. */
  1359. export class GLTFLoader implements IGLTFLoader {
  1360. /** @hidden */
  1361. _completePromises: Promise<any>[];
  1362. private _disposed;
  1363. private _parent;
  1364. private _state;
  1365. private _extensions;
  1366. private _rootUrl;
  1367. private _fileName;
  1368. private _uniqueRootUrl;
  1369. private _gltf;
  1370. private _babylonScene;
  1371. private _rootBabylonMesh;
  1372. private _defaultBabylonMaterialData;
  1373. private _progressCallback?;
  1374. private _requests;
  1375. private static readonly _DefaultSampler;
  1376. private static _ExtensionNames;
  1377. private static _ExtensionFactories;
  1378. /**
  1379. * Registers a loader extension.
  1380. * @param name The name of the loader extension.
  1381. * @param factory The factory function that creates the loader extension.
  1382. */
  1383. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1384. /**
  1385. * Unregisters a loader extension.
  1386. * @param name The name of the loader extenion.
  1387. * @returns A boolean indicating whether the extension has been unregistered
  1388. */
  1389. static UnregisterExtension(name: string): boolean;
  1390. /**
  1391. * Gets the loader state.
  1392. */
  1393. readonly state: Nullable<GLTFLoaderState>;
  1394. /**
  1395. * The glTF object parsed from the JSON.
  1396. */
  1397. readonly gltf: IGLTF;
  1398. /**
  1399. * The Babylon scene when loading the asset.
  1400. */
  1401. readonly babylonScene: Scene;
  1402. /**
  1403. * The root Babylon mesh when loading the asset.
  1404. */
  1405. readonly rootBabylonMesh: Mesh;
  1406. /** @hidden */
  1407. constructor(parent: GLTFFileLoader);
  1408. /** @hidden */
  1409. dispose(): void;
  1410. /** @hidden */
  1411. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1412. meshes: AbstractMesh[];
  1413. particleSystems: IParticleSystem[];
  1414. skeletons: Skeleton[];
  1415. animationGroups: AnimationGroup[];
  1416. }>;
  1417. /** @hidden */
  1418. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1419. private _loadAsync;
  1420. private _loadData;
  1421. private _setupData;
  1422. private _loadExtensions;
  1423. private _checkExtensions;
  1424. private _setState;
  1425. private _createRootNode;
  1426. /**
  1427. * Loads a glTF scene.
  1428. * @param context The context when loading the asset
  1429. * @param scene The glTF scene property
  1430. * @returns A promise that resolves when the load is complete
  1431. */
  1432. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1433. private _forEachPrimitive;
  1434. private _getMeshes;
  1435. private _getSkeletons;
  1436. private _getAnimationGroups;
  1437. private _startAnimations;
  1438. /**
  1439. * Loads a glTF node.
  1440. * @param context The context when loading the asset
  1441. * @param node The glTF node property
  1442. * @param assign A function called synchronously after parsing the glTF properties
  1443. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1444. */
  1445. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1446. private _loadMeshAsync;
  1447. /**
  1448. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1449. * @param context The context when loading the asset
  1450. * @param name The mesh name when loading the asset
  1451. * @param node The glTF node when loading the asset
  1452. * @param mesh The glTF mesh when loading the asset
  1453. * @param primitive The glTF mesh primitive property
  1454. * @param assign A function called synchronously after parsing the glTF properties
  1455. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1456. */
  1457. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1458. private _loadVertexDataAsync;
  1459. private _createMorphTargets;
  1460. private _loadMorphTargetsAsync;
  1461. private _loadMorphTargetVertexDataAsync;
  1462. private static _LoadTransform;
  1463. private _loadSkinAsync;
  1464. private _loadBones;
  1465. private _loadBone;
  1466. private _loadSkinInverseBindMatricesDataAsync;
  1467. private _updateBoneMatrices;
  1468. private _getNodeMatrix;
  1469. /**
  1470. * Loads a glTF camera.
  1471. * @param context The context when loading the asset
  1472. * @param camera The glTF camera property
  1473. * @param assign A function called synchronously after parsing the glTF properties
  1474. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1475. */
  1476. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1477. private _loadAnimationsAsync;
  1478. /**
  1479. * Loads a glTF animation.
  1480. * @param context The context when loading the asset
  1481. * @param animation The glTF animation property
  1482. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1483. */
  1484. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1485. /**
  1486. * @hidden Loads a glTF animation channel.
  1487. * @param context The context when loading the asset
  1488. * @param animationContext The context of the animation when loading the asset
  1489. * @param animation The glTF animation property
  1490. * @param channel The glTF animation channel property
  1491. * @param babylonAnimationGroup The babylon animation group property
  1492. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1493. * @returns A void promise when the channel load is complete
  1494. */
  1495. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1496. private _loadAnimationSamplerAsync;
  1497. private _loadBufferAsync;
  1498. /**
  1499. * Loads a glTF buffer view.
  1500. * @param context The context when loading the asset
  1501. * @param bufferView The glTF buffer view property
  1502. * @returns A promise that resolves with the loaded data when the load is complete
  1503. */
  1504. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1505. private _loadAccessorAsync;
  1506. private _loadFloatAccessorAsync;
  1507. private _loadIndicesAccessorAsync;
  1508. private _loadVertexBufferViewAsync;
  1509. private _loadVertexAccessorAsync;
  1510. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1511. /** @hidden */
  1512. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1513. private _createDefaultMaterial;
  1514. /**
  1515. * Creates a Babylon material from a glTF material.
  1516. * @param context The context when loading the asset
  1517. * @param material The glTF material property
  1518. * @param babylonDrawMode The draw mode for the Babylon material
  1519. * @returns The Babylon material
  1520. */
  1521. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1522. /**
  1523. * Loads properties from a glTF material into a Babylon material.
  1524. * @param context The context when loading the asset
  1525. * @param material The glTF material property
  1526. * @param babylonMaterial The Babylon material
  1527. * @returns A promise that resolves when the load is complete
  1528. */
  1529. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1530. /**
  1531. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1532. * @param context The context when loading the asset
  1533. * @param material The glTF material property
  1534. * @param babylonMaterial The Babylon material
  1535. * @returns A promise that resolves when the load is complete
  1536. */
  1537. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1538. /**
  1539. * Loads the alpha properties from a glTF material into a Babylon material.
  1540. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1541. * @param context The context when loading the asset
  1542. * @param material The glTF material property
  1543. * @param babylonMaterial The Babylon material
  1544. */
  1545. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1546. /**
  1547. * Loads a glTF texture info.
  1548. * @param context The context when loading the asset
  1549. * @param textureInfo The glTF texture info property
  1550. * @param assign A function called synchronously after parsing the glTF properties
  1551. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1552. */
  1553. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1554. private _loadTextureAsync;
  1555. private _loadSampler;
  1556. /**
  1557. * Loads a glTF image.
  1558. * @param context The context when loading the asset
  1559. * @param image The glTF image property
  1560. * @returns A promise that resolves with the loaded data when the load is complete
  1561. */
  1562. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1563. /**
  1564. * Loads a glTF uri.
  1565. * @param context The context when loading the asset
  1566. * @param property The glTF property associated with the uri
  1567. * @param uri The base64 or relative uri
  1568. * @returns A promise that resolves with the loaded data when the load is complete
  1569. */
  1570. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1571. private _onProgress;
  1572. /**
  1573. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1574. * @param babylonObject the Babylon object with metadata
  1575. * @param pointer the JSON pointer
  1576. */
  1577. static AddPointerMetadata(babylonObject: {
  1578. metadata: any;
  1579. }, pointer: string): void;
  1580. private static _GetTextureWrapMode;
  1581. private static _GetTextureSamplingMode;
  1582. private static _GetTypedArrayConstructor;
  1583. private static _GetTypedArray;
  1584. private static _GetNumComponents;
  1585. private static _ValidateUri;
  1586. private static _GetDrawMode;
  1587. private _compileMaterialsAsync;
  1588. private _compileShadowGeneratorsAsync;
  1589. private _forEachExtensions;
  1590. private _applyExtensions;
  1591. private _extensionsOnLoading;
  1592. private _extensionsOnReady;
  1593. private _extensionsLoadSceneAsync;
  1594. private _extensionsLoadNodeAsync;
  1595. private _extensionsLoadCameraAsync;
  1596. private _extensionsLoadVertexDataAsync;
  1597. private _extensionsLoadMeshPrimitiveAsync;
  1598. private _extensionsLoadMaterialAsync;
  1599. private _extensionsCreateMaterial;
  1600. private _extensionsLoadMaterialPropertiesAsync;
  1601. private _extensionsLoadTextureInfoAsync;
  1602. private _extensionsLoadAnimationAsync;
  1603. private _extensionsLoadSkinAsync;
  1604. private _extensionsLoadUriAsync;
  1605. /**
  1606. * Helper method called by a loader extension to load an glTF extension.
  1607. * @param context The context when loading the asset
  1608. * @param property The glTF property to load the extension from
  1609. * @param extensionName The name of the extension to load
  1610. * @param actionAsync The action to run
  1611. * @returns The promise returned by actionAsync or null if the extension does not exist
  1612. */
  1613. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1614. /**
  1615. * Helper method called by a loader extension to load a glTF extra.
  1616. * @param context The context when loading the asset
  1617. * @param property The glTF property to load the extra from
  1618. * @param extensionName The name of the extension to load
  1619. * @param actionAsync The action to run
  1620. * @returns The promise returned by actionAsync or null if the extra does not exist
  1621. */
  1622. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1623. /**
  1624. * Increments the indentation level and logs a message.
  1625. * @param message The message to log
  1626. */
  1627. logOpen(message: string): void;
  1628. /**
  1629. * Decrements the indentation level.
  1630. */
  1631. logClose(): void;
  1632. /**
  1633. * Logs a message
  1634. * @param message The message to log
  1635. */
  1636. log(message: string): void;
  1637. /**
  1638. * Starts a performance counter.
  1639. * @param counterName The name of the performance counter
  1640. */
  1641. startPerformanceCounter(counterName: string): void;
  1642. /**
  1643. * Ends a performance counter.
  1644. * @param counterName The name of the performance counter
  1645. */
  1646. endPerformanceCounter(counterName: string): void;
  1647. }
  1648. }
  1649. declare module "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based" {
  1650. import { Nullable } from "babylonjs/types";
  1651. import { IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1652. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1653. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1654. /**
  1655. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1656. */
  1657. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1658. /** The name of this extension. */
  1659. readonly name: string;
  1660. /** Defines whether this extension is enabled. */
  1661. enabled: boolean;
  1662. private _loader;
  1663. private _lights?;
  1664. /** @hidden */
  1665. constructor(loader: GLTFLoader);
  1666. /** @hidden */
  1667. dispose(): void;
  1668. /** @hidden */
  1669. onLoading(): void;
  1670. /** @hidden */
  1671. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1672. private _loadLightAsync;
  1673. }
  1674. }
  1675. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression" {
  1676. import { DracoCompression } from "babylonjs/Meshes/Compression/dracoCompression";
  1677. import { Nullable } from "babylonjs/types";
  1678. import { Geometry } from "babylonjs/Meshes/geometry";
  1679. import { Mesh } from "babylonjs/Meshes/mesh";
  1680. import { IMeshPrimitive } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1681. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1682. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1683. /**
  1684. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1685. */
  1686. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1687. /** The name of this extension. */
  1688. readonly name: string;
  1689. /** The draco compression used to decode vertex data or DracoCompression.Default if not defined */
  1690. dracoCompression?: DracoCompression;
  1691. /** Defines whether this extension is enabled. */
  1692. enabled: boolean;
  1693. private _loader;
  1694. /** @hidden */
  1695. constructor(loader: GLTFLoader);
  1696. /** @hidden */
  1697. dispose(): void;
  1698. /** @hidden */
  1699. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1700. }
  1701. }
  1702. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual" {
  1703. import { Nullable } from "babylonjs/types";
  1704. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1705. import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1706. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1707. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1708. /**
  1709. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1710. */
  1711. export class KHR_lights implements IGLTFLoaderExtension {
  1712. /** The name of this extension. */
  1713. readonly name: string;
  1714. /** Defines whether this extension is enabled. */
  1715. enabled: boolean;
  1716. private _loader;
  1717. private _lights?;
  1718. /** @hidden */
  1719. constructor(loader: GLTFLoader);
  1720. /** @hidden */
  1721. dispose(): void;
  1722. /** @hidden */
  1723. onLoading(): void;
  1724. /** @hidden */
  1725. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1726. }
  1727. }
  1728. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness" {
  1729. import { Nullable } from "babylonjs/types";
  1730. import { Material } from "babylonjs/Materials/material";
  1731. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1732. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1733. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1734. /**
  1735. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1736. */
  1737. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1738. /** The name of this extension. */
  1739. readonly name: string;
  1740. /** Defines whether this extension is enabled. */
  1741. enabled: boolean;
  1742. private _loader;
  1743. /** @hidden */
  1744. constructor(loader: GLTFLoader);
  1745. /** @hidden */
  1746. dispose(): void;
  1747. /** @hidden */
  1748. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1749. private _loadSpecularGlossinessPropertiesAsync;
  1750. }
  1751. }
  1752. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit" {
  1753. import { Nullable } from "babylonjs/types";
  1754. import { Material } from "babylonjs/Materials/material";
  1755. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1756. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1757. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1758. /**
  1759. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1760. */
  1761. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1762. /** The name of this extension. */
  1763. readonly name: string;
  1764. /** Defines whether this extension is enabled. */
  1765. enabled: boolean;
  1766. private _loader;
  1767. /** @hidden */
  1768. constructor(loader: GLTFLoader);
  1769. /** @hidden */
  1770. dispose(): void;
  1771. /** @hidden */
  1772. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1773. private _loadUnlitPropertiesAsync;
  1774. }
  1775. }
  1776. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform" {
  1777. import { Nullable } from "babylonjs/types";
  1778. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1779. import { ITextureInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1780. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1781. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1782. /**
  1783. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1784. */
  1785. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1786. /** The name of this extension. */
  1787. readonly name: string;
  1788. /** Defines whether this extension is enabled. */
  1789. enabled: boolean;
  1790. private _loader;
  1791. /** @hidden */
  1792. constructor(loader: GLTFLoader);
  1793. /** @hidden */
  1794. dispose(): void;
  1795. /** @hidden */
  1796. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1797. }
  1798. }
  1799. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter" {
  1800. import { Nullable } from "babylonjs/types";
  1801. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1802. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1803. import { IScene, INode, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1804. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1805. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1806. /**
  1807. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1808. */
  1809. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1810. /** The name of this extension. */
  1811. readonly name: string;
  1812. /** Defines whether this extension is enabled. */
  1813. enabled: boolean;
  1814. private _loader;
  1815. private _clips;
  1816. private _emitters;
  1817. /** @hidden */
  1818. constructor(loader: GLTFLoader);
  1819. /** @hidden */
  1820. dispose(): void;
  1821. /** @hidden */
  1822. onLoading(): void;
  1823. /** @hidden */
  1824. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1825. /** @hidden */
  1826. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1827. /** @hidden */
  1828. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1829. private _loadClipAsync;
  1830. private _loadEmitterAsync;
  1831. private _getEventAction;
  1832. private _loadAnimationEventAsync;
  1833. }
  1834. }
  1835. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod" {
  1836. import { Nullable } from "babylonjs/types";
  1837. import { Observable } from "babylonjs/Misc/observable";
  1838. import { Material } from "babylonjs/Materials/material";
  1839. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1840. import { Mesh } from "babylonjs/Meshes/mesh";
  1841. import { INode, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1842. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1843. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1844. import { IProperty } from 'babylonjs-gltf2interface';
  1845. /**
  1846. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1847. */
  1848. export class MSFT_lod implements IGLTFLoaderExtension {
  1849. /** The name of this extension. */
  1850. readonly name: string;
  1851. /** Defines whether this extension is enabled. */
  1852. enabled: boolean;
  1853. /**
  1854. * Maximum number of LODs to load, starting from the lowest LOD.
  1855. */
  1856. maxLODsToLoad: number;
  1857. /**
  1858. * Observable raised when all node LODs of one level are loaded.
  1859. * The event data is the index of the loaded LOD starting from zero.
  1860. * Dispose the loader to cancel the loading of the next level of LODs.
  1861. */
  1862. onNodeLODsLoadedObservable: Observable<number>;
  1863. /**
  1864. * Observable raised when all material LODs of one level are loaded.
  1865. * The event data is the index of the loaded LOD starting from zero.
  1866. * Dispose the loader to cancel the loading of the next level of LODs.
  1867. */
  1868. onMaterialLODsLoadedObservable: Observable<number>;
  1869. private _loader;
  1870. private _nodeIndexLOD;
  1871. private _nodeSignalLODs;
  1872. private _nodePromiseLODs;
  1873. private _materialIndexLOD;
  1874. private _materialSignalLODs;
  1875. private _materialPromiseLODs;
  1876. /** @hidden */
  1877. constructor(loader: GLTFLoader);
  1878. /** @hidden */
  1879. dispose(): void;
  1880. /** @hidden */
  1881. onReady(): void;
  1882. /** @hidden */
  1883. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1884. /** @hidden */
  1885. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1886. /** @hidden */
  1887. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1888. /**
  1889. * Gets an array of LOD properties from lowest to highest.
  1890. */
  1891. private _getLODs;
  1892. private _disposeUnusedMaterials;
  1893. }
  1894. }
  1895. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh" {
  1896. import { Nullable } from "babylonjs/types";
  1897. import { Material } from "babylonjs/Materials/material";
  1898. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1899. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1900. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1901. /** @hidden */
  1902. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1903. readonly name: string;
  1904. enabled: boolean;
  1905. private _loader;
  1906. constructor(loader: GLTFLoader);
  1907. dispose(): void;
  1908. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1909. }
  1910. }
  1911. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors" {
  1912. import { Nullable } from "babylonjs/types";
  1913. import { Material } from "babylonjs/Materials/material";
  1914. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1915. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1916. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1917. /** @hidden */
  1918. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1919. readonly name: string;
  1920. enabled: boolean;
  1921. private _loader;
  1922. constructor(loader: GLTFLoader);
  1923. dispose(): void;
  1924. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1925. }
  1926. }
  1927. declare module "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata" {
  1928. import { Nullable } from "babylonjs/types";
  1929. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1930. import { Camera } from "babylonjs/Cameras/camera";
  1931. import { INode, ICamera, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1932. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1933. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1934. import { Material } from "babylonjs/Materials/material";
  1935. /**
  1936. * Store glTF extras (if present) in BJS objects' metadata
  1937. */
  1938. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  1939. /** The name of this extension. */
  1940. readonly name: string;
  1941. /** Defines whether this extension is enabled. */
  1942. enabled: boolean;
  1943. private _loader;
  1944. private _assignExtras;
  1945. /** @hidden */
  1946. constructor(loader: GLTFLoader);
  1947. /** @hidden */
  1948. dispose(): void;
  1949. /** @hidden */
  1950. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1951. /** @hidden */
  1952. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1953. /** @hidden */
  1954. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1955. }
  1956. }
  1957. declare module "babylonjs-loaders/glTF/2.0/Extensions/index" {
  1958. export * from "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based";
  1959. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
  1960. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual";
  1961. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness";
  1962. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit";
  1963. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform";
  1964. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter";
  1965. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod";
  1966. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh";
  1967. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors";
  1968. export * from "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata";
  1969. }
  1970. declare module "babylonjs-loaders/glTF/2.0/index" {
  1971. export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1972. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1973. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1974. export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
  1975. }
  1976. declare module "babylonjs-loaders/glTF/index" {
  1977. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  1978. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  1979. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  1980. export { GLTF1, GLTF2 };
  1981. }
  1982. declare module "babylonjs-loaders/OBJ/objFileLoader" {
  1983. import { Vector2 } from "babylonjs/Maths/math";
  1984. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1985. import { Skeleton } from "babylonjs/Bones/skeleton";
  1986. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1987. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  1988. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1989. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin } from "babylonjs/Loading/sceneLoader";
  1990. import { AssetContainer } from "babylonjs/assetContainer";
  1991. import { Scene } from "babylonjs/scene";
  1992. /**
  1993. * Class reading and parsing the MTL file bundled with the obj file.
  1994. */
  1995. export class MTLFileLoader {
  1996. /**
  1997. * All material loaded from the mtl will be set here
  1998. */
  1999. materials: StandardMaterial[];
  2000. /**
  2001. * This function will read the mtl file and create each material described inside
  2002. * This function could be improve by adding :
  2003. * -some component missing (Ni, Tf...)
  2004. * -including the specific options available
  2005. *
  2006. * @param scene defines the scene the material will be created in
  2007. * @param data defines the mtl data to parse
  2008. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2009. */
  2010. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  2011. /**
  2012. * Gets the texture for the material.
  2013. *
  2014. * If the material is imported from input file,
  2015. * We sanitize the url to ensure it takes the textre from aside the material.
  2016. *
  2017. * @param rootUrl The root url to load from
  2018. * @param value The value stored in the mtl
  2019. * @return The Texture
  2020. */
  2021. private static _getTexture;
  2022. }
  2023. /**
  2024. * Options for loading OBJ/MTL files
  2025. */
  2026. type MeshLoadOptions = {
  2027. /**
  2028. * Defines if UVs are optimized by default during load.
  2029. */
  2030. OptimizeWithUV: boolean;
  2031. /**
  2032. * Defines custom scaling of UV coordinates of loaded meshes.
  2033. */
  2034. UVScaling: Vector2;
  2035. /**
  2036. * Invert model on y-axis (does a model scaling inversion)
  2037. */
  2038. InvertY: boolean;
  2039. /**
  2040. * Invert Y-Axis of referenced textures on load
  2041. */
  2042. InvertTextureY: boolean;
  2043. /**
  2044. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2045. */
  2046. ImportVertexColors: boolean;
  2047. /**
  2048. * Compute the normals for the model, even if normals are present in the file.
  2049. */
  2050. ComputeNormals: boolean;
  2051. /**
  2052. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2053. */
  2054. SkipMaterials: boolean;
  2055. /**
  2056. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2057. */
  2058. MaterialLoadingFailsSilently: boolean;
  2059. };
  2060. /**
  2061. * OBJ file type loader.
  2062. * This is a babylon scene loader plugin.
  2063. */
  2064. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2065. /**
  2066. * Defines if UVs are optimized by default during load.
  2067. */
  2068. static OPTIMIZE_WITH_UV: boolean;
  2069. /**
  2070. * Invert model on y-axis (does a model scaling inversion)
  2071. */
  2072. static INVERT_Y: boolean;
  2073. /**
  2074. * Invert Y-Axis of referenced textures on load
  2075. */
  2076. static INVERT_TEXTURE_Y: boolean;
  2077. /**
  2078. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2079. */
  2080. static IMPORT_VERTEX_COLORS: boolean;
  2081. /**
  2082. * Compute the normals for the model, even if normals are present in the file.
  2083. */
  2084. static COMPUTE_NORMALS: boolean;
  2085. /**
  2086. * Defines custom scaling of UV coordinates of loaded meshes.
  2087. */
  2088. static UV_SCALING: Vector2;
  2089. /**
  2090. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2091. */
  2092. static SKIP_MATERIALS: boolean;
  2093. /**
  2094. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2095. *
  2096. * Defaults to true for backwards compatibility.
  2097. */
  2098. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2099. /**
  2100. * Defines the name of the plugin.
  2101. */
  2102. name: string;
  2103. /**
  2104. * Defines the extension the plugin is able to load.
  2105. */
  2106. extensions: string;
  2107. /** @hidden */
  2108. obj: RegExp;
  2109. /** @hidden */
  2110. group: RegExp;
  2111. /** @hidden */
  2112. mtllib: RegExp;
  2113. /** @hidden */
  2114. usemtl: RegExp;
  2115. /** @hidden */
  2116. smooth: RegExp;
  2117. /** @hidden */
  2118. vertexPattern: RegExp;
  2119. /** @hidden */
  2120. normalPattern: RegExp;
  2121. /** @hidden */
  2122. uvPattern: RegExp;
  2123. /** @hidden */
  2124. facePattern1: RegExp;
  2125. /** @hidden */
  2126. facePattern2: RegExp;
  2127. /** @hidden */
  2128. facePattern3: RegExp;
  2129. /** @hidden */
  2130. facePattern4: RegExp;
  2131. /** @hidden */
  2132. facePattern5: RegExp;
  2133. private _meshLoadOptions;
  2134. /**
  2135. * Creates loader for .OBJ files
  2136. *
  2137. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2138. */
  2139. constructor(meshLoadOptions?: MeshLoadOptions);
  2140. private static readonly currentMeshLoadOptions;
  2141. /**
  2142. * Calls synchronously the MTL file attached to this obj.
  2143. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2144. * Without this function materials are not displayed in the first frame (but displayed after).
  2145. * In consequence it is impossible to get material information in your HTML file
  2146. *
  2147. * @param url The URL of the MTL file
  2148. * @param rootUrl
  2149. * @param onSuccess Callback function to be called when the MTL file is loaded
  2150. * @private
  2151. */
  2152. private _loadMTL;
  2153. /**
  2154. * Instantiates a OBJ file loader plugin.
  2155. * @returns the created plugin
  2156. */
  2157. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2158. /**
  2159. * If the data string can be loaded directly.
  2160. *
  2161. * @param data string containing the file data
  2162. * @returns if the data can be loaded directly
  2163. */
  2164. canDirectLoad(data: string): boolean;
  2165. /**
  2166. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2167. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2168. * @param scene the scene the meshes should be added to
  2169. * @param data the OBJ data to load
  2170. * @param rootUrl root url to load from
  2171. * @param onProgress event that fires when loading progress has occured
  2172. * @param fileName Defines the name of the file to load
  2173. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2174. */
  2175. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2176. meshes: AbstractMesh[];
  2177. particleSystems: IParticleSystem[];
  2178. skeletons: Skeleton[];
  2179. animationGroups: AnimationGroup[];
  2180. }>;
  2181. /**
  2182. * Imports all objects from the loaded OBJ data and adds them to the scene
  2183. * @param scene the scene the objects should be added to
  2184. * @param data the OBJ data to load
  2185. * @param rootUrl root url to load from
  2186. * @param onProgress event that fires when loading progress has occured
  2187. * @param fileName Defines the name of the file to load
  2188. * @returns a promise which completes when objects have been loaded to the scene
  2189. */
  2190. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2191. /**
  2192. * Load into an asset container.
  2193. * @param scene The scene to load into
  2194. * @param data The data to import
  2195. * @param rootUrl The root url for scene and resources
  2196. * @param onProgress The callback when the load progresses
  2197. * @param fileName Defines the name of the file to load
  2198. * @returns The loaded asset container
  2199. */
  2200. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2201. /**
  2202. * Read the OBJ file and create an Array of meshes.
  2203. * Each mesh contains all information given by the OBJ and the MTL file.
  2204. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2205. *
  2206. * @param meshesNames
  2207. * @param scene Scene The scene where are displayed the data
  2208. * @param data String The content of the obj file
  2209. * @param rootUrl String The path to the folder
  2210. * @returns Array<AbstractMesh>
  2211. * @private
  2212. */
  2213. private _parseSolid;
  2214. }
  2215. }
  2216. declare module "babylonjs-loaders/OBJ/index" {
  2217. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2218. }
  2219. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2220. import { Nullable } from "babylonjs/types";
  2221. import { Skeleton } from "babylonjs/Bones/skeleton";
  2222. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2223. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2224. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2225. import { AssetContainer } from "babylonjs/assetContainer";
  2226. import { Scene } from "babylonjs/scene";
  2227. /**
  2228. * STL file type loader.
  2229. * This is a babylon scene loader plugin.
  2230. */
  2231. export class STLFileLoader implements ISceneLoaderPlugin {
  2232. /** @hidden */
  2233. solidPattern: RegExp;
  2234. /** @hidden */
  2235. facetsPattern: RegExp;
  2236. /** @hidden */
  2237. normalPattern: RegExp;
  2238. /** @hidden */
  2239. vertexPattern: RegExp;
  2240. /**
  2241. * Defines the name of the plugin.
  2242. */
  2243. name: string;
  2244. /**
  2245. * Defines the extensions the stl loader is able to load.
  2246. * force data to come in as an ArrayBuffer
  2247. * we'll convert to string if it looks like it's an ASCII .stl
  2248. */
  2249. extensions: ISceneLoaderPluginExtensions;
  2250. /**
  2251. * Import meshes into a scene.
  2252. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2253. * @param scene The scene to import into
  2254. * @param data The data to import
  2255. * @param rootUrl The root url for scene and resources
  2256. * @param meshes The meshes array to import into
  2257. * @param particleSystems The particle systems array to import into
  2258. * @param skeletons The skeletons array to import into
  2259. * @param onError The callback when import fails
  2260. * @returns True if successful or false otherwise
  2261. */
  2262. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2263. /**
  2264. * Load into a scene.
  2265. * @param scene The scene to load into
  2266. * @param data The data to import
  2267. * @param rootUrl The root url for scene and resources
  2268. * @param onError The callback when import fails
  2269. * @returns true if successful or false otherwise
  2270. */
  2271. load(scene: Scene, data: any, rootUrl: string): boolean;
  2272. /**
  2273. * Load into an asset container.
  2274. * @param scene The scene to load into
  2275. * @param data The data to import
  2276. * @param rootUrl The root url for scene and resources
  2277. * @param onError The callback when import fails
  2278. * @returns The loaded asset container
  2279. */
  2280. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2281. private _isBinary;
  2282. private _parseBinary;
  2283. private _parseASCII;
  2284. }
  2285. }
  2286. declare module "babylonjs-loaders/STL/index" {
  2287. export * from "babylonjs-loaders/STL/stlFileLoader";
  2288. }
  2289. declare module "babylonjs-loaders/index" {
  2290. export * from "babylonjs-loaders/glTF/index";
  2291. export * from "babylonjs-loaders/OBJ/index";
  2292. export * from "babylonjs-loaders/STL/index";
  2293. }
  2294. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2295. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2296. }
  2297. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2298. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2299. export { GLTF1 };
  2300. }
  2301. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2302. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2303. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2304. }
  2305. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2306. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2307. export { GLTF2 };
  2308. }
  2309. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2310. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2311. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2312. }
  2313. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2314. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2315. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2316. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2317. }
  2318. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2319. export * from "babylonjs-loaders/OBJ/index";
  2320. }
  2321. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2322. export * from "babylonjs-loaders/STL/index";
  2323. }
  2324. declare module "babylonjs-loaders/legacy/legacy" {
  2325. import "babylonjs-loaders/index";
  2326. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2327. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2328. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2329. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2330. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2331. }
  2332. declare module "babylonjs-loaders" {
  2333. export * from "babylonjs-loaders/legacy/legacy";
  2334. }
  2335. declare module BABYLON {
  2336. /**
  2337. * Mode that determines the coordinate system to use.
  2338. */
  2339. export enum GLTFLoaderCoordinateSystemMode {
  2340. /**
  2341. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2342. */
  2343. AUTO = 0,
  2344. /**
  2345. * Sets the useRightHandedSystem flag on the scene.
  2346. */
  2347. FORCE_RIGHT_HANDED = 1
  2348. }
  2349. /**
  2350. * Mode that determines what animations will start.
  2351. */
  2352. export enum GLTFLoaderAnimationStartMode {
  2353. /**
  2354. * No animation will start.
  2355. */
  2356. NONE = 0,
  2357. /**
  2358. * The first animation will start.
  2359. */
  2360. FIRST = 1,
  2361. /**
  2362. * All animations will start.
  2363. */
  2364. ALL = 2
  2365. }
  2366. /**
  2367. * Interface that contains the data for the glTF asset.
  2368. */
  2369. export interface IGLTFLoaderData {
  2370. /**
  2371. * Object that represents the glTF JSON.
  2372. */
  2373. json: Object;
  2374. /**
  2375. * The BIN chunk of a binary glTF.
  2376. */
  2377. bin: Nullable<ArrayBufferView>;
  2378. }
  2379. /**
  2380. * Interface for extending the loader.
  2381. */
  2382. export interface IGLTFLoaderExtension {
  2383. /**
  2384. * The name of this extension.
  2385. */
  2386. readonly name: string;
  2387. /**
  2388. * Defines whether this extension is enabled.
  2389. */
  2390. enabled: boolean;
  2391. }
  2392. /**
  2393. * Loader state.
  2394. */
  2395. export enum GLTFLoaderState {
  2396. /**
  2397. * The asset is loading.
  2398. */
  2399. LOADING = 0,
  2400. /**
  2401. * The asset is ready for rendering.
  2402. */
  2403. READY = 1,
  2404. /**
  2405. * The asset is completely loaded.
  2406. */
  2407. COMPLETE = 2
  2408. }
  2409. /** @hidden */
  2410. export interface IGLTFLoader extends IDisposable {
  2411. readonly state: Nullable<GLTFLoaderState>;
  2412. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  2413. meshes: AbstractMesh[];
  2414. particleSystems: IParticleSystem[];
  2415. skeletons: Skeleton[];
  2416. animationGroups: AnimationGroup[];
  2417. }>;
  2418. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2419. }
  2420. /**
  2421. * File loader for loading glTF files into a scene.
  2422. */
  2423. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2424. /** @hidden */
  2425. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2426. /** @hidden */
  2427. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2428. /**
  2429. * Raised when the asset has been parsed
  2430. */
  2431. onParsedObservable: Observable<IGLTFLoaderData>;
  2432. private _onParsedObserver;
  2433. /**
  2434. * Raised when the asset has been parsed
  2435. */
  2436. onParsed: (loaderData: IGLTFLoaderData) => void;
  2437. /**
  2438. * 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.
  2439. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2440. * Defaults to true.
  2441. * @hidden
  2442. */
  2443. static IncrementalLoading: boolean;
  2444. /**
  2445. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2446. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2447. * @hidden
  2448. */
  2449. static HomogeneousCoordinates: boolean;
  2450. /**
  2451. * The coordinate system mode. Defaults to AUTO.
  2452. */
  2453. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2454. /**
  2455. * The animation start mode. Defaults to FIRST.
  2456. */
  2457. animationStartMode: GLTFLoaderAnimationStartMode;
  2458. /**
  2459. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2460. */
  2461. compileMaterials: boolean;
  2462. /**
  2463. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2464. */
  2465. useClipPlane: boolean;
  2466. /**
  2467. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2468. */
  2469. compileShadowGenerators: boolean;
  2470. /**
  2471. * Defines if the Alpha blended materials are only applied as coverage.
  2472. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2473. * If true, no extra effects are applied to transparent pixels.
  2474. */
  2475. transparencyAsCoverage: boolean;
  2476. /**
  2477. * Function called before loading a url referenced by the asset.
  2478. */
  2479. preprocessUrlAsync: (url: string) => Promise<string>;
  2480. /**
  2481. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2482. */
  2483. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2484. private _onMeshLoadedObserver;
  2485. /**
  2486. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2487. */
  2488. onMeshLoaded: (mesh: AbstractMesh) => void;
  2489. /**
  2490. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2491. */
  2492. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2493. private _onTextureLoadedObserver;
  2494. /**
  2495. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2496. */
  2497. onTextureLoaded: (texture: BaseTexture) => void;
  2498. /**
  2499. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2500. */
  2501. readonly onMaterialLoadedObservable: Observable<Material>;
  2502. private _onMaterialLoadedObserver;
  2503. /**
  2504. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2505. */
  2506. onMaterialLoaded: (material: Material) => void;
  2507. /**
  2508. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2509. */
  2510. readonly onCameraLoadedObservable: Observable<Camera>;
  2511. private _onCameraLoadedObserver;
  2512. /**
  2513. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2514. */
  2515. onCameraLoaded: (camera: Camera) => void;
  2516. /**
  2517. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2518. * For assets with LODs, raised when all of the LODs are complete.
  2519. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2520. */
  2521. readonly onCompleteObservable: Observable<void>;
  2522. private _onCompleteObserver;
  2523. /**
  2524. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2525. * For assets with LODs, raised when all of the LODs are complete.
  2526. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2527. */
  2528. onComplete: () => void;
  2529. /**
  2530. * Observable raised when an error occurs.
  2531. */
  2532. readonly onErrorObservable: Observable<any>;
  2533. private _onErrorObserver;
  2534. /**
  2535. * Callback raised when an error occurs.
  2536. */
  2537. onError: (reason: any) => void;
  2538. /**
  2539. * Observable raised after the loader is disposed.
  2540. */
  2541. readonly onDisposeObservable: Observable<void>;
  2542. private _onDisposeObserver;
  2543. /**
  2544. * Callback raised after the loader is disposed.
  2545. */
  2546. onDispose: () => void;
  2547. /**
  2548. * Observable raised after a loader extension is created.
  2549. * Set additional options for a loader extension in this event.
  2550. */
  2551. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2552. private _onExtensionLoadedObserver;
  2553. /**
  2554. * Callback raised after a loader extension is created.
  2555. */
  2556. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  2557. /**
  2558. * Defines if the loader logging is enabled.
  2559. */
  2560. loggingEnabled: boolean;
  2561. /**
  2562. * Defines if the loader should capture performance counters.
  2563. */
  2564. capturePerformanceCounters: boolean;
  2565. /**
  2566. * Defines if the loader should validate the asset.
  2567. */
  2568. validate: boolean;
  2569. /**
  2570. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2571. */
  2572. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  2573. private _onValidatedObserver;
  2574. /**
  2575. * Callback raised after a loader extension is created.
  2576. */
  2577. onValidated: (results: BABYLON.GLTF2.IGLTFValidationResults) => void;
  2578. private _loader;
  2579. /**
  2580. * Name of the loader ("gltf")
  2581. */
  2582. name: string;
  2583. /**
  2584. * Supported file extensions of the loader (.gltf, .glb)
  2585. */
  2586. extensions: ISceneLoaderPluginExtensions;
  2587. /**
  2588. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2589. */
  2590. dispose(): void;
  2591. /** @hidden */
  2592. _clear(): void;
  2593. /**
  2594. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  2595. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2596. * @param scene the scene the meshes should be added to
  2597. * @param data the glTF data to load
  2598. * @param rootUrl root url to load from
  2599. * @param onProgress event that fires when loading progress has occured
  2600. * @param fileName Defines the name of the file to load
  2601. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2602. */
  2603. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2604. meshes: AbstractMesh[];
  2605. particleSystems: IParticleSystem[];
  2606. skeletons: Skeleton[];
  2607. animationGroups: AnimationGroup[];
  2608. }>;
  2609. /**
  2610. * Imports all objects from the loaded glTF data and adds them to the scene
  2611. * @param scene the scene the objects should be added to
  2612. * @param data the glTF data to load
  2613. * @param rootUrl root url to load from
  2614. * @param onProgress event that fires when loading progress has occured
  2615. * @param fileName Defines the name of the file to load
  2616. * @returns a promise which completes when objects have been loaded to the scene
  2617. */
  2618. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2619. /**
  2620. * Load into an asset container.
  2621. * @param scene The scene to load into
  2622. * @param data The data to import
  2623. * @param rootUrl The root url for scene and resources
  2624. * @param onProgress The callback when the load progresses
  2625. * @param fileName Defines the name of the file to load
  2626. * @returns The loaded asset container
  2627. */
  2628. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2629. /**
  2630. * If the data string can be loaded directly.
  2631. * @param data string contianing the file data
  2632. * @returns if the data can be loaded directly
  2633. */
  2634. canDirectLoad(data: string): boolean;
  2635. /**
  2636. * Rewrites a url by combining a root url and response url.
  2637. */
  2638. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  2639. /**
  2640. * Instantiates a glTF file loader plugin.
  2641. * @returns the created plugin
  2642. */
  2643. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2644. /**
  2645. * The loader state or null if the loader is not active.
  2646. */
  2647. readonly loaderState: Nullable<GLTFLoaderState>;
  2648. /**
  2649. * Returns a promise that resolves when the asset is completely loaded.
  2650. * @returns a promise that resolves when the asset is completely loaded.
  2651. */
  2652. whenCompleteAsync(): Promise<void>;
  2653. private _parseAsync;
  2654. private _validateAsync;
  2655. private _getLoader;
  2656. private _unpackBinary;
  2657. private _unpackBinaryV1;
  2658. private _unpackBinaryV2;
  2659. private static _parseVersion;
  2660. private static _compareVersion;
  2661. private static _decodeBufferToText;
  2662. private static readonly _logSpaces;
  2663. private _logIndentLevel;
  2664. private _loggingEnabled;
  2665. /** @hidden */
  2666. _log: (message: string) => void;
  2667. /** @hidden */
  2668. _logOpen(message: string): void;
  2669. /** @hidden */
  2670. _logClose(): void;
  2671. private _logEnabled;
  2672. private _logDisabled;
  2673. private _capturePerformanceCounters;
  2674. /** @hidden */
  2675. _startPerformanceCounter: (counterName: string) => void;
  2676. /** @hidden */
  2677. _endPerformanceCounter: (counterName: string) => void;
  2678. private _startPerformanceCounterEnabled;
  2679. private _startPerformanceCounterDisabled;
  2680. private _endPerformanceCounterEnabled;
  2681. private _endPerformanceCounterDisabled;
  2682. }
  2683. }
  2684. declare module BABYLON.GLTF1 {
  2685. /**
  2686. * Enums
  2687. * @hidden
  2688. */
  2689. export enum EComponentType {
  2690. BYTE = 5120,
  2691. UNSIGNED_BYTE = 5121,
  2692. SHORT = 5122,
  2693. UNSIGNED_SHORT = 5123,
  2694. FLOAT = 5126
  2695. }
  2696. /** @hidden */
  2697. export enum EShaderType {
  2698. FRAGMENT = 35632,
  2699. VERTEX = 35633
  2700. }
  2701. /** @hidden */
  2702. export enum EParameterType {
  2703. BYTE = 5120,
  2704. UNSIGNED_BYTE = 5121,
  2705. SHORT = 5122,
  2706. UNSIGNED_SHORT = 5123,
  2707. INT = 5124,
  2708. UNSIGNED_INT = 5125,
  2709. FLOAT = 5126,
  2710. FLOAT_VEC2 = 35664,
  2711. FLOAT_VEC3 = 35665,
  2712. FLOAT_VEC4 = 35666,
  2713. INT_VEC2 = 35667,
  2714. INT_VEC3 = 35668,
  2715. INT_VEC4 = 35669,
  2716. BOOL = 35670,
  2717. BOOL_VEC2 = 35671,
  2718. BOOL_VEC3 = 35672,
  2719. BOOL_VEC4 = 35673,
  2720. FLOAT_MAT2 = 35674,
  2721. FLOAT_MAT3 = 35675,
  2722. FLOAT_MAT4 = 35676,
  2723. SAMPLER_2D = 35678
  2724. }
  2725. /** @hidden */
  2726. export enum ETextureWrapMode {
  2727. CLAMP_TO_EDGE = 33071,
  2728. MIRRORED_REPEAT = 33648,
  2729. REPEAT = 10497
  2730. }
  2731. /** @hidden */
  2732. export enum ETextureFilterType {
  2733. NEAREST = 9728,
  2734. LINEAR = 9728,
  2735. NEAREST_MIPMAP_NEAREST = 9984,
  2736. LINEAR_MIPMAP_NEAREST = 9985,
  2737. NEAREST_MIPMAP_LINEAR = 9986,
  2738. LINEAR_MIPMAP_LINEAR = 9987
  2739. }
  2740. /** @hidden */
  2741. export enum ETextureFormat {
  2742. ALPHA = 6406,
  2743. RGB = 6407,
  2744. RGBA = 6408,
  2745. LUMINANCE = 6409,
  2746. LUMINANCE_ALPHA = 6410
  2747. }
  2748. /** @hidden */
  2749. export enum ECullingType {
  2750. FRONT = 1028,
  2751. BACK = 1029,
  2752. FRONT_AND_BACK = 1032
  2753. }
  2754. /** @hidden */
  2755. export enum EBlendingFunction {
  2756. ZERO = 0,
  2757. ONE = 1,
  2758. SRC_COLOR = 768,
  2759. ONE_MINUS_SRC_COLOR = 769,
  2760. DST_COLOR = 774,
  2761. ONE_MINUS_DST_COLOR = 775,
  2762. SRC_ALPHA = 770,
  2763. ONE_MINUS_SRC_ALPHA = 771,
  2764. DST_ALPHA = 772,
  2765. ONE_MINUS_DST_ALPHA = 773,
  2766. CONSTANT_COLOR = 32769,
  2767. ONE_MINUS_CONSTANT_COLOR = 32770,
  2768. CONSTANT_ALPHA = 32771,
  2769. ONE_MINUS_CONSTANT_ALPHA = 32772,
  2770. SRC_ALPHA_SATURATE = 776
  2771. }
  2772. /** @hidden */
  2773. export interface IGLTFProperty {
  2774. extensions?: {
  2775. [key: string]: any;
  2776. };
  2777. extras?: Object;
  2778. }
  2779. /** @hidden */
  2780. export interface IGLTFChildRootProperty extends IGLTFProperty {
  2781. name?: string;
  2782. }
  2783. /** @hidden */
  2784. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  2785. bufferView: string;
  2786. byteOffset: number;
  2787. byteStride: number;
  2788. count: number;
  2789. type: string;
  2790. componentType: EComponentType;
  2791. max?: number[];
  2792. min?: number[];
  2793. name?: string;
  2794. }
  2795. /** @hidden */
  2796. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  2797. buffer: string;
  2798. byteOffset: number;
  2799. byteLength: number;
  2800. byteStride: number;
  2801. target?: number;
  2802. }
  2803. /** @hidden */
  2804. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  2805. uri: string;
  2806. byteLength?: number;
  2807. type?: string;
  2808. }
  2809. /** @hidden */
  2810. export interface IGLTFShader extends IGLTFChildRootProperty {
  2811. uri: string;
  2812. type: EShaderType;
  2813. }
  2814. /** @hidden */
  2815. export interface IGLTFProgram extends IGLTFChildRootProperty {
  2816. attributes: string[];
  2817. fragmentShader: string;
  2818. vertexShader: string;
  2819. }
  2820. /** @hidden */
  2821. export interface IGLTFTechniqueParameter {
  2822. type: number;
  2823. count?: number;
  2824. semantic?: string;
  2825. node?: string;
  2826. value?: number | boolean | string | Array<any>;
  2827. source?: string;
  2828. babylonValue?: any;
  2829. }
  2830. /** @hidden */
  2831. export interface IGLTFTechniqueCommonProfile {
  2832. lightingModel: string;
  2833. texcoordBindings: Object;
  2834. parameters?: Array<any>;
  2835. }
  2836. /** @hidden */
  2837. export interface IGLTFTechniqueStatesFunctions {
  2838. blendColor?: number[];
  2839. blendEquationSeparate?: number[];
  2840. blendFuncSeparate?: number[];
  2841. colorMask: boolean[];
  2842. cullFace: number[];
  2843. }
  2844. /** @hidden */
  2845. export interface IGLTFTechniqueStates {
  2846. enable: number[];
  2847. functions: IGLTFTechniqueStatesFunctions;
  2848. }
  2849. /** @hidden */
  2850. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  2851. parameters: {
  2852. [key: string]: IGLTFTechniqueParameter;
  2853. };
  2854. program: string;
  2855. attributes: {
  2856. [key: string]: string;
  2857. };
  2858. uniforms: {
  2859. [key: string]: string;
  2860. };
  2861. states: IGLTFTechniqueStates;
  2862. }
  2863. /** @hidden */
  2864. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  2865. technique?: string;
  2866. values: string[];
  2867. }
  2868. /** @hidden */
  2869. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  2870. attributes: {
  2871. [key: string]: string;
  2872. };
  2873. indices: string;
  2874. material: string;
  2875. mode?: number;
  2876. }
  2877. /** @hidden */
  2878. export interface IGLTFMesh extends IGLTFChildRootProperty {
  2879. primitives: IGLTFMeshPrimitive[];
  2880. }
  2881. /** @hidden */
  2882. export interface IGLTFImage extends IGLTFChildRootProperty {
  2883. uri: string;
  2884. }
  2885. /** @hidden */
  2886. export interface IGLTFSampler extends IGLTFChildRootProperty {
  2887. magFilter?: number;
  2888. minFilter?: number;
  2889. wrapS?: number;
  2890. wrapT?: number;
  2891. }
  2892. /** @hidden */
  2893. export interface IGLTFTexture extends IGLTFChildRootProperty {
  2894. sampler: string;
  2895. source: string;
  2896. format?: ETextureFormat;
  2897. internalFormat?: ETextureFormat;
  2898. target?: number;
  2899. type?: number;
  2900. babylonTexture?: Texture;
  2901. }
  2902. /** @hidden */
  2903. export interface IGLTFAmbienLight {
  2904. color?: number[];
  2905. }
  2906. /** @hidden */
  2907. export interface IGLTFDirectionalLight {
  2908. color?: number[];
  2909. }
  2910. /** @hidden */
  2911. export interface IGLTFPointLight {
  2912. color?: number[];
  2913. constantAttenuation?: number;
  2914. linearAttenuation?: number;
  2915. quadraticAttenuation?: number;
  2916. }
  2917. /** @hidden */
  2918. export interface IGLTFSpotLight {
  2919. color?: number[];
  2920. constantAttenuation?: number;
  2921. fallOfAngle?: number;
  2922. fallOffExponent?: number;
  2923. linearAttenuation?: number;
  2924. quadraticAttenuation?: number;
  2925. }
  2926. /** @hidden */
  2927. export interface IGLTFLight extends IGLTFChildRootProperty {
  2928. type: string;
  2929. }
  2930. /** @hidden */
  2931. export interface IGLTFCameraOrthographic {
  2932. xmag: number;
  2933. ymag: number;
  2934. zfar: number;
  2935. znear: number;
  2936. }
  2937. /** @hidden */
  2938. export interface IGLTFCameraPerspective {
  2939. aspectRatio: number;
  2940. yfov: number;
  2941. zfar: number;
  2942. znear: number;
  2943. }
  2944. /** @hidden */
  2945. export interface IGLTFCamera extends IGLTFChildRootProperty {
  2946. type: string;
  2947. }
  2948. /** @hidden */
  2949. export interface IGLTFAnimationChannelTarget {
  2950. id: string;
  2951. path: string;
  2952. }
  2953. /** @hidden */
  2954. export interface IGLTFAnimationChannel {
  2955. sampler: string;
  2956. target: IGLTFAnimationChannelTarget;
  2957. }
  2958. /** @hidden */
  2959. export interface IGLTFAnimationSampler {
  2960. input: string;
  2961. output: string;
  2962. interpolation?: string;
  2963. }
  2964. /** @hidden */
  2965. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  2966. channels?: IGLTFAnimationChannel[];
  2967. parameters?: {
  2968. [key: string]: string;
  2969. };
  2970. samplers?: {
  2971. [key: string]: IGLTFAnimationSampler;
  2972. };
  2973. }
  2974. /** @hidden */
  2975. export interface IGLTFNodeInstanceSkin {
  2976. skeletons: string[];
  2977. skin: string;
  2978. meshes: string[];
  2979. }
  2980. /** @hidden */
  2981. export interface IGLTFSkins extends IGLTFChildRootProperty {
  2982. bindShapeMatrix: number[];
  2983. inverseBindMatrices: string;
  2984. jointNames: string[];
  2985. babylonSkeleton?: Skeleton;
  2986. }
  2987. /** @hidden */
  2988. export interface IGLTFNode extends IGLTFChildRootProperty {
  2989. camera?: string;
  2990. children: string[];
  2991. skin?: string;
  2992. jointName?: string;
  2993. light?: string;
  2994. matrix: number[];
  2995. mesh?: string;
  2996. meshes?: string[];
  2997. rotation?: number[];
  2998. scale?: number[];
  2999. translation?: number[];
  3000. babylonNode?: Node;
  3001. }
  3002. /** @hidden */
  3003. export interface IGLTFScene extends IGLTFChildRootProperty {
  3004. nodes: string[];
  3005. }
  3006. /** @hidden */
  3007. export interface IGLTFRuntime {
  3008. extensions: {
  3009. [key: string]: any;
  3010. };
  3011. accessors: {
  3012. [key: string]: IGLTFAccessor;
  3013. };
  3014. buffers: {
  3015. [key: string]: IGLTFBuffer;
  3016. };
  3017. bufferViews: {
  3018. [key: string]: IGLTFBufferView;
  3019. };
  3020. meshes: {
  3021. [key: string]: IGLTFMesh;
  3022. };
  3023. lights: {
  3024. [key: string]: IGLTFLight;
  3025. };
  3026. cameras: {
  3027. [key: string]: IGLTFCamera;
  3028. };
  3029. nodes: {
  3030. [key: string]: IGLTFNode;
  3031. };
  3032. images: {
  3033. [key: string]: IGLTFImage;
  3034. };
  3035. textures: {
  3036. [key: string]: IGLTFTexture;
  3037. };
  3038. shaders: {
  3039. [key: string]: IGLTFShader;
  3040. };
  3041. programs: {
  3042. [key: string]: IGLTFProgram;
  3043. };
  3044. samplers: {
  3045. [key: string]: IGLTFSampler;
  3046. };
  3047. techniques: {
  3048. [key: string]: IGLTFTechnique;
  3049. };
  3050. materials: {
  3051. [key: string]: IGLTFMaterial;
  3052. };
  3053. animations: {
  3054. [key: string]: IGLTFAnimation;
  3055. };
  3056. skins: {
  3057. [key: string]: IGLTFSkins;
  3058. };
  3059. currentScene?: Object;
  3060. scenes: {
  3061. [key: string]: IGLTFScene;
  3062. };
  3063. extensionsUsed: string[];
  3064. extensionsRequired?: string[];
  3065. buffersCount: number;
  3066. shaderscount: number;
  3067. scene: Scene;
  3068. rootUrl: string;
  3069. loadedBufferCount: number;
  3070. loadedBufferViews: {
  3071. [name: string]: ArrayBufferView;
  3072. };
  3073. loadedShaderCount: number;
  3074. importOnlyMeshes: boolean;
  3075. importMeshesNames?: string[];
  3076. dummyNodes: Node[];
  3077. }
  3078. /** @hidden */
  3079. export interface INodeToRoot {
  3080. bone: Bone;
  3081. node: IGLTFNode;
  3082. id: string;
  3083. }
  3084. /** @hidden */
  3085. export interface IJointNode {
  3086. node: IGLTFNode;
  3087. id: string;
  3088. }
  3089. }
  3090. declare module BABYLON.GLTF1 {
  3091. /**
  3092. * Utils functions for GLTF
  3093. * @hidden
  3094. */
  3095. export class GLTFUtils {
  3096. /**
  3097. * Sets the given "parameter" matrix
  3098. * @param scene: the Scene object
  3099. * @param source: the source node where to pick the matrix
  3100. * @param parameter: the GLTF technique parameter
  3101. * @param uniformName: the name of the shader's uniform
  3102. * @param shaderMaterial: the shader material
  3103. */
  3104. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  3105. /**
  3106. * Sets the given "parameter" matrix
  3107. * @param shaderMaterial: the shader material
  3108. * @param uniform: the name of the shader's uniform
  3109. * @param value: the value of the uniform
  3110. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3111. */
  3112. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  3113. /**
  3114. * Returns the wrap mode of the texture
  3115. * @param mode: the mode value
  3116. */
  3117. static GetWrapMode(mode: number): number;
  3118. /**
  3119. * Returns the byte stride giving an accessor
  3120. * @param accessor: the GLTF accessor objet
  3121. */
  3122. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  3123. /**
  3124. * Returns the texture filter mode giving a mode value
  3125. * @param mode: the filter mode value
  3126. */
  3127. static GetTextureFilterMode(mode: number): ETextureFilterType;
  3128. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  3129. /**
  3130. * Returns a buffer from its accessor
  3131. * @param gltfRuntime: the GLTF runtime
  3132. * @param accessor: the GLTF accessor
  3133. */
  3134. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  3135. /**
  3136. * Decodes a buffer view into a string
  3137. * @param view: the buffer view
  3138. */
  3139. static DecodeBufferToText(view: ArrayBufferView): string;
  3140. /**
  3141. * Returns the default material of gltf. Related to
  3142. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3143. * @param scene: the Babylon.js scene
  3144. */
  3145. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  3146. private static _DefaultMaterial;
  3147. }
  3148. }
  3149. declare module BABYLON.GLTF1 {
  3150. /**
  3151. * Implementation of the base glTF spec
  3152. * @hidden
  3153. */
  3154. export class GLTFLoaderBase {
  3155. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  3156. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3157. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  3158. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3159. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  3160. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3161. }
  3162. /**
  3163. * glTF V1 Loader
  3164. * @hidden
  3165. */
  3166. export class GLTFLoader implements IGLTFLoader {
  3167. static Extensions: {
  3168. [name: string]: GLTFLoaderExtension;
  3169. };
  3170. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3171. state: Nullable<GLTFLoaderState>;
  3172. dispose(): void;
  3173. private _importMeshAsync;
  3174. /**
  3175. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3176. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3177. * @param scene the scene the meshes should be added to
  3178. * @param data gltf data containing information of the meshes in a loaded file
  3179. * @param rootUrl root url to load from
  3180. * @param onProgress event that fires when loading progress has occured
  3181. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3182. */
  3183. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  3184. meshes: AbstractMesh[];
  3185. particleSystems: IParticleSystem[];
  3186. skeletons: Skeleton[];
  3187. animationGroups: AnimationGroup[];
  3188. }>;
  3189. private _loadAsync;
  3190. /**
  3191. * Imports all objects from a loaded gltf file and adds them to the scene
  3192. * @param scene the scene the objects should be added to
  3193. * @param data gltf data containing information of the meshes in a loaded file
  3194. * @param rootUrl root url to load from
  3195. * @param onProgress event that fires when loading progress has occured
  3196. * @returns a promise which completes when objects have been loaded to the scene
  3197. */
  3198. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3199. private _loadShadersAsync;
  3200. private _loadBuffersAsync;
  3201. private _createNodes;
  3202. }
  3203. /** @hidden */
  3204. export abstract class GLTFLoaderExtension {
  3205. private _name;
  3206. constructor(name: string);
  3207. readonly name: string;
  3208. /**
  3209. * Defines an override for loading the runtime
  3210. * Return true to stop further extensions from loading the runtime
  3211. */
  3212. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3213. /**
  3214. * Defines an onverride for creating gltf runtime
  3215. * Return true to stop further extensions from creating the runtime
  3216. */
  3217. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3218. /**
  3219. * Defines an override for loading buffers
  3220. * Return true to stop further extensions from loading this buffer
  3221. */
  3222. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3223. /**
  3224. * Defines an override for loading texture buffers
  3225. * Return true to stop further extensions from loading this texture data
  3226. */
  3227. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3228. /**
  3229. * Defines an override for creating textures
  3230. * Return true to stop further extensions from loading this texture
  3231. */
  3232. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3233. /**
  3234. * Defines an override for loading shader strings
  3235. * Return true to stop further extensions from loading this shader data
  3236. */
  3237. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3238. /**
  3239. * Defines an override for loading materials
  3240. * Return true to stop further extensions from loading this material
  3241. */
  3242. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3243. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3244. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3245. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3246. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3247. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3248. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3249. private static LoadTextureBufferAsync;
  3250. private static CreateTextureAsync;
  3251. private static ApplyExtensions;
  3252. }
  3253. }
  3254. declare module BABYLON.GLTF1 {
  3255. /** @hidden */
  3256. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3257. private _bin;
  3258. constructor();
  3259. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3260. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3261. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3262. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3263. }
  3264. }
  3265. declare module BABYLON.GLTF1 {
  3266. /** @hidden */
  3267. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3268. constructor();
  3269. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3270. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3271. private _loadTexture;
  3272. }
  3273. }
  3274. declare module BABYLON.GLTF2.Loader {
  3275. /**
  3276. * Loader interface with an index field.
  3277. */
  3278. export interface IArrayItem {
  3279. /**
  3280. * The index of this item in the array.
  3281. */
  3282. index: number;
  3283. }
  3284. /**
  3285. * Loader interface with additional members.
  3286. */
  3287. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3288. /** @hidden */
  3289. _data?: Promise<ArrayBufferView>;
  3290. /** @hidden */
  3291. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3292. }
  3293. /**
  3294. * Loader interface with additional members.
  3295. */
  3296. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3297. }
  3298. /** @hidden */
  3299. export interface _IAnimationSamplerData {
  3300. input: Float32Array;
  3301. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3302. output: Float32Array;
  3303. }
  3304. /**
  3305. * Loader interface with additional members.
  3306. */
  3307. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3308. /** @hidden */
  3309. _data?: Promise<_IAnimationSamplerData>;
  3310. }
  3311. /**
  3312. * Loader interface with additional members.
  3313. */
  3314. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3315. channels: IAnimationChannel[];
  3316. samplers: IAnimationSampler[];
  3317. /** @hidden */
  3318. _babylonAnimationGroup?: AnimationGroup;
  3319. }
  3320. /**
  3321. * Loader interface with additional members.
  3322. */
  3323. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3324. /** @hidden */
  3325. _data?: Promise<ArrayBufferView>;
  3326. }
  3327. /**
  3328. * Loader interface with additional members.
  3329. */
  3330. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3331. /** @hidden */
  3332. _data?: Promise<ArrayBufferView>;
  3333. /** @hidden */
  3334. _babylonBuffer?: Promise<Buffer>;
  3335. }
  3336. /**
  3337. * Loader interface with additional members.
  3338. */
  3339. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3340. }
  3341. /**
  3342. * Loader interface with additional members.
  3343. */
  3344. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3345. /** @hidden */
  3346. _data?: Promise<ArrayBufferView>;
  3347. }
  3348. /**
  3349. * Loader interface with additional members.
  3350. */
  3351. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3352. }
  3353. /**
  3354. * Loader interface with additional members.
  3355. */
  3356. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3357. }
  3358. /**
  3359. * Loader interface with additional members.
  3360. */
  3361. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3362. baseColorTexture?: ITextureInfo;
  3363. metallicRoughnessTexture?: ITextureInfo;
  3364. }
  3365. /**
  3366. * Loader interface with additional members.
  3367. */
  3368. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3369. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3370. normalTexture?: IMaterialNormalTextureInfo;
  3371. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3372. emissiveTexture?: ITextureInfo;
  3373. /** @hidden */
  3374. _data?: {
  3375. [babylonDrawMode: number]: {
  3376. babylonMaterial: Material;
  3377. babylonMeshes: AbstractMesh[];
  3378. promise: Promise<void>;
  3379. };
  3380. };
  3381. }
  3382. /**
  3383. * Loader interface with additional members.
  3384. */
  3385. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3386. primitives: IMeshPrimitive[];
  3387. }
  3388. /**
  3389. * Loader interface with additional members.
  3390. */
  3391. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3392. /** @hidden */
  3393. _instanceData?: {
  3394. babylonSourceMesh: Mesh;
  3395. promise: Promise<any>;
  3396. };
  3397. }
  3398. /**
  3399. * Loader interface with additional members.
  3400. */
  3401. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3402. /**
  3403. * The parent glTF node.
  3404. */
  3405. parent?: INode;
  3406. /** @hidden */
  3407. _babylonTransformNode?: TransformNode;
  3408. /** @hidden */
  3409. _primitiveBabylonMeshes?: AbstractMesh[];
  3410. /** @hidden */
  3411. _babylonBones?: Bone[];
  3412. /** @hidden */
  3413. _numMorphTargets?: number;
  3414. }
  3415. /** @hidden */
  3416. export interface _ISamplerData {
  3417. noMipMaps: boolean;
  3418. samplingMode: number;
  3419. wrapU: number;
  3420. wrapV: number;
  3421. }
  3422. /**
  3423. * Loader interface with additional members.
  3424. */
  3425. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3426. /** @hidden */
  3427. _data?: _ISamplerData;
  3428. }
  3429. /**
  3430. * Loader interface with additional members.
  3431. */
  3432. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3433. }
  3434. /**
  3435. * Loader interface with additional members.
  3436. */
  3437. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3438. /** @hidden */
  3439. _data?: {
  3440. babylonSkeleton: Skeleton;
  3441. promise: Promise<void>;
  3442. };
  3443. }
  3444. /**
  3445. * Loader interface with additional members.
  3446. */
  3447. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3448. }
  3449. /**
  3450. * Loader interface with additional members.
  3451. */
  3452. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3453. }
  3454. /**
  3455. * Loader interface with additional members.
  3456. */
  3457. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3458. accessors?: IAccessor[];
  3459. animations?: IAnimation[];
  3460. buffers?: IBuffer[];
  3461. bufferViews?: IBufferView[];
  3462. cameras?: ICamera[];
  3463. images?: IImage[];
  3464. materials?: IMaterial[];
  3465. meshes?: IMesh[];
  3466. nodes?: INode[];
  3467. samplers?: ISampler[];
  3468. scenes?: IScene[];
  3469. skins?: ISkin[];
  3470. textures?: ITexture[];
  3471. }
  3472. }
  3473. declare module BABYLON.GLTF2 {
  3474. /**
  3475. * Interface for a glTF loader extension.
  3476. */
  3477. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3478. /**
  3479. * Called after the loader state changes to LOADING.
  3480. */
  3481. onLoading?(): void;
  3482. /**
  3483. * Called after the loader state changes to READY.
  3484. */
  3485. onReady?(): void;
  3486. /**
  3487. * Define this method to modify the default behavior when loading scenes.
  3488. * @param context The context when loading the asset
  3489. * @param scene The glTF scene property
  3490. * @returns A promise that resolves when the load is complete or null if not handled
  3491. */
  3492. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3493. /**
  3494. * Define this method to modify the default behavior when loading nodes.
  3495. * @param context The context when loading the asset
  3496. * @param node The glTF node property
  3497. * @param assign A function called synchronously after parsing the glTF properties
  3498. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3499. */
  3500. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3501. /**
  3502. * Define this method to modify the default behavior when loading cameras.
  3503. * @param context The context when loading the asset
  3504. * @param camera The glTF camera property
  3505. * @param assign A function called synchronously after parsing the glTF properties
  3506. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3507. */
  3508. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3509. /**
  3510. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3511. * @param context The context when loading the asset
  3512. * @param primitive The glTF mesh primitive property
  3513. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3514. */
  3515. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3516. /**
  3517. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3518. * @param context The context when loading the asset
  3519. * @param name The mesh name when loading the asset
  3520. * @param node The glTF node when loading the asset
  3521. * @param mesh The glTF mesh when loading the asset
  3522. * @param primitive The glTF mesh primitive property
  3523. * @param assign A function called synchronously after parsing the glTF properties
  3524. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3525. */
  3526. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3527. /**
  3528. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3529. * @param context The context when loading the asset
  3530. * @param material The glTF material property
  3531. * @param assign A function called synchronously after parsing the glTF properties
  3532. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3533. */
  3534. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3535. /**
  3536. * Define this method to modify the default behavior when creating materials.
  3537. * @param context The context when loading the asset
  3538. * @param material The glTF material property
  3539. * @param babylonDrawMode The draw mode for the Babylon material
  3540. * @returns The Babylon material or null if not handled
  3541. */
  3542. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3543. /**
  3544. * Define this method to modify the default behavior when loading material properties.
  3545. * @param context The context when loading the asset
  3546. * @param material The glTF material property
  3547. * @param babylonMaterial The Babylon material
  3548. * @returns A promise that resolves when the load is complete or null if not handled
  3549. */
  3550. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3551. /**
  3552. * Define this method to modify the default behavior when loading texture infos.
  3553. * @param context The context when loading the asset
  3554. * @param textureInfo The glTF texture info property
  3555. * @param assign A function called synchronously after parsing the glTF properties
  3556. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3557. */
  3558. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3559. /**
  3560. * Define this method to modify the default behavior when loading animations.
  3561. * @param context The context when loading the asset
  3562. * @param animation The glTF animation property
  3563. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3564. */
  3565. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3566. /**
  3567. * @hidden Define this method to modify the default behavior when loading skins.
  3568. * @param context The context when loading the asset
  3569. * @param node The glTF node property
  3570. * @param skin The glTF skin property
  3571. * @returns A promise that resolves when the load is complete or null if not handled
  3572. */
  3573. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  3574. /**
  3575. * @hidden Define this method to modify the default behavior when loading uris.
  3576. * @param context The context when loading the asset
  3577. * @param property The glTF property associated with the uri
  3578. * @param uri The uri to load
  3579. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3580. */
  3581. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  3582. }
  3583. }
  3584. declare module BABYLON.GLTF2 {
  3585. /**
  3586. * Helper class for working with arrays when loading the glTF asset
  3587. */
  3588. export class ArrayItem {
  3589. /**
  3590. * Gets an item from the given array.
  3591. * @param context The context when loading the asset
  3592. * @param array The array to get the item from
  3593. * @param index The index to the array
  3594. * @returns The array item
  3595. */
  3596. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3597. /**
  3598. * Assign an `index` field to each item of the given array.
  3599. * @param array The array of items
  3600. */
  3601. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3602. }
  3603. /**
  3604. * The glTF 2.0 loader
  3605. */
  3606. export class GLTFLoader implements IGLTFLoader {
  3607. /** @hidden */
  3608. _completePromises: Promise<any>[];
  3609. private _disposed;
  3610. private _parent;
  3611. private _state;
  3612. private _extensions;
  3613. private _rootUrl;
  3614. private _fileName;
  3615. private _uniqueRootUrl;
  3616. private _gltf;
  3617. private _babylonScene;
  3618. private _rootBabylonMesh;
  3619. private _defaultBabylonMaterialData;
  3620. private _progressCallback?;
  3621. private _requests;
  3622. private static readonly _DefaultSampler;
  3623. private static _ExtensionNames;
  3624. private static _ExtensionFactories;
  3625. /**
  3626. * Registers a loader extension.
  3627. * @param name The name of the loader extension.
  3628. * @param factory The factory function that creates the loader extension.
  3629. */
  3630. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3631. /**
  3632. * Unregisters a loader extension.
  3633. * @param name The name of the loader extenion.
  3634. * @returns A boolean indicating whether the extension has been unregistered
  3635. */
  3636. static UnregisterExtension(name: string): boolean;
  3637. /**
  3638. * Gets the loader state.
  3639. */
  3640. readonly state: Nullable<GLTFLoaderState>;
  3641. /**
  3642. * The glTF object parsed from the JSON.
  3643. */
  3644. readonly gltf: IGLTF;
  3645. /**
  3646. * The Babylon scene when loading the asset.
  3647. */
  3648. readonly babylonScene: Scene;
  3649. /**
  3650. * The root Babylon mesh when loading the asset.
  3651. */
  3652. readonly rootBabylonMesh: Mesh;
  3653. /** @hidden */
  3654. constructor(parent: GLTFFileLoader);
  3655. /** @hidden */
  3656. dispose(): void;
  3657. /** @hidden */
  3658. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  3659. meshes: AbstractMesh[];
  3660. particleSystems: IParticleSystem[];
  3661. skeletons: Skeleton[];
  3662. animationGroups: AnimationGroup[];
  3663. }>;
  3664. /** @hidden */
  3665. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3666. private _loadAsync;
  3667. private _loadData;
  3668. private _setupData;
  3669. private _loadExtensions;
  3670. private _checkExtensions;
  3671. private _setState;
  3672. private _createRootNode;
  3673. /**
  3674. * Loads a glTF scene.
  3675. * @param context The context when loading the asset
  3676. * @param scene The glTF scene property
  3677. * @returns A promise that resolves when the load is complete
  3678. */
  3679. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3680. private _forEachPrimitive;
  3681. private _getMeshes;
  3682. private _getSkeletons;
  3683. private _getAnimationGroups;
  3684. private _startAnimations;
  3685. /**
  3686. * Loads a glTF node.
  3687. * @param context The context when loading the asset
  3688. * @param node The glTF node property
  3689. * @param assign A function called synchronously after parsing the glTF properties
  3690. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3691. */
  3692. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3693. private _loadMeshAsync;
  3694. /**
  3695. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3696. * @param context The context when loading the asset
  3697. * @param name The mesh name when loading the asset
  3698. * @param node The glTF node when loading the asset
  3699. * @param mesh The glTF mesh when loading the asset
  3700. * @param primitive The glTF mesh primitive property
  3701. * @param assign A function called synchronously after parsing the glTF properties
  3702. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3703. */
  3704. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3705. private _loadVertexDataAsync;
  3706. private _createMorphTargets;
  3707. private _loadMorphTargetsAsync;
  3708. private _loadMorphTargetVertexDataAsync;
  3709. private static _LoadTransform;
  3710. private _loadSkinAsync;
  3711. private _loadBones;
  3712. private _loadBone;
  3713. private _loadSkinInverseBindMatricesDataAsync;
  3714. private _updateBoneMatrices;
  3715. private _getNodeMatrix;
  3716. /**
  3717. * Loads a glTF camera.
  3718. * @param context The context when loading the asset
  3719. * @param camera The glTF camera property
  3720. * @param assign A function called synchronously after parsing the glTF properties
  3721. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3722. */
  3723. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  3724. private _loadAnimationsAsync;
  3725. /**
  3726. * Loads a glTF animation.
  3727. * @param context The context when loading the asset
  3728. * @param animation The glTF animation property
  3729. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3730. */
  3731. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  3732. /**
  3733. * @hidden Loads a glTF animation channel.
  3734. * @param context The context when loading the asset
  3735. * @param animationContext The context of the animation when loading the asset
  3736. * @param animation The glTF animation property
  3737. * @param channel The glTF animation channel property
  3738. * @param babylonAnimationGroup The babylon animation group property
  3739. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3740. * @returns A void promise when the channel load is complete
  3741. */
  3742. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  3743. private _loadAnimationSamplerAsync;
  3744. private _loadBufferAsync;
  3745. /**
  3746. * Loads a glTF buffer view.
  3747. * @param context The context when loading the asset
  3748. * @param bufferView The glTF buffer view property
  3749. * @returns A promise that resolves with the loaded data when the load is complete
  3750. */
  3751. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  3752. private _loadAccessorAsync;
  3753. private _loadFloatAccessorAsync;
  3754. private _loadIndicesAccessorAsync;
  3755. private _loadVertexBufferViewAsync;
  3756. private _loadVertexAccessorAsync;
  3757. private _loadMaterialMetallicRoughnessPropertiesAsync;
  3758. /** @hidden */
  3759. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  3760. private _createDefaultMaterial;
  3761. /**
  3762. * Creates a Babylon material from a glTF material.
  3763. * @param context The context when loading the asset
  3764. * @param material The glTF material property
  3765. * @param babylonDrawMode The draw mode for the Babylon material
  3766. * @returns The Babylon material
  3767. */
  3768. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  3769. /**
  3770. * Loads properties from a glTF material into a Babylon material.
  3771. * @param context The context when loading the asset
  3772. * @param material The glTF material property
  3773. * @param babylonMaterial The Babylon material
  3774. * @returns A promise that resolves when the load is complete
  3775. */
  3776. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3777. /**
  3778. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3779. * @param context The context when loading the asset
  3780. * @param material The glTF material property
  3781. * @param babylonMaterial The Babylon material
  3782. * @returns A promise that resolves when the load is complete
  3783. */
  3784. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3785. /**
  3786. * Loads the alpha properties from a glTF material into a Babylon material.
  3787. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3788. * @param context The context when loading the asset
  3789. * @param material The glTF material property
  3790. * @param babylonMaterial The Babylon material
  3791. */
  3792. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  3793. /**
  3794. * Loads a glTF texture info.
  3795. * @param context The context when loading the asset
  3796. * @param textureInfo The glTF texture info property
  3797. * @param assign A function called synchronously after parsing the glTF properties
  3798. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3799. */
  3800. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  3801. private _loadTextureAsync;
  3802. private _loadSampler;
  3803. /**
  3804. * Loads a glTF image.
  3805. * @param context The context when loading the asset
  3806. * @param image The glTF image property
  3807. * @returns A promise that resolves with the loaded data when the load is complete
  3808. */
  3809. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  3810. /**
  3811. * Loads a glTF uri.
  3812. * @param context The context when loading the asset
  3813. * @param property The glTF property associated with the uri
  3814. * @param uri The base64 or relative uri
  3815. * @returns A promise that resolves with the loaded data when the load is complete
  3816. */
  3817. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  3818. private _onProgress;
  3819. /**
  3820. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3821. * @param babylonObject the Babylon object with metadata
  3822. * @param pointer the JSON pointer
  3823. */
  3824. static AddPointerMetadata(babylonObject: {
  3825. metadata: any;
  3826. }, pointer: string): void;
  3827. private static _GetTextureWrapMode;
  3828. private static _GetTextureSamplingMode;
  3829. private static _GetTypedArrayConstructor;
  3830. private static _GetTypedArray;
  3831. private static _GetNumComponents;
  3832. private static _ValidateUri;
  3833. private static _GetDrawMode;
  3834. private _compileMaterialsAsync;
  3835. private _compileShadowGeneratorsAsync;
  3836. private _forEachExtensions;
  3837. private _applyExtensions;
  3838. private _extensionsOnLoading;
  3839. private _extensionsOnReady;
  3840. private _extensionsLoadSceneAsync;
  3841. private _extensionsLoadNodeAsync;
  3842. private _extensionsLoadCameraAsync;
  3843. private _extensionsLoadVertexDataAsync;
  3844. private _extensionsLoadMeshPrimitiveAsync;
  3845. private _extensionsLoadMaterialAsync;
  3846. private _extensionsCreateMaterial;
  3847. private _extensionsLoadMaterialPropertiesAsync;
  3848. private _extensionsLoadTextureInfoAsync;
  3849. private _extensionsLoadAnimationAsync;
  3850. private _extensionsLoadSkinAsync;
  3851. private _extensionsLoadUriAsync;
  3852. /**
  3853. * Helper method called by a loader extension to load an glTF extension.
  3854. * @param context The context when loading the asset
  3855. * @param property The glTF property to load the extension from
  3856. * @param extensionName The name of the extension to load
  3857. * @param actionAsync The action to run
  3858. * @returns The promise returned by actionAsync or null if the extension does not exist
  3859. */
  3860. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3861. /**
  3862. * Helper method called by a loader extension to load a glTF extra.
  3863. * @param context The context when loading the asset
  3864. * @param property The glTF property to load the extra from
  3865. * @param extensionName The name of the extension to load
  3866. * @param actionAsync The action to run
  3867. * @returns The promise returned by actionAsync or null if the extra does not exist
  3868. */
  3869. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3870. /**
  3871. * Increments the indentation level and logs a message.
  3872. * @param message The message to log
  3873. */
  3874. logOpen(message: string): void;
  3875. /**
  3876. * Decrements the indentation level.
  3877. */
  3878. logClose(): void;
  3879. /**
  3880. * Logs a message
  3881. * @param message The message to log
  3882. */
  3883. log(message: string): void;
  3884. /**
  3885. * Starts a performance counter.
  3886. * @param counterName The name of the performance counter
  3887. */
  3888. startPerformanceCounter(counterName: string): void;
  3889. /**
  3890. * Ends a performance counter.
  3891. * @param counterName The name of the performance counter
  3892. */
  3893. endPerformanceCounter(counterName: string): void;
  3894. }
  3895. }
  3896. declare module BABYLON.GLTF2.Loader.Extensions {
  3897. /**
  3898. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  3899. */
  3900. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  3901. /** The name of this extension. */
  3902. readonly name: string;
  3903. /** Defines whether this extension is enabled. */
  3904. enabled: boolean;
  3905. private _loader;
  3906. private _lights?;
  3907. /** @hidden */
  3908. constructor(loader: GLTFLoader);
  3909. /** @hidden */
  3910. dispose(): void;
  3911. /** @hidden */
  3912. onLoading(): void;
  3913. /** @hidden */
  3914. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  3915. private _loadLightAsync;
  3916. }
  3917. }
  3918. declare module BABYLON.GLTF2.Loader.Extensions {
  3919. /**
  3920. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  3921. */
  3922. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  3923. /** The name of this extension. */
  3924. readonly name: string;
  3925. /** The draco compression used to decode vertex data or DracoCompression.Default if not defined */
  3926. dracoCompression?: DracoCompression;
  3927. /** Defines whether this extension is enabled. */
  3928. enabled: boolean;
  3929. private _loader;
  3930. /** @hidden */
  3931. constructor(loader: GLTFLoader);
  3932. /** @hidden */
  3933. dispose(): void;
  3934. /** @hidden */
  3935. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3936. }
  3937. }
  3938. declare module BABYLON.GLTF2.Loader.Extensions {
  3939. /**
  3940. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  3941. */
  3942. export class KHR_lights implements IGLTFLoaderExtension {
  3943. /** The name of this extension. */
  3944. readonly name: string;
  3945. /** Defines whether this extension is enabled. */
  3946. enabled: boolean;
  3947. private _loader;
  3948. private _lights?;
  3949. /** @hidden */
  3950. constructor(loader: GLTFLoader);
  3951. /** @hidden */
  3952. dispose(): void;
  3953. /** @hidden */
  3954. onLoading(): void;
  3955. /** @hidden */
  3956. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3957. }
  3958. }
  3959. declare module BABYLON.GLTF2.Loader.Extensions {
  3960. /**
  3961. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  3962. */
  3963. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  3964. /** The name of this extension. */
  3965. readonly name: string;
  3966. /** Defines whether this extension is enabled. */
  3967. enabled: boolean;
  3968. private _loader;
  3969. /** @hidden */
  3970. constructor(loader: GLTFLoader);
  3971. /** @hidden */
  3972. dispose(): void;
  3973. /** @hidden */
  3974. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3975. private _loadSpecularGlossinessPropertiesAsync;
  3976. }
  3977. }
  3978. declare module BABYLON.GLTF2.Loader.Extensions {
  3979. /**
  3980. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  3981. */
  3982. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  3983. /** The name of this extension. */
  3984. readonly name: string;
  3985. /** Defines whether this extension is enabled. */
  3986. enabled: boolean;
  3987. private _loader;
  3988. /** @hidden */
  3989. constructor(loader: GLTFLoader);
  3990. /** @hidden */
  3991. dispose(): void;
  3992. /** @hidden */
  3993. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3994. private _loadUnlitPropertiesAsync;
  3995. }
  3996. }
  3997. declare module BABYLON.GLTF2.Loader.Extensions {
  3998. /**
  3999. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4000. */
  4001. export class KHR_texture_transform implements IGLTFLoaderExtension {
  4002. /** The name of this extension. */
  4003. readonly name: string;
  4004. /** Defines whether this extension is enabled. */
  4005. enabled: boolean;
  4006. private _loader;
  4007. /** @hidden */
  4008. constructor(loader: GLTFLoader);
  4009. /** @hidden */
  4010. dispose(): void;
  4011. /** @hidden */
  4012. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  4013. }
  4014. }
  4015. declare module BABYLON.GLTF2.Loader.Extensions {
  4016. /**
  4017. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4018. */
  4019. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  4020. /** The name of this extension. */
  4021. readonly name: string;
  4022. /** Defines whether this extension is enabled. */
  4023. enabled: boolean;
  4024. private _loader;
  4025. private _clips;
  4026. private _emitters;
  4027. /** @hidden */
  4028. constructor(loader: GLTFLoader);
  4029. /** @hidden */
  4030. dispose(): void;
  4031. /** @hidden */
  4032. onLoading(): void;
  4033. /** @hidden */
  4034. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4035. /** @hidden */
  4036. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4037. /** @hidden */
  4038. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  4039. private _loadClipAsync;
  4040. private _loadEmitterAsync;
  4041. private _getEventAction;
  4042. private _loadAnimationEventAsync;
  4043. }
  4044. }
  4045. declare module BABYLON.GLTF2.Loader.Extensions {
  4046. /**
  4047. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4048. */
  4049. export class MSFT_lod implements IGLTFLoaderExtension {
  4050. /** The name of this extension. */
  4051. readonly name: string;
  4052. /** Defines whether this extension is enabled. */
  4053. enabled: boolean;
  4054. /**
  4055. * Maximum number of LODs to load, starting from the lowest LOD.
  4056. */
  4057. maxLODsToLoad: number;
  4058. /**
  4059. * Observable raised when all node LODs of one level are loaded.
  4060. * The event data is the index of the loaded LOD starting from zero.
  4061. * Dispose the loader to cancel the loading of the next level of LODs.
  4062. */
  4063. onNodeLODsLoadedObservable: Observable<number>;
  4064. /**
  4065. * Observable raised when all material LODs of one level are loaded.
  4066. * The event data is the index of the loaded LOD starting from zero.
  4067. * Dispose the loader to cancel the loading of the next level of LODs.
  4068. */
  4069. onMaterialLODsLoadedObservable: Observable<number>;
  4070. private _loader;
  4071. private _nodeIndexLOD;
  4072. private _nodeSignalLODs;
  4073. private _nodePromiseLODs;
  4074. private _materialIndexLOD;
  4075. private _materialSignalLODs;
  4076. private _materialPromiseLODs;
  4077. /** @hidden */
  4078. constructor(loader: GLTFLoader);
  4079. /** @hidden */
  4080. dispose(): void;
  4081. /** @hidden */
  4082. onReady(): void;
  4083. /** @hidden */
  4084. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4085. /** @hidden */
  4086. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  4087. /** @hidden */
  4088. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  4089. /**
  4090. * Gets an array of LOD properties from lowest to highest.
  4091. */
  4092. private _getLODs;
  4093. private _disposeUnusedMaterials;
  4094. }
  4095. }
  4096. declare module BABYLON.GLTF2.Loader.Extensions {
  4097. /** @hidden */
  4098. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  4099. readonly name: string;
  4100. enabled: boolean;
  4101. private _loader;
  4102. constructor(loader: GLTFLoader);
  4103. dispose(): void;
  4104. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4105. }
  4106. }
  4107. declare module BABYLON.GLTF2.Loader.Extensions {
  4108. /** @hidden */
  4109. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  4110. readonly name: string;
  4111. enabled: boolean;
  4112. private _loader;
  4113. constructor(loader: GLTFLoader);
  4114. dispose(): void;
  4115. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4116. }
  4117. }
  4118. declare module BABYLON.GLTF2.Loader.Extensions {
  4119. /**
  4120. * Store glTF extras (if present) in BJS objects' metadata
  4121. */
  4122. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  4123. /** The name of this extension. */
  4124. readonly name: string;
  4125. /** Defines whether this extension is enabled. */
  4126. enabled: boolean;
  4127. private _loader;
  4128. private _assignExtras;
  4129. /** @hidden */
  4130. constructor(loader: GLTFLoader);
  4131. /** @hidden */
  4132. dispose(): void;
  4133. /** @hidden */
  4134. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4135. /** @hidden */
  4136. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  4137. /** @hidden */
  4138. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  4139. }
  4140. }
  4141. declare module BABYLON {
  4142. /**
  4143. * Class reading and parsing the MTL file bundled with the obj file.
  4144. */
  4145. export class MTLFileLoader {
  4146. /**
  4147. * All material loaded from the mtl will be set here
  4148. */
  4149. materials: StandardMaterial[];
  4150. /**
  4151. * This function will read the mtl file and create each material described inside
  4152. * This function could be improve by adding :
  4153. * -some component missing (Ni, Tf...)
  4154. * -including the specific options available
  4155. *
  4156. * @param scene defines the scene the material will be created in
  4157. * @param data defines the mtl data to parse
  4158. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  4159. */
  4160. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  4161. /**
  4162. * Gets the texture for the material.
  4163. *
  4164. * If the material is imported from input file,
  4165. * We sanitize the url to ensure it takes the textre from aside the material.
  4166. *
  4167. * @param rootUrl The root url to load from
  4168. * @param value The value stored in the mtl
  4169. * @return The Texture
  4170. */
  4171. private static _getTexture;
  4172. }
  4173. /**
  4174. * Options for loading OBJ/MTL files
  4175. */
  4176. type MeshLoadOptions = {
  4177. /**
  4178. * Defines if UVs are optimized by default during load.
  4179. */
  4180. OptimizeWithUV: boolean;
  4181. /**
  4182. * Defines custom scaling of UV coordinates of loaded meshes.
  4183. */
  4184. UVScaling: Vector2;
  4185. /**
  4186. * Invert model on y-axis (does a model scaling inversion)
  4187. */
  4188. InvertY: boolean;
  4189. /**
  4190. * Invert Y-Axis of referenced textures on load
  4191. */
  4192. InvertTextureY: boolean;
  4193. /**
  4194. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4195. */
  4196. ImportVertexColors: boolean;
  4197. /**
  4198. * Compute the normals for the model, even if normals are present in the file.
  4199. */
  4200. ComputeNormals: boolean;
  4201. /**
  4202. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4203. */
  4204. SkipMaterials: boolean;
  4205. /**
  4206. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4207. */
  4208. MaterialLoadingFailsSilently: boolean;
  4209. };
  4210. /**
  4211. * OBJ file type loader.
  4212. * This is a babylon scene loader plugin.
  4213. */
  4214. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  4215. /**
  4216. * Defines if UVs are optimized by default during load.
  4217. */
  4218. static OPTIMIZE_WITH_UV: boolean;
  4219. /**
  4220. * Invert model on y-axis (does a model scaling inversion)
  4221. */
  4222. static INVERT_Y: boolean;
  4223. /**
  4224. * Invert Y-Axis of referenced textures on load
  4225. */
  4226. static INVERT_TEXTURE_Y: boolean;
  4227. /**
  4228. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4229. */
  4230. static IMPORT_VERTEX_COLORS: boolean;
  4231. /**
  4232. * Compute the normals for the model, even if normals are present in the file.
  4233. */
  4234. static COMPUTE_NORMALS: boolean;
  4235. /**
  4236. * Defines custom scaling of UV coordinates of loaded meshes.
  4237. */
  4238. static UV_SCALING: Vector2;
  4239. /**
  4240. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4241. */
  4242. static SKIP_MATERIALS: boolean;
  4243. /**
  4244. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4245. *
  4246. * Defaults to true for backwards compatibility.
  4247. */
  4248. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  4249. /**
  4250. * Defines the name of the plugin.
  4251. */
  4252. name: string;
  4253. /**
  4254. * Defines the extension the plugin is able to load.
  4255. */
  4256. extensions: string;
  4257. /** @hidden */
  4258. obj: RegExp;
  4259. /** @hidden */
  4260. group: RegExp;
  4261. /** @hidden */
  4262. mtllib: RegExp;
  4263. /** @hidden */
  4264. usemtl: RegExp;
  4265. /** @hidden */
  4266. smooth: RegExp;
  4267. /** @hidden */
  4268. vertexPattern: RegExp;
  4269. /** @hidden */
  4270. normalPattern: RegExp;
  4271. /** @hidden */
  4272. uvPattern: RegExp;
  4273. /** @hidden */
  4274. facePattern1: RegExp;
  4275. /** @hidden */
  4276. facePattern2: RegExp;
  4277. /** @hidden */
  4278. facePattern3: RegExp;
  4279. /** @hidden */
  4280. facePattern4: RegExp;
  4281. /** @hidden */
  4282. facePattern5: RegExp;
  4283. private _meshLoadOptions;
  4284. /**
  4285. * Creates loader for .OBJ files
  4286. *
  4287. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  4288. */
  4289. constructor(meshLoadOptions?: MeshLoadOptions);
  4290. private static readonly currentMeshLoadOptions;
  4291. /**
  4292. * Calls synchronously the MTL file attached to this obj.
  4293. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  4294. * Without this function materials are not displayed in the first frame (but displayed after).
  4295. * In consequence it is impossible to get material information in your HTML file
  4296. *
  4297. * @param url The URL of the MTL file
  4298. * @param rootUrl
  4299. * @param onSuccess Callback function to be called when the MTL file is loaded
  4300. * @private
  4301. */
  4302. private _loadMTL;
  4303. /**
  4304. * Instantiates a OBJ file loader plugin.
  4305. * @returns the created plugin
  4306. */
  4307. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  4308. /**
  4309. * If the data string can be loaded directly.
  4310. *
  4311. * @param data string containing the file data
  4312. * @returns if the data can be loaded directly
  4313. */
  4314. canDirectLoad(data: string): boolean;
  4315. /**
  4316. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  4317. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  4318. * @param scene the scene the meshes should be added to
  4319. * @param data the OBJ data to load
  4320. * @param rootUrl root url to load from
  4321. * @param onProgress event that fires when loading progress has occured
  4322. * @param fileName Defines the name of the file to load
  4323. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4324. */
  4325. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4326. meshes: AbstractMesh[];
  4327. particleSystems: IParticleSystem[];
  4328. skeletons: Skeleton[];
  4329. animationGroups: AnimationGroup[];
  4330. }>;
  4331. /**
  4332. * Imports all objects from the loaded OBJ data and adds them to the scene
  4333. * @param scene the scene the objects should be added to
  4334. * @param data the OBJ data to load
  4335. * @param rootUrl root url to load from
  4336. * @param onProgress event that fires when loading progress has occured
  4337. * @param fileName Defines the name of the file to load
  4338. * @returns a promise which completes when objects have been loaded to the scene
  4339. */
  4340. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4341. /**
  4342. * Load into an asset container.
  4343. * @param scene The scene to load into
  4344. * @param data The data to import
  4345. * @param rootUrl The root url for scene and resources
  4346. * @param onProgress The callback when the load progresses
  4347. * @param fileName Defines the name of the file to load
  4348. * @returns The loaded asset container
  4349. */
  4350. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4351. /**
  4352. * Read the OBJ file and create an Array of meshes.
  4353. * Each mesh contains all information given by the OBJ and the MTL file.
  4354. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4355. *
  4356. * @param meshesNames
  4357. * @param scene Scene The scene where are displayed the data
  4358. * @param data String The content of the obj file
  4359. * @param rootUrl String The path to the folder
  4360. * @returns Array<AbstractMesh>
  4361. * @private
  4362. */
  4363. private _parseSolid;
  4364. }
  4365. }
  4366. declare module BABYLON {
  4367. /**
  4368. * STL file type loader.
  4369. * This is a babylon scene loader plugin.
  4370. */
  4371. export class STLFileLoader implements ISceneLoaderPlugin {
  4372. /** @hidden */
  4373. solidPattern: RegExp;
  4374. /** @hidden */
  4375. facetsPattern: RegExp;
  4376. /** @hidden */
  4377. normalPattern: RegExp;
  4378. /** @hidden */
  4379. vertexPattern: RegExp;
  4380. /**
  4381. * Defines the name of the plugin.
  4382. */
  4383. name: string;
  4384. /**
  4385. * Defines the extensions the stl loader is able to load.
  4386. * force data to come in as an ArrayBuffer
  4387. * we'll convert to string if it looks like it's an ASCII .stl
  4388. */
  4389. extensions: ISceneLoaderPluginExtensions;
  4390. /**
  4391. * Import meshes into a scene.
  4392. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4393. * @param scene The scene to import into
  4394. * @param data The data to import
  4395. * @param rootUrl The root url for scene and resources
  4396. * @param meshes The meshes array to import into
  4397. * @param particleSystems The particle systems array to import into
  4398. * @param skeletons The skeletons array to import into
  4399. * @param onError The callback when import fails
  4400. * @returns True if successful or false otherwise
  4401. */
  4402. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4403. /**
  4404. * Load into a scene.
  4405. * @param scene The scene to load into
  4406. * @param data The data to import
  4407. * @param rootUrl The root url for scene and resources
  4408. * @param onError The callback when import fails
  4409. * @returns true if successful or false otherwise
  4410. */
  4411. load(scene: Scene, data: any, rootUrl: string): boolean;
  4412. /**
  4413. * Load into an asset container.
  4414. * @param scene The scene to load into
  4415. * @param data The data to import
  4416. * @param rootUrl The root url for scene and resources
  4417. * @param onError The callback when import fails
  4418. * @returns The loaded asset container
  4419. */
  4420. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4421. private _isBinary;
  4422. private _parseBinary;
  4423. private _parseASCII;
  4424. }
  4425. }