babylon.glTF2FileLoader.js 285 KB

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