babylon.glTF2FileLoader.js 243 KB

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