babylon.glTF2FileLoader.js 220 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385
  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_Maths_math__) {
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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/Maths/math");
  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. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  1884. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  1885. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  1886. babylonGeometry.applyToMesh(babylonMesh_1);
  1887. });
  1888. }));
  1889. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  1890. if (primitive.material == undefined) {
  1891. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  1892. if (!babylonMaterial) {
  1893. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  1894. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1895. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  1896. }
  1897. babylonMesh_1.material = babylonMaterial;
  1898. }
  1899. else {
  1900. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  1901. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  1902. babylonMesh_1.material = babylonMaterial;
  1903. }));
  1904. }
  1905. promise = Promise.all(promises);
  1906. if (canInstance) {
  1907. primitive._instanceData = {
  1908. babylonSourceMesh: babylonMesh_1,
  1909. promise: promise
  1910. };
  1911. }
  1912. babylonAbstractMesh = babylonMesh_1;
  1913. }
  1914. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  1915. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  1916. assign(babylonAbstractMesh);
  1917. this.logClose();
  1918. return promise.then(function () {
  1919. return babylonAbstractMesh;
  1920. });
  1921. };
  1922. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  1923. var _this = this;
  1924. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  1925. if (extensionPromise) {
  1926. return extensionPromise;
  1927. }
  1928. var attributes = primitive.attributes;
  1929. if (!attributes) {
  1930. throw new Error(context + ": Attributes are missing");
  1931. }
  1932. var promises = new Array();
  1933. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  1934. if (primitive.indices == undefined) {
  1935. babylonMesh.isUnIndexed = true;
  1936. }
  1937. else {
  1938. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  1939. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  1940. babylonGeometry.setIndices(data);
  1941. }));
  1942. }
  1943. var loadAttribute = function (attribute, kind, callback) {
  1944. if (attributes[attribute] == undefined) {
  1945. return;
  1946. }
  1947. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  1948. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  1949. babylonMesh._delayInfo.push(kind);
  1950. }
  1951. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  1952. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  1953. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  1954. }));
  1955. if (callback) {
  1956. callback(accessor);
  1957. }
  1958. };
  1959. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  1960. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  1961. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  1962. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  1963. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  1964. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  1965. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  1966. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  1967. if (accessor.type === "VEC4" /* VEC4 */) {
  1968. babylonMesh.hasVertexAlpha = true;
  1969. }
  1970. });
  1971. return Promise.all(promises).then(function () {
  1972. return babylonGeometry;
  1973. });
  1974. };
  1975. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  1976. if (!primitive.targets) {
  1977. return;
  1978. }
  1979. if (node._numMorphTargets == undefined) {
  1980. node._numMorphTargets = primitive.targets.length;
  1981. }
  1982. else if (primitive.targets.length !== node._numMorphTargets) {
  1983. throw new Error(context + ": Primitives do not have the same number of targets");
  1984. }
  1985. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  1986. for (var index = 0; index < primitive.targets.length; index++) {
  1987. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  1988. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"]("morphTarget" + index, weight, babylonMesh.getScene()));
  1989. // TODO: tell the target whether it has positions, normals, tangents
  1990. }
  1991. };
  1992. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  1993. if (!primitive.targets) {
  1994. return Promise.resolve();
  1995. }
  1996. var promises = new Array();
  1997. var morphTargetManager = babylonMesh.morphTargetManager;
  1998. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  1999. var babylonMorphTarget = morphTargetManager.getTarget(index);
  2000. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  2001. }
  2002. return Promise.all(promises).then(function () { });
  2003. };
  2004. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  2005. var _this = this;
  2006. var promises = new Array();
  2007. var loadAttribute = function (attribute, kind, setData) {
  2008. if (attributes[attribute] == undefined) {
  2009. return;
  2010. }
  2011. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  2012. if (!babylonVertexBuffer) {
  2013. return;
  2014. }
  2015. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2016. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2017. setData(babylonVertexBuffer, data);
  2018. }));
  2019. };
  2020. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  2021. var positions = new Float32Array(data.length);
  2022. babylonVertexBuffer.forEach(data.length, function (value, index) {
  2023. positions[index] = data[index] + value;
  2024. });
  2025. babylonMorphTarget.setPositions(positions);
  2026. });
  2027. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  2028. var normals = new Float32Array(data.length);
  2029. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  2030. normals[index] = data[index] + value;
  2031. });
  2032. babylonMorphTarget.setNormals(normals);
  2033. });
  2034. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  2035. var tangents = new Float32Array(data.length / 3 * 4);
  2036. var dataIndex = 0;
  2037. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  2038. // Tangent data for morph targets is stored as xyz delta.
  2039. // The vertexData.tangent is stored as xyzw.
  2040. // So we need to skip every fourth vertexData.tangent.
  2041. if (((index + 1) % 4) !== 0) {
  2042. tangents[dataIndex] = data[dataIndex] + value;
  2043. dataIndex++;
  2044. }
  2045. });
  2046. babylonMorphTarget.setTangents(tangents);
  2047. });
  2048. return Promise.all(promises).then(function () { });
  2049. };
  2050. GLTFLoader._LoadTransform = function (node, babylonNode) {
  2051. // Ignore the TRS of skinned nodes.
  2052. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  2053. if (node.skin != undefined) {
  2054. return;
  2055. }
  2056. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  2057. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  2058. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  2059. if (node.matrix) {
  2060. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  2061. matrix.decompose(scaling, rotation, position);
  2062. }
  2063. else {
  2064. if (node.translation) {
  2065. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  2066. }
  2067. if (node.rotation) {
  2068. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  2069. }
  2070. if (node.scale) {
  2071. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  2072. }
  2073. }
  2074. babylonNode.position = position;
  2075. babylonNode.rotationQuaternion = rotation;
  2076. babylonNode.scaling = scaling;
  2077. };
  2078. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  2079. var _this = this;
  2080. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  2081. if (extensionPromise) {
  2082. return extensionPromise;
  2083. }
  2084. var assignSkeleton = function (skeleton) {
  2085. _this._forEachPrimitive(node, function (babylonMesh) {
  2086. babylonMesh.skeleton = skeleton;
  2087. });
  2088. };
  2089. if (skin._data) {
  2090. assignSkeleton(skin._data.babylonSkeleton);
  2091. return skin._data.promise;
  2092. }
  2093. var skeletonId = "skeleton" + skin.index;
  2094. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  2095. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  2096. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  2097. this._loadBones(context, skin, babylonSkeleton);
  2098. assignSkeleton(babylonSkeleton);
  2099. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  2100. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  2101. });
  2102. skin._data = {
  2103. babylonSkeleton: babylonSkeleton,
  2104. promise: promise
  2105. };
  2106. return promise;
  2107. };
  2108. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  2109. var babylonBones = {};
  2110. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  2111. var index = _a[_i];
  2112. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  2113. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  2114. }
  2115. };
  2116. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  2117. var babylonBone = babylonBones[node.index];
  2118. if (babylonBone) {
  2119. return babylonBone;
  2120. }
  2121. var babylonParentBone = null;
  2122. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  2123. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  2124. }
  2125. var boneIndex = skin.joints.indexOf(node.index);
  2126. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  2127. babylonBones[node.index] = babylonBone;
  2128. node._babylonBones = node._babylonBones || [];
  2129. node._babylonBones.push(babylonBone);
  2130. return babylonBone;
  2131. };
  2132. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  2133. if (skin.inverseBindMatrices == undefined) {
  2134. return Promise.resolve(null);
  2135. }
  2136. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  2137. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  2138. };
  2139. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  2140. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  2141. var babylonBone = _a[_i];
  2142. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  2143. var boneIndex = babylonBone._index;
  2144. if (inverseBindMatricesData && boneIndex !== -1) {
  2145. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  2146. baseMatrix.invertToRef(baseMatrix);
  2147. }
  2148. var babylonParentBone = babylonBone.getParent();
  2149. if (babylonParentBone) {
  2150. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  2151. }
  2152. babylonBone.updateMatrix(baseMatrix, false, false);
  2153. babylonBone._updateDifferenceMatrix(undefined, false);
  2154. }
  2155. };
  2156. GLTFLoader.prototype._getNodeMatrix = function (node) {
  2157. return node.matrix ?
  2158. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  2159. 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());
  2160. };
  2161. /**
  2162. * Loads a glTF camera.
  2163. * @param context The context when loading the asset
  2164. * @param camera The glTF camera property
  2165. * @param assign A function called synchronously after parsing the glTF properties
  2166. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  2167. */
  2168. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  2169. if (assign === void 0) { assign = function () { }; }
  2170. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  2171. if (extensionPromise) {
  2172. return extensionPromise;
  2173. }
  2174. var promises = new Array();
  2175. this.logOpen(context + " " + (camera.name || ""));
  2176. 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);
  2177. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  2178. switch (camera.type) {
  2179. case "perspective" /* PERSPECTIVE */: {
  2180. var perspective = camera.perspective;
  2181. if (!perspective) {
  2182. throw new Error(context + ": Camera perspective properties are missing");
  2183. }
  2184. babylonCamera.fov = perspective.yfov;
  2185. babylonCamera.minZ = perspective.znear;
  2186. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  2187. break;
  2188. }
  2189. case "orthographic" /* ORTHOGRAPHIC */: {
  2190. if (!camera.orthographic) {
  2191. throw new Error(context + ": Camera orthographic properties are missing");
  2192. }
  2193. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  2194. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  2195. babylonCamera.orthoRight = camera.orthographic.xmag;
  2196. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  2197. babylonCamera.orthoTop = camera.orthographic.ymag;
  2198. babylonCamera.minZ = camera.orthographic.znear;
  2199. babylonCamera.maxZ = camera.orthographic.zfar;
  2200. break;
  2201. }
  2202. default: {
  2203. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  2204. }
  2205. }
  2206. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  2207. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  2208. assign(babylonCamera);
  2209. return Promise.all(promises).then(function () {
  2210. return babylonCamera;
  2211. });
  2212. };
  2213. GLTFLoader.prototype._loadAnimationsAsync = function () {
  2214. var animations = this._gltf.animations;
  2215. if (!animations) {
  2216. return Promise.resolve();
  2217. }
  2218. var promises = new Array();
  2219. for (var index = 0; index < animations.length; index++) {
  2220. var animation = animations[index];
  2221. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  2222. }
  2223. return Promise.all(promises).then(function () { });
  2224. };
  2225. /**
  2226. * Loads a glTF animation.
  2227. * @param context The context when loading the asset
  2228. * @param animation The glTF animation property
  2229. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  2230. */
  2231. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  2232. var promise = this._extensionsLoadAnimationAsync(context, animation);
  2233. if (promise) {
  2234. return promise;
  2235. }
  2236. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  2237. animation._babylonAnimationGroup = babylonAnimationGroup;
  2238. var promises = new Array();
  2239. ArrayItem.Assign(animation.channels);
  2240. ArrayItem.Assign(animation.samplers);
  2241. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  2242. var channel = _a[_i];
  2243. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  2244. }
  2245. return Promise.all(promises).then(function () {
  2246. babylonAnimationGroup.normalize(0);
  2247. return babylonAnimationGroup;
  2248. });
  2249. };
  2250. /**
  2251. * @hidden Loads a glTF animation channel.
  2252. * @param context The context when loading the asset
  2253. * @param animationContext The context of the animation when loading the asset
  2254. * @param animation The glTF animation property
  2255. * @param channel The glTF animation channel property
  2256. * @param babylonAnimationGroup The babylon animation group property
  2257. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  2258. * @returns A void promise when the channel load is complete
  2259. */
  2260. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  2261. var _this = this;
  2262. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  2263. if (channel.target.node == undefined) {
  2264. return Promise.resolve();
  2265. }
  2266. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  2267. // Ignore animations that have no animation targets.
  2268. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  2269. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  2270. return Promise.resolve();
  2271. }
  2272. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  2273. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  2274. var targetPath;
  2275. var animationType;
  2276. switch (channel.target.path) {
  2277. case "translation" /* TRANSLATION */: {
  2278. targetPath = "position";
  2279. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2280. break;
  2281. }
  2282. case "rotation" /* ROTATION */: {
  2283. targetPath = "rotationQuaternion";
  2284. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  2285. break;
  2286. }
  2287. case "scale" /* SCALE */: {
  2288. targetPath = "scaling";
  2289. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2290. break;
  2291. }
  2292. case "weights" /* WEIGHTS */: {
  2293. targetPath = "influence";
  2294. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  2295. break;
  2296. }
  2297. default: {
  2298. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  2299. }
  2300. }
  2301. var outputBufferOffset = 0;
  2302. var getNextOutputValue;
  2303. switch (targetPath) {
  2304. case "position": {
  2305. getNextOutputValue = function () {
  2306. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2307. outputBufferOffset += 3;
  2308. return value;
  2309. };
  2310. break;
  2311. }
  2312. case "rotationQuaternion": {
  2313. getNextOutputValue = function () {
  2314. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  2315. outputBufferOffset += 4;
  2316. return value;
  2317. };
  2318. break;
  2319. }
  2320. case "scaling": {
  2321. getNextOutputValue = function () {
  2322. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2323. outputBufferOffset += 3;
  2324. return value;
  2325. };
  2326. break;
  2327. }
  2328. case "influence": {
  2329. getNextOutputValue = function () {
  2330. var value = new Array(targetNode._numMorphTargets);
  2331. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  2332. value[i] = data.output[outputBufferOffset++];
  2333. }
  2334. return value;
  2335. };
  2336. break;
  2337. }
  2338. }
  2339. var getNextKey;
  2340. switch (data.interpolation) {
  2341. case "STEP" /* STEP */: {
  2342. getNextKey = function (frameIndex) { return ({
  2343. frame: data.input[frameIndex],
  2344. value: getNextOutputValue(),
  2345. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  2346. }); };
  2347. break;
  2348. }
  2349. case "LINEAR" /* LINEAR */: {
  2350. getNextKey = function (frameIndex) { return ({
  2351. frame: data.input[frameIndex],
  2352. value: getNextOutputValue()
  2353. }); };
  2354. break;
  2355. }
  2356. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2357. getNextKey = function (frameIndex) { return ({
  2358. frame: data.input[frameIndex],
  2359. inTangent: getNextOutputValue(),
  2360. value: getNextOutputValue(),
  2361. outTangent: getNextOutputValue()
  2362. }); };
  2363. break;
  2364. }
  2365. }
  2366. var keys = new Array(data.input.length);
  2367. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  2368. keys[frameIndex] = getNextKey(frameIndex);
  2369. }
  2370. if (targetPath === "influence") {
  2371. var _loop_1 = function (targetIndex) {
  2372. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2373. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2374. babylonAnimation.setKeys(keys.map(function (key) { return ({
  2375. frame: key.frame,
  2376. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  2377. value: key.value[targetIndex],
  2378. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  2379. }); }));
  2380. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  2381. var babylonMesh = babylonAbstractMesh;
  2382. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  2383. var babylonAnimationClone = babylonAnimation.clone();
  2384. morphTarget.animations.push(babylonAnimationClone);
  2385. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  2386. });
  2387. };
  2388. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  2389. _loop_1(targetIndex);
  2390. }
  2391. }
  2392. else {
  2393. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2394. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2395. babylonAnimation.setKeys(keys);
  2396. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  2397. animationTargetOverride.animations.push(babylonAnimation);
  2398. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  2399. }
  2400. else {
  2401. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  2402. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  2403. }
  2404. }
  2405. });
  2406. };
  2407. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  2408. if (sampler._data) {
  2409. return sampler._data;
  2410. }
  2411. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  2412. switch (interpolation) {
  2413. case "STEP" /* STEP */:
  2414. case "LINEAR" /* LINEAR */:
  2415. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2416. break;
  2417. }
  2418. default: {
  2419. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  2420. }
  2421. }
  2422. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  2423. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  2424. sampler._data = Promise.all([
  2425. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  2426. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  2427. ]).then(function (_a) {
  2428. var inputData = _a[0], outputData = _a[1];
  2429. return {
  2430. input: inputData,
  2431. interpolation: interpolation,
  2432. output: outputData,
  2433. };
  2434. });
  2435. return sampler._data;
  2436. };
  2437. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  2438. if (buffer._data) {
  2439. return buffer._data;
  2440. }
  2441. if (!buffer.uri) {
  2442. throw new Error(context + "/uri: Value is missing");
  2443. }
  2444. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  2445. return buffer._data;
  2446. };
  2447. /**
  2448. * Loads a glTF buffer view.
  2449. * @param context The context when loading the asset
  2450. * @param bufferView The glTF buffer view property
  2451. * @returns A promise that resolves with the loaded data when the load is complete
  2452. */
  2453. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  2454. if (bufferView._data) {
  2455. return bufferView._data;
  2456. }
  2457. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  2458. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer).then(function (data) {
  2459. try {
  2460. return new Uint8Array(data.buffer, data.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  2461. }
  2462. catch (e) {
  2463. throw new Error(context + ": " + e.message);
  2464. }
  2465. });
  2466. return bufferView._data;
  2467. };
  2468. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  2469. if (accessor.type !== "SCALAR" /* SCALAR */) {
  2470. throw new Error(context + "/type: Invalid value " + accessor.type);
  2471. }
  2472. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  2473. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  2474. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  2475. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  2476. }
  2477. if (accessor._data) {
  2478. return accessor._data;
  2479. }
  2480. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2481. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2482. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  2483. });
  2484. return accessor._data;
  2485. };
  2486. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  2487. var _this = this;
  2488. if (accessor._data) {
  2489. return accessor._data;
  2490. }
  2491. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  2492. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  2493. var length = numComponents * accessor.count;
  2494. if (accessor.bufferView == undefined) {
  2495. accessor._data = Promise.resolve(new Float32Array(length));
  2496. }
  2497. else {
  2498. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2499. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  2500. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  2501. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  2502. }
  2503. else {
  2504. var floatData_1 = new Float32Array(length);
  2505. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, floatData_1.length, accessor.normalized || false, function (value, index) {
  2506. floatData_1[index] = value;
  2507. });
  2508. return floatData_1;
  2509. }
  2510. });
  2511. }
  2512. if (accessor.sparse) {
  2513. var sparse_1 = accessor.sparse;
  2514. accessor._data = accessor._data.then(function (view) {
  2515. var data = view;
  2516. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  2517. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  2518. return Promise.all([
  2519. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  2520. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  2521. ]).then(function (_a) {
  2522. var indicesData = _a[0], valuesData = _a[1];
  2523. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  2524. var sparseLength = numComponents * sparse_1.count;
  2525. var values;
  2526. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  2527. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  2528. }
  2529. else {
  2530. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  2531. values = new Float32Array(sparseLength);
  2532. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  2533. values[index] = value;
  2534. });
  2535. }
  2536. var valuesIndex = 0;
  2537. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  2538. var dataIndex = indices[indicesIndex] * numComponents;
  2539. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  2540. data[dataIndex++] = values[valuesIndex++];
  2541. }
  2542. }
  2543. return data;
  2544. });
  2545. });
  2546. }
  2547. return accessor._data;
  2548. };
  2549. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  2550. var _this = this;
  2551. if (bufferView._babylonBuffer) {
  2552. return bufferView._babylonBuffer;
  2553. }
  2554. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2555. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  2556. });
  2557. return bufferView._babylonBuffer;
  2558. };
  2559. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  2560. var _this = this;
  2561. if (accessor._babylonVertexBuffer) {
  2562. return accessor._babylonVertexBuffer;
  2563. }
  2564. if (accessor.sparse) {
  2565. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2566. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  2567. });
  2568. }
  2569. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  2570. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  2571. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Accessor byte offset is not a multiple of component type byte length");
  2572. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2573. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  2574. });
  2575. }
  2576. else {
  2577. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2578. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  2579. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  2580. 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);
  2581. });
  2582. }
  2583. return accessor._babylonVertexBuffer;
  2584. };
  2585. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  2586. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2587. throw new Error(context + ": Material type not supported");
  2588. }
  2589. var promises = new Array();
  2590. if (properties) {
  2591. if (properties.baseColorFactor) {
  2592. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  2593. babylonMaterial.alpha = properties.baseColorFactor[3];
  2594. }
  2595. else {
  2596. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  2597. }
  2598. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  2599. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  2600. if (properties.baseColorTexture) {
  2601. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  2602. texture.name = babylonMaterial.name + " (Base Color)";
  2603. babylonMaterial.albedoTexture = texture;
  2604. }));
  2605. }
  2606. if (properties.metallicRoughnessTexture) {
  2607. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  2608. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  2609. babylonMaterial.metallicTexture = texture;
  2610. }));
  2611. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  2612. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  2613. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  2614. }
  2615. }
  2616. return Promise.all(promises).then(function () { });
  2617. };
  2618. /** @hidden */
  2619. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  2620. if (assign === void 0) { assign = function () { }; }
  2621. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  2622. if (extensionPromise) {
  2623. return extensionPromise;
  2624. }
  2625. material._data = material._data || {};
  2626. var babylonData = material._data[babylonDrawMode];
  2627. if (!babylonData) {
  2628. this.logOpen(context + " " + (material.name || ""));
  2629. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  2630. babylonData = {
  2631. babylonMaterial: babylonMaterial,
  2632. babylonMeshes: [],
  2633. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  2634. };
  2635. material._data[babylonDrawMode] = babylonData;
  2636. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  2637. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2638. this.logClose();
  2639. }
  2640. babylonData.babylonMeshes.push(babylonMesh);
  2641. babylonMesh.onDisposeObservable.addOnce(function () {
  2642. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  2643. if (index !== -1) {
  2644. babylonData.babylonMeshes.splice(index, 1);
  2645. }
  2646. });
  2647. assign(babylonData.babylonMaterial);
  2648. return babylonData.promise.then(function () {
  2649. return babylonData.babylonMaterial;
  2650. });
  2651. };
  2652. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  2653. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  2654. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2655. babylonMaterial.fillMode = babylonDrawMode;
  2656. babylonMaterial.enableSpecularAntiAliasing = true;
  2657. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  2658. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  2659. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2660. babylonMaterial.metallic = 1;
  2661. babylonMaterial.roughness = 1;
  2662. return babylonMaterial;
  2663. };
  2664. /**
  2665. * Creates a Babylon material from a glTF material.
  2666. * @param context The context when loading the asset
  2667. * @param material The glTF material property
  2668. * @param babylonDrawMode The draw mode for the Babylon material
  2669. * @returns The Babylon material
  2670. */
  2671. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  2672. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  2673. if (extensionPromise) {
  2674. return extensionPromise;
  2675. }
  2676. var name = material.name || "material" + material.index;
  2677. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  2678. return babylonMaterial;
  2679. };
  2680. /**
  2681. * Loads properties from a glTF material into a Babylon material.
  2682. * @param context The context when loading the asset
  2683. * @param material The glTF material property
  2684. * @param babylonMaterial The Babylon material
  2685. * @returns A promise that resolves when the load is complete
  2686. */
  2687. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2688. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  2689. if (extensionPromise) {
  2690. return extensionPromise;
  2691. }
  2692. var promises = new Array();
  2693. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  2694. if (material.pbrMetallicRoughness) {
  2695. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  2696. }
  2697. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  2698. return Promise.all(promises).then(function () { });
  2699. };
  2700. /**
  2701. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  2702. * @param context The context when loading the asset
  2703. * @param material The glTF material property
  2704. * @param babylonMaterial The Babylon material
  2705. * @returns A promise that resolves when the load is complete
  2706. */
  2707. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  2708. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2709. throw new Error(context + ": Material type not supported");
  2710. }
  2711. var promises = new Array();
  2712. 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);
  2713. if (material.doubleSided) {
  2714. babylonMaterial.backFaceCulling = false;
  2715. babylonMaterial.twoSidedLighting = true;
  2716. }
  2717. if (material.normalTexture) {
  2718. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  2719. texture.name = babylonMaterial.name + " (Normal)";
  2720. babylonMaterial.bumpTexture = texture;
  2721. }));
  2722. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  2723. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  2724. if (material.normalTexture.scale != undefined) {
  2725. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  2726. }
  2727. babylonMaterial.forceIrradianceInFragment = true;
  2728. }
  2729. if (material.occlusionTexture) {
  2730. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  2731. texture.name = babylonMaterial.name + " (Occlusion)";
  2732. babylonMaterial.ambientTexture = texture;
  2733. }));
  2734. babylonMaterial.useAmbientInGrayScale = true;
  2735. if (material.occlusionTexture.strength != undefined) {
  2736. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  2737. }
  2738. }
  2739. if (material.emissiveTexture) {
  2740. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  2741. texture.name = babylonMaterial.name + " (Emissive)";
  2742. babylonMaterial.emissiveTexture = texture;
  2743. }));
  2744. }
  2745. return Promise.all(promises).then(function () { });
  2746. };
  2747. /**
  2748. * Loads the alpha properties from a glTF material into a Babylon material.
  2749. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  2750. * @param context The context when loading the asset
  2751. * @param material The glTF material property
  2752. * @param babylonMaterial The Babylon material
  2753. */
  2754. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  2755. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2756. throw new Error(context + ": Material type not supported");
  2757. }
  2758. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  2759. switch (alphaMode) {
  2760. case "OPAQUE" /* OPAQUE */: {
  2761. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2762. break;
  2763. }
  2764. case "MASK" /* MASK */: {
  2765. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  2766. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  2767. if (babylonMaterial.albedoTexture) {
  2768. babylonMaterial.albedoTexture.hasAlpha = true;
  2769. }
  2770. break;
  2771. }
  2772. case "BLEND" /* BLEND */: {
  2773. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  2774. if (babylonMaterial.albedoTexture) {
  2775. babylonMaterial.albedoTexture.hasAlpha = true;
  2776. babylonMaterial.useAlphaFromAlbedoTexture = true;
  2777. }
  2778. break;
  2779. }
  2780. default: {
  2781. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  2782. }
  2783. }
  2784. };
  2785. /**
  2786. * Loads a glTF texture info.
  2787. * @param context The context when loading the asset
  2788. * @param textureInfo The glTF texture info property
  2789. * @param assign A function called synchronously after parsing the glTF properties
  2790. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  2791. */
  2792. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  2793. var _this = this;
  2794. if (assign === void 0) { assign = function () { }; }
  2795. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  2796. if (extensionPromise) {
  2797. return extensionPromise;
  2798. }
  2799. this.logOpen("" + context);
  2800. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  2801. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  2802. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  2803. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  2804. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  2805. assign(babylonTexture);
  2806. });
  2807. this.logClose();
  2808. return promise;
  2809. };
  2810. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  2811. var _this = this;
  2812. if (assign === void 0) { assign = function () { }; }
  2813. var promises = new Array();
  2814. this.logOpen(context + " " + (texture.name || ""));
  2815. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  2816. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  2817. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  2818. var url = null;
  2819. if (image.uri) {
  2820. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  2821. url = image.uri;
  2822. }
  2823. else if (this._babylonScene.getEngine().textureFormatInUse) {
  2824. // 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
  2825. url = this._rootUrl + image.uri;
  2826. }
  2827. }
  2828. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  2829. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  2830. if (!_this._disposed) {
  2831. deferred.resolve();
  2832. }
  2833. }, function (message, exception) {
  2834. if (!_this._disposed) {
  2835. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  2836. }
  2837. });
  2838. promises.push(deferred.promise);
  2839. if (!url) {
  2840. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  2841. var name = image.uri || _this._fileName + "#image" + image.index;
  2842. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  2843. babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
  2844. }));
  2845. }
  2846. babylonTexture.wrapU = samplerData.wrapU;
  2847. babylonTexture.wrapV = samplerData.wrapV;
  2848. assign(babylonTexture);
  2849. this.logClose();
  2850. return Promise.all(promises).then(function () {
  2851. return babylonTexture;
  2852. });
  2853. };
  2854. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  2855. if (!sampler._data) {
  2856. sampler._data = {
  2857. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  2858. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  2859. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  2860. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  2861. };
  2862. }
  2863. return sampler._data;
  2864. };
  2865. /**
  2866. * Loads a glTF image.
  2867. * @param context The context when loading the asset
  2868. * @param image The glTF image property
  2869. * @returns A promise that resolves with the loaded data when the load is complete
  2870. */
  2871. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  2872. if (!image._data) {
  2873. this.logOpen(context + " " + (image.name || ""));
  2874. if (image.uri) {
  2875. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  2876. }
  2877. else {
  2878. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  2879. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  2880. }
  2881. this.logClose();
  2882. }
  2883. return image._data;
  2884. };
  2885. /**
  2886. * Loads a glTF uri.
  2887. * @param context The context when loading the asset
  2888. * @param property The glTF property associated with the uri
  2889. * @param uri The base64 or relative uri
  2890. * @returns A promise that resolves with the loaded data when the load is complete
  2891. */
  2892. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  2893. var _this = this;
  2894. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  2895. if (extensionPromise) {
  2896. return extensionPromise;
  2897. }
  2898. if (!GLTFLoader._ValidateUri(uri)) {
  2899. throw new Error(context + ": '" + uri + "' is invalid");
  2900. }
  2901. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  2902. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  2903. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  2904. return Promise.resolve(data);
  2905. }
  2906. this.log("Loading " + uri);
  2907. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  2908. return new Promise(function (resolve, reject) {
  2909. if (!_this._disposed) {
  2910. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  2911. if (!_this._disposed) {
  2912. var data = new Uint8Array(fileData);
  2913. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  2914. resolve(data);
  2915. }
  2916. }, function (event) {
  2917. if (!_this._disposed) {
  2918. if (request_1) {
  2919. request_1._lengthComputable = event.lengthComputable;
  2920. request_1._loaded = event.loaded;
  2921. request_1._total = event.total;
  2922. }
  2923. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  2924. try {
  2925. _this._onProgress();
  2926. }
  2927. catch (e) {
  2928. reject(e);
  2929. }
  2930. }
  2931. }
  2932. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  2933. if (!_this._disposed) {
  2934. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  2935. }
  2936. });
  2937. _this._requests.push(request_1);
  2938. }
  2939. });
  2940. });
  2941. };
  2942. GLTFLoader.prototype._onProgress = function () {
  2943. if (!this._progressCallback) {
  2944. return;
  2945. }
  2946. var lengthComputable = true;
  2947. var loaded = 0;
  2948. var total = 0;
  2949. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  2950. var request = _a[_i];
  2951. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  2952. return;
  2953. }
  2954. lengthComputable = lengthComputable && request._lengthComputable;
  2955. loaded += request._loaded;
  2956. total += request._total;
  2957. }
  2958. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  2959. };
  2960. /**
  2961. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  2962. * @param babylonObject the Babylon object with metadata
  2963. * @param pointer the JSON pointer
  2964. */
  2965. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  2966. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  2967. var gltf = (metadata.gltf = metadata.gltf || {});
  2968. var pointers = (gltf.pointers = gltf.pointers || []);
  2969. pointers.push(pointer);
  2970. };
  2971. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  2972. // Set defaults if undefined
  2973. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  2974. switch (mode) {
  2975. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  2976. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  2977. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2978. default:
  2979. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Invalid value (" + mode + ")");
  2980. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2981. }
  2982. };
  2983. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  2984. // Set defaults if undefined
  2985. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  2986. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  2987. if (magFilter === 9729 /* LINEAR */) {
  2988. switch (minFilter) {
  2989. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  2990. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  2991. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  2992. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  2993. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  2994. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2995. default:
  2996. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  2997. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2998. }
  2999. }
  3000. else {
  3001. if (magFilter !== 9728 /* NEAREST */) {
  3002. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  3003. }
  3004. switch (minFilter) {
  3005. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  3006. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  3007. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3008. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  3009. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  3010. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  3011. default:
  3012. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3013. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3014. }
  3015. }
  3016. };
  3017. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  3018. var buffer = bufferView.buffer;
  3019. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  3020. try {
  3021. switch (componentType) {
  3022. case 5120 /* BYTE */: return new Int8Array(buffer, byteOffset, length);
  3023. case 5121 /* UNSIGNED_BYTE */: return new Uint8Array(buffer, byteOffset, length);
  3024. case 5122 /* SHORT */: return new Int16Array(buffer, byteOffset, length);
  3025. case 5123 /* UNSIGNED_SHORT */: return new Uint16Array(buffer, byteOffset, length);
  3026. case 5125 /* UNSIGNED_INT */: return new Uint32Array(buffer, byteOffset, length);
  3027. case 5126 /* FLOAT */: return new Float32Array(buffer, byteOffset, length);
  3028. default: throw new Error("Invalid component type " + componentType);
  3029. }
  3030. }
  3031. catch (e) {
  3032. throw new Error(context + ": " + e);
  3033. }
  3034. };
  3035. GLTFLoader._GetNumComponents = function (context, type) {
  3036. switch (type) {
  3037. case "SCALAR": return 1;
  3038. case "VEC2": return 2;
  3039. case "VEC3": return 3;
  3040. case "VEC4": return 4;
  3041. case "MAT2": return 4;
  3042. case "MAT3": return 9;
  3043. case "MAT4": return 16;
  3044. }
  3045. throw new Error(context + ": Invalid type (" + type + ")");
  3046. };
  3047. GLTFLoader._ValidateUri = function (uri) {
  3048. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  3049. };
  3050. GLTFLoader._GetDrawMode = function (context, mode) {
  3051. if (mode == undefined) {
  3052. mode = 4 /* TRIANGLES */;
  3053. }
  3054. switch (mode) {
  3055. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  3056. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  3057. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  3058. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  3059. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  3060. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  3061. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  3062. }
  3063. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  3064. };
  3065. GLTFLoader.prototype._compileMaterialsAsync = function () {
  3066. var _this = this;
  3067. this._parent._startPerformanceCounter("Compile materials");
  3068. var promises = new Array();
  3069. if (this._gltf.materials) {
  3070. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  3071. var material = _a[_i];
  3072. if (material._data) {
  3073. for (var babylonDrawMode in material._data) {
  3074. var babylonData = material._data[babylonDrawMode];
  3075. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  3076. var babylonMesh = _c[_b];
  3077. // Ensure nonUniformScaling is set if necessary.
  3078. babylonMesh.computeWorldMatrix(true);
  3079. var babylonMaterial = babylonData.babylonMaterial;
  3080. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  3081. if (this._parent.useClipPlane) {
  3082. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  3083. }
  3084. }
  3085. }
  3086. }
  3087. }
  3088. }
  3089. return Promise.all(promises).then(function () {
  3090. _this._parent._endPerformanceCounter("Compile materials");
  3091. });
  3092. };
  3093. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  3094. var _this = this;
  3095. this._parent._startPerformanceCounter("Compile shadow generators");
  3096. var promises = new Array();
  3097. var lights = this._babylonScene.lights;
  3098. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  3099. var light = lights_1[_i];
  3100. var generator = light.getShadowGenerator();
  3101. if (generator) {
  3102. promises.push(generator.forceCompilationAsync());
  3103. }
  3104. }
  3105. return Promise.all(promises).then(function () {
  3106. _this._parent._endPerformanceCounter("Compile shadow generators");
  3107. });
  3108. };
  3109. GLTFLoader.prototype._forEachExtensions = function (action) {
  3110. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  3111. var name_4 = _a[_i];
  3112. var extension = this._extensions[name_4];
  3113. if (extension.enabled) {
  3114. action(extension);
  3115. }
  3116. }
  3117. };
  3118. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  3119. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  3120. var name_5 = _a[_i];
  3121. var extension = this._extensions[name_5];
  3122. if (extension.enabled) {
  3123. var id = name_5 + "." + functionName;
  3124. var loaderProperty = property;
  3125. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  3126. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  3127. if (!activeLoaderExtensionFunctions[id]) {
  3128. activeLoaderExtensionFunctions[id] = true;
  3129. try {
  3130. var result = actionAsync(extension);
  3131. if (result) {
  3132. return result;
  3133. }
  3134. }
  3135. finally {
  3136. delete activeLoaderExtensionFunctions[id];
  3137. }
  3138. }
  3139. }
  3140. }
  3141. return null;
  3142. };
  3143. GLTFLoader.prototype._extensionsOnLoading = function () {
  3144. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  3145. };
  3146. GLTFLoader.prototype._extensionsOnReady = function () {
  3147. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  3148. };
  3149. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  3150. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  3151. };
  3152. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  3153. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  3154. };
  3155. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  3156. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  3157. };
  3158. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  3159. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  3160. };
  3161. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  3162. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  3163. };
  3164. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3165. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  3166. };
  3167. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  3168. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  3169. };
  3170. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3171. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  3172. };
  3173. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  3174. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  3175. };
  3176. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  3177. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  3178. };
  3179. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  3180. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  3181. };
  3182. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  3183. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  3184. };
  3185. /**
  3186. * Helper method called by a loader extension to load an glTF extension.
  3187. * @param context The context when loading the asset
  3188. * @param property The glTF property to load the extension from
  3189. * @param extensionName The name of the extension to load
  3190. * @param actionAsync The action to run
  3191. * @returns The promise returned by actionAsync or null if the extension does not exist
  3192. */
  3193. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  3194. if (!property.extensions) {
  3195. return null;
  3196. }
  3197. var extensions = property.extensions;
  3198. var extension = extensions[extensionName];
  3199. if (!extension) {
  3200. return null;
  3201. }
  3202. return actionAsync(context + "/extensions/" + extensionName, extension);
  3203. };
  3204. /**
  3205. * Helper method called by a loader extension to load a glTF extra.
  3206. * @param context The context when loading the asset
  3207. * @param property The glTF property to load the extra from
  3208. * @param extensionName The name of the extension to load
  3209. * @param actionAsync The action to run
  3210. * @returns The promise returned by actionAsync or null if the extra does not exist
  3211. */
  3212. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  3213. if (!property.extras) {
  3214. return null;
  3215. }
  3216. var extras = property.extras;
  3217. var extra = extras[extensionName];
  3218. if (!extra) {
  3219. return null;
  3220. }
  3221. return actionAsync(context + "/extras/" + extensionName, extra);
  3222. };
  3223. /**
  3224. * Increments the indentation level and logs a message.
  3225. * @param message The message to log
  3226. */
  3227. GLTFLoader.prototype.logOpen = function (message) {
  3228. this._parent._logOpen(message);
  3229. };
  3230. /**
  3231. * Decrements the indentation level.
  3232. */
  3233. GLTFLoader.prototype.logClose = function () {
  3234. this._parent._logClose();
  3235. };
  3236. /**
  3237. * Logs a message
  3238. * @param message The message to log
  3239. */
  3240. GLTFLoader.prototype.log = function (message) {
  3241. this._parent._log(message);
  3242. };
  3243. /**
  3244. * Starts a performance counter.
  3245. * @param counterName The name of the performance counter
  3246. */
  3247. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  3248. this._parent._startPerformanceCounter(counterName);
  3249. };
  3250. /**
  3251. * Ends a performance counter.
  3252. * @param counterName The name of the performance counter
  3253. */
  3254. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  3255. this._parent._endPerformanceCounter(counterName);
  3256. };
  3257. GLTFLoader._DefaultSampler = { index: -1 };
  3258. GLTFLoader._ExtensionNames = new Array();
  3259. GLTFLoader._ExtensionFactories = {};
  3260. return GLTFLoader;
  3261. }());
  3262. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  3263. /***/ }),
  3264. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  3265. /*!******************************************!*\
  3266. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  3267. \******************************************/
  3268. /*! no static exports found */
  3269. /***/ (function(module, exports) {
  3270. /***/ }),
  3271. /***/ "./glTF/2.0/index.ts":
  3272. /*!***************************!*\
  3273. !*** ./glTF/2.0/index.ts ***!
  3274. \***************************/
  3275. /*! 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 */
  3276. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3277. "use strict";
  3278. __webpack_require__.r(__webpack_exports__);
  3279. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3280. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  3281. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  3282. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  3283. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  3284. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  3285. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  3286. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  3287. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  3288. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  3289. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  3290. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  3291. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  3292. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  3293. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  3294. /***/ }),
  3295. /***/ "./glTF/glTFFileLoader.ts":
  3296. /*!********************************!*\
  3297. !*** ./glTF/glTFFileLoader.ts ***!
  3298. \********************************/
  3299. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3300. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3301. "use strict";
  3302. __webpack_require__.r(__webpack_exports__);
  3303. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  3304. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  3305. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  3306. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  3307. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Maths/math");
  3308. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  3309. /**
  3310. * Mode that determines the coordinate system to use.
  3311. */
  3312. var GLTFLoaderCoordinateSystemMode;
  3313. (function (GLTFLoaderCoordinateSystemMode) {
  3314. /**
  3315. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  3316. */
  3317. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  3318. /**
  3319. * Sets the useRightHandedSystem flag on the scene.
  3320. */
  3321. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  3322. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  3323. /**
  3324. * Mode that determines what animations will start.
  3325. */
  3326. var GLTFLoaderAnimationStartMode;
  3327. (function (GLTFLoaderAnimationStartMode) {
  3328. /**
  3329. * No animation will start.
  3330. */
  3331. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  3332. /**
  3333. * The first animation will start.
  3334. */
  3335. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  3336. /**
  3337. * All animations will start.
  3338. */
  3339. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  3340. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  3341. /**
  3342. * Loader state.
  3343. */
  3344. var GLTFLoaderState;
  3345. (function (GLTFLoaderState) {
  3346. /**
  3347. * The asset is loading.
  3348. */
  3349. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  3350. /**
  3351. * The asset is ready for rendering.
  3352. */
  3353. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  3354. /**
  3355. * The asset is completely loaded.
  3356. */
  3357. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  3358. })(GLTFLoaderState || (GLTFLoaderState = {}));
  3359. /**
  3360. * File loader for loading glTF files into a scene.
  3361. */
  3362. var GLTFFileLoader = /** @class */ (function () {
  3363. function GLTFFileLoader() {
  3364. // --------------
  3365. // Common options
  3366. // --------------
  3367. /**
  3368. * Raised when the asset has been parsed
  3369. */
  3370. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3371. // ----------
  3372. // V2 options
  3373. // ----------
  3374. /**
  3375. * The coordinate system mode. Defaults to AUTO.
  3376. */
  3377. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  3378. /**
  3379. * The animation start mode. Defaults to FIRST.
  3380. */
  3381. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  3382. /**
  3383. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  3384. */
  3385. this.compileMaterials = false;
  3386. /**
  3387. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  3388. */
  3389. this.useClipPlane = false;
  3390. /**
  3391. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  3392. */
  3393. this.compileShadowGenerators = false;
  3394. /**
  3395. * Defines if the Alpha blended materials are only applied as coverage.
  3396. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  3397. * If true, no extra effects are applied to transparent pixels.
  3398. */
  3399. this.transparencyAsCoverage = false;
  3400. /**
  3401. * Function called before loading a url referenced by the asset.
  3402. */
  3403. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3404. /**
  3405. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3406. */
  3407. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3408. /**
  3409. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  3410. */
  3411. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3412. /**
  3413. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  3414. */
  3415. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3416. /**
  3417. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  3418. */
  3419. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3420. /**
  3421. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  3422. * For assets with LODs, raised when all of the LODs are complete.
  3423. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3424. */
  3425. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3426. /**
  3427. * Observable raised when an error occurs.
  3428. */
  3429. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3430. /**
  3431. * Observable raised after the loader is disposed.
  3432. */
  3433. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3434. /**
  3435. * Observable raised after a loader extension is created.
  3436. * Set additional options for a loader extension in this event.
  3437. */
  3438. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3439. /**
  3440. * Defines if the loader should validate the asset.
  3441. */
  3442. this.validate = false;
  3443. /**
  3444. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  3445. */
  3446. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3447. this._loader = null;
  3448. /**
  3449. * Name of the loader ("gltf")
  3450. */
  3451. this.name = "gltf";
  3452. /**
  3453. * Supported file extensions of the loader (.gltf, .glb)
  3454. */
  3455. this.extensions = {
  3456. ".gltf": { isBinary: false },
  3457. ".glb": { isBinary: true }
  3458. };
  3459. this._logIndentLevel = 0;
  3460. this._loggingEnabled = false;
  3461. /** @hidden */
  3462. this._log = this._logDisabled;
  3463. this._capturePerformanceCounters = false;
  3464. /** @hidden */
  3465. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3466. /** @hidden */
  3467. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3468. }
  3469. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  3470. /**
  3471. * Raised when the asset has been parsed
  3472. */
  3473. set: function (callback) {
  3474. if (this._onParsedObserver) {
  3475. this.onParsedObservable.remove(this._onParsedObserver);
  3476. }
  3477. this._onParsedObserver = this.onParsedObservable.add(callback);
  3478. },
  3479. enumerable: true,
  3480. configurable: true
  3481. });
  3482. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  3483. /**
  3484. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3485. */
  3486. set: function (callback) {
  3487. if (this._onMeshLoadedObserver) {
  3488. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  3489. }
  3490. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  3491. },
  3492. enumerable: true,
  3493. configurable: true
  3494. });
  3495. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  3496. /**
  3497. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  3498. */
  3499. set: function (callback) {
  3500. if (this._onTextureLoadedObserver) {
  3501. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  3502. }
  3503. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  3504. },
  3505. enumerable: true,
  3506. configurable: true
  3507. });
  3508. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  3509. /**
  3510. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  3511. */
  3512. set: function (callback) {
  3513. if (this._onMaterialLoadedObserver) {
  3514. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  3515. }
  3516. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  3517. },
  3518. enumerable: true,
  3519. configurable: true
  3520. });
  3521. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  3522. /**
  3523. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  3524. */
  3525. set: function (callback) {
  3526. if (this._onCameraLoadedObserver) {
  3527. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  3528. }
  3529. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  3530. },
  3531. enumerable: true,
  3532. configurable: true
  3533. });
  3534. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  3535. /**
  3536. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  3537. * For assets with LODs, raised when all of the LODs are complete.
  3538. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3539. */
  3540. set: function (callback) {
  3541. if (this._onCompleteObserver) {
  3542. this.onCompleteObservable.remove(this._onCompleteObserver);
  3543. }
  3544. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  3545. },
  3546. enumerable: true,
  3547. configurable: true
  3548. });
  3549. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  3550. /**
  3551. * Callback raised when an error occurs.
  3552. */
  3553. set: function (callback) {
  3554. if (this._onErrorObserver) {
  3555. this.onErrorObservable.remove(this._onErrorObserver);
  3556. }
  3557. this._onErrorObserver = this.onErrorObservable.add(callback);
  3558. },
  3559. enumerable: true,
  3560. configurable: true
  3561. });
  3562. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  3563. /**
  3564. * Callback raised after the loader is disposed.
  3565. */
  3566. set: function (callback) {
  3567. if (this._onDisposeObserver) {
  3568. this.onDisposeObservable.remove(this._onDisposeObserver);
  3569. }
  3570. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  3571. },
  3572. enumerable: true,
  3573. configurable: true
  3574. });
  3575. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  3576. /**
  3577. * Callback raised after a loader extension is created.
  3578. */
  3579. set: function (callback) {
  3580. if (this._onExtensionLoadedObserver) {
  3581. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  3582. }
  3583. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  3584. },
  3585. enumerable: true,
  3586. configurable: true
  3587. });
  3588. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  3589. /**
  3590. * Defines if the loader logging is enabled.
  3591. */
  3592. get: function () {
  3593. return this._loggingEnabled;
  3594. },
  3595. set: function (value) {
  3596. if (this._loggingEnabled === value) {
  3597. return;
  3598. }
  3599. this._loggingEnabled = value;
  3600. if (this._loggingEnabled) {
  3601. this._log = this._logEnabled;
  3602. }
  3603. else {
  3604. this._log = this._logDisabled;
  3605. }
  3606. },
  3607. enumerable: true,
  3608. configurable: true
  3609. });
  3610. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  3611. /**
  3612. * Defines if the loader should capture performance counters.
  3613. */
  3614. get: function () {
  3615. return this._capturePerformanceCounters;
  3616. },
  3617. set: function (value) {
  3618. if (this._capturePerformanceCounters === value) {
  3619. return;
  3620. }
  3621. this._capturePerformanceCounters = value;
  3622. if (this._capturePerformanceCounters) {
  3623. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  3624. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  3625. }
  3626. else {
  3627. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3628. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3629. }
  3630. },
  3631. enumerable: true,
  3632. configurable: true
  3633. });
  3634. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  3635. /**
  3636. * Callback raised after a loader extension is created.
  3637. */
  3638. set: function (callback) {
  3639. if (this._onValidatedObserver) {
  3640. this.onValidatedObservable.remove(this._onValidatedObserver);
  3641. }
  3642. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  3643. },
  3644. enumerable: true,
  3645. configurable: true
  3646. });
  3647. /**
  3648. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  3649. */
  3650. GLTFFileLoader.prototype.dispose = function () {
  3651. if (this._loader) {
  3652. this._loader.dispose();
  3653. this._loader = null;
  3654. }
  3655. this._clear();
  3656. this.onDisposeObservable.notifyObservers(undefined);
  3657. this.onDisposeObservable.clear();
  3658. };
  3659. /** @hidden */
  3660. GLTFFileLoader.prototype._clear = function () {
  3661. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3662. this.onMeshLoadedObservable.clear();
  3663. this.onTextureLoadedObservable.clear();
  3664. this.onMaterialLoadedObservable.clear();
  3665. this.onCameraLoadedObservable.clear();
  3666. this.onCompleteObservable.clear();
  3667. this.onExtensionLoadedObservable.clear();
  3668. };
  3669. /**
  3670. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  3671. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3672. * @param scene the scene the meshes should be added to
  3673. * @param data the glTF data to load
  3674. * @param rootUrl root url to load from
  3675. * @param onProgress event that fires when loading progress has occured
  3676. * @param fileName Defines the name of the file to load
  3677. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3678. */
  3679. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  3680. var _this = this;
  3681. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3682. _this._log("Loading " + (fileName || ""));
  3683. _this._loader = _this._getLoader(loaderData);
  3684. return _this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onProgress, fileName);
  3685. });
  3686. };
  3687. /**
  3688. * Imports all objects from the loaded glTF data and adds them to the scene
  3689. * @param scene the scene the objects 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 which completes when objects have been loaded to the scene
  3695. */
  3696. GLTFFileLoader.prototype.loadAsync = function (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.loadAsync(scene, loaderData, rootUrl, onProgress, fileName);
  3702. });
  3703. };
  3704. /**
  3705. * Load into an asset container.
  3706. * @param scene The scene to load into
  3707. * @param data The data to import
  3708. * @param rootUrl The root url for scene and resources
  3709. * @param onProgress The callback when the load progresses
  3710. * @param fileName Defines the name of the file to load
  3711. * @returns The loaded asset container
  3712. */
  3713. GLTFFileLoader.prototype.loadAssetContainerAsync = 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. // Get materials/textures when loading to add to container
  3719. var materials = [];
  3720. _this.onMaterialLoadedObservable.add(function (material) {
  3721. materials.push(material);
  3722. });
  3723. var textures = [];
  3724. _this.onTextureLoadedObservable.add(function (texture) {
  3725. textures.push(texture);
  3726. });
  3727. return _this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress, fileName).then(function (result) {
  3728. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  3729. Array.prototype.push.apply(container.meshes, result.meshes);
  3730. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  3731. Array.prototype.push.apply(container.skeletons, result.skeletons);
  3732. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  3733. Array.prototype.push.apply(container.materials, materials);
  3734. Array.prototype.push.apply(container.textures, textures);
  3735. container.removeAllFromScene();
  3736. return container;
  3737. });
  3738. });
  3739. };
  3740. /**
  3741. * If the data string can be loaded directly.
  3742. * @param data string contianing the file data
  3743. * @returns if the data can be loaded directly
  3744. */
  3745. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  3746. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  3747. };
  3748. /**
  3749. * Instantiates a glTF file loader plugin.
  3750. * @returns the created plugin
  3751. */
  3752. GLTFFileLoader.prototype.createPlugin = function () {
  3753. return new GLTFFileLoader();
  3754. };
  3755. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  3756. /**
  3757. * The loader state or null if the loader is not active.
  3758. */
  3759. get: function () {
  3760. return this._loader ? this._loader.state : null;
  3761. },
  3762. enumerable: true,
  3763. configurable: true
  3764. });
  3765. /**
  3766. * Returns a promise that resolves when the asset is completely loaded.
  3767. * @returns a promise that resolves when the asset is completely loaded.
  3768. */
  3769. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  3770. var _this = this;
  3771. return new Promise(function (resolve, reject) {
  3772. _this.onCompleteObservable.addOnce(function () {
  3773. resolve();
  3774. });
  3775. _this.onErrorObservable.addOnce(function (reason) {
  3776. reject(reason);
  3777. });
  3778. });
  3779. };
  3780. GLTFFileLoader.prototype._parseAsync = function (scene, data, rootUrl, fileName) {
  3781. var _this = this;
  3782. return Promise.resolve().then(function () {
  3783. return _this._validateAsync(scene, data, rootUrl, fileName).then(function () {
  3784. var unpacked = (data instanceof ArrayBuffer) ? _this._unpackBinary(data) : { json: data, bin: null };
  3785. _this._startPerformanceCounter("Parse JSON");
  3786. _this._log("JSON length: " + unpacked.json.length);
  3787. var loaderData = {
  3788. json: JSON.parse(unpacked.json),
  3789. bin: unpacked.bin
  3790. };
  3791. _this._endPerformanceCounter("Parse JSON");
  3792. _this.onParsedObservable.notifyObservers(loaderData);
  3793. _this.onParsedObservable.clear();
  3794. return loaderData;
  3795. });
  3796. });
  3797. };
  3798. GLTFFileLoader.prototype._validateAsync = function (scene, data, rootUrl, fileName) {
  3799. var _this = this;
  3800. if (!this.validate || typeof GLTFValidator === "undefined") {
  3801. return Promise.resolve();
  3802. }
  3803. this._startPerformanceCounter("Validate JSON");
  3804. var options = {
  3805. externalResourceFunction: function (uri) {
  3806. return _this.preprocessUrlAsync(rootUrl + uri)
  3807. .then(function (url) { return scene._loadFileAsync(url, true, true); })
  3808. .then(function (data) { return new Uint8Array(data); });
  3809. }
  3810. };
  3811. if (fileName && fileName.substr(0, 5) !== "data:") {
  3812. options.uri = (rootUrl === "file:" ? fileName : "" + rootUrl + fileName);
  3813. }
  3814. var promise = (data instanceof ArrayBuffer)
  3815. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  3816. : GLTFValidator.validateString(data, options);
  3817. return promise.then(function (result) {
  3818. _this._endPerformanceCounter("Validate JSON");
  3819. _this.onValidatedObservable.notifyObservers(result);
  3820. _this.onValidatedObservable.clear();
  3821. }, function (reason) {
  3822. _this._endPerformanceCounter("Validate JSON");
  3823. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason);
  3824. _this.onValidatedObservable.clear();
  3825. });
  3826. };
  3827. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  3828. var asset = loaderData.json.asset || {};
  3829. this._log("Asset version: " + asset.version);
  3830. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  3831. asset.generator && this._log("Asset generator: " + asset.generator);
  3832. var version = GLTFFileLoader._parseVersion(asset.version);
  3833. if (!version) {
  3834. throw new Error("Invalid version: " + asset.version);
  3835. }
  3836. if (asset.minVersion !== undefined) {
  3837. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  3838. if (!minVersion) {
  3839. throw new Error("Invalid minimum version: " + asset.minVersion);
  3840. }
  3841. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  3842. throw new Error("Incompatible minimum version: " + asset.minVersion);
  3843. }
  3844. }
  3845. var createLoaders = {
  3846. 1: GLTFFileLoader._CreateGLTF1Loader,
  3847. 2: GLTFFileLoader._CreateGLTF2Loader
  3848. };
  3849. var createLoader = createLoaders[version.major];
  3850. if (!createLoader) {
  3851. throw new Error("Unsupported version: " + asset.version);
  3852. }
  3853. return createLoader(this);
  3854. };
  3855. GLTFFileLoader.prototype._unpackBinary = function (data) {
  3856. this._startPerformanceCounter("Unpack binary");
  3857. this._log("Binary length: " + data.byteLength);
  3858. var Binary = {
  3859. Magic: 0x46546C67
  3860. };
  3861. var binaryReader = new BinaryReader(data);
  3862. var magic = binaryReader.readUint32();
  3863. if (magic !== Binary.Magic) {
  3864. throw new Error("Unexpected magic: " + magic);
  3865. }
  3866. var version = binaryReader.readUint32();
  3867. if (this.loggingEnabled) {
  3868. this._log("Binary version: " + version);
  3869. }
  3870. var unpacked;
  3871. switch (version) {
  3872. case 1: {
  3873. unpacked = this._unpackBinaryV1(binaryReader);
  3874. break;
  3875. }
  3876. case 2: {
  3877. unpacked = this._unpackBinaryV2(binaryReader);
  3878. break;
  3879. }
  3880. default: {
  3881. throw new Error("Unsupported version: " + version);
  3882. }
  3883. }
  3884. this._endPerformanceCounter("Unpack binary");
  3885. return unpacked;
  3886. };
  3887. GLTFFileLoader.prototype._unpackBinaryV1 = function (binaryReader) {
  3888. var ContentFormat = {
  3889. JSON: 0
  3890. };
  3891. var length = binaryReader.readUint32();
  3892. if (length != binaryReader.getLength()) {
  3893. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3894. }
  3895. var contentLength = binaryReader.readUint32();
  3896. var contentFormat = binaryReader.readUint32();
  3897. var content;
  3898. switch (contentFormat) {
  3899. case ContentFormat.JSON: {
  3900. content = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength));
  3901. break;
  3902. }
  3903. default: {
  3904. throw new Error("Unexpected content format: " + contentFormat);
  3905. }
  3906. }
  3907. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  3908. var body = binaryReader.readUint8Array(bytesRemaining);
  3909. return {
  3910. json: content,
  3911. bin: body
  3912. };
  3913. };
  3914. GLTFFileLoader.prototype._unpackBinaryV2 = function (binaryReader) {
  3915. var ChunkFormat = {
  3916. JSON: 0x4E4F534A,
  3917. BIN: 0x004E4942
  3918. };
  3919. var length = binaryReader.readUint32();
  3920. if (length !== binaryReader.getLength()) {
  3921. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3922. }
  3923. // JSON chunk
  3924. var chunkLength = binaryReader.readUint32();
  3925. var chunkFormat = binaryReader.readUint32();
  3926. if (chunkFormat !== ChunkFormat.JSON) {
  3927. throw new Error("First chunk format is not JSON");
  3928. }
  3929. var json = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength));
  3930. // Look for BIN chunk
  3931. var bin = null;
  3932. while (binaryReader.getPosition() < binaryReader.getLength()) {
  3933. var chunkLength_1 = binaryReader.readUint32();
  3934. var chunkFormat_1 = binaryReader.readUint32();
  3935. switch (chunkFormat_1) {
  3936. case ChunkFormat.JSON: {
  3937. throw new Error("Unexpected JSON chunk");
  3938. }
  3939. case ChunkFormat.BIN: {
  3940. bin = binaryReader.readUint8Array(chunkLength_1);
  3941. break;
  3942. }
  3943. default: {
  3944. // ignore unrecognized chunkFormat
  3945. binaryReader.skipBytes(chunkLength_1);
  3946. break;
  3947. }
  3948. }
  3949. }
  3950. return {
  3951. json: json,
  3952. bin: bin
  3953. };
  3954. };
  3955. GLTFFileLoader._parseVersion = function (version) {
  3956. if (version === "1.0" || version === "1.0.1") {
  3957. return {
  3958. major: 1,
  3959. minor: 0
  3960. };
  3961. }
  3962. var match = (version + "").match(/^(\d+)\.(\d+)/);
  3963. if (!match) {
  3964. return null;
  3965. }
  3966. return {
  3967. major: parseInt(match[1]),
  3968. minor: parseInt(match[2])
  3969. };
  3970. };
  3971. GLTFFileLoader._compareVersion = function (a, b) {
  3972. if (a.major > b.major) {
  3973. return 1;
  3974. }
  3975. if (a.major < b.major) {
  3976. return -1;
  3977. }
  3978. if (a.minor > b.minor) {
  3979. return 1;
  3980. }
  3981. if (a.minor < b.minor) {
  3982. return -1;
  3983. }
  3984. return 0;
  3985. };
  3986. GLTFFileLoader._decodeBufferToText = function (buffer) {
  3987. if (typeof TextDecoder !== "undefined") {
  3988. return new TextDecoder().decode(buffer);
  3989. }
  3990. var result = "";
  3991. var length = buffer.byteLength;
  3992. for (var i = 0; i < length; i++) {
  3993. result += String.fromCharCode(buffer[i]);
  3994. }
  3995. return result;
  3996. };
  3997. /** @hidden */
  3998. GLTFFileLoader.prototype._logOpen = function (message) {
  3999. this._log(message);
  4000. this._logIndentLevel++;
  4001. };
  4002. /** @hidden */
  4003. GLTFFileLoader.prototype._logClose = function () {
  4004. --this._logIndentLevel;
  4005. };
  4006. GLTFFileLoader.prototype._logEnabled = function (message) {
  4007. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  4008. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("" + spaces + message);
  4009. };
  4010. GLTFFileLoader.prototype._logDisabled = function (message) {
  4011. };
  4012. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  4013. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  4014. };
  4015. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  4016. };
  4017. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  4018. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  4019. };
  4020. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  4021. };
  4022. // ----------
  4023. // V1 options
  4024. // ----------
  4025. /**
  4026. * 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.
  4027. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  4028. * Defaults to true.
  4029. * @hidden
  4030. */
  4031. GLTFFileLoader.IncrementalLoading = true;
  4032. /**
  4033. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  4034. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  4035. * @hidden
  4036. */
  4037. GLTFFileLoader.HomogeneousCoordinates = false;
  4038. GLTFFileLoader._logSpaces = " ";
  4039. return GLTFFileLoader;
  4040. }());
  4041. var BinaryReader = /** @class */ (function () {
  4042. function BinaryReader(arrayBuffer) {
  4043. this._arrayBuffer = arrayBuffer;
  4044. this._dataView = new DataView(arrayBuffer);
  4045. this._byteOffset = 0;
  4046. }
  4047. BinaryReader.prototype.getPosition = function () {
  4048. return this._byteOffset;
  4049. };
  4050. BinaryReader.prototype.getLength = function () {
  4051. return this._arrayBuffer.byteLength;
  4052. };
  4053. BinaryReader.prototype.readUint32 = function () {
  4054. var value = this._dataView.getUint32(this._byteOffset, true);
  4055. this._byteOffset += 4;
  4056. return value;
  4057. };
  4058. BinaryReader.prototype.readUint8Array = function (length) {
  4059. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  4060. this._byteOffset += length;
  4061. return value;
  4062. };
  4063. BinaryReader.prototype.skipBytes = function (length) {
  4064. this._byteOffset += length;
  4065. };
  4066. return BinaryReader;
  4067. }());
  4068. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  4069. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  4070. }
  4071. /***/ }),
  4072. /***/ "./legacy/legacy-glTF.ts":
  4073. /*!*******************************!*\
  4074. !*** ./legacy/legacy-glTF.ts ***!
  4075. \*******************************/
  4076. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4077. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4078. "use strict";
  4079. __webpack_require__.r(__webpack_exports__);
  4080. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  4081. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  4082. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  4083. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  4084. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  4085. /**
  4086. * This is the entry point for the UMD module.
  4087. * The entry point for a future ESM package should be index.ts
  4088. */
  4089. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4090. if (typeof globalObject !== "undefined") {
  4091. globalObject.BABYLON = globalObject.BABYLON || {};
  4092. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  4093. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  4094. }
  4095. }
  4096. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4097. /***/ }),
  4098. /***/ "./legacy/legacy-glTF2.ts":
  4099. /*!********************************!*\
  4100. !*** ./legacy/legacy-glTF2.ts ***!
  4101. \********************************/
  4102. /*! exports provided: GLTF2 */
  4103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4104. "use strict";
  4105. __webpack_require__.r(__webpack_exports__);
  4106. /* 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");
  4107. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  4108. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  4109. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  4110. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  4111. /**
  4112. * This is the entry point for the UMD module.
  4113. * The entry point for a future ESM package should be index.ts
  4114. */
  4115. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4116. if (typeof globalObject !== "undefined") {
  4117. globalObject.BABYLON = globalObject.BABYLON || {};
  4118. var BABYLON = globalObject.BABYLON;
  4119. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  4120. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  4121. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  4122. var keys = [];
  4123. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  4124. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  4125. keys.push(key);
  4126. }
  4127. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  4128. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  4129. keys.push(key);
  4130. }
  4131. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  4132. // Prevent Reassignment.
  4133. if (keys.indexOf(key) > -1) {
  4134. continue;
  4135. }
  4136. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  4137. }
  4138. }
  4139. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4140. /***/ }),
  4141. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  4142. /*!******************************************!*\
  4143. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  4144. \******************************************/
  4145. /*! exports provided: GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4146. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4147. "use strict";
  4148. __webpack_require__.r(__webpack_exports__);
  4149. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  4150. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  4151. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  4152. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  4153. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  4154. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  4155. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  4156. /***/ }),
  4157. /***/ "babylonjs/Maths/math":
  4158. /*!****************************************************************************************************!*\
  4159. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  4160. \****************************************************************************************************/
  4161. /*! no static exports found */
  4162. /***/ (function(module, exports) {
  4163. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__;
  4164. /***/ })
  4165. /******/ });
  4166. });
  4167. //# sourceMappingURL=babylon.glTF2FileLoader.js.map