babylon.glTF2FileLoader.js 285 KB

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