babylon.glTF2FileLoader.js 222 KB

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