babylon.glTF2FileLoader.js 229 KB

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