babylon.glTF2FileLoader.js 271 KB

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