babylon.glTF2FileLoader.js 234 KB

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