babylon.glTF2FileLoader.js 280 KB

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