babylonjs.loaders.module.d.ts 197 KB

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