babylon.glTF2FileLoader.js 267 KB

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