babylon.glTF2FileLoader.js 221 KB

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