babylon.glTF2FileLoader.js 215 KB

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