babylon.glTF2FileLoader.js 290 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTF2FileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/webpack/buildin/global.js":
  99. /*!***********************************!*\
  100. !*** (webpack)/buildin/global.js ***!
  101. \***********************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || new Function("return this")();
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  122. /*!*******************************************************!*\
  123. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  124. \*******************************************************/
  125. /*! exports provided: EXT_lights_image_based */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  130. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/observable");
  131. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  133. var NAME = "EXT_lights_image_based";
  134. /**
  135. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  136. */
  137. var EXT_lights_image_based = /** @class */ (function () {
  138. /** @hidden */
  139. function EXT_lights_image_based(loader) {
  140. /**
  141. * The name of this extension.
  142. */
  143. this.name = NAME;
  144. this._loader = loader;
  145. this.enabled = this._loader.isExtensionUsed(NAME);
  146. }
  147. /** @hidden */
  148. EXT_lights_image_based.prototype.dispose = function () {
  149. delete this._loader;
  150. delete this._lights;
  151. };
  152. /** @hidden */
  153. EXT_lights_image_based.prototype.onLoading = function () {
  154. var extensions = this._loader.gltf.extensions;
  155. if (extensions && extensions[this.name]) {
  156. var extension = extensions[this.name];
  157. this._lights = extension.lights;
  158. }
  159. };
  160. /** @hidden */
  161. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  162. var _this = this;
  163. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  164. var promises = new Array();
  165. promises.push(_this._loader.loadSceneAsync(context, scene));
  166. _this._loader.logOpen("" + extensionContext);
  167. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  168. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  169. _this._loader.babylonScene.environmentTexture = texture;
  170. }));
  171. _this._loader.logClose();
  172. return Promise.all(promises).then(function () { });
  173. });
  174. };
  175. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  176. var _this = this;
  177. if (!light._loaded) {
  178. var promises = new Array();
  179. this._loader.logOpen("" + context);
  180. var imageData_1 = new Array(light.specularImages.length);
  181. var _loop_1 = function (mipmap) {
  182. var faces = light.specularImages[mipmap];
  183. imageData_1[mipmap] = new Array(faces.length);
  184. var _loop_2 = function (face) {
  185. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  186. this_1._loader.logOpen("" + specularImageContext);
  187. var index = faces[face];
  188. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  189. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  190. imageData_1[mipmap][face] = data;
  191. }));
  192. this_1._loader.logClose();
  193. };
  194. for (var face = 0; face < faces.length; face++) {
  195. _loop_2(face);
  196. }
  197. };
  198. var this_1 = this;
  199. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  200. _loop_1(mipmap);
  201. }
  202. this._loader.logClose();
  203. light._loaded = Promise.all(promises).then(function () {
  204. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  205. babylonTexture.name = light.name || "environment";
  206. light._babylonTexture = babylonTexture;
  207. if (light.intensity != undefined) {
  208. babylonTexture.level = light.intensity;
  209. }
  210. if (light.rotation) {
  211. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  212. // Invert the rotation so that positive rotation is counter-clockwise.
  213. if (!_this._loader.babylonScene.useRightHandedSystem) {
  214. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  215. }
  216. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  217. }
  218. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  219. sphericalHarmonics.scaleInPlace(light.intensity);
  220. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  221. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  222. // Compute the lod generation scale to fit exactly to the number of levels available.
  223. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  224. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  225. });
  226. }
  227. return light._loaded.then(function () {
  228. return light._babylonTexture;
  229. });
  230. };
  231. return EXT_lights_image_based;
  232. }());
  233. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  234. /***/ }),
  235. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  236. /*!********************************************************!*\
  237. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  238. \********************************************************/
  239. /*! exports provided: EXT_mesh_gpu_instancing */
  240. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  241. "use strict";
  242. __webpack_require__.r(__webpack_exports__);
  243. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  244. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  245. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  246. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  247. var NAME = "EXT_mesh_gpu_instancing";
  248. /**
  249. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  250. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  251. * !!! Experimental Extension Subject to Changes !!!
  252. */
  253. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  254. /** @hidden */
  255. function EXT_mesh_gpu_instancing(loader) {
  256. /**
  257. * The name of this extension.
  258. */
  259. this.name = NAME;
  260. this._loader = loader;
  261. this.enabled = this._loader.isExtensionUsed(NAME);
  262. }
  263. /** @hidden */
  264. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  265. delete this._loader;
  266. };
  267. /** @hidden */
  268. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  269. var _this = this;
  270. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  271. _this._loader._disableInstancedMesh++;
  272. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  273. _this._loader._disableInstancedMesh--;
  274. if (!node._primitiveBabylonMeshes) {
  275. return promise;
  276. }
  277. var promises = new Array();
  278. var instanceCount = 0;
  279. var loadAttribute = function (attribute) {
  280. if (extension.attributes[attribute] == undefined) {
  281. promises.push(Promise.resolve(null));
  282. return;
  283. }
  284. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  285. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  286. if (instanceCount === 0) {
  287. instanceCount = accessor.count;
  288. }
  289. else if (instanceCount !== accessor.count) {
  290. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  291. }
  292. };
  293. loadAttribute("TRANSLATION");
  294. loadAttribute("ROTATION");
  295. loadAttribute("SCALE");
  296. return promise.then(function (babylonTransformNode) {
  297. return Promise.all(promises).then(function (_a) {
  298. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  299. var matrices = new Float32Array(instanceCount * 16);
  300. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  301. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  302. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  303. for (var i = 0; i < instanceCount; ++i) {
  304. translationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0]);
  305. rotationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0]);
  306. scaleBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1]);
  307. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0]);
  308. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  309. }
  310. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  311. var babylonMesh = _b[_i];
  312. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  313. }
  314. return babylonTransformNode;
  315. });
  316. });
  317. });
  318. };
  319. return EXT_mesh_gpu_instancing;
  320. }());
  321. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  322. /***/ }),
  323. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  324. /*!*************************************************!*\
  325. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  326. \*************************************************/
  327. /*! exports provided: ExtrasAsMetadata */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  332. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  333. var NAME = "ExtrasAsMetadata";
  334. /**
  335. * Store glTF extras (if present) in BJS objects' metadata
  336. */
  337. var ExtrasAsMetadata = /** @class */ (function () {
  338. /** @hidden */
  339. function ExtrasAsMetadata(loader) {
  340. /**
  341. * The name of this extension.
  342. */
  343. this.name = NAME;
  344. /**
  345. * Defines whether this extension is enabled.
  346. */
  347. this.enabled = true;
  348. this._loader = loader;
  349. }
  350. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  351. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  352. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  353. var gltf = (metadata.gltf = metadata.gltf || {});
  354. gltf.extras = gltfProp.extras;
  355. }
  356. };
  357. /** @hidden */
  358. ExtrasAsMetadata.prototype.dispose = function () {
  359. delete this._loader;
  360. };
  361. /** @hidden */
  362. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  363. var _this = this;
  364. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  365. _this._assignExtras(babylonTransformNode, node);
  366. assign(babylonTransformNode);
  367. });
  368. };
  369. /** @hidden */
  370. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  371. var _this = this;
  372. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  373. _this._assignExtras(babylonCamera, camera);
  374. assign(babylonCamera);
  375. });
  376. };
  377. /** @hidden */
  378. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  379. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  380. this._assignExtras(babylonMaterial, material);
  381. return babylonMaterial;
  382. };
  383. return ExtrasAsMetadata;
  384. }());
  385. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  386. /***/ }),
  387. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  388. /*!***********************************************************!*\
  389. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  390. \***********************************************************/
  391. /*! exports provided: KHR_draco_mesh_compression */
  392. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  393. "use strict";
  394. __webpack_require__.r(__webpack_exports__);
  395. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  396. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/observable");
  397. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  398. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  399. var NAME = "KHR_draco_mesh_compression";
  400. /**
  401. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  402. */
  403. var KHR_draco_mesh_compression = /** @class */ (function () {
  404. /** @hidden */
  405. function KHR_draco_mesh_compression(loader) {
  406. /**
  407. * The name of this extension.
  408. */
  409. this.name = NAME;
  410. this._loader = loader;
  411. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  412. }
  413. /** @hidden */
  414. KHR_draco_mesh_compression.prototype.dispose = function () {
  415. delete this.dracoCompression;
  416. delete this._loader;
  417. };
  418. /** @hidden */
  419. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  420. var _this = this;
  421. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  422. if (primitive.mode != undefined) {
  423. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  424. primitive.mode !== 4 /* TRIANGLES */) {
  425. throw new Error(context + ": Unsupported mode " + primitive.mode);
  426. }
  427. // TODO: handle triangle strips
  428. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  429. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  430. }
  431. }
  432. var attributes = {};
  433. var loadAttribute = function (name, kind) {
  434. var uniqueId = extension.attributes[name];
  435. if (uniqueId == undefined) {
  436. return;
  437. }
  438. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  439. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  440. babylonMesh._delayInfo.push(kind);
  441. }
  442. attributes[kind] = uniqueId;
  443. };
  444. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  445. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  446. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  447. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  448. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  449. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  450. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  451. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  452. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  453. if (!bufferView._dracoBabylonGeometry) {
  454. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  455. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  456. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  457. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  458. babylonVertexData.applyToGeometry(babylonGeometry);
  459. return babylonGeometry;
  460. }).catch(function (error) {
  461. throw new Error(context + ": " + error.message);
  462. });
  463. });
  464. }
  465. return bufferView._dracoBabylonGeometry;
  466. });
  467. };
  468. return KHR_draco_mesh_compression;
  469. }());
  470. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  471. /***/ }),
  472. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  473. /*!****************************************************!*\
  474. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  475. \****************************************************/
  476. /*! exports provided: KHR_lights */
  477. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  478. "use strict";
  479. __webpack_require__.r(__webpack_exports__);
  480. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  481. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  482. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  483. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  484. var NAME = "KHR_lights_punctual";
  485. var LightType;
  486. (function (LightType) {
  487. LightType["DIRECTIONAL"] = "directional";
  488. LightType["POINT"] = "point";
  489. LightType["SPOT"] = "spot";
  490. })(LightType || (LightType = {}));
  491. /**
  492. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  493. */
  494. var KHR_lights = /** @class */ (function () {
  495. /** @hidden */
  496. function KHR_lights(loader) {
  497. /**
  498. * The name of this extension.
  499. */
  500. this.name = NAME;
  501. this._loader = loader;
  502. this.enabled = this._loader.isExtensionUsed(NAME);
  503. }
  504. /** @hidden */
  505. KHR_lights.prototype.dispose = function () {
  506. delete this._loader;
  507. delete this._lights;
  508. };
  509. /** @hidden */
  510. KHR_lights.prototype.onLoading = function () {
  511. var extensions = this._loader.gltf.extensions;
  512. if (extensions && extensions[this.name]) {
  513. var extension = extensions[this.name];
  514. this._lights = extension.lights;
  515. }
  516. };
  517. /** @hidden */
  518. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  519. var _this = this;
  520. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  521. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  522. var babylonLight;
  523. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  524. var name = light.name || babylonMesh.name;
  525. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  526. switch (light.type) {
  527. case LightType.DIRECTIONAL: {
  528. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  529. break;
  530. }
  531. case LightType.POINT: {
  532. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  533. break;
  534. }
  535. case LightType.SPOT: {
  536. var babylonSpotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  537. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  538. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  539. babylonLight = babylonSpotLight;
  540. break;
  541. }
  542. default: {
  543. _this._loader.babylonScene._blockEntityCollection = false;
  544. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  545. }
  546. }
  547. _this._loader.babylonScene._blockEntityCollection = false;
  548. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  549. babylonLight.diffuse = light.color ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  550. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  551. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  552. babylonLight.parent = babylonMesh;
  553. _this._loader._babylonLights.push(babylonLight);
  554. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  555. assign(babylonMesh);
  556. });
  557. });
  558. };
  559. return KHR_lights;
  560. }());
  561. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  562. /***/ }),
  563. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  564. /*!********************************************************!*\
  565. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  566. \********************************************************/
  567. /*! exports provided: KHR_materials_clearcoat */
  568. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  569. "use strict";
  570. __webpack_require__.r(__webpack_exports__);
  571. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  572. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  573. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  574. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  575. var NAME = "KHR_materials_clearcoat";
  576. /**
  577. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  578. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  579. * !!! Experimental Extension Subject to Changes !!!
  580. */
  581. var KHR_materials_clearcoat = /** @class */ (function () {
  582. /** @hidden */
  583. function KHR_materials_clearcoat(loader) {
  584. /**
  585. * The name of this extension.
  586. */
  587. this.name = NAME;
  588. /**
  589. * Defines a number that determines the order the extensions are applied.
  590. */
  591. this.order = 190;
  592. this._loader = loader;
  593. this.enabled = this._loader.isExtensionUsed(NAME);
  594. }
  595. /** @hidden */
  596. KHR_materials_clearcoat.prototype.dispose = function () {
  597. delete this._loader;
  598. };
  599. /** @hidden */
  600. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  601. var _this = this;
  602. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  603. var promises = new Array();
  604. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  605. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  606. return Promise.all(promises).then(function () { });
  607. });
  608. };
  609. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  610. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  611. throw new Error(context + ": Material type not supported");
  612. }
  613. var promises = new Array();
  614. babylonMaterial.clearCoat.isEnabled = true;
  615. if (properties.clearcoatFactor != undefined) {
  616. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  617. }
  618. else {
  619. babylonMaterial.clearCoat.intensity = 0;
  620. }
  621. if (properties.clearcoatTexture) {
  622. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  623. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  624. babylonMaterial.clearCoat.texture = texture;
  625. }));
  626. }
  627. if (properties.clearcoatRoughnessFactor != undefined) {
  628. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  629. }
  630. else {
  631. babylonMaterial.clearCoat.roughness = 0;
  632. }
  633. if (properties.clearcoatRoughnessTexture) {
  634. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  635. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  636. babylonMaterial.clearCoat.texture = texture;
  637. }));
  638. }
  639. if (properties.clearcoatNormalTexture) {
  640. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  641. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  642. babylonMaterial.clearCoat.bumpTexture = texture;
  643. }));
  644. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  645. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  646. if (properties.clearcoatNormalTexture.scale != undefined) {
  647. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  648. }
  649. }
  650. return Promise.all(promises).then(function () { });
  651. };
  652. return KHR_materials_clearcoat;
  653. }());
  654. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  655. /***/ }),
  656. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  657. /*!**************************************************!*\
  658. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  659. \**************************************************/
  660. /*! exports provided: KHR_materials_ior */
  661. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  662. "use strict";
  663. __webpack_require__.r(__webpack_exports__);
  664. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  665. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  666. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  667. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  668. var NAME = "KHR_materials_ior";
  669. /**
  670. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  671. * !!! Experimental Extension Subject to Changes !!!
  672. */
  673. var KHR_materials_ior = /** @class */ (function () {
  674. /** @hidden */
  675. function KHR_materials_ior(loader) {
  676. /**
  677. * The name of this extension.
  678. */
  679. this.name = NAME;
  680. /**
  681. * Defines a number that determines the order the extensions are applied.
  682. */
  683. this.order = 180;
  684. this._loader = loader;
  685. this.enabled = this._loader.isExtensionUsed(NAME);
  686. }
  687. /** @hidden */
  688. KHR_materials_ior.prototype.dispose = function () {
  689. delete this._loader;
  690. };
  691. /** @hidden */
  692. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  693. var _this = this;
  694. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  695. var promises = new Array();
  696. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  697. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  698. return Promise.all(promises).then(function () { });
  699. });
  700. };
  701. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  702. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  703. throw new Error(context + ": Material type not supported");
  704. }
  705. if (properties.ior !== undefined) {
  706. babylonMaterial.indexOfRefraction = properties.ior;
  707. }
  708. else {
  709. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  710. }
  711. return Promise.resolve();
  712. };
  713. /**
  714. * Default ior Value from the spec.
  715. */
  716. KHR_materials_ior._DEFAULT_IOR = 1.5;
  717. return KHR_materials_ior;
  718. }());
  719. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  720. /***/ }),
  721. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  722. /*!********************************************************************!*\
  723. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  724. \********************************************************************/
  725. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  726. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  727. "use strict";
  728. __webpack_require__.r(__webpack_exports__);
  729. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  730. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  731. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  732. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  733. var NAME = "KHR_materials_pbrSpecularGlossiness";
  734. /**
  735. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  736. */
  737. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  738. /** @hidden */
  739. function KHR_materials_pbrSpecularGlossiness(loader) {
  740. /**
  741. * The name of this extension.
  742. */
  743. this.name = NAME;
  744. /**
  745. * Defines a number that determines the order the extensions are applied.
  746. */
  747. this.order = 200;
  748. this._loader = loader;
  749. this.enabled = this._loader.isExtensionUsed(NAME);
  750. }
  751. /** @hidden */
  752. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  753. delete this._loader;
  754. };
  755. /** @hidden */
  756. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  757. var _this = this;
  758. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  759. var promises = new Array();
  760. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  761. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  762. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  763. return Promise.all(promises).then(function () { });
  764. });
  765. };
  766. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  767. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  768. throw new Error(context + ": Material type not supported");
  769. }
  770. var promises = new Array();
  771. babylonMaterial.metallic = null;
  772. babylonMaterial.roughness = null;
  773. if (properties.diffuseFactor) {
  774. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  775. babylonMaterial.alpha = properties.diffuseFactor[3];
  776. }
  777. else {
  778. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  779. }
  780. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  781. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  782. if (properties.diffuseTexture) {
  783. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  784. texture.name = babylonMaterial.name + " (Diffuse)";
  785. babylonMaterial.albedoTexture = texture;
  786. }));
  787. }
  788. if (properties.specularGlossinessTexture) {
  789. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  790. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  791. babylonMaterial.reflectivityTexture = texture;
  792. }));
  793. babylonMaterial.reflectivityTexture.hasAlpha = true;
  794. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  795. }
  796. return Promise.all(promises).then(function () { });
  797. };
  798. return KHR_materials_pbrSpecularGlossiness;
  799. }());
  800. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  801. /***/ }),
  802. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  803. /*!****************************************************!*\
  804. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  805. \****************************************************/
  806. /*! exports provided: KHR_materials_sheen */
  807. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  808. "use strict";
  809. __webpack_require__.r(__webpack_exports__);
  810. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  811. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  812. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  813. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  814. var NAME = "KHR_materials_sheen";
  815. /**
  816. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  817. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  818. * !!! Experimental Extension Subject to Changes !!!
  819. */
  820. var KHR_materials_sheen = /** @class */ (function () {
  821. /** @hidden */
  822. function KHR_materials_sheen(loader) {
  823. /**
  824. * The name of this extension.
  825. */
  826. this.name = NAME;
  827. /**
  828. * Defines a number that determines the order the extensions are applied.
  829. */
  830. this.order = 190;
  831. this._loader = loader;
  832. this.enabled = this._loader.isExtensionUsed(NAME);
  833. }
  834. /** @hidden */
  835. KHR_materials_sheen.prototype.dispose = function () {
  836. delete this._loader;
  837. };
  838. /** @hidden */
  839. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  840. var _this = this;
  841. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  842. var promises = new Array();
  843. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  844. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  845. return Promise.all(promises).then(function () { });
  846. });
  847. };
  848. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  849. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  850. throw new Error(context + ": Material type not supported");
  851. }
  852. var promises = new Array();
  853. babylonMaterial.sheen.isEnabled = true;
  854. babylonMaterial.sheen.intensity = 1;
  855. if (properties.sheenColorFactor != undefined) {
  856. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.sheenColorFactor);
  857. }
  858. else {
  859. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  860. }
  861. if (properties.sheenTexture) {
  862. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.sheenTexture, function (texture) {
  863. texture.name = babylonMaterial.name + " (Sheen Color)";
  864. babylonMaterial.sheen.texture = texture;
  865. }));
  866. }
  867. if (properties.sheenRoughnessFactor !== undefined) {
  868. babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;
  869. }
  870. else {
  871. babylonMaterial.sheen.roughness = 0;
  872. }
  873. babylonMaterial.sheen.albedoScaling = true;
  874. return Promise.all(promises).then(function () { });
  875. };
  876. return KHR_materials_sheen;
  877. }());
  878. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  879. /***/ }),
  880. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  881. /*!*******************************************************!*\
  882. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  883. \*******************************************************/
  884. /*! exports provided: KHR_materials_specular */
  885. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  886. "use strict";
  887. __webpack_require__.r(__webpack_exports__);
  888. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  889. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  890. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  891. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  892. var NAME = "KHR_materials_specular";
  893. /**
  894. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  895. * !!! Experimental Extension Subject to Changes !!!
  896. */
  897. var KHR_materials_specular = /** @class */ (function () {
  898. /** @hidden */
  899. function KHR_materials_specular(loader) {
  900. /**
  901. * The name of this extension.
  902. */
  903. this.name = NAME;
  904. /**
  905. * Defines a number that determines the order the extensions are applied.
  906. */
  907. this.order = 190;
  908. this._loader = loader;
  909. this.enabled = this._loader.isExtensionUsed(NAME);
  910. }
  911. /** @hidden */
  912. KHR_materials_specular.prototype.dispose = function () {
  913. delete this._loader;
  914. };
  915. /** @hidden */
  916. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  917. var _this = this;
  918. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  919. var promises = new Array();
  920. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  921. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  922. return Promise.all(promises).then(function () { });
  923. });
  924. };
  925. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  926. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  927. throw new Error(context + ": Material type not supported");
  928. }
  929. var promises = new Array();
  930. if (properties.specularFactor !== undefined) {
  931. babylonMaterial.metallicF0Factor = properties.specularFactor;
  932. }
  933. if (properties.specularColorFactor !== undefined) {
  934. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  935. }
  936. if (properties.specularTexture) {
  937. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  938. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  939. babylonMaterial.metallicReflectanceTexture = texture;
  940. }));
  941. }
  942. return Promise.all(promises).then(function () { });
  943. };
  944. return KHR_materials_specular;
  945. }());
  946. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  947. /***/ }),
  948. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  949. /*!***********************************************************!*\
  950. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  951. \***********************************************************/
  952. /*! exports provided: KHR_materials_transmission */
  953. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  954. "use strict";
  955. __webpack_require__.r(__webpack_exports__);
  956. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  957. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  958. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  959. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  960. var NAME = "KHR_materials_transmission";
  961. /**
  962. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  963. * !!! Experimental Extension Subject to Changes !!!
  964. */
  965. var KHR_materials_transmission = /** @class */ (function () {
  966. /** @hidden */
  967. function KHR_materials_transmission(loader) {
  968. /**
  969. * The name of this extension.
  970. */
  971. this.name = NAME;
  972. /**
  973. * Defines a number that determines the order the extensions are applied.
  974. */
  975. this.order = 175;
  976. this._loader = loader;
  977. this.enabled = this._loader.isExtensionUsed(NAME);
  978. if (this.enabled) {
  979. loader._parent.transparencyAsCoverage = true;
  980. }
  981. }
  982. /** @hidden */
  983. KHR_materials_transmission.prototype.dispose = function () {
  984. delete this._loader;
  985. };
  986. /** @hidden */
  987. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  988. var _this = this;
  989. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  990. console.log(extensionContext);
  991. var promises = new Array();
  992. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  993. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  994. promises.push(_this._loadTransparentPropertiesAsync(context, material, babylonMaterial, extension));
  995. return Promise.all(promises).then(function () { });
  996. });
  997. };
  998. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  999. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1000. throw new Error(context + ": Material type not supported");
  1001. }
  1002. var pbrMaterial = babylonMaterial;
  1003. // Enables "refraction" texture which represents transmitted light.
  1004. pbrMaterial.subSurface.isRefractionEnabled = true;
  1005. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  1006. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  1007. // Albedo colour will tint transmission.
  1008. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  1009. if (extension.transmissionFactor !== undefined) {
  1010. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  1011. }
  1012. else {
  1013. pbrMaterial.subSurface.refractionIntensity = 0.0;
  1014. pbrMaterial.subSurface.isRefractionEnabled = false;
  1015. return Promise.resolve();
  1016. }
  1017. if (extension.transmissionTexture) {
  1018. return this._loader.loadTextureInfoAsync(context, extension.transmissionTexture)
  1019. .then(function (texture) {
  1020. pbrMaterial.subSurface.thicknessTexture = texture;
  1021. pbrMaterial.subSurface.useMaskFromThicknessTexture = true;
  1022. });
  1023. }
  1024. else {
  1025. return Promise.resolve();
  1026. }
  1027. };
  1028. return KHR_materials_transmission;
  1029. }());
  1030. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  1031. /***/ }),
  1032. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  1033. /*!****************************************************!*\
  1034. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  1035. \****************************************************/
  1036. /*! exports provided: KHR_materials_unlit */
  1037. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1038. "use strict";
  1039. __webpack_require__.r(__webpack_exports__);
  1040. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  1041. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  1042. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  1043. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1044. var NAME = "KHR_materials_unlit";
  1045. /**
  1046. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1047. */
  1048. var KHR_materials_unlit = /** @class */ (function () {
  1049. /** @hidden */
  1050. function KHR_materials_unlit(loader) {
  1051. /**
  1052. * The name of this extension.
  1053. */
  1054. this.name = NAME;
  1055. /**
  1056. * Defines a number that determines the order the extensions are applied.
  1057. */
  1058. this.order = 210;
  1059. this._loader = loader;
  1060. this.enabled = this._loader.isExtensionUsed(NAME);
  1061. }
  1062. /** @hidden */
  1063. KHR_materials_unlit.prototype.dispose = function () {
  1064. delete this._loader;
  1065. };
  1066. /** @hidden */
  1067. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  1068. var _this = this;
  1069. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  1070. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1071. });
  1072. };
  1073. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  1074. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1075. throw new Error(context + ": Material type not supported");
  1076. }
  1077. var promises = new Array();
  1078. babylonMaterial.unlit = true;
  1079. var properties = material.pbrMetallicRoughness;
  1080. if (properties) {
  1081. if (properties.baseColorFactor) {
  1082. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  1083. babylonMaterial.alpha = properties.baseColorFactor[3];
  1084. }
  1085. else {
  1086. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  1087. }
  1088. if (properties.baseColorTexture) {
  1089. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  1090. texture.name = babylonMaterial.name + " (Base Color)";
  1091. babylonMaterial.albedoTexture = texture;
  1092. }));
  1093. }
  1094. }
  1095. if (material.doubleSided) {
  1096. babylonMaterial.backFaceCulling = false;
  1097. babylonMaterial.twoSidedLighting = true;
  1098. }
  1099. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  1100. return Promise.all(promises).then(function () { });
  1101. };
  1102. return KHR_materials_unlit;
  1103. }());
  1104. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  1105. /***/ }),
  1106. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  1107. /*!*******************************************************!*\
  1108. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  1109. \*******************************************************/
  1110. /*! exports provided: KHR_materials_variants */
  1111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1112. "use strict";
  1113. __webpack_require__.r(__webpack_exports__);
  1114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  1115. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1116. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/observable");
  1117. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  1118. var NAME = "KHR_materials_variants";
  1119. /**
  1120. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1121. * !!! Experimental Extension Subject to Changes !!!
  1122. */
  1123. var KHR_materials_variants = /** @class */ (function () {
  1124. /** @hidden */
  1125. function KHR_materials_variants(loader) {
  1126. /**
  1127. * The name of this extension.
  1128. */
  1129. this.name = NAME;
  1130. this._loader = loader;
  1131. this.enabled = this._loader.isExtensionUsed(NAME);
  1132. }
  1133. /** @hidden */
  1134. KHR_materials_variants.prototype.dispose = function () {
  1135. delete this._loader;
  1136. };
  1137. /**
  1138. * Gets the list of available variant tag names for this asset.
  1139. * @param rootMesh The glTF root mesh
  1140. * @returns the list of all the variant names for this model
  1141. */
  1142. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  1143. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1144. if (!extensionMetadata) {
  1145. return [];
  1146. }
  1147. return Object.keys(extensionMetadata.variants);
  1148. };
  1149. /**
  1150. * Select a variant given a variant tag name or a list of variant tag names.
  1151. * @param rootMesh The glTF root mesh
  1152. * @param variantName The variant name(s) to select.
  1153. */
  1154. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  1155. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1156. if (!extensionMetadata) {
  1157. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  1158. }
  1159. var select = function (variantName) {
  1160. var entries = extensionMetadata.variants[variantName];
  1161. if (entries) {
  1162. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  1163. var entry = entries_1[_i];
  1164. entry.mesh.material = entry.material;
  1165. }
  1166. }
  1167. };
  1168. if (variantName instanceof Array) {
  1169. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  1170. var name_1 = variantName_1[_i];
  1171. select(name_1);
  1172. }
  1173. }
  1174. else {
  1175. select(variantName);
  1176. }
  1177. extensionMetadata.lastSelected = variantName;
  1178. };
  1179. /**
  1180. * Reset back to the original before selecting a variant.
  1181. * @param rootMesh The glTF root mesh
  1182. */
  1183. KHR_materials_variants.Reset = function (rootMesh) {
  1184. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1185. if (!extensionMetadata) {
  1186. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  1187. }
  1188. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  1189. var entry = _a[_i];
  1190. entry.mesh.material = entry.material;
  1191. }
  1192. extensionMetadata.lastSelected = null;
  1193. };
  1194. /**
  1195. * Gets the last selected variant tag name(s) or null if original.
  1196. * @param rootMesh The glTF root mesh
  1197. * @returns The selected variant tag name(s).
  1198. */
  1199. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  1200. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1201. if (!extensionMetadata) {
  1202. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  1203. }
  1204. return extensionMetadata.lastSelected;
  1205. };
  1206. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  1207. var _a, _b;
  1208. return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
  1209. };
  1210. /** @hidden */
  1211. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  1212. var _this = this;
  1213. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  1214. var promises = new Array();
  1215. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  1216. assign(babylonMesh);
  1217. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  1218. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  1219. var root = _this._loader.rootBabylonMesh;
  1220. var metadata = (root.metadata = root.metadata || {});
  1221. var gltf = (metadata.gltf = metadata.gltf || {});
  1222. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  1223. // Store the original material.
  1224. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  1225. // For each mapping, look at the tags and make a new entry for them.
  1226. var variants_1 = extensionMetadata.variants;
  1227. for (var _i = 0, _a = extension.mapping; _i < _a.length; _i++) {
  1228. var mapping = _a[_i];
  1229. var _loop_1 = function (tag) {
  1230. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  1231. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1232. variants_1[tag] = variants_1[tag] || [];
  1233. variants_1[tag].push({
  1234. mesh: babylonMesh,
  1235. material: babylonMaterial
  1236. });
  1237. }));
  1238. };
  1239. for (var _b = 0, _c = mapping.tags; _b < _c.length; _b++) {
  1240. var tag = _c[_b];
  1241. _loop_1(tag);
  1242. }
  1243. }
  1244. }
  1245. }));
  1246. return Promise.all(promises).then(function (_a) {
  1247. var babylonMesh = _a[0];
  1248. return babylonMesh;
  1249. });
  1250. });
  1251. };
  1252. return KHR_materials_variants;
  1253. }());
  1254. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  1255. /***/ }),
  1256. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  1257. /*!******************************************************!*\
  1258. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  1259. \******************************************************/
  1260. /*! exports provided: KHR_mesh_quantization */
  1261. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1262. "use strict";
  1263. __webpack_require__.r(__webpack_exports__);
  1264. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  1265. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1266. var NAME = "KHR_mesh_quantization";
  1267. /**
  1268. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1269. */
  1270. var KHR_mesh_quantization = /** @class */ (function () {
  1271. /** @hidden */
  1272. function KHR_mesh_quantization(loader) {
  1273. /**
  1274. * The name of this extension.
  1275. */
  1276. this.name = NAME;
  1277. this.enabled = loader.isExtensionUsed(NAME);
  1278. }
  1279. /** @hidden */
  1280. KHR_mesh_quantization.prototype.dispose = function () {
  1281. };
  1282. return KHR_mesh_quantization;
  1283. }());
  1284. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  1285. /***/ }),
  1286. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  1287. /*!***************************************************!*\
  1288. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  1289. \***************************************************/
  1290. /*! exports provided: KHR_texture_basisu */
  1291. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1292. "use strict";
  1293. __webpack_require__.r(__webpack_exports__);
  1294. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  1295. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1296. var NAME = "KHR_texture_basisu";
  1297. /**
  1298. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  1299. * !!! Experimental Extension Subject to Changes !!!
  1300. */
  1301. var KHR_texture_basisu = /** @class */ (function () {
  1302. /** @hidden */
  1303. function KHR_texture_basisu(loader) {
  1304. /** The name of this extension. */
  1305. this.name = NAME;
  1306. this._loader = loader;
  1307. this.enabled = loader.isExtensionUsed(NAME);
  1308. }
  1309. /** @hidden */
  1310. KHR_texture_basisu.prototype.dispose = function () {
  1311. delete this._loader;
  1312. };
  1313. /** @hidden */
  1314. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  1315. var _this = this;
  1316. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  1317. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  1318. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  1319. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  1320. babylonTexture.gammaSpace = false;
  1321. assign(babylonTexture);
  1322. });
  1323. });
  1324. };
  1325. return KHR_texture_basisu;
  1326. }());
  1327. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  1328. /***/ }),
  1329. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  1330. /*!******************************************************!*\
  1331. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  1332. \******************************************************/
  1333. /*! exports provided: KHR_texture_transform */
  1334. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1335. "use strict";
  1336. __webpack_require__.r(__webpack_exports__);
  1337. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  1338. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/observable");
  1339. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  1340. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1341. var NAME = "KHR_texture_transform";
  1342. /**
  1343. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  1344. */
  1345. var KHR_texture_transform = /** @class */ (function () {
  1346. /** @hidden */
  1347. function KHR_texture_transform(loader) {
  1348. /**
  1349. * The name of this extension.
  1350. */
  1351. this.name = NAME;
  1352. this._loader = loader;
  1353. this.enabled = this._loader.isExtensionUsed(NAME);
  1354. }
  1355. /** @hidden */
  1356. KHR_texture_transform.prototype.dispose = function () {
  1357. delete this._loader;
  1358. };
  1359. /** @hidden */
  1360. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  1361. var _this = this;
  1362. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  1363. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  1364. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  1365. throw new Error(extensionContext + ": Texture type not supported");
  1366. }
  1367. if (extension.offset) {
  1368. babylonTexture.uOffset = extension.offset[0];
  1369. babylonTexture.vOffset = extension.offset[1];
  1370. }
  1371. // Always rotate around the origin.
  1372. babylonTexture.uRotationCenter = 0;
  1373. babylonTexture.vRotationCenter = 0;
  1374. if (extension.rotation) {
  1375. babylonTexture.wAng = -extension.rotation;
  1376. }
  1377. if (extension.scale) {
  1378. babylonTexture.uScale = extension.scale[0];
  1379. babylonTexture.vScale = extension.scale[1];
  1380. }
  1381. if (extension.texCoord != undefined) {
  1382. babylonTexture.coordinatesIndex = extension.texCoord;
  1383. }
  1384. assign(babylonTexture);
  1385. });
  1386. });
  1387. };
  1388. return KHR_texture_transform;
  1389. }());
  1390. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  1391. /***/ }),
  1392. /***/ "./glTF/2.0/Extensions/KHR_xmp.ts":
  1393. /*!****************************************!*\
  1394. !*** ./glTF/2.0/Extensions/KHR_xmp.ts ***!
  1395. \****************************************/
  1396. /*! exports provided: KHR_xmp */
  1397. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1398. "use strict";
  1399. __webpack_require__.r(__webpack_exports__);
  1400. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return KHR_xmp; });
  1401. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1402. var NAME = "KHR_xmp";
  1403. /**
  1404. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  1405. * !!! Experimental Extension Subject to Changes !!!
  1406. */
  1407. var KHR_xmp = /** @class */ (function () {
  1408. /** @hidden */
  1409. function KHR_xmp(loader) {
  1410. /**
  1411. * The name of this extension.
  1412. */
  1413. this.name = NAME;
  1414. /**
  1415. * Defines a number that determines the order the extensions are applied.
  1416. */
  1417. this.order = 100;
  1418. this._loader = loader;
  1419. this.enabled = this._loader.isExtensionUsed(NAME);
  1420. }
  1421. /** @hidden */
  1422. KHR_xmp.prototype.dispose = function () {
  1423. delete this._loader;
  1424. };
  1425. /**
  1426. * Called after the loader state changes to LOADING.
  1427. */
  1428. KHR_xmp.prototype.onLoading = function () {
  1429. var _a, _b, _c;
  1430. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp;
  1431. var xmp_node = (_c = (_b = this._loader.gltf.asset) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.KHR_xmp;
  1432. if (xmp_gltf && xmp_node) {
  1433. var packet = +xmp_node.packet;
  1434. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  1435. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  1436. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  1437. }
  1438. }
  1439. };
  1440. return KHR_xmp;
  1441. }());
  1442. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp(loader); });
  1443. /***/ }),
  1444. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  1445. /*!***************************************************!*\
  1446. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  1447. \***************************************************/
  1448. /*! exports provided: MSFT_audio_emitter */
  1449. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1450. "use strict";
  1451. __webpack_require__.r(__webpack_exports__);
  1452. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  1453. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  1454. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  1455. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1456. var NAME = "MSFT_audio_emitter";
  1457. /**
  1458. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1459. */
  1460. var MSFT_audio_emitter = /** @class */ (function () {
  1461. /** @hidden */
  1462. function MSFT_audio_emitter(loader) {
  1463. /**
  1464. * The name of this extension.
  1465. */
  1466. this.name = NAME;
  1467. this._loader = loader;
  1468. this.enabled = this._loader.isExtensionUsed(NAME);
  1469. }
  1470. /** @hidden */
  1471. MSFT_audio_emitter.prototype.dispose = function () {
  1472. delete this._loader;
  1473. delete this._clips;
  1474. delete this._emitters;
  1475. };
  1476. /** @hidden */
  1477. MSFT_audio_emitter.prototype.onLoading = function () {
  1478. var extensions = this._loader.gltf.extensions;
  1479. if (extensions && extensions[this.name]) {
  1480. var extension = extensions[this.name];
  1481. this._clips = extension.clips;
  1482. this._emitters = extension.emitters;
  1483. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  1484. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  1485. }
  1486. };
  1487. /** @hidden */
  1488. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  1489. var _this = this;
  1490. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  1491. var promises = new Array();
  1492. promises.push(_this._loader.loadSceneAsync(context, scene));
  1493. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1494. var emitterIndex = _a[_i];
  1495. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1496. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  1497. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1498. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  1499. }
  1500. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  1501. }
  1502. return Promise.all(promises).then(function () { });
  1503. });
  1504. };
  1505. /** @hidden */
  1506. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  1507. var _this = this;
  1508. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1509. var promises = new Array();
  1510. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  1511. var _loop_1 = function (emitterIndex) {
  1512. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1513. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  1514. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  1515. var sound = _a[_i];
  1516. sound.attachToMesh(babylonMesh);
  1517. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1518. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  1519. sound.setDirectionalCone(2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  1520. }
  1521. }
  1522. }));
  1523. };
  1524. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1525. var emitterIndex = _a[_i];
  1526. _loop_1(emitterIndex);
  1527. }
  1528. assign(babylonMesh);
  1529. }).then(function (babylonMesh) {
  1530. return Promise.all(promises).then(function () {
  1531. return babylonMesh;
  1532. });
  1533. });
  1534. });
  1535. };
  1536. /** @hidden */
  1537. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  1538. var _this = this;
  1539. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  1540. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  1541. var promises = new Array();
  1542. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  1543. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  1544. var event_1 = _a[_i];
  1545. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  1546. }
  1547. return Promise.all(promises).then(function () {
  1548. return babylonAnimationGroup;
  1549. });
  1550. });
  1551. });
  1552. };
  1553. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  1554. if (clip._objectURL) {
  1555. return clip._objectURL;
  1556. }
  1557. var promise;
  1558. if (clip.uri) {
  1559. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  1560. }
  1561. else {
  1562. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  1563. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  1564. }
  1565. clip._objectURL = promise.then(function (data) {
  1566. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  1567. });
  1568. return clip._objectURL;
  1569. };
  1570. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  1571. var _this = this;
  1572. emitter._babylonSounds = emitter._babylonSounds || [];
  1573. if (!emitter._babylonData) {
  1574. var clipPromises = new Array();
  1575. var name_1 = emitter.name || "emitter" + emitter.index;
  1576. var options_1 = {
  1577. loop: false,
  1578. autoplay: false,
  1579. volume: emitter.volume == undefined ? 1 : emitter.volume,
  1580. };
  1581. var _loop_2 = function (i) {
  1582. var clipContext = "/extensions/" + this_1.name + "/clips";
  1583. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  1584. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  1585. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  1586. sound.refDistance = emitter.refDistance || 1;
  1587. sound.maxDistance = emitter.maxDistance || 256;
  1588. sound.rolloffFactor = emitter.rolloffFactor || 1;
  1589. sound.distanceModel = emitter.distanceModel || 'exponential';
  1590. sound._positionInEmitterSpace = true;
  1591. }));
  1592. };
  1593. var this_1 = this;
  1594. for (var i = 0; i < emitter.clips.length; i++) {
  1595. _loop_2(i);
  1596. }
  1597. var promise = Promise.all(clipPromises).then(function () {
  1598. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  1599. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  1600. if (emitter.innerAngle) {
  1601. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  1602. }
  1603. if (emitter.outerAngle) {
  1604. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  1605. }
  1606. if (emitter.volume) {
  1607. weightedSound.volume = emitter.volume;
  1608. }
  1609. emitter._babylonData.sound = weightedSound;
  1610. });
  1611. emitter._babylonData = {
  1612. loaded: promise
  1613. };
  1614. }
  1615. return emitter._babylonData.loaded;
  1616. };
  1617. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  1618. switch (action) {
  1619. case "play" /* play */: {
  1620. return function (currentFrame) {
  1621. var frameOffset = (startOffset || 0) + (currentFrame - time);
  1622. sound.play(frameOffset);
  1623. };
  1624. }
  1625. case "stop" /* stop */: {
  1626. return function (currentFrame) {
  1627. sound.stop();
  1628. };
  1629. }
  1630. case "pause" /* pause */: {
  1631. return function (currentFrame) {
  1632. sound.pause();
  1633. };
  1634. }
  1635. default: {
  1636. throw new Error(context + ": Unsupported action " + action);
  1637. }
  1638. }
  1639. };
  1640. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  1641. var _this = this;
  1642. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  1643. return Promise.resolve();
  1644. }
  1645. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  1646. var emitterIndex = event.emitter;
  1647. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  1648. return this._loadEmitterAsync(context, emitter).then(function () {
  1649. var sound = emitter._babylonData.sound;
  1650. if (sound) {
  1651. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  1652. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  1653. // Make sure all started audio stops when this animation is terminated.
  1654. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  1655. sound.stop();
  1656. });
  1657. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  1658. sound.pause();
  1659. });
  1660. }
  1661. });
  1662. };
  1663. return MSFT_audio_emitter;
  1664. }());
  1665. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  1666. /***/ }),
  1667. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  1668. /*!*****************************************!*\
  1669. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  1670. \*****************************************/
  1671. /*! exports provided: MSFT_lod */
  1672. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1673. "use strict";
  1674. __webpack_require__.r(__webpack_exports__);
  1675. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  1676. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  1677. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  1678. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1679. var NAME = "MSFT_lod";
  1680. /**
  1681. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1682. */
  1683. var MSFT_lod = /** @class */ (function () {
  1684. /** @hidden */
  1685. function MSFT_lod(loader) {
  1686. /**
  1687. * The name of this extension.
  1688. */
  1689. this.name = NAME;
  1690. /**
  1691. * Defines a number that determines the order the extensions are applied.
  1692. */
  1693. this.order = 100;
  1694. /**
  1695. * Maximum number of LODs to load, starting from the lowest LOD.
  1696. */
  1697. this.maxLODsToLoad = 10;
  1698. /**
  1699. * Observable raised when all node LODs of one level are loaded.
  1700. * The event data is the index of the loaded LOD starting from zero.
  1701. * Dispose the loader to cancel the loading of the next level of LODs.
  1702. */
  1703. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1704. /**
  1705. * Observable raised when all material LODs of one level are loaded.
  1706. * The event data is the index of the loaded LOD starting from zero.
  1707. * Dispose the loader to cancel the loading of the next level of LODs.
  1708. */
  1709. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1710. this._bufferLODs = new Array();
  1711. this._nodeIndexLOD = null;
  1712. this._nodeSignalLODs = new Array();
  1713. this._nodePromiseLODs = new Array();
  1714. this._nodeBufferLODs = new Array();
  1715. this._materialIndexLOD = null;
  1716. this._materialSignalLODs = new Array();
  1717. this._materialPromiseLODs = new Array();
  1718. this._materialBufferLODs = new Array();
  1719. this._loader = loader;
  1720. this.enabled = this._loader.isExtensionUsed(NAME);
  1721. }
  1722. /** @hidden */
  1723. MSFT_lod.prototype.dispose = function () {
  1724. delete this._loader;
  1725. this._nodeIndexLOD = null;
  1726. this._nodeSignalLODs.length = 0;
  1727. this._nodePromiseLODs.length = 0;
  1728. this._nodeBufferLODs.length = 0;
  1729. this._materialIndexLOD = null;
  1730. this._materialSignalLODs.length = 0;
  1731. this._materialPromiseLODs.length = 0;
  1732. this._materialBufferLODs.length = 0;
  1733. this.onMaterialLODsLoadedObservable.clear();
  1734. this.onNodeLODsLoadedObservable.clear();
  1735. };
  1736. /** @hidden */
  1737. MSFT_lod.prototype.onReady = function () {
  1738. var _this = this;
  1739. var _loop_1 = function (indexLOD) {
  1740. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  1741. if (indexLOD !== 0) {
  1742. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  1743. _this._loader.log("Loaded node LOD " + indexLOD);
  1744. }
  1745. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  1746. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  1747. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  1748. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  1749. if (_this._nodeSignalLODs[indexLOD]) {
  1750. _this._nodeSignalLODs[indexLOD].resolve();
  1751. }
  1752. }
  1753. });
  1754. this_1._loader._completePromises.push(promise);
  1755. };
  1756. var this_1 = this;
  1757. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  1758. _loop_1(indexLOD);
  1759. }
  1760. var _loop_2 = function (indexLOD) {
  1761. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  1762. if (indexLOD !== 0) {
  1763. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  1764. _this._loader.log("Loaded material LOD " + indexLOD);
  1765. }
  1766. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  1767. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  1768. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  1769. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  1770. if (_this._materialSignalLODs[indexLOD]) {
  1771. _this._materialSignalLODs[indexLOD].resolve();
  1772. }
  1773. }
  1774. });
  1775. this_2._loader._completePromises.push(promise);
  1776. };
  1777. var this_2 = this;
  1778. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  1779. _loop_2(indexLOD);
  1780. }
  1781. };
  1782. /** @hidden */
  1783. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  1784. var promise = this._loader.loadSceneAsync(context, scene);
  1785. this._loadBufferLOD(this._bufferLODs, 0);
  1786. return promise;
  1787. };
  1788. /** @hidden */
  1789. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  1790. var _this = this;
  1791. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1792. var firstPromise;
  1793. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  1794. _this._loader.logOpen("" + extensionContext);
  1795. var _loop_3 = function (indexLOD) {
  1796. var nodeLOD = nodeLODs[indexLOD];
  1797. if (indexLOD !== 0) {
  1798. _this._nodeIndexLOD = indexLOD;
  1799. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1800. }
  1801. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  1802. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  1803. if (indexLOD !== 0) {
  1804. // TODO: should not rely on _babylonTransformNode
  1805. var previousNodeLOD = nodeLODs[indexLOD - 1];
  1806. if (previousNodeLOD._babylonTransformNode) {
  1807. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  1808. delete previousNodeLOD._babylonTransformNode;
  1809. }
  1810. }
  1811. babylonMesh.setEnabled(true);
  1812. return babylonMesh;
  1813. });
  1814. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  1815. if (indexLOD === 0) {
  1816. firstPromise = promise;
  1817. }
  1818. else {
  1819. _this._nodeIndexLOD = null;
  1820. _this._nodePromiseLODs[indexLOD].push(promise);
  1821. }
  1822. };
  1823. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  1824. _loop_3(indexLOD);
  1825. }
  1826. _this._loader.logClose();
  1827. return firstPromise;
  1828. });
  1829. };
  1830. /** @hidden */
  1831. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  1832. var _this = this;
  1833. // Don't load material LODs if already loading a node LOD.
  1834. if (this._nodeIndexLOD) {
  1835. return null;
  1836. }
  1837. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  1838. var firstPromise;
  1839. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  1840. _this._loader.logOpen("" + extensionContext);
  1841. var _loop_4 = function (indexLOD) {
  1842. var materialLOD = materialLODs[indexLOD];
  1843. if (indexLOD !== 0) {
  1844. _this._materialIndexLOD = indexLOD;
  1845. }
  1846. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1847. if (indexLOD === 0) {
  1848. assign(babylonMaterial);
  1849. }
  1850. }).then(function (babylonMaterial) {
  1851. if (indexLOD !== 0) {
  1852. assign(babylonMaterial);
  1853. // TODO: should not rely on _data
  1854. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  1855. if (previousDataLOD[babylonDrawMode]) {
  1856. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  1857. delete previousDataLOD[babylonDrawMode];
  1858. }
  1859. }
  1860. return babylonMaterial;
  1861. });
  1862. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  1863. if (indexLOD === 0) {
  1864. firstPromise = promise;
  1865. }
  1866. else {
  1867. _this._materialIndexLOD = null;
  1868. _this._materialPromiseLODs[indexLOD].push(promise);
  1869. }
  1870. };
  1871. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  1872. _loop_4(indexLOD);
  1873. }
  1874. _this._loader.logClose();
  1875. return firstPromise;
  1876. });
  1877. };
  1878. /** @hidden */
  1879. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  1880. var _this = this;
  1881. // Defer the loading of uris if loading a node or material LOD.
  1882. if (this._nodeIndexLOD !== null) {
  1883. this._loader.log("deferred");
  1884. var previousIndexLOD = this._nodeIndexLOD - 1;
  1885. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1886. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  1887. return _this._loader.loadUriAsync(context, property, uri);
  1888. });
  1889. }
  1890. else if (this._materialIndexLOD !== null) {
  1891. this._loader.log("deferred");
  1892. var previousIndexLOD = this._materialIndexLOD - 1;
  1893. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1894. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  1895. return _this._loader.loadUriAsync(context, property, uri);
  1896. });
  1897. }
  1898. return null;
  1899. };
  1900. /** @hidden */
  1901. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  1902. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  1903. if (!this._loader.bin) {
  1904. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  1905. }
  1906. var loadAsync = function (bufferLODs, indexLOD) {
  1907. var start = byteOffset;
  1908. var end = start + byteLength - 1;
  1909. var bufferLOD = bufferLODs[indexLOD];
  1910. if (bufferLOD) {
  1911. bufferLOD.start = Math.min(bufferLOD.start, start);
  1912. bufferLOD.end = Math.max(bufferLOD.end, end);
  1913. }
  1914. else {
  1915. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  1916. bufferLODs[indexLOD] = bufferLOD;
  1917. }
  1918. return bufferLOD.loaded.promise.then(function (data) {
  1919. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  1920. });
  1921. };
  1922. this._loader.log("deferred");
  1923. if (this._nodeIndexLOD !== null) {
  1924. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  1925. }
  1926. else if (this._materialIndexLOD !== null) {
  1927. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  1928. }
  1929. else {
  1930. return loadAsync(this._bufferLODs, 0);
  1931. }
  1932. }
  1933. return null;
  1934. };
  1935. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  1936. var bufferLOD = bufferLODs[indexLOD];
  1937. if (bufferLOD) {
  1938. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  1939. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  1940. bufferLOD.loaded.resolve(data);
  1941. }, function (error) {
  1942. bufferLOD.loaded.reject(error);
  1943. });
  1944. }
  1945. };
  1946. /**
  1947. * Gets an array of LOD properties from lowest to highest.
  1948. */
  1949. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  1950. if (this.maxLODsToLoad <= 0) {
  1951. throw new Error("maxLODsToLoad must be greater than zero");
  1952. }
  1953. var properties = new Array();
  1954. for (var i = ids.length - 1; i >= 0; i--) {
  1955. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  1956. if (properties.length === this.maxLODsToLoad) {
  1957. return properties;
  1958. }
  1959. }
  1960. properties.push(property);
  1961. return properties;
  1962. };
  1963. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  1964. var _this = this;
  1965. var babylonMaterials = new Array();
  1966. var babylonMaterial = babylonTransformNode.material;
  1967. if (babylonMaterial) {
  1968. babylonMaterials.push(babylonMaterial);
  1969. }
  1970. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  1971. var babylonMesh = _a[_i];
  1972. if (babylonMesh.material) {
  1973. babylonMaterials.push(babylonMesh.material);
  1974. }
  1975. }
  1976. babylonTransformNode.dispose();
  1977. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  1978. this._disposeMaterials(babylonMaterialsToDispose);
  1979. };
  1980. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  1981. var babylonTextures = {};
  1982. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  1983. var babylonMaterial = babylonMaterials_1[_i];
  1984. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  1985. var babylonTexture = _b[_a];
  1986. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  1987. }
  1988. babylonMaterial.dispose();
  1989. }
  1990. for (var uniqueId in babylonTextures) {
  1991. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  1992. var babylonMaterial = _d[_c];
  1993. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  1994. delete babylonTextures[uniqueId];
  1995. }
  1996. }
  1997. }
  1998. for (var uniqueId in babylonTextures) {
  1999. babylonTextures[uniqueId].dispose();
  2000. }
  2001. };
  2002. return MSFT_lod;
  2003. }());
  2004. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  2005. /***/ }),
  2006. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  2007. /*!***************************************************!*\
  2008. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  2009. \***************************************************/
  2010. /*! exports provided: MSFT_minecraftMesh */
  2011. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2012. "use strict";
  2013. __webpack_require__.r(__webpack_exports__);
  2014. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  2015. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  2016. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2017. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2018. var NAME = "MSFT_minecraftMesh";
  2019. /** @hidden */
  2020. var MSFT_minecraftMesh = /** @class */ (function () {
  2021. function MSFT_minecraftMesh(loader) {
  2022. this.name = NAME;
  2023. this._loader = loader;
  2024. this.enabled = this._loader.isExtensionUsed(NAME);
  2025. }
  2026. MSFT_minecraftMesh.prototype.dispose = function () {
  2027. delete this._loader;
  2028. };
  2029. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2030. var _this = this;
  2031. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2032. if (extra) {
  2033. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2034. throw new Error(extraContext + ": Material type not supported");
  2035. }
  2036. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2037. if (babylonMaterial.needAlphaBlending()) {
  2038. babylonMaterial.forceDepthWrite = true;
  2039. babylonMaterial.separateCullingPass = true;
  2040. }
  2041. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  2042. babylonMaterial.twoSidedLighting = true;
  2043. return promise;
  2044. }
  2045. return null;
  2046. });
  2047. };
  2048. return MSFT_minecraftMesh;
  2049. }());
  2050. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  2051. /***/ }),
  2052. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  2053. /*!*************************************************!*\
  2054. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  2055. \*************************************************/
  2056. /*! exports provided: MSFT_sRGBFactors */
  2057. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2058. "use strict";
  2059. __webpack_require__.r(__webpack_exports__);
  2060. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  2061. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  2062. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2063. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2064. var NAME = "MSFT_sRGBFactors";
  2065. /** @hidden */
  2066. var MSFT_sRGBFactors = /** @class */ (function () {
  2067. function MSFT_sRGBFactors(loader) {
  2068. this.name = NAME;
  2069. this._loader = loader;
  2070. this.enabled = this._loader.isExtensionUsed(NAME);
  2071. }
  2072. MSFT_sRGBFactors.prototype.dispose = function () {
  2073. delete this._loader;
  2074. };
  2075. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2076. var _this = this;
  2077. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2078. if (extra) {
  2079. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2080. throw new Error(extraContext + ": Material type not supported");
  2081. }
  2082. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2083. if (!babylonMaterial.albedoTexture) {
  2084. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  2085. }
  2086. if (!babylonMaterial.reflectivityTexture) {
  2087. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  2088. }
  2089. return promise;
  2090. }
  2091. return null;
  2092. });
  2093. };
  2094. return MSFT_sRGBFactors;
  2095. }());
  2096. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  2097. /***/ }),
  2098. /***/ "./glTF/2.0/Extensions/index.ts":
  2099. /*!**************************************!*\
  2100. !*** ./glTF/2.0/Extensions/index.ts ***!
  2101. \**************************************/
  2102. /*! exports provided: EXT_lights_image_based, EXT_mesh_gpu_instancing, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  2103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2104. "use strict";
  2105. __webpack_require__.r(__webpack_exports__);
  2106. /* harmony import */ var _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EXT_lights_image_based */ "./glTF/2.0/Extensions/EXT_lights_image_based.ts");
  2107. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__["EXT_lights_image_based"]; });
  2108. /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts");
  2109. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  2110. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  2111. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__["KHR_draco_mesh_compression"]; });
  2112. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  2113. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  2114. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  2115. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_pbrSpecularGlossiness"]; });
  2116. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  2117. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_unlit"]; });
  2118. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  2119. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_clearcoat"]; });
  2120. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  2121. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  2122. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  2123. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_specular"]; });
  2124. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  2125. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_ior"]; });
  2126. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  2127. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_variants"]; });
  2128. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  2129. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_transmission"]; });
  2130. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  2131. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__["KHR_mesh_quantization"]; });
  2132. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  2133. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__["KHR_texture_basisu"]; });
  2134. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  2135. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__["KHR_texture_transform"]; });
  2136. /* harmony import */ var _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_xmp */ "./glTF/2.0/Extensions/KHR_xmp.ts");
  2137. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__["KHR_xmp"]; });
  2138. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  2139. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__["MSFT_audio_emitter"]; });
  2140. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  2141. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__["MSFT_lod"]; });
  2142. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  2143. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__["MSFT_minecraftMesh"]; });
  2144. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  2145. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__["MSFT_sRGBFactors"]; });
  2146. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  2147. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__["ExtrasAsMetadata"]; });
  2148. /***/ }),
  2149. /***/ "./glTF/2.0/glTFLoader.ts":
  2150. /*!********************************!*\
  2151. !*** ./glTF/2.0/glTFLoader.ts ***!
  2152. \********************************/
  2153. /*! exports provided: ArrayItem, GLTFLoader */
  2154. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2155. "use strict";
  2156. __webpack_require__.r(__webpack_exports__);
  2157. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  2158. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  2159. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/observable");
  2160. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  2161. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  2162. /**
  2163. * Helper class for working with arrays when loading the glTF asset
  2164. */
  2165. var ArrayItem = /** @class */ (function () {
  2166. function ArrayItem() {
  2167. }
  2168. /**
  2169. * Gets an item from the given array.
  2170. * @param context The context when loading the asset
  2171. * @param array The array to get the item from
  2172. * @param index The index to the array
  2173. * @returns The array item
  2174. */
  2175. ArrayItem.Get = function (context, array, index) {
  2176. if (!array || index == undefined || !array[index]) {
  2177. throw new Error(context + ": Failed to find index (" + index + ")");
  2178. }
  2179. return array[index];
  2180. };
  2181. /**
  2182. * Assign an `index` field to each item of the given array.
  2183. * @param array The array of items
  2184. */
  2185. ArrayItem.Assign = function (array) {
  2186. if (array) {
  2187. for (var index = 0; index < array.length; index++) {
  2188. array[index].index = index;
  2189. }
  2190. }
  2191. };
  2192. return ArrayItem;
  2193. }());
  2194. /**
  2195. * The glTF 2.0 loader
  2196. */
  2197. var GLTFLoader = /** @class */ (function () {
  2198. /** @hidden */
  2199. function GLTFLoader(parent) {
  2200. /** @hidden */
  2201. this._completePromises = new Array();
  2202. /** @hidden */
  2203. this._forAssetContainer = false;
  2204. /** Storage */
  2205. this._babylonLights = [];
  2206. /** @hidden */
  2207. this._disableInstancedMesh = 0;
  2208. this._disposed = false;
  2209. this._state = null;
  2210. this._extensions = new Array();
  2211. this._defaultBabylonMaterialData = {};
  2212. this._parent = parent;
  2213. }
  2214. /**
  2215. * Registers a loader extension.
  2216. * @param name The name of the loader extension.
  2217. * @param factory The factory function that creates the loader extension.
  2218. */
  2219. GLTFLoader.RegisterExtension = function (name, factory) {
  2220. if (GLTFLoader.UnregisterExtension(name)) {
  2221. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  2222. }
  2223. GLTFLoader._RegisteredExtensions[name] = {
  2224. factory: factory
  2225. };
  2226. };
  2227. /**
  2228. * Unregisters a loader extension.
  2229. * @param name The name of the loader extension.
  2230. * @returns A boolean indicating whether the extension has been unregistered
  2231. */
  2232. GLTFLoader.UnregisterExtension = function (name) {
  2233. if (!GLTFLoader._RegisteredExtensions[name]) {
  2234. return false;
  2235. }
  2236. delete GLTFLoader._RegisteredExtensions[name];
  2237. return true;
  2238. };
  2239. Object.defineProperty(GLTFLoader.prototype, "state", {
  2240. /**
  2241. * The loader state.
  2242. */
  2243. get: function () {
  2244. return this._state;
  2245. },
  2246. enumerable: false,
  2247. configurable: true
  2248. });
  2249. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  2250. /**
  2251. * The object that represents the glTF JSON.
  2252. */
  2253. get: function () {
  2254. return this._gltf;
  2255. },
  2256. enumerable: false,
  2257. configurable: true
  2258. });
  2259. Object.defineProperty(GLTFLoader.prototype, "bin", {
  2260. /**
  2261. * The BIN chunk of a binary glTF.
  2262. */
  2263. get: function () {
  2264. return this._bin;
  2265. },
  2266. enumerable: false,
  2267. configurable: true
  2268. });
  2269. Object.defineProperty(GLTFLoader.prototype, "parent", {
  2270. /**
  2271. * The parent file loader.
  2272. */
  2273. get: function () {
  2274. return this._parent;
  2275. },
  2276. enumerable: false,
  2277. configurable: true
  2278. });
  2279. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  2280. /**
  2281. * The Babylon scene when loading the asset.
  2282. */
  2283. get: function () {
  2284. return this._babylonScene;
  2285. },
  2286. enumerable: false,
  2287. configurable: true
  2288. });
  2289. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  2290. /**
  2291. * The root Babylon mesh when loading the asset.
  2292. */
  2293. get: function () {
  2294. return this._rootBabylonMesh;
  2295. },
  2296. enumerable: false,
  2297. configurable: true
  2298. });
  2299. /** @hidden */
  2300. GLTFLoader.prototype.dispose = function () {
  2301. if (this._disposed) {
  2302. return;
  2303. }
  2304. this._disposed = true;
  2305. this._completePromises.length = 0;
  2306. for (var name_1 in this._extensions) {
  2307. var extension = this._extensions[name_1];
  2308. extension.dispose && extension.dispose();
  2309. delete this._extensions[name_1];
  2310. }
  2311. delete this._gltf;
  2312. delete this._babylonScene;
  2313. delete this._rootBabylonMesh;
  2314. this._parent.dispose();
  2315. };
  2316. /** @hidden */
  2317. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  2318. var _this = this;
  2319. return Promise.resolve().then(function () {
  2320. _this._babylonScene = scene;
  2321. _this._rootUrl = rootUrl;
  2322. _this._fileName = fileName || "scene";
  2323. _this._forAssetContainer = forAssetContainer;
  2324. _this._loadData(data);
  2325. var nodes = null;
  2326. if (meshesNames) {
  2327. var nodeMap_1 = {};
  2328. if (_this._gltf.nodes) {
  2329. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  2330. var node = _a[_i];
  2331. if (node.name) {
  2332. nodeMap_1[node.name] = node.index;
  2333. }
  2334. }
  2335. }
  2336. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  2337. nodes = names.map(function (name) {
  2338. var node = nodeMap_1[name];
  2339. if (node === undefined) {
  2340. throw new Error("Failed to find node '" + name + "'");
  2341. }
  2342. return node;
  2343. });
  2344. }
  2345. return _this._loadAsync(nodes, function () {
  2346. return {
  2347. meshes: _this._getMeshes(),
  2348. particleSystems: [],
  2349. skeletons: _this._getSkeletons(),
  2350. animationGroups: _this._getAnimationGroups(),
  2351. lights: _this._babylonLights,
  2352. transformNodes: _this._getTransformNodes()
  2353. };
  2354. });
  2355. });
  2356. };
  2357. /** @hidden */
  2358. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  2359. var _this = this;
  2360. return Promise.resolve().then(function () {
  2361. _this._babylonScene = scene;
  2362. _this._rootUrl = rootUrl;
  2363. _this._fileName = fileName || "scene";
  2364. _this._loadData(data);
  2365. return _this._loadAsync(null, function () { return undefined; });
  2366. });
  2367. };
  2368. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  2369. var _this = this;
  2370. return Promise.resolve().then(function () {
  2371. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  2372. _this._loadExtensions();
  2373. _this._checkExtensions();
  2374. var loadingToReadyCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY];
  2375. var loadingToCompleteCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE];
  2376. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  2377. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  2378. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  2379. _this._extensionsOnLoading();
  2380. var promises = new Array();
  2381. // Block the marking of materials dirty until the scene is loaded.
  2382. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  2383. _this._babylonScene.blockMaterialDirtyMechanism = true;
  2384. if (nodes) {
  2385. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  2386. }
  2387. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  2388. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  2389. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  2390. }
  2391. // Restore the blocking of material dirty.
  2392. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  2393. if (_this._parent.compileMaterials) {
  2394. promises.push(_this._compileMaterialsAsync());
  2395. }
  2396. if (_this._parent.compileShadowGenerators) {
  2397. promises.push(_this._compileShadowGeneratorsAsync());
  2398. }
  2399. var resultPromise = Promise.all(promises).then(function () {
  2400. if (_this._rootBabylonMesh) {
  2401. _this._rootBabylonMesh.setEnabled(true);
  2402. }
  2403. _this._extensionsOnReady();
  2404. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  2405. _this._startAnimations();
  2406. return resultFunc();
  2407. });
  2408. resultPromise.then(function () {
  2409. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  2410. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  2411. if (!_this._disposed) {
  2412. Promise.all(_this._completePromises).then(function () {
  2413. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  2414. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  2415. _this._parent.onCompleteObservable.notifyObservers(undefined);
  2416. _this._parent.onCompleteObservable.clear();
  2417. _this.dispose();
  2418. }, function (error) {
  2419. _this._parent.onErrorObservable.notifyObservers(error);
  2420. _this._parent.onErrorObservable.clear();
  2421. _this.dispose();
  2422. });
  2423. }
  2424. });
  2425. });
  2426. return resultPromise;
  2427. }).catch(function (error) {
  2428. if (!_this._disposed) {
  2429. _this._parent.onErrorObservable.notifyObservers(error);
  2430. _this._parent.onErrorObservable.clear();
  2431. _this.dispose();
  2432. }
  2433. throw error;
  2434. });
  2435. };
  2436. GLTFLoader.prototype._loadData = function (data) {
  2437. this._gltf = data.json;
  2438. this._setupData();
  2439. if (data.bin) {
  2440. var buffers = this._gltf.buffers;
  2441. if (buffers && buffers[0] && !buffers[0].uri) {
  2442. var binaryBuffer = buffers[0];
  2443. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  2444. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  2445. }
  2446. this._bin = data.bin;
  2447. }
  2448. else {
  2449. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  2450. }
  2451. }
  2452. };
  2453. GLTFLoader.prototype._setupData = function () {
  2454. ArrayItem.Assign(this._gltf.accessors);
  2455. ArrayItem.Assign(this._gltf.animations);
  2456. ArrayItem.Assign(this._gltf.buffers);
  2457. ArrayItem.Assign(this._gltf.bufferViews);
  2458. ArrayItem.Assign(this._gltf.cameras);
  2459. ArrayItem.Assign(this._gltf.images);
  2460. ArrayItem.Assign(this._gltf.materials);
  2461. ArrayItem.Assign(this._gltf.meshes);
  2462. ArrayItem.Assign(this._gltf.nodes);
  2463. ArrayItem.Assign(this._gltf.samplers);
  2464. ArrayItem.Assign(this._gltf.scenes);
  2465. ArrayItem.Assign(this._gltf.skins);
  2466. ArrayItem.Assign(this._gltf.textures);
  2467. if (this._gltf.nodes) {
  2468. var nodeParents = {};
  2469. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  2470. var node = _a[_i];
  2471. if (node.children) {
  2472. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  2473. var index = _c[_b];
  2474. nodeParents[index] = node.index;
  2475. }
  2476. }
  2477. }
  2478. var rootNode = this._createRootNode();
  2479. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  2480. var node = _e[_d];
  2481. var parentIndex = nodeParents[node.index];
  2482. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  2483. }
  2484. }
  2485. };
  2486. GLTFLoader.prototype._loadExtensions = function () {
  2487. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  2488. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  2489. if (extension.name !== name_2) {
  2490. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  2491. }
  2492. this._extensions.push(extension);
  2493. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  2494. }
  2495. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  2496. this._parent.onExtensionLoadedObservable.clear();
  2497. };
  2498. GLTFLoader.prototype._checkExtensions = function () {
  2499. if (this._gltf.extensionsRequired) {
  2500. var _loop_1 = function (name_3) {
  2501. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  2502. if (!available) {
  2503. throw new Error("Require extension " + name_3 + " is not available");
  2504. }
  2505. };
  2506. var this_1 = this;
  2507. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  2508. var name_3 = _a[_i];
  2509. _loop_1(name_3);
  2510. }
  2511. }
  2512. };
  2513. GLTFLoader.prototype._setState = function (state) {
  2514. this._state = state;
  2515. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  2516. };
  2517. GLTFLoader.prototype._createRootNode = function () {
  2518. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2519. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  2520. this._babylonScene._blockEntityCollection = false;
  2521. this._rootBabylonMesh.setEnabled(false);
  2522. var rootNode = {
  2523. _babylonTransformNode: this._rootBabylonMesh,
  2524. index: -1
  2525. };
  2526. switch (this._parent.coordinateSystemMode) {
  2527. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  2528. if (!this._babylonScene.useRightHandedSystem) {
  2529. rootNode.rotation = [0, 1, 0, 0];
  2530. rootNode.scale = [1, 1, -1];
  2531. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  2532. }
  2533. break;
  2534. }
  2535. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  2536. this._babylonScene.useRightHandedSystem = true;
  2537. break;
  2538. }
  2539. default: {
  2540. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  2541. }
  2542. }
  2543. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  2544. return rootNode;
  2545. };
  2546. /**
  2547. * Loads a glTF scene.
  2548. * @param context The context when loading the asset
  2549. * @param scene The glTF scene property
  2550. * @returns A promise that resolves when the load is complete
  2551. */
  2552. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  2553. var _this = this;
  2554. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  2555. if (extensionPromise) {
  2556. return extensionPromise;
  2557. }
  2558. var promises = new Array();
  2559. this.logOpen(context + " " + (scene.name || ""));
  2560. if (scene.nodes) {
  2561. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  2562. var index = _a[_i];
  2563. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  2564. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  2565. babylonMesh.parent = _this._rootBabylonMesh;
  2566. }));
  2567. }
  2568. }
  2569. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  2570. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  2571. if (this._gltf.nodes) {
  2572. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  2573. var node = _c[_b];
  2574. if (node._babylonTransformNode && node._babylonBones) {
  2575. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  2576. var babylonBone = _e[_d];
  2577. babylonBone.linkTransformNode(node._babylonTransformNode);
  2578. }
  2579. }
  2580. }
  2581. }
  2582. promises.push(this._loadAnimationsAsync());
  2583. this.logClose();
  2584. return Promise.all(promises).then(function () { });
  2585. };
  2586. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  2587. if (node._primitiveBabylonMeshes) {
  2588. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  2589. var babylonMesh = _a[_i];
  2590. callback(babylonMesh);
  2591. }
  2592. }
  2593. };
  2594. GLTFLoader.prototype._getMeshes = function () {
  2595. var meshes = new Array();
  2596. // Root mesh is always first.
  2597. meshes.push(this._rootBabylonMesh);
  2598. var nodes = this._gltf.nodes;
  2599. if (nodes) {
  2600. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2601. var node = nodes_1[_i];
  2602. this._forEachPrimitive(node, function (babylonMesh) {
  2603. meshes.push(babylonMesh);
  2604. });
  2605. }
  2606. }
  2607. return meshes;
  2608. };
  2609. GLTFLoader.prototype._getTransformNodes = function () {
  2610. var transformNodes = new Array();
  2611. var nodes = this._gltf.nodes;
  2612. if (nodes) {
  2613. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2614. var node = nodes_2[_i];
  2615. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  2616. transformNodes.push(node._babylonTransformNode);
  2617. }
  2618. }
  2619. }
  2620. return transformNodes;
  2621. };
  2622. GLTFLoader.prototype._getSkeletons = function () {
  2623. var skeletons = new Array();
  2624. var skins = this._gltf.skins;
  2625. if (skins) {
  2626. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  2627. var skin = skins_1[_i];
  2628. if (skin._data) {
  2629. skeletons.push(skin._data.babylonSkeleton);
  2630. }
  2631. }
  2632. }
  2633. return skeletons;
  2634. };
  2635. GLTFLoader.prototype._getAnimationGroups = function () {
  2636. var animationGroups = new Array();
  2637. var animations = this._gltf.animations;
  2638. if (animations) {
  2639. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  2640. var animation = animations_1[_i];
  2641. if (animation._babylonAnimationGroup) {
  2642. animationGroups.push(animation._babylonAnimationGroup);
  2643. }
  2644. }
  2645. }
  2646. return animationGroups;
  2647. };
  2648. GLTFLoader.prototype._startAnimations = function () {
  2649. switch (this._parent.animationStartMode) {
  2650. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  2651. // do nothing
  2652. break;
  2653. }
  2654. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  2655. var babylonAnimationGroups = this._getAnimationGroups();
  2656. if (babylonAnimationGroups.length !== 0) {
  2657. babylonAnimationGroups[0].start(true);
  2658. }
  2659. break;
  2660. }
  2661. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  2662. var babylonAnimationGroups = this._getAnimationGroups();
  2663. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  2664. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  2665. babylonAnimationGroup.start(true);
  2666. }
  2667. break;
  2668. }
  2669. default: {
  2670. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  2671. return;
  2672. }
  2673. }
  2674. };
  2675. /**
  2676. * Loads a glTF node.
  2677. * @param context The context when loading the asset
  2678. * @param node The glTF node property
  2679. * @param assign A function called synchronously after parsing the glTF properties
  2680. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  2681. */
  2682. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  2683. var _this = this;
  2684. if (assign === void 0) { assign = function () { }; }
  2685. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  2686. if (extensionPromise) {
  2687. return extensionPromise;
  2688. }
  2689. if (node._babylonTransformNode) {
  2690. throw new Error(context + ": Invalid recursive node hierarchy");
  2691. }
  2692. var promises = new Array();
  2693. this.logOpen(context + " " + (node.name || ""));
  2694. var loadNode = function (babylonTransformNode) {
  2695. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  2696. GLTFLoader._LoadTransform(node, babylonTransformNode);
  2697. if (node.camera != undefined) {
  2698. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  2699. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  2700. babylonCamera.parent = babylonTransformNode;
  2701. }));
  2702. }
  2703. if (node.children) {
  2704. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  2705. var index = _a[_i];
  2706. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  2707. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  2708. childBabylonMesh.parent = babylonTransformNode;
  2709. }));
  2710. }
  2711. }
  2712. assign(babylonTransformNode);
  2713. };
  2714. if (node.mesh == undefined) {
  2715. var nodeName = node.name || "node" + node.index;
  2716. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2717. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  2718. this._babylonScene._blockEntityCollection = false;
  2719. loadNode(node._babylonTransformNode);
  2720. }
  2721. else {
  2722. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  2723. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  2724. }
  2725. this.logClose();
  2726. return Promise.all(promises).then(function () {
  2727. _this._forEachPrimitive(node, function (babylonMesh) {
  2728. if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
  2729. // simply apply the world matrices to the bounding info - the extends are already ok
  2730. babylonMesh._updateBoundingInfo();
  2731. }
  2732. else {
  2733. babylonMesh.refreshBoundingInfo(true);
  2734. }
  2735. });
  2736. return node._babylonTransformNode;
  2737. });
  2738. };
  2739. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  2740. var primitives = mesh.primitives;
  2741. if (!primitives || !primitives.length) {
  2742. throw new Error(context + ": Primitives are missing");
  2743. }
  2744. if (primitives[0].index == undefined) {
  2745. ArrayItem.Assign(primitives);
  2746. }
  2747. var promises = new Array();
  2748. this.logOpen(context + " " + (mesh.name || ""));
  2749. var name = node.name || "node" + node.index;
  2750. if (primitives.length === 1) {
  2751. var primitive = mesh.primitives[0];
  2752. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  2753. node._babylonTransformNode = babylonMesh;
  2754. node._primitiveBabylonMeshes = [babylonMesh];
  2755. }));
  2756. }
  2757. else {
  2758. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2759. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  2760. this._babylonScene._blockEntityCollection = false;
  2761. node._primitiveBabylonMeshes = [];
  2762. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  2763. var primitive = primitives_1[_i];
  2764. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  2765. babylonMesh.parent = node._babylonTransformNode;
  2766. node._primitiveBabylonMeshes.push(babylonMesh);
  2767. }));
  2768. }
  2769. }
  2770. if (node.skin != undefined) {
  2771. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  2772. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  2773. }
  2774. assign(node._babylonTransformNode);
  2775. this.logClose();
  2776. return Promise.all(promises).then(function () {
  2777. return node._babylonTransformNode;
  2778. });
  2779. };
  2780. /**
  2781. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  2782. * @param context The context when loading the asset
  2783. * @param name The mesh name when loading the asset
  2784. * @param node The glTF node when loading the asset
  2785. * @param mesh The glTF mesh when loading the asset
  2786. * @param primitive The glTF mesh primitive property
  2787. * @param assign A function called synchronously after parsing the glTF properties
  2788. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  2789. */
  2790. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  2791. var _this = this;
  2792. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  2793. if (extensionPromise) {
  2794. return extensionPromise;
  2795. }
  2796. this.logOpen("" + context);
  2797. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  2798. var babylonAbstractMesh;
  2799. var promise;
  2800. if (shouldInstance && primitive._instanceData) {
  2801. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  2802. promise = primitive._instanceData.promise;
  2803. }
  2804. else {
  2805. var promises = new Array();
  2806. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2807. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  2808. this._babylonScene._blockEntityCollection = false;
  2809. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2810. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  2811. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  2812. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  2813. babylonGeometry.applyToMesh(babylonMesh_1);
  2814. });
  2815. }));
  2816. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  2817. if (primitive.material == undefined) {
  2818. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  2819. if (!babylonMaterial) {
  2820. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  2821. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2822. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  2823. }
  2824. babylonMesh_1.material = babylonMaterial;
  2825. }
  2826. else {
  2827. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  2828. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  2829. babylonMesh_1.material = babylonMaterial;
  2830. }));
  2831. }
  2832. promise = Promise.all(promises);
  2833. if (shouldInstance) {
  2834. primitive._instanceData = {
  2835. babylonSourceMesh: babylonMesh_1,
  2836. promise: promise
  2837. };
  2838. }
  2839. babylonAbstractMesh = babylonMesh_1;
  2840. }
  2841. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  2842. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  2843. assign(babylonAbstractMesh);
  2844. this.logClose();
  2845. return promise.then(function () {
  2846. return babylonAbstractMesh;
  2847. });
  2848. };
  2849. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2850. var _this = this;
  2851. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  2852. if (extensionPromise) {
  2853. return extensionPromise;
  2854. }
  2855. var attributes = primitive.attributes;
  2856. if (!attributes) {
  2857. throw new Error(context + ": Attributes are missing");
  2858. }
  2859. var promises = new Array();
  2860. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  2861. if (primitive.indices == undefined) {
  2862. babylonMesh.isUnIndexed = true;
  2863. }
  2864. else {
  2865. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  2866. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2867. babylonGeometry.setIndices(data);
  2868. }));
  2869. }
  2870. var loadAttribute = function (attribute, kind, callback) {
  2871. if (attributes[attribute] == undefined) {
  2872. return;
  2873. }
  2874. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2875. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2876. babylonMesh._delayInfo.push(kind);
  2877. }
  2878. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2879. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  2880. if (babylonVertexBuffer.getKind() === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
  2881. var mmin = accessor.min, mmax = accessor.max;
  2882. if (mmin !== undefined && mmax !== undefined) {
  2883. var min = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], max = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1];
  2884. min.copyFromFloats.apply(min, mmin);
  2885. max.copyFromFloats.apply(max, mmax);
  2886. babylonGeometry._boundingInfo = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["BoundingInfo"](min, max);
  2887. babylonGeometry.useBoundingInfoFromGeometry = true;
  2888. }
  2889. }
  2890. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  2891. }));
  2892. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  2893. babylonMesh.numBoneInfluencers = 8;
  2894. }
  2895. if (callback) {
  2896. callback(accessor);
  2897. }
  2898. };
  2899. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  2900. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  2901. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  2902. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  2903. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  2904. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  2905. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  2906. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  2907. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  2908. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  2909. if (accessor.type === "VEC4" /* VEC4 */) {
  2910. babylonMesh.hasVertexAlpha = true;
  2911. }
  2912. });
  2913. return Promise.all(promises).then(function () {
  2914. return babylonGeometry;
  2915. });
  2916. };
  2917. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  2918. if (!primitive.targets) {
  2919. return;
  2920. }
  2921. if (node._numMorphTargets == undefined) {
  2922. node._numMorphTargets = primitive.targets.length;
  2923. }
  2924. else if (primitive.targets.length !== node._numMorphTargets) {
  2925. throw new Error(context + ": Primitives do not have the same number of targets");
  2926. }
  2927. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  2928. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  2929. for (var index = 0; index < primitive.targets.length; index++) {
  2930. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  2931. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  2932. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  2933. // TODO: tell the target whether it has positions, normals, tangents
  2934. }
  2935. };
  2936. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  2937. if (!primitive.targets) {
  2938. return Promise.resolve();
  2939. }
  2940. var promises = new Array();
  2941. var morphTargetManager = babylonMesh.morphTargetManager;
  2942. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  2943. var babylonMorphTarget = morphTargetManager.getTarget(index);
  2944. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  2945. }
  2946. return Promise.all(promises).then(function () { });
  2947. };
  2948. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  2949. var _this = this;
  2950. var promises = new Array();
  2951. var loadAttribute = function (attribute, kind, setData) {
  2952. if (attributes[attribute] == undefined) {
  2953. return;
  2954. }
  2955. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  2956. if (!babylonVertexBuffer) {
  2957. return;
  2958. }
  2959. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2960. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2961. setData(babylonVertexBuffer, data);
  2962. }));
  2963. };
  2964. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  2965. var positions = new Float32Array(data.length);
  2966. babylonVertexBuffer.forEach(data.length, function (value, index) {
  2967. positions[index] = data[index] + value;
  2968. });
  2969. babylonMorphTarget.setPositions(positions);
  2970. });
  2971. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  2972. var normals = new Float32Array(data.length);
  2973. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  2974. normals[index] = data[index] + value;
  2975. });
  2976. babylonMorphTarget.setNormals(normals);
  2977. });
  2978. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  2979. var tangents = new Float32Array(data.length / 3 * 4);
  2980. var dataIndex = 0;
  2981. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  2982. // Tangent data for morph targets is stored as xyz delta.
  2983. // The vertexData.tangent is stored as xyzw.
  2984. // So we need to skip every fourth vertexData.tangent.
  2985. if (((index + 1) % 4) !== 0) {
  2986. tangents[dataIndex] = data[dataIndex] + value;
  2987. dataIndex++;
  2988. }
  2989. });
  2990. babylonMorphTarget.setTangents(tangents);
  2991. });
  2992. return Promise.all(promises).then(function () { });
  2993. };
  2994. GLTFLoader._LoadTransform = function (node, babylonNode) {
  2995. // Ignore the TRS of skinned nodes.
  2996. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  2997. if (node.skin != undefined) {
  2998. return;
  2999. }
  3000. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  3001. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  3002. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  3003. if (node.matrix) {
  3004. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  3005. matrix.decompose(scaling, rotation, position);
  3006. }
  3007. else {
  3008. if (node.translation) {
  3009. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  3010. }
  3011. if (node.rotation) {
  3012. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  3013. }
  3014. if (node.scale) {
  3015. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  3016. }
  3017. }
  3018. babylonNode.position = position;
  3019. babylonNode.rotationQuaternion = rotation;
  3020. babylonNode.scaling = scaling;
  3021. };
  3022. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  3023. var _this = this;
  3024. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  3025. if (extensionPromise) {
  3026. return extensionPromise;
  3027. }
  3028. var assignSkeleton = function (skeleton) {
  3029. _this._forEachPrimitive(node, function (babylonMesh) {
  3030. babylonMesh.skeleton = skeleton;
  3031. });
  3032. };
  3033. if (skin._data) {
  3034. assignSkeleton(skin._data.babylonSkeleton);
  3035. return skin._data.promise;
  3036. }
  3037. var skeletonId = "skeleton" + skin.index;
  3038. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3039. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  3040. this._babylonScene._blockEntityCollection = false;
  3041. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  3042. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  3043. this._loadBones(context, skin, babylonSkeleton);
  3044. assignSkeleton(babylonSkeleton);
  3045. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  3046. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  3047. });
  3048. skin._data = {
  3049. babylonSkeleton: babylonSkeleton,
  3050. promise: promise
  3051. };
  3052. return promise;
  3053. };
  3054. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  3055. var babylonBones = {};
  3056. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  3057. var index = _a[_i];
  3058. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  3059. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  3060. }
  3061. };
  3062. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  3063. var babylonBone = babylonBones[node.index];
  3064. if (babylonBone) {
  3065. return babylonBone;
  3066. }
  3067. var babylonParentBone = null;
  3068. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  3069. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  3070. }
  3071. var boneIndex = skin.joints.indexOf(node.index);
  3072. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  3073. babylonBones[node.index] = babylonBone;
  3074. node._babylonBones = node._babylonBones || [];
  3075. node._babylonBones.push(babylonBone);
  3076. return babylonBone;
  3077. };
  3078. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  3079. if (skin.inverseBindMatrices == undefined) {
  3080. return Promise.resolve(null);
  3081. }
  3082. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  3083. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  3084. };
  3085. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  3086. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  3087. var babylonBone = _a[_i];
  3088. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  3089. var boneIndex = babylonBone._index;
  3090. if (inverseBindMatricesData && boneIndex !== -1) {
  3091. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  3092. baseMatrix.invertToRef(baseMatrix);
  3093. }
  3094. var babylonParentBone = babylonBone.getParent();
  3095. if (babylonParentBone) {
  3096. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  3097. }
  3098. babylonBone.updateMatrix(baseMatrix, false, false);
  3099. babylonBone._updateDifferenceMatrix(undefined, false);
  3100. }
  3101. };
  3102. GLTFLoader.prototype._getNodeMatrix = function (node) {
  3103. return node.matrix ?
  3104. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  3105. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Compose(node.scale ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One(), node.rotation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity(), node.translation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero());
  3106. };
  3107. /**
  3108. * Loads a glTF camera.
  3109. * @param context The context when loading the asset
  3110. * @param camera The glTF camera property
  3111. * @param assign A function called synchronously after parsing the glTF properties
  3112. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3113. */
  3114. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  3115. if (assign === void 0) { assign = function () { }; }
  3116. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  3117. if (extensionPromise) {
  3118. return extensionPromise;
  3119. }
  3120. var promises = new Array();
  3121. this.logOpen(context + " " + (camera.name || ""));
  3122. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3123. var babylonCamera = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["FreeCamera"](camera.name || "camera" + camera.index, babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), this._babylonScene, false);
  3124. this._babylonScene._blockEntityCollection = false;
  3125. babylonCamera.ignoreParentScaling = true;
  3126. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  3127. switch (camera.type) {
  3128. case "perspective" /* PERSPECTIVE */: {
  3129. var perspective = camera.perspective;
  3130. if (!perspective) {
  3131. throw new Error(context + ": Camera perspective properties are missing");
  3132. }
  3133. babylonCamera.fov = perspective.yfov;
  3134. babylonCamera.minZ = perspective.znear;
  3135. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  3136. break;
  3137. }
  3138. case "orthographic" /* ORTHOGRAPHIC */: {
  3139. if (!camera.orthographic) {
  3140. throw new Error(context + ": Camera orthographic properties are missing");
  3141. }
  3142. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  3143. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  3144. babylonCamera.orthoRight = camera.orthographic.xmag;
  3145. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  3146. babylonCamera.orthoTop = camera.orthographic.ymag;
  3147. babylonCamera.minZ = camera.orthographic.znear;
  3148. babylonCamera.maxZ = camera.orthographic.zfar;
  3149. break;
  3150. }
  3151. default: {
  3152. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  3153. }
  3154. }
  3155. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  3156. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  3157. assign(babylonCamera);
  3158. this.logClose();
  3159. return Promise.all(promises).then(function () {
  3160. return babylonCamera;
  3161. });
  3162. };
  3163. GLTFLoader.prototype._loadAnimationsAsync = function () {
  3164. var animations = this._gltf.animations;
  3165. if (!animations) {
  3166. return Promise.resolve();
  3167. }
  3168. var promises = new Array();
  3169. for (var index = 0; index < animations.length; index++) {
  3170. var animation = animations[index];
  3171. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  3172. }
  3173. return Promise.all(promises).then(function () { });
  3174. };
  3175. /**
  3176. * Loads a glTF animation.
  3177. * @param context The context when loading the asset
  3178. * @param animation The glTF animation property
  3179. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3180. */
  3181. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  3182. var promise = this._extensionsLoadAnimationAsync(context, animation);
  3183. if (promise) {
  3184. return promise;
  3185. }
  3186. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3187. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  3188. this._babylonScene._blockEntityCollection = false;
  3189. animation._babylonAnimationGroup = babylonAnimationGroup;
  3190. var promises = new Array();
  3191. ArrayItem.Assign(animation.channels);
  3192. ArrayItem.Assign(animation.samplers);
  3193. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  3194. var channel = _a[_i];
  3195. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  3196. }
  3197. return Promise.all(promises).then(function () {
  3198. babylonAnimationGroup.normalize(0);
  3199. return babylonAnimationGroup;
  3200. });
  3201. };
  3202. /**
  3203. * @hidden Loads a glTF animation channel.
  3204. * @param context The context when loading the asset
  3205. * @param animationContext The context of the animation when loading the asset
  3206. * @param animation The glTF animation property
  3207. * @param channel The glTF animation channel property
  3208. * @param babylonAnimationGroup The babylon animation group property
  3209. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3210. * @returns A void promise when the channel load is complete
  3211. */
  3212. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  3213. var _this = this;
  3214. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  3215. if (channel.target.node == undefined) {
  3216. return Promise.resolve();
  3217. }
  3218. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  3219. // Ignore animations that have no animation targets.
  3220. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  3221. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  3222. return Promise.resolve();
  3223. }
  3224. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  3225. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  3226. var targetPath;
  3227. var animationType;
  3228. switch (channel.target.path) {
  3229. case "translation" /* TRANSLATION */: {
  3230. targetPath = "position";
  3231. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3232. break;
  3233. }
  3234. case "rotation" /* ROTATION */: {
  3235. targetPath = "rotationQuaternion";
  3236. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  3237. break;
  3238. }
  3239. case "scale" /* SCALE */: {
  3240. targetPath = "scaling";
  3241. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3242. break;
  3243. }
  3244. case "weights" /* WEIGHTS */: {
  3245. targetPath = "influence";
  3246. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  3247. break;
  3248. }
  3249. default: {
  3250. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  3251. }
  3252. }
  3253. var outputBufferOffset = 0;
  3254. var getNextOutputValue;
  3255. switch (targetPath) {
  3256. case "position": {
  3257. getNextOutputValue = function () {
  3258. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3259. outputBufferOffset += 3;
  3260. return value;
  3261. };
  3262. break;
  3263. }
  3264. case "rotationQuaternion": {
  3265. getNextOutputValue = function () {
  3266. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  3267. outputBufferOffset += 4;
  3268. return value;
  3269. };
  3270. break;
  3271. }
  3272. case "scaling": {
  3273. getNextOutputValue = function () {
  3274. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3275. outputBufferOffset += 3;
  3276. return value;
  3277. };
  3278. break;
  3279. }
  3280. case "influence": {
  3281. getNextOutputValue = function () {
  3282. var value = new Array(targetNode._numMorphTargets);
  3283. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  3284. value[i] = data.output[outputBufferOffset++];
  3285. }
  3286. return value;
  3287. };
  3288. break;
  3289. }
  3290. }
  3291. var getNextKey;
  3292. switch (data.interpolation) {
  3293. case "STEP" /* STEP */: {
  3294. getNextKey = function (frameIndex) { return ({
  3295. frame: data.input[frameIndex],
  3296. value: getNextOutputValue(),
  3297. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  3298. }); };
  3299. break;
  3300. }
  3301. case "LINEAR" /* LINEAR */: {
  3302. getNextKey = function (frameIndex) { return ({
  3303. frame: data.input[frameIndex],
  3304. value: getNextOutputValue()
  3305. }); };
  3306. break;
  3307. }
  3308. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3309. getNextKey = function (frameIndex) { return ({
  3310. frame: data.input[frameIndex],
  3311. inTangent: getNextOutputValue(),
  3312. value: getNextOutputValue(),
  3313. outTangent: getNextOutputValue()
  3314. }); };
  3315. break;
  3316. }
  3317. }
  3318. var keys = new Array(data.input.length);
  3319. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  3320. keys[frameIndex] = getNextKey(frameIndex);
  3321. }
  3322. if (targetPath === "influence") {
  3323. var _loop_2 = function (targetIndex) {
  3324. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3325. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3326. babylonAnimation.setKeys(keys.map(function (key) { return ({
  3327. frame: key.frame,
  3328. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  3329. value: key.value[targetIndex],
  3330. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  3331. }); }));
  3332. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  3333. var babylonMesh = babylonAbstractMesh;
  3334. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  3335. var babylonAnimationClone = babylonAnimation.clone();
  3336. morphTarget.animations.push(babylonAnimationClone);
  3337. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  3338. });
  3339. };
  3340. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  3341. _loop_2(targetIndex);
  3342. }
  3343. }
  3344. else {
  3345. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3346. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3347. babylonAnimation.setKeys(keys);
  3348. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  3349. animationTargetOverride.animations.push(babylonAnimation);
  3350. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  3351. }
  3352. else {
  3353. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  3354. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  3355. }
  3356. }
  3357. });
  3358. };
  3359. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  3360. if (sampler._data) {
  3361. return sampler._data;
  3362. }
  3363. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  3364. switch (interpolation) {
  3365. case "STEP" /* STEP */:
  3366. case "LINEAR" /* LINEAR */:
  3367. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3368. break;
  3369. }
  3370. default: {
  3371. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  3372. }
  3373. }
  3374. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  3375. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  3376. sampler._data = Promise.all([
  3377. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  3378. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  3379. ]).then(function (_a) {
  3380. var inputData = _a[0], outputData = _a[1];
  3381. return {
  3382. input: inputData,
  3383. interpolation: interpolation,
  3384. output: outputData,
  3385. };
  3386. });
  3387. return sampler._data;
  3388. };
  3389. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  3390. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  3391. if (extensionPromise) {
  3392. return extensionPromise;
  3393. }
  3394. if (!buffer._data) {
  3395. if (buffer.uri) {
  3396. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  3397. }
  3398. else {
  3399. if (!this._bin) {
  3400. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  3401. }
  3402. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  3403. }
  3404. }
  3405. return buffer._data.then(function (data) {
  3406. try {
  3407. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  3408. }
  3409. catch (e) {
  3410. throw new Error(context + ": " + e.message);
  3411. }
  3412. });
  3413. };
  3414. /**
  3415. * Loads a glTF buffer view.
  3416. * @param context The context when loading the asset
  3417. * @param bufferView The glTF buffer view property
  3418. * @returns A promise that resolves with the loaded data when the load is complete
  3419. */
  3420. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  3421. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  3422. if (extensionPromise) {
  3423. return extensionPromise;
  3424. }
  3425. if (bufferView._data) {
  3426. return bufferView._data;
  3427. }
  3428. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  3429. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  3430. return bufferView._data;
  3431. };
  3432. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  3433. var _this = this;
  3434. if (accessor._data) {
  3435. return accessor._data;
  3436. }
  3437. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  3438. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  3439. var length = numComponents * accessor.count;
  3440. if (accessor.bufferView == undefined) {
  3441. accessor._data = Promise.resolve(new constructor(length));
  3442. }
  3443. else {
  3444. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3445. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  3446. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3447. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  3448. }
  3449. else {
  3450. var typedArray_1 = new constructor(length);
  3451. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
  3452. typedArray_1[index] = value;
  3453. });
  3454. return typedArray_1;
  3455. }
  3456. });
  3457. }
  3458. if (accessor.sparse) {
  3459. var sparse_1 = accessor.sparse;
  3460. accessor._data = accessor._data.then(function (data) {
  3461. var typedArray = data;
  3462. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  3463. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  3464. return Promise.all([
  3465. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  3466. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  3467. ]).then(function (_a) {
  3468. var indicesData = _a[0], valuesData = _a[1];
  3469. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  3470. var sparseLength = numComponents * sparse_1.count;
  3471. var values;
  3472. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3473. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3474. }
  3475. else {
  3476. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3477. values = new constructor(sparseLength);
  3478. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  3479. values[index] = value;
  3480. });
  3481. }
  3482. var valuesIndex = 0;
  3483. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  3484. var dataIndex = indices[indicesIndex] * numComponents;
  3485. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  3486. typedArray[dataIndex++] = values[valuesIndex++];
  3487. }
  3488. }
  3489. return typedArray;
  3490. });
  3491. });
  3492. }
  3493. return accessor._data;
  3494. };
  3495. /** @hidden */
  3496. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  3497. return this._loadAccessorAsync(context, accessor, Float32Array);
  3498. };
  3499. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  3500. if (accessor.type !== "SCALAR" /* SCALAR */) {
  3501. throw new Error(context + "/type: Invalid value " + accessor.type);
  3502. }
  3503. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  3504. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  3505. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  3506. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  3507. }
  3508. if (accessor._data) {
  3509. return accessor._data;
  3510. }
  3511. if (accessor.sparse) {
  3512. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  3513. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  3514. }
  3515. else {
  3516. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3517. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3518. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  3519. });
  3520. }
  3521. return accessor._data;
  3522. };
  3523. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  3524. var _this = this;
  3525. if (bufferView._babylonBuffer) {
  3526. return bufferView._babylonBuffer;
  3527. }
  3528. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3529. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  3530. });
  3531. return bufferView._babylonBuffer;
  3532. };
  3533. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  3534. var _this = this;
  3535. if (accessor._babylonVertexBuffer) {
  3536. return accessor._babylonVertexBuffer;
  3537. }
  3538. if (accessor.sparse) {
  3539. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3540. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3541. });
  3542. }
  3543. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  3544. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  3545. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  3546. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3547. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3548. });
  3549. }
  3550. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  3551. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  3552. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  3553. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3554. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3555. });
  3556. }
  3557. else {
  3558. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3559. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  3560. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  3561. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  3562. });
  3563. }
  3564. return accessor._babylonVertexBuffer;
  3565. };
  3566. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  3567. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3568. throw new Error(context + ": Material type not supported");
  3569. }
  3570. var promises = new Array();
  3571. if (properties) {
  3572. if (properties.baseColorFactor) {
  3573. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  3574. babylonMaterial.alpha = properties.baseColorFactor[3];
  3575. }
  3576. else {
  3577. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3578. }
  3579. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  3580. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  3581. if (properties.baseColorTexture) {
  3582. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  3583. texture.name = babylonMaterial.name + " (Base Color)";
  3584. babylonMaterial.albedoTexture = texture;
  3585. }));
  3586. }
  3587. if (properties.metallicRoughnessTexture) {
  3588. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  3589. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  3590. babylonMaterial.metallicTexture = texture;
  3591. }));
  3592. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  3593. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  3594. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  3595. }
  3596. }
  3597. return Promise.all(promises).then(function () { });
  3598. };
  3599. /** @hidden */
  3600. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3601. if (assign === void 0) { assign = function () { }; }
  3602. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  3603. if (extensionPromise) {
  3604. return extensionPromise;
  3605. }
  3606. material._data = material._data || {};
  3607. var babylonData = material._data[babylonDrawMode];
  3608. if (!babylonData) {
  3609. this.logOpen(context + " " + (material.name || ""));
  3610. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  3611. babylonData = {
  3612. babylonMaterial: babylonMaterial,
  3613. babylonMeshes: [],
  3614. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  3615. };
  3616. material._data[babylonDrawMode] = babylonData;
  3617. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  3618. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  3619. this.logClose();
  3620. }
  3621. babylonData.babylonMeshes.push(babylonMesh);
  3622. babylonMesh.onDisposeObservable.addOnce(function () {
  3623. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  3624. if (index !== -1) {
  3625. babylonData.babylonMeshes.splice(index, 1);
  3626. }
  3627. });
  3628. assign(babylonData.babylonMaterial);
  3629. return babylonData.promise.then(function () {
  3630. return babylonData.babylonMaterial;
  3631. });
  3632. };
  3633. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  3634. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3635. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  3636. this._babylonScene._blockEntityCollection = false;
  3637. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  3638. babylonMaterial.fillMode = babylonDrawMode;
  3639. babylonMaterial.enableSpecularAntiAliasing = true;
  3640. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  3641. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  3642. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3643. babylonMaterial.metallic = 1;
  3644. babylonMaterial.roughness = 1;
  3645. return babylonMaterial;
  3646. };
  3647. /**
  3648. * Creates a Babylon material from a glTF material.
  3649. * @param context The context when loading the asset
  3650. * @param material The glTF material property
  3651. * @param babylonDrawMode The draw mode for the Babylon material
  3652. * @returns The Babylon material
  3653. */
  3654. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  3655. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  3656. if (extensionPromise) {
  3657. return extensionPromise;
  3658. }
  3659. var name = material.name || "material" + material.index;
  3660. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  3661. return babylonMaterial;
  3662. };
  3663. /**
  3664. * Loads properties from a glTF material into a Babylon material.
  3665. * @param context The context when loading the asset
  3666. * @param material The glTF material property
  3667. * @param babylonMaterial The Babylon material
  3668. * @returns A promise that resolves when the load is complete
  3669. */
  3670. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3671. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  3672. if (extensionPromise) {
  3673. return extensionPromise;
  3674. }
  3675. var promises = new Array();
  3676. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  3677. if (material.pbrMetallicRoughness) {
  3678. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  3679. }
  3680. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  3681. return Promise.all(promises).then(function () { });
  3682. };
  3683. /**
  3684. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3685. * @param context The context when loading the asset
  3686. * @param material The glTF material property
  3687. * @param babylonMaterial The Babylon material
  3688. * @returns A promise that resolves when the load is complete
  3689. */
  3690. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  3691. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3692. throw new Error(context + ": Material type not supported");
  3693. }
  3694. var promises = new Array();
  3695. babylonMaterial.emissiveColor = material.emissiveFactor ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(material.emissiveFactor) : new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"](0, 0, 0);
  3696. if (material.doubleSided) {
  3697. babylonMaterial.backFaceCulling = false;
  3698. babylonMaterial.twoSidedLighting = true;
  3699. }
  3700. if (material.normalTexture) {
  3701. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  3702. texture.name = babylonMaterial.name + " (Normal)";
  3703. babylonMaterial.bumpTexture = texture;
  3704. }));
  3705. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  3706. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  3707. if (material.normalTexture.scale != undefined) {
  3708. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  3709. }
  3710. babylonMaterial.forceIrradianceInFragment = true;
  3711. }
  3712. if (material.occlusionTexture) {
  3713. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  3714. texture.name = babylonMaterial.name + " (Occlusion)";
  3715. babylonMaterial.ambientTexture = texture;
  3716. }));
  3717. babylonMaterial.useAmbientInGrayScale = true;
  3718. if (material.occlusionTexture.strength != undefined) {
  3719. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  3720. }
  3721. }
  3722. if (material.emissiveTexture) {
  3723. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  3724. texture.name = babylonMaterial.name + " (Emissive)";
  3725. babylonMaterial.emissiveTexture = texture;
  3726. }));
  3727. }
  3728. return Promise.all(promises).then(function () { });
  3729. };
  3730. /**
  3731. * Loads the alpha properties from a glTF material into a Babylon material.
  3732. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3733. * @param context The context when loading the asset
  3734. * @param material The glTF material property
  3735. * @param babylonMaterial The Babylon material
  3736. */
  3737. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  3738. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3739. throw new Error(context + ": Material type not supported");
  3740. }
  3741. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  3742. switch (alphaMode) {
  3743. case "OPAQUE" /* OPAQUE */: {
  3744. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3745. break;
  3746. }
  3747. case "MASK" /* MASK */: {
  3748. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  3749. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  3750. if (babylonMaterial.albedoTexture) {
  3751. babylonMaterial.albedoTexture.hasAlpha = true;
  3752. }
  3753. break;
  3754. }
  3755. case "BLEND" /* BLEND */: {
  3756. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  3757. if (babylonMaterial.albedoTexture) {
  3758. babylonMaterial.albedoTexture.hasAlpha = true;
  3759. babylonMaterial.useAlphaFromAlbedoTexture = true;
  3760. }
  3761. break;
  3762. }
  3763. default: {
  3764. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  3765. }
  3766. }
  3767. };
  3768. /**
  3769. * Loads a glTF texture info.
  3770. * @param context The context when loading the asset
  3771. * @param textureInfo The glTF texture info property
  3772. * @param assign A function called synchronously after parsing the glTF properties
  3773. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3774. */
  3775. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  3776. var _this = this;
  3777. if (assign === void 0) { assign = function () { }; }
  3778. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  3779. if (extensionPromise) {
  3780. return extensionPromise;
  3781. }
  3782. this.logOpen("" + context);
  3783. if (textureInfo.texCoord >= 2) {
  3784. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  3785. }
  3786. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  3787. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  3788. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  3789. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  3790. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  3791. assign(babylonTexture);
  3792. });
  3793. this.logClose();
  3794. return promise;
  3795. };
  3796. /** @hidden */
  3797. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  3798. if (assign === void 0) { assign = function () { }; }
  3799. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  3800. if (extensionPromise) {
  3801. return extensionPromise;
  3802. }
  3803. this.logOpen(context + " " + (texture.name || ""));
  3804. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  3805. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  3806. var promise = this._createTextureAsync(context, sampler, image, assign);
  3807. this.logClose();
  3808. return promise;
  3809. };
  3810. /** @hidden */
  3811. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  3812. var _this = this;
  3813. if (assign === void 0) { assign = function () { }; }
  3814. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  3815. var promises = new Array();
  3816. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3817. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3818. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  3819. if (!_this._disposed) {
  3820. deferred.resolve();
  3821. }
  3822. }, function (message, exception) {
  3823. if (!_this._disposed) {
  3824. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  3825. }
  3826. }, undefined, undefined, undefined, image.mimeType);
  3827. this._babylonScene._blockEntityCollection = false;
  3828. promises.push(deferred.promise);
  3829. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  3830. var name = image.uri || _this._fileName + "#image" + image.index;
  3831. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  3832. babylonTexture.updateURL(dataUrl, data);
  3833. }));
  3834. babylonTexture.wrapU = samplerData.wrapU;
  3835. babylonTexture.wrapV = samplerData.wrapV;
  3836. assign(babylonTexture);
  3837. return Promise.all(promises).then(function () {
  3838. return babylonTexture;
  3839. });
  3840. };
  3841. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  3842. if (!sampler._data) {
  3843. sampler._data = {
  3844. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  3845. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  3846. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  3847. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  3848. };
  3849. }
  3850. return sampler._data;
  3851. };
  3852. /**
  3853. * Loads a glTF image.
  3854. * @param context The context when loading the asset
  3855. * @param image The glTF image property
  3856. * @returns A promise that resolves with the loaded data when the load is complete
  3857. */
  3858. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  3859. if (!image._data) {
  3860. this.logOpen(context + " " + (image.name || ""));
  3861. if (image.uri) {
  3862. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  3863. }
  3864. else {
  3865. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  3866. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  3867. }
  3868. this.logClose();
  3869. }
  3870. return image._data;
  3871. };
  3872. /**
  3873. * Loads a glTF uri.
  3874. * @param context The context when loading the asset
  3875. * @param property The glTF property associated with the uri
  3876. * @param uri The base64 or relative uri
  3877. * @returns A promise that resolves with the loaded data when the load is complete
  3878. */
  3879. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  3880. var _this = this;
  3881. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  3882. if (extensionPromise) {
  3883. return extensionPromise;
  3884. }
  3885. if (!GLTFLoader._ValidateUri(uri)) {
  3886. throw new Error(context + ": '" + uri + "' is invalid");
  3887. }
  3888. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  3889. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  3890. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  3891. return Promise.resolve(data);
  3892. }
  3893. this.log("Loading " + uri);
  3894. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  3895. return new Promise(function (resolve, reject) {
  3896. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  3897. if (!_this._disposed) {
  3898. _this.log("Loaded " + uri + " (" + data.byteLength + " bytes)");
  3899. resolve(new Uint8Array(data));
  3900. }
  3901. }, true, function (request) {
  3902. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  3903. });
  3904. });
  3905. });
  3906. };
  3907. /**
  3908. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3909. * @param babylonObject the Babylon object with metadata
  3910. * @param pointer the JSON pointer
  3911. */
  3912. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  3913. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  3914. var gltf = (metadata.gltf = metadata.gltf || {});
  3915. var pointers = (gltf.pointers = gltf.pointers || []);
  3916. pointers.push(pointer);
  3917. };
  3918. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  3919. // Set defaults if undefined
  3920. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  3921. switch (mode) {
  3922. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  3923. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  3924. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3925. default:
  3926. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  3927. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3928. }
  3929. };
  3930. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  3931. // Set defaults if undefined
  3932. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  3933. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  3934. if (magFilter === 9729 /* LINEAR */) {
  3935. switch (minFilter) {
  3936. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  3937. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  3938. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  3939. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  3940. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  3941. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3942. default:
  3943. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3944. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3945. }
  3946. }
  3947. else {
  3948. if (magFilter !== 9728 /* NEAREST */) {
  3949. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  3950. }
  3951. switch (minFilter) {
  3952. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  3953. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  3954. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3955. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  3956. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  3957. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  3958. default:
  3959. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3960. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3961. }
  3962. }
  3963. };
  3964. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  3965. switch (componentType) {
  3966. case 5120 /* BYTE */: return Int8Array;
  3967. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  3968. case 5122 /* SHORT */: return Int16Array;
  3969. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  3970. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  3971. case 5126 /* FLOAT */: return Float32Array;
  3972. default: throw new Error(context + ": Invalid component type " + componentType);
  3973. }
  3974. };
  3975. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  3976. var buffer = bufferView.buffer;
  3977. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  3978. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  3979. try {
  3980. return new constructor(buffer, byteOffset, length);
  3981. }
  3982. catch (e) {
  3983. throw new Error(context + ": " + e);
  3984. }
  3985. };
  3986. GLTFLoader._GetNumComponents = function (context, type) {
  3987. switch (type) {
  3988. case "SCALAR": return 1;
  3989. case "VEC2": return 2;
  3990. case "VEC3": return 3;
  3991. case "VEC4": return 4;
  3992. case "MAT2": return 4;
  3993. case "MAT3": return 9;
  3994. case "MAT4": return 16;
  3995. }
  3996. throw new Error(context + ": Invalid type (" + type + ")");
  3997. };
  3998. GLTFLoader._ValidateUri = function (uri) {
  3999. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  4000. };
  4001. /** @hidden */
  4002. GLTFLoader._GetDrawMode = function (context, mode) {
  4003. if (mode == undefined) {
  4004. mode = 4 /* TRIANGLES */;
  4005. }
  4006. switch (mode) {
  4007. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  4008. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  4009. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  4010. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  4011. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  4012. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  4013. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  4014. }
  4015. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  4016. };
  4017. GLTFLoader.prototype._compileMaterialsAsync = function () {
  4018. var _this = this;
  4019. this._parent._startPerformanceCounter("Compile materials");
  4020. var promises = new Array();
  4021. if (this._gltf.materials) {
  4022. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  4023. var material = _a[_i];
  4024. if (material._data) {
  4025. for (var babylonDrawMode in material._data) {
  4026. var babylonData = material._data[babylonDrawMode];
  4027. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  4028. var babylonMesh = _c[_b];
  4029. // Ensure nonUniformScaling is set if necessary.
  4030. babylonMesh.computeWorldMatrix(true);
  4031. var babylonMaterial = babylonData.babylonMaterial;
  4032. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  4033. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  4034. if (this._parent.useClipPlane) {
  4035. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  4036. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  4037. }
  4038. }
  4039. }
  4040. }
  4041. }
  4042. }
  4043. return Promise.all(promises).then(function () {
  4044. _this._parent._endPerformanceCounter("Compile materials");
  4045. });
  4046. };
  4047. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  4048. var _this = this;
  4049. this._parent._startPerformanceCounter("Compile shadow generators");
  4050. var promises = new Array();
  4051. var lights = this._babylonScene.lights;
  4052. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  4053. var light = lights_1[_i];
  4054. var generator = light.getShadowGenerator();
  4055. if (generator) {
  4056. promises.push(generator.forceCompilationAsync());
  4057. }
  4058. }
  4059. return Promise.all(promises).then(function () {
  4060. _this._parent._endPerformanceCounter("Compile shadow generators");
  4061. });
  4062. };
  4063. GLTFLoader.prototype._forEachExtensions = function (action) {
  4064. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4065. var extension = _a[_i];
  4066. if (extension.enabled) {
  4067. action(extension);
  4068. }
  4069. }
  4070. };
  4071. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  4072. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4073. var extension = _a[_i];
  4074. if (extension.enabled) {
  4075. var id = extension.name + "." + functionName;
  4076. var loaderProperty = property;
  4077. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  4078. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  4079. if (!activeLoaderExtensionFunctions[id]) {
  4080. activeLoaderExtensionFunctions[id] = true;
  4081. try {
  4082. var result = actionAsync(extension);
  4083. if (result) {
  4084. return result;
  4085. }
  4086. }
  4087. finally {
  4088. delete activeLoaderExtensionFunctions[id];
  4089. }
  4090. }
  4091. }
  4092. }
  4093. return null;
  4094. };
  4095. GLTFLoader.prototype._extensionsOnLoading = function () {
  4096. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  4097. };
  4098. GLTFLoader.prototype._extensionsOnReady = function () {
  4099. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  4100. };
  4101. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  4102. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  4103. };
  4104. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  4105. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  4106. };
  4107. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  4108. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  4109. };
  4110. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  4111. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  4112. };
  4113. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4114. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  4115. };
  4116. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  4117. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  4118. };
  4119. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  4120. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  4121. };
  4122. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4123. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  4124. };
  4125. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  4126. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  4127. };
  4128. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  4129. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  4130. };
  4131. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  4132. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  4133. };
  4134. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  4135. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  4136. };
  4137. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  4138. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  4139. };
  4140. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  4141. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  4142. };
  4143. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  4144. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  4145. };
  4146. /**
  4147. * Helper method called by a loader extension to load an glTF extension.
  4148. * @param context The context when loading the asset
  4149. * @param property The glTF property to load the extension from
  4150. * @param extensionName The name of the extension to load
  4151. * @param actionAsync The action to run
  4152. * @returns The promise returned by actionAsync or null if the extension does not exist
  4153. */
  4154. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  4155. if (!property.extensions) {
  4156. return null;
  4157. }
  4158. var extensions = property.extensions;
  4159. var extension = extensions[extensionName];
  4160. if (!extension) {
  4161. return null;
  4162. }
  4163. return actionAsync(context + "/extensions/" + extensionName, extension);
  4164. };
  4165. /**
  4166. * Helper method called by a loader extension to load a glTF extra.
  4167. * @param context The context when loading the asset
  4168. * @param property The glTF property to load the extra from
  4169. * @param extensionName The name of the extension to load
  4170. * @param actionAsync The action to run
  4171. * @returns The promise returned by actionAsync or null if the extra does not exist
  4172. */
  4173. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  4174. if (!property.extras) {
  4175. return null;
  4176. }
  4177. var extras = property.extras;
  4178. var extra = extras[extensionName];
  4179. if (!extra) {
  4180. return null;
  4181. }
  4182. return actionAsync(context + "/extras/" + extensionName, extra);
  4183. };
  4184. /**
  4185. * Checks for presence of an extension.
  4186. * @param name The name of the extension to check
  4187. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4188. */
  4189. GLTFLoader.prototype.isExtensionUsed = function (name) {
  4190. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  4191. };
  4192. /**
  4193. * Increments the indentation level and logs a message.
  4194. * @param message The message to log
  4195. */
  4196. GLTFLoader.prototype.logOpen = function (message) {
  4197. this._parent._logOpen(message);
  4198. };
  4199. /**
  4200. * Decrements the indentation level.
  4201. */
  4202. GLTFLoader.prototype.logClose = function () {
  4203. this._parent._logClose();
  4204. };
  4205. /**
  4206. * Logs a message
  4207. * @param message The message to log
  4208. */
  4209. GLTFLoader.prototype.log = function (message) {
  4210. this._parent._log(message);
  4211. };
  4212. /**
  4213. * Starts a performance counter.
  4214. * @param counterName The name of the performance counter
  4215. */
  4216. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  4217. this._parent._startPerformanceCounter(counterName);
  4218. };
  4219. /**
  4220. * Ends a performance counter.
  4221. * @param counterName The name of the performance counter
  4222. */
  4223. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  4224. this._parent._endPerformanceCounter(counterName);
  4225. };
  4226. GLTFLoader._RegisteredExtensions = {};
  4227. /**
  4228. * The default glTF sampler.
  4229. */
  4230. GLTFLoader.DefaultSampler = { index: -1 };
  4231. return GLTFLoader;
  4232. }());
  4233. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  4234. /***/ }),
  4235. /***/ "./glTF/2.0/glTFLoaderExtension.ts":
  4236. /*!*****************************************!*\
  4237. !*** ./glTF/2.0/glTFLoaderExtension.ts ***!
  4238. \*****************************************/
  4239. /*! no static exports found */
  4240. /***/ (function(module, exports) {
  4241. /***/ }),
  4242. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  4243. /*!******************************************!*\
  4244. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  4245. \******************************************/
  4246. /*! no static exports found */
  4247. /***/ (function(module, exports) {
  4248. /***/ }),
  4249. /***/ "./glTF/2.0/index.ts":
  4250. /*!***************************!*\
  4251. !*** ./glTF/2.0/index.ts ***!
  4252. \***************************/
  4253. /*! no static exports found */
  4254. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4255. "use strict";
  4256. __webpack_require__.r(__webpack_exports__);
  4257. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4258. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  4259. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  4260. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoaderExtension */ "./glTF/2.0/glTFLoaderExtension.ts");
  4261. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__);
  4262. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4263. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  4264. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__);
  4265. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4266. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  4267. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_lights_image_based"]; });
  4268. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_mesh_gpu_instancing"]; });
  4269. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_draco_mesh_compression"]; });
  4270. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  4271. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  4272. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  4273. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_clearcoat"]; });
  4274. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_sheen"]; });
  4275. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_specular"]; });
  4276. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_ior"]; });
  4277. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_variants"]; });
  4278. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_transmission"]; });
  4279. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_mesh_quantization"]; });
  4280. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_basisu"]; });
  4281. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_transform"]; });
  4282. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_xmp"]; });
  4283. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_audio_emitter"]; });
  4284. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_lod"]; });
  4285. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_minecraftMesh"]; });
  4286. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_sRGBFactors"]; });
  4287. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["ExtrasAsMetadata"]; });
  4288. /***/ }),
  4289. /***/ "./glTF/glTFFileLoader.ts":
  4290. /*!********************************!*\
  4291. !*** ./glTF/glTFFileLoader.ts ***!
  4292. \********************************/
  4293. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4294. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4295. "use strict";
  4296. __webpack_require__.r(__webpack_exports__);
  4297. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  4298. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  4299. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  4300. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  4301. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  4302. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4303. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  4304. /**
  4305. * Mode that determines the coordinate system to use.
  4306. */
  4307. var GLTFLoaderCoordinateSystemMode;
  4308. (function (GLTFLoaderCoordinateSystemMode) {
  4309. /**
  4310. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  4311. */
  4312. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  4313. /**
  4314. * Sets the useRightHandedSystem flag on the scene.
  4315. */
  4316. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  4317. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  4318. /**
  4319. * Mode that determines what animations will start.
  4320. */
  4321. var GLTFLoaderAnimationStartMode;
  4322. (function (GLTFLoaderAnimationStartMode) {
  4323. /**
  4324. * No animation will start.
  4325. */
  4326. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  4327. /**
  4328. * The first animation will start.
  4329. */
  4330. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  4331. /**
  4332. * All animations will start.
  4333. */
  4334. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  4335. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  4336. /**
  4337. * Loader state.
  4338. */
  4339. var GLTFLoaderState;
  4340. (function (GLTFLoaderState) {
  4341. /**
  4342. * The asset is loading.
  4343. */
  4344. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  4345. /**
  4346. * The asset is ready for rendering.
  4347. */
  4348. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  4349. /**
  4350. * The asset is completely loaded.
  4351. */
  4352. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  4353. })(GLTFLoaderState || (GLTFLoaderState = {}));
  4354. /**
  4355. * File loader for loading glTF files into a scene.
  4356. */
  4357. var GLTFFileLoader = /** @class */ (function () {
  4358. function GLTFFileLoader() {
  4359. // --------------
  4360. // Common options
  4361. // --------------
  4362. /**
  4363. * Raised when the asset has been parsed
  4364. */
  4365. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4366. // ----------
  4367. // V2 options
  4368. // ----------
  4369. /**
  4370. * The coordinate system mode. Defaults to AUTO.
  4371. */
  4372. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  4373. /**
  4374. * The animation start mode. Defaults to FIRST.
  4375. */
  4376. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  4377. /**
  4378. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  4379. */
  4380. this.compileMaterials = false;
  4381. /**
  4382. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  4383. */
  4384. this.useClipPlane = false;
  4385. /**
  4386. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  4387. */
  4388. this.compileShadowGenerators = false;
  4389. /**
  4390. * Defines if the Alpha blended materials are only applied as coverage.
  4391. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  4392. * If true, no extra effects are applied to transparent pixels.
  4393. */
  4394. this.transparencyAsCoverage = false;
  4395. /**
  4396. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  4397. * Enabling will disable offline support and glTF validator.
  4398. * Defaults to false.
  4399. */
  4400. this.useRangeRequests = false;
  4401. /**
  4402. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  4403. */
  4404. this.createInstances = true;
  4405. /**
  4406. * Defines if the loader should always compute the bounding boxes of meshes and not use the min/max values from the position accessor. Defaults to false.
  4407. */
  4408. this.alwaysComputeBoundingBox = false;
  4409. /**
  4410. * Function called before loading a url referenced by the asset.
  4411. */
  4412. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4413. /**
  4414. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4415. */
  4416. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4417. /**
  4418. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  4419. */
  4420. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4421. /**
  4422. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  4423. */
  4424. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4425. /**
  4426. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  4427. */
  4428. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4429. /**
  4430. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  4431. * For assets with LODs, raised when all of the LODs are complete.
  4432. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4433. */
  4434. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4435. /**
  4436. * Observable raised when an error occurs.
  4437. */
  4438. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4439. /**
  4440. * Observable raised after the loader is disposed.
  4441. */
  4442. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4443. /**
  4444. * Observable raised after a loader extension is created.
  4445. * Set additional options for a loader extension in this event.
  4446. */
  4447. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4448. /**
  4449. * Defines if the loader should validate the asset.
  4450. */
  4451. this.validate = false;
  4452. /**
  4453. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  4454. */
  4455. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4456. this._loader = null;
  4457. this._requests = new Array();
  4458. /**
  4459. * Name of the loader ("gltf")
  4460. */
  4461. this.name = "gltf";
  4462. /** @hidden */
  4463. this.extensions = {
  4464. ".gltf": { isBinary: false },
  4465. ".glb": { isBinary: true }
  4466. };
  4467. this._logIndentLevel = 0;
  4468. this._loggingEnabled = false;
  4469. /** @hidden */
  4470. this._log = this._logDisabled;
  4471. this._capturePerformanceCounters = false;
  4472. /** @hidden */
  4473. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4474. /** @hidden */
  4475. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4476. }
  4477. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  4478. /**
  4479. * Raised when the asset has been parsed
  4480. */
  4481. set: function (callback) {
  4482. if (this._onParsedObserver) {
  4483. this.onParsedObservable.remove(this._onParsedObserver);
  4484. }
  4485. this._onParsedObserver = this.onParsedObservable.add(callback);
  4486. },
  4487. enumerable: false,
  4488. configurable: true
  4489. });
  4490. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  4491. /**
  4492. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4493. */
  4494. set: function (callback) {
  4495. if (this._onMeshLoadedObserver) {
  4496. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  4497. }
  4498. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  4499. },
  4500. enumerable: false,
  4501. configurable: true
  4502. });
  4503. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  4504. /**
  4505. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  4506. */
  4507. set: function (callback) {
  4508. if (this._onTextureLoadedObserver) {
  4509. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  4510. }
  4511. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  4512. },
  4513. enumerable: false,
  4514. configurable: true
  4515. });
  4516. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  4517. /**
  4518. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  4519. */
  4520. set: function (callback) {
  4521. if (this._onMaterialLoadedObserver) {
  4522. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  4523. }
  4524. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  4525. },
  4526. enumerable: false,
  4527. configurable: true
  4528. });
  4529. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  4530. /**
  4531. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  4532. */
  4533. set: function (callback) {
  4534. if (this._onCameraLoadedObserver) {
  4535. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  4536. }
  4537. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  4538. },
  4539. enumerable: false,
  4540. configurable: true
  4541. });
  4542. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  4543. /**
  4544. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  4545. * For assets with LODs, raised when all of the LODs are complete.
  4546. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4547. */
  4548. set: function (callback) {
  4549. if (this._onCompleteObserver) {
  4550. this.onCompleteObservable.remove(this._onCompleteObserver);
  4551. }
  4552. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  4553. },
  4554. enumerable: false,
  4555. configurable: true
  4556. });
  4557. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  4558. /**
  4559. * Callback raised when an error occurs.
  4560. */
  4561. set: function (callback) {
  4562. if (this._onErrorObserver) {
  4563. this.onErrorObservable.remove(this._onErrorObserver);
  4564. }
  4565. this._onErrorObserver = this.onErrorObservable.add(callback);
  4566. },
  4567. enumerable: false,
  4568. configurable: true
  4569. });
  4570. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  4571. /**
  4572. * Callback raised after the loader is disposed.
  4573. */
  4574. set: function (callback) {
  4575. if (this._onDisposeObserver) {
  4576. this.onDisposeObservable.remove(this._onDisposeObserver);
  4577. }
  4578. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  4579. },
  4580. enumerable: false,
  4581. configurable: true
  4582. });
  4583. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  4584. /**
  4585. * Callback raised after a loader extension is created.
  4586. */
  4587. set: function (callback) {
  4588. if (this._onExtensionLoadedObserver) {
  4589. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  4590. }
  4591. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  4592. },
  4593. enumerable: false,
  4594. configurable: true
  4595. });
  4596. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  4597. /**
  4598. * Defines if the loader logging is enabled.
  4599. */
  4600. get: function () {
  4601. return this._loggingEnabled;
  4602. },
  4603. set: function (value) {
  4604. if (this._loggingEnabled === value) {
  4605. return;
  4606. }
  4607. this._loggingEnabled = value;
  4608. if (this._loggingEnabled) {
  4609. this._log = this._logEnabled;
  4610. }
  4611. else {
  4612. this._log = this._logDisabled;
  4613. }
  4614. },
  4615. enumerable: false,
  4616. configurable: true
  4617. });
  4618. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  4619. /**
  4620. * Defines if the loader should capture performance counters.
  4621. */
  4622. get: function () {
  4623. return this._capturePerformanceCounters;
  4624. },
  4625. set: function (value) {
  4626. if (this._capturePerformanceCounters === value) {
  4627. return;
  4628. }
  4629. this._capturePerformanceCounters = value;
  4630. if (this._capturePerformanceCounters) {
  4631. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  4632. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  4633. }
  4634. else {
  4635. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4636. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4637. }
  4638. },
  4639. enumerable: false,
  4640. configurable: true
  4641. });
  4642. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  4643. /**
  4644. * Callback raised after a loader extension is created.
  4645. */
  4646. set: function (callback) {
  4647. if (this._onValidatedObserver) {
  4648. this.onValidatedObservable.remove(this._onValidatedObserver);
  4649. }
  4650. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  4651. },
  4652. enumerable: false,
  4653. configurable: true
  4654. });
  4655. /**
  4656. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  4657. */
  4658. GLTFFileLoader.prototype.dispose = function () {
  4659. if (this._loader) {
  4660. this._loader.dispose();
  4661. this._loader = null;
  4662. }
  4663. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4664. var request = _a[_i];
  4665. request.abort();
  4666. }
  4667. this._requests.length = 0;
  4668. delete this._progressCallback;
  4669. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4670. this.onMeshLoadedObservable.clear();
  4671. this.onTextureLoadedObservable.clear();
  4672. this.onMaterialLoadedObservable.clear();
  4673. this.onCameraLoadedObservable.clear();
  4674. this.onCompleteObservable.clear();
  4675. this.onExtensionLoadedObservable.clear();
  4676. this.onDisposeObservable.notifyObservers(undefined);
  4677. this.onDisposeObservable.clear();
  4678. };
  4679. /** @hidden */
  4680. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  4681. var _this = this;
  4682. this._progressCallback = onProgress;
  4683. if (useArrayBuffer) {
  4684. if (this.useRangeRequests) {
  4685. if (this.validate) {
  4686. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  4687. }
  4688. var fileRequest_1 = {
  4689. abort: function () { },
  4690. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  4691. };
  4692. var dataBuffer = {
  4693. readAsync: function (byteOffset, byteLength) {
  4694. return new Promise(function (resolve, reject) {
  4695. _this._requestFile(url, scene, function (data) {
  4696. resolve(new Uint8Array(data));
  4697. }, true, function (error) {
  4698. reject(error);
  4699. }, function (webRequest) {
  4700. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  4701. });
  4702. });
  4703. },
  4704. byteLength: 0
  4705. };
  4706. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  4707. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  4708. onSuccess(loaderData);
  4709. }, onError);
  4710. return fileRequest_1;
  4711. }
  4712. return this._requestFile(url, scene, function (data, request) {
  4713. var arrayBuffer = data;
  4714. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4715. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  4716. byteLength: arrayBuffer.byteLength
  4717. })).then(function (loaderData) {
  4718. onSuccess(loaderData, request);
  4719. }, onError);
  4720. }, true, onError);
  4721. }
  4722. return this._requestFile(url, scene, function (data, request) {
  4723. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  4724. onSuccess({ json: _this._parseJson(data) }, request);
  4725. }, useArrayBuffer, onError);
  4726. };
  4727. /** @hidden */
  4728. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  4729. var _this = this;
  4730. return scene._readFile(file, function (data) {
  4731. _this._validate(scene, data, "file:", file.name);
  4732. if (useArrayBuffer) {
  4733. var arrayBuffer_1 = data;
  4734. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4735. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  4736. byteLength: arrayBuffer_1.byteLength
  4737. })).then(onSuccess, onError);
  4738. }
  4739. else {
  4740. onSuccess({ json: _this._parseJson(data) });
  4741. }
  4742. }, onProgress, useArrayBuffer, onError);
  4743. };
  4744. /** @hidden */
  4745. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  4746. var _this = this;
  4747. return Promise.resolve().then(function () {
  4748. _this.onParsedObservable.notifyObservers(data);
  4749. _this.onParsedObservable.clear();
  4750. _this._log("Loading " + (fileName || ""));
  4751. _this._loader = _this._getLoader(data);
  4752. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  4753. });
  4754. };
  4755. /** @hidden */
  4756. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4757. var _this = this;
  4758. return Promise.resolve().then(function () {
  4759. _this.onParsedObservable.notifyObservers(data);
  4760. _this.onParsedObservable.clear();
  4761. _this._log("Loading " + (fileName || ""));
  4762. _this._loader = _this._getLoader(data);
  4763. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  4764. });
  4765. };
  4766. /** @hidden */
  4767. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4768. var _this = this;
  4769. return Promise.resolve().then(function () {
  4770. _this.onParsedObservable.notifyObservers(data);
  4771. _this.onParsedObservable.clear();
  4772. _this._log("Loading " + (fileName || ""));
  4773. _this._loader = _this._getLoader(data);
  4774. // Get materials/textures when loading to add to container
  4775. var materials = [];
  4776. _this.onMaterialLoadedObservable.add(function (material) {
  4777. materials.push(material);
  4778. });
  4779. var textures = [];
  4780. _this.onTextureLoadedObservable.add(function (texture) {
  4781. textures.push(texture);
  4782. });
  4783. var cameras = [];
  4784. _this.onCameraLoadedObservable.add(function (camera) {
  4785. cameras.push(camera);
  4786. });
  4787. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  4788. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  4789. Array.prototype.push.apply(container.meshes, result.meshes);
  4790. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  4791. Array.prototype.push.apply(container.skeletons, result.skeletons);
  4792. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  4793. Array.prototype.push.apply(container.materials, materials);
  4794. Array.prototype.push.apply(container.textures, textures);
  4795. Array.prototype.push.apply(container.lights, result.lights);
  4796. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  4797. Array.prototype.push.apply(container.cameras, cameras);
  4798. return container;
  4799. });
  4800. });
  4801. };
  4802. /** @hidden */
  4803. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  4804. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  4805. };
  4806. /** @hidden */
  4807. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  4808. this._validate(scene, data);
  4809. return { json: this._parseJson(data) };
  4810. };
  4811. /** @hidden */
  4812. GLTFFileLoader.prototype.createPlugin = function () {
  4813. return new GLTFFileLoader();
  4814. };
  4815. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  4816. /**
  4817. * The loader state or null if the loader is not active.
  4818. */
  4819. get: function () {
  4820. return this._loader ? this._loader.state : null;
  4821. },
  4822. enumerable: false,
  4823. configurable: true
  4824. });
  4825. /**
  4826. * Returns a promise that resolves when the asset is completely loaded.
  4827. * @returns a promise that resolves when the asset is completely loaded.
  4828. */
  4829. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  4830. var _this = this;
  4831. return new Promise(function (resolve, reject) {
  4832. _this.onCompleteObservable.addOnce(function () {
  4833. resolve();
  4834. });
  4835. _this.onErrorObservable.addOnce(function (reason) {
  4836. reject(reason);
  4837. });
  4838. });
  4839. };
  4840. /** @hidden */
  4841. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  4842. var _this = this;
  4843. var request = scene._loadFile(url, onSuccess, function (event) {
  4844. _this._onProgress(event, request);
  4845. }, undefined, useArrayBuffer, onError);
  4846. request.onCompleteObservable.add(function (request) {
  4847. _this._requests.splice(_this._requests.indexOf(request), 1);
  4848. });
  4849. this._requests.push(request);
  4850. return request;
  4851. };
  4852. /** @hidden */
  4853. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  4854. var _this = this;
  4855. var request = scene._requestFile(url, onSuccess, function (event) {
  4856. _this._onProgress(event, request);
  4857. }, undefined, useArrayBuffer, onError, onOpened);
  4858. request.onCompleteObservable.add(function (request) {
  4859. _this._requests.splice(_this._requests.indexOf(request), 1);
  4860. });
  4861. this._requests.push(request);
  4862. return request;
  4863. };
  4864. GLTFFileLoader.prototype._onProgress = function (event, request) {
  4865. if (!this._progressCallback) {
  4866. return;
  4867. }
  4868. request._lengthComputable = event.lengthComputable;
  4869. request._loaded = event.loaded;
  4870. request._total = event.total;
  4871. var lengthComputable = true;
  4872. var loaded = 0;
  4873. var total = 0;
  4874. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4875. var request_1 = _a[_i];
  4876. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  4877. return;
  4878. }
  4879. lengthComputable = lengthComputable && request_1._lengthComputable;
  4880. loaded += request_1._loaded;
  4881. total += request_1._total;
  4882. }
  4883. this._progressCallback({
  4884. lengthComputable: lengthComputable,
  4885. loaded: loaded,
  4886. total: lengthComputable ? total : 0
  4887. });
  4888. };
  4889. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  4890. var _this = this;
  4891. if (rootUrl === void 0) { rootUrl = ""; }
  4892. if (fileName === void 0) { fileName = ""; }
  4893. if (!this.validate) {
  4894. return;
  4895. }
  4896. this._startPerformanceCounter("Validate JSON");
  4897. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  4898. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  4899. }).then(function (result) {
  4900. _this._endPerformanceCounter("Validate JSON");
  4901. _this.onValidatedObservable.notifyObservers(result);
  4902. _this.onValidatedObservable.clear();
  4903. }, function (reason) {
  4904. _this._endPerformanceCounter("Validate JSON");
  4905. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  4906. _this.onValidatedObservable.clear();
  4907. });
  4908. };
  4909. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  4910. var asset = loaderData.json.asset || {};
  4911. this._log("Asset version: " + asset.version);
  4912. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  4913. asset.generator && this._log("Asset generator: " + asset.generator);
  4914. var version = GLTFFileLoader._parseVersion(asset.version);
  4915. if (!version) {
  4916. throw new Error("Invalid version: " + asset.version);
  4917. }
  4918. if (asset.minVersion !== undefined) {
  4919. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  4920. if (!minVersion) {
  4921. throw new Error("Invalid minimum version: " + asset.minVersion);
  4922. }
  4923. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  4924. throw new Error("Incompatible minimum version: " + asset.minVersion);
  4925. }
  4926. }
  4927. var createLoaders = {
  4928. 1: GLTFFileLoader._CreateGLTF1Loader,
  4929. 2: GLTFFileLoader._CreateGLTF2Loader
  4930. };
  4931. var createLoader = createLoaders[version.major];
  4932. if (!createLoader) {
  4933. throw new Error("Unsupported version: " + asset.version);
  4934. }
  4935. return createLoader(this);
  4936. };
  4937. GLTFFileLoader.prototype._parseJson = function (json) {
  4938. this._startPerformanceCounter("Parse JSON");
  4939. this._log("JSON length: " + json.length);
  4940. var parsed = JSON.parse(json);
  4941. this._endPerformanceCounter("Parse JSON");
  4942. return parsed;
  4943. };
  4944. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  4945. var _this = this;
  4946. this._startPerformanceCounter("Unpack Binary");
  4947. // Read magic + version + length + json length + json format
  4948. return dataReader.loadAsync(20).then(function () {
  4949. var Binary = {
  4950. Magic: 0x46546C67
  4951. };
  4952. var magic = dataReader.readUint32();
  4953. if (magic !== Binary.Magic) {
  4954. throw new Error("Unexpected magic: " + magic);
  4955. }
  4956. var version = dataReader.readUint32();
  4957. if (_this.loggingEnabled) {
  4958. _this._log("Binary version: " + version);
  4959. }
  4960. var length = dataReader.readUint32();
  4961. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  4962. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  4963. }
  4964. var unpacked;
  4965. switch (version) {
  4966. case 1: {
  4967. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  4968. break;
  4969. }
  4970. case 2: {
  4971. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  4972. break;
  4973. }
  4974. default: {
  4975. throw new Error("Unsupported version: " + version);
  4976. }
  4977. }
  4978. _this._endPerformanceCounter("Unpack Binary");
  4979. return unpacked;
  4980. });
  4981. };
  4982. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  4983. var ContentFormat = {
  4984. JSON: 0
  4985. };
  4986. var contentLength = dataReader.readUint32();
  4987. var contentFormat = dataReader.readUint32();
  4988. if (contentFormat !== ContentFormat.JSON) {
  4989. throw new Error("Unexpected content format: " + contentFormat);
  4990. }
  4991. var bodyLength = length - dataReader.byteOffset;
  4992. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  4993. if (bodyLength !== 0) {
  4994. var startByteOffset_1 = dataReader.byteOffset;
  4995. data.bin = {
  4996. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  4997. byteLength: bodyLength
  4998. };
  4999. }
  5000. return Promise.resolve(data);
  5001. };
  5002. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  5003. var _this = this;
  5004. var ChunkFormat = {
  5005. JSON: 0x4E4F534A,
  5006. BIN: 0x004E4942
  5007. };
  5008. // Read the JSON chunk header.
  5009. var chunkLength = dataReader.readUint32();
  5010. var chunkFormat = dataReader.readUint32();
  5011. if (chunkFormat !== ChunkFormat.JSON) {
  5012. throw new Error("First chunk format is not JSON");
  5013. }
  5014. // Bail if there are no other chunks.
  5015. if (dataReader.byteOffset + chunkLength === length) {
  5016. return dataReader.loadAsync(chunkLength).then(function () {
  5017. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  5018. });
  5019. }
  5020. // Read the JSON chunk and the length and type of the next chunk.
  5021. return dataReader.loadAsync(chunkLength + 8).then(function () {
  5022. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  5023. var readAsync = function () {
  5024. var chunkLength = dataReader.readUint32();
  5025. var chunkFormat = dataReader.readUint32();
  5026. switch (chunkFormat) {
  5027. case ChunkFormat.JSON: {
  5028. throw new Error("Unexpected JSON chunk");
  5029. }
  5030. case ChunkFormat.BIN: {
  5031. var startByteOffset_2 = dataReader.byteOffset;
  5032. data.bin = {
  5033. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  5034. byteLength: chunkLength
  5035. };
  5036. dataReader.skipBytes(chunkLength);
  5037. break;
  5038. }
  5039. default: {
  5040. // ignore unrecognized chunkFormat
  5041. dataReader.skipBytes(chunkLength);
  5042. break;
  5043. }
  5044. }
  5045. if (dataReader.byteOffset !== length) {
  5046. return dataReader.loadAsync(8).then(readAsync);
  5047. }
  5048. return Promise.resolve(data);
  5049. };
  5050. return readAsync();
  5051. });
  5052. };
  5053. GLTFFileLoader._parseVersion = function (version) {
  5054. if (version === "1.0" || version === "1.0.1") {
  5055. return {
  5056. major: 1,
  5057. minor: 0
  5058. };
  5059. }
  5060. var match = (version + "").match(/^(\d+)\.(\d+)/);
  5061. if (!match) {
  5062. return null;
  5063. }
  5064. return {
  5065. major: parseInt(match[1]),
  5066. minor: parseInt(match[2])
  5067. };
  5068. };
  5069. GLTFFileLoader._compareVersion = function (a, b) {
  5070. if (a.major > b.major) {
  5071. return 1;
  5072. }
  5073. if (a.major < b.major) {
  5074. return -1;
  5075. }
  5076. if (a.minor > b.minor) {
  5077. return 1;
  5078. }
  5079. if (a.minor < b.minor) {
  5080. return -1;
  5081. }
  5082. return 0;
  5083. };
  5084. /** @hidden */
  5085. GLTFFileLoader.prototype._logOpen = function (message) {
  5086. this._log(message);
  5087. this._logIndentLevel++;
  5088. };
  5089. /** @hidden */
  5090. GLTFFileLoader.prototype._logClose = function () {
  5091. --this._logIndentLevel;
  5092. };
  5093. GLTFFileLoader.prototype._logEnabled = function (message) {
  5094. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  5095. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  5096. };
  5097. GLTFFileLoader.prototype._logDisabled = function (message) {
  5098. };
  5099. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  5100. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  5101. };
  5102. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  5103. };
  5104. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  5105. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  5106. };
  5107. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  5108. };
  5109. // ----------
  5110. // V1 options
  5111. // ----------
  5112. /**
  5113. * 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.
  5114. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  5115. * Defaults to true.
  5116. * @hidden
  5117. */
  5118. GLTFFileLoader.IncrementalLoading = true;
  5119. /**
  5120. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  5121. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  5122. * @hidden
  5123. */
  5124. GLTFFileLoader.HomogeneousCoordinates = false;
  5125. GLTFFileLoader._logSpaces = " ";
  5126. return GLTFFileLoader;
  5127. }());
  5128. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  5129. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  5130. }
  5131. /***/ }),
  5132. /***/ "./glTF/glTFValidation.ts":
  5133. /*!********************************!*\
  5134. !*** ./glTF/glTFValidation.ts ***!
  5135. \********************************/
  5136. /*! exports provided: GLTFValidation */
  5137. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5138. "use strict";
  5139. __webpack_require__.r(__webpack_exports__);
  5140. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  5141. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  5142. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  5143. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  5144. var options = {
  5145. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  5146. };
  5147. if (fileName) {
  5148. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  5149. }
  5150. return (data instanceof ArrayBuffer)
  5151. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  5152. : GLTFValidator.validateString(data, options);
  5153. }
  5154. /**
  5155. * The worker function that gets converted to a blob url to pass into a worker.
  5156. */
  5157. function workerFunc() {
  5158. var pendingExternalResources = [];
  5159. onmessage = function (message) {
  5160. var data = message.data;
  5161. switch (data.id) {
  5162. case "init": {
  5163. importScripts(data.url);
  5164. break;
  5165. }
  5166. case "validate": {
  5167. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  5168. var index = pendingExternalResources.length;
  5169. pendingExternalResources.push({ resolve: resolve, reject: reject });
  5170. postMessage({ id: "getExternalResource", index: index, uri: uri });
  5171. }); }).then(function (value) {
  5172. postMessage({ id: "validate.resolve", value: value });
  5173. }, function (reason) {
  5174. postMessage({ id: "validate.reject", reason: reason });
  5175. });
  5176. break;
  5177. }
  5178. case "getExternalResource.resolve": {
  5179. pendingExternalResources[data.index].resolve(data.value);
  5180. break;
  5181. }
  5182. case "getExternalResource.reject": {
  5183. pendingExternalResources[data.index].reject(data.reason);
  5184. break;
  5185. }
  5186. }
  5187. };
  5188. }
  5189. /**
  5190. * glTF validation
  5191. */
  5192. var GLTFValidation = /** @class */ (function () {
  5193. function GLTFValidation() {
  5194. }
  5195. /**
  5196. * Validate a glTF asset using the glTF-Validator.
  5197. * @param data The JSON of a glTF or the array buffer of a binary glTF
  5198. * @param rootUrl The root url for the glTF
  5199. * @param fileName The file name for the glTF
  5200. * @param getExternalResource The callback to get external resources for the glTF validator
  5201. * @returns A promise that resolves with the glTF validation results once complete
  5202. */
  5203. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  5204. var _this = this;
  5205. if (typeof Worker === "function") {
  5206. return new Promise(function (resolve, reject) {
  5207. var workerContent = validateAsync + "(" + workerFunc + ")()";
  5208. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  5209. var worker = new Worker(workerBlobUrl);
  5210. var onError = function (error) {
  5211. worker.removeEventListener("error", onError);
  5212. worker.removeEventListener("message", onMessage);
  5213. reject(error);
  5214. };
  5215. var onMessage = function (message) {
  5216. var data = message.data;
  5217. switch (data.id) {
  5218. case "getExternalResource": {
  5219. getExternalResource(data.uri).then(function (value) {
  5220. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  5221. }, function (reason) {
  5222. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  5223. });
  5224. break;
  5225. }
  5226. case "validate.resolve": {
  5227. worker.removeEventListener("error", onError);
  5228. worker.removeEventListener("message", onMessage);
  5229. resolve(data.value);
  5230. break;
  5231. }
  5232. case "validate.reject": {
  5233. worker.removeEventListener("error", onError);
  5234. worker.removeEventListener("message", onMessage);
  5235. reject(data.reason);
  5236. }
  5237. }
  5238. };
  5239. worker.addEventListener("error", onError);
  5240. worker.addEventListener("message", onMessage);
  5241. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  5242. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  5243. });
  5244. }
  5245. else {
  5246. if (!this._LoadScriptPromise) {
  5247. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  5248. }
  5249. return this._LoadScriptPromise.then(function () {
  5250. return validateAsync(data, rootUrl, fileName, getExternalResource);
  5251. });
  5252. }
  5253. };
  5254. /**
  5255. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  5256. */
  5257. GLTFValidation.Configuration = {
  5258. url: "https://preview.babylonjs.com/gltf_validator.js"
  5259. };
  5260. return GLTFValidation;
  5261. }());
  5262. /***/ }),
  5263. /***/ "./legacy/legacy-glTF.ts":
  5264. /*!*******************************!*\
  5265. !*** ./legacy/legacy-glTF.ts ***!
  5266. \*******************************/
  5267. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  5268. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5269. "use strict";
  5270. __webpack_require__.r(__webpack_exports__);
  5271. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5272. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  5273. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5274. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5275. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5276. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5277. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  5278. /**
  5279. * This is the entry point for the UMD module.
  5280. * The entry point for a future ESM package should be index.ts
  5281. */
  5282. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5283. if (typeof globalObject !== "undefined") {
  5284. globalObject.BABYLON = globalObject.BABYLON || {};
  5285. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  5286. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  5287. }
  5288. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  5289. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  5290. }
  5291. }
  5292. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5293. /***/ }),
  5294. /***/ "./legacy/legacy-glTF2.ts":
  5295. /*!********************************!*\
  5296. !*** ./legacy/legacy-glTF2.ts ***!
  5297. \********************************/
  5298. /*! exports provided: GLTF2 */
  5299. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5300. "use strict";
  5301. __webpack_require__.r(__webpack_exports__);
  5302. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  5303. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  5304. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  5305. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  5306. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  5307. /**
  5308. * This is the entry point for the UMD module.
  5309. * The entry point for a future ESM package should be index.ts
  5310. */
  5311. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5312. if (typeof globalObject !== "undefined") {
  5313. globalObject.BABYLON = globalObject.BABYLON || {};
  5314. var BABYLON = globalObject.BABYLON;
  5315. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  5316. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  5317. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  5318. var keys = [];
  5319. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  5320. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  5321. keys.push(key);
  5322. }
  5323. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  5324. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  5325. keys.push(key);
  5326. }
  5327. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  5328. // Prevent Reassignment.
  5329. if (keys.indexOf(key) > -1) {
  5330. continue;
  5331. }
  5332. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  5333. }
  5334. }
  5335. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5336. /***/ }),
  5337. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  5338. /*!******************************************!*\
  5339. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  5340. \******************************************/
  5341. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF2 */
  5342. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5343. "use strict";
  5344. __webpack_require__.r(__webpack_exports__);
  5345. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  5346. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5347. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5348. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5349. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5350. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  5351. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  5352. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  5353. /***/ }),
  5354. /***/ "babylonjs/Misc/observable":
  5355. /*!****************************************************************************************************!*\
  5356. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  5357. \****************************************************************************************************/
  5358. /*! no static exports found */
  5359. /***/ (function(module, exports) {
  5360. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  5361. /***/ })
  5362. /******/ });
  5363. });
  5364. //# sourceMappingURL=babylon.glTF2FileLoader.js.map